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