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.CommonUI
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 InputFieldAttributes inputFieldAttrs = null;
37 // the flag indicate should relayout the textField in base class
38 private bool relayoutTextField = true;
41 /// Initializes a new instance of the InputField class.
43 /// <since_tizen> 6 </since_tizen>
44 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
45 [EditorBrowsable(EditorBrowsableState.Never)]
46 public InputField() : base()
51 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
52 [EditorBrowsable(EditorBrowsableState.Never)]
53 public InputField(string style) : base(style)
59 /// Initializes a new instance of the InputField class.
61 /// <param name="attributes">Create Header by attributes customized by user.</param>
62 /// <since_tizen> 6 </since_tizen>
63 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
64 [EditorBrowsable(EditorBrowsableState.Never)]
65 public InputField(InputFieldAttributes attributes) : base(attributes)
71 /// Gets or sets the property for the enabled state.
73 /// <since_tizen> 6 </since_tizen>
74 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
75 [EditorBrowsable(EditorBrowsableState.Never)]
76 public bool StateEnabled
89 /// Gets or sets the property for the text content.
91 /// <since_tizen> 6 </since_tizen>
92 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
93 [EditorBrowsable(EditorBrowsableState.Never)]
98 return textField.Text;
102 textField.Text = value;
107 /// Gets or sets the property for the hint text.
109 /// <since_tizen> 6 </since_tizen>
110 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
111 [EditorBrowsable(EditorBrowsableState.Never)]
112 public string HintText
116 return textField.PlaceholderText;
120 textField.PlaceholderText = value;
125 /// Gets or sets the property for the color of the input text.
127 /// <since_tizen> 6 </since_tizen>
128 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
129 [EditorBrowsable(EditorBrowsableState.Never)]
130 public Color TextColor
134 return textField.TextColor;
138 CreateTextFieldAttributes();
139 if (null == inputFieldAttrs.InputBoxAttributes.TextColor)
141 inputFieldAttrs.InputBoxAttributes.TextColor = new ColorSelector();
143 inputFieldAttrs.InputBoxAttributes.TextColor.All = value;
144 textField.TextColor = value;
149 /// Gets or sets text color.
151 /// <since_tizen> 6 </since_tizen>
152 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
153 [EditorBrowsable(EditorBrowsableState.Never)]
154 public Color HintTextColor
158 return textField.PlaceholderTextColor;
162 CreateTextFieldAttributes();
163 if (null == inputFieldAttrs.InputBoxAttributes.PlaceholderTextColor)
165 inputFieldAttrs.InputBoxAttributes.PlaceholderTextColor = new ColorSelector();
167 inputFieldAttrs.InputBoxAttributes.PlaceholderTextColor.All = value;
168 textField.PlaceholderTextColor = value;
173 /// Gets or sets primary cursor color.
175 /// <since_tizen> 6 </since_tizen>
176 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
177 [EditorBrowsable(EditorBrowsableState.Never)]
178 public Color PrimaryCursorColor
182 return textField.PrimaryCursorColor;
186 CreateTextFieldAttributes();
187 if (null == inputFieldAttrs.InputBoxAttributes.PrimaryCursorColor)
189 inputFieldAttrs.InputBoxAttributes.PrimaryCursorColor = new ColorSelector();
191 inputFieldAttrs.InputBoxAttributes.PrimaryCursorColor.All = value;
192 textField.PrimaryCursorColor = value;
197 /// Gets or sets secondary cursor color.
199 /// <since_tizen> 6 </since_tizen>
200 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
201 [EditorBrowsable(EditorBrowsableState.Never)]
202 public Color SecondaryCursorColor
206 return textField.SecondaryCursorColor;
210 CreateTextFieldAttributes();
211 if (null == inputFieldAttrs.InputBoxAttributes.SecondaryCursorColor)
213 inputFieldAttrs.InputBoxAttributes.SecondaryCursorColor = new ColorSelector();
215 inputFieldAttrs.InputBoxAttributes.SecondaryCursorColor.All = value;
216 textField.SecondaryCursorColor = value;
221 /// Gets or sets font family of text.
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 string FontFamily
230 return textField.FontFamily;
234 CreateTextFieldAttributes();
235 inputFieldAttrs.InputBoxAttributes.FontFamily = value;
236 textField.FontFamily = value;
241 /// Gets or sets point size of text.
243 /// <since_tizen> 6 </since_tizen>
244 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
245 [EditorBrowsable(EditorBrowsableState.Never)]
246 public float PointSize
250 return textField.PointSize;
254 CreateTextFieldAttributes();
255 if (null == inputFieldAttrs.InputBoxAttributes.PointSize)
257 inputFieldAttrs.InputBoxAttributes.PointSize = new FloatSelector();
259 inputFieldAttrs.InputBoxAttributes.PointSize.All = value;
260 textField.PointSize = value;
265 /// Gets or sets enable cursor blink.
267 /// <since_tizen> 6 </since_tizen>
268 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
269 [EditorBrowsable(EditorBrowsableState.Never)]
270 public bool EnableCursorBlink
274 return textField.EnableCursorBlink;
278 CreateTextFieldAttributes();
279 inputFieldAttrs.InputBoxAttributes.EnableCursorBlink = value;
280 textField.EnableCursorBlink = value;
285 /// Gets or sets enable selection.
287 /// <since_tizen> 6 </since_tizen>
288 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
289 [EditorBrowsable(EditorBrowsableState.Never)]
290 public bool EnableSelection
294 return textField.EnableSelection;
298 CreateTextFieldAttributes();
299 inputFieldAttrs.InputBoxAttributes.EnableSelection = value;
300 textField.EnableSelection = value;
305 /// Gets or sets cursor width.
307 /// <since_tizen> 6 </since_tizen>
308 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
309 [EditorBrowsable(EditorBrowsableState.Never)]
310 public int CursorWidth
314 return textField.CursorWidth;
318 CreateTextFieldAttributes();
319 inputFieldAttrs.InputBoxAttributes.CursorWidth = value;
320 textField.CursorWidth = value;
325 /// Gets or sets if enable ellipsis.
327 /// <since_tizen> 6 </since_tizen>
328 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
329 [EditorBrowsable(EditorBrowsableState.Never)]
330 public bool EnableEllipsis
334 return textField.Ellipsis;
338 CreateTextFieldAttributes();
339 inputFieldAttrs.InputBoxAttributes.EnableEllipsis = value;
340 textField.Ellipsis = value;
345 /// Gets or sets background image's resource url of input field.
347 /// <since_tizen> 6 </since_tizen>
348 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
349 [EditorBrowsable(EditorBrowsableState.Never)]
350 public string BackgroundImageURL
354 return inputFieldAttrs.BackgroundImageAttributes?.ResourceURL?.All;
360 CreateBackgroundAttributes();
361 if (inputFieldAttrs.BackgroundImageAttributes.ResourceURL == null)
363 inputFieldAttrs.BackgroundImageAttributes.ResourceURL = new StringSelector();
365 inputFieldAttrs.BackgroundImageAttributes.ResourceURL.All = value;
372 /// Background image's border in Button.
374 /// <since_tizen> 6 </since_tizen>
375 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
376 [EditorBrowsable(EditorBrowsableState.Never)]
377 public Rectangle BackgroundImageBorder
381 return inputFieldAttrs.BackgroundImageAttributes?.Border?.All;
387 CreateBackgroundAttributes();
388 if (inputFieldAttrs.BackgroundImageAttributes.Border == null)
390 inputFieldAttrs.BackgroundImageAttributes.Border = new RectangleSelector();
392 inputFieldAttrs.BackgroundImageAttributes.Border.All = value;
399 /// Gets and Sets Space.
405 return inputFieldAttrs.Space ?? 0;
409 inputFieldAttrs.Space = value;
415 /// Get Input Field attribues.
417 /// <since_tizen> 6 </since_tizen>
418 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
419 [EditorBrowsable(EditorBrowsableState.Never)]
420 protected override Attributes GetAttributes()
422 return new InputFieldAttributes();
426 /// Dispose Input Field and all children on it.
428 /// <param name="type">Dispose type.</param>
429 /// <since_tizen> 6 </since_tizen>
430 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
431 [EditorBrowsable(EditorBrowsableState.Never)]
432 protected override void Dispose(DisposeTypes type)
438 if (type == DisposeTypes.Explicit)
442 this.Remove(bgImage);
446 if (null != textField)
448 textField.FocusGained -= OnTextFieldFocusGained;
449 textField.FocusLost -= OnTextFieldFocusLost;
450 textField.TextChanged -= OnTextFieldTextChanged;
451 textField.KeyEvent -= OnTextFieldKeyEvent;
452 this.Remove(textField);
462 /// Update Input Field by attributes.
464 /// <since_tizen> 6 </since_tizen>
465 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
466 [EditorBrowsable(EditorBrowsableState.Never)]
467 protected override void OnUpdate()
469 ApplyAttributes(this, inputFieldAttrs);
470 ApplyAttributes(bgImage, inputFieldAttrs.BackgroundImageAttributes);
471 ApplyAttributes(textField, inputFieldAttrs.InputBoxAttributes);
473 OnLayoutDirectionChanged();
477 /// Theme change callback when theme is changed, this callback will be trigger.
479 /// <since_tizen> 6 </since_tizen>
480 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
481 [EditorBrowsable(EditorBrowsableState.Never)]
482 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
484 InputFieldAttributes tempAttributes = StyleManager.Instance.GetAttributes(style) as InputFieldAttributes;
485 if (tempAttributes != null)
487 attributes = inputFieldAttrs = tempAttributes;
493 /// Theme change callback when text field focus is gained, this callback will be trigger.
495 /// <since_tizen> 6 </since_tizen>
496 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
497 [EditorBrowsable(EditorBrowsableState.Never)]
498 protected virtual void OnTextFieldFocusGained(object source, EventArgs e)
503 /// Theme change callback when text field is lost, this callback will be trigger.
505 /// <since_tizen> 6 </since_tizen>
506 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
507 [EditorBrowsable(EditorBrowsableState.Never)]
508 protected virtual void OnTextFieldFocusLost(object source, EventArgs e)
513 /// Theme change callback when text field's text is changed, this callback will be trigger.
515 /// <since_tizen> 6 </since_tizen>
516 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
517 [EditorBrowsable(EditorBrowsableState.Never)]
518 protected virtual void OnTextFieldTextChanged(object sender, TextField.TextChangedEventArgs e)
523 /// Theme change callback when text field have a key event, this callback will be trigger.
525 /// <since_tizen> 6 </since_tizen>
526 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
527 [EditorBrowsable(EditorBrowsableState.Never)]
528 protected virtual bool OnTextFieldKeyEvent(object source, KeyEventArgs e)
534 /// Set the text field 2D size
536 /// <param name="w">Input Field' width.</param>
537 /// <param name="h">Input Field' height.</param>
538 /// <since_tizen> 6 </since_tizen>
539 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
540 [EditorBrowsable(EditorBrowsableState.Never)]
541 protected void SetTextFieldSize2D(int w, int h)
543 if (textField != null)
545 textField.Size2D = new Size2D(w, h);
550 /// Set the text field X pose
552 /// <param name="x">Input Field' X.</param>
553 /// <since_tizen> 6 </since_tizen>
554 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
555 [EditorBrowsable(EditorBrowsableState.Never)]
556 protected void SetTextFieldPosX(int x)
558 if (textField != null)
560 textField.PositionX = x;
565 /// Set the text field text color
567 /// <param name="color">Input Field' color.</param>
568 /// <since_tizen> 6 </since_tizen>
569 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
570 [EditorBrowsable(EditorBrowsableState.Never)]
571 protected void SetTextFieldTextColor(Color color)
573 if (textField != null)
575 textField.TextColor = color;
580 /// Set the text field relayout flag
582 /// <param name="value">relayout text field' value.</param>
583 /// <since_tizen> 6 </since_tizen>
584 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
585 [EditorBrowsable(EditorBrowsableState.Never)]
586 protected void RelayoutTextField(bool value)
588 relayoutTextField = value;
591 private void Initialize()
593 inputFieldAttrs = attributes as InputFieldAttributes;
594 if (null == inputFieldAttrs)
596 throw new Exception("Fail to get the InputField attributes.");
599 bgImage = new ImageView();
602 throw new Exception("Fail to create background image.");
605 textField = new TextField();
606 if (null == textField)
608 throw new Exception("Fail to create text field.");
611 if (null != inputFieldAttrs.BackgroundImageAttributes)
613 bgImage.WidthResizePolicy = ResizePolicyType.FillToParent;
614 bgImage.HeightResizePolicy = ResizePolicyType.FillToParent;
615 bgImage.ParentOrigin = Tizen.NUI.ParentOrigin.Center;
616 bgImage.PivotPoint = Tizen.NUI.PivotPoint.Center;
617 bgImage.PositionUsesPivotPoint = true;
621 if (null != inputFieldAttrs.InputBoxAttributes)
623 textField.WidthResizePolicy = ResizePolicyType.Fixed;
624 textField.HeightResizePolicy = ResizePolicyType.Fixed;
625 textField.ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft;
626 textField.PivotPoint = Tizen.NUI.PivotPoint.CenterLeft;
627 textField.PositionUsesPivotPoint = true;
630 textField.FocusGained += OnTextFieldFocusGained;
631 textField.FocusLost += OnTextFieldFocusLost;
632 textField.TextChanged += OnTextFieldTextChanged;
633 textField.KeyEvent += OnTextFieldKeyEvent;
637 private void OnLayoutDirectionChanged()
639 if (inputFieldAttrs == null) return;
640 if (textField != null)
642 if (LayoutDirection == ViewLayoutDirectionType.LTR)
644 if(inputFieldAttrs.InputBoxAttributes != null)
646 inputFieldAttrs.InputBoxAttributes.HorizontalAlignment = HorizontalAlignment.Begin;
647 inputFieldAttrs.InputBoxAttributes.ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft;
648 inputFieldAttrs.InputBoxAttributes.PivotPoint = Tizen.NUI.PivotPoint.CenterLeft;
649 inputFieldAttrs.InputBoxAttributes.PositionUsesPivotPoint = true;
651 textField.HorizontalAlignment = HorizontalAlignment.Begin;
652 textField.ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft;
653 textField.PivotPoint = Tizen.NUI.PivotPoint.CenterLeft;
654 textField.PositionUsesPivotPoint = true;
656 else //ViewLayoutDirectionType.RTL
658 if (inputFieldAttrs.InputBoxAttributes != null)
660 inputFieldAttrs.InputBoxAttributes.HorizontalAlignment = HorizontalAlignment.End;
661 inputFieldAttrs.InputBoxAttributes.ParentOrigin = Tizen.NUI.ParentOrigin.CenterRight;
662 inputFieldAttrs.InputBoxAttributes.PivotPoint = Tizen.NUI.PivotPoint.CenterRight;
664 textField.HorizontalAlignment = HorizontalAlignment.End;
665 textField.ParentOrigin = Tizen.NUI.ParentOrigin.CenterRight;
666 textField.PivotPoint = Tizen.NUI.PivotPoint.CenterRight;
667 textField.PositionUsesPivotPoint = true;
672 private void RelayoutComponent()
674 if (!relayoutTextField)
678 int space = inputFieldAttrs.Space ?? 0;
680 if (textField != null)
682 textField.Size2D = new Size2D(this.Size2D.Width - space * 2, this.Size2D.Height);
683 textField.PositionX = space;
687 private void CreateBackgroundAttributes()
689 if (null == inputFieldAttrs.BackgroundImageAttributes)
691 inputFieldAttrs.BackgroundImageAttributes = new ImageAttributes();
695 private void CreateTextFieldAttributes()
697 if (null == inputFieldAttrs.InputBoxAttributes)
699 inputFieldAttrs.InputBoxAttributes = new TextFieldAttributes();