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 public class Key : global::System.IDisposable
26 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30 /// <since_tizen> 3 </since_tizen>
31 protected bool swigCMemOwn;
33 internal Key(global::System.IntPtr cPtr, bool cMemoryOwn)
35 swigCMemOwn = cMemoryOwn;
36 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
39 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Key obj)
41 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
44 //A Flag to check who called Dispose(). (By User or DisposeQueue)
45 private bool isDisposeQueued = false;
47 /// A Flat to check if it is already disposed.
49 /// <since_tizen> 3 </since_tizen>
50 protected bool disposed = false;
55 /// <since_tizen> 3 </since_tizen>
60 isDisposeQueued = true;
61 DisposeQueue.Instance.Add(this);
68 /// <since_tizen> 3 </since_tizen>
71 //Throw excpetion if Dispose() is called in separate thread.
72 if (!Window.IsInstalled())
74 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
79 Dispose(DisposeTypes.Implicit);
83 Dispose(DisposeTypes.Explicit);
84 System.GC.SuppressFinalize(this);
91 /// <param name="type">The dispose type.</param>
92 /// <since_tizen> 3 </since_tizen>
93 protected virtual void Dispose(DisposeTypes type)
100 if(type == DisposeTypes.Explicit)
103 //Release your own managed resources here.
104 //You should release all of your own disposable objects here.
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.
111 if (swigCPtr.Handle != global::System.IntPtr.Zero)
116 NDalicPINVOKE.delete_Key(swigCPtr);
118 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
124 internal static Key GetKeyFromPtr(global::System.IntPtr cPtr)
126 Key ret = new Key(cPtr, false);
127 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134 /// <since_tizen> 3 </since_tizen>
135 public string DeviceName
139 string ret = NDalicPINVOKE.GetDeviceName(swigCPtr);
140 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
146 /// Name given to the key pressed.
148 /// <since_tizen> 3 </since_tizen>
149 public string KeyPressedName
153 return keyPressedName;
157 keyPressedName = value;
161 /* duplicated with KeyPressedName : removed
162 public string KeyPressed
172 /// Keycode for the key pressed.
174 /// <since_tizen> 3 </since_tizen>
188 /// Special keys like Shift, Alt, and Ctrl which modify the next key pressed.
190 /// <since_tizen> 3 </since_tizen>
191 public int KeyModifier
204 /// The time (in ms) that the key event occurred.
206 /// <since_tizen> 3 </since_tizen>
220 /// State of the key event.
222 /// <since_tizen> 3 </since_tizen>
223 public Key.StateType State
236 /// Get the device class the key event originated from.
238 /// <since_tizen> 3 </since_tizen>
239 public DeviceClassType DeviceClass
243 int ret = NDalicPINVOKE.GetDeviceClass(swigCPtr);
244 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245 return (DeviceClassType)ret;
250 /// Get the device subclass the key event originated from.
252 /// <since_tizen> 4 </since_tizen>
253 public DeviceSubClassType DeviceSubClass
257 int ret = NDalicPINVOKE.GetDeviceSubClass(swigCPtr);
258 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 return (DeviceSubClassType)ret;
264 /// The default constructor.
266 /// <since_tizen> 3 </since_tizen>
267 public Key() : this(NDalicPINVOKE.new_Key__SWIG_0(), true)
269 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 /// <param name="keyName">The name of the key pressed or command from the IMF, if later, then the following parameters will be needed.</param>
276 /// <param name="keyString">A string of input characters or key pressed.</param>
277 /// <param name="keyCode">The unique key code for the key pressed.</param>
278 /// <param name="keyModifier">The key modifier for special keys like Shift and Alt.</param>
279 /// <param name="timeStamp">The time (in ms) that the key event occurred.</param>
280 /// <param name="keyState">The state of the key event.</param>
281 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)
283 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
287 /// Checks to see if the Shift key modifier has been supplied.
289 /// <returns>True if Shift modifier.</returns>
290 /// <since_tizen> 3 </since_tizen>
291 public bool IsShiftModifier()
293 bool ret = NDalicPINVOKE.Key_IsShiftModifier(swigCPtr);
294 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299 /// Checks to see if Ctrl (control) key modifier has been supplied.
301 /// <returns>True if Ctrl modifier.</returns>
302 /// <since_tizen> 3 </since_tizen>
303 public bool IsCtrlModifier()
305 bool ret = NDalicPINVOKE.Key_IsCtrlModifier(swigCPtr);
306 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311 /// Checks to see if Alt key modifier has been supplied.
313 /// <returns>True if Alt modifier.</returns>
314 /// <since_tizen> 3 </since_tizen>
315 public bool IsAltModifier()
317 bool ret = NDalicPINVOKE.Key_IsAltModifier(swigCPtr);
318 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322 private string keyPressedName
326 NDalicPINVOKE.Key_keyPressedName_set(swigCPtr, value);
327 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
331 string ret = NDalicPINVOKE.Key_keyPressedName_get(swigCPtr);
332 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
337 private string keyPressed
341 NDalicPINVOKE.Key_keyPressed_set(swigCPtr, value);
342 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346 string ret = NDalicPINVOKE.Key_keyPressed_get(swigCPtr);
347 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
356 NDalicPINVOKE.Key_keyCode_set(swigCPtr, value);
357 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
361 int ret = NDalicPINVOKE.Key_keyCode_get(swigCPtr);
362 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
367 private int keyModifier
371 NDalicPINVOKE.Key_keyModifier_set(swigCPtr, value);
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 int ret = NDalicPINVOKE.Key_keyModifier_get(swigCPtr);
377 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
386 NDalicPINVOKE.Key_time_set(swigCPtr, value);
387 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
391 uint ret = NDalicPINVOKE.Key_time_get(swigCPtr);
392 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
397 private Key.StateType state
401 NDalicPINVOKE.Key_state_set(swigCPtr, (int)value);
402 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
406 Key.StateType ret = (Key.StateType)NDalicPINVOKE.Key_state_get(swigCPtr);
407 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
413 /// Enumeration for specifying the state of the key event.
415 /// <since_tizen> 3 </since_tizen>
416 public enum StateType
421 /// <since_tizen> 3 </since_tizen>
426 /// <since_tizen> 3 </since_tizen>
431 /// <since_tizen> 3 </since_tizen>