Release 4.0.0-preview1-00235
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Wheel.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 namespace Tizen.NUI
18 {
19
20     /// <summary>
21     /// The wheel event structure is used to store a wheel rolling, it facilitates processing of the wheel rolling and passing to other libraries like Toolkit.<br>
22     /// There is a key modifier which relates to keys like Alt, Shift, and Ctrl functions are supplied to check if they have been pressed when the wheel is being rolled.<br>
23     /// We support a mouse device and there may be another custom device that support the wheel event. The device type is specified as \e type.<br>
24     /// The mouse wheel event can be sent to the specific actor but the custom wheel event will be sent to the window.<br>
25     /// </summary>
26     public class Wheel : global::System.IDisposable
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29         protected bool swigCMemOwn;
30
31         internal Wheel(global::System.IntPtr cPtr, bool cMemoryOwn)
32         {
33             swigCMemOwn = cMemoryOwn;
34             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35         }
36
37         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Wheel obj)
38         {
39             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
40         }
41
42         //A Flag to check who called Dispose(). (By User or DisposeQueue)
43         private bool isDisposeQueued = false;
44         //A Flat to check if it is already disposed.
45         protected bool disposed = false;
46
47         ~Wheel()
48         {
49             if(!isDisposeQueued)
50             {
51                 isDisposeQueued = true;
52                 DisposeQueue.Instance.Add(this);
53             }
54         }
55
56         public void Dispose()
57         {
58             //Throw excpetion if Dispose() is called in separate thread.
59             if (!Window.IsInstalled())
60             {
61                 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
62             }
63
64             if (isDisposeQueued)
65             {
66                 Dispose(DisposeTypes.Implicit);
67             }
68             else
69             {
70                 Dispose(DisposeTypes.Explicit);
71                 System.GC.SuppressFinalize(this);
72             }
73         }
74
75         protected virtual void Dispose(DisposeTypes type)
76         {
77             if (disposed)
78             {
79                 return;
80             }
81
82             if(type == DisposeTypes.Explicit)
83             {
84                 //Called by User
85                 //Release your own managed resources here.
86                 //You should release all of your own disposable objects here.
87             }
88
89             //Release your own unmanaged resources here.
90             //You should not access any managed member here except static instance.
91             //because the execution order of Finalizes is non-deterministic.
92
93             if (swigCPtr.Handle != global::System.IntPtr.Zero)
94             {
95                 if (swigCMemOwn)
96                 {
97                     swigCMemOwn = false;
98                     NDalicPINVOKE.delete_Wheel(swigCPtr);
99                 }
100                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
101             }
102             disposed = true;
103         }
104
105
106         internal static Wheel GetWheelFromPtr(global::System.IntPtr cPtr)
107         {
108             Wheel ret = new Wheel(cPtr, false);
109             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110             return ret;
111         }
112
113         /// <summary>
114         /// The type of the wheel event.
115         /// </summary>
116         public Wheel.WheelType Type
117         {
118             get
119             {
120                 return type;
121             }
122         }
123
124         /// <summary>
125         /// The direction of wheel rolling (0 = default vertical wheel, 1 = horizontal wheel).
126         /// </summary>
127         public int Direction
128         {
129             get
130             {
131                 return direction;
132             }
133         }
134
135         /// <summary>
136         /// Modifier keys pressed during the event (such as Shift, Alt, and Ctrl).
137         /// </summary>
138         public uint Modifiers
139         {
140             get
141             {
142                 return modifiers;
143             }
144         }
145
146         /// <summary>
147         /// The coordinates of the cursor relative to the top-left of the screen.
148         /// </summary>
149         public Vector2 Point
150         {
151             get
152             {
153                 return point;
154             }
155         }
156
157         /// <summary>
158         /// The offset of rolling (positive value means roll down or clockwise, and negative value means roll up or counter-clockwise).
159         /// </summary>
160         public int Z
161         {
162             get
163             {
164                 return z;
165             }
166         }
167
168         /// <summary>
169         /// The time the wheel is being rolled.
170         /// </summary>
171         public uint TimeStamp
172         {
173             get
174             {
175                 return timeStamp;
176             }
177         }
178
179         /// <summary>
180         /// The default constructor.
181         /// </summary>
182         public Wheel() : this(NDalicPINVOKE.new_Wheel__SWIG_0(), true)
183         {
184             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185         }
186
187         /// <summary>
188         /// The constructor.
189         /// </summary>
190         /// <param name="type">The type of the wheel event.</param>
191         /// <param name="direction">The direction of wheel rolling (0 = default vertical wheel, 1 = horizontal wheel).</param>
192         /// <param name="modifiers">Modifier keys pressed during the event (such as Shift, Alt, and Ctrl).</param>
193         /// <param name="point">The coordinates of the cursor relative to the top-left of the screen.</param>
194         /// <param name="z">The offset of rolling (positive value means roll down or clockwise, and negative value means roll up or counter-clockwise).</param>
195         /// <param name="timeStamp">The time the wheel is being rolled.</param>
196         public Wheel(Wheel.WheelType type, int direction, uint modifiers, Vector2 point, int z, uint timeStamp) : this(NDalicPINVOKE.new_Wheel__SWIG_1((int)type, direction, modifiers, Vector2.getCPtr(point), z, timeStamp), true)
197         {
198             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199         }
200
201         /// <summary>
202         /// Checks to see if the Shift key modifier has been supplied.
203         /// </summary>
204         /// <returns>True if Shift modifier.</returns>
205         public bool IsShiftModifier()
206         {
207             bool ret = NDalicPINVOKE.Wheel_IsShiftModifier(swigCPtr);
208             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209             return ret;
210         }
211
212         /// <summary>
213         /// Checks to see if Ctrl (control) key modifier has been supplied.
214         /// </summary>
215         /// <returns>True if Ctrl modifier.</returns>
216         public bool IsCtrlModifier()
217         {
218             bool ret = NDalicPINVOKE.Wheel_IsCtrlModifier(swigCPtr);
219             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220             return ret;
221         }
222
223         /// <summary>
224         /// Checks to see if Alt key modifier has been supplied.
225         /// </summary>
226         /// <returns>True if Alt modifier.</returns>
227         public bool IsAltModifier()
228         {
229             bool ret = NDalicPINVOKE.Wheel_IsAltModifier(swigCPtr);
230             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
231             return ret;
232         }
233
234         private Wheel.WheelType type
235         {
236             set
237             {
238                 NDalicPINVOKE.Wheel_type_set(swigCPtr, (int)value);
239                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
240             }
241             get
242             {
243                 Wheel.WheelType ret = (Wheel.WheelType)NDalicPINVOKE.Wheel_type_get(swigCPtr);
244                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245                 return ret;
246             }
247         }
248
249         private int direction
250         {
251             set
252             {
253                 NDalicPINVOKE.Wheel_direction_set(swigCPtr, value);
254                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255             }
256             get
257             {
258                 int ret = NDalicPINVOKE.Wheel_direction_get(swigCPtr);
259                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260                 return ret;
261             }
262         }
263
264         private uint modifiers
265         {
266             set
267             {
268                 NDalicPINVOKE.Wheel_modifiers_set(swigCPtr, value);
269                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
270             }
271             get
272             {
273                 uint ret = NDalicPINVOKE.Wheel_modifiers_get(swigCPtr);
274                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275                 return ret;
276             }
277         }
278
279         private Vector2 point
280         {
281             set
282             {
283                 NDalicPINVOKE.Wheel_point_set(swigCPtr, Vector2.getCPtr(value));
284                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285             }
286             get
287             {
288                 global::System.IntPtr cPtr = NDalicPINVOKE.Wheel_point_get(swigCPtr);
289                 Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
290                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291                 return ret;
292             }
293         }
294
295         private int z
296         {
297             set
298             {
299                 NDalicPINVOKE.Wheel_z_set(swigCPtr, value);
300                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301             }
302             get
303             {
304                 int ret = NDalicPINVOKE.Wheel_z_get(swigCPtr);
305                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
306                 return ret;
307             }
308         }
309
310         private uint timeStamp
311         {
312             set
313             {
314                 NDalicPINVOKE.Wheel_timeStamp_set(swigCPtr, value);
315                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316             }
317             get
318             {
319                 uint ret = NDalicPINVOKE.Wheel_timeStamp_get(swigCPtr);
320                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
321                 return ret;
322             }
323         }
324
325         /// <summary>
326         /// The type of the wheel event.
327         /// </summary>
328         public enum WheelType
329         {
330             MouseWheel,
331             CustomWheel
332         }
333
334     }
335
336 }