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;
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(InputFieldStyle 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 Selector<Color>();
143 if (null != inputFieldAttrs.InputBoxAttributes.TextColor)
145 inputFieldAttrs.InputBoxAttributes.TextColor.All = value;
147 textField.TextColor = value;
152 /// Gets or sets text color.
154 /// <since_tizen> 6 </since_tizen>
155 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
156 [EditorBrowsable(EditorBrowsableState.Never)]
157 public Color HintTextColor
161 return textField.PlaceholderTextColor;
165 CreateTextFieldAttributes();
166 if (null == inputFieldAttrs.InputBoxAttributes.PlaceholderTextColor)
168 inputFieldAttrs.InputBoxAttributes.PlaceholderTextColor = new Selector<Color>();
170 if (null != inputFieldAttrs.InputBoxAttributes.PlaceholderTextColor)
172 inputFieldAttrs.InputBoxAttributes.PlaceholderTextColor.All = value;
174 textField.PlaceholderTextColor = value;
179 /// Gets or sets primary cursor color.
181 /// <since_tizen> 6 </since_tizen>
182 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
183 [EditorBrowsable(EditorBrowsableState.Never)]
184 public Color PrimaryCursorColor
188 return textField.PrimaryCursorColor;
192 CreateTextFieldAttributes();
193 if (null == inputFieldAttrs.InputBoxAttributes.PrimaryCursorColor)
195 inputFieldAttrs.InputBoxAttributes.PrimaryCursorColor = new Selector<Color>();
197 if (null != inputFieldAttrs.InputBoxAttributes.PrimaryCursorColor)
199 inputFieldAttrs.InputBoxAttributes.PrimaryCursorColor.All = value;
201 textField.PrimaryCursorColor = value;
206 /// Gets or sets font family of text.
208 /// <since_tizen> 6 </since_tizen>
209 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
210 [EditorBrowsable(EditorBrowsableState.Never)]
211 public string FontFamily
215 return textField.FontFamily;
219 CreateTextFieldAttributes();
220 inputFieldAttrs.InputBoxAttributes.FontFamily = value;
221 textField.FontFamily = value;
226 /// Gets or sets enable cursor blink.
228 /// <since_tizen> 6 </since_tizen>
229 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
230 [EditorBrowsable(EditorBrowsableState.Never)]
231 public bool EnableCursorBlink
235 return textField.EnableCursorBlink;
239 CreateTextFieldAttributes();
240 inputFieldAttrs.InputBoxAttributes.EnableCursorBlink = value;
241 textField.EnableCursorBlink = value;
246 /// Gets or sets enable selection.
248 /// <since_tizen> 6 </since_tizen>
249 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
250 [EditorBrowsable(EditorBrowsableState.Never)]
251 public bool EnableSelection
255 return textField.EnableSelection;
259 CreateTextFieldAttributes();
260 inputFieldAttrs.InputBoxAttributes.EnableSelection = value;
261 textField.EnableSelection = value;
266 /// Gets or sets cursor width.
268 /// <since_tizen> 6 </since_tizen>
269 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
270 [EditorBrowsable(EditorBrowsableState.Never)]
271 public int CursorWidth
275 return textField.CursorWidth;
279 CreateTextFieldAttributes();
280 inputFieldAttrs.InputBoxAttributes.CursorWidth = value;
281 textField.CursorWidth = value;
286 /// Gets or sets if enable ellipsis.
288 /// <since_tizen> 6 </since_tizen>
289 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
290 [EditorBrowsable(EditorBrowsableState.Never)]
291 public bool EnableEllipsis
295 return textField.Ellipsis;
299 CreateTextFieldAttributes();
300 inputFieldAttrs.InputBoxAttributes.Ellipsis = value;
301 textField.Ellipsis = value;
306 /// Gets or sets background image's resource url of input field.
308 /// <since_tizen> 6 </since_tizen>
309 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
310 [EditorBrowsable(EditorBrowsableState.Never)]
311 public string BackgroundImageURL
315 return inputFieldAttrs.BackgroundImageAttributes?.ResourceUrl?.All;
321 CreateBackgroundAttributes();
322 if (inputFieldAttrs.BackgroundImageAttributes.ResourceUrl == null)
324 inputFieldAttrs.BackgroundImageAttributes.ResourceUrl = new Selector<string>();
326 if (inputFieldAttrs.BackgroundImageAttributes.ResourceUrl != null)
328 inputFieldAttrs.BackgroundImageAttributes.ResourceUrl.All = 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 Rectangle BackgroundImageBorder
345 return inputFieldAttrs.BackgroundImageAttributes?.Border?.All;
351 CreateBackgroundAttributes();
352 if (inputFieldAttrs.BackgroundImageAttributes.Border == null)
354 inputFieldAttrs.BackgroundImageAttributes.Border = new Selector<Rectangle>();
356 if (inputFieldAttrs.BackgroundImageAttributes.Border != null)
358 inputFieldAttrs.BackgroundImageAttributes.Border.All = value;
366 /// Gets and Sets Space.
372 return inputFieldAttrs.Space ?? 0;
376 inputFieldAttrs.Space = value;
382 /// Get Input Field attribues.
384 /// <since_tizen> 6 </since_tizen>
385 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
386 [EditorBrowsable(EditorBrowsableState.Never)]
387 protected override ViewStyle GetViewStyle()
389 return new InputFieldStyle();
393 /// Dispose Input Field and all children on it.
395 /// <param name="type">Dispose type.</param>
396 /// <since_tizen> 6 </since_tizen>
397 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
398 [EditorBrowsable(EditorBrowsableState.Never)]
399 protected override void Dispose(DisposeTypes type)
405 if (type == DisposeTypes.Explicit)
409 this.Remove(bgImage);
413 if (null != textField)
415 textField.FocusGained -= OnTextFieldFocusGained;
416 textField.FocusLost -= OnTextFieldFocusLost;
417 textField.TextChanged -= OnTextFieldTextChanged;
418 textField.KeyEvent -= OnTextFieldKeyEvent;
419 this.Remove(textField);
429 /// Update Input Field by attributes.
431 /// <since_tizen> 6 </since_tizen>
432 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
433 [EditorBrowsable(EditorBrowsableState.Never)]
434 protected override void OnUpdate()
437 OnLayoutDirectionChanged();
441 /// Theme change callback when theme is changed, this callback will be trigger.
443 /// <since_tizen> 6 </since_tizen>
444 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
445 [EditorBrowsable(EditorBrowsableState.Never)]
446 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
448 InputFieldStyle tempStyle = StyleManager.Instance.GetAttributes(style) as InputFieldStyle;
449 if (tempStyle != null)
451 Style.CopyFrom(tempStyle);
457 /// Theme change callback when text field focus is gained, this callback will be trigger.
459 /// <since_tizen> 6 </since_tizen>
460 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
461 [EditorBrowsable(EditorBrowsableState.Never)]
462 protected virtual void OnTextFieldFocusGained(object source, EventArgs e)
467 /// Theme change callback when text field is lost, this callback will be trigger.
469 /// <since_tizen> 6 </since_tizen>
470 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
471 [EditorBrowsable(EditorBrowsableState.Never)]
472 protected virtual void OnTextFieldFocusLost(object source, EventArgs e)
477 /// Theme change callback when text field's text 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 virtual void OnTextFieldTextChanged(object sender, TextField.TextChangedEventArgs e)
487 /// Theme change callback when text field have a key event, this callback will be trigger.
489 /// <since_tizen> 6 </since_tizen>
490 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
491 [EditorBrowsable(EditorBrowsableState.Never)]
492 protected virtual bool OnTextFieldKeyEvent(object source, KeyEventArgs e)
498 /// Set the text field 2D size
500 /// <param name="w">Input Field' width.</param>
501 /// <param name="h">Input Field' height.</param>
502 /// <since_tizen> 6 </since_tizen>
503 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
504 [EditorBrowsable(EditorBrowsableState.Never)]
505 protected void SetTextFieldSize2D(int w, int h)
507 if (textField != null)
509 textField.Size2D = new Size2D(w, h);
514 /// Set the text field X pose
516 /// <param name="x">Input Field' X.</param>
517 /// <since_tizen> 6 </since_tizen>
518 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
519 [EditorBrowsable(EditorBrowsableState.Never)]
520 protected void SetTextFieldPosX(int x)
522 if (textField != null)
524 textField.PositionX = x;
529 /// Set the text field text color
531 /// <param name="color">Input Field' color.</param>
532 /// <since_tizen> 6 </since_tizen>
533 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
534 [EditorBrowsable(EditorBrowsableState.Never)]
535 protected void SetTextFieldTextColor(Color color)
537 if (textField != null)
539 textField.TextColor = color;
544 /// Set the text field relayout flag
546 /// <param name="value">relayout text field' value.</param>
547 /// <since_tizen> 6 </since_tizen>
548 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
549 [EditorBrowsable(EditorBrowsableState.Never)]
550 protected void RelayoutTextField(bool value)
552 relayoutTextField = value;
555 private void Initialize()
557 inputFieldAttrs = Style as InputFieldStyle;
558 if (null == inputFieldAttrs)
560 throw new Exception("Fail to get the InputField attributes.");
563 bgImage = new ImageView();
566 throw new Exception("Fail to create background image.");
569 textField = new TextField();
570 if (null == textField)
572 throw new Exception("Fail to create text field.");
575 if (null != inputFieldAttrs.BackgroundImageAttributes)
577 bgImage.WidthResizePolicy = ResizePolicyType.FillToParent;
578 bgImage.HeightResizePolicy = ResizePolicyType.FillToParent;
579 bgImage.ParentOrigin = Tizen.NUI.ParentOrigin.Center;
580 bgImage.PivotPoint = Tizen.NUI.PivotPoint.Center;
581 bgImage.PositionUsesPivotPoint = true;
585 if (null != inputFieldAttrs.InputBoxAttributes)
587 textField.WidthResizePolicy = ResizePolicyType.Fixed;
588 textField.HeightResizePolicy = ResizePolicyType.Fixed;
589 textField.ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft;
590 textField.PivotPoint = Tizen.NUI.PivotPoint.CenterLeft;
591 textField.PositionUsesPivotPoint = true;
594 textField.FocusGained += OnTextFieldFocusGained;
595 textField.FocusLost += OnTextFieldFocusLost;
596 textField.TextChanged += OnTextFieldTextChanged;
597 textField.KeyEvent += OnTextFieldKeyEvent;
601 private void OnLayoutDirectionChanged()
603 if (inputFieldAttrs == null) return;
604 if (textField != null)
606 if (LayoutDirection == ViewLayoutDirectionType.LTR)
608 if(inputFieldAttrs.InputBoxAttributes != null)
610 inputFieldAttrs.InputBoxAttributes.HorizontalAlignment = HorizontalAlignment.Begin;
611 inputFieldAttrs.InputBoxAttributes.ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft;
612 inputFieldAttrs.InputBoxAttributes.PivotPoint = Tizen.NUI.PivotPoint.CenterLeft;
613 inputFieldAttrs.InputBoxAttributes.PositionUsesPivotPoint = true;
615 textField.HorizontalAlignment = HorizontalAlignment.Begin;
616 textField.ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft;
617 textField.PivotPoint = Tizen.NUI.PivotPoint.CenterLeft;
618 textField.PositionUsesPivotPoint = true;
620 else //ViewLayoutDirectionType.RTL
622 if (inputFieldAttrs.InputBoxAttributes != null)
624 inputFieldAttrs.InputBoxAttributes.HorizontalAlignment = HorizontalAlignment.End;
625 inputFieldAttrs.InputBoxAttributes.ParentOrigin = Tizen.NUI.ParentOrigin.CenterRight;
626 inputFieldAttrs.InputBoxAttributes.PivotPoint = Tizen.NUI.PivotPoint.CenterRight;
628 textField.HorizontalAlignment = HorizontalAlignment.End;
629 textField.ParentOrigin = Tizen.NUI.ParentOrigin.CenterRight;
630 textField.PivotPoint = Tizen.NUI.PivotPoint.CenterRight;
631 textField.PositionUsesPivotPoint = true;
636 private void RelayoutComponent()
638 if (!relayoutTextField)
642 int space = inputFieldAttrs.Space ?? 0;
644 if (textField != null)
646 textField.Size2D = new Size2D(this.Size2D.Width - space * 2, this.Size2D.Height);
647 textField.PositionX = space;
651 private void CreateBackgroundAttributes()
653 if (null == inputFieldAttrs.BackgroundImageAttributes)
655 inputFieldAttrs.BackgroundImageAttributes = new ImageViewStyle();
659 private void CreateTextFieldAttributes()
661 if (null == inputFieldAttrs.InputBoxAttributes)
663 inputFieldAttrs.InputBoxAttributes = new TextFieldStyle();