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