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.
18 using System.ComponentModel;
24 /// The key structure is used to store a key press.
26 /// <since_tizen> 3 </since_tizen>
27 public class Key : global::System.IDisposable
32 /// <since_tizen> 3 </since_tizen>
33 protected bool swigCMemOwn;
36 /// A Flat to check if it is already disposed.
38 /// <since_tizen> 3 </since_tizen>
39 protected bool disposed = false;
41 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
43 //A Flag to check who called Dispose(). (By User or DisposeQueue)
44 private bool isDisposeQueued = false;
47 /// The default constructor.
49 /// <since_tizen> 3 </since_tizen>
50 public Key() : this(Interop.Key.new_Key__SWIG_0(), true)
52 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
58 /// <param name="keyName">The name of the key pressed or command from the IMF, if later, then the following parameters will be needed.</param>
59 /// <param name="keyString">A string of input characters or key pressed.</param>
60 /// <param name="keyCode">The unique key code for the key pressed.</param>
61 /// <param name="keyModifier">The key modifier for special keys like Shift and Alt.</param>
62 /// <param name="timeStamp">The time (in ms) that the key event occurred.</param>
63 /// <param name="keyState">The state of the key event.</param>
64 internal Key(string keyName, string keyString, int keyCode, int keyModifier, uint timeStamp, Key.StateType keyState) : this(Interop.Key.new_Key__SWIG_1(keyName, keyString, keyCode, keyModifier, timeStamp, (int)keyState), true)
66 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
69 internal Key(global::System.IntPtr cPtr, bool cMemoryOwn)
71 swigCMemOwn = cMemoryOwn;
72 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
78 /// <since_tizen> 3 </since_tizen>
83 isDisposeQueued = true;
84 DisposeQueue.Instance.Add(this);
89 /// Enumeration for specifying the state of the key event.
91 /// <since_tizen> 3 </since_tizen>
97 /// <since_tizen> 3 </since_tizen>
102 /// <since_tizen> 3 </since_tizen>
107 /// <since_tizen> 3 </since_tizen>
114 /// <since_tizen> 3 </since_tizen>
115 public string DeviceName
119 string ret = Interop.NDalic.GetDeviceName(swigCPtr);
120 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
126 /// Name given to the key pressed.
128 /// <since_tizen> 3 </since_tizen>
129 public string KeyPressedName
133 return keyPressedName;
137 keyPressedName = value;
142 /// Get the logical key string. (eg. shift + 1 == "exclamation")
144 /// <returns>The logical key symbol</returns>
145 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
146 [EditorBrowsable(EditorBrowsableState.Never)]
147 public string LogicalKey
156 /// Get the actual string returned that should be used for input editors.
158 /// <returns>The key string</returns>
159 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
160 [EditorBrowsable(EditorBrowsableState.Never)]
161 public string KeyPressed
170 /// Get the actual string returned that should be used for input editors.
172 /// <returns>The key string</returns>
173 /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
174 [EditorBrowsable(EditorBrowsableState.Never)]
175 public string KeyString
188 /// Keycode for the key pressed.
190 /// <since_tizen> 3 </since_tizen>
204 /// Special keys like Shift, Alt, and Ctrl which modify the next key pressed.
206 /// <since_tizen> 3 </since_tizen>
207 public int KeyModifier
220 /// The time (in ms) that the key event occurred.
222 /// <since_tizen> 3 </since_tizen>
236 /// State of the key event.
238 /// <since_tizen> 3 </since_tizen>
239 public Key.StateType State
252 /// Get the device class the key event originated from.
254 /// <since_tizen> 3 </since_tizen>
255 public DeviceClassType DeviceClass
259 int ret = Interop.NDalic.GetDeviceClass(swigCPtr);
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
261 return (DeviceClassType)ret;
266 /// Get the device subclass the key event originated from.
268 /// <since_tizen> 4 </since_tizen>
269 public DeviceSubClassType DeviceSubClass
273 int ret = Interop.NDalic.GetDeviceSubClass(swigCPtr);
274 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 return (DeviceSubClassType)ret;
279 private string keyPressedName
283 Interop.Key.Key_keyPressedName_set(swigCPtr, value);
284 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288 string ret = Interop.Key.Key_keyPressedName_get(swigCPtr);
289 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294 private string keyPressed
298 Interop.Key.Key_keyPressed_set(swigCPtr, value);
299 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
303 string ret = Interop.Key.Key_keyPressed_get(swigCPtr);
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309 private string keyString
313 Interop.Key.Key_keyString_set(swigCPtr, value);
314 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318 string ret = Interop.Key.Key_keyString_get(swigCPtr);
319 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328 Interop.Key.Key_keyCode_set(swigCPtr, value);
329 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333 int ret = Interop.Key.Key_keyCode_get(swigCPtr);
334 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339 private int keyModifier
343 Interop.Key.Key_keyModifier_set(swigCPtr, value);
344 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348 int ret = Interop.Key.Key_keyModifier_get(swigCPtr);
349 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
358 Interop.Key.Key_time_set(swigCPtr, value);
359 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
363 uint ret = Interop.Key.Key_time_get(swigCPtr);
364 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
369 private Key.StateType state
373 Interop.Key.Key_state_set(swigCPtr, (int)value);
374 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 Key.StateType ret = (Key.StateType)Interop.Key.Key_state_get(swigCPtr);
379 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384 private string logicalKey
388 string ret = Interop.Key.Key_logicalKey_get(swigCPtr);
389 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
397 /// <since_tizen> 3 </since_tizen>
398 public void Dispose()
400 //Throw excpetion if Dispose() is called in separate thread.
401 if (!Window.IsInstalled())
403 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
408 Dispose(DisposeTypes.Implicit);
412 Dispose(DisposeTypes.Explicit);
413 System.GC.SuppressFinalize(this);
418 /// Checks to see if the Shift key modifier has been supplied.
420 /// <returns>True if Shift modifier.</returns>
421 /// <since_tizen> 3 </since_tizen>
422 public bool IsShiftModifier()
424 bool ret = Interop.Key.Key_IsShiftModifier(swigCPtr);
425 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
430 /// Checks to see if Ctrl (control) key modifier has been supplied.
432 /// <returns>True if Ctrl modifier.</returns>
433 /// <since_tizen> 3 </since_tizen>
434 public bool IsCtrlModifier()
436 bool ret = Interop.Key.Key_IsCtrlModifier(swigCPtr);
437 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
442 /// Checks to see if Alt key modifier has been supplied.
444 /// <returns>True if Alt modifier.</returns>
445 /// <since_tizen> 3 </since_tizen>
446 public bool IsAltModifier()
448 bool ret = Interop.Key.Key_IsAltModifier(swigCPtr);
449 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
453 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Key obj)
455 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
458 internal static Key GetKeyFromPtr(global::System.IntPtr cPtr)
460 Key ret = new Key(cPtr, false);
461 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
468 /// <param name="type">The dispose type.</param>
469 /// <since_tizen> 3 </since_tizen>
470 protected virtual void Dispose(DisposeTypes type)
477 if(type == DisposeTypes.Explicit)
480 //Release your own managed resources here.
481 //You should release all of your own disposable objects here.
484 //Release your own unmanaged resources here.
485 //You should not access any managed member here except static instance.
486 //because the execution order of Finalizes is non-deterministic.
488 if (swigCPtr.Handle != global::System.IntPtr.Zero)
493 Interop.Key.delete_Key(swigCPtr);
495 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);