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 if (null != textField) 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 if (null != textField) 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)
141 inputFieldAttrs.InputBoxAttributes.TextColor = value;
142 if (null != textField) textField.TextColor = value;
148 /// Gets or sets text color.
150 /// <since_tizen> 6 </since_tizen>
151 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
152 [EditorBrowsable(EditorBrowsableState.Never)]
153 public Color HintTextColor
157 return textField?.PlaceholderTextColor;
161 CreateTextFieldAttributes();
162 if (null != inputFieldAttrs?.InputBoxAttributes && null != value)
164 Vector4 color = new Vector4(value.R, value.G, value.B, value.A);
165 inputFieldAttrs.InputBoxAttributes.PlaceholderTextColor = color;
166 if (null != textField) textField.PlaceholderTextColor = color;
172 /// Gets or sets primary cursor color.
174 /// <since_tizen> 6 </since_tizen>
175 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
176 [EditorBrowsable(EditorBrowsableState.Never)]
177 public Color PrimaryCursorColor
181 return textField?.PrimaryCursorColor;
185 CreateTextFieldAttributes();
186 if (null != inputFieldAttrs?.InputBoxAttributes && null != value)
188 Vector4 color = new Vector4(value.R, value.G, value.B, value.A);
189 inputFieldAttrs.InputBoxAttributes.PrimaryCursorColor = color;
190 if (null != textField) textField.PrimaryCursorColor = color;
196 /// Gets or sets font family of text.
198 /// <since_tizen> 6 </since_tizen>
199 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
200 [EditorBrowsable(EditorBrowsableState.Never)]
201 public string FontFamily
205 return textField?.FontFamily;
209 CreateTextFieldAttributes();
210 if (null != inputFieldAttrs?.InputBoxAttributes)
212 inputFieldAttrs.InputBoxAttributes.FontFamily = value;
213 if (null != textField) textField.FontFamily = value;
219 /// Gets or sets enable cursor blink.
221 /// <since_tizen> 6 </since_tizen>
222 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
223 [EditorBrowsable(EditorBrowsableState.Never)]
224 public bool EnableCursorBlink
228 return textField?.EnableCursorBlink ?? false;
232 CreateTextFieldAttributes();
233 if (null != inputFieldAttrs.InputBoxAttributes)
235 inputFieldAttrs.InputBoxAttributes.EnableCursorBlink = value;
236 if (null != textField) textField.EnableCursorBlink = value;
242 /// Gets or sets enable selection.
244 /// <since_tizen> 6 </since_tizen>
245 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
246 [EditorBrowsable(EditorBrowsableState.Never)]
247 public bool EnableSelection
251 return textField?.EnableSelection ?? false;
255 CreateTextFieldAttributes();
256 if (null != inputFieldAttrs?.InputBoxAttributes)
258 inputFieldAttrs.InputBoxAttributes.EnableSelection = value;
259 if (null != textField) textField.EnableSelection = value;
265 /// Gets or sets cursor width.
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 int CursorWidth
274 return textField?.CursorWidth ?? 0;
278 CreateTextFieldAttributes();
279 if (null != inputFieldAttrs.InputBoxAttributes)
281 inputFieldAttrs.InputBoxAttributes.CursorWidth = value;
282 if (null != textField) textField.CursorWidth = value;
288 /// Gets or sets if enable ellipsis.
290 /// <since_tizen> 6 </since_tizen>
291 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
292 [EditorBrowsable(EditorBrowsableState.Never)]
293 public bool EnableEllipsis
297 return textField?.Ellipsis ?? false;
301 CreateTextFieldAttributes();
302 if (null != inputFieldAttrs.InputBoxAttributes)
304 inputFieldAttrs.InputBoxAttributes.Ellipsis = value;
305 if (null != textField) textField.Ellipsis = value;
311 /// Gets or sets background image's resource url of input field.
313 /// <since_tizen> 6 </since_tizen>
314 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
315 [EditorBrowsable(EditorBrowsableState.Never)]
316 public string BackgroundImageURL
320 return inputFieldAttrs?.BackgroundImageAttributes?.ResourceUrl?.All;
324 CreateBackgroundAttributes();
325 if (null != inputFieldAttrs?.BackgroundImageAttributes)
327 inputFieldAttrs.BackgroundImageAttributes.ResourceUrl = value;
334 /// Background image's border in Button.
336 /// <since_tizen> 6 </since_tizen>
337 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
338 [EditorBrowsable(EditorBrowsableState.Never)]
339 public Rectangle BackgroundImageBorder
343 return inputFieldAttrs?.BackgroundImageAttributes?.Border?.All;
347 CreateBackgroundAttributes();
348 if (null != inputFieldAttrs?.BackgroundImageAttributes)
350 inputFieldAttrs.BackgroundImageAttributes.Border = value;
357 /// Gets and Sets Space.
363 return inputFieldAttrs?.Space ?? 0;
367 if (null != inputFieldAttrs)
369 inputFieldAttrs.Space = value;
375 /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
376 [EditorBrowsable(EditorBrowsableState.Never)]
377 public override void ApplyStyle(ViewStyle viewStyle)
379 base.ApplyStyle(viewStyle);
381 InputFieldStyle inputFieldStyle = viewStyle as InputFieldStyle;
383 if (null != inputFieldStyle.BackgroundImageAttributes)
387 bgImage = new ImageView()
389 WidthResizePolicy = ResizePolicyType.FillToParent,
390 HeightResizePolicy = ResizePolicyType.FillToParent,
395 bgImage.ApplyStyle(inputFieldStyle.BackgroundImageAttributes);
397 if (null != inputFieldStyle.InputBoxAttributes)
399 if (null == textField)
401 textField = new TextField()
403 WidthResizePolicy = ResizePolicyType.Fixed,
404 HeightResizePolicy = ResizePolicyType.Fixed,
405 ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft,
406 PivotPoint = Tizen.NUI.PivotPoint.CenterLeft,
407 PositionUsesPivotPoint = true,
410 textField.FocusGained += OnTextFieldFocusGained;
411 textField.FocusLost += OnTextFieldFocusLost;
412 textField.TextChanged += OnTextFieldTextChanged;
413 textField.KeyEvent += OnTextFieldKeyEvent;
415 textField.ApplyStyle(inputFieldStyle.InputBoxAttributes);
420 /// Get Input Field attribues.
422 /// <since_tizen> 6 </since_tizen>
423 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
424 [EditorBrowsable(EditorBrowsableState.Never)]
425 protected override ViewStyle GetViewStyle()
427 return new InputFieldStyle();
431 /// Dispose Input Field and all children on it.
433 /// <param name="type">Dispose type.</param>
434 /// <since_tizen> 6 </since_tizen>
435 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
436 [EditorBrowsable(EditorBrowsableState.Never)]
437 protected override void Dispose(DisposeTypes type)
443 if (type == DisposeTypes.Explicit)
447 this.Remove(bgImage);
451 if (null != textField)
453 textField.FocusGained -= OnTextFieldFocusGained;
454 textField.FocusLost -= OnTextFieldFocusLost;
455 textField.TextChanged -= OnTextFieldTextChanged;
456 textField.KeyEvent -= OnTextFieldKeyEvent;
457 this.Remove(textField);
467 /// Update Input Field by attributes.
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 override void OnUpdate()
475 OnLayoutDirectionChanged();
479 /// Theme change callback when theme is changed, this callback will be trigger.
481 /// <since_tizen> 6 </since_tizen>
482 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
483 [EditorBrowsable(EditorBrowsableState.Never)]
484 protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
486 InputFieldStyle tempStyle = StyleManager.Instance.GetViewStyle(style) as InputFieldStyle;
487 if (tempStyle != null)
489 Style.CopyFrom(tempStyle);
495 /// Theme change callback when text field focus is gained, this callback will be trigger.
497 /// <since_tizen> 6 </since_tizen>
498 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
499 [EditorBrowsable(EditorBrowsableState.Never)]
500 protected virtual void OnTextFieldFocusGained(object source, EventArgs e)
505 /// Theme change callback when text field is lost, this callback will be trigger.
507 /// <since_tizen> 6 </since_tizen>
508 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
509 [EditorBrowsable(EditorBrowsableState.Never)]
510 protected virtual void OnTextFieldFocusLost(object source, EventArgs e)
515 /// Theme change callback when text field's text is changed, this callback will be trigger.
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 virtual void OnTextFieldTextChanged(object sender, TextField.TextChangedEventArgs e)
525 /// Theme change callback when text field have a key event, this callback will be trigger.
527 /// <since_tizen> 6 </since_tizen>
528 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
529 [EditorBrowsable(EditorBrowsableState.Never)]
530 protected virtual bool OnTextFieldKeyEvent(object source, KeyEventArgs e)
536 /// Set the text field 2D size
538 /// <param name="w">Input Field' width.</param>
539 /// <param name="h">Input Field' height.</param>
540 /// <since_tizen> 6 </since_tizen>
541 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
542 [EditorBrowsable(EditorBrowsableState.Never)]
543 protected void SetTextFieldSize2D(int w, int h)
545 if (textField != null)
547 textField.Size2D = new Size2D(w, h);
552 /// Set the text field X pose
554 /// <param name="x">Input Field' X.</param>
555 /// <since_tizen> 6 </since_tizen>
556 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
557 [EditorBrowsable(EditorBrowsableState.Never)]
558 protected void SetTextFieldPosX(int x)
560 if (textField != null)
562 textField.PositionX = x;
567 /// Set the text field text color
569 /// <param name="color">Input Field' color.</param>
570 /// <since_tizen> 6 </since_tizen>
571 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
572 [EditorBrowsable(EditorBrowsableState.Never)]
573 protected void SetTextFieldTextColor(Color color)
575 if (textField != null)
577 textField.TextColor = color;
582 /// Set the text field relayout flag
584 /// <param name="value">relayout text field' value.</param>
585 /// <since_tizen> 6 </since_tizen>
586 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
587 [EditorBrowsable(EditorBrowsableState.Never)]
588 protected void RelayoutTextField(bool value)
590 relayoutTextField = value;
593 private void Initialize()
595 inputFieldAttrs = Style as InputFieldStyle;
596 if (null == inputFieldAttrs)
598 throw new Exception("Fail to get the InputField attributes.");
603 bgImage = new ImageView()
605 WidthResizePolicy = ResizePolicyType.FillToParent,
606 HeightResizePolicy = ResizePolicyType.FillToParent,
611 if (null == textField)
613 textField = new TextField()
615 WidthResizePolicy = ResizePolicyType.Fixed,
616 HeightResizePolicy = ResizePolicyType.Fixed,
617 ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft,
618 PivotPoint = Tizen.NUI.PivotPoint.CenterLeft,
619 PositionUsesPivotPoint = true,
622 textField.FocusGained += OnTextFieldFocusGained;
623 textField.FocusLost += OnTextFieldFocusLost;
624 textField.TextChanged += OnTextFieldTextChanged;
625 textField.KeyEvent += OnTextFieldKeyEvent;
629 private void OnLayoutDirectionChanged()
631 if (inputFieldAttrs == null) return;
632 if (textField != null)
634 if (LayoutDirection == ViewLayoutDirectionType.LTR)
636 if(inputFieldAttrs.InputBoxAttributes != null)
638 inputFieldAttrs.InputBoxAttributes.HorizontalAlignment = HorizontalAlignment.Begin;
639 inputFieldAttrs.InputBoxAttributes.ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft;
640 inputFieldAttrs.InputBoxAttributes.PivotPoint = Tizen.NUI.PivotPoint.CenterLeft;
641 inputFieldAttrs.InputBoxAttributes.PositionUsesPivotPoint = true;
643 textField.HorizontalAlignment = HorizontalAlignment.Begin;
644 textField.ParentOrigin = Tizen.NUI.ParentOrigin.CenterLeft;
645 textField.PivotPoint = Tizen.NUI.PivotPoint.CenterLeft;
646 textField.PositionUsesPivotPoint = true;
648 else //ViewLayoutDirectionType.RTL
650 if (inputFieldAttrs.InputBoxAttributes != null)
652 inputFieldAttrs.InputBoxAttributes.HorizontalAlignment = HorizontalAlignment.End;
653 inputFieldAttrs.InputBoxAttributes.ParentOrigin = Tizen.NUI.ParentOrigin.CenterRight;
654 inputFieldAttrs.InputBoxAttributes.PivotPoint = Tizen.NUI.PivotPoint.CenterRight;
656 textField.HorizontalAlignment = HorizontalAlignment.End;
657 textField.ParentOrigin = Tizen.NUI.ParentOrigin.CenterRight;
658 textField.PivotPoint = Tizen.NUI.PivotPoint.CenterRight;
659 textField.PositionUsesPivotPoint = true;
664 private void RelayoutComponent()
666 if (!relayoutTextField)
670 int space = inputFieldAttrs.Space ?? 0;
672 if (textField != null)
674 textField.Size2D = new Size2D(this.Size2D.Width - space * 2, this.Size2D.Height);
675 textField.PositionX = space;
679 private void CreateBackgroundAttributes()
681 if (null == inputFieldAttrs.BackgroundImageAttributes)
683 inputFieldAttrs.BackgroundImageAttributes = new ImageViewStyle();
687 private void CreateTextFieldAttributes()
689 if (null == inputFieldAttrs.InputBoxAttributes)
691 inputFieldAttrs.InputBoxAttributes = new TextFieldStyle();