[NUI] Fix button layout when resize policy is FillToParent and etc. (#2809)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / Button.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 using System;
18 using System.ComponentModel;
19 using System.Diagnostics;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Binding;
22 using Tizen.NUI.Accessibility;
23
24 namespace Tizen.NUI.Components
25 {
26     /// <summary>
27     /// ClickedEventArgs is a class to record button click event arguments which will sent to user.
28     /// </summary>
29     /// <since_tizen> 8 </since_tizen>
30     public class ClickedEventArgs : EventArgs
31     {
32     }
33
34     /// <summary>
35     /// SelectedChangedEventArgs is a class to record item selected arguments which will sent to user.
36     /// </summary>
37     /// <since_tizen> 8 </since_tizen>
38     public class SelectedChangedEventArgs : EventArgs
39     {
40         /// <summary> Selected state </summary>
41         /// <since_tizen> 8 </since_tizen>
42         public bool IsSelected { get; set; }
43     }
44
45     /// <summary>
46     /// Button is one kind of common component, a button clearly describes what action will occur when the user selects it.
47     /// Button may contain text or an icon.
48     /// </summary>
49     /// <since_tizen> 6 </since_tizen>
50     public partial class Button : Control
51     {
52         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
53         [EditorBrowsable(EditorBrowsableState.Never)]
54         public static readonly BindableProperty IconRelativeOrientationProperty = BindableProperty.Create(nameof(IconRelativeOrientation), typeof(IconOrientation?), typeof(Button), null, propertyChanged: (bindable, oldValue, newValue) =>
55         {
56             var instance = (Button)bindable;
57             var newIconOrientation = (IconOrientation?)newValue;
58             if (instance.iconRelativeOrientation != newIconOrientation)
59             {
60                 instance.iconRelativeOrientation = newIconOrientation;
61                 instance.LayoutItems();
62             }
63         },
64         defaultValueCreator: (bindable) => ((Button)bindable).iconRelativeOrientation
65         );
66
67         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
68         [EditorBrowsable(EditorBrowsableState.Never)]
69         public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(Button), true, propertyChanged: (bindable, oldValue, newValue) =>
70         {
71             var instance = (Button)bindable;
72             if (newValue != null)
73             {
74                 bool newEnabled = (bool)newValue;
75                 if (instance.isEnabled != newEnabled)
76                 {
77                     instance.isEnabled = newEnabled;
78                     instance.Sensitive = newEnabled;
79                     instance.UpdateState();
80                 }
81             }
82         },
83         defaultValueCreator: (bindable) => ((Button)bindable).isEnabled);
84         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
85         [EditorBrowsable(EditorBrowsableState.Never)]
86         public static readonly BindableProperty IsSelectedProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool), typeof(Button), true, propertyChanged: (bindable, oldValue, newValue) =>
87         {
88             var instance = (Button)bindable;
89             if (newValue != null)
90             {
91                 bool newSelected = (bool)newValue;
92                 if (instance.isSelected != newSelected)
93                 {
94                     instance.isSelected = newSelected;
95
96                     if (instance.isSelectable)
97                     {
98                         instance.UpdateState();
99                     }
100                 }
101             }
102         },
103         defaultValueCreator: (bindable) =>
104         {
105             var instance = (Button)bindable;
106             return instance.isSelectable && instance.isSelected;
107         });
108         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
109         [EditorBrowsable(EditorBrowsableState.Never)]
110         public static readonly BindableProperty IsSelectableProperty = BindableProperty.Create(nameof(IsSelectable), typeof(bool), typeof(Button), true, propertyChanged: (bindable, oldValue, newValue) =>
111         {
112             var instance = (Button)bindable;
113             if (newValue != null)
114             {
115                 bool newSelectable = (bool)newValue;
116                 if (instance.isSelectable != newSelectable)
117                 {
118                     instance.isSelectable = newSelectable;
119                     instance.UpdateState();
120                 }
121             }
122         },
123         defaultValueCreator: (bindable) => ((Button)bindable).isSelectable);
124
125         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
126         [EditorBrowsable(EditorBrowsableState.Never)]
127         public static readonly BindableProperty IconPaddingProperty = BindableProperty.Create(nameof(IconPadding), typeof(Extents), typeof(Button), null, propertyChanged: (bindable, oldValue, newValue) =>
128         {
129             var instance = (Button)bindable;
130             if (instance.buttonIcon == null)
131             {
132                 return;
133             }
134             instance.buttonIcon.Padding = (Extents)newValue;
135         },
136         defaultValueCreator: (bindable) => ((Button)bindable).buttonIcon?.Padding);
137
138         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
139         [EditorBrowsable(EditorBrowsableState.Never)]
140         public static readonly BindableProperty TextPaddingProperty = BindableProperty.Create(nameof(TextPadding), typeof(Extents), typeof(Button), null, propertyChanged: (bindable, oldValue, newValue) =>
141         {
142             var instance = (Button)bindable;
143             if (instance.buttonText == null)
144             {
145                 return;
146             }
147             instance.buttonText.Padding = (Extents)newValue;
148         },
149         defaultValueCreator: (bindable) => ((Button)bindable).buttonText?.Padding);
150
151         /// <summary> The bindable property of ItemAlignment. </summary>
152         [EditorBrowsable(EditorBrowsableState.Never)]
153         internal static readonly BindableProperty ItemAlignmentProperty = BindableProperty.Create(nameof(ItemAlignment), typeof(LinearLayout.Alignment), typeof(Button), LinearLayout.Alignment.Center, propertyChanged: (bindable, oldValue, newValue) =>
154         {
155             var instance = (Button)bindable;
156             instance.itemAlignment = (LinearLayout.Alignment)newValue;
157             instance.LayoutItems();
158         },
159         defaultValueCreator: (bindable) => ((Button)bindable).itemAlignment);
160
161         /// <summary> The bindable property of ItemSpacing. </summary>
162         [EditorBrowsable(EditorBrowsableState.Never)]
163         internal static readonly BindableProperty ItemSpacingProperty = BindableProperty.Create(nameof(ItemSpacing), typeof(Size2D), typeof(Button), null, propertyChanged: (bindable, oldValue, newValue) =>
164         {
165             var instance = (Button)bindable;
166             instance.itemSpacing = (Size2D)newValue;
167             instance.UpdateSizeAndSpacing();
168         },
169         defaultValueCreator: (bindable) => ((Button)bindable).itemSpacing);
170
171         private IconOrientation? iconRelativeOrientation = IconOrientation.Left;
172         private bool isSelected = false;
173         private bool isSelectable = false;
174         private bool isEnabled = true;
175         private Size2D itemSpacing;
176         private LinearLayout.Alignment itemAlignment;
177
178         static Button() { }
179
180         /// <summary>
181         /// Creates a new instance of a Button.
182         /// </summary>
183         /// <since_tizen> 6 </since_tizen>
184         public Button() : base()
185         {
186         }
187
188         /// <summary>
189         /// Creates a new instance of a Button with style.
190         /// </summary>
191         /// <param name="style">Create Button by special style defined in UX.</param>
192         /// <since_tizen> 8 </since_tizen>
193         public Button(string style) : base(style)
194         {
195         }
196
197         /// <summary>
198         /// Creates a new instance of a Button with style.
199         /// </summary>
200         /// <param name="buttonStyle">Create Button by style customized by user.</param>
201         /// <since_tizen> 8 </since_tizen>
202         public Button(ButtonStyle buttonStyle) : base(buttonStyle)
203         {
204         }
205
206         /// <summary>
207         /// Calculates current states for the button<br />
208         /// </summary>
209         [EditorBrowsable(EditorBrowsableState.Never)]
210         protected override AccessibilityStates AccessibilityCalculateStates()
211         {
212             var states = base.AccessibilityCalculateStates();
213             states.Set(AccessibilityState.Checked, this.IsSelected);
214             states.Set(AccessibilityState.Enabled, this.IsEnabled);
215             return states;
216         }
217
218         /// <summary>
219         /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
220         /// </summary>
221         /// <since_tizen> 6 </since_tizen>
222         [Obsolete("Deprecated in API8; Will be removed in API10. Please use Clicked event instead.")]
223         public event EventHandler<ClickEventArgs> ClickEvent;
224
225         /// <summary>
226         /// An event for the button clicked signal which can be used to subscribe or unsubscribe the event handler provided by the user.
227         /// </summary>
228         /// <since_tizen> 8 </since_tizen>
229         public event EventHandler<ClickedEventArgs> Clicked;
230
231         /// <summary>
232         /// An event for the button state changed signal which can be used to subscribe or unsubscribe the event handler provided by the user.<br />
233         /// </summary>
234         /// <since_tizen> 6 </since_tizen>
235         [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEvent")]
236         public event EventHandler<StateChangedEventArgs> StateChangedEvent
237         {
238             add
239             {
240                 stateChangeHandler += value;
241             }
242             remove
243             {
244                 stateChangeHandler -= value;
245             }
246         }
247
248         /// <summary>
249         /// Icon orientation.
250         /// </summary>
251         /// <since_tizen> 6 </since_tizen>
252         public enum IconOrientation
253         {
254             /// <summary>
255             /// Top.
256             /// </summary>
257             /// <since_tizen> 6 </since_tizen>
258             Top,
259             /// <summary>
260             /// Bottom.
261             /// </summary>
262             /// <since_tizen> 6 </since_tizen>
263             Bottom,
264             /// <summary>
265             /// Left.
266             /// </summary>
267             /// <since_tizen> 6 </since_tizen>
268             Left,
269             /// <summary>
270             /// Right.
271             /// </summary>
272             /// <since_tizen> 6 </since_tizen>
273             Right,
274         }
275
276         /// <summary>
277         /// Button's icon part.
278         /// </summary>
279         /// <since_tizen> 8 </since_tizen>
280         public ImageView Icon
281         {
282             get => buttonIcon;
283             internal set
284             {
285                 buttonIcon = value;
286             }
287         }
288
289         /// <summary>
290         /// Button's overlay image part.
291         /// </summary>
292         /// <since_tizen> 8 </since_tizen>
293         public ImageView OverlayImage
294         {
295             get
296             {
297                 if (null == overlayImage)
298                 {
299                     overlayImage = CreateOverlayImage();
300                     if (null != Extension)
301                     {
302                         overlayImage = Extension.OnCreateOverlayImage(this, overlayImage);
303                     }
304                     if (null != overlayImage)
305                     {
306                         overlayImage.ExcludeLayouting = true;
307                         Add(overlayImage);
308                     }
309                 }
310                 return overlayImage;
311             }
312             internal set
313             {
314                 overlayImage = value;
315             }
316         }
317
318         /// <summary>
319         /// Button's text part.
320         /// </summary>
321         /// <since_tizen> 8 </since_tizen>
322         public TextLabel TextLabel
323         {
324             get => buttonText;
325             internal set
326             {
327                 buttonText = value;
328                 AccessibilityManager.Instance.SetAccessibilityAttribute(this, AccessibilityManager.AccessibilityAttribute.Label, buttonText.Text);
329             }
330         }
331
332         /// <summary>
333         /// Return currently applied style.
334         /// </summary>
335         /// <remarks>
336         /// Modifying contents in style may cause unexpected behaviour.
337         /// </remarks>
338         /// <since_tizen> 8 </since_tizen>
339         public ButtonStyle Style => (ButtonStyle)(ViewStyle as ButtonStyle)?.Clone();
340
341         /// <summary>
342         /// The text of Button.
343         /// </summary>
344         /// <since_tizen> 6 </since_tizen>
345         public string Text
346         {
347             get
348             {
349                 return TextLabel.Text;
350             }
351             set
352             {
353                 TextLabel.Text = value;
354
355                 if (IsHighlighted && String.IsNullOrEmpty(AccessibilityName) && GetAccessibilityNameSignal().Empty())
356                 {
357                     EmitAccessibilityEvent(ObjectPropertyChangeEvent.Name);
358                 }
359             }
360         }
361
362         /// <summary>
363         /// Flag to decide Button can be selected or not.
364         /// </summary>
365         /// <since_tizen> 6 </since_tizen>
366         public bool IsSelectable
367         {
368             get
369             {
370                 return (bool)GetValue(IsSelectableProperty);
371             }
372             set
373             {
374                 SetValue(IsSelectableProperty, value);
375             }
376         }
377
378         /// <summary>
379         /// Translate text string in Button.
380         /// </summary>
381         /// <since_tizen> 6 </since_tizen>
382         public string TranslatableText
383         {
384             get
385             {
386                 return TextLabel.TranslatableText;
387             }
388             set
389             {
390                 TextLabel.TranslatableText = value;
391             }
392         }
393
394         /// <summary>
395         /// Text point size in Button.
396         /// </summary>
397         /// <since_tizen> 6 </since_tizen>
398         public float PointSize
399         {
400             get
401             {
402                 return TextLabel.PointSize;
403             }
404             set
405             {
406                 TextLabel.PointSize = value;
407             }
408         }
409
410         /// <summary>
411         /// Text font family in Button.
412         /// </summary>
413         /// <since_tizen> 6 </since_tizen>
414         public string FontFamily
415         {
416             get
417             {
418                 return TextLabel.FontFamily;
419             }
420             set
421             {
422                 TextLabel.FontFamily = value;
423             }
424         }
425
426         /// <summary>
427         /// Text color in Button.
428         /// </summary>
429         /// <since_tizen> 6 </since_tizen>
430         public Color TextColor
431         {
432             get
433             {
434                 return TextLabel.TextColor;
435             }
436             set
437             {
438                 TextLabel.TextColor = value;
439             }
440         }
441
442         /// <summary>
443         /// Text horizontal alignment in Button.
444         /// </summary>
445         /// <since_tizen> 6 </since_tizen>
446         public HorizontalAlignment TextAlignment
447         {
448             get
449             {
450                 return TextLabel.HorizontalAlignment;
451             }
452             set
453             {
454                 TextLabel.HorizontalAlignment = value;
455             }
456         }
457
458         /// <summary>
459         /// Icon image's resource url in Button.
460         /// </summary>
461         /// <since_tizen> 6 </since_tizen>
462         public string IconURL
463         {
464             get
465             {
466                 return Icon.ResourceUrl;
467             }
468             set
469             {
470                 Icon.ResourceUrl = value;
471             }
472         }
473
474         /// <summary>
475         /// Text string selector in Button.
476         /// Getter returns copied selector value if exist, null otherwise.
477         /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
478         /// </summary>
479         /// <since_tizen> 6 </since_tizen>
480         public StringSelector TextSelector
481         {
482             get => buttonText == null ? null : new StringSelector((Selector<string>)buttonText.GetValue(TextLabel.TextSelectorProperty));
483             set
484             {
485                 if (value == null || buttonText == null)
486                 {
487                     throw new NullReferenceException("Button.TextSelector is null");
488                 }
489                 else
490                 {
491                     buttonText.SetValue(TextLabel.TextSelectorProperty, value);
492                 }
493             }
494         }
495
496         /// <summary>
497         /// Translatable text string selector in Button.
498         /// Getter returns copied selector value if exist, null otherwise.
499         /// </summary>
500         /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
501         /// <since_tizen> 6 </since_tizen>
502         public StringSelector TranslatableTextSelector
503         {
504             get => buttonText == null ? null : new StringSelector((Selector<string>)buttonText.GetValue(TextLabel.TranslatableTextSelectorProperty));
505             set
506             {
507                 if (value == null || buttonText == null)
508                 {
509                     throw new NullReferenceException("Button.TranslatableTextSelector is null");
510                 }
511                 else
512                 {
513                     buttonText.SetValue(TextLabel.TranslatableTextSelectorProperty, value);
514                 }
515             }
516         }
517
518         /// <summary>
519         /// Text color selector in Button.
520         /// Getter returns copied selector value if exist, null otherwise.
521         /// </summary>
522         /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
523         /// <since_tizen> 6 </since_tizen>
524         public ColorSelector TextColorSelector
525         {
526             get => buttonText == null ? null : new ColorSelector((Selector<Color>)buttonText.GetValue(TextLabel.TextColorSelectorProperty));
527             set
528             {
529                 if (value == null || buttonText == null)
530                 {
531                     throw new NullReferenceException("Button.TextColorSelectorProperty is null");
532                 }
533                 else
534                 {
535                     buttonText.SetValue(TextLabel.TextColorSelectorProperty, value);
536                 }
537             }
538         }
539
540         /// <summary>
541         /// Text font size selector in Button.
542         /// Getter returns copied selector value if exist, null otherwise.
543         /// </summary>
544         /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
545         /// <since_tizen> 6 </since_tizen>
546         public FloatSelector PointSizeSelector
547         {
548             get => buttonText == null ? null : new FloatSelector((Selector<float?>)buttonText.GetValue(TextLabel.PointSizeSelectorProperty));
549             set
550             {
551                 if (value == null || buttonText == null)
552                 {
553                     throw new NullReferenceException("Button.PointSizeSelector is null");
554                 }
555                 else
556                 {
557                     buttonText.SetValue(TextLabel.PointSizeSelectorProperty, value);
558                 }
559             }
560         }
561
562         /// <summary>
563         /// Icon image's resource url selector in Button.
564         /// Getter returns copied selector value if exist, null otherwise.
565         /// </summary>
566         /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
567         /// <since_tizen> 6 </since_tizen>
568         public StringSelector IconURLSelector
569         {
570             get => buttonIcon == null ? null : new StringSelector((Selector<string>)buttonIcon.GetValue(ImageView.ResourceUrlSelectorProperty));
571             set
572             {
573                 if (value == null || buttonIcon == null)
574                 {
575                     throw new NullReferenceException("Button.IconURLSelector is null");
576                 }
577                 else
578                 {
579                     buttonIcon.SetValue(ImageView.ResourceUrlSelectorProperty, value);
580                 }
581             }
582         }
583
584         /// <summary>
585         /// Flag to decide selected state in Button.
586         /// </summary>
587         /// <since_tizen> 6 </since_tizen>
588         public bool IsSelected
589         {
590             get
591             {
592                 return (bool)GetValue(IsSelectedProperty);
593             }
594             set
595             {
596                 SetValue(IsSelectedProperty, value);
597             }
598         }
599
600         /// <summary>
601         /// Flag to decide enable or disable in Button.
602         /// </summary>
603         /// <since_tizen> 6 </since_tizen>
604         public bool IsEnabled
605         {
606             get
607             {
608                 return (bool)GetValue(IsEnabledProperty);
609             }
610             set
611             {
612                 SetValue(IsEnabledProperty, value);
613             }
614         }
615
616         /// <summary>
617         /// Icon relative orientation in Button, work only when show icon and text.
618         /// </summary>
619         /// <since_tizen> 8 </since_tizen>
620         public IconOrientation? IconRelativeOrientation
621         {
622             get
623             {
624                 return (IconOrientation?)GetValue(IconRelativeOrientationProperty) ?? IconOrientation.Left;
625             }
626             set
627             {
628                 SetValue(IconRelativeOrientationProperty, value);
629             }
630         }
631
632         /// <summary>
633         /// Icon padding in Button. It is shortcut of Icon.Padding.
634         /// </summary>
635         /// <since_tizen> 6 </since_tizen>
636         public Extents IconPadding
637         {
638             get => (Extents)GetValue(IconPaddingProperty) ?? new Extents();
639             set => SetValue(IconPaddingProperty, value);
640         }
641
642         /// <summary>
643         /// Text padding in Button. It is shortcut of TextLabel.Padding.
644         /// </summary>
645         /// <since_tizen> 6 </since_tizen>
646         public Extents TextPadding
647         {
648             get => (Extents)GetValue(TextPaddingProperty) ?? new Extents();
649             set => SetValue(TextPaddingProperty, value);
650         }
651
652         /// <summary>
653         /// The item (text or icon or both) alignment.
654         /// </summary>
655         [EditorBrowsable(EditorBrowsableState.Never)]
656         public LinearLayout.Alignment ItemAlignment
657         {
658             get => (LinearLayout.Alignment)GetValue(ItemAlignmentProperty);
659             set => SetValue(ItemAlignmentProperty, value);
660         }
661
662         /// <summary>
663         /// The space between icon and text.
664         /// The value is applied when there exist icon and text both.
665         /// The width value is used when the items are arranged horizontally. Otherwise, the height value is used.
666         /// </summary>
667         [EditorBrowsable(EditorBrowsableState.Never)]
668         public Size2D ItemSpacing
669         {
670             get => (Size2D)GetValue(ItemSpacingProperty);
671             set => SetValue(ItemSpacingProperty, value);
672         }
673
674         /// <summary>
675         /// Called after a key event is received by the view that has had its focus set.
676         /// </summary>
677         /// <param name="key">The key event.</param>
678         /// <returns>True if the key event should be consumed.</returns>
679         /// <since_tizen> 6 </since_tizen>
680         public override bool OnKey(Key key)
681         {
682             if (!IsEnabled || null == key)
683             {
684                 return false;
685             }
686
687             if (key.State == Key.StateType.Down)
688             {
689                 if (key.KeyPressedName == "Return")
690                 {
691                     isPressed = true;
692                     UpdateState();
693                 }
694             }
695             else if (key.State == Key.StateType.Up)
696             {
697                 if (key.KeyPressedName == "Return")
698                 {
699                     bool clicked = isPressed && IsEnabled;
700
701                     isPressed = false;
702
703                     if (IsSelectable)
704                     {
705                         IsSelected = !IsSelected;
706                     }
707                     else
708                     {
709                         UpdateState();
710                     }
711
712                     if (clicked)
713                     {
714                         ClickedEventArgs eventArgs = new ClickedEventArgs();
715                         OnClickedInternal(eventArgs);
716                     }
717                 }
718             }
719             return base.OnKey(key);
720         }
721
722         /// <summary>
723         /// 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.
724         /// </summary>
725         /// <since_tizen> 8 </since_tizen>
726         public override void OnFocusGained()
727         {
728             base.OnFocusGained();
729             UpdateState();
730         }
731
732         /// <summary>
733         /// 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.
734         /// </summary>
735         /// <since_tizen> 8 </since_tizen>
736         public override void OnFocusLost()
737         {
738             base.OnFocusLost();
739             UpdateState();
740         }
741
742         /// <summary>
743         /// Called after a touch event is received by the owning view.<br />
744         /// CustomViewBehaviour.REQUIRES_TOUCH_EVENTS must be enabled during construction. See CustomView(ViewWrapperImpl.CustomViewBehaviour behaviour).<br />
745         /// </summary>
746         /// <param name="touch">The touch event.</param>
747         /// <returns>True if the event should be consumed.</returns>
748         /// <since_tizen> 8 </since_tizen>
749         [Obsolete("Deprecated in API8; Will be removed in API10. Please use OnClicked instead.")]
750 #pragma warning disable CS0809 // Obsolete member overrides non-obsolete member, It will be removed in API10
751         public override bool OnTouch(Touch touch)
752 #pragma warning restore CS0809 // Obsolete member overrides non-obsolete member, It will be removed in API10
753         {
754             return base.OnTouch(touch);
755         }
756
757         /// <summary>
758         /// Apply style to button.
759         /// </summary>
760         /// <param name="viewStyle">The style to apply.</param>
761         /// <since_tizen> 8 </since_tizen>
762         public override void ApplyStyle(ViewStyle viewStyle)
763         {
764             Debug.Assert(buttonIcon != null && buttonText != null);
765
766             styleApplied = false;
767
768             base.ApplyStyle(viewStyle);
769
770             if (viewStyle is ButtonStyle buttonStyle)
771             {
772                 Extension = buttonStyle.CreateExtension();
773
774                 if (buttonStyle.Overlay != null)
775                 {   
776                     OverlayImage?.ApplyStyle(buttonStyle.Overlay);
777                 }
778
779                 if (Extension != null)
780                 {
781                     buttonIcon.Unparent();
782                     buttonIcon = Extension.OnCreateIcon(this, buttonIcon);
783
784                     buttonText.Unparent();
785                     buttonText = Extension.OnCreateText(this, buttonText);
786
787                     LayoutItems();
788                 }
789
790                 if (buttonStyle.Text != null)
791                 {
792                     buttonText.ApplyStyle(buttonStyle.Text);
793                 }
794
795                 if (buttonStyle.Icon != null)
796                 {
797                     buttonIcon.ApplyStyle(buttonStyle.Icon);
798                 }
799             }
800
801             styleApplied = true;
802             UpdateState();
803         }
804
805         /// <summary>
806         /// ClickEventArgs is a class to record button click event arguments which will sent to user.
807         /// </summary>
808         /// <since_tizen> 6 </since_tizen>
809         [Obsolete("Deprecated in API8; Will be removed in API10. Please use ClickedEventArgs instead.")]
810         [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
811         public class ClickEventArgs : EventArgs
812         {
813         }
814
815         /// <summary>
816         /// StateChangeEventArgs is a class to record button state change event arguments which will sent to user.
817         /// </summary>
818         /// <since_tizen> 6 </since_tizen>
819         [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEventArgs")]
820         [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
821         public class StateChangedEventArgs : EventArgs
822         {
823             /// <summary> previous state of Button </summary>
824             /// <since_tizen> 6 </since_tizen>
825             /// It will be removed in API10
826             [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
827             [Obsolete("Deprecated in API8; Will be removed in API10")]
828             public ControlStates PreviousState;
829             /// <summary> current state of Button </summary>
830             /// <since_tizen> 6 </since_tizen>
831             /// It will be removed in API10
832             [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
833             [Obsolete("Deprecated in API8; Will be removed in API10")]
834             public ControlStates CurrentState;
835         }
836     }
837 }