[NUI] Change parent class of Hover, Key, Wheel and Gesture to BaseHandle (#2001)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Key.cs
1 /*
2  * Copyright(c) 2020 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
18 using System.ComponentModel;
19
20 namespace Tizen.NUI
21 {
22
23     /// <summary>
24     /// The key structure is used to store a key press.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     public class Key : BaseHandle
28     {
29
30         /// <summary>
31         /// The default constructor.
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         public Key() : this(Interop.Key.Key_New("", "", 0, 0, 0u, 0), true)
35         {
36             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
37         }
38
39         /// <summary>
40         /// The constructor.
41         /// </summary>
42         /// <param name="keyName">The name of the key pressed or command from the IMF, if later, then the following parameters will be needed.</param>
43         /// <param name="keyString">A string of input characters or key pressed.</param>
44         /// <param name="keyCode">The unique key code for the key pressed.</param>
45         /// <param name="keyModifier">The key modifier for special keys like Shift and Alt.</param>
46         /// <param name="timeStamp">The time (in ms) that the key event occurred.</param>
47         /// <param name="keyState">The state of the key event.</param>
48         internal Key(string keyName, string keyString, int keyCode, int keyModifier, uint timeStamp, Key.StateType keyState) : this(Interop.Key.Key_New(keyName, keyString, keyCode, keyModifier, timeStamp, (int)keyState), true)
49         {
50             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
51         }
52
53         internal Key(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.Key.Key_SWIGUpcast(cPtr), cMemoryOwn)
54         {
55         }
56
57         /// <summary>
58         /// Enumeration for specifying the state of the key event.
59         /// </summary>
60         /// <since_tizen> 3 </since_tizen>
61         public enum StateType
62         {
63             /// <summary>
64             /// Key Down.
65             /// </summary>
66             /// <since_tizen> 3 </since_tizen>
67             Down,
68             /// <summary>
69             /// Key Up.
70             /// </summary>
71             /// <since_tizen> 3 </since_tizen>
72             Up,
73             /// <summary>
74             /// Key Last.
75             /// </summary>
76             /// <since_tizen> 3 </since_tizen>
77             Last
78         }
79
80         /// <summary>
81         /// Device name
82         /// </summary>
83         /// <since_tizen> 3 </since_tizen>
84         public string DeviceName
85         {
86             get
87             {
88                 string ret = Interop.NDalic.GetDeviceName(swigCPtr);
89                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
90                 return ret;
91             }
92         }
93
94         /// <summary>
95         /// Name given to the key pressed.
96         /// </summary>
97         /// <since_tizen> 3 </since_tizen>
98         public string KeyPressedName
99         {
100             get
101             {
102                 string ret = Interop.Key.Key_keyPressedName_get(swigCPtr);
103                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
104                 return ret;
105             }
106             set
107             {
108                 Interop.Key.Key_keyPressedName_set(swigCPtr, value);
109                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110             }
111
112         }
113
114         /// <summary>
115         /// Get the logical key string. (eg. shift + 1 == "exclamation")
116         /// </summary>
117         /// <returns>The logical key symbol</returns>
118         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
119         [EditorBrowsable(EditorBrowsableState.Never)]
120         public string LogicalKey
121         {
122             get
123             {
124                 string ret = Interop.Key.Key_logicalKey_get(swigCPtr);
125                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
126                 return ret;
127             }
128         }
129
130         /// <summary>
131         /// Get the actual string returned that should be used for input editors.
132         /// </summary>
133         /// <returns>The key string</returns>
134         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
135         [EditorBrowsable(EditorBrowsableState.Never)]
136         public string KeyPressed
137         {
138             get
139             {
140                 return keyPressed;
141             }
142         }
143
144         /// <summary>
145         /// Get the actual string returned that should be used for input editors.
146         /// </summary>
147         /// <returns>The key string</returns>
148         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
149         [EditorBrowsable(EditorBrowsableState.Never)]
150         public string KeyString
151         {
152             get
153             {
154                 string ret = Interop.Key.Key_keyString_get(swigCPtr);
155                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
156                 return ret;
157             }
158             set
159             {
160                 Interop.Key.Key_keyString_set(swigCPtr, value);
161                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162             }
163         }
164
165         /// <summary>
166         /// Keycode for the key pressed.
167         /// </summary>
168         /// <since_tizen> 3 </since_tizen>
169         public int KeyCode
170         {
171             get
172             {
173                 int ret = Interop.Key.Key_keyCode_get(swigCPtr);
174                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175                 return ret;
176             }
177             set
178             {
179                 Interop.Key.Key_keyCode_set(swigCPtr, value);
180                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181             }
182         }
183
184         /// <summary>
185         /// Special keys like Shift, Alt, and Ctrl which modify the next key pressed.
186         /// </summary>
187         /// <since_tizen> 3 </since_tizen>
188         public int KeyModifier
189         {
190             get
191             {
192                 int ret = Interop.Key.Key_keyModifier_get(swigCPtr);
193                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194                 return ret;
195             }
196             set
197             {
198                 Interop.Key.Key_keyModifier_set(swigCPtr, value);
199                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
200             }
201         }
202
203         /// <summary>
204         /// The time (in ms) that the key event occurred.
205         /// </summary>
206         /// <since_tizen> 3 </since_tizen>
207         public uint Time
208         {
209             get
210             {
211                 uint ret = Interop.Key.Key_time_get(swigCPtr);
212                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213                 return ret;
214             }
215             set
216             {
217                 Interop.Key.Key_time_set(swigCPtr, value);
218                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219             }
220         }
221
222         /// <summary>
223         /// State of the key event.
224         /// </summary>
225         /// <since_tizen> 3 </since_tizen>
226         public Key.StateType State
227         {
228             get
229             {
230                 Key.StateType ret = (Key.StateType)Interop.Key.Key_state_get(swigCPtr);
231                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
232                 return ret;
233             }
234             set
235             {
236                 Interop.Key.Key_state_set(swigCPtr, (int)value);
237                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238             }
239         }
240
241         /// <summary>
242         /// Get the device class the key event originated from.
243         /// </summary>
244         /// <since_tizen> 3 </since_tizen>
245         public DeviceClassType DeviceClass
246         {
247             get
248             {
249                 int ret = Interop.NDalic.GetDeviceClass(swigCPtr);
250                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
251                 return (DeviceClassType)ret;
252             }
253         }
254
255         /// <summary>
256         /// Get the device subclass the key event originated from.
257         /// </summary>
258         /// <since_tizen> 4 </since_tizen>
259         public DeviceSubClassType DeviceSubClass
260         {
261             get
262             {
263                 int ret = Interop.NDalic.GetDeviceSubClass(swigCPtr);
264                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265                 return (DeviceSubClassType)ret;
266             }
267         }
268
269         private string keyPressed
270         {
271             set
272             {
273                 Interop.Key.Key_keyPressed_set(swigCPtr, value);
274                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275             }
276             get
277             {
278                 string ret = Interop.Key.Key_keyPressed_get(swigCPtr);
279                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
280                 return ret;
281             }
282         }
283
284         /// <summary>
285         /// Checks to see if the Shift key modifier has been supplied.
286         /// </summary>
287         /// <returns>True if Shift modifier.</returns>
288         /// <since_tizen> 3 </since_tizen>
289         public bool IsShiftModifier()
290         {
291             bool ret = Interop.Key.Key_IsShiftModifier(swigCPtr);
292             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293             return ret;
294         }
295
296         /// <summary>
297         /// Checks to see if Ctrl (control) key modifier has been supplied.
298         /// </summary>
299         /// <returns>True if Ctrl modifier.</returns>
300         /// <since_tizen> 3 </since_tizen>
301         public bool IsCtrlModifier()
302         {
303             bool ret = Interop.Key.Key_IsCtrlModifier(swigCPtr);
304             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305             return ret;
306         }
307
308         /// <summary>
309         /// Checks to see if Alt key modifier has been supplied.
310         /// </summary>
311         /// <returns>True if Alt modifier.</returns>
312         /// <since_tizen> 3 </since_tizen>
313         public bool IsAltModifier()
314         {
315             bool ret = Interop.Key.Key_IsAltModifier(swigCPtr);
316             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317             return ret;
318         }
319
320         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Key obj)
321         {
322             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
323         }
324
325         internal static Key GetKeyFromPtr(global::System.IntPtr cPtr)
326         {
327             Key ret = Registry.GetManagedBaseHandleFromNativePtr(cPtr) as Key;
328             if (ret == null)
329             {
330                 ret = new Key(cPtr, false);
331             }
332             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333             return ret;
334         }
335
336         /// This will not be public opened.
337         [EditorBrowsable(EditorBrowsableState.Never)]
338         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
339         {
340             Interop.Key.delete_Key(swigCPtr);
341         }
342     }
343 }