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 /// 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;
251 /// The default constructor.
253 /// <since_tizen> 3 </since_tizen>
254 public Key() : this(NDalicPINVOKE.new_Key__SWIG_0(), true)
256 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262 /// <param name="keyName">The name of the key pressed or command from the IMF, if later, then the following parameters will be needed.</param>
263 /// <param name="keyString">A string of input characters or key pressed.</param>
264 /// <param name="keyCode">The unique key code for the key pressed.</param>
265 /// <param name="keyModifier">The key modifier for special keys like Shift and Alt.</param>
266 /// <param name="timeStamp">The time (in ms) that the key event occurred.</param>
267 /// <param name="keyState">The state of the key event.</param>
268 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)
270 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274 /// Checks to see if the Shift key modifier has been supplied.
276 /// <returns>True if Shift modifier.</returns>
277 /// <since_tizen> 3 </since_tizen>
278 public bool IsShiftModifier()
280 bool ret = NDalicPINVOKE.Key_IsShiftModifier(swigCPtr);
281 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286 /// Checks to see if Ctrl (control) key modifier has been supplied.
288 /// <returns>True if Ctrl modifier.</returns>
289 /// <since_tizen> 3 </since_tizen>
290 public bool IsCtrlModifier()
292 bool ret = NDalicPINVOKE.Key_IsCtrlModifier(swigCPtr);
293 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298 /// Checks to see if Alt key modifier has been supplied.
300 /// <returns>True if Alt modifier.</returns>
301 /// <since_tizen> 3 </since_tizen>
302 public bool IsAltModifier()
304 bool ret = NDalicPINVOKE.Key_IsAltModifier(swigCPtr);
305 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
309 private string keyPressedName
313 NDalicPINVOKE.Key_keyPressedName_set(swigCPtr, value);
314 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318 string ret = NDalicPINVOKE.Key_keyPressedName_get(swigCPtr);
319 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324 private string keyPressed
328 NDalicPINVOKE.Key_keyPressed_set(swigCPtr, value);
329 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333 string ret = NDalicPINVOKE.Key_keyPressed_get(swigCPtr);
334 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343 NDalicPINVOKE.Key_keyCode_set(swigCPtr, value);
344 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348 int ret = NDalicPINVOKE.Key_keyCode_get(swigCPtr);
349 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
354 private int keyModifier
358 NDalicPINVOKE.Key_keyModifier_set(swigCPtr, value);
359 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
363 int ret = NDalicPINVOKE.Key_keyModifier_get(swigCPtr);
364 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373 NDalicPINVOKE.Key_time_set(swigCPtr, value);
374 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
378 uint ret = NDalicPINVOKE.Key_time_get(swigCPtr);
379 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384 private Key.StateType state
388 NDalicPINVOKE.Key_state_set(swigCPtr, (int)value);
389 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
393 Key.StateType ret = (Key.StateType)NDalicPINVOKE.Key_state_get(swigCPtr);
394 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
400 /// Enumeration for specifying the state of the key event.
402 /// <since_tizen> 3 </since_tizen>
403 public enum StateType
408 /// <since_tizen> 3 </since_tizen>
413 /// <since_tizen> 3 </since_tizen>
418 /// <since_tizen> 3 </since_tizen>