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