2 * Copyright(c) 2019 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 using Tizen.NUI.BaseComponents;
19 using System.ComponentModel;
21 namespace Tizen.NUI.Components
24 /// InputField is a editable input compoment
26 /// <since_tizen> 6 </since_tizen>
27 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public class InputField : Control
31 // the background image
32 private ImageView bgImage = null;
34 private TextField textField = null;
35 // the attributes of the inputField
36 private InputFieldStyle inputFieldAttrs = null;
37 // the flag indicate should relayout the textField in base class
38 private bool relayoutTextField = true;
40 static InputField() { }
43 /// Initializes a new instance of the InputField class.
45 /// <since_tizen> 6 </since_tizen>
46 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
47 [EditorBrowsable(EditorBrowsableState.Never)]
48 public InputField() : base()
53 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
54 [EditorBrowsable(EditorBrowsableState.Never)]
55 public InputField(string style) : base(style)
61 /// Initializes a new instance of the InputField class.
63 /// <param name="attributes">Create Header by attributes customized by user.</param>
64 /// <since_tizen> 6 </since_tizen>
65 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
66 [EditorBrowsable(EditorBrowsableState.Never)]
67 public InputField(InputFieldStyle attributes) : base(attributes)
73 /// Gets or sets the property for the enabled state.
75 /// <since_tizen> 6 </since_tizen>
76 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
77 [EditorBrowsable(EditorBrowsableState.Never)]
78 public bool StateEnabled
91 /// Gets or sets the property for the text content.
93 /// <since_tizen> 6 </since_tizen>
94 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
95 [EditorBrowsable(EditorBrowsableState.Never)]
100 return textField?.Text;
104 if (null != textField) textField.Text = value;
109 /// Gets or sets the property for the hint text.
111 /// <since_tizen> 6 </since_tizen>
112 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
113 [EditorBrowsable(EditorBrowsableState.Never)]
114 public string HintText
118 return textField?.PlaceholderText;
122 if (null != textField) textField.PlaceholderText = value;
127 /// Gets or sets the property for the color of the input text.
129 /// <since_tizen> 6 </since_tizen>
130 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
131 [EditorBrowsable(EditorBrowsableState.Never)]
132 public Color TextColor
136 return textField?.TextColor;
140 CreateTextFieldAttributes();
141 if (null != inputFieldAttrs?.InputBoxAttributes)
143 inputFieldAttrs.InputBoxAttributes.TextColor = value;
144 if (null != textField) textField.TextColor = value;
150 /// Gets or sets text color.
152 /// <since_tizen> 6 </since_tizen>
153 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
154 [EditorBrowsable(EditorBrowsableState.Never)]
155 public Color HintTextColor
159 return textField?.PlaceholderTextColor;
163 CreateTextFieldAttributes();
164 if (null != inputFieldAttrs?.InputBoxAttributes && null != value)
166 Vector4 color = new Vector4(value.R, value.G, value.B, value.A);
167 inputFieldAttrs.InputBoxAttributes.PlaceholderTextColor = color;
168 if (null != textField) textField.PlaceholderTextColor = color;
174 /// Gets or sets primary cursor color.
176 /// <since_tizen> 6 </since_tizen>
177 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
178 [EditorBrowsable(EditorBrowsableState.Never)]
179 public Color PrimaryCursorColor
183 return textField?.PrimaryCursorColor;
187 CreateTextFieldAttributes();
188 if (null != inputFieldAttrs?.InputBoxAttributes && null != value)
190 Vector4 color = new Vector4(value.R, value.G, value.B, value.A);
191 inputFieldAttrs.InputBoxAttributes.PrimaryCursorColor = color;
192 if (null != textField) textField.PrimaryCursorColor = color;
198 /// Gets or sets font family of text.
200 /// <since_tizen> 6 </since_tizen>
201 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
202 [EditorBrowsable(EditorBrowsableState.Never)]
203 public string FontFamily
207 return textField?.FontFamily;
211 CreateTextFieldAttributes();
212 if (null != inputFieldAttrs?.InputBoxAttributes)
214 inputFieldAttrs.InputBoxAttributes.FontFamily = value;
215 if (null != textField) textField.FontFamily = value;
221 /// Gets or sets enable cursor blink.
223 /// <since_tizen> 6 </since_tizen>
224 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
225 [EditorBrowsable(EditorBrowsableState.Never)]
226 public bool EnableCursorBlink
230 return textField?.EnableCursorBlink ?? false;
234 CreateTextFieldAttributes();
235 if (null != inputFieldAttrs.InputBoxAttributes)
237 inputFieldAttrs.InputBoxAttributes.EnableCursorBlink = value;
238 if (null != textField) textField.EnableCursorBlink = value;
244 /// Gets or sets enable selection.
246 /// <since_tizen> 6 </since_tizen>
247 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
248 [EditorBrowsable(EditorBrowsableState.Never)]
249 public bool EnableSelection
253 return textField?.EnableSelection ?? false;
257 CreateTextFieldAttributes();
258 if (null != inputFieldAttrs?.InputBoxAttributes)
260 inputFieldAttrs.InputBoxAttributes.EnableSelection = value;
261 if (null != textField) textField.EnableSelection = value;
267 /// Gets or sets cursor width.
269 /// <since_tizen> 6 </since_tizen>
270 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
271 [EditorBrowsable(EditorBrowsableState.Never)]
272 public int CursorWidth
276 return textField?.CursorWidth ?? 0;
280 CreateTextFieldAttributes();
281 if (null != inputFieldAttrs.InputBoxAttributes)
283 inputFieldAttrs.InputBoxAttributes.CursorWidth = value;
284 if (null != textField) textField.CursorWidth = value;
290 /// Gets or sets if enable ellipsis.
292 /// <since_tizen> 6 </since_tizen>
293 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
294 [EditorBrowsable(EditorBrowsableState.Never)]
295 public bool EnableEllipsis
299 return textField?.Ellipsis ?? false;
303 CreateTextFieldAttributes();
304 if (null != inputFieldAttrs.InputBoxAttributes)
306 inputFieldAttrs.InputBoxAttributes.Ellipsis = value;
307 if (null != textField) textField.Ellipsis = value;
313 /// Gets or sets background image's resource url of input field.
315 /// <since_tizen> 6 </since_tizen>
316 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
317 [EditorBrowsable(EditorBrowsableState.Never)]
318 public string BackgroundImageURL
322 return inputFieldAttrs?.BackgroundImageAttributes?.ResourceUrl?.All;
326 CreateBackgroundAttributes();
327 if (null != inputFieldAttrs?.BackgroundImageAttributes)
329 inputFieldAttrs.BackgroundImageAttributes.ResourceUrl = value;
336 /// Background image's border in Button.
338 /// <since_tizen> 6 </since_tizen>
339 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
340 [EditorBrowsable(EditorBrowsableState.Never)]
341 public new Rectangle BackgroundImageBorder
345 return inputFieldAttrs?.BackgroundImageAttributes?.Border?.All;
349 CreateBackgroundAttributes();
350 if (null != inputFieldAttrs?.BackgroundImageAttributes)
352 inputFieldAttrs.BackgroundImageAttributes.Border = value;
359 /// Gets and Sets Space.
365 return inputFieldAttrs?.Space ?? 0;
369 if (null != inputFieldAttrs)
371 inputFieldAttrs.Space = value;
377 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
378 [EditorBrowsable(EditorBrowsableState.Never)]
379 public override void ApplyStyle(ViewStyle viewStyle)
381 base.ApplyStyle(viewStyle);
383 InputFieldStyle inputFieldStyle = viewStyle as InputFieldStyle;
385 if (null != inputFieldStyle.BackgroundImageAttributes)
389 bgImage = new ImageView()
391 WidthResizePolicy = ResizePolicyType.FillToParent,
392 HeightResizePolicy = ResizePolicyType.FillToParent,
397 bgImage.ApplyStyle(inputFieldStyle.BackgroundImageAttributes);
399 if (null != inputFieldStyle.InputBoxAttributes)
401 if (null == textField)
403 textField = new TextField()
405 WidthResizePolicy = ResizePolicyType.Fixed,
406 HeightResizePolicy = ResizePolicyType.Fixed,
407 ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft,
408 PivotPoint = Tizen.NUI.PivotPoint.CenterLeft,
409 PositionUsesPivotPoint = true,
412 textField.FocusGained += OnTextFieldFocusGained;
413 textField.FocusLost += OnTextFieldFocusLost;
414 textField.TextChanged += OnTextFieldTextChanged;
415 textField.KeyEvent += OnTextFieldKeyEvent;
417 textField.ApplyStyle(inputFieldStyle.InputBoxAttributes);
422 /// Get Input Field attribues.
424 /// <since_tizen> 6 </since_tizen>
425 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
426 [EditorBrowsable(EditorBrowsableState.Never)]
427 protected override ViewStyle GetViewStyle()
429 return new InputFieldStyle();
433 /// Dispose Input Field and all children on it.
435 /// <param name="type">Dispose type.</param>
436 /// <since_tizen> 6 </since_tizen>
437 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
438 [EditorBrowsable(EditorBrowsableState.Never)]
439 protected override void Dispose(DisposeTypes type)
445 if (type == DisposeTypes.Explicit)
449 this.Remove(bgImage);
453 if (null != textField)
455 textField.FocusGained -= OnTextFieldFocusGained;
456 textField.FocusLost -= OnTextFieldFocusLost;
457 textField.TextChanged -= OnTextFieldTextChanged;
458 textField.KeyEvent -= OnTextFieldKeyEvent;
459 this.Remove(textField);
469 /// Update Input Field by attributes.
471 /// <since_tizen> 6 </since_tizen>
472 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
473 [EditorBrowsable(EditorBrowsableState.Never)]
474 protected override void OnUpdate()
477 OnLayoutDirectionChanged();
481 /// Theme change callback when theme is changed, this callback will be trigger.
483 /// <since_tizen> 6 </since_tizen>
484 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
485 [EditorBrowsable(EditorBrowsableState.Never)]
486 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
488 InputFieldStyle tempStyle = StyleManager.Instance.GetViewStyle(style) as InputFieldStyle;
489 if (tempStyle != null)
491 Style.CopyFrom(tempStyle);
497 /// Theme change callback when text field focus is gained, this callback will be trigger.
499 /// <since_tizen> 6 </since_tizen>
500 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
501 [EditorBrowsable(EditorBrowsableState.Never)]
502 protected virtual void OnTextFieldFocusGained(object source, EventArgs e)
507 /// Theme change callback when text field is lost, this callback will be trigger.
509 /// <since_tizen> 6 </since_tizen>
510 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
511 [EditorBrowsable(EditorBrowsableState.Never)]
512 protected virtual void OnTextFieldFocusLost(object source, EventArgs e)
517 /// Theme change callback when text field's text is changed, this callback will be trigger.
519 /// <since_tizen> 6 </since_tizen>
520 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
521 [EditorBrowsable(EditorBrowsableState.Never)]
522 protected virtual void OnTextFieldTextChanged(object sender, TextField.TextChangedEventArgs e)
527 /// Theme change callback when text field have a key event, this callback will be trigger.
529 /// <since_tizen> 6 </since_tizen>
530 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
531 [EditorBrowsable(EditorBrowsableState.Never)]
532 protected virtual bool OnTextFieldKeyEvent(object source, KeyEventArgs e)
538 /// Set the text field 2D size
540 /// <param name="w">Input Field' width.</param>
541 /// <param name="h">Input Field' height.</param>
542 /// <since_tizen> 6 </since_tizen>
543 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
544 [EditorBrowsable(EditorBrowsableState.Never)]
545 protected void SetTextFieldSize2D(int w, int h)
547 if (textField != null)
549 textField.Size2D = new Size2D(w, h);
554 /// Set the text field X pose
556 /// <param name="x">Input Field' X.</param>
557 /// <since_tizen> 6 </since_tizen>
558 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
559 [EditorBrowsable(EditorBrowsableState.Never)]
560 protected void SetTextFieldPosX(int x)
562 if (textField != null)
564 textField.PositionX = x;
569 /// Set the text field text color
571 /// <param name="color">Input Field' color.</param>
572 /// <since_tizen> 6 </since_tizen>
573 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
574 [EditorBrowsable(EditorBrowsableState.Never)]
575 protected void SetTextFieldTextColor(Color color)
577 if (textField != null)
579 textField.TextColor = color;
584 /// Set the text field relayout flag
586 /// <param name="value">relayout text field' value.</param>
587 /// <since_tizen> 6 </since_tizen>
588 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
589 [EditorBrowsable(EditorBrowsableState.Never)]
590 protected void RelayoutTextField(bool value)
592 relayoutTextField = value;
595 private void Initialize()
597 inputFieldAttrs = Style as InputFieldStyle;
598 if (null == inputFieldAttrs)
600 throw new Exception("Fail to get the InputField attributes.");
605 bgImage = new ImageView()
607 WidthResizePolicy = ResizePolicyType.FillToParent,
608 HeightResizePolicy = ResizePolicyType.FillToParent,
613 if (null == textField)
615 textField = new TextField()
617 WidthResizePolicy = ResizePolicyType.Fixed,
618 HeightResizePolicy = ResizePolicyType.Fixed,
619 ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft,
620 PivotPoint = Tizen.NUI.PivotPoint.CenterLeft,
621 PositionUsesPivotPoint = true,
624 textField.FocusGained += OnTextFieldFocusGained;
625 textField.FocusLost += OnTextFieldFocusLost;
626 textField.TextChanged += OnTextFieldTextChanged;
627 textField.KeyEvent += OnTextFieldKeyEvent;
631 private void OnLayoutDirectionChanged()
633 if (inputFieldAttrs == null) return;
634 if (textField != null)
636 if (LayoutDirection == ViewLayoutDirectionType.LTR)
638 if(inputFieldAttrs.InputBoxAttributes != null)
640 inputFieldAttrs.InputBoxAttributes.HorizontalAlignment = HorizontalAlignment.Begin;
641 inputFieldAttrs.InputBoxAttributes.ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft;
642 inputFieldAttrs.InputBoxAttributes.PivotPoint = Tizen.NUI.PivotPoint.CenterLeft;
643 inputFieldAttrs.InputBoxAttributes.PositionUsesPivotPoint = true;
645 textField.HorizontalAlignment = HorizontalAlignment.Begin;
646 textField.ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft;
647 textField.PivotPoint = Tizen.NUI.PivotPoint.CenterLeft;
648 textField.PositionUsesPivotPoint = true;
650 else //ViewLayoutDirectionType.RTL
652 if (inputFieldAttrs.InputBoxAttributes != null)
654 inputFieldAttrs.InputBoxAttributes.HorizontalAlignment = HorizontalAlignment.End;
655 inputFieldAttrs.InputBoxAttributes.ParentOrigin = Tizen.NUI.ParentOrigin.CenterRight;
656 inputFieldAttrs.InputBoxAttributes.PivotPoint = Tizen.NUI.PivotPoint.CenterRight;
658 textField.HorizontalAlignment = HorizontalAlignment.End;
659 textField.ParentOrigin = Tizen.NUI.ParentOrigin.CenterRight;
660 textField.PivotPoint = Tizen.NUI.PivotPoint.CenterRight;
661 textField.PositionUsesPivotPoint = true;
666 private void RelayoutComponent()
668 if (!relayoutTextField)
672 int space = inputFieldAttrs.Space ?? 0;
674 if (textField != null)
676 textField.Size2D = new Size2D(this.Size2D.Width - space * 2, this.Size2D.Height);
677 textField.PositionX = space;
681 private void CreateBackgroundAttributes()
683 if (null == inputFieldAttrs.BackgroundImageAttributes)
685 inputFieldAttrs.BackgroundImageAttributes = new ImageViewStyle();
689 private void CreateTextFieldAttributes()
691 if (null == inputFieldAttrs.InputBoxAttributes)
693 inputFieldAttrs.InputBoxAttributes = new TextFieldStyle();