[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / UIComponents / 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 System.Runtime.InteropServices;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Binding;
22
23 namespace Tizen.NUI.UIComponents
24 {
25     /// <summary>
26     /// The Button class is a base class for different kinds of buttons.<br />
27     /// This class provides the disabled property and the clicked signal.<br />
28     /// The clicked event handler is emitted when the button is touched, and the touch point doesn't leave the boundary of the button.<br />
29     /// When the disabled property is set to true, no signal is emitted.<br />
30     /// The 'Visual' describes not just traditional images like PNG and BMP, but also refers to whatever is used to show the button. It could be a color, gradient, or some other kind of renderer.<br />
31     /// The button's appearance can be modified by setting properties for the various visuals or images.<br />
32     /// It is not mandatory to set all the visuals. A button could be defined only by setting its background visual, or by setting its background and selected visuals.<br />
33     /// The button visual is shown over the background visual.<br />
34     /// When pressed, the unselected visuals are replaced by the selected visuals.<br />
35     /// The text label is always placed on the top of all images.<br />
36     /// When the button is disabled, the background button and the selected visuals are replaced by their disabled visuals.<br />
37     /// </summary>
38     /// <since_tizen> 3 </since_tizen>
39     public class Button : View
40     {
41         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
42         [EditorBrowsable(EditorBrowsableState.Never)]
43         public static readonly BindableProperty UnselectedVisualProperty = BindableProperty.Create("UnselectedVisual", typeof(PropertyMap), typeof(Button), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
44         {
45             var button = (Button)bindable;
46             if (newValue != null)
47             {
48                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.UNSELECTED_VISUAL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
49             }
50         },
51         defaultValueCreator:(bindable) =>
52         {
53             var button = (Button)bindable;
54             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
55             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.UNSELECTED_VISUAL).Get(temp);
56             return temp;
57         });
58         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
59         [EditorBrowsable(EditorBrowsableState.Never)]
60         public static readonly BindableProperty SelectedVisualProperty = BindableProperty.Create("SelectedVisual", typeof(PropertyMap), typeof(Button), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
61         {
62             var button = (Button)bindable;
63             if (newValue != null)
64             {
65                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.SELECTED_VISUAL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
66             }
67         },
68         defaultValueCreator:(bindable) =>
69         {
70             var button = (Button)bindable;
71             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
72             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.SELECTED_VISUAL).Get(temp);
73             return temp;
74         });
75         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
76         [EditorBrowsable(EditorBrowsableState.Never)]
77         public static readonly BindableProperty DisabledSelectedVisualProperty = BindableProperty.Create("DisabledSelectedVisual", typeof(PropertyMap), typeof(Button), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
78         {
79             var button = (Button)bindable;
80             if (newValue != null)
81             {
82                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.DISABLED_SELECTED_VISUAL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
83             }
84         },
85         defaultValueCreator:(bindable) =>
86         {
87             var button = (Button)bindable;
88             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
89             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.DISABLED_SELECTED_VISUAL).Get(temp);
90             return temp;
91         });
92         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
93         [EditorBrowsable(EditorBrowsableState.Never)]
94         public static readonly BindableProperty DisabledUnselectedVisualProperty = BindableProperty.Create("DisabledUnselectedVisual", typeof(PropertyMap), typeof(Button), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
95         {
96             var button = (Button)bindable;
97             if (newValue != null)
98             {
99                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.DISABLED_UNSELECTED_VISUAL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
100             }
101         },
102         defaultValueCreator:(bindable) =>
103         {
104             var button = (Button)bindable;
105             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
106             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.DISABLED_UNSELECTED_VISUAL).Get(temp);
107             return temp;
108         });
109         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
110         [EditorBrowsable(EditorBrowsableState.Never)]
111         public static readonly BindableProperty UnselectedBackgroundVisualProperty = BindableProperty.Create("UnselectedBackgroundVisual", typeof(PropertyMap), typeof(Button), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
112         {
113             var button = (Button)bindable;
114             if (newValue != null)
115             {
116                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.UNSELECTED_BACKGROUND_VISUAL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
117             }
118         },
119         defaultValueCreator:(bindable) =>
120         {
121             var button = (Button)bindable;
122             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
123             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.UNSELECTED_BACKGROUND_VISUAL).Get(temp);
124             return temp;
125         });
126         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
127         [EditorBrowsable(EditorBrowsableState.Never)]
128         public static readonly BindableProperty SelectedBackgroundVisualProperty = BindableProperty.Create("SelectedBackgroundVisual", typeof(PropertyMap), typeof(Button), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
129         {
130             var button = (Button)bindable;
131             if (newValue != null)
132             {
133                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.SELECTED_BACKGROUND_VISUAL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
134             }
135         },
136         defaultValueCreator:(bindable) =>
137         {
138             var button = (Button)bindable;
139             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
140             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.SELECTED_BACKGROUND_VISUAL).Get(temp);
141             return temp;
142         });
143         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
144         [EditorBrowsable(EditorBrowsableState.Never)]
145         public static readonly BindableProperty DisabledUnselectedBackgroundVisualProperty = BindableProperty.Create("DisabledUnselectedBackgroundVisual", typeof(PropertyMap), typeof(Button), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
146         {
147             var button = (Button)bindable;
148             if (newValue != null)
149             {
150                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.DISABLED_UNSELECTED_BACKGROUND_VISUAL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
151             }
152         },
153         defaultValueCreator:(bindable) =>
154         {
155             var button = (Button)bindable;
156             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
157             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.DISABLED_UNSELECTED_BACKGROUND_VISUAL).Get(temp);
158             return temp;
159         });
160         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
161         [EditorBrowsable(EditorBrowsableState.Never)]
162         public static readonly BindableProperty DisabledSelectedBackgroundVisualProperty = BindableProperty.Create("DisabledSelectedBackgroundVisual", typeof(PropertyMap), typeof(Button), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
163         {
164             var button = (Button)bindable;
165             if (newValue != null)
166             {
167                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.DISABLED_SELECTED_BACKGROUND_VISUAL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
168             }
169         },
170         defaultValueCreator:(bindable) =>
171         {
172             var button = (Button)bindable;
173             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
174             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.DISABLED_SELECTED_BACKGROUND_VISUAL).Get(temp);
175             return temp;
176         });
177         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
178         [EditorBrowsable(EditorBrowsableState.Never)]
179         public static readonly BindableProperty LabelRelativeAlignmentProperty = BindableProperty.Create("LabelRelativeAlignment", typeof(Align), typeof(Button), Align.End, propertyChanged: (bindable, oldValue, newValue) =>
180         {
181             var button = (Button)bindable;
182             string valueToString = "";
183             if (newValue != null)
184             {
185                 switch ((Align)newValue)
186                 {
187                     case Align.Begin: { valueToString = "BEGIN"; break; }
188                     case Align.End: { valueToString = "END"; break; }
189                     case Align.Top: { valueToString = "TOP"; break; }
190                     case Align.Bottom: { valueToString = "BOTTOM"; break; }
191                     default: { valueToString = "END";  break; }
192                 }
193                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.LABEL_RELATIVE_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
194             }
195         },
196         defaultValueCreator:(bindable) =>
197         {
198             var button = (Button)bindable;
199             string temp;
200             if (Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.LABEL_RELATIVE_ALIGNMENT).Get(out temp) == false)
201             {
202                 NUILog.Error("LabelRelativeAlignment get error!");
203             }
204             switch (temp)
205             {
206                 case "BEGIN":  return Align.Begin;
207                 case "END": return Align.End;
208                 case "TOP": return Align.Top;
209                 case "BOTTOM": return Align.Bottom;
210                 default: return Align.End;
211             }
212         });
213         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
214         [EditorBrowsable(EditorBrowsableState.Never)]
215         public static readonly BindableProperty LabelPaddingProperty = BindableProperty.Create("LabelPadding", typeof(Vector4), typeof(Button), Vector4.Zero, propertyChanged: (bindable, oldValue, newValue) =>
216         {
217             var button = (Button)bindable;
218             if (newValue != null)
219             {
220                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.LABEL_PADDING, new Tizen.NUI.PropertyValue((Vector4)newValue));
221             }
222         },
223         defaultValueCreator:(bindable) =>
224         {
225             var button = (Button)bindable;
226             Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
227             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.LABEL_PADDING).Get(temp);
228             return temp;
229         });
230         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
231         [EditorBrowsable(EditorBrowsableState.Never)]
232         public static readonly BindableProperty ForegroundVisualPaddingProperty = BindableProperty.Create("ForegroundVisualPadding", typeof(Vector4), typeof(Button), Vector4.Zero, propertyChanged: (bindable, oldValue, newValue) =>
233         {
234             var button = (Button)bindable;
235             if (newValue != null)
236             {
237                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.FOREGROUND_VISUAL_PADDING, new Tizen.NUI.PropertyValue((Vector4)newValue));
238             }
239         },
240         defaultValueCreator:(bindable) =>
241         {
242             var button = (Button)bindable;
243             Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
244             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.FOREGROUND_VISUAL_PADDING).Get(temp);
245             return temp;
246         });
247         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
248         [EditorBrowsable(EditorBrowsableState.Never)]
249         public static readonly BindableProperty AutoRepeatingProperty = BindableProperty.Create("AutoRepeating", typeof(bool), typeof(Button), false, propertyChanged: (bindable, oldValue, newValue) =>
250         {
251             var button = (Button)bindable;
252             if (newValue != null)
253             {
254                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.AUTO_REPEATING, new Tizen.NUI.PropertyValue((bool)newValue));
255             }
256         },
257         defaultValueCreator:(bindable) =>
258         {
259             var button = (Button)bindable;
260             bool temp = false;
261             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.AUTO_REPEATING).Get(out temp);
262             return temp;
263         });
264         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
265         [EditorBrowsable(EditorBrowsableState.Never)]
266         public static readonly BindableProperty InitialAutoRepeatingDelayProperty = BindableProperty.Create("InitialAutoRepeatingDelay", typeof(float), typeof(Button), default(float), propertyChanged: (bindable, oldValue, newValue) =>
267         {
268             var button = (Button)bindable;
269             if (newValue != null)
270             {
271                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.INITIAL_AUTO_REPEATING_DELAY, new Tizen.NUI.PropertyValue((float)newValue));
272             }
273         },
274         defaultValueCreator:(bindable) =>
275         {
276             var button = (Button)bindable;
277             float temp = 0.0f;
278             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.INITIAL_AUTO_REPEATING_DELAY).Get(out temp);
279             return temp;
280         });
281         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
282         [EditorBrowsable(EditorBrowsableState.Never)]
283         public static readonly BindableProperty NextAutoRepeatingDelayProperty = BindableProperty.Create("NextAutoRepeatingDelay", typeof(float), typeof(Button), default(float), propertyChanged: (bindable, oldValue, newValue) =>
284         {
285             var button = (Button)bindable;
286             if (newValue != null)
287             {
288                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.NEXT_AUTO_REPEATING_DELAY, new Tizen.NUI.PropertyValue((float)newValue));
289             }
290         },
291         defaultValueCreator:(bindable) =>
292         {
293             var button = (Button)bindable;
294             float temp = 0.0f;
295             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.NEXT_AUTO_REPEATING_DELAY).Get(out temp);
296             return temp;
297         });
298         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
299         [EditorBrowsable(EditorBrowsableState.Never)]
300         public static readonly BindableProperty TogglableProperty = BindableProperty.Create("Togglable", typeof(bool), typeof(Button), false, propertyChanged: (bindable, oldValue, newValue) =>
301         {
302             var button = (Button)bindable;
303             if (newValue != null)
304             {
305                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.TOGGLABLE, new Tizen.NUI.PropertyValue((bool)newValue));
306             }
307         },
308         defaultValueCreator:(bindable) =>
309         {
310             var button = (Button)bindable;
311             bool temp = false;
312             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.TOGGLABLE).Get(out temp);
313             return temp;
314         });
315         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
316         [EditorBrowsable(EditorBrowsableState.Never)]
317         public static readonly BindableProperty SelectedProperty = BindableProperty.Create("Selected", typeof(bool), typeof(Button), false, propertyChanged: (bindable, oldValue, newValue) =>
318         {
319             var button = (Button)bindable;
320             if (newValue != null)
321             {
322                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.SELECTED, new Tizen.NUI.PropertyValue((bool)newValue));
323             }
324         },
325         defaultValueCreator:(bindable) =>
326         {
327             var button = (Button)bindable;
328             bool temp = false;
329             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.SELECTED).Get(out temp);
330             return temp;
331         });
332         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
333         [EditorBrowsable(EditorBrowsableState.Never)]
334         public static readonly BindableProperty UnselectedColorProperty = BindableProperty.Create("UnselectedColor", typeof(Color), typeof(Button), Color.Transparent, propertyChanged: (bindable, oldValue, newValue) =>
335         {
336             var button = (Button)bindable;
337             if (newValue != null)
338             {
339                 PropertyMap background = new PropertyMap();
340                 background.Add( Visual.Property.Type, new PropertyValue((int)Visual.Type.Color) )
341                           .Add( ColorVisualProperty.MixColor, new PropertyValue((Color)newValue) );
342                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.UNSELECTED_BACKGROUND_VISUAL, new Tizen.NUI.PropertyValue(background));
343             }
344         },
345         defaultValueCreator:(bindable) =>
346         {
347             var button = (Button)bindable;
348             Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
349             Tizen.NUI.PropertyMap map = new Tizen.NUI.PropertyMap();
350             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.UNSELECTED_BACKGROUND_VISUAL).Get(map);
351             Tizen.NUI.PropertyValue value = map.Find( Visual.Property.MixColor);
352             value?.Get(temp);
353             return temp;
354         });
355         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
356         [EditorBrowsable(EditorBrowsableState.Never)]
357         public static readonly BindableProperty SelectedColorProperty = BindableProperty.Create("SelectedColor", typeof(Color), typeof(Button), Color.Transparent, propertyChanged: (bindable, oldValue, newValue) =>
358         {
359             var button = (Button)bindable;
360             if (newValue != null)
361             {
362                 PropertyMap background = new PropertyMap();
363                 background.Add( Visual.Property.Type, new PropertyValue((int)Visual.Type.Color) )
364                           .Add( ColorVisualProperty.MixColor, new PropertyValue((Color)newValue) );
365                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.SELECTED_BACKGROUND_VISUAL, new Tizen.NUI.PropertyValue(background));
366             }
367         },
368         defaultValueCreator:(bindable) =>
369         {
370             var button = (Button)bindable;
371             Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
372             Tizen.NUI.PropertyMap map = new Tizen.NUI.PropertyMap();
373             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.SELECTED_BACKGROUND_VISUAL).Get(map);
374             Tizen.NUI.PropertyValue value = map.Find( Visual.Property.MixColor);
375             value?.Get(temp);
376             return temp;
377         });
378         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
379         [EditorBrowsable(EditorBrowsableState.Never)]
380         public static readonly BindableProperty LabelProperty = BindableProperty.Create("Label", typeof(PropertyMap), typeof(Button), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
381         {
382             var button = (Button)bindable;
383             if (newValue != null)
384             {
385                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.LABEL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
386             }
387         },
388         defaultValueCreator:(bindable) =>
389         {
390             var button = (Button)bindable;
391             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
392             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.LABEL).Get(temp);
393             return temp;
394         });
395         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
396         [EditorBrowsable(EditorBrowsableState.Never)]
397         public static readonly BindableProperty LabelTextProperty = BindableProperty.Create("LabelText", typeof(string), typeof(Button), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
398         {
399             var button = (Button)bindable;
400             if (newValue != null)
401             {
402                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.LABEL, new Tizen.NUI.PropertyValue((string)newValue));
403             }
404         },
405         defaultValueCreator:(bindable) =>
406         {
407             var button = (Button)bindable;
408             Tizen.NUI.PropertyMap map = new Tizen.NUI.PropertyMap();
409             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.LABEL).Get(map);
410             Tizen.NUI.PropertyValue value = map.Find( TextVisualProperty.Text, "Text");
411             string str = "";
412             value?.Get(out str);
413             return str;
414         });
415
416         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
417         private EventHandlerWithReturnType<object, EventArgs, bool> _clickedEventHandler;
418         private ClickedCallbackType _clickedCallback;
419         private EventHandlerWithReturnType<object, EventArgs, bool> _pressedEventHandler;
420         private PressedCallbackType _pressedCallback;
421         private EventHandlerWithReturnType<object, EventArgs, bool> _releasedEventHandler;
422         private ReleasedCallbackType _releasedCallback;
423         private EventHandlerWithReturnType<object, EventArgs, bool> _stateChangedEventHandler;
424         private StateChangedCallback _stateChangedCallback;
425
426         /// <summary>
427         /// Creates an uninitialized button.<br />
428         /// Only the derived versions can be instantiated.<br />
429         /// </summary>
430         /// <since_tizen> 3 </since_tizen>
431         public Button() : this(Interop.Button.new_Button__SWIG_0(), true)
432         {
433             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
434         }
435
436         internal Button(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Button.Button_SWIGUpcast(cPtr), cMemoryOwn)
437         {
438             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
439         }
440
441         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
442         private delegate bool ClickedCallbackType(global::System.IntPtr data);
443         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
444         private delegate bool PressedCallbackType(global::System.IntPtr data);
445         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
446         private delegate bool ReleasedCallbackType(global::System.IntPtr data);
447         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
448         private delegate bool StateChangedCallback(global::System.IntPtr data);
449
450         /// <summary>
451         /// The Clicked event will be triggered when the button is touched and the touch point doesn't leave the boundary of the button.
452         /// </summary>
453         /// <since_tizen> 3 </since_tizen>
454         public event EventHandlerWithReturnType<object, EventArgs, bool> Clicked
455         {
456             add
457             {
458                 if (_clickedEventHandler == null)
459                 {
460                     _clickedCallback = OnClicked;
461                     ClickedSignal().Connect(_clickedCallback);
462                 }
463
464                 _clickedEventHandler += value;
465             }
466
467             remove
468             {
469                 _clickedEventHandler -= value;
470
471                 if (_clickedEventHandler == null && ClickedSignal().Empty() == false)
472                 {
473                     ClickedSignal().Disconnect(_clickedCallback);
474                 }
475             }
476         }
477
478         /// <summary>
479         /// The Pressed event will be triggered when the button is touched.
480         /// </summary>
481         /// <since_tizen> 3 </since_tizen>
482         public event EventHandlerWithReturnType<object, EventArgs, bool> Pressed
483         {
484             add
485             {
486                 if (_pressedEventHandler == null)
487                 {
488                     _pressedCallback = OnPressed;
489                     PressedSignal().Connect(_pressedCallback);
490                 }
491
492                 _pressedEventHandler += value;
493             }
494
495             remove
496             {
497                 _pressedEventHandler -= value;
498
499                 if (_pressedEventHandler == null && PressedSignal().Empty() == false)
500                 {
501                     this.PressedSignal().Disconnect(_pressedCallback);
502                 }
503             }
504         }
505
506         /// <summary>
507         /// The Released event will be triggered when the button is touched and the touch point leaves the boundary of the button.
508         /// </summary>
509         /// <since_tizen> 3 </since_tizen>
510         public event EventHandlerWithReturnType<object, EventArgs, bool> Released
511         {
512             add
513             {
514                 if (_releasedEventHandler == null)
515                 {
516                     _releasedCallback = OnReleased;
517                     ReleasedSignal().Connect(_releasedCallback);
518                 }
519                 _releasedEventHandler += value;
520             }
521
522             remove
523             {
524                 _releasedEventHandler -= value;
525
526                 if (_releasedEventHandler == null && ReleasedSignal().Empty() == false)
527                 {
528                     ReleasedSignal().Disconnect(_releasedCallback);
529                 }
530
531             }
532         }
533
534         /// <summary>
535         /// The StateChanged event will be triggered when the button's state is changed.
536         /// </summary>
537         /// <since_tizen> 3 </since_tizen>
538         public event EventHandlerWithReturnType<object, EventArgs, bool> StateChanged
539         {
540             add
541             {
542                 if (_stateChangedEventHandler == null)
543                 {
544                     _stateChangedCallback = OnStateChanged;
545                     StateChangedSignal().Connect(_stateChangedCallback);
546                 }
547
548                 _stateChangedEventHandler += value;
549             }
550
551             remove
552             {
553                 _stateChangedEventHandler -= value;
554
555                 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false)
556                 {
557                     StateChangedSignal().Disconnect(_stateChangedCallback);
558                 }
559             }
560         }
561
562         /// <summary>
563         /// Enumeration for describing the position, the text label can be, in relation to the control (and foreground/icon).
564         /// </summary>
565         /// <since_tizen> 3 </since_tizen>
566         public enum Align
567         {
568             /// <summary>
569             /// At the start of the control before the foreground or icon.
570             /// </summary>
571             Begin,
572             /// <summary>
573             /// At the end of the control after the foreground or icon.
574             /// </summary>
575             End,
576             /// <summary>
577             /// At the top of the control above the foreground or icon.
578             /// </summary>
579             Top,
580             /// <summary>
581             /// At the bottom of the control below the foreground or icon.
582             /// </summary>
583             Bottom
584         }
585
586         /// <summary>
587         /// Gets or sets the unselected button foreground or icon visual.
588         /// </summary>
589         /// <since_tizen> 3 </since_tizen>
590         public Tizen.NUI.PropertyMap UnselectedVisual
591         {
592             get
593             {
594                 return (PropertyMap)GetValue(UnselectedVisualProperty);
595             }
596             set
597             {
598                 SetValue(UnselectedVisualProperty, value);
599             }
600         }
601
602         /// <summary>
603         /// Gets or sets the selected button foreground or icon visual.
604         /// </summary>
605         /// <since_tizen> 3 </since_tizen>
606         public Tizen.NUI.PropertyMap SelectedVisual
607         {
608             get
609             {
610                 return (PropertyMap)GetValue(SelectedVisualProperty);
611             }
612             set
613             {
614                 SetValue(SelectedVisualProperty, value);
615             }
616         }
617
618         /// <summary>
619         /// Gets or sets the disabled selected state foreground or icon button visual.
620         /// </summary>
621         /// <since_tizen> 3 </since_tizen>
622         public Tizen.NUI.PropertyMap DisabledSelectedVisual
623         {
624             get
625             {
626                 return (PropertyMap)GetValue(DisabledSelectedVisualProperty);
627             }
628             set
629             {
630                 SetValue(DisabledSelectedVisualProperty, value);
631             }
632         }
633
634         /// <summary>
635         /// Gets or sets the disabled unselected state foreground or icon visual.
636         /// </summary>
637         /// <since_tizen> 3 </since_tizen>
638         public Tizen.NUI.PropertyMap DisabledUnselectedVisual
639         {
640             get
641             {
642                 return (PropertyMap)GetValue(DisabledUnselectedVisualProperty);
643             }
644             set
645             {
646                 SetValue(DisabledUnselectedVisualProperty, value);
647             }
648         }
649
650         /// <summary>
651         /// Gets or sets the disabled unselected state background button visual.
652         /// </summary>
653         /// <since_tizen> 3 </since_tizen>
654         public Tizen.NUI.PropertyMap UnselectedBackgroundVisual
655         {
656             get
657             {
658                 return (PropertyMap)GetValue(UnselectedBackgroundVisualProperty);
659             }
660             set
661             {
662                 SetValue(UnselectedBackgroundVisualProperty, value);
663             }
664         }
665
666         /// <summary>
667         /// Gets or sets the selected background button visual.
668         /// </summary>
669         /// <since_tizen> 3 </since_tizen>
670         public Tizen.NUI.PropertyMap SelectedBackgroundVisual
671         {
672             get
673             {
674                 return (PropertyMap)GetValue(SelectedBackgroundVisualProperty);
675             }
676             set
677             {
678                 SetValue(SelectedBackgroundVisualProperty, value);
679             }
680         }
681
682         /// <summary>
683         /// Gets or sets the disabled while unselected background button visual.
684         /// </summary>
685         /// <since_tizen> 3 </since_tizen>
686         public Tizen.NUI.PropertyMap DisabledUnselectedBackgroundVisual
687         {
688             get
689             {
690                 return (PropertyMap)GetValue(DisabledUnselectedBackgroundVisualProperty);
691             }
692             set
693             {
694                 SetValue(DisabledUnselectedBackgroundVisualProperty, value);
695             }
696         }
697
698         /// <summary>
699         /// Gets or sets the disabled while selected background button visual.
700         /// </summary>
701         /// <since_tizen> 3 </since_tizen>
702         public Tizen.NUI.PropertyMap DisabledSelectedBackgroundVisual
703         {
704             get
705             {
706                 return (PropertyMap)GetValue(DisabledSelectedBackgroundVisualProperty);
707             }
708             set
709             {
710                 SetValue(DisabledSelectedBackgroundVisualProperty, value);
711             }
712         }
713
714         /// <summary>
715         /// Gets or sets the position of the the label in relation to the foreground or icon, if both present.
716         /// </summary>
717         /// <since_tizen> 3 </since_tizen>
718         public Align LabelRelativeAlignment
719         {
720             get
721             {
722                 return (Align)GetValue(LabelRelativeAlignmentProperty);
723             }
724             set
725             {
726                 SetValue(LabelRelativeAlignmentProperty, value);
727             }
728         }
729
730         /// <summary>
731         /// Gets or sets the padding around the text.
732         /// </summary>
733         /// <since_tizen> 3 </since_tizen>
734         public Vector4 LabelPadding
735         {
736             get
737             {
738                 return (Vector4)GetValue(LabelPaddingProperty);
739             }
740             set
741             {
742                 SetValue(LabelPaddingProperty, value);
743             }
744         }
745
746         /// <summary>
747         /// Gets or sets the padding around the foreground visual.
748         /// </summary>
749         /// <since_tizen> 3 </since_tizen>
750         public Vector4 ForegroundVisualPadding
751         {
752             get
753             {
754                 return (Vector4)GetValue(ForegroundVisualPaddingProperty);
755             }
756             set
757             {
758                 SetValue(ForegroundVisualPaddingProperty, value);
759             }
760         }
761
762         /// <summary>
763         /// If the autorepeating property is set to true, then the togglable property is set to false.
764         /// </summary>
765         /// <since_tizen> 3 </since_tizen>
766         public bool AutoRepeating
767         {
768             get
769             {
770                 return (bool)GetValue(AutoRepeatingProperty);
771             }
772             set
773             {
774                 SetValue(AutoRepeatingProperty, value);
775             }
776         }
777
778         /// <summary>
779         /// By default, this value is set to 0.15 seconds.
780         /// </summary>
781         /// <since_tizen> 3 </since_tizen>
782         public float InitialAutoRepeatingDelay
783         {
784             get
785             {
786                 return (float)GetValue(InitialAutoRepeatingDelayProperty);
787             }
788             set
789             {
790                 SetValue(InitialAutoRepeatingDelayProperty, value);
791             }
792         }
793
794         /// <summary>
795         /// By default, this value is set to 0.05 seconds.
796         /// </summary>
797         /// <since_tizen> 3 </since_tizen>
798         public float NextAutoRepeatingDelay
799         {
800             get
801             {
802                 return (float)GetValue(NextAutoRepeatingDelayProperty);
803             }
804             set
805             {
806                 SetValue(NextAutoRepeatingDelayProperty, value);
807             }
808         }
809
810         /// <summary>
811         /// If the togglable property is set to true, then the autorepeating property is set to false.
812         /// </summary>
813         /// <since_tizen> 3 </since_tizen>
814         public bool Togglable
815         {
816             get
817             {
818                 return (bool)GetValue(TogglableProperty);
819             }
820             set
821             {
822                 SetValue(TogglableProperty, value);
823             }
824         }
825
826         /// <summary>
827         /// Gets or sets the togglable button as either selected or unselected, togglable property must be set to true.
828         /// </summary>
829         /// <since_tizen> 3 </since_tizen>
830         public bool Selected
831         {
832             get
833             {
834                 return (bool)GetValue(SelectedProperty);
835             }
836             set
837             {
838                 SetValue(SelectedProperty, value);
839             }
840         }
841
842         /// <summary>
843         /// Gets or sets the unselected color.
844         /// </summary>
845         /// <since_tizen> 3 </since_tizen>
846         public Color UnselectedColor
847         {
848             get
849             {
850                 return (Color)GetValue(UnselectedColorProperty);
851             }
852             set
853             {
854                 SetValue(UnselectedColorProperty, value);
855             }
856         }
857
858         /// <summary>
859         /// Gets or sets the selected color.
860         /// </summary>
861         /// <since_tizen> 3 </since_tizen>
862         public Color SelectedColor
863         {
864             get
865             {
866                 return (Color)GetValue(SelectedColorProperty);
867             }
868             set
869             {
870                 SetValue(SelectedColorProperty, value);
871             }
872         }
873
874         /// <summary>
875         /// Gets or sets the label.
876         /// </summary>
877         /// <since_tizen> 3 </since_tizen>
878         public Tizen.NUI.PropertyMap Label
879         {
880             get
881             {
882                 return (PropertyMap)GetValue(LabelProperty);
883             }
884             set
885             {
886                 SetValue(LabelProperty, value);
887             }
888         }
889
890         /// <summary>
891         /// Gets or sets the text of the label.
892         /// </summary>
893         /// <since_tizen> 3 </since_tizen>
894         public string LabelText
895         {
896             get
897             {
898                 return (string)GetValue(LabelTextProperty);
899             }
900             set
901             {
902                 SetValue(LabelTextProperty, value);
903             }
904         }
905
906         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Button obj)
907         {
908             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
909         }
910
911         internal ButtonSignal PressedSignal()
912         {
913             ButtonSignal ret = new ButtonSignal(Interop.Button.Button_PressedSignal(swigCPtr), false);
914             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
915             return ret;
916         }
917
918         internal ButtonSignal ReleasedSignal()
919         {
920             ButtonSignal ret = new ButtonSignal(Interop.Button.Button_ReleasedSignal(swigCPtr), false);
921             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
922             return ret;
923         }
924
925         internal ButtonSignal ClickedSignal()
926         {
927             ButtonSignal ret = new ButtonSignal(Interop.Button.Button_ClickedSignal(swigCPtr), false);
928             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
929             return ret;
930         }
931
932         internal ButtonSignal StateChangedSignal()
933         {
934             ButtonSignal ret = new ButtonSignal(Interop.Button.Button_StateChangedSignal(swigCPtr), false);
935             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
936             return ret;
937         }
938
939         /// <summary>
940         /// To dispose the button instance.
941         /// </summary>
942         /// <since_tizen> 3 </since_tizen>
943         protected override void Dispose(DisposeTypes type)
944         {
945             if (disposed)
946             {
947                 return;
948             }
949
950             //Release your own unmanaged resources here.
951             //You should not access any managed member here except static instance.
952             //because the execution order of Finalizes is non-deterministic.
953             if (this != null)
954             {
955                 DisConnectFromSignals();
956             }
957
958             if (swigCPtr.Handle != global::System.IntPtr.Zero)
959             {
960                 if (swigCMemOwn)
961                 {
962                     swigCMemOwn = false;
963                     Interop.Button.delete_Button(swigCPtr);
964                 }
965                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
966             }
967
968             base.Dispose(type);
969         }
970
971         private void DisConnectFromSignals()
972         {
973             // Save current CPtr.
974             global::System.Runtime.InteropServices.HandleRef currentCPtr = swigCPtr;
975
976             // Use BaseHandle CPtr as current might have been deleted already in derived classes.
977             swigCPtr = GetBaseHandleCPtrHandleRef;
978
979             if (_stateChangedCallback != null)
980             {
981                 StateChangedSignal().Disconnect(_stateChangedCallback);
982             }
983
984             if (_releasedCallback != null)
985             {
986                 ReleasedSignal().Disconnect(_releasedCallback);
987             }
988
989             if (_pressedCallback != null)
990             {
991                 this.PressedSignal().Disconnect(_pressedCallback);
992             }
993
994             if (_clickedCallback != null)
995             {
996                 ClickedSignal().Disconnect(_clickedCallback);
997             }
998
999             // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here.
1000             // Restore current CPtr.
1001             swigCPtr = currentCPtr;
1002         }
1003
1004         private bool OnClicked(IntPtr data)
1005         {
1006             if (_clickedEventHandler != null)
1007             {
1008                 return _clickedEventHandler(this, null);
1009             }
1010             return false;
1011         }
1012
1013         private bool OnPressed(IntPtr data)
1014         {
1015             if (_pressedEventHandler != null)
1016             {
1017                 return _pressedEventHandler(this, null);
1018             }
1019             return false;
1020         }
1021
1022         private bool OnReleased(IntPtr data)
1023         {
1024             if (_releasedEventHandler != null)
1025             {
1026                 return _releasedEventHandler(this, null);
1027             }
1028             return false;
1029         }
1030
1031         private bool OnStateChanged(IntPtr data)
1032         {
1033             if (_stateChangedEventHandler != null)
1034             {
1035                 return _stateChangedEventHandler(this, null);
1036             }
1037             return false;
1038         }
1039
1040         internal new class Property
1041         {
1042             internal static readonly int UNSELECTED_VISUAL = Interop.Button.Button_Property_UNSELECTED_VISUAL_get();
1043             internal static readonly int SELECTED_VISUAL = Interop.Button.Button_Property_SELECTED_VISUAL_get();
1044             internal static readonly int DISABLED_SELECTED_VISUAL = Interop.Button.Button_Property_DISABLED_SELECTED_VISUAL_get();
1045             internal static readonly int DISABLED_UNSELECTED_VISUAL = Interop.Button.Button_Property_DISABLED_UNSELECTED_VISUAL_get();
1046             internal static readonly int UNSELECTED_BACKGROUND_VISUAL = Interop.Button.Button_Property_UNSELECTED_BACKGROUND_VISUAL_get();
1047             internal static readonly int SELECTED_BACKGROUND_VISUAL = Interop.Button.Button_Property_SELECTED_BACKGROUND_VISUAL_get();
1048             internal static readonly int DISABLED_UNSELECTED_BACKGROUND_VISUAL = Interop.Button.Button_Property_DISABLED_UNSELECTED_BACKGROUND_VISUAL_get();
1049             internal static readonly int DISABLED_SELECTED_BACKGROUND_VISUAL = Interop.Button.Button_Property_DISABLED_SELECTED_BACKGROUND_VISUAL_get();
1050             internal static readonly int LABEL_RELATIVE_ALIGNMENT = Interop.Button.Button_Property_LABEL_RELATIVE_ALIGNMENT_get();
1051             internal static readonly int LABEL_PADDING = Interop.Button.Button_Property_LABEL_PADDING_get();
1052             internal static readonly int FOREGROUND_VISUAL_PADDING = Interop.Button.Button_Property_VISUAL_PADDING_get();
1053             internal static readonly int AUTO_REPEATING = Interop.Button.Button_Property_AUTO_REPEATING_get();
1054             internal static readonly int INITIAL_AUTO_REPEATING_DELAY = Interop.Button.Button_Property_INITIAL_AUTO_REPEATING_DELAY_get();
1055             internal static readonly int NEXT_AUTO_REPEATING_DELAY = Interop.Button.Button_Property_NEXT_AUTO_REPEATING_DELAY_get();
1056             internal static readonly int TOGGLABLE = Interop.Button.Button_Property_TOGGLABLE_get();
1057             internal static readonly int SELECTED = Interop.Button.Button_Property_SELECTED_get();
1058             internal static readonly int LABEL = Interop.Button.Button_Property_LABEL_get();
1059         }
1060     }
1061 }