[NUI] Create TextLayout when parent has layout
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / TextLabel.cs
1 /*
2  * Copyright(c) 2020 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 extern alias TizenSystemSettings;
19 using TizenSystemSettings.Tizen.System;
20 using System;
21 using System.Globalization;
22 using System.ComponentModel;
23 using Tizen.NUI.Binding;
24
25 namespace Tizen.NUI.BaseComponents
26 {
27     /// <summary>
28     /// A control which renders a short text string.<br />
29     /// Text labels are lightweight, non-editable, and do not respond to the user input.<br />
30     /// </summary>
31     /// <since_tizen> 3 </since_tizen>
32     public partial class TextLabel : View
33     {
34         private class TextLayout : LayoutItem
35         {
36             protected override void OnMeasure(MeasureSpecification widthMeasureSpec, MeasureSpecification heightMeasureSpec)
37             {
38                 // Padding will be automatically applied by DALi TextLabel.
39                 float totalWidth = widthMeasureSpec.Size.AsDecimal();
40                 float totalHeight = heightMeasureSpec.Size.AsDecimal();
41
42                 if (widthMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
43                 {
44                     if (heightMeasureSpec.Mode != MeasureSpecification.ModeType.Exactly)
45                     {
46                         totalHeight = Owner.GetHeightForWidth(totalWidth);
47                         heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
48                     }
49                 }
50                 else
51                 {
52                     if (heightMeasureSpec.Mode == MeasureSpecification.ModeType.Exactly)
53                     {
54                         // GetWidthForHeight is not implemented.
55                         totalWidth = Owner.GetNaturalSize().Width;
56                         widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
57                     }
58                     else
59                     {
60                         Vector3 naturalSize = Owner.GetNaturalSize();
61                         totalWidth = naturalSize.Width;
62                         totalHeight = naturalSize.Height;
63
64                         heightMeasureSpec = new MeasureSpecification(new LayoutLength(totalHeight), MeasureSpecification.ModeType.Exactly);
65                         widthMeasureSpec = new MeasureSpecification(new LayoutLength(totalWidth), MeasureSpecification.ModeType.Exactly);
66                     }
67                 }
68
69                 MeasuredSize.StateType childWidthState = MeasuredSize.StateType.MeasuredSizeOK;
70                 MeasuredSize.StateType childHeightState = MeasuredSize.StateType.MeasuredSizeOK;
71
72                 SetMeasuredDimensions(ResolveSizeAndState(new LayoutLength(totalWidth), widthMeasureSpec, childWidthState),
73                                        ResolveSizeAndState(new LayoutLength(totalHeight), heightMeasureSpec, childHeightState));
74             }
75         }
76
77         static TextLabel() { }
78
79         private string textLabelSid = null;
80         private bool systemlangTextFlag = false;
81         private TextLabelSelectorData selectorData;
82         private float fontSizeScale = 1.0f;
83         private bool hasFontSizeChangedCallback = false;
84
85         /// <summary>
86         /// Creates the TextLabel control.
87         /// </summary>
88         /// <since_tizen> 3 </since_tizen>
89         public TextLabel() : this(Interop.TextLabel.New(), true)
90         {
91             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92         }
93
94         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
95         [EditorBrowsable(EditorBrowsableState.Never)]
96         public TextLabel(TextLabelStyle viewStyle) : this(Interop.TextLabel.New(), true, viewStyle)
97         {
98         }
99
100         /// <summary>
101         /// Creates the TextLabel with setting the status of shown or hidden.
102         /// </summary>
103         /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
104         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
105         [EditorBrowsable(EditorBrowsableState.Never)]
106         public TextLabel(bool shown) : this(Interop.TextLabel.New(), true)
107         {
108             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
109             SetVisible(shown);
110         }
111
112         /// <summary>
113         /// Creates the TextLabel control.
114         /// </summary>
115         /// <param name="text">The text to display</param>
116         /// <since_tizen> 3 </since_tizen>
117         public TextLabel(string text) : this(Interop.TextLabel.New(text), true)
118         {
119             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
120         }
121
122         /// <summary>
123         /// Creates the TextLabel with setting the status of shown or hidden.
124         /// </summary>
125         /// <param name="text">The text to display</param>
126         /// <param name="shown">false : Not displayed (hidden), true : displayed (shown)</param>
127         /// This will be public opened in next release of tizen after ACR done. Before ACR, it is used as HiddenAPI (InhouseAPI).
128         [EditorBrowsable(EditorBrowsableState.Never)]
129         public TextLabel(string text, bool shown) : this(Interop.TextLabel.New(text), true)
130         {
131             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
132             SetVisible(shown);
133         }
134
135         internal TextLabel(TextLabel handle, bool shown = true) : this(Interop.TextLabel.NewTextLabel(TextLabel.getCPtr(handle)), true)
136         {
137             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
138
139             if (!shown)
140             {
141                 SetVisible(false);
142             }
143         }
144
145         internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, ViewStyle viewStyle, bool shown = true) : base(cPtr, cMemoryOwn, viewStyle)
146         {
147             if (!shown)
148             {
149                 SetVisible(false);
150             }
151         }
152
153         internal TextLabel(global::System.IntPtr cPtr, bool cMemoryOwn, bool shown = true) : base(cPtr, cMemoryOwn, null)
154         {
155             if (!shown)
156             {
157                 SetVisible(false);
158             }
159         }
160
161         /// <summary>
162         /// Create internal layout of TextLabel
163         /// </summary>
164         internal LayoutItem CreateTextLayout()
165         {
166             return new TextLayout();
167         }
168
169         /// <summary>
170         /// The TranslatableText property.<br />
171         /// The text can set the SID value.<br />
172         /// </summary>
173         /// <exception cref='ArgumentNullException'>
174         /// ResourceManager about multilingual is null.
175         /// </exception>
176         /// <since_tizen> 4 </since_tizen>
177         public string TranslatableText
178         {
179             get
180             {
181                 return (string)GetValue(TranslatableTextProperty);
182             }
183             set
184             {
185                 SetValue(TranslatableTextProperty, value);
186                 selectorData?.TranslatableText.UpdateIfNeeds(this, value);
187             }
188         }
189         private string translatableText
190         {
191             get
192             {
193                 return textLabelSid;
194             }
195             set
196             {
197                 if (NUIApplication.MultilingualResourceManager == null)
198                 {
199                     throw new ArgumentNullException(null, "ResourceManager about multilingual is null");
200                 }
201                 string translatableText = null;
202                 textLabelSid = value;
203                 translatableText = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(SystemSettings.LocaleLanguage.Replace("_", "-")));
204                 if (translatableText != null)
205                 {
206                     Text = translatableText;
207                     if (systemlangTextFlag == false)
208                     {
209                         SystemSettings.LocaleLanguageChanged += SystemSettings_LocaleLanguageChanged;
210                         systemlangTextFlag = true;
211                     }
212                 }
213                 else
214                 {
215                     Text = "";
216                 }
217                 NotifyPropertyChanged();
218             }
219         }
220
221         /// <summary>
222         /// The Text property.<br />
223         /// The text to display in the UTF-8 format.<br />
224         /// </summary>
225         /// <since_tizen> 3 </since_tizen>
226         public string Text
227         {
228             get
229             {
230                 return (string)GetValue(TextProperty);
231             }
232             set
233             {
234                 SetValue(TextProperty, value);
235                 selectorData?.Text.UpdateIfNeeds(this, value);
236                 NotifyPropertyChangedAndRequestLayout();
237             }
238         }
239
240         /// <summary>
241         /// The FontFamily property.<br />
242         /// The requested font family to use.<br />
243         /// </summary>
244         /// <since_tizen> 3 </since_tizen>
245         public string FontFamily
246         {
247             get
248             {
249                 return (string)GetValue(FontFamilyProperty);
250             }
251             set
252             {
253                 SetValue(FontFamilyProperty, value);
254                 selectorData?.FontFamily.UpdateIfNeeds(this, value);
255                 NotifyPropertyChangedAndRequestLayout();
256             }
257         }
258
259         /// <summary>
260         /// The FontStyle property.<br />
261         /// The requested font style to use.<br />
262         /// </summary>
263         /// <since_tizen> 3 </since_tizen>
264         public PropertyMap FontStyle
265         {
266             get
267             {
268                 return (PropertyMap)GetValue(FontStyleProperty);
269             }
270             set
271             {
272                 SetValue(FontStyleProperty, value);
273                 NotifyPropertyChangedAndRequestLayout();
274             }
275         }
276
277         /// <summary>
278         /// The PointSize property.<br />
279         /// The size of font in points.<br />
280         /// </summary>
281         /// <since_tizen> 3 </since_tizen>
282         public float PointSize
283         {
284             get
285             {
286                 return (float)GetValue(PointSizeProperty);
287             }
288             set
289             {
290                 SetValue(PointSizeProperty, value);
291                 selectorData?.PointSize.UpdateIfNeeds(this, value);
292                 NotifyPropertyChangedAndRequestLayout();
293             }
294         }
295
296         /// <summary>
297         /// The MultiLine property.<br />
298         /// The single-line or multi-line layout option.<br />
299         /// </summary>
300         /// <since_tizen> 3 </since_tizen>
301         public bool MultiLine
302         {
303             get
304             {
305                 return (bool)GetValue(MultiLineProperty);
306             }
307             set
308             {
309                 SetValue(MultiLineProperty, value);
310                 NotifyPropertyChangedAndRequestLayout();
311             }
312         }
313
314         /// <summary>
315         /// The HorizontalAlignment property.<br />
316         /// The line horizontal alignment.<br />
317         /// </summary>
318         /// <since_tizen> 3 </since_tizen>
319         public HorizontalAlignment HorizontalAlignment
320         {
321             get
322             {
323                 return (HorizontalAlignment)GetValue(HorizontalAlignmentProperty);
324             }
325             set
326             {
327                 SetValue(HorizontalAlignmentProperty, value);
328                 NotifyPropertyChanged();
329             }
330         }
331
332         /// <summary>
333         /// The VerticalAlignment property.<br />
334         /// The line vertical alignment.<br />
335         /// </summary>
336         /// <since_tizen> 3 </since_tizen>
337         public VerticalAlignment VerticalAlignment
338         {
339             get
340             {
341                 return (VerticalAlignment)GetValue(VerticalAlignmentProperty);
342             }
343             set
344             {
345                 SetValue(VerticalAlignmentProperty, value);
346                 NotifyPropertyChanged();
347             }
348         }
349
350         /// <summary>
351         /// The TextColor property.<br />
352         /// The color of the text.<br />
353         /// Animation framework can be used to change the color of the text when not using mark up.<br />
354         /// Cannot animate the color when text is auto scrolling.<br />
355         /// </summary>
356         /// <remarks>
357         /// The property cascade chaining set is possible. For example, this (textLabel.TextColor.X = 0.1f;) is possible.
358         /// </remarks>
359         /// <since_tizen> 3 </since_tizen>
360         public Color TextColor
361         {
362             get
363             {
364                 Color temp = (Color)GetValue(TextColorProperty);
365                 return new Color(OnTextColorChanged, temp.R, temp.G, temp.B, temp.A);
366             }
367             set
368             {
369                 SetValue(TextColorProperty, value);
370                 selectorData?.TextColor.UpdateIfNeeds(this, value);
371                 NotifyPropertyChanged();
372             }
373         }
374
375         /// <summary>
376         /// The ShadowOffset property.<br />
377         /// The drop shadow offset 0 indicates no shadow.<br />
378         /// </summary>
379         /// <since_tizen> 3 </since_tizen>
380         /// <remarks>
381         /// Deprecated.(API Level 6) Use Shadow instead.
382         /// The property cascade chaining set is possible. For example, this (textLabel.ShadowOffset.X = 0.1f;) is possible.
383         /// </remarks>
384         [Obsolete("Please do not use this ShadowOffset(Deprecated). Please use Shadow instead.")]
385         public Vector2 ShadowOffset
386         {
387             get
388             {
389                 Vector2 shadowOffset = new Vector2();
390                 Shadow.Find(TextLabel.Property.SHADOW, "offset")?.Get(shadowOffset);
391                 return new Vector2(OnShadowOffsetChanged, shadowOffset.X, shadowOffset.Y);
392             }
393             set
394             {
395                 PropertyMap temp = new PropertyMap();
396                 temp.Insert("offset", new PropertyValue(value));
397
398                 PropertyMap shadowMap = Shadow;
399                 shadowMap.Merge(temp);
400
401                 SetValue(ShadowProperty, shadowMap);
402                 NotifyPropertyChanged();
403             }
404         }
405
406         /// <summary>
407         /// The ShadowColor property.<br />
408         /// The color of a drop shadow.<br />
409         /// </summary>
410         /// <since_tizen> 3 </since_tizen>
411         /// <remarks>
412         /// Deprecated.(API Level 6) Use Shadow instead.
413         /// The property cascade chaining set is possible. For example, this (textLabel.ShadowColor.X = 0.1f;) is possible.
414         /// </remarks>
415         [Obsolete("Please do not use this ShadowColor(Deprecated). Please use Shadow instead.")]
416         public Vector4 ShadowColor
417         {
418             get
419             {
420                 Vector4 shadowColor = new Vector4();
421                 Shadow.Find(TextLabel.Property.SHADOW, "color")?.Get(shadowColor);
422                 return new Vector4(OnShadowColorChanged, shadowColor.X, shadowColor.Y, shadowColor.Z, shadowColor.W);
423             }
424             set
425             {
426                 PropertyMap temp = new PropertyMap();
427                 temp.Insert("color", new PropertyValue(value));
428
429                 PropertyMap shadowMap = Shadow;
430                 shadowMap.Merge(temp);
431
432                 SetValue(ShadowProperty, shadowMap);
433                 NotifyPropertyChanged();
434             }
435         }
436
437         /// <summary>
438         /// The UnderlineEnabled property.<br />
439         /// The underline enabled flag.<br />
440         /// </summary>
441         /// <since_tizen> 3 </since_tizen>
442         /// <remarks>
443         /// Deprecated.(API Level 6) Use Underline instead.
444         /// </remarks>
445         [Obsolete("Please do not use this UnderlineEnabled(Deprecated). Please use Underline instead.")]
446         public bool UnderlineEnabled
447         {
448             get
449             {
450                 bool underlineEnabled = false;
451                 Underline.Find(TextLabel.Property.UNDERLINE, "enable")?.Get(out underlineEnabled);
452                 return underlineEnabled;
453             }
454             set
455             {
456                 PropertyMap temp = new PropertyMap();
457                 temp.Add("enable", new PropertyValue(value));
458
459                 PropertyMap undelineMap = Underline;
460                 undelineMap.Merge(temp);
461
462                 SetValue(UnderlineProperty, undelineMap);
463                 NotifyPropertyChanged();
464
465             }
466         }
467
468         /// <summary>
469         /// The UnderlineColor property.<br />
470         /// Overrides the underline height from font metrics.<br />
471         /// </summary>
472         /// <since_tizen> 3 </since_tizen>
473         /// <remarks>
474         /// Deprecated.(API Level 6) Use Underline instead.
475         /// The property cascade chaining set is possible. For example, this (textLabel.UnderlineColor.X = 0.1f;) is possible.
476         /// </remarks>
477         [Obsolete("Please do not use this UnderlineColor(Deprecated). Please use Underline instead.")]
478         public Vector4 UnderlineColor
479         {
480             get
481             {
482                 Vector4 underlineColor = new Vector4();
483                 Underline.Find(TextLabel.Property.UNDERLINE, "color")?.Get(underlineColor);
484                 return new Vector4(OnUnderlineColorChanged, underlineColor.X, underlineColor.Y, underlineColor.Z, underlineColor.W);
485             }
486             set
487             {
488                 PropertyMap temp = new PropertyMap();
489                 temp.Insert("color", new PropertyValue(value));
490
491                 PropertyMap undelineMap = Underline;
492                 undelineMap.Merge(temp);
493
494                 SetValue(UnderlineProperty, undelineMap);
495                 NotifyPropertyChanged();
496             }
497         }
498
499         /// <summary>
500         /// The UnderlineHeight property.<br />
501         /// Overrides the underline height from font metrics.<br />
502         /// </summary>
503         /// <since_tizen> 3 </since_tizen>
504         /// <remarks>
505         /// Deprecated.(API Level 6) Use Underline instead.
506         /// </remarks>
507         [Obsolete("Please do not use this UnderlineHeight(Deprecated). Please use Underline instead.")]
508         public float UnderlineHeight
509         {
510             get
511             {
512                 float underlineHeight = 0.0f;
513                 Underline.Find(TextLabel.Property.UNDERLINE, "height")?.Get(out underlineHeight);
514                 return underlineHeight;
515             }
516             set
517             {
518                 PropertyMap temp = new PropertyMap();
519                 temp.Insert("height", new PropertyValue(value));
520
521                 PropertyMap undelineMap = Underline;
522                 undelineMap.Merge(temp);
523
524                 SetValue(UnderlineProperty, undelineMap);
525                 NotifyPropertyChanged();
526             }
527         }
528
529         /// <summary>
530         /// The EnableMarkup property.<br />
531         /// Whether the mark-up processing is enabled.<br />
532         /// </summary>
533         /// <since_tizen> 3 </since_tizen>
534         public bool EnableMarkup
535         {
536             get
537             {
538                 return (bool)GetValue(EnableMarkupProperty);
539             }
540             set
541             {
542                 SetValue(EnableMarkupProperty, value);
543                 NotifyPropertyChanged();
544             }
545         }
546
547         /// <summary>
548         /// The EnableAutoScroll property.<br />
549         /// Starts or stops auto scrolling.<br />
550         /// </summary>
551         /// <since_tizen> 3 </since_tizen>
552         public bool EnableAutoScroll
553         {
554             get
555             {
556                 return (bool)GetValue(EnableAutoScrollProperty);
557             }
558             set
559             {
560                 SetValue(EnableAutoScrollProperty, value);
561                 NotifyPropertyChanged();
562             }
563         }
564
565         /// <summary>
566         /// The AutoScrollSpeed property.<br />
567         /// Sets the speed of scrolling in pixels per second.<br />
568         /// </summary>
569         /// <since_tizen> 3 </since_tizen>
570         public int AutoScrollSpeed
571         {
572             get
573             {
574                 return (int)GetValue(AutoScrollSpeedProperty);
575             }
576             set
577             {
578                 SetValue(AutoScrollSpeedProperty, value);
579                 NotifyPropertyChanged();
580             }
581         }
582
583         /// <summary>
584         /// The AutoScrollLoopCount property.<br />
585         /// Number of complete loops when scrolling enabled.<br />
586         /// </summary>
587         /// <since_tizen> 3 </since_tizen>
588         public int AutoScrollLoopCount
589         {
590             get
591             {
592                 return (int)GetValue(AutoScrollLoopCountProperty);
593             }
594             set
595             {
596                 SetValue(AutoScrollLoopCountProperty, value);
597                 NotifyPropertyChanged();
598             }
599         }
600
601         /// <summary>
602         /// The AutoScrollGap property.<br />
603         /// Gap before scrolling wraps.<br />
604         /// </summary>
605         /// <since_tizen> 3 </since_tizen>
606         public float AutoScrollGap
607         {
608             get
609             {
610                 return (float)GetValue(AutoScrollGapProperty);
611             }
612             set
613             {
614                 SetValue(AutoScrollGapProperty, value);
615                 NotifyPropertyChanged();
616             }
617         }
618
619         /// <summary>
620         /// The LineSpacing property.<br />
621         /// The default extra space between lines in points.<br />
622         /// </summary>
623         /// <since_tizen> 3 </since_tizen>
624         public float LineSpacing
625         {
626             get
627             {
628                 return (float)GetValue(LineSpacingProperty);
629             }
630             set
631             {
632                 SetValue(LineSpacingProperty, value);
633                 NotifyPropertyChangedAndRequestLayout();
634             }
635         }
636
637         /// <summary>
638         /// The Underline property.<br />
639         /// The default underline parameters.<br />
640         /// </summary>
641         /// <since_tizen> 3 </since_tizen>
642         public PropertyMap Underline
643         {
644             get
645             {
646                 return (PropertyMap)GetValue(UnderlineProperty);
647             }
648             set
649             {
650                 SetValue(UnderlineProperty, value);
651                 NotifyPropertyChanged();
652             }
653         }
654
655         /// <summary>
656         /// The Shadow property.<br />
657         /// The default shadow parameters.<br />
658         /// </summary>
659         /// <since_tizen> 3 </since_tizen>
660         public PropertyMap Shadow
661         {
662             get
663             {
664                 return (PropertyMap)GetValue(ShadowProperty);
665             }
666             set
667             {
668                 SetValue(ShadowProperty, value);
669                 NotifyPropertyChanged();
670             }
671         }
672
673         /// <summary>
674         /// Describes a text shadow for a TextLabel.
675         /// It is null by default.
676         /// </summary>
677         [EditorBrowsable(EditorBrowsableState.Never)]
678         public TextShadow TextShadow
679         {
680             get
681             {
682                 return (TextShadow)GetValue(TextShadowProperty);
683             }
684             set
685             {
686                 SetValue(TextShadowProperty, value);
687                 selectorData?.TextShadow.UpdateIfNeeds(this, value);
688                 NotifyPropertyChanged();
689             }
690         }
691
692         /// <summary>
693         /// The Emboss property.<br />
694         /// The default emboss parameters.<br />
695         /// </summary>
696         /// <since_tizen> 3 </since_tizen>
697         public string Emboss
698         {
699             get
700             {
701                 return (string)GetValue(EmbossProperty);
702             }
703             set
704             {
705                 SetValue(EmbossProperty, value);
706                 NotifyPropertyChanged();
707             }
708         }
709
710         /// <summary>
711         /// The Outline property.<br />
712         /// The default outline parameters.<br />
713         /// </summary>
714         /// <since_tizen> 3 </since_tizen>
715         public PropertyMap Outline
716         {
717             get
718             {
719                 return (PropertyMap)GetValue(OutlineProperty);
720             }
721             set
722             {
723                 SetValue(OutlineProperty, value);
724                 NotifyPropertyChanged();
725             }
726         }
727
728         /// <summary>
729         /// The PixelSize property.<br />
730         /// The size of font in pixels.<br />
731         /// </summary>
732         /// <since_tizen> 3 </since_tizen>
733         public float PixelSize
734         {
735             get
736             {
737                 return (float)GetValue(PixelSizeProperty);
738             }
739             set
740             {
741                 SetValue(PixelSizeProperty, value);
742                 selectorData?.PixelSize.UpdateIfNeeds(this, value);
743                 NotifyPropertyChangedAndRequestLayout();
744             }
745         }
746
747         /// <summary>
748         /// The Ellipsis property.<br />
749         /// Enable or disable the ellipsis.<br />
750         /// </summary>
751         /// <since_tizen> 3 </since_tizen>
752         public bool Ellipsis
753         {
754             get
755             {
756                 return (bool)GetValue(EllipsisProperty);
757             }
758             set
759             {
760                 SetValue(EllipsisProperty, value);
761                 NotifyPropertyChanged();
762             }
763         }
764
765         /// <summary>
766         /// The AutoScrollLoopDelay property.<br />
767         /// Do something.<br />
768         /// </summary>
769         /// <since_tizen> 3 </since_tizen>
770         public float AutoScrollLoopDelay
771         {
772             get
773             {
774                 return (float)GetValue(AutoScrollLoopDelayProperty);
775             }
776             set
777             {
778                 SetValue(AutoScrollLoopDelayProperty, value);
779                 NotifyPropertyChanged();
780             }
781         }
782
783         /// <summary>
784         /// The AutoScrollStopMode property.<br />
785         /// Do something.<br />
786         /// </summary>
787         /// <since_tizen> 3 </since_tizen>
788         public AutoScrollStopMode AutoScrollStopMode
789         {
790             get
791             {
792                 return (AutoScrollStopMode)GetValue(AutoScrollStopModeProperty);
793             }
794             set
795             {
796                 SetValue(AutoScrollStopModeProperty, value);
797                 NotifyPropertyChanged();
798             }
799         }
800
801         /// <summary>
802         /// The line count of the text.
803         /// </summary>
804         /// <since_tizen> 3 </since_tizen>
805         public int LineCount
806         {
807             get
808             {
809                 int temp = 0;
810                 GetProperty(TextLabel.Property.LineCount).Get(out temp);
811                 return temp;
812             }
813         }
814
815         /// <summary>
816         /// The LineWrapMode property.<br />
817         /// line wrap mode when the text lines over layout width.<br />
818         /// </summary>
819         /// <since_tizen> 4 </since_tizen>
820         public LineWrapMode LineWrapMode
821         {
822             get
823             {
824                 return (LineWrapMode)GetValue(LineWrapModeProperty);
825             }
826             set
827             {
828                 SetValue(LineWrapModeProperty, value);
829                 NotifyPropertyChanged();
830             }
831         }
832
833         /// <summary>
834         /// The direction of the text such as left to right or right to left.
835         /// </summary>
836         /// <since_tizen> 5 </since_tizen>
837         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
838         [EditorBrowsable(EditorBrowsableState.Never)]
839         public TextDirection TextDirection
840         {
841             get
842             {
843                 int temp = 0;
844                 GetProperty(TextLabel.Property.TextDirection).Get(out temp);
845                 return (TextDirection)temp;
846             }
847         }
848
849         /// <summary>
850         /// The vertical line alignment of the text.
851         /// </summary>
852         /// <since_tizen> 5 </since_tizen>
853         /// This will be released at Tizen.NET API Level 5, so currently this would be used as inhouse API.
854         [EditorBrowsable(EditorBrowsableState.Never)]
855         public VerticalLineAlignment VerticalLineAlignment
856         {
857             get
858             {
859                 return (VerticalLineAlignment)GetValue(VerticalLineAlignmentProperty);
860             }
861             set
862             {
863                 SetValue(VerticalLineAlignmentProperty, value);
864                 NotifyPropertyChanged();
865             }
866         }
867
868         /// <summary>
869         /// The text alignment to match the direction of the system language.
870         /// </summary>
871         /// <since_tizen> 6 </since_tizen>
872         public bool MatchSystemLanguageDirection
873         {
874             get
875             {
876                 return (bool)GetValue(MatchSystemLanguageDirectionProperty);
877             }
878             set
879             {
880                 SetValue(MatchSystemLanguageDirectionProperty, value);
881                 NotifyPropertyChanged();
882             }
883         }
884
885         /// <summary>
886         /// The text fit parameters.<br />
887         /// The textFit map contains the following keys :<br />
888         /// - enable (bool type) : True to enable the text fit or false to disable(the default value is false)<br />
889         /// - minSize (float type) : Minimum Size for text fit(the default value is 10.f)<br />
890         /// - maxSize (float type) : Maximum Size for text fit(the default value is 100.f)<br />
891         /// - stepSize (float type) : Step Size for font increase(the default value is 1.f)<br />
892         /// - fontSize (string type) : The size type of font, You can choose between "pointSize" or "pixelSize". (the default value is "pointSize")<br />
893         /// </summary>
894         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
895         [EditorBrowsable(EditorBrowsableState.Never)]
896         public PropertyMap TextFit
897         {
898             get
899             {
900                 return (PropertyMap)GetValue(TextFitProperty);
901             }
902             set
903             {
904                 SetValue(TextFitProperty, value);
905                 NotifyPropertyChanged();
906             }
907         }
908
909         /// <summary>
910         /// The MinLineSize property.<br />
911         /// </summary>
912         /// <since_tizen> 8 </since_tizen>
913         [EditorBrowsable(EditorBrowsableState.Never)]
914         public float MinLineSize
915         {
916             get
917             {
918                 return (float)GetValue(MinLineSizeProperty);
919             }
920             set
921             {
922                 SetValue(MinLineSizeProperty, value);
923                 NotifyPropertyChangedAndRequestLayout();
924             }
925         }
926
927         /// <summary>
928         /// The FontSizeScale property. <br />
929         /// The default value is 1.0. <br />
930         /// If FontSizeScale.UseSystemSetting, will use the SystemSettings.FontSize internally. <br />
931         /// </summary>
932         /// <since_tizen> 9 </since_tizen>
933         public float FontSizeScale
934         {
935             get
936             {
937                 return fontSizeScale;
938             }
939             set
940             {
941                 float newFontSizeScale;
942
943                 if (fontSizeScale == value) return;
944
945                 fontSizeScale = value;
946                 if (fontSizeScale == Tizen.NUI.FontSizeScale.UseSystemSetting)
947                 {
948                     SystemSettingsFontSize systemSettingsFontSize;
949
950                     try
951                     {
952                         systemSettingsFontSize = SystemSettings.FontSize;
953                     }
954                     catch (Exception e)
955                     {
956                         Console.WriteLine("{0} Exception caught.", e);
957                         systemSettingsFontSize = SystemSettingsFontSize.Normal;
958                     }
959                     newFontSizeScale = TextUtils.GetFontSizeScale(systemSettingsFontSize);
960                     addFontSizeChangedCallback();
961                 }
962                 else
963                 {
964                     newFontSizeScale = fontSizeScale;
965                     removeFontSizeChangedCallback();
966                 }
967
968                 SetValue(FontSizeScaleProperty, newFontSizeScale);
969                 NotifyPropertyChangedAndRequestLayout();
970             }
971         }
972
973         private TextLabelSelectorData SelectorData
974         {
975             get
976             {
977                 if (selectorData == null)
978                 {
979                     selectorData = new TextLabelSelectorData();
980                 }
981                 return selectorData;
982             }
983         }
984
985         /// <summary>
986         /// Downcasts a handle to textLabel handle
987         /// </summary>
988         /// <param name="handle"></param>
989         /// <returns></returns>
990         /// <exception cref="ArgumentNullException"> Thrown when handle is null. </exception>
991         /// <since_tizen> 3 </since_tizen>
992         /// Please do not use! this will be deprecated!
993         /// Instead please use as keyword.
994         [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead! " +
995             "Like: " +
996             "BaseHandle handle = new TextLabel(\"Hello World!\"); " +
997             "TextLabel label = handle as TextLabel")]
998         [EditorBrowsable(EditorBrowsableState.Never)]
999         public static TextLabel DownCast(BaseHandle handle)
1000         {
1001             if (null == handle)
1002             {
1003                 throw new ArgumentNullException(nameof(handle));
1004             }
1005             TextLabel ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TextLabel;
1006             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
1007             return ret;
1008         }
1009
1010         /// <inheritdoc/>
1011         [EditorBrowsable(EditorBrowsableState.Never)]
1012         protected override void Dispose(DisposeTypes type)
1013         {
1014             if (disposed)
1015             {
1016                 return;
1017             }
1018
1019             if (systemlangTextFlag)
1020             {
1021                 SystemSettings.LocaleLanguageChanged -= SystemSettings_LocaleLanguageChanged;
1022             }
1023
1024             removeFontSizeChangedCallback();
1025
1026             if (type == DisposeTypes.Explicit)
1027             {
1028                 //Called by User
1029                 //Release your own managed resources here.
1030                 //You should release all of your own disposable objects here.
1031                 selectorData?.Reset(this);
1032             }
1033
1034             base.Dispose(type);
1035         }
1036
1037         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TextLabel obj)
1038         {
1039             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
1040         }
1041
1042         /// This will not be public opened.
1043         [EditorBrowsable(EditorBrowsableState.Never)]
1044         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
1045         {
1046             Interop.TextLabel.DeleteTextLabel(swigCPtr);
1047         }
1048
1049         /// <summary>
1050         /// Get attribues, it is abstract function and must be override.
1051         /// </summary>
1052         [EditorBrowsable(EditorBrowsableState.Never)]
1053         protected override ViewStyle CreateViewStyle()
1054         {
1055             return new TextLabelStyle();
1056         }
1057
1058         /// <summary>
1059         /// Invoked whenever the binding context of the textlabel changes. Implement this method to add class handling for this event.
1060         /// </summary>
1061         protected override void OnBindingContextChanged()
1062         {
1063             base.OnBindingContextChanged();
1064         }
1065
1066         private void SystemSettings_LocaleLanguageChanged(object sender, LocaleLanguageChangedEventArgs e)
1067         {
1068             Text = NUIApplication.MultilingualResourceManager?.GetString(textLabelSid, new CultureInfo(e.Value.Replace("_", "-")));
1069         }
1070
1071         private void SystemSettingsFontSizeChanged(object sender, FontSizeChangedEventArgs e)
1072         {
1073             float newFontSizeScale = TextUtils.GetFontSizeScale(e.Value);
1074             SetValue(FontSizeScaleProperty, newFontSizeScale);
1075             NotifyPropertyChangedAndRequestLayout();
1076         }
1077
1078         private void addFontSizeChangedCallback()
1079         {
1080             if (hasFontSizeChangedCallback != true)
1081             {
1082                 try
1083                 {
1084                     SystemSettings.FontSizeChanged += SystemSettingsFontSizeChanged;
1085                     hasFontSizeChangedCallback = true;
1086                 }
1087                 catch (Exception e)
1088                 {
1089                     Console.WriteLine("{0} Exception caught.", e);
1090                     hasFontSizeChangedCallback = false;
1091                 }
1092             }
1093         }
1094
1095         private void removeFontSizeChangedCallback()
1096         {
1097             if (hasFontSizeChangedCallback == true)
1098             {
1099                 try
1100                 {
1101                     SystemSettings.FontSizeChanged -= SystemSettingsFontSizeChanged;
1102                     hasFontSizeChangedCallback = false;
1103                 }
1104                 catch (Exception e)
1105                 {
1106                     Console.WriteLine("{0} Exception caught.", e);
1107                     hasFontSizeChangedCallback = true;
1108                 }
1109             }
1110         }
1111
1112         private void NotifyPropertyChangedAndRequestLayout()
1113         {
1114             NotifyPropertyChanged();
1115             Layout?.RequestLayout();
1116         }
1117
1118         internal new class Property
1119         {
1120             internal static readonly int TEXT = Interop.TextLabel.TextGet();
1121             internal static readonly int FontFamily = Interop.TextLabel.FontFamilyGet();
1122             internal static readonly int FontStyle = Interop.TextLabel.FontStyleGet();
1123             internal static readonly int PointSize = Interop.TextLabel.PointSizeGet();
1124             internal static readonly int MultiLine = Interop.TextLabel.MultiLineGet();
1125             internal static readonly int HorizontalAlignment = Interop.TextLabel.HorizontalAlignmentGet();
1126             internal static readonly int VerticalAlignment = Interop.TextLabel.VerticalAlignmentGet();
1127             internal static readonly int TextColor = Interop.TextLabel.TextColorGet();
1128             internal static readonly int EnableMarkup = Interop.TextLabel.EnableMarkupGet();
1129             internal static readonly int EnableAutoScroll = Interop.TextLabel.EnableAutoScrollGet();
1130             internal static readonly int AutoScrollSpeed = Interop.TextLabel.AutoScrollSpeedGet();
1131             internal static readonly int AutoScrollLoopCount = Interop.TextLabel.AutoScrollLoopCountGet();
1132             internal static readonly int AutoScrollGap = Interop.TextLabel.AutoScrollGapGet();
1133             internal static readonly int LineSpacing = Interop.TextLabel.LineSpacingGet();
1134             internal static readonly int UNDERLINE = Interop.TextLabel.UnderlineGet();
1135             internal static readonly int SHADOW = Interop.TextLabel.ShadowGet();
1136             internal static readonly int EMBOSS = Interop.TextLabel.EmbossGet();
1137             internal static readonly int OUTLINE = Interop.TextLabel.OutlineGet();
1138             internal static readonly int PixelSize = Interop.TextLabel.PixelSizeGet();
1139             internal static readonly int ELLIPSIS = Interop.TextLabel.EllipsisGet();
1140             internal static readonly int AutoScrollStopMode = Interop.TextLabel.AutoScrollStopModeGet();
1141             internal static readonly int AutoScrollLoopDelay = Interop.TextLabel.AutoScrollLoopDelayGet();
1142             internal static readonly int LineCount = Interop.TextLabel.LineCountGet();
1143             internal static readonly int LineWrapMode = Interop.TextLabel.LineWrapModeGet();
1144             internal static readonly int TextDirection = Interop.TextLabel.TextDirectionGet();
1145             internal static readonly int VerticalLineAlignment = Interop.TextLabel.VerticalLineAlignmentGet();
1146             internal static readonly int MatchSystemLanguageDirection = Interop.TextLabel.MatchSystemLanguageDirectionGet();
1147             internal static readonly int TextFit = Interop.TextLabel.TextFitGet();
1148             internal static readonly int MinLineSize = Interop.TextLabel.MinLineSizeGet();
1149             internal static readonly int FontSizeScale = Interop.TextLabel.FontSizeScaleGet();
1150         }
1151
1152         private void OnShadowColorChanged(float x, float y, float z, float w)
1153         {
1154             ShadowColor = new Vector4(x, y, z, w);
1155         }
1156         private void OnShadowOffsetChanged(float x, float y)
1157         {
1158             ShadowOffset = new Vector2(x, y);
1159         }
1160         private void OnTextColorChanged(float r, float g, float b, float a)
1161         {
1162             TextColor = new Color(r, g, b, a);
1163         }
1164         private void OnUnderlineColorChanged(float x, float y, float z, float w)
1165         {
1166             UnderlineColor = new Vector4(x, y, z, w);
1167         }
1168     }
1169 }