Release 4.0.0-preview1-00301
[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         /// 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
250         /// <summary>
251         /// The default constructor.
252         /// </summary>
253         /// <since_tizen> 3 </since_tizen>
254         public Key() : this(NDalicPINVOKE.new_Key__SWIG_0(), true)
255         {
256             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257         }
258
259         /// <summary>
260         /// The constructor.
261         /// </summary>
262         /// <param name="keyName">The name of the key pressed or command from the IMF, if later, then the following parameters will be needed.</param>
263         /// <param name="keyString">A string of input characters or key pressed.</param>
264         /// <param name="keyCode">The unique key code for the key pressed.</param>
265         /// <param name="keyModifier">The key modifier for special keys like Shift and Alt.</param>
266         /// <param name="timeStamp">The time (in ms) that the key event occurred.</param>
267         /// <param name="keyState">The state of the key event.</param>
268         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)
269         {
270             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271         }
272
273         /// <summary>
274         /// Checks to see if the Shift key modifier has been supplied.
275         /// </summary>
276         /// <returns>True if Shift modifier.</returns>
277         /// <since_tizen> 3 </since_tizen>
278         public bool IsShiftModifier()
279         {
280             bool ret = NDalicPINVOKE.Key_IsShiftModifier(swigCPtr);
281             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282             return ret;
283         }
284
285         /// <summary>
286         /// Checks to see if Ctrl (control) key modifier has been supplied.
287         /// </summary>
288         /// <returns>True if Ctrl modifier.</returns>
289         /// <since_tizen> 3 </since_tizen>
290         public bool IsCtrlModifier()
291         {
292             bool ret = NDalicPINVOKE.Key_IsCtrlModifier(swigCPtr);
293             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294             return ret;
295         }
296
297         /// <summary>
298         /// Checks to see if Alt key modifier has been supplied.
299         /// </summary>
300         /// <returns>True if Alt modifier.</returns>
301         /// <since_tizen> 3 </since_tizen>
302         public bool IsAltModifier()
303         {
304             bool ret = NDalicPINVOKE.Key_IsAltModifier(swigCPtr);
305             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
306             return ret;
307         }
308
309         private string keyPressedName
310         {
311             set
312             {
313                 NDalicPINVOKE.Key_keyPressedName_set(swigCPtr, value);
314                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315             }
316             get
317             {
318                 string ret = NDalicPINVOKE.Key_keyPressedName_get(swigCPtr);
319                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320                 return ret;
321             }
322         }
323
324         private string keyPressed
325         {
326             set
327             {
328                 NDalicPINVOKE.Key_keyPressed_set(swigCPtr, value);
329                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330             }
331             get
332             {
333                 string ret = NDalicPINVOKE.Key_keyPressed_get(swigCPtr);
334                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
335                 return ret;
336             }
337         }
338
339         private int keyCode
340         {
341             set
342             {
343                 NDalicPINVOKE.Key_keyCode_set(swigCPtr, value);
344                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345             }
346             get
347             {
348                 int ret = NDalicPINVOKE.Key_keyCode_get(swigCPtr);
349                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
350                 return ret;
351             }
352         }
353
354         private int keyModifier
355         {
356             set
357             {
358                 NDalicPINVOKE.Key_keyModifier_set(swigCPtr, value);
359                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
360             }
361             get
362             {
363                 int ret = NDalicPINVOKE.Key_keyModifier_get(swigCPtr);
364                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
365                 return ret;
366             }
367         }
368
369         private uint time
370         {
371             set
372             {
373                 NDalicPINVOKE.Key_time_set(swigCPtr, value);
374                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
375             }
376             get
377             {
378                 uint ret = NDalicPINVOKE.Key_time_get(swigCPtr);
379                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
380                 return ret;
381             }
382         }
383
384         private Key.StateType state
385         {
386             set
387             {
388                 NDalicPINVOKE.Key_state_set(swigCPtr, (int)value);
389                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
390             }
391             get
392             {
393                 Key.StateType ret = (Key.StateType)NDalicPINVOKE.Key_state_get(swigCPtr);
394                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
395                 return ret;
396             }
397         }
398
399         /// <summary>
400         /// Enumeration for specifying the state of the key event.
401         /// </summary>
402         /// <since_tizen> 3 </since_tizen>
403         public enum StateType
404         {
405             /// <summary>
406             /// Key Down.
407             /// </summary>
408             /// <since_tizen> 3 </since_tizen>
409             Down,
410             /// <summary>
411             /// Key Up.
412             /// </summary>
413             /// <since_tizen> 3 </since_tizen>
414             Up,
415             /// <summary>
416             /// Key Last.
417             /// </summary>
418             /// <since_tizen> 3 </since_tizen>
419             Last
420         }
421
422     }
423 }