[NUI] Do not registry last event items who get retrieved
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Input / Key.cs
1 /*
2  * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17
18 using System;
19 using System.ComponentModel;
20
21 namespace Tizen.NUI
22 {
23     /// <summary>
24     /// The key structure is used to store a key press.
25     /// </summary>
26     /// <since_tizen> 3 </since_tizen>
27     public class Key : BaseHandle
28     {
29         /// <summary>
30         /// The default constructor.
31         /// </summary>
32         /// <since_tizen> 3 </since_tizen>
33         public Key() : this(Interop.Key.New("", "", 0, 0, 0u, 0), true)
34         {
35             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
36         }
37
38         /// <summary>
39         /// The constructor.
40         /// </summary>
41         /// <param name="keyName">The name of the key pressed or command from the IMF, if later, then the following parameters will be needed.</param>
42         /// <param name="keyString">A string of input characters or key pressed.</param>
43         /// <param name="keyCode">The unique key code for the key pressed.</param>
44         /// <param name="keyModifier">The key modifier for special keys like Shift and Alt.</param>
45         /// <param name="timeStamp">The time (in ms) that the key event occurred.</param>
46         /// <param name="keyState">The state of the key event.</param>
47         internal Key(string keyName, string keyString, int keyCode, int keyModifier, uint timeStamp, Key.StateType keyState) : this(Interop.Key.New(keyName, keyString, keyCode, keyModifier, timeStamp, (int)keyState), true)
48         {
49             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
50         }
51
52         internal Key(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
53         {
54         }
55
56         /// <summary>
57         /// Enumeration for specifying the state of the key event.
58         /// </summary>
59         /// <since_tizen> 3 </since_tizen>
60         public enum StateType
61         {
62             /// <summary>
63             /// Key Down.
64             /// </summary>
65             /// <since_tizen> 3 </since_tizen>
66             Down,
67             /// <summary>
68             /// Key Up.
69             /// </summary>
70             /// <since_tizen> 3 </since_tizen>
71             Up,
72             /// <summary>
73             /// Key Last.
74             /// </summary>
75             /// <since_tizen> 3 </since_tizen>
76             Last
77         }
78
79         /// <summary>
80         /// Device name
81         /// </summary>
82         /// <since_tizen> 3 </since_tizen>
83         public string DeviceName
84         {
85             get
86             {
87                 string ret = Interop.NDalic.GetDeviceName(SwigCPtr);
88                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
89                 return ret;
90             }
91         }
92
93         /// <summary>
94         /// Name given to the key pressed.
95         /// </summary>
96         /// <since_tizen> 3 </since_tizen>
97         public string KeyPressedName
98         {
99             get
100             {
101                 string ret = Interop.Key.KeyPressedNameGet(SwigCPtr);
102                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
103                 return ret;
104             }
105             set
106             {
107                 Interop.Key.KeyPressedNameSet(SwigCPtr, value);
108                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
109             }
110
111         }
112
113         /// <summary>
114         /// Get the logical key string. (eg. shift + 1 == "exclamation")
115         /// </summary>
116         /// <returns>The logical key symbol</returns>
117         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
118         [EditorBrowsable(EditorBrowsableState.Never)]
119         public string LogicalKey
120         {
121             get
122             {
123                 string ret = Interop.Key.LogicalKeyGet(SwigCPtr);
124                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
125                 return ret;
126             }
127         }
128
129         /// <summary>
130         /// Get the actual string returned that should be used for input editors.
131         /// </summary>
132         /// <returns>The key string</returns>
133         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
134         [EditorBrowsable(EditorBrowsableState.Never)]
135         public string KeyPressed
136         {
137             get
138             {
139                 return keyPressed;
140             }
141         }
142
143         /// <summary>
144         /// Get the actual string returned that should be used for input editors.
145         /// </summary>
146         /// <returns>The key string</returns>
147         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
148         [EditorBrowsable(EditorBrowsableState.Never)]
149         public string KeyString
150         {
151             get
152             {
153                 string ret = Interop.Key.KeyStringGet(SwigCPtr);
154                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
155                 return ret;
156             }
157             set
158             {
159                 Interop.Key.KeyStringSet(SwigCPtr, value);
160                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161             }
162         }
163
164         /// <summary>
165         /// Keycode for the key pressed.
166         /// </summary>
167         /// <since_tizen> 3 </since_tizen>
168         public int KeyCode
169         {
170             get
171             {
172                 int ret = Interop.Key.KeyCodeGet(SwigCPtr);
173                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
174                 return ret;
175             }
176             set
177             {
178                 Interop.Key.KeyCodeSet(SwigCPtr, value);
179                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180             }
181         }
182
183         /// <summary>
184         /// Special keys like Shift, Alt, and Ctrl which modify the next key pressed.
185         /// </summary>
186         /// <since_tizen> 3 </since_tizen>
187         public int KeyModifier
188         {
189             get
190             {
191                 int ret = Interop.Key.KeyModifierGet(SwigCPtr);
192                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
193                 return ret;
194             }
195             set
196             {
197                 Interop.Key.KeyModifierSet(SwigCPtr, value);
198                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199             }
200         }
201
202         /// <summary>
203         /// The time (in ms) that the key event occurred.
204         /// </summary>
205         /// <since_tizen> 3 </since_tizen>
206         public uint Time
207         {
208             get
209             {
210                 uint ret = Interop.Key.TimeGet(SwigCPtr);
211                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
212                 return ret;
213             }
214             set
215             {
216                 Interop.Key.TimeSet(SwigCPtr, value);
217                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
218             }
219         }
220
221         /// <summary>
222         /// State of the key event.
223         /// </summary>
224         /// <since_tizen> 3 </since_tizen>
225         public Key.StateType State
226         {
227             get
228             {
229                 Key.StateType ret = (Key.StateType)Interop.Key.StateGet(SwigCPtr);
230                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
231                 return ret;
232             }
233             set
234             {
235                 Interop.Key.StateSet(SwigCPtr, (int)value);
236                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237             }
238         }
239
240         /// <summary>
241         /// Get the device class the key event originated from.
242         /// </summary>
243         /// <since_tizen> 3 </since_tizen>
244         public DeviceClassType DeviceClass
245         {
246             get
247             {
248                 int ret = Interop.NDalic.GetDeviceClass(SwigCPtr);
249                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
250                 return (DeviceClassType)ret;
251             }
252         }
253
254         /// <summary>
255         /// Get the device subclass the key event originated from.
256         /// </summary>
257         /// <since_tizen> 4 </since_tizen>
258         public DeviceSubClassType DeviceSubClass
259         {
260             get
261             {
262                 int ret = Interop.NDalic.GetDeviceSubClass(SwigCPtr);
263                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
264                 return (DeviceSubClassType)ret;
265             }
266         }
267
268         private string keyPressed
269         {
270             set
271             {
272                 Interop.Key.KeyPressedSet(SwigCPtr, value);
273                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
274             }
275             get
276             {
277                 string ret = Interop.Key.KeyPressedGet(SwigCPtr);
278                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
279                 return ret;
280             }
281         }
282
283         /// <summary>
284         /// Checks to see if the Shift key modifier has been supplied.
285         /// </summary>
286         /// <returns>True if Shift modifier.</returns>
287         /// <since_tizen> 3 </since_tizen>
288         public bool IsShiftModifier()
289         {
290             bool ret = Interop.Key.IsShiftModifier(SwigCPtr);
291             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292             return ret;
293         }
294
295         /// <summary>
296         /// Checks to see if Ctrl (control) key modifier has been supplied.
297         /// </summary>
298         /// <returns>True if Ctrl modifier.</returns>
299         /// <since_tizen> 3 </since_tizen>
300         public bool IsCtrlModifier()
301         {
302             bool ret = Interop.Key.IsCtrlModifier(SwigCPtr);
303             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304             return ret;
305         }
306
307         /// <summary>
308         /// Checks to see if Alt key modifier has been supplied.
309         /// </summary>
310         /// <returns>True if Alt modifier.</returns>
311         /// <since_tizen> 3 </since_tizen>
312         public bool IsAltModifier()
313         {
314             bool ret = Interop.Key.IsAltModifier(SwigCPtr);
315             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316             return ret;
317         }
318
319         internal static Key GetKeyFromPtr(global::System.IntPtr cPtr)
320         {
321             Key ret = new Key(cPtr, false);
322             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323             return ret;
324         }
325
326         /// This will not be public opened.
327         [EditorBrowsable(EditorBrowsableState.Never)]
328         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
329         {
330             Interop.Key.DeleteKey(swigCPtr);
331         }
332     }
333 }