Release 4.0.0-preview1-00271
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Key.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 namespace Tizen.NUI
18 {
19
20     /// <summary>
21     /// The key structure is used to store a key press.
22     /// </summary>
23     public class Key : global::System.IDisposable
24     {
25         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26         protected bool swigCMemOwn;
27
28         internal Key(global::System.IntPtr cPtr, bool cMemoryOwn)
29         {
30             swigCMemOwn = cMemoryOwn;
31             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
32         }
33
34         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Key obj)
35         {
36             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
37         }
38
39         //A Flag to check who called Dispose(). (By User or DisposeQueue)
40         private bool isDisposeQueued = false;
41         //A Flat to check if it is already disposed.
42         protected bool disposed = false;
43
44         ~Key()
45         {
46             if(!isDisposeQueued)
47             {
48                 isDisposeQueued = true;
49                 DisposeQueue.Instance.Add(this);
50             }
51         }
52
53         public void Dispose()
54         {
55             //Throw excpetion if Dispose() is called in separate thread.
56             if (!Window.IsInstalled())
57             {
58                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
59             }
60
61             if (isDisposeQueued)
62             {
63                 Dispose(DisposeTypes.Implicit);
64             }
65             else
66             {
67                 Dispose(DisposeTypes.Explicit);
68                 System.GC.SuppressFinalize(this);
69             }
70         }
71
72         protected virtual void Dispose(DisposeTypes type)
73         {
74             if (disposed)
75             {
76                 return;
77             }
78
79             if(type == DisposeTypes.Explicit)
80             {
81                 //Called by User
82                 //Release your own managed resources here.
83                 //You should release all of your own disposable objects here.
84             }
85
86             //Release your own unmanaged resources here.
87             //You should not access any managed member here except static instance.
88             //because the execution order of Finalizes is non-deterministic.
89
90             if (swigCPtr.Handle != global::System.IntPtr.Zero)
91             {
92                 if (swigCMemOwn)
93                 {
94                     swigCMemOwn = false;
95                     NDalicPINVOKE.delete_Key(swigCPtr);
96                 }
97                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
98             }
99             disposed = true;
100         }
101
102
103         internal static Key GetKeyFromPtr(global::System.IntPtr cPtr)
104         {
105             Key ret = new Key(cPtr, false);
106             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107             return ret;
108         }
109
110         public string DeviceName
111         {
112             get
113             {
114                 string ret = NDalicPINVOKE.GetDeviceName(swigCPtr);
115                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
116                 return ret;
117             }
118         }
119
120         /// <summary>
121         /// Name given to the key pressed.
122         /// </summary>
123         /// <since_tizen> 3 </since_tizen>
124         public string KeyPressedName
125         {
126             get
127             {
128                 return keyPressedName;
129             }
130             set
131             {
132                 keyPressedName = value;
133             }
134         }
135
136         /* duplicated with KeyPressedName : removed
137         public string KeyPressed
138         {
139             get
140             {
141                 return keyPressed;
142             }
143         }
144         */
145
146         /// <summary>
147         /// Keycode for the key pressed.
148         /// </summary>
149         /// <since_tizen> 3 </since_tizen>
150         public int KeyCode
151         {
152             get
153             {
154                 return keyCode;
155             }
156             set
157             {
158                 keyCode = value;
159             }
160         }
161
162         /// <summary>
163         /// Special keys like Shift, Alt, and Ctrl which modify the next key pressed.
164         /// </summary>
165         /// <since_tizen> 3 </since_tizen>
166         public int KeyModifier
167         {
168             get
169             {
170                 return keyModifier;
171             }
172             set
173             {
174                 keyModifier = value;
175             }
176         }
177
178         /// <summary>
179         /// The time (in ms) that the key event occurred.
180         /// </summary>
181         /// <since_tizen> 3 </since_tizen>
182         public uint Time
183         {
184             get
185             {
186                 return time;
187             }
188             set
189             {
190                 time = value;
191             }
192         }
193
194         /// <summary>
195         /// State of the key event.
196         /// </summary>
197         /// <since_tizen> 3 </since_tizen>
198         public Key.StateType State
199         {
200             get
201             {
202                 return state;
203             }
204             set
205             {
206                 state = value;
207             }
208         }
209
210         public DeviceClassType DeviceClass
211         {
212             get
213             {
214                 int ret = NDalicPINVOKE.GetDeviceClass(swigCPtr);
215                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216                 return (DeviceClassType)ret;
217             }
218         }
219
220
221         /// <summary>
222         /// The default constructor.
223         /// </summary>
224         /// <since_tizen> 3 </since_tizen>
225         public Key() : this(NDalicPINVOKE.new_Key__SWIG_0(), true)
226         {
227             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228         }
229
230         /// <summary>
231         /// The constructor.
232         /// </summary>
233         /// <param name="keyName">The name of the key pressed or command from the IMF, if later, then the following parameters will be needed.</param>
234         /// <param name="keyString">A string of input characters or key pressed.</param>
235         /// <param name="keyCode">The unique key code for the key pressed.</param>
236         /// <param name="keyModifier">The key modifier for special keys like Shift and Alt.</param>
237         /// <param name="timeStamp">The time (in ms) that the key event occurred.</param>
238         /// <param name="keyState">The state of the key event.</param>
239         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)
240         {
241             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242         }
243
244         /// <summary>
245         /// Checks to see if the Shift key modifier has been supplied.
246         /// </summary>
247         /// <returns>True if Shift modifier.</returns>
248         /// <since_tizen> 3 </since_tizen>
249         public bool IsShiftModifier()
250         {
251             bool ret = NDalicPINVOKE.Key_IsShiftModifier(swigCPtr);
252             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253             return ret;
254         }
255
256         /// <summary>
257         /// Checks to see if Ctrl (control) key modifier has been supplied.
258         /// </summary>
259         /// <returns>True if Ctrl modifier.</returns>
260         /// <since_tizen> 3 </since_tizen>
261         public bool IsCtrlModifier()
262         {
263             bool ret = NDalicPINVOKE.Key_IsCtrlModifier(swigCPtr);
264             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265             return ret;
266         }
267
268         /// <summary>
269         /// Checks to see if Alt key modifier has been supplied.
270         /// </summary>
271         /// <returns>True if Alt modifier.</returns>
272         /// <since_tizen> 3 </since_tizen>
273         public bool IsAltModifier()
274         {
275             bool ret = NDalicPINVOKE.Key_IsAltModifier(swigCPtr);
276             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
277             return ret;
278         }
279
280         private string keyPressedName
281         {
282             set
283             {
284                 NDalicPINVOKE.Key_keyPressedName_set(swigCPtr, value);
285                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286             }
287             get
288             {
289                 string ret = NDalicPINVOKE.Key_keyPressedName_get(swigCPtr);
290                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291                 return ret;
292             }
293         }
294
295         private string keyPressed
296         {
297             set
298             {
299                 NDalicPINVOKE.Key_keyPressed_set(swigCPtr, value);
300                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301             }
302             get
303             {
304                 string ret = NDalicPINVOKE.Key_keyPressed_get(swigCPtr);
305                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
306                 return ret;
307             }
308         }
309
310         private int keyCode
311         {
312             set
313             {
314                 NDalicPINVOKE.Key_keyCode_set(swigCPtr, value);
315                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316             }
317             get
318             {
319                 int ret = NDalicPINVOKE.Key_keyCode_get(swigCPtr);
320                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
321                 return ret;
322             }
323         }
324
325         private int keyModifier
326         {
327             set
328             {
329                 NDalicPINVOKE.Key_keyModifier_set(swigCPtr, value);
330                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
331             }
332             get
333             {
334                 int ret = NDalicPINVOKE.Key_keyModifier_get(swigCPtr);
335                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336                 return ret;
337             }
338         }
339
340         private uint time
341         {
342             set
343             {
344                 NDalicPINVOKE.Key_time_set(swigCPtr, value);
345                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346             }
347             get
348             {
349                 uint ret = NDalicPINVOKE.Key_time_get(swigCPtr);
350                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
351                 return ret;
352             }
353         }
354
355         private Key.StateType state
356         {
357             set
358             {
359                 NDalicPINVOKE.Key_state_set(swigCPtr, (int)value);
360                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361             }
362             get
363             {
364                 Key.StateType ret = (Key.StateType)NDalicPINVOKE.Key_state_get(swigCPtr);
365                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
366                 return ret;
367             }
368         }
369
370         /// <summary>
371         /// Enumeration for specifying the state of the key event.
372         /// </summary>
373         /// <since_tizen> 3 </since_tizen>
374         public enum StateType
375         {
376             Down,
377             Up,
378             Last
379         }
380
381     }
382 }