Ensuring that Registry.Unregister is called from the most derived class before the...
[platform/core/csapi/nui.git] / Tizen.NUI / src / public / UIComponents / PushButton.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 using System;
18 using Tizen.NUI.BaseComponents;
19
20 namespace Tizen.NUI.UIComponents
21 {
22
23     /// <summary>
24     /// A PushButton changes its appearance when is pressed and returns to its original when is released.
25     /// </summary>
26     public class PushButton : Button
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29
30         internal PushButton(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PushButton_SWIGUpcast(cPtr), cMemoryOwn)
31         {
32             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
33         }
34
35         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PushButton obj)
36         {
37             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
38         }
39
40         /// <summary>
41         /// To make PushButton instance be disposed.
42         /// </summary>
43         protected override void Dispose(DisposeTypes type)
44         {
45             if (disposed)
46             {
47                 return;
48             }
49
50             if(type == DisposeTypes.Explicit)
51             {
52                 //Called by User
53                 //Release your own managed resources here.
54                 //You should release all of your own disposable objects here.
55             }
56
57             //Release your own unmanaged resources here.
58             //You should not access any managed member here except static instance.
59             //because the execution order of Finalizes is non-deterministic.
60
61             if (swigCPtr.Handle != global::System.IntPtr.Zero)
62             {
63                 if (swigCMemOwn)
64                 {
65                     swigCMemOwn = false;
66
67                     //Unreference this instance from Registry.
68                     Registry.Unregister(this);
69
70                     NDalicPINVOKE.delete_PushButton(swigCPtr);
71                 }
72                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
73             }
74
75             base.Dispose(type);
76         }
77
78
79         internal class Property
80         {
81             internal static readonly int UNSELECTED_ICON = NDalicPINVOKE.PushButton_Property_UNSELECTED_ICON_get();
82             internal static readonly int SELECTED_ICON = NDalicPINVOKE.PushButton_Property_SELECTED_ICON_get();
83             internal static readonly int ICON_ALIGNMENT = NDalicPINVOKE.PushButton_Property_ICON_ALIGNMENT_get();
84             internal static readonly int LABEL_PADDING = NDalicPINVOKE.PushButton_Property_LABEL_PADDING_get();
85             internal static readonly int ICON_PADDING = NDalicPINVOKE.PushButton_Property_ICON_PADDING_get();
86         }
87
88         /// <summary>
89         /// Creates the PushButton.
90         /// </summary>
91         public PushButton() : this(NDalicPINVOKE.PushButton_New(), true)
92         {
93             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
94
95         }
96
97         [Obsolete("Please do not use! this will be deprecated")]
98         public new static PushButton DownCast(BaseHandle handle)
99         {
100             PushButton ret = new PushButton(NDalicPINVOKE.PushButton_DownCast(BaseHandle.getCPtr(handle)), true);
101             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
102             return ret;
103         }
104
105         [Obsolete("Please do not use! this will be deprecated")]
106         public string UnselectedIcon
107         {
108             set
109             {
110                 SetProperty(PushButton.Property.UNSELECTED_ICON, new Tizen.NUI.PropertyValue(value));
111             }
112         }
113         [Obsolete("Please do not use! this will be deprecated")]
114         public string SelectedIcon
115         {
116             set
117             {
118                 SetProperty(PushButton.Property.SELECTED_ICON, new Tizen.NUI.PropertyValue(value));
119             }
120         }
121         [Obsolete("Please do not use! this will be deprecated")]
122         public IconAlignmentType IconAlignment
123         {
124             get
125             {
126                 string temp;
127                 if (GetProperty(PushButton.Property.ICON_ALIGNMENT).Get(out temp) == false)
128                 {
129                     NUILog.Error("IconAlignment get error!");
130                 }
131                 switch (temp)
132                 {
133                     case "LEFT":
134                         return IconAlignmentType.Left;
135                     case "RIGHT":
136                         return IconAlignmentType.Right;
137                     case "TOP":
138                         return IconAlignmentType.Top;
139                     case "BOTTOM":
140                         return IconAlignmentType.Bottom;
141                     default:
142                         return IconAlignmentType.Default;
143                 }
144             }
145             set
146             {
147                 string valueToString = "";
148                 switch (value)
149                 {
150                     case IconAlignmentType.Left:
151                         {
152                             valueToString = "LEFT";
153                             break;
154                         }
155                     case IconAlignmentType.Right:
156                         {
157                             valueToString = "RIGHT";
158                             break;
159                         }
160                     case IconAlignmentType.Top:
161                         {
162                             valueToString = "TOP";
163                             break;
164                         }
165                     case IconAlignmentType.Bottom:
166                         {
167                             valueToString = "BOTTOM";
168                             break;
169                         }
170                     default:
171                         {
172                             valueToString = "DEFAULT";
173                             break;
174                         }
175                 }
176                 SetProperty(PushButton.Property.ICON_ALIGNMENT, new Tizen.NUI.PropertyValue(valueToString));
177             }
178         }
179         [Obsolete("Please do not use! this will be deprecated")]
180         public Vector4 LabelPadding
181         {
182             get
183             {
184                 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
185                 GetProperty(PushButton.Property.LABEL_PADDING).Get(temp);
186                 return temp;
187             }
188             set
189             {
190                 SetProperty(PushButton.Property.LABEL_PADDING, new Tizen.NUI.PropertyValue(value));
191             }
192         }
193
194         [Obsolete("Please do not use! this will be deprecated")]
195         public Vector4 IconPadding
196         {
197             get
198             {
199                 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
200                 GetProperty(PushButton.Property.ICON_PADDING).Get(temp);
201                 return temp;
202             }
203             set
204             {
205                 SetProperty(PushButton.Property.ICON_PADDING, new Tizen.NUI.PropertyValue(value));
206             }
207         }
208
209         [Obsolete("Please do not use! this will be deprecated")]
210         public enum IconAlignmentType
211         {
212             /// <summary>
213             /// Icon located to the left of text.
214             /// </summary>
215             Left,
216             /// <summary>
217             /// Icon located to the right of text.
218             /// </summary>
219             Right,
220             /// <summary>
221             /// Icon located to the top of text.
222             /// </summary>
223             Top,
224             /// <summary>
225             /// Icon located to the bottom of text.
226             /// </summary>
227             Bottom,
228             /// <summary>
229             /// Icon located to the right of text by default.
230             /// </summary>
231             Default = Right
232         }
233
234     }
235 }