2 * Copyright(c) 2017 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
22 /// The key structure is used to store a key press.
24 /// <since_tizen> 3 </since_tizen>
25 public class Key : global::System.IDisposable
27 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31 /// <since_tizen> 3 </since_tizen>
32 protected bool swigCMemOwn;
34 internal Key(global::System.IntPtr cPtr, bool cMemoryOwn)
36 swigCMemOwn = cMemoryOwn;
37 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
40 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Key obj)
42 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
45 //A Flag to check who called Dispose(). (By User or DisposeQueue)
46 private bool isDisposeQueued = false;
48 /// A Flat to check if it is already disposed.
50 /// <since_tizen> 3 </since_tizen>
51 protected bool disposed = false;
56 /// <since_tizen> 3 </since_tizen>
61 isDisposeQueued = true;
62 DisposeQueue.Instance.Add(this);
69 /// <since_tizen> 3 </since_tizen>
72 //Throw excpetion if Dispose() is called in separate thread.
73 if (!Window.IsInstalled())
75 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
80 Dispose(DisposeTypes.Implicit);
84 Dispose(DisposeTypes.Explicit);
85 System.GC.SuppressFinalize(this);
92 /// <param name="type">The dispose type.</param>
93 /// <since_tizen> 3 </since_tizen>
94 protected virtual void Dispose(DisposeTypes type)
101 if(type == DisposeTypes.Explicit)
104 //Release your own managed resources here.
105 //You should release all of your own disposable objects here.
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.
112 if (swigCPtr.Handle != global::System.IntPtr.Zero)
117 NDalicPINVOKE.delete_Key(swigCPtr);
119 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
125 internal static Key GetKeyFromPtr(global::System.IntPtr cPtr)
127 Key ret = new Key(cPtr, false);
128 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
135 /// <since_tizen> 3 </since_tizen>
136 public string DeviceName
140 string ret = NDalicPINVOKE.GetDeviceName(swigCPtr);
141 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
147 /// Name given to the key pressed.
149 /// <since_tizen> 3 </since_tizen>
150 public string KeyPressedName
154 return keyPressedName;
158 keyPressedName = value;
162 /* duplicated with KeyPressedName : removed
163 public string KeyPressed
173 /// Keycode for the key pressed.
175 /// <since_tizen> 3 </since_tizen>
189 /// Special keys like Shift, Alt, and Ctrl which modify the next key pressed.
191 /// <since_tizen> 3 </since_tizen>
192 public int KeyModifier
205 /// The time (in ms) that the key event occurred.
207 /// <since_tizen> 3 </since_tizen>
221 /// State of the key event.
223 /// <since_tizen> 3 </since_tizen>
224 public Key.StateType State
237 /// Get the device class the key event originated from.
239 /// <since_tizen> 3 </since_tizen>
240 public DeviceClassType DeviceClass
244 int ret = NDalicPINVOKE.GetDeviceClass(swigCPtr);
245 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246 return (DeviceClassType)ret;
251 /// Get the device subclass the key event originated from.
253 /// <since_tizen> 4 </since_tizen>
254 public DeviceSubClassType DeviceSubClass
258 int ret = NDalicPINVOKE.GetDeviceSubClass(swigCPtr);
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260 return (DeviceSubClassType)ret;
265 /// The default constructor.
267 /// <since_tizen> 3 </since_tizen>
268 public Key() : this(NDalicPINVOKE.new_Key__SWIG_0(), true)
270 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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)
284 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288 /// Checks to see if the Shift key modifier has been supplied.
290 /// <returns>True if Shift modifier.</returns>
291 /// <since_tizen> 3 </since_tizen>
292 public bool IsShiftModifier()
294 bool ret = NDalicPINVOKE.Key_IsShiftModifier(swigCPtr);
295 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300 /// Checks to see if Ctrl (control) key modifier has been supplied.
302 /// <returns>True if Ctrl modifier.</returns>
303 /// <since_tizen> 3 </since_tizen>
304 public bool IsCtrlModifier()
306 bool ret = NDalicPINVOKE.Key_IsCtrlModifier(swigCPtr);
307 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312 /// Checks to see if Alt key modifier has been supplied.
314 /// <returns>True if Alt modifier.</returns>
315 /// <since_tizen> 3 </since_tizen>
316 public bool IsAltModifier()
318 bool ret = NDalicPINVOKE.Key_IsAltModifier(swigCPtr);
319 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323 private string keyPressedName
327 NDalicPINVOKE.Key_keyPressedName_set(swigCPtr, value);
328 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332 string ret = NDalicPINVOKE.Key_keyPressedName_get(swigCPtr);
333 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338 private string keyPressed
342 NDalicPINVOKE.Key_keyPressed_set(swigCPtr, value);
343 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
347 string ret = NDalicPINVOKE.Key_keyPressed_get(swigCPtr);
348 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
357 NDalicPINVOKE.Key_keyCode_set(swigCPtr, value);
358 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 int ret = NDalicPINVOKE.Key_keyCode_get(swigCPtr);
363 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368 private int keyModifier
372 NDalicPINVOKE.Key_keyModifier_set(swigCPtr, value);
373 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
377 int ret = NDalicPINVOKE.Key_keyModifier_get(swigCPtr);
378 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
387 NDalicPINVOKE.Key_time_set(swigCPtr, value);
388 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
392 uint ret = NDalicPINVOKE.Key_time_get(swigCPtr);
393 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
398 private Key.StateType state
402 NDalicPINVOKE.Key_state_set(swigCPtr, (int)value);
403 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
407 Key.StateType ret = (Key.StateType)NDalicPINVOKE.Key_state_get(swigCPtr);
408 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
414 /// Enumeration for specifying the state of the key event.
416 /// <since_tizen> 3 </since_tizen>
417 public enum StateType
422 /// <since_tizen> 3 </since_tizen>
427 /// <since_tizen> 3 </since_tizen>
432 /// <since_tizen> 3 </since_tizen>