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