Sync upstream
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Key.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
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 : Disposable
28     {
29
30         /// <summary>
31         /// The default constructor.
32         /// </summary>
33         /// <since_tizen> 3 </since_tizen>
34         public Key() : this(Interop.Key.new_Key__SWIG_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.new_Key__SWIG_1(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(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                 return keyPressedName;
103             }
104             set
105             {
106                 keyPressedName = value;
107             }
108         }
109
110         /// <summary>
111         /// Get the logical key string. (eg. shift + 1 == "exclamation")
112         /// </summary>
113         /// <returns>The logical key symbol</returns>
114         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
115         [EditorBrowsable(EditorBrowsableState.Never)]
116         public string LogicalKey
117         {
118             get
119             {
120                 return logicalKey;
121             }
122         }
123
124         /// <summary>
125         /// Get the actual string returned that should be used for input editors.
126         /// </summary>
127         /// <returns>The key string</returns>
128         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
129         [EditorBrowsable(EditorBrowsableState.Never)]
130         public string KeyPressed
131         {
132             get
133             {
134                 return keyPressed;
135             }
136         }
137
138         /// <summary>
139         /// Get the actual string returned that should be used for input editors.
140         /// </summary>
141         /// <returns>The key string</returns>
142         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
143         [EditorBrowsable(EditorBrowsableState.Never)]
144         public string KeyString
145         {
146             get
147             {
148                 return keyString;
149             }
150             set
151             {
152                 keyString = value;
153             }
154         }
155
156         /// <summary>
157         /// Keycode for the key pressed.
158         /// </summary>
159         /// <since_tizen> 3 </since_tizen>
160         public int KeyCode
161         {
162             get
163             {
164                 return keyCode;
165             }
166             set
167             {
168                 keyCode = value;
169             }
170         }
171
172         /// <summary>
173         /// Special keys like Shift, Alt, and Ctrl which modify the next key pressed.
174         /// </summary>
175         /// <since_tizen> 3 </since_tizen>
176         public int KeyModifier
177         {
178             get
179             {
180                 return keyModifier;
181             }
182             set
183             {
184                 keyModifier = value;
185             }
186         }
187
188         /// <summary>
189         /// The time (in ms) that the key event occurred.
190         /// </summary>
191         /// <since_tizen> 3 </since_tizen>
192         public uint Time
193         {
194             get
195             {
196                 return time;
197             }
198             set
199             {
200                 time = value;
201             }
202         }
203
204         /// <summary>
205         /// State of the key event.
206         /// </summary>
207         /// <since_tizen> 3 </since_tizen>
208         public Key.StateType State
209         {
210             get
211             {
212                 return state;
213             }
214             set
215             {
216                 state = value;
217             }
218         }
219
220         /// <summary>
221         /// Get the device class the key event originated from.
222         /// </summary>
223         /// <since_tizen> 3 </since_tizen>
224         public DeviceClassType DeviceClass
225         {
226             get
227             {
228                 int ret = Interop.NDalic.GetDeviceClass(swigCPtr);
229                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230                 return (DeviceClassType)ret;
231             }
232         }
233
234         /// <summary>
235         /// Get the device subclass the key event originated from.
236         /// </summary>
237         /// <since_tizen> 4 </since_tizen>
238         public DeviceSubClassType DeviceSubClass
239         {
240             get
241             {
242                 int ret = Interop.NDalic.GetDeviceSubClass(swigCPtr);
243                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
244                 return (DeviceSubClassType)ret;
245             }
246         }
247
248         private string keyPressedName
249         {
250             set
251             {
252                 Interop.Key.Key_keyPressedName_set(swigCPtr, value);
253                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
254             }
255             get
256             {
257                 string ret = Interop.Key.Key_keyPressedName_get(swigCPtr);
258                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259                 return ret;
260             }
261         }
262
263         private string keyPressed
264         {
265             set
266             {
267                 Interop.Key.Key_keyPressed_set(swigCPtr, value);
268                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269             }
270             get
271             {
272                 string ret = Interop.Key.Key_keyPressed_get(swigCPtr);
273                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274                 return ret;
275             }
276         }
277
278         private string keyString
279         {
280             set
281             {
282                 Interop.Key.Key_keyString_set(swigCPtr, value);
283                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284             }
285             get
286             {
287                 string ret = Interop.Key.Key_keyString_get(swigCPtr);
288                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289                 return ret;
290             }
291         }
292
293         private int keyCode
294         {
295             set
296             {
297                 Interop.Key.Key_keyCode_set(swigCPtr, value);
298                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299             }
300             get
301             {
302                 int ret = Interop.Key.Key_keyCode_get(swigCPtr);
303                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304                 return ret;
305             }
306         }
307
308         private int keyModifier
309         {
310             set
311             {
312                 Interop.Key.Key_keyModifier_set(swigCPtr, value);
313                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
314             }
315             get
316             {
317                 int ret = Interop.Key.Key_keyModifier_get(swigCPtr);
318                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319                 return ret;
320             }
321         }
322
323         private uint time
324         {
325             set
326             {
327                 Interop.Key.Key_time_set(swigCPtr, value);
328                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329             }
330             get
331             {
332                 uint ret = Interop.Key.Key_time_get(swigCPtr);
333                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334                 return ret;
335             }
336         }
337
338         private Key.StateType state
339         {
340             set
341             {
342                 Interop.Key.Key_state_set(swigCPtr, (int)value);
343                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344             }
345             get
346             {
347                 Key.StateType ret = (Key.StateType)Interop.Key.Key_state_get(swigCPtr);
348                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349                 return ret;
350             }
351         }
352
353         private string logicalKey
354         {
355             get
356             {
357                 string ret = Interop.Key.Key_logicalKey_get(swigCPtr);
358                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359                 return ret;
360             }
361         }
362
363         /// <summary>
364         /// Checks to see if the Shift key modifier has been supplied.
365         /// </summary>
366         /// <returns>True if Shift modifier.</returns>
367         /// <since_tizen> 3 </since_tizen>
368         public bool IsShiftModifier()
369         {
370             bool ret = Interop.Key.Key_IsShiftModifier(swigCPtr);
371             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
372             return ret;
373         }
374
375         /// <summary>
376         /// Checks to see if Ctrl (control) key modifier has been supplied.
377         /// </summary>
378         /// <returns>True if Ctrl modifier.</returns>
379         /// <since_tizen> 3 </since_tizen>
380         public bool IsCtrlModifier()
381         {
382             bool ret = Interop.Key.Key_IsCtrlModifier(swigCPtr);
383             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384             return ret;
385         }
386
387         /// <summary>
388         /// Checks to see if Alt key modifier has been supplied.
389         /// </summary>
390         /// <returns>True if Alt modifier.</returns>
391         /// <since_tizen> 3 </since_tizen>
392         public bool IsAltModifier()
393         {
394             bool ret = Interop.Key.Key_IsAltModifier(swigCPtr);
395             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396             return ret;
397         }
398
399         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Key obj)
400         {
401             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
402         }
403
404         internal static Key GetKeyFromPtr(global::System.IntPtr cPtr)
405         {
406             Key ret = new Key(cPtr, false);
407             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
408             return ret;
409         }
410
411         /// This will not be public opened.
412         [EditorBrowsable(EditorBrowsableState.Never)]
413         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
414         {
415             Interop.Key.delete_Key(swigCPtr);
416         }
417     }
418 }