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(NDalicPINVOKE.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(NDalicPINVOKE.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 = NDalicPINVOKE.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 /// Keycode for the key pressed.
172 /// <since_tizen> 3 </since_tizen>
186 /// Special keys like Shift, Alt, and Ctrl which modify the next key pressed.
188 /// <since_tizen> 3 </since_tizen>
189 public int KeyModifier
202 /// The time (in ms) that the key event occurred.
204 /// <since_tizen> 3 </since_tizen>
218 /// State of the key event.
220 /// <since_tizen> 3 </since_tizen>
221 public Key.StateType State
234 /// Get the device class the key event originated from.
236 /// <since_tizen> 3 </since_tizen>
237 public DeviceClassType DeviceClass
241 int ret = NDalicPINVOKE.GetDeviceClass(swigCPtr);
242 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243 return (DeviceClassType)ret;
248 /// Get the device subclass the key event originated from.
250 /// <since_tizen> 4 </since_tizen>
251 public DeviceSubClassType DeviceSubClass
255 int ret = NDalicPINVOKE.GetDeviceSubClass(swigCPtr);
256 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257 return (DeviceSubClassType)ret;
261 private string keyPressedName
265 NDalicPINVOKE.Key_keyPressedName_set(swigCPtr, value);
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270 string ret = NDalicPINVOKE.Key_keyPressedName_get(swigCPtr);
271 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276 private string keyPressed
280 NDalicPINVOKE.Key_keyPressed_set(swigCPtr, value);
281 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285 string ret = NDalicPINVOKE.Key_keyPressed_get(swigCPtr);
286 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295 NDalicPINVOKE.Key_keyCode_set(swigCPtr, value);
296 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300 int ret = NDalicPINVOKE.Key_keyCode_get(swigCPtr);
301 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
306 private int keyModifier
310 NDalicPINVOKE.Key_keyModifier_set(swigCPtr, value);
311 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315 int ret = NDalicPINVOKE.Key_keyModifier_get(swigCPtr);
316 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325 NDalicPINVOKE.Key_time_set(swigCPtr, value);
326 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330 uint ret = NDalicPINVOKE.Key_time_get(swigCPtr);
331 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336 private Key.StateType state
340 NDalicPINVOKE.Key_state_set(swigCPtr, (int)value);
341 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345 Key.StateType ret = (Key.StateType)NDalicPINVOKE.Key_state_get(swigCPtr);
346 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
351 private string logicalKey
355 string ret = NDalicPINVOKE.Key_logicalKey_get(swigCPtr);
356 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364 /// <since_tizen> 3 </since_tizen>
365 public void Dispose()
367 //Throw excpetion if Dispose() is called in separate thread.
368 if (!Window.IsInstalled())
370 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
375 Dispose(DisposeTypes.Implicit);
379 Dispose(DisposeTypes.Explicit);
380 System.GC.SuppressFinalize(this);
385 /// Checks to see if the Shift key modifier has been supplied.
387 /// <returns>True if Shift modifier.</returns>
388 /// <since_tizen> 3 </since_tizen>
389 public bool IsShiftModifier()
391 bool ret = NDalicPINVOKE.Key_IsShiftModifier(swigCPtr);
392 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
397 /// Checks to see if Ctrl (control) key modifier has been supplied.
399 /// <returns>True if Ctrl modifier.</returns>
400 /// <since_tizen> 3 </since_tizen>
401 public bool IsCtrlModifier()
403 bool ret = NDalicPINVOKE.Key_IsCtrlModifier(swigCPtr);
404 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
409 /// Checks to see if Alt key modifier has been supplied.
411 /// <returns>True if Alt modifier.</returns>
412 /// <since_tizen> 3 </since_tizen>
413 public bool IsAltModifier()
415 bool ret = NDalicPINVOKE.Key_IsAltModifier(swigCPtr);
416 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
420 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Key obj)
422 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
425 internal static Key GetKeyFromPtr(global::System.IntPtr cPtr)
427 Key ret = new Key(cPtr, false);
428 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
435 /// <param name="type">The dispose type.</param>
436 /// <since_tizen> 3 </since_tizen>
437 protected virtual void Dispose(DisposeTypes type)
444 if(type == DisposeTypes.Explicit)
447 //Release your own managed resources here.
448 //You should release all of your own disposable objects here.
451 //Release your own unmanaged resources here.
452 //You should not access any managed member here except static instance.
453 //because the execution order of Finalizes is non-deterministic.
455 if (swigCPtr.Handle != global::System.IntPtr.Zero)
460 NDalicPINVOKE.delete_Key(swigCPtr);
462 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);