[NUI] Split NUI Interop class (#804)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / UIComponents / Button.cs
1 /*
2  * Copyright(c) 2017 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                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.UNSELECTED_COLOR, new Tizen.NUI.PropertyValue((Color)newValue));
340             }
341         },
342         defaultValueCreator:(bindable) =>
343         {
344             var button = (Button)bindable;
345             Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
346             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.UNSELECTED_COLOR).Get(temp);
347             return temp;
348         });
349         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
350         [EditorBrowsable(EditorBrowsableState.Never)]
351         public static readonly BindableProperty SelectedColorProperty = BindableProperty.Create("SelectedColor", typeof(Color), typeof(Button), Color.Transparent, propertyChanged: (bindable, oldValue, newValue) =>
352         {
353             var button = (Button)bindable;
354             if (newValue != null)
355             {
356                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.SELECTED_COLOR, new Tizen.NUI.PropertyValue((Color)newValue));
357             }
358         },
359         defaultValueCreator:(bindable) =>
360         {
361             var button = (Button)bindable;
362             Color temp = new Color(0.0f, 0.0f, 0.0f, 0.0f);
363             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.SELECTED_COLOR).Get(temp);
364             return temp;
365         });
366         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
367         [EditorBrowsable(EditorBrowsableState.Never)]
368         public static readonly BindableProperty LabelProperty = BindableProperty.Create("Label", typeof(PropertyMap), typeof(Button), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
369         {
370             var button = (Button)bindable;
371             if (newValue != null)
372             {
373                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.LABEL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
374             }
375         },
376         defaultValueCreator:(bindable) =>
377         {
378             var button = (Button)bindable;
379             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
380             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.LABEL).Get(temp);
381             return temp;
382         });
383         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
384         [EditorBrowsable(EditorBrowsableState.Never)]
385         public static readonly BindableProperty LabelTextProperty = BindableProperty.Create("LabelText", typeof(string), typeof(Button), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
386         {
387             var button = (Button)bindable;
388             if (newValue != null)
389             {
390                 Tizen.NUI.Object.SetProperty(button.swigCPtr, Button.Property.LABEL, new Tizen.NUI.PropertyValue((string)newValue));
391             }
392         },
393         defaultValueCreator:(bindable) =>
394         {
395             var button = (Button)bindable;
396             Tizen.NUI.PropertyMap map = new Tizen.NUI.PropertyMap();
397             Tizen.NUI.Object.GetProperty(button.swigCPtr, Button.Property.LABEL).Get(map);
398             Tizen.NUI.PropertyValue value = map.Find( TextVisualProperty.Text, "Text");
399             string str = "";
400             value?.Get(out str);
401             return str;
402         });
403
404         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
405         private EventHandlerWithReturnType<object, EventArgs, bool> _clickedEventHandler;
406         private ClickedCallbackType _clickedCallback;
407         private EventHandlerWithReturnType<object, EventArgs, bool> _pressedEventHandler;
408         private PressedCallbackType _pressedCallback;
409         private EventHandlerWithReturnType<object, EventArgs, bool> _releasedEventHandler;
410         private ReleasedCallbackType _releasedCallback;
411         private EventHandlerWithReturnType<object, EventArgs, bool> _stateChangedEventHandler;
412         private StateChangedCallback _stateChangedCallback;
413
414         /// <summary>
415         /// Creates an uninitialized button.<br />
416         /// Only the derived versions can be instantiated.<br />
417         /// </summary>
418         /// <since_tizen> 3 </since_tizen>
419         public Button() : this(Interop.Button.new_Button__SWIG_0(), true)
420         {
421             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
422         }
423
424         internal Button(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Button.Button_SWIGUpcast(cPtr), cMemoryOwn)
425         {
426             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
427         }
428
429         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
430         private delegate bool ClickedCallbackType(global::System.IntPtr data);
431         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
432         private delegate bool PressedCallbackType(global::System.IntPtr data);
433         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
434         private delegate bool ReleasedCallbackType(global::System.IntPtr data);
435         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
436         private delegate bool StateChangedCallback(global::System.IntPtr data);
437
438         /// <summary>
439         /// The Clicked event will be triggered when the button is touched and the touch point doesn't leave the boundary of the button.
440         /// </summary>
441         /// <since_tizen> 3 </since_tizen>
442         public event EventHandlerWithReturnType<object, EventArgs, bool> Clicked
443         {
444             add
445             {
446                 if (_clickedEventHandler == null)
447                 {
448                     _clickedCallback = OnClicked;
449                     ClickedSignal().Connect(_clickedCallback);
450                 }
451
452                 _clickedEventHandler += value;
453             }
454
455             remove
456             {
457                 _clickedEventHandler -= value;
458
459                 if (_clickedEventHandler == null && ClickedSignal().Empty() == false)
460                 {
461                     ClickedSignal().Disconnect(_clickedCallback);
462                 }
463             }
464         }
465
466         /// <summary>
467         /// The Pressed event will be triggered when the button is touched.
468         /// </summary>
469         /// <since_tizen> 3 </since_tizen>
470         public event EventHandlerWithReturnType<object, EventArgs, bool> Pressed
471         {
472             add
473             {
474                 if (_pressedEventHandler == null)
475                 {
476                     _pressedCallback = OnPressed;
477                     PressedSignal().Connect(_pressedCallback);
478                 }
479
480                 _pressedEventHandler += value;
481             }
482
483             remove
484             {
485                 _pressedEventHandler -= value;
486
487                 if (_pressedEventHandler == null && PressedSignal().Empty() == false)
488                 {
489                     this.PressedSignal().Disconnect(_pressedCallback);
490                 }
491             }
492         }
493
494         /// <summary>
495         /// The Released event will be triggered when the button is touched and the touch point leaves the boundary of the button.
496         /// </summary>
497         /// <since_tizen> 3 </since_tizen>
498         public event EventHandlerWithReturnType<object, EventArgs, bool> Released
499         {
500             add
501             {
502                 if (_releasedEventHandler == null)
503                 {
504                     _releasedCallback = OnReleased;
505                     ReleasedSignal().Connect(_releasedCallback);
506                 }
507                 _releasedEventHandler += value;
508             }
509
510             remove
511             {
512                 _releasedEventHandler -= value;
513
514                 if (_releasedEventHandler == null && ReleasedSignal().Empty() == false)
515                 {
516                     ReleasedSignal().Disconnect(_releasedCallback);
517                 }
518
519             }
520         }
521
522         /// <summary>
523         /// The StateChanged event will be triggered when the button's state is changed.
524         /// </summary>
525         /// <since_tizen> 3 </since_tizen>
526         public event EventHandlerWithReturnType<object, EventArgs, bool> StateChanged
527         {
528             add
529             {
530                 if (_stateChangedEventHandler == null)
531                 {
532                     _stateChangedCallback = OnStateChanged;
533                     StateChangedSignal().Connect(_stateChangedCallback);
534                 }
535
536                 _stateChangedEventHandler += value;
537             }
538
539             remove
540             {
541                 _stateChangedEventHandler -= value;
542
543                 if (_stateChangedEventHandler == null && StateChangedSignal().Empty() == false)
544                 {
545                     StateChangedSignal().Disconnect(_stateChangedCallback);
546                 }
547             }
548         }
549
550         /// <summary>
551         /// Enumeration for describing the position, the text label can be, in relation to the control (and foreground/icon).
552         /// </summary>
553         /// <since_tizen> 3 </since_tizen>
554         public enum Align
555         {
556             /// <summary>
557             /// At the start of the control before the foreground or icon.
558             /// </summary>
559             Begin,
560             /// <summary>
561             /// At the end of the control after the foreground or icon.
562             /// </summary>
563             End,
564             /// <summary>
565             /// At the top of the control above the foreground or icon.
566             /// </summary>
567             Top,
568             /// <summary>
569             /// At the bottom of the control below the foreground or icon.
570             /// </summary>
571             Bottom
572         }
573
574         /// <summary>
575         /// Gets or sets the unselected button foreground or icon visual.
576         /// </summary>
577         /// <since_tizen> 3 </since_tizen>
578         public Tizen.NUI.PropertyMap UnselectedVisual
579         {
580             get
581             {
582                 return (PropertyMap)GetValue(UnselectedVisualProperty);
583             }
584             set
585             {
586                 SetValue(UnselectedVisualProperty, value);
587             }
588         }
589
590         /// <summary>
591         /// Gets or sets the selected button foreground or icon visual.
592         /// </summary>
593         /// <since_tizen> 3 </since_tizen>
594         public Tizen.NUI.PropertyMap SelectedVisual
595         {
596             get
597             {
598                 return (PropertyMap)GetValue(SelectedVisualProperty);
599             }
600             set
601             {
602                 SetValue(SelectedVisualProperty, value);
603             }
604         }
605
606         /// <summary>
607         /// Gets or sets the disabled selected state foreground or icon button visual.
608         /// </summary>
609         /// <since_tizen> 3 </since_tizen>
610         public Tizen.NUI.PropertyMap DisabledSelectedVisual
611         {
612             get
613             {
614                 return (PropertyMap)GetValue(DisabledSelectedVisualProperty);
615             }
616             set
617             {
618                 SetValue(DisabledSelectedVisualProperty, value);
619             }
620         }
621
622         /// <summary>
623         /// Gets or sets the disabled unselected state foreground or icon visual.
624         /// </summary>
625         /// <since_tizen> 3 </since_tizen>
626         public Tizen.NUI.PropertyMap DisabledUnselectedVisual
627         {
628             get
629             {
630                 return (PropertyMap)GetValue(DisabledUnselectedVisualProperty);
631             }
632             set
633             {
634                 SetValue(DisabledUnselectedVisualProperty, value);
635             }
636         }
637
638         /// <summary>
639         /// Gets or sets the disabled unselected state background button visual.
640         /// </summary>
641         /// <since_tizen> 3 </since_tizen>
642         public Tizen.NUI.PropertyMap UnselectedBackgroundVisual
643         {
644             get
645             {
646                 return (PropertyMap)GetValue(UnselectedBackgroundVisualProperty);
647             }
648             set
649             {
650                 SetValue(UnselectedBackgroundVisualProperty, value);
651             }
652         }
653
654         /// <summary>
655         /// Gets or sets the selected background button visual.
656         /// </summary>
657         /// <since_tizen> 3 </since_tizen>
658         public Tizen.NUI.PropertyMap SelectedBackgroundVisual
659         {
660             get
661             {
662                 return (PropertyMap)GetValue(SelectedBackgroundVisualProperty);
663             }
664             set
665             {
666                 SetValue(SelectedBackgroundVisualProperty, value);
667             }
668         }
669
670         /// <summary>
671         /// Gets or sets the disabled while unselected background button visual.
672         /// </summary>
673         /// <since_tizen> 3 </since_tizen>
674         public Tizen.NUI.PropertyMap DisabledUnselectedBackgroundVisual
675         {
676             get
677             {
678                 return (PropertyMap)GetValue(DisabledUnselectedBackgroundVisualProperty);
679             }
680             set
681             {
682                 SetValue(DisabledUnselectedBackgroundVisualProperty, value);
683             }
684         }
685
686         /// <summary>
687         /// Gets or sets the disabled while selected background button visual.
688         /// </summary>
689         /// <since_tizen> 3 </since_tizen>
690         public Tizen.NUI.PropertyMap DisabledSelectedBackgroundVisual
691         {
692             get
693             {
694                 return (PropertyMap)GetValue(DisabledSelectedBackgroundVisualProperty);
695             }
696             set
697             {
698                 SetValue(DisabledSelectedBackgroundVisualProperty, value);
699             }
700         }
701
702         /// <summary>
703         /// Gets or sets the position of the the label in relation to the foreground or icon, if both present.
704         /// </summary>
705         /// <since_tizen> 3 </since_tizen>
706         public Align LabelRelativeAlignment
707         {
708             get
709             {
710                 return (Align)GetValue(LabelRelativeAlignmentProperty);
711             }
712             set
713             {
714                 SetValue(LabelRelativeAlignmentProperty, value);
715             }
716         }
717
718         /// <summary>
719         /// Gets or sets the padding around the text.
720         /// </summary>
721         /// <since_tizen> 3 </since_tizen>
722         public Vector4 LabelPadding
723         {
724             get
725             {
726                 return (Vector4)GetValue(LabelPaddingProperty);
727             }
728             set
729             {
730                 SetValue(LabelPaddingProperty, value);
731             }
732         }
733
734         /// <summary>
735         /// Gets or sets the padding around the foreground visual.
736         /// </summary>
737         /// <since_tizen> 3 </since_tizen>
738         public Vector4 ForegroundVisualPadding
739         {
740             get
741             {
742                 return (Vector4)GetValue(ForegroundVisualPaddingProperty);
743             }
744             set
745             {
746                 SetValue(ForegroundVisualPaddingProperty, value);
747             }
748         }
749
750         /// <summary>
751         /// If the autorepeating property is set to true, then the togglable property is set to false.
752         /// </summary>
753         /// <since_tizen> 3 </since_tizen>
754         public bool AutoRepeating
755         {
756             get
757             {
758                 return (bool)GetValue(AutoRepeatingProperty);
759             }
760             set
761             {
762                 SetValue(AutoRepeatingProperty, value);
763             }
764         }
765
766         /// <summary>
767         /// By default, this value is set to 0.15 seconds.
768         /// </summary>
769         /// <since_tizen> 3 </since_tizen>
770         public float InitialAutoRepeatingDelay
771         {
772             get
773             {
774                 return (float)GetValue(InitialAutoRepeatingDelayProperty);
775             }
776             set
777             {
778                 SetValue(InitialAutoRepeatingDelayProperty, value);
779             }
780         }
781
782         /// <summary>
783         /// By default, this value is set to 0.05 seconds.
784         /// </summary>
785         /// <since_tizen> 3 </since_tizen>
786         public float NextAutoRepeatingDelay
787         {
788             get
789             {
790                 return (float)GetValue(NextAutoRepeatingDelayProperty);
791             }
792             set
793             {
794                 SetValue(NextAutoRepeatingDelayProperty, value);
795             }
796         }
797
798         /// <summary>
799         /// If the togglable property is set to true, then the autorepeating property is set to false.
800         /// </summary>
801         /// <since_tizen> 3 </since_tizen>
802         public bool Togglable
803         {
804             get
805             {
806                 return (bool)GetValue(TogglableProperty);
807             }
808             set
809             {
810                 SetValue(TogglableProperty, value);
811             }
812         }
813
814         /// <summary>
815         /// Gets or sets the togglable button as either selected or unselected, togglable property must be set to true.
816         /// </summary>
817         /// <since_tizen> 3 </since_tizen>
818         public bool Selected
819         {
820             get
821             {
822                 return (bool)GetValue(SelectedProperty);
823             }
824             set
825             {
826                 SetValue(SelectedProperty, value);
827             }
828         }
829
830         /// <summary>
831         /// Gets or sets the unselected color.
832         /// </summary>
833         /// <since_tizen> 3 </since_tizen>
834         public Color UnselectedColor
835         {
836             get
837             {
838                 return (Color)GetValue(UnselectedColorProperty);
839             }
840             set
841             {
842                 SetValue(UnselectedColorProperty, value);
843             }
844         }
845
846         /// <summary>
847         /// Gets or sets the selected color.
848         /// </summary>
849         /// <since_tizen> 3 </since_tizen>
850         public Color SelectedColor
851         {
852             get
853             {
854                 return (Color)GetValue(SelectedColorProperty);
855             }
856             set
857             {
858                 SetValue(SelectedColorProperty, value);
859             }
860         }
861
862         /// <summary>
863         /// Gets or sets the label.
864         /// </summary>
865         /// <since_tizen> 3 </since_tizen>
866         public Tizen.NUI.PropertyMap Label
867         {
868             get
869             {
870                 return (PropertyMap)GetValue(LabelProperty);
871             }
872             set
873             {
874                 SetValue(LabelProperty, value);
875             }
876         }
877
878         /// <summary>
879         /// Gets or sets the text of the label.
880         /// </summary>
881         /// <since_tizen> 3 </since_tizen>
882         public string LabelText
883         {
884             get
885             {
886                 return (string)GetValue(LabelTextProperty);
887             }
888             set
889             {
890                 SetValue(LabelTextProperty, value);
891             }
892         }
893
894         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Button obj)
895         {
896             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
897         }
898
899         internal ButtonSignal PressedSignal()
900         {
901             ButtonSignal ret = new ButtonSignal(Interop.Button.Button_PressedSignal(swigCPtr), false);
902             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
903             return ret;
904         }
905
906         internal ButtonSignal ReleasedSignal()
907         {
908             ButtonSignal ret = new ButtonSignal(Interop.Button.Button_ReleasedSignal(swigCPtr), false);
909             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
910             return ret;
911         }
912
913         internal ButtonSignal ClickedSignal()
914         {
915             ButtonSignal ret = new ButtonSignal(Interop.Button.Button_ClickedSignal(swigCPtr), false);
916             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
917             return ret;
918         }
919
920         internal ButtonSignal StateChangedSignal()
921         {
922             ButtonSignal ret = new ButtonSignal(Interop.Button.Button_StateChangedSignal(swigCPtr), false);
923             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
924             return ret;
925         }
926
927         /// <summary>
928         /// To dispose the button instance.
929         /// </summary>
930         /// <since_tizen> 3 </since_tizen>
931         protected override void Dispose(DisposeTypes type)
932         {
933             if (disposed)
934             {
935                 return;
936             }
937
938             if (type == DisposeTypes.Explicit)
939             {
940                 //Called by User
941                 //Release your own managed resources here.
942                 //You should release all of your own disposable objects here.
943
944             }
945
946             //Release your own unmanaged resources here.
947             //You should not access any managed member here except static instance.
948             //because the execution order of Finalizes is non-deterministic.
949             if (this != null)
950             {
951                 DisConnectFromSignals();
952             }
953
954             if (swigCPtr.Handle != global::System.IntPtr.Zero)
955             {
956                 if (swigCMemOwn)
957                 {
958                     swigCMemOwn = false;
959                     Interop.Button.delete_Button(swigCPtr);
960                 }
961                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
962             }
963
964             base.Dispose(type);
965         }
966
967         private void DisConnectFromSignals()
968         {
969             // Save current CPtr.
970             global::System.Runtime.InteropServices.HandleRef currentCPtr = swigCPtr;
971
972             // Use BaseHandle CPtr as current might have been deleted already in derived classes.
973             swigCPtr = GetBaseHandleCPtrHandleRef;
974
975             if (_stateChangedCallback != null)
976             {
977                 StateChangedSignal().Disconnect(_stateChangedCallback);
978             }
979
980             if (_releasedCallback != null)
981             {
982                 ReleasedSignal().Disconnect(_releasedCallback);
983             }
984
985             if (_pressedCallback != null)
986             {
987                 this.PressedSignal().Disconnect(_pressedCallback);
988             }
989
990             if (_clickedCallback != null)
991             {
992                 ClickedSignal().Disconnect(_clickedCallback);
993             }
994
995             // BaseHandle CPtr is used in Registry and there is danger of deletion if we keep using it here.
996             // Restore current CPtr.
997             swigCPtr = currentCPtr;
998         }
999
1000         private bool OnClicked(IntPtr data)
1001         {
1002             if (_clickedEventHandler != null)
1003             {
1004                 return _clickedEventHandler(this, null);
1005             }
1006             return false;
1007         }
1008
1009         private bool OnPressed(IntPtr data)
1010         {
1011             if (_pressedEventHandler != null)
1012             {
1013                 return _pressedEventHandler(this, null);
1014             }
1015             return false;
1016         }
1017
1018         private bool OnReleased(IntPtr data)
1019         {
1020             if (_releasedEventHandler != null)
1021             {
1022                 return _releasedEventHandler(this, null);
1023             }
1024             return false;
1025         }
1026
1027         private bool OnStateChanged(IntPtr data)
1028         {
1029             if (_stateChangedEventHandler != null)
1030             {
1031                 return _stateChangedEventHandler(this, null);
1032             }
1033             return false;
1034         }
1035
1036         internal new class Property
1037         {
1038             internal static readonly int UNSELECTED_VISUAL = Interop.Button.Button_Property_UNSELECTED_VISUAL_get();
1039             internal static readonly int SELECTED_VISUAL = Interop.Button.Button_Property_SELECTED_VISUAL_get();
1040             internal static readonly int DISABLED_SELECTED_VISUAL = Interop.Button.Button_Property_DISABLED_SELECTED_VISUAL_get();
1041             internal static readonly int DISABLED_UNSELECTED_VISUAL = Interop.Button.Button_Property_DISABLED_UNSELECTED_VISUAL_get();
1042             internal static readonly int UNSELECTED_BACKGROUND_VISUAL = Interop.Button.Button_Property_UNSELECTED_BACKGROUND_VISUAL_get();
1043             internal static readonly int SELECTED_BACKGROUND_VISUAL = Interop.Button.Button_Property_SELECTED_BACKGROUND_VISUAL_get();
1044             internal static readonly int DISABLED_UNSELECTED_BACKGROUND_VISUAL = Interop.Button.Button_Property_DISABLED_UNSELECTED_BACKGROUND_VISUAL_get();
1045             internal static readonly int DISABLED_SELECTED_BACKGROUND_VISUAL = Interop.Button.Button_Property_DISABLED_SELECTED_BACKGROUND_VISUAL_get();
1046             internal static readonly int LABEL_RELATIVE_ALIGNMENT = Interop.Button.Button_Property_LABEL_RELATIVE_ALIGNMENT_get();
1047             internal static readonly int LABEL_PADDING = Interop.Button.Button_Property_LABEL_PADDING_get();
1048             internal static readonly int FOREGROUND_VISUAL_PADDING = Interop.Button.Button_Property_VISUAL_PADDING_get();
1049             internal static readonly int AUTO_REPEATING = Interop.Button.Button_Property_AUTO_REPEATING_get();
1050             internal static readonly int INITIAL_AUTO_REPEATING_DELAY = Interop.Button.Button_Property_INITIAL_AUTO_REPEATING_DELAY_get();
1051             internal static readonly int NEXT_AUTO_REPEATING_DELAY = Interop.Button.Button_Property_NEXT_AUTO_REPEATING_DELAY_get();
1052             internal static readonly int TOGGLABLE = Interop.Button.Button_Property_TOGGLABLE_get();
1053             internal static readonly int SELECTED = Interop.Button.Button_Property_SELECTED_get();
1054             internal static readonly int UNSELECTED_COLOR = Interop.Button.Button_Property_UNSELECTED_COLOR_get();
1055             internal static readonly int SELECTED_COLOR = Interop.Button.Button_Property_SELECTED_COLOR_get();
1056             internal static readonly int LABEL = Interop.Button.Button_Property_LABEL_get();
1057         }
1058     }
1059 }