[NUI.Components] Fix build warnings (#1233)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / Button.cs
1 /*
2  * Copyright(c) 2019 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 using System;
18 using System.ComponentModel;
19 using Tizen.NUI.BaseComponents;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI.Components
23 {
24     /// <summary>
25     /// Button is one kind of common component, a button clearly describes what action will occur when the user selects it.
26     /// Button may contain text or an icon.
27     /// </summary>
28     /// <since_tizen> 6 </since_tizen>
29     public class Button : Control
30     {
31         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
32         [EditorBrowsable(EditorBrowsableState.Never)]
33         public static readonly BindableProperty IconRelativeOrientationProperty = BindableProperty.Create(nameof(IconRelativeOrientation), typeof(IconOrientation?), typeof(Button), null, propertyChanged: (bindable, oldValue, newValue) =>
34         {
35             var instance = (Button)bindable;
36             if (newValue != null)
37             {
38                 instance.privateIconRelativeOrientation = (IconOrientation?)newValue;
39             }
40         },
41         defaultValueCreator: (bindable) =>
42         {
43             var instance = (Button)bindable;
44             return instance.privateIconRelativeOrientation;
45         });
46         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
47         [EditorBrowsable(EditorBrowsableState.Never)]
48         public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(Button), true, propertyChanged: (bindable, oldValue, newValue) =>
49         {
50             var instance = (Button)bindable;
51             if (newValue != null)
52             {
53                 instance.privateIsEnabled = (bool)newValue;
54             }
55         },
56         defaultValueCreator: (bindable) =>
57         {
58             var instance = (Button)bindable;
59             return instance.privateIsEnabled;
60         });
61         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
62         [EditorBrowsable(EditorBrowsableState.Never)]
63         public static readonly BindableProperty IsSelectedProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool), typeof(Button), true, propertyChanged: (bindable, oldValue, newValue) =>
64         {
65             var instance = (Button)bindable;
66             if (newValue != null)
67             {
68                 instance.privateIsSelected = (bool)newValue;
69             }
70         },
71         defaultValueCreator: (bindable) =>
72         {
73             var instance = (Button)bindable;
74             return instance.privateIsSelected;
75         });
76         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
77         [EditorBrowsable(EditorBrowsableState.Never)]
78         public static readonly BindableProperty IsSelectableProperty = BindableProperty.Create(nameof(IsSelectable), typeof(bool), typeof(Button), true, propertyChanged: (bindable, oldValue, newValue) =>
79         {
80             var instance = (Button)bindable;
81             if (newValue != null)
82             {
83                 instance.privateIsSelectable = (bool)newValue;
84             }
85         },
86         defaultValueCreator: (bindable) =>
87         {
88             var instance = (Button)bindable;
89             return instance.privateIsSelectable;
90         });
91         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
92         [EditorBrowsable(EditorBrowsableState.Never)]
93         public static readonly BindableProperty IconPaddingProperty = BindableProperty.Create(nameof(IconPadding), typeof(Extents), typeof(Button), null, propertyChanged: (bindable, oldValue, newValue) =>
94         {
95             var instance = (Button)bindable;
96             if (null != newValue && null != instance.Style?.IconPadding)
97             {
98                 instance.Style.IconPadding.CopyFrom((Extents)newValue);
99                 instance.UpdateUIContent();
100             }
101         },
102         defaultValueCreator: (bindable) =>
103         {
104             var instance = (Button)bindable;
105             return instance.Style?.IconPadding;
106         });
107         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
108         [EditorBrowsable(EditorBrowsableState.Never)]
109         public static readonly BindableProperty TextPaddingProperty = BindableProperty.Create(nameof(TextPadding), typeof(Extents), typeof(Button), null, propertyChanged: (bindable, oldValue, newValue) =>
110         {
111             var instance = (Button)bindable;
112             if (null != newValue && null != instance.Style?.TextPadding)
113             {
114                 instance.Style.TextPadding.CopyFrom((Extents)newValue);
115                 instance.UpdateUIContent();
116             }
117         },
118         defaultValueCreator: (bindable) =>
119         {
120             var instance = (Button)bindable;
121             return instance.Style?.TextPadding;
122         });
123
124         private ImageView overlayImage;
125
126         private TextLabel buttonText;
127         private ImageControl buttonIcon;
128
129         private EventHandler<StateChangedEventArgs> stateChangeHander;
130
131         private bool isSelected = false;
132         private bool isEnabled = true;
133         private bool isPressed = false;
134
135         /// <summary>
136         /// Creates a new instance of a Button.
137         /// </summary>
138         /// <since_tizen> 6 </since_tizen>
139         public Button() : base()
140         {
141             Initialize();
142         }
143
144         /// <summary>
145         /// Creates a new instance of a Button with style.
146         /// </summary>
147         /// <param name="style">Create Button by special style defined in UX.</param>
148         /// <since_tizen> 6 </since_tizen>
149         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
150         [EditorBrowsable(EditorBrowsableState.Never)]
151         public Button(string style) : base(style)
152         {
153             Initialize();
154         }
155
156         /// <summary>
157         /// Creates a new instance of a Button with attributes.
158         /// </summary>
159         /// <param name="controlStyle">Create Button by attributes customized by user.</param>
160         /// <since_tizen> 6 </since_tizen>
161         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
162         [EditorBrowsable(EditorBrowsableState.Never)]
163         public Button(ButtonStyle controlStyle) : base(controlStyle)
164         {
165             Initialize();
166         }
167
168         /// <summary>
169         /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
170         /// </summary>
171         /// <since_tizen> 6 </since_tizen>
172         public event EventHandler<ClickEventArgs> ClickEvent;
173         /// <summary>
174         /// An event for the button state changed signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
175         /// </summary>
176         /// <since_tizen> 6 </since_tizen>
177         public event EventHandler<StateChangedEventArgs> StateChangedEvent
178         {
179             add
180             {
181                 stateChangeHander += value;
182             }
183             remove
184             {
185                 stateChangeHander -= value;
186             }
187         }
188         /// <summary>
189         /// Icon orientation.
190         /// </summary>
191         /// <since_tizen> 6 </since_tizen>
192         public enum IconOrientation
193         {
194             /// <summary>
195             /// Top.
196             /// </summary>
197             /// <since_tizen> 6 </since_tizen>
198             Top,
199             /// <summary>
200             /// Bottom.
201             /// </summary>
202             /// <since_tizen> 6 </since_tizen>
203             Bottom,
204             /// <summary>
205             /// Left.
206             /// </summary>
207             /// <since_tizen> 6 </since_tizen>
208             Left,
209             /// <summary>
210             /// Right.
211             /// </summary>
212             /// <since_tizen> 6 </since_tizen>
213             Right,
214         }
215
216         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
217         [EditorBrowsable(EditorBrowsableState.Never)]
218         public new ButtonStyle Style => ViewStyle as ButtonStyle;
219
220         /// <summary>
221         /// The text of Button.
222         /// </summary>
223         /// <since_tizen> 6 </since_tizen>
224         public string Text
225         {
226             get
227             {
228                 return Style?.Text?.Text?.GetValue(ControlState);
229             }
230             set
231             {
232                 if (null != Style?.Text)
233                 {
234                     Style.Text.Text = value;
235                 }
236             }
237         }
238
239         /// <summary>
240         /// Flag to decide Button can be selected or not.
241         /// </summary>
242         /// <since_tizen> 6 </since_tizen>
243         public bool IsSelectable
244         {
245             get
246             {
247                 return (bool)GetValue(IsSelectableProperty);
248             }
249             set
250             {
251                 SetValue(IsSelectableProperty, value);
252             }
253         }
254
255         private bool privateIsSelectable
256         {
257             get
258             {
259                 return Style?.IsSelectable ?? false;
260             }
261             set
262             {
263                 Style.IsSelectable = value;
264             }
265         }
266
267         /// <summary>
268         /// Translate text string in Button.
269         /// </summary>
270         /// <since_tizen> 6 </since_tizen>
271         public string TranslatableText
272         {
273             get
274             {
275                 return Style?.Text?.TranslatableText?.All;
276             }
277             set
278             {
279                 if (null != Style?.Text)
280                 {
281                     Style.Text.TranslatableText = value;
282                 }
283             }
284         }
285
286         /// <summary>
287         /// Text point size in Button.
288         /// </summary>
289         /// <since_tizen> 6 </since_tizen>
290         public float PointSize
291         {
292             get
293             {
294                 return Style?.Text?.PointSize?.All ?? 0;
295             }
296             set
297             {
298                 if (null != Style?.Text)
299                 {
300                     Style.Text.PointSize = value;
301                 }
302             }
303         }
304
305         /// <summary>
306         /// Text font family in Button.
307         /// </summary>
308         /// <since_tizen> 6 </since_tizen>
309         public string FontFamily
310         {
311             get
312             {
313                 return Style?.Text?.FontFamily.All;
314             }
315             set
316             {
317                 if (null != Style?.Text)
318                 {
319                     Style.Text.FontFamily = value;
320                 }
321             }
322         }
323         /// <summary>
324         /// Text color in Button.
325         /// </summary>
326         /// <since_tizen> 6 </since_tizen>
327         public Color TextColor
328         {
329             get
330             {
331                 return Style?.Text?.TextColor?.All;
332             }
333             set
334             {
335                 if (null != Style?.Text)
336                 {
337                     Style.Text.TextColor = value;
338                 }
339             }
340         }
341         /// <summary>
342         /// Text horizontal alignment in Button.
343         /// </summary>
344         /// <since_tizen> 6 </since_tizen>
345         public HorizontalAlignment TextAlignment
346         {
347             get
348             {
349                 return Style?.Text?.HorizontalAlignment ?? HorizontalAlignment.Center;
350             }
351             set
352             {
353                 if (null != Style?.Text)
354                 {
355                     Style.Text.HorizontalAlignment = value;
356                 }
357             }
358         }
359         /// <summary>
360         /// Icon image's resource url in Button.
361         /// </summary>
362         /// <since_tizen> 6 </since_tizen>
363         public string IconURL
364         {
365             get
366             {
367                 return Style?.Icon?.ResourceUrl?.All;
368             }
369             set
370             {
371                 if (null != Style?.Icon)
372                 {
373                     Style.Icon.ResourceUrl = value;
374                 }
375             }
376         }
377
378         private StringSelector textSelector = new StringSelector();
379         /// <summary>
380         /// Text string selector in Button.
381         /// </summary>
382         /// <since_tizen> 6 </since_tizen>
383         public StringSelector TextSelector
384         {
385             get
386             {
387                 return textSelector;
388             }
389             set
390             {
391                 textSelector.Clone(value);
392             }
393         }
394
395         private StringSelector translatableTextSelector = new StringSelector();
396         /// <summary>
397         /// Translateable text string selector in Button.
398         /// </summary>
399         /// <since_tizen> 6 </since_tizen>
400         public StringSelector TranslatableTextSelector
401         {
402             get
403             {
404                 return translatableTextSelector;
405             }
406             set
407             {
408                 translatableTextSelector.Clone(value);
409             }
410         }
411
412         private ColorSelector textColorSelector = new ColorSelector();
413         /// <summary>
414         /// Text color selector in Button.
415         /// </summary>
416         /// <since_tizen> 6 </since_tizen>
417         public ColorSelector TextColorSelector
418         {
419             get
420             {
421                 return textColorSelector;
422             }
423             set
424             {
425                 textColorSelector.Clone(value);
426             }
427         }
428
429         private FloatSelector pointSizeSelector = new FloatSelector();
430         /// <summary>
431         /// Text font size selector in Button.
432         /// </summary>
433         /// <since_tizen> 6 </since_tizen>
434         public FloatSelector PointSizeSelector
435         {
436             get
437             {
438                 return pointSizeSelector;
439             }
440             set
441             {
442                 pointSizeSelector.Clone(value);
443             }
444         }
445
446         private StringSelector iconURLSelector = new StringSelector();
447         /// <summary>
448         /// Icon image's resource url selector in Button.
449         /// </summary>
450         /// <since_tizen> 6 </since_tizen>
451         public StringSelector IconURLSelector
452         {
453             get
454             {
455                 return iconURLSelector;
456             }
457             set
458             {
459                 iconURLSelector.Clone(value);
460             }
461         }
462
463         /// <summary>
464         /// Flag to decide selected state in Button.
465         /// </summary>
466         /// <since_tizen> 6 </since_tizen>
467         public bool IsSelected
468         {
469             get
470             {
471                 return (bool)GetValue(IsSelectedProperty);
472             }
473             set
474             {
475                 SetValue(IsSelectedProperty, value);
476             }
477         }
478         private bool privateIsSelected
479         {
480             get
481             {
482                 return isSelected;
483             }
484             set
485             {
486                 isSelected = value;
487                 UpdateState();
488             }
489         }
490         /// <summary>
491         /// Flag to decide enable or disable in Button.
492         /// </summary>
493         /// <since_tizen> 6 </since_tizen>
494         public bool IsEnabled
495         {
496             get
497             {
498                 return (bool)GetValue(IsEnabledProperty);
499             }
500             set
501             {
502                 SetValue(IsEnabledProperty, value);
503             }
504         }
505         private bool privateIsEnabled
506         {
507             get
508             {
509                 return isEnabled;
510             }
511             set
512             {
513                 isEnabled = value;
514                 UpdateState();
515             }
516         }
517
518         /// <summary>
519         /// Icon relative orientation in Button, work only when show icon and text.
520         /// </summary>
521         /// <since_tizen> 6 </since_tizen>
522         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
523         [EditorBrowsable(EditorBrowsableState.Never)]
524         public IconOrientation? IconRelativeOrientation
525         {
526             get
527             {
528                 return (IconOrientation?)GetValue(IconRelativeOrientationProperty);
529             }
530             set
531             {
532                 SetValue(IconRelativeOrientationProperty, value);
533             }
534         }
535         private IconOrientation? privateIconRelativeOrientation
536         {
537             get
538             {
539                 return Style?.IconRelativeOrientation;
540             }
541             set
542             {
543                 if(Style != null && Style.IconRelativeOrientation != value)
544                 {
545                     Style.IconRelativeOrientation = value;
546                     UpdateUIContent();
547                 }
548             }
549         }
550
551         /// <summary>
552         /// Icon padding in Button, work only when show icon and text.
553         /// </summary>
554         /// <since_tizen> 6 </since_tizen>
555         public Extents IconPadding
556         {
557             get => (Extents)GetValue(IconPaddingProperty);
558             set => SetValue(IconPaddingProperty, value);
559         }
560
561         /// <summary>
562         /// Text padding in Button, work only when show icon and text.
563         /// </summary>
564         /// <since_tizen> 6 </since_tizen>
565         public Extents TextPadding
566         {
567             get => (Extents) GetValue(TextPaddingProperty);
568             set => SetValue(TextPaddingProperty, value);
569         }
570
571         /// <summary>
572         /// Dispose Button and all children on it.
573         /// </summary>
574         /// <param name="type">Dispose type.</param>
575         /// <since_tizen> 6 </since_tizen>
576         protected override void Dispose(DisposeTypes type)
577         {
578             if (disposed)
579             {
580                 return;
581             }
582
583             if (type == DisposeTypes.Explicit)
584             {
585                 if (buttonIcon != null)
586                 {
587                     Utility.Dispose(buttonIcon);
588                 }
589                 if (buttonText != null)
590                 {
591                     Utility.Dispose(buttonText);
592                 }
593                 if (overlayImage != null)
594                 {
595                     Utility.Dispose(overlayImage);
596                 }
597             }
598
599             base.Dispose(type);
600         }
601         /// <summary>
602         /// Called after a key event is received by the view that has had its focus set.
603         /// </summary>
604         /// <param name="key">The key event.</param>
605         /// <returns>True if the key event should be consumed.</returns>
606         /// <since_tizen> 6 </since_tizen>
607         public override bool OnKey(Key key)
608         {
609             if (null == key) return false;
610             if (key.State == Key.StateType.Down)
611             {
612                 if (key.KeyPressedName == "Return")
613                 {
614                     isPressed = true;
615                     UpdateState();
616                     if(isEnabled)
617                     {
618                         ClickEventArgs eventArgs = new ClickEventArgs();
619                         OnClick(eventArgs);
620                     }
621                 }
622             }
623             else if (key.State == Key.StateType.Up)
624             {
625                 if (key.KeyPressedName == "Return")
626                 {
627                     isPressed = false;
628                     if (Style.IsSelectable != null && Style.IsSelectable == true)
629                     {
630                         isSelected = !isSelected;
631                     }
632                     UpdateState();
633                 }
634             }
635             return base.OnKey(key);
636         }
637
638         /// <summary>
639         /// Called when the control gain key input focus. Should be overridden by derived classes if they need to customize what happens when the focus is gained.
640         /// </summary>
641         /// <since_tizen> 6 </since_tizen>
642         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
643         [EditorBrowsable(EditorBrowsableState.Never)]
644         public override void OnFocusGained()
645         {
646             base.OnFocusGained();
647             UpdateState();
648         }
649
650         /// <summary>
651         /// Called when the control loses key input focus. Should be overridden by derived classes if they need to customize what happens when the focus is lost.
652         /// </summary>
653         /// <since_tizen> 6 </since_tizen>
654         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
655         [EditorBrowsable(EditorBrowsableState.Never)]
656         public override void OnFocusLost()
657         {
658             base.OnFocusLost();
659             UpdateState();
660         }
661
662         /// <summary>
663         /// Tap gesture event callback.
664         /// </summary>
665         /// <param name="source">Source which recieved touch event.</param>
666         /// <param name="e">Tap gesture event argument.</param>
667         /// <since_tizen> 6 </since_tizen>
668         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
669         [EditorBrowsable(EditorBrowsableState.Never)]
670         protected override void OnTapGestureDetected(object source, TapGestureDetector.DetectedEventArgs e)
671         {
672             if (isEnabled)
673             {
674                 ClickEventArgs eventArgs = new ClickEventArgs();
675                 OnClick(eventArgs);
676                 base.OnTapGestureDetected(source, e);
677             }
678         }
679         /// <summary>
680         /// Called after a touch event is received by the owning view.<br />
681         /// CustomViewBehaviour.REQUIRES_TOUCH_EVENTS must be enabled during construction. See CustomView(ViewWrapperImpl.CustomViewBehaviour behaviour).<br />
682         /// </summary>
683         /// <param name="touch">The touch event.</param>
684         /// <returns>True if the event should be consumed.</returns>
685         /// <since_tizen> 6 </since_tizen>
686         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
687         [EditorBrowsable(EditorBrowsableState.Never)]
688         public override bool OnTouch(Touch touch)
689         {
690             if (null == touch) return false;
691             PointStateType state = touch.GetState(0);
692
693             switch(state)
694             {
695                 case PointStateType.Down:
696                     isPressed = true;
697                     UpdateState();
698                     return true;
699                 case PointStateType.Interrupted:
700                     isPressed = false;
701                     UpdateState();
702                     return true;
703                 case PointStateType.Up:
704                     isPressed = false;
705                     if (Style.IsSelectable != null && Style.IsSelectable == true)
706                     {
707                         isSelected = !isSelected;
708                     }
709                     UpdateState();
710                     return true;
711                 default:
712                     break;
713             }
714             return base.OnTouch(touch);
715         }
716
717         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
718         [EditorBrowsable(EditorBrowsableState.Never)]
719         public override void ApplyStyle(ViewStyle viewStyle)
720         {
721             base.ApplyStyle(viewStyle);
722
723             ButtonStyle buttonStyle = viewStyle as ButtonStyle;
724
725             if (null != buttonStyle)
726             {
727                 if (null == overlayImage)
728                 {
729                     overlayImage = new ImageView()
730                     {
731                         WidthResizePolicy = ResizePolicyType.FillToParent,
732                         HeightResizePolicy = ResizePolicyType.FillToParent
733                     };
734                     this.Add(overlayImage);
735                 }
736
737                 if (null == buttonText)
738                 {
739                     buttonText = new TextLabel();
740                     this.Add(buttonText);
741                 }
742
743                 if (null == buttonIcon)
744                 {
745                     buttonIcon = new ImageControl();
746                     this.Add(buttonIcon);
747                 }
748
749                 overlayImage.ApplyStyle(buttonStyle.Overlay);
750                 buttonText.ApplyStyle(buttonStyle.Text);
751                 buttonIcon.ApplyStyle(buttonStyle.Icon);
752             }
753         }
754
755         /// <summary>
756         /// Get Button attribues.
757         /// </summary>
758         /// <since_tizen> 6 </since_tizen>
759         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
760         [EditorBrowsable(EditorBrowsableState.Never)]
761         protected override ViewStyle GetViewStyle()
762         {
763             return new ButtonStyle();
764         }
765
766         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
767         [EditorBrowsable(EditorBrowsableState.Never)]
768         protected override void OnUpdate()
769         {
770             base.OnUpdate();
771             UpdateUIContent();
772         }
773
774         /// <summary>
775         /// Update Button State.
776         /// </summary>
777         /// <since_tizen> 6 </since_tizen>
778         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
779         [EditorBrowsable(EditorBrowsableState.Never)]
780         protected void UpdateState()
781         {
782             ControlStates sourceState = ControlState;
783             ControlStates targetState;
784
785             if(isEnabled)
786             {
787                 targetState = isPressed ? ControlStates.Pressed : (IsFocused ? (IsSelected ? ControlStates.SelectedFocused : ControlStates.Focused) : (IsSelected ? ControlStates.Selected : ControlStates.Normal));
788             }
789             else
790             {
791                 targetState = IsSelected ? ControlStates.DisabledSelected : (IsFocused ? ControlStates.DisabledFocused : ControlStates.Disabled);
792             }
793
794             if(sourceState != targetState)
795             {
796                 ControlState = targetState;
797
798                 OnUpdate();
799
800                 StateChangedEventArgs e = new StateChangedEventArgs
801                 {
802                     PreviousState = sourceState,
803                     CurrentState = targetState
804                 };
805                 stateChangeHander?.Invoke(this, e);
806             }
807         }
808
809         /// <summary>
810         /// It is hijack by using protected, attributes copy problem when class inherited from Button.
811         /// </summary>
812         /// <since_tizen> 6 </since_tizen>
813         private void Initialize()
814         {
815             if (null == Style.IconRelativeOrientation) Style.IconRelativeOrientation = IconOrientation.Left;
816             UpdateState();
817             LayoutDirectionChanged += OnLayoutDirectionChanged;
818         }
819
820         /// <summary>
821         /// Measure text, it can be override.
822         /// </summary>
823         /// <since_tizen> 6 </since_tizen>
824         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
825         [EditorBrowsable(EditorBrowsableState.Never)]
826         protected virtual void MeasureText()
827         {
828             if (Style.IconRelativeOrientation == null || buttonIcon == null || buttonText == null)
829             {
830                 return;
831             }
832             buttonText.WidthResizePolicy = ResizePolicyType.Fixed;
833             buttonText.HeightResizePolicy = ResizePolicyType.Fixed;
834             int textPaddingStart = Style.TextPadding.Start;
835             int textPaddingEnd = Style.TextPadding.End;
836             int textPaddingTop = Style.TextPadding.Top;
837             int textPaddingBottom = Style.TextPadding.Bottom;
838
839             int iconPaddingStart = Style.IconPadding.Start;
840             int iconPaddingEnd = Style.IconPadding.End;
841             int iconPaddingTop = Style.IconPadding.Top;
842             int iconPaddingBottom = Style.IconPadding.Bottom;
843
844             if (IconRelativeOrientation == IconOrientation.Top || IconRelativeOrientation == IconOrientation.Bottom)
845             {
846                 buttonText.SizeWidth = SizeWidth - textPaddingStart - textPaddingEnd;
847                 buttonText.SizeHeight = SizeHeight - textPaddingTop - textPaddingBottom - iconPaddingTop - iconPaddingBottom - buttonIcon.SizeHeight;
848             }
849             else
850             {
851                 buttonText.SizeWidth = SizeWidth - textPaddingStart - textPaddingEnd - iconPaddingStart - iconPaddingEnd - buttonIcon.SizeWidth;
852                 buttonText.SizeHeight = SizeHeight - textPaddingTop - textPaddingBottom;
853             }
854         }
855         /// <summary>
856         /// Layout child, it can be override.
857         /// </summary>
858         /// <since_tizen> 6 </since_tizen>
859         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
860         [EditorBrowsable(EditorBrowsableState.Never)]
861         protected virtual void LayoutChild()
862         {
863             if (Style.IconRelativeOrientation == null || buttonIcon == null || buttonText == null)
864             {
865                 return;
866             }
867
868             int textPaddingStart = Style.TextPadding.Start;
869             int textPaddingEnd = Style.TextPadding.End;
870             int textPaddingTop = Style.TextPadding.Top;
871             int textPaddingBottom = Style.TextPadding.Bottom;
872
873             int iconPaddingStart = Style.IconPadding.Start;
874             int iconPaddingEnd = Style.IconPadding.End;
875             int iconPaddingTop = Style.IconPadding.Top;
876             int iconPaddingBottom = Style.IconPadding.Bottom;
877
878             switch (IconRelativeOrientation)
879             {
880                 case IconOrientation.Top:
881                     buttonIcon.PositionUsesPivotPoint = true;
882                     buttonIcon.ParentOrigin = NUI.ParentOrigin.TopCenter;
883                     buttonIcon.PivotPoint = NUI.PivotPoint.TopCenter;
884                     buttonIcon.Position2D = new Position2D(0, iconPaddingTop);
885
886                     buttonText.PositionUsesPivotPoint = true;
887                     buttonText.ParentOrigin = NUI.ParentOrigin.BottomCenter;
888                     buttonText.PivotPoint = NUI.PivotPoint.BottomCenter;
889                     buttonText.Position2D = new Position2D(0, -textPaddingBottom);
890                     break;
891                 case IconOrientation.Bottom:
892                     buttonIcon.PositionUsesPivotPoint = true;
893                     buttonIcon.ParentOrigin = NUI.ParentOrigin.BottomCenter;
894                     buttonIcon.PivotPoint = NUI.PivotPoint.BottomCenter;
895                     buttonIcon.Position2D = new Position2D(0, -iconPaddingBottom);
896
897                     buttonText.PositionUsesPivotPoint = true;
898                     buttonText.ParentOrigin = NUI.ParentOrigin.TopCenter;
899                     buttonText.PivotPoint = NUI.PivotPoint.TopCenter;
900                     buttonText.Position2D = new Position2D(0, textPaddingTop);
901                     break;
902                 case IconOrientation.Left:
903                     if (LayoutDirection == ViewLayoutDirectionType.LTR)
904                     {
905                         buttonIcon.PositionUsesPivotPoint = true;
906                         buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterLeft;
907                         buttonIcon.PivotPoint = NUI.PivotPoint.CenterLeft;
908                         buttonIcon.Position2D = new Position2D(iconPaddingStart, 0);
909
910                         buttonText.PositionUsesPivotPoint = true;
911                         buttonText.ParentOrigin = NUI.ParentOrigin.CenterRight;
912                         buttonText.PivotPoint = NUI.PivotPoint.CenterRight;
913                         buttonText.Position2D = new Position2D(-textPaddingEnd, 0);
914                     }
915                     else
916                     {
917                         buttonIcon.PositionUsesPivotPoint = true;
918                         buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterRight;
919                         buttonIcon.PivotPoint = NUI.PivotPoint.CenterRight;
920                         buttonIcon.Position2D = new Position2D(-iconPaddingStart, 0);
921
922                         buttonText.PositionUsesPivotPoint = true;
923                         buttonText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
924                         buttonText.PivotPoint = NUI.PivotPoint.CenterLeft;
925                         buttonText.Position2D = new Position2D(textPaddingEnd, 0);
926                     }
927
928                     break;
929                 case IconOrientation.Right:
930                     if (LayoutDirection == ViewLayoutDirectionType.RTL)
931                     {
932                         buttonIcon.PositionUsesPivotPoint = true;
933                         buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterLeft;
934                         buttonIcon.PivotPoint = NUI.PivotPoint.CenterLeft;
935                         buttonIcon.Position2D = new Position2D(iconPaddingEnd, 0);
936
937                         buttonText.PositionUsesPivotPoint = true;
938                         buttonText.ParentOrigin = NUI.ParentOrigin.CenterRight;
939                         buttonText.PivotPoint = NUI.PivotPoint.CenterRight;
940                         buttonText.Position2D = new Position2D(-textPaddingStart, 0);
941                     }
942                     else
943                     {
944                         buttonIcon.PositionUsesPivotPoint = true;
945                         buttonIcon.ParentOrigin = NUI.ParentOrigin.CenterRight;
946                         buttonIcon.PivotPoint = NUI.PivotPoint.CenterRight;
947                         buttonIcon.Position2D = new Position2D(-iconPaddingEnd, 0);
948
949                         buttonText.PositionUsesPivotPoint = true;
950                         buttonText.ParentOrigin = NUI.ParentOrigin.CenterLeft;
951                         buttonText.PivotPoint = NUI.PivotPoint.CenterLeft;
952                         buttonText.Position2D = new Position2D(textPaddingStart, 0);
953                     }
954                     break;
955                 default:
956                     break;
957             }
958             if (string.IsNullOrEmpty(buttonText.Text))
959             {
960                 buttonIcon.ParentOrigin = NUI.ParentOrigin.Center;
961                 buttonIcon.PivotPoint = NUI.PivotPoint.Center;
962             }
963         }
964         /// <summary>
965         /// Theme change callback when theme is changed, this callback will be trigger.
966         /// </summary>
967         /// <since_tizen> 6 </since_tizen>
968         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
969         [EditorBrowsable(EditorBrowsableState.Never)]
970         protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
971         {
972             ButtonStyle tempAttributes = StyleManager.Instance.GetViewStyle(style) as ButtonStyle;
973             if (tempAttributes != null)
974             {
975                 Style.CopyFrom(tempAttributes);
976                 UpdateUIContent();
977             }
978         }
979
980         private void UpdateUIContent()
981         {
982             MeasureText();
983             LayoutChild();
984
985             Sensitive = isEnabled;
986         }
987
988         private void OnLayoutDirectionChanged(object sender, LayoutDirectionChangedEventArgs e)
989         {
990             MeasureText();
991             LayoutChild();
992         }
993
994         private void OnClick(ClickEventArgs eventArgs)
995         {
996             ClickEvent?.Invoke(this, eventArgs);
997         }
998
999         private void OnIconRelayout(object sender, EventArgs e)
1000         {
1001             MeasureText();
1002             LayoutChild();
1003         }
1004
1005         /// <summary>
1006         /// ClickEventArgs is a class to record button click event arguments which will sent to user.
1007         /// </summary>
1008         /// <since_tizen> 6 </since_tizen>
1009         public class ClickEventArgs : EventArgs
1010         {
1011         }
1012         /// <summary>
1013         /// StateChangeEventArgs is a class to record button state change event arguments which will sent to user.
1014         /// </summary>
1015         /// <since_tizen> 6 </since_tizen>
1016         public class StateChangedEventArgs : EventArgs
1017         {
1018             /// <summary> previous state of Button </summary>
1019             /// <since_tizen> 6 </since_tizen>
1020             public ControlStates PreviousState;
1021             /// <summary> current state of Button </summary>
1022             /// <since_tizen> 6 </since_tizen>
1023             public ControlStates CurrentState;
1024         }
1025
1026     }
1027 }