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 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 Selector<Color>();
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 Selector<Color>();
191 inputFieldAttrs.InputBoxAttributes.PrimaryCursorColor.All = value;
192 textField.PrimaryCursorColor = value;
197 /// Gets or sets font family of text.
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 string FontFamily
206 return textField.FontFamily;
210 CreateTextFieldAttributes();
211 inputFieldAttrs.InputBoxAttributes.FontFamily = value;
212 textField.FontFamily = value;
217 /// Gets or sets enable cursor blink.
219 /// <since_tizen> 6 </since_tizen>
220 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
221 [EditorBrowsable(EditorBrowsableState.Never)]
222 public bool EnableCursorBlink
226 return textField.EnableCursorBlink;
230 CreateTextFieldAttributes();
231 inputFieldAttrs.InputBoxAttributes.EnableCursorBlink = value;
232 textField.EnableCursorBlink = value;
237 /// Gets or sets enable selection.
239 /// <since_tizen> 6 </since_tizen>
240 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
241 [EditorBrowsable(EditorBrowsableState.Never)]
242 public bool EnableSelection
246 return textField.EnableSelection;
250 CreateTextFieldAttributes();
251 inputFieldAttrs.InputBoxAttributes.EnableSelection = value;
252 textField.EnableSelection = value;
257 /// Gets or sets cursor width.
259 /// <since_tizen> 6 </since_tizen>
260 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
261 [EditorBrowsable(EditorBrowsableState.Never)]
262 public int CursorWidth
266 return textField.CursorWidth;
270 CreateTextFieldAttributes();
271 inputFieldAttrs.InputBoxAttributes.CursorWidth = value;
272 textField.CursorWidth = value;
277 /// Gets or sets if enable ellipsis.
279 /// <since_tizen> 6 </since_tizen>
280 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
281 [EditorBrowsable(EditorBrowsableState.Never)]
282 public bool EnableEllipsis
286 return textField.Ellipsis;
290 CreateTextFieldAttributes();
291 inputFieldAttrs.InputBoxAttributes.Ellipsis = value;
292 textField.Ellipsis = value;
297 /// Gets or sets background image's resource url of input field.
299 /// <since_tizen> 6 </since_tizen>
300 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
301 [EditorBrowsable(EditorBrowsableState.Never)]
302 public string BackgroundImageURL
306 return inputFieldAttrs.BackgroundImageAttributes?.ResourceUrl?.All;
312 CreateBackgroundAttributes();
313 if (inputFieldAttrs.BackgroundImageAttributes.ResourceUrl == null)
315 inputFieldAttrs.BackgroundImageAttributes.ResourceUrl = new Selector<string>();
317 inputFieldAttrs.BackgroundImageAttributes.ResourceUrl.All = value;
324 /// Background image's border in Button.
326 /// <since_tizen> 6 </since_tizen>
327 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
328 [EditorBrowsable(EditorBrowsableState.Never)]
329 public Rectangle BackgroundImageBorder
333 return inputFieldAttrs.BackgroundImageAttributes?.Border?.All;
339 CreateBackgroundAttributes();
340 if (inputFieldAttrs.BackgroundImageAttributes.Border == null)
342 inputFieldAttrs.BackgroundImageAttributes.Border = new Selector<Rectangle>();
344 inputFieldAttrs.BackgroundImageAttributes.Border.All = value;
351 /// Gets and Sets Space.
357 return inputFieldAttrs.Space ?? 0;
361 inputFieldAttrs.Space = value;
367 /// Get Input Field attribues.
369 /// <since_tizen> 6 </since_tizen>
370 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
371 [EditorBrowsable(EditorBrowsableState.Never)]
372 protected override ViewStyle GetViewStyle()
374 return new InputFieldStyle();
378 /// Dispose Input Field and all children on it.
380 /// <param name="type">Dispose type.</param>
381 /// <since_tizen> 6 </since_tizen>
382 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
383 [EditorBrowsable(EditorBrowsableState.Never)]
384 protected override void Dispose(DisposeTypes type)
390 if (type == DisposeTypes.Explicit)
394 this.Remove(bgImage);
398 if (null != textField)
400 textField.FocusGained -= OnTextFieldFocusGained;
401 textField.FocusLost -= OnTextFieldFocusLost;
402 textField.TextChanged -= OnTextFieldTextChanged;
403 textField.KeyEvent -= OnTextFieldKeyEvent;
404 this.Remove(textField);
414 /// Update Input Field by attributes.
416 /// <since_tizen> 6 </since_tizen>
417 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
418 [EditorBrowsable(EditorBrowsableState.Never)]
419 protected override void OnUpdate()
422 OnLayoutDirectionChanged();
426 /// Theme change callback when theme is changed, this callback will be trigger.
428 /// <since_tizen> 6 </since_tizen>
429 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
430 [EditorBrowsable(EditorBrowsableState.Never)]
431 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
433 InputFieldStyle tempStyle = StyleManager.Instance.GetAttributes(style) as InputFieldStyle;
434 if (tempStyle != null)
436 Style.CopyFrom(tempStyle);
442 /// Theme change callback when text field focus is gained, this callback will be trigger.
444 /// <since_tizen> 6 </since_tizen>
445 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
446 [EditorBrowsable(EditorBrowsableState.Never)]
447 protected virtual void OnTextFieldFocusGained(object source, EventArgs e)
452 /// Theme change callback when text field is lost, this callback will be trigger.
454 /// <since_tizen> 6 </since_tizen>
455 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
456 [EditorBrowsable(EditorBrowsableState.Never)]
457 protected virtual void OnTextFieldFocusLost(object source, EventArgs e)
462 /// Theme change callback when text field's text is changed, this callback will be trigger.
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 virtual void OnTextFieldTextChanged(object sender, TextField.TextChangedEventArgs e)
472 /// Theme change callback when text field have a key event, this callback will be trigger.
474 /// <since_tizen> 6 </since_tizen>
475 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
476 [EditorBrowsable(EditorBrowsableState.Never)]
477 protected virtual bool OnTextFieldKeyEvent(object source, KeyEventArgs e)
483 /// Set the text field 2D size
485 /// <param name="w">Input Field' width.</param>
486 /// <param name="h">Input Field' height.</param>
487 /// <since_tizen> 6 </since_tizen>
488 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
489 [EditorBrowsable(EditorBrowsableState.Never)]
490 protected void SetTextFieldSize2D(int w, int h)
492 if (textField != null)
494 textField.Size2D = new Size2D(w, h);
499 /// Set the text field X pose
501 /// <param name="x">Input Field' X.</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 SetTextFieldPosX(int x)
507 if (textField != null)
509 textField.PositionX = x;
514 /// Set the text field text color
516 /// <param name="color">Input Field' color.</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 SetTextFieldTextColor(Color color)
522 if (textField != null)
524 textField.TextColor = color;
529 /// Set the text field relayout flag
531 /// <param name="value">relayout text field' value.</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 RelayoutTextField(bool value)
537 relayoutTextField = value;
540 private void Initialize()
542 inputFieldAttrs = Style as InputFieldStyle;
543 if (null == inputFieldAttrs)
545 throw new Exception("Fail to get the InputField attributes.");
548 bgImage = new ImageView();
551 throw new Exception("Fail to create background image.");
554 textField = new TextField();
555 if (null == textField)
557 throw new Exception("Fail to create text field.");
560 if (null != inputFieldAttrs.BackgroundImageAttributes)
562 bgImage.WidthResizePolicy = ResizePolicyType.FillToParent;
563 bgImage.HeightResizePolicy = ResizePolicyType.FillToParent;
564 bgImage.ParentOrigin = Tizen.NUI.ParentOrigin.Center;
565 bgImage.PivotPoint = Tizen.NUI.PivotPoint.Center;
566 bgImage.PositionUsesPivotPoint = true;
570 if (null != inputFieldAttrs.InputBoxAttributes)
572 textField.WidthResizePolicy = ResizePolicyType.Fixed;
573 textField.HeightResizePolicy = ResizePolicyType.Fixed;
574 textField.ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft;
575 textField.PivotPoint = Tizen.NUI.PivotPoint.CenterLeft;
576 textField.PositionUsesPivotPoint = true;
579 textField.FocusGained += OnTextFieldFocusGained;
580 textField.FocusLost += OnTextFieldFocusLost;
581 textField.TextChanged += OnTextFieldTextChanged;
582 textField.KeyEvent += OnTextFieldKeyEvent;
586 private void OnLayoutDirectionChanged()
588 if (inputFieldAttrs == null) return;
589 if (textField != null)
591 if (LayoutDirection == ViewLayoutDirectionType.LTR)
593 if(inputFieldAttrs.InputBoxAttributes != null)
595 inputFieldAttrs.InputBoxAttributes.HorizontalAlignment = HorizontalAlignment.Begin;
596 inputFieldAttrs.InputBoxAttributes.ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft;
597 inputFieldAttrs.InputBoxAttributes.PivotPoint = Tizen.NUI.PivotPoint.CenterLeft;
598 inputFieldAttrs.InputBoxAttributes.PositionUsesPivotPoint = true;
600 textField.HorizontalAlignment = HorizontalAlignment.Begin;
601 textField.ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft;
602 textField.PivotPoint = Tizen.NUI.PivotPoint.CenterLeft;
603 textField.PositionUsesPivotPoint = true;
605 else //ViewLayoutDirectionType.RTL
607 if (inputFieldAttrs.InputBoxAttributes != null)
609 inputFieldAttrs.InputBoxAttributes.HorizontalAlignment = HorizontalAlignment.End;
610 inputFieldAttrs.InputBoxAttributes.ParentOrigin = Tizen.NUI.ParentOrigin.CenterRight;
611 inputFieldAttrs.InputBoxAttributes.PivotPoint = Tizen.NUI.PivotPoint.CenterRight;
613 textField.HorizontalAlignment = HorizontalAlignment.End;
614 textField.ParentOrigin = Tizen.NUI.ParentOrigin.CenterRight;
615 textField.PivotPoint = Tizen.NUI.PivotPoint.CenterRight;
616 textField.PositionUsesPivotPoint = true;
621 private void RelayoutComponent()
623 if (!relayoutTextField)
627 int space = inputFieldAttrs.Space ?? 0;
629 if (textField != null)
631 textField.Size2D = new Size2D(this.Size2D.Width - space * 2, this.Size2D.Height);
632 textField.PositionX = space;
636 private void CreateBackgroundAttributes()
638 if (null == inputFieldAttrs.BackgroundImageAttributes)
640 inputFieldAttrs.BackgroundImageAttributes = new ImageViewStyle();
644 private void CreateTextFieldAttributes()
646 if (null == inputFieldAttrs.InputBoxAttributes)
648 inputFieldAttrs.InputBoxAttributes = new TextFieldStyle();