[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Key.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
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         /// <summary>
30         /// swigCMemOwn
31         /// </summary>
32         /// <since_tizen> 3 </since_tizen>
33         protected bool swigCMemOwn;
34
35         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
36
37         /// <summary>
38         /// The default constructor.
39         /// </summary>
40         /// <since_tizen> 3 </since_tizen>
41         public Key() : this(Interop.Key.new_Key__SWIG_0(), true)
42         {
43             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
44         }
45
46         /// <summary>
47         /// The constructor.
48         /// </summary>
49         /// <param name="keyName">The name of the key pressed or command from the IMF, if later, then the following parameters will be needed.</param>
50         /// <param name="keyString">A string of input characters or key pressed.</param>
51         /// <param name="keyCode">The unique key code for the key pressed.</param>
52         /// <param name="keyModifier">The key modifier for special keys like Shift and Alt.</param>
53         /// <param name="timeStamp">The time (in ms) that the key event occurred.</param>
54         /// <param name="keyState">The state of the key event.</param>
55         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)
56         {
57             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
58         }
59
60         internal Key(global::System.IntPtr cPtr, bool cMemoryOwn)
61         {
62             swigCMemOwn = cMemoryOwn;
63             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
64         }
65
66         /// <summary>
67         /// Enumeration for specifying the state of the key event.
68         /// </summary>
69         /// <since_tizen> 3 </since_tizen>
70         public enum StateType
71         {
72             /// <summary>
73             /// Key Down.
74             /// </summary>
75             /// <since_tizen> 3 </since_tizen>
76             Down,
77             /// <summary>
78             /// Key Up.
79             /// </summary>
80             /// <since_tizen> 3 </since_tizen>
81             Up,
82             /// <summary>
83             /// Key Last.
84             /// </summary>
85             /// <since_tizen> 3 </since_tizen>
86             Last
87         }
88
89         /// <summary>
90         /// Device name
91         /// </summary>
92         /// <since_tizen> 3 </since_tizen>
93         public string DeviceName
94         {
95             get
96             {
97                 string ret = Interop.NDalic.GetDeviceName(swigCPtr);
98                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99                 return ret;
100             }
101         }
102
103         /// <summary>
104         /// Name given to the key pressed.
105         /// </summary>
106         /// <since_tizen> 3 </since_tizen>
107         public string KeyPressedName
108         {
109             get
110             {
111                 return keyPressedName;
112             }
113             set
114             {
115                 keyPressedName = value;
116             }
117         }
118
119         /// <summary>
120         /// Get the logical key string. (eg. shift + 1 == "exclamation")
121         /// </summary>
122         /// <returns>The logical key symbol</returns>
123         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
124         [EditorBrowsable(EditorBrowsableState.Never)]
125         public string LogicalKey
126         {
127             get
128             {
129                 return logicalKey;
130             }
131         }
132
133         /// <summary>
134         /// Get the actual string returned that should be used for input editors.
135         /// </summary>
136         /// <returns>The key string</returns>
137         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
138         [EditorBrowsable(EditorBrowsableState.Never)]
139         public string KeyPressed
140         {
141             get
142             {
143                 return keyPressed;
144             }
145         }
146
147         /// <summary>
148         /// Get the actual string returned that should be used for input editors.
149         /// </summary>
150         /// <returns>The key string</returns>
151         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
152         [EditorBrowsable(EditorBrowsableState.Never)]
153         public string KeyString
154         {
155             get
156             {
157                 return keyString;
158             }
159             set
160             {
161                 keyString = value;
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                 return keyCode;
174             }
175             set
176             {
177                 keyCode = value;
178             }
179         }
180
181         /// <summary>
182         /// Special keys like Shift, Alt, and Ctrl which modify the next key pressed.
183         /// </summary>
184         /// <since_tizen> 3 </since_tizen>
185         public int KeyModifier
186         {
187             get
188             {
189                 return keyModifier;
190             }
191             set
192             {
193                 keyModifier = value;
194             }
195         }
196
197         /// <summary>
198         /// The time (in ms) that the key event occurred.
199         /// </summary>
200         /// <since_tizen> 3 </since_tizen>
201         public uint Time
202         {
203             get
204             {
205                 return time;
206             }
207             set
208             {
209                 time = value;
210             }
211         }
212
213         /// <summary>
214         /// State of the key event.
215         /// </summary>
216         /// <since_tizen> 3 </since_tizen>
217         public Key.StateType State
218         {
219             get
220             {
221                 return state;
222             }
223             set
224             {
225                 state = value;
226             }
227         }
228
229         /// <summary>
230         /// Get the device class the key event originated from.
231         /// </summary>
232         /// <since_tizen> 3 </since_tizen>
233         public DeviceClassType DeviceClass
234         {
235             get
236             {
237                 int ret = Interop.NDalic.GetDeviceClass(swigCPtr);
238                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239                 return (DeviceClassType)ret;
240             }
241         }
242
243         /// <summary>
244         /// Get the device subclass the key event originated from.
245         /// </summary>
246         /// <since_tizen> 4 </since_tizen>
247         public DeviceSubClassType DeviceSubClass
248         {
249             get
250             {
251                 int ret = Interop.NDalic.GetDeviceSubClass(swigCPtr);
252                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253                 return (DeviceSubClassType)ret;
254             }
255         }
256
257         private string keyPressedName
258         {
259             set
260             {
261                 Interop.Key.Key_keyPressedName_set(swigCPtr, value);
262                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263             }
264             get
265             {
266                 string ret = Interop.Key.Key_keyPressedName_get(swigCPtr);
267                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268                 return ret;
269             }
270         }
271
272         private string keyPressed
273         {
274             set
275             {
276                 Interop.Key.Key_keyPressed_set(swigCPtr, value);
277                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278             }
279             get
280             {
281                 string ret = Interop.Key.Key_keyPressed_get(swigCPtr);
282                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
283                 return ret;
284             }
285         }
286
287         private string keyString
288         {
289             set
290             {
291                 Interop.Key.Key_keyString_set(swigCPtr, value);
292                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
293             }
294             get
295             {
296                 string ret = Interop.Key.Key_keyString_get(swigCPtr);
297                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298                 return ret;
299             }
300         }
301
302         private int keyCode
303         {
304             set
305             {
306                 Interop.Key.Key_keyCode_set(swigCPtr, value);
307                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308             }
309             get
310             {
311                 int ret = Interop.Key.Key_keyCode_get(swigCPtr);
312                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313                 return ret;
314             }
315         }
316
317         private int keyModifier
318         {
319             set
320             {
321                 Interop.Key.Key_keyModifier_set(swigCPtr, value);
322                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323             }
324             get
325             {
326                 int ret = Interop.Key.Key_keyModifier_get(swigCPtr);
327                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328                 return ret;
329             }
330         }
331
332         private uint time
333         {
334             set
335             {
336                 Interop.Key.Key_time_set(swigCPtr, value);
337                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338             }
339             get
340             {
341                 uint ret = Interop.Key.Key_time_get(swigCPtr);
342                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343                 return ret;
344             }
345         }
346
347         private Key.StateType state
348         {
349             set
350             {
351                 Interop.Key.Key_state_set(swigCPtr, (int)value);
352                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
353             }
354             get
355             {
356                 Key.StateType ret = (Key.StateType)Interop.Key.Key_state_get(swigCPtr);
357                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
358                 return ret;
359             }
360         }
361
362         private string logicalKey
363         {
364             get
365             {
366                 string ret = Interop.Key.Key_logicalKey_get(swigCPtr);
367                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368                 return "";
369             }
370         }
371
372         /// <summary>
373         /// Checks to see if the Shift key modifier has been supplied.
374         /// </summary>
375         /// <returns>True if Shift modifier.</returns>
376         /// <since_tizen> 3 </since_tizen>
377         public bool IsShiftModifier()
378         {
379             bool ret = Interop.Key.Key_IsShiftModifier(swigCPtr);
380             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
381             return ret;
382         }
383
384         /// <summary>
385         /// Checks to see if Ctrl (control) key modifier has been supplied.
386         /// </summary>
387         /// <returns>True if Ctrl modifier.</returns>
388         /// <since_tizen> 3 </since_tizen>
389         public bool IsCtrlModifier()
390         {
391             bool ret = Interop.Key.Key_IsCtrlModifier(swigCPtr);
392             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
393             return ret;
394         }
395
396         /// <summary>
397         /// Checks to see if Alt key modifier has been supplied.
398         /// </summary>
399         /// <returns>True if Alt modifier.</returns>
400         /// <since_tizen> 3 </since_tizen>
401         public bool IsAltModifier()
402         {
403             bool ret = Interop.Key.Key_IsAltModifier(swigCPtr);
404             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
405             return ret;
406         }
407
408         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Key obj)
409         {
410             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
411         }
412
413         internal static Key GetKeyFromPtr(global::System.IntPtr cPtr)
414         {
415             Key ret = new Key(cPtr, false);
416             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
417             return ret;
418         }
419
420         /// <summary>
421         /// Dispose.
422         /// </summary>
423         /// <param name="type">The dispose type.</param>
424         /// <since_tizen> 3 </since_tizen>
425         protected override void Dispose(DisposeTypes type)
426         {
427             if (disposed)
428             {
429                 return;
430             }
431
432             //Release your own unmanaged resources here.
433             //You should not access any managed member here except static instance.
434             //because the execution order of Finalizes is non-deterministic.
435
436             if (swigCPtr.Handle != global::System.IntPtr.Zero)
437             {
438                 if (swigCMemOwn)
439                 {
440                     swigCMemOwn = false;
441                     Interop.Key.delete_Key(swigCPtr);
442                 }
443                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
444             }
445             base.Dispose(type);
446         }
447     }
448 }