Add exception handler for rpc-port-parcel (#394)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / PanGestureDetector.cs
1 /*
2  * Copyright(c) 2017 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 namespace Tizen.NUI
19 {
20
21     using System;
22     using System.Runtime.InteropServices;
23     using Tizen.NUI.BaseComponents;
24
25
26     internal class PanGestureDetector : GestureDetector
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29
30         internal PanGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PanGestureDetector_SWIGUpcast(cPtr), cMemoryOwn)
31         {
32             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
33         }
34
35         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PanGestureDetector obj)
36         {
37             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
38         }
39
40         protected override void Dispose(DisposeTypes type)
41         {
42             if (disposed)
43             {
44                 return;
45             }
46
47             if (type == DisposeTypes.Explicit)
48             {
49                 //Called by User
50                 //Release your own managed resources here.
51                 //You should release all of your own disposable objects here.
52
53             }
54
55             //Release your own unmanaged resources here.
56             //You should not access any managed member here except static instance.
57             //because the execution order of Finalizes is non-deterministic.
58
59             if (swigCPtr.Handle != global::System.IntPtr.Zero)
60             {
61                 if (swigCMemOwn)
62                 {
63                     swigCMemOwn = false;
64                     NDalicPINVOKE.delete_PanGestureDetector(swigCPtr);
65                 }
66                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
67             }
68
69             base.Dispose(type);
70         }
71
72
73
74         /// <since_tizen> 3 </since_tizen>
75         public class DetectedEventArgs : EventArgs
76         {
77             private View _view;
78             private PanGesture _panGesture;
79
80             /// <since_tizen> 3 </since_tizen>
81             public View View
82             {
83                 get
84                 {
85                     return _view;
86                 }
87                 set
88                 {
89                     _view = value;
90                 }
91             }
92
93             /// <since_tizen> 3 </since_tizen>
94             public PanGesture PanGesture
95             {
96                 get
97                 {
98                     return _panGesture;
99                 }
100                 set
101                 {
102                     _panGesture = value;
103                 }
104             }
105         }
106
107         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
108         private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr panGesture);
109         private DaliEventHandler<object, DetectedEventArgs> _panGestureEventHandler;
110         private DetectedCallbackDelegate _panGestureCallbackDelegate;
111
112
113         public event DaliEventHandler<object, DetectedEventArgs> Detected
114         {
115             add
116             {
117                 lock (this)
118                 {
119                     // Restricted to only one listener
120                     if (_panGestureEventHandler == null)
121                     {
122                         _panGestureEventHandler += value;
123
124                         _panGestureCallbackDelegate = new DetectedCallbackDelegate(OnPanGestureDetected);
125                         this.DetectedSignal().Connect(_panGestureCallbackDelegate);
126                     }
127                 }
128             }
129
130             remove
131             {
132                 lock (this)
133                 {
134                     if (_panGestureEventHandler != null)
135                     {
136                         this.DetectedSignal().Disconnect(_panGestureCallbackDelegate);
137                     }
138
139                     _panGestureEventHandler -= value;
140                 }
141             }
142         }
143
144         private void OnPanGestureDetected(IntPtr actor, IntPtr panGesture)
145         {
146             DetectedEventArgs e = new DetectedEventArgs();
147
148             // Populate all members of "e" (PanGestureEventArgs) with real data
149             e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
150             e.PanGesture = Tizen.NUI.PanGesture.GetPanGestureFromPtr(panGesture);
151
152             if (_panGestureEventHandler != null)
153             {
154                 //here we send all data to user event handlers
155                 _panGestureEventHandler(this, e);
156             }
157
158         }
159
160
161         public static PanGestureDetector GetPanGestureDetectorFromPtr(global::System.IntPtr cPtr)
162         {
163             PanGestureDetector ret = new PanGestureDetector(cPtr, false);
164             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
165             return ret;
166         }
167
168
169         /// <since_tizen> 3 </since_tizen>
170         public class Property : global::System.IDisposable
171         {
172             private global::System.Runtime.InteropServices.HandleRef swigCPtr;
173             /// <since_tizen> 3 </since_tizen>
174             protected bool swigCMemOwn;
175
176             internal Property(global::System.IntPtr cPtr, bool cMemoryOwn)
177             {
178                 swigCMemOwn = cMemoryOwn;
179                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
180             }
181
182             internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Property obj)
183             {
184                 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
185             }
186
187             //A Flag to check who called Dispose(). (By User or DisposeQueue)
188             private bool isDisposeQueued = false;
189             //A Flat to check if it is already disposed.
190             /// <since_tizen> 3 </since_tizen>
191             protected bool disposed = false;
192
193
194             ~Property()
195             {
196                 if (!isDisposeQueued)
197                 {
198                     isDisposeQueued = true;
199                     DisposeQueue.Instance.Add(this);
200                 }
201             }
202
203             /// <since_tizen> 3 </since_tizen>
204             public void Dispose()
205             {
206                 //Throw excpetion if Dispose() is called in separate thread.
207                 if (!Window.IsInstalled())
208                 {
209                     throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
210                 }
211
212                 if (isDisposeQueued)
213                 {
214                     Dispose(DisposeTypes.Implicit);
215                 }
216                 else
217                 {
218                     Dispose(DisposeTypes.Explicit);
219                     System.GC.SuppressFinalize(this);
220                 }
221             }
222
223             /// <since_tizen> 3 </since_tizen>
224             protected virtual void Dispose(DisposeTypes type)
225             {
226                 if (disposed)
227                 {
228                     return;
229                 }
230
231                 if (type == DisposeTypes.Explicit)
232                 {
233                     //Called by User
234                     //Release your own managed resources here.
235                     //You should release all of your own disposable objects here.
236
237                 }
238
239                 //Release your own unmanaged resources here.
240                 //You should not access any managed member here except static instance.
241                 //because the execution order of Finalizes is non-deterministic.
242
243                 if (swigCPtr.Handle != global::System.IntPtr.Zero)
244                 {
245                     if (swigCMemOwn)
246                     {
247                         swigCMemOwn = false;
248                         NDalicPINVOKE.delete_PanGestureDetector_Property(swigCPtr);
249                     }
250                     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
251                 }
252
253                 disposed = true;
254             }
255
256             /// <since_tizen> 3 </since_tizen>
257             public Property() : this(NDalicPINVOKE.new_PanGestureDetector_Property(), true)
258             {
259                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260             }
261
262             /// <since_tizen> 3 </since_tizen>
263             public static readonly int SCREEN_POSITION = NDalicPINVOKE.PanGestureDetector_Property_SCREEN_POSITION_get();
264             /// <since_tizen> 3 </since_tizen>
265             public static readonly int SCREEN_DISPLACEMENT = NDalicPINVOKE.PanGestureDetector_Property_SCREEN_DISPLACEMENT_get();
266             /// <since_tizen> 3 </since_tizen>
267             public static readonly int SCREEN_VELOCITY = NDalicPINVOKE.PanGestureDetector_Property_SCREEN_VELOCITY_get();
268             /// <since_tizen> 3 </since_tizen>
269             public static readonly int LOCAL_POSITION = NDalicPINVOKE.PanGestureDetector_Property_LOCAL_POSITION_get();
270             /// <since_tizen> 3 </since_tizen>
271             public static readonly int LOCAL_DISPLACEMENT = NDalicPINVOKE.PanGestureDetector_Property_LOCAL_DISPLACEMENT_get();
272             /// <since_tizen> 3 </since_tizen>
273             public static readonly int LOCAL_VELOCITY = NDalicPINVOKE.PanGestureDetector_Property_LOCAL_VELOCITY_get();
274             /// <since_tizen> 3 </since_tizen>
275             public static readonly int PANNING = NDalicPINVOKE.PanGestureDetector_Property_PANNING_get();
276
277         }
278
279         public static Radian DIRECTION_LEFT
280         {
281             get
282             {
283                 global::System.IntPtr cPtr = NDalicPINVOKE.PanGestureDetector_DIRECTION_LEFT_get();
284                 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
285                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286                 return ret;
287             }
288         }
289
290         public static Radian DIRECTION_RIGHT
291         {
292             get
293             {
294                 global::System.IntPtr cPtr = NDalicPINVOKE.PanGestureDetector_DIRECTION_RIGHT_get();
295                 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
296                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297                 return ret;
298             }
299         }
300
301         public static Radian DIRECTION_UP
302         {
303             get
304             {
305                 global::System.IntPtr cPtr = NDalicPINVOKE.PanGestureDetector_DIRECTION_UP_get();
306                 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
307                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308                 return ret;
309             }
310         }
311
312         public static Radian DIRECTION_DOWN
313         {
314             get
315             {
316                 global::System.IntPtr cPtr = NDalicPINVOKE.PanGestureDetector_DIRECTION_DOWN_get();
317                 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
318                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319                 return ret;
320             }
321         }
322
323         public static Radian DIRECTION_HORIZONTAL
324         {
325             get
326             {
327                 global::System.IntPtr cPtr = NDalicPINVOKE.PanGestureDetector_DIRECTION_HORIZONTAL_get();
328                 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
329                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330                 return ret;
331             }
332         }
333
334         public static Radian DIRECTION_VERTICAL
335         {
336             get
337             {
338                 global::System.IntPtr cPtr = NDalicPINVOKE.PanGestureDetector_DIRECTION_VERTICAL_get();
339                 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
340                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341                 return ret;
342             }
343         }
344
345         public static Radian DEFAULT_THRESHOLD
346         {
347             get
348             {
349                 global::System.IntPtr cPtr = NDalicPINVOKE.PanGestureDetector_DEFAULT_THRESHOLD_get();
350                 Radian ret = (cPtr == global::System.IntPtr.Zero) ? null : new Radian(cPtr, false);
351                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352                 return ret;
353             }
354         }
355
356         public PanGestureDetector() : this(NDalicPINVOKE.PanGestureDetector_New(), true)
357         {
358             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359
360         }
361         public new static PanGestureDetector DownCast(BaseHandle handle)
362         {
363             PanGestureDetector ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as PanGestureDetector;
364             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
365             return ret;
366         }
367
368         public PanGestureDetector(PanGestureDetector handle) : this(NDalicPINVOKE.new_PanGestureDetector__SWIG_1(PanGestureDetector.getCPtr(handle)), true)
369         {
370             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
371         }
372
373         public PanGestureDetector Assign(PanGestureDetector rhs)
374         {
375             PanGestureDetector ret = new PanGestureDetector(NDalicPINVOKE.PanGestureDetector_Assign(swigCPtr, PanGestureDetector.getCPtr(rhs)), false);
376             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
377             return ret;
378         }
379
380         public void SetMinimumTouchesRequired(uint minimum)
381         {
382             NDalicPINVOKE.PanGestureDetector_SetMinimumTouchesRequired(swigCPtr, minimum);
383             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
384         }
385
386         public void SetMaximumTouchesRequired(uint maximum)
387         {
388             NDalicPINVOKE.PanGestureDetector_SetMaximumTouchesRequired(swigCPtr, maximum);
389             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
390         }
391
392         public uint GetMinimumTouchesRequired()
393         {
394             uint ret = NDalicPINVOKE.PanGestureDetector_GetMinimumTouchesRequired(swigCPtr);
395             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
396             return ret;
397         }
398
399         public uint GetMaximumTouchesRequired()
400         {
401             uint ret = NDalicPINVOKE.PanGestureDetector_GetMaximumTouchesRequired(swigCPtr);
402             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
403             return ret;
404         }
405
406         public void AddAngle(Radian angle, Radian threshold)
407         {
408             NDalicPINVOKE.PanGestureDetector_AddAngle__SWIG_0(swigCPtr, Radian.getCPtr(angle), Radian.getCPtr(threshold));
409             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
410         }
411
412         public void AddAngle(Radian angle)
413         {
414             NDalicPINVOKE.PanGestureDetector_AddAngle__SWIG_1(swigCPtr, Radian.getCPtr(angle));
415             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
416         }
417
418         public void AddDirection(Radian direction, Radian threshold)
419         {
420             NDalicPINVOKE.PanGestureDetector_AddDirection__SWIG_0(swigCPtr, Radian.getCPtr(direction), Radian.getCPtr(threshold));
421             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
422         }
423
424         public void AddDirection(Radian direction)
425         {
426             NDalicPINVOKE.PanGestureDetector_AddDirection__SWIG_1(swigCPtr, Radian.getCPtr(direction));
427             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
428         }
429
430         public uint GetAngleCount()
431         {
432             uint ret = NDalicPINVOKE.PanGestureDetector_GetAngleCount(swigCPtr);
433             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
434             return ret;
435         }
436
437         internal AngleThresholdPair GetAngle(uint index)
438         {
439             AngleThresholdPair ret = new AngleThresholdPair(NDalicPINVOKE.PanGestureDetector_GetAngle(swigCPtr, index), true);
440             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
441             return ret;
442         }
443
444         public void ClearAngles()
445         {
446             NDalicPINVOKE.PanGestureDetector_ClearAngles(swigCPtr);
447             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
448         }
449
450         public void RemoveAngle(Radian angle)
451         {
452             NDalicPINVOKE.PanGestureDetector_RemoveAngle(swigCPtr, Radian.getCPtr(angle));
453             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
454         }
455
456         public void RemoveDirection(Radian direction)
457         {
458             NDalicPINVOKE.PanGestureDetector_RemoveDirection(swigCPtr, Radian.getCPtr(direction));
459             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
460         }
461
462         internal PanGestureDetectedSignal DetectedSignal()
463         {
464             PanGestureDetectedSignal ret = new PanGestureDetectedSignal(NDalicPINVOKE.PanGestureDetector_DetectedSignal(swigCPtr), false);
465             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
466             return ret;
467         }
468
469         public static void SetPanGestureProperties(PanGesture pan)
470         {
471             NDalicPINVOKE.PanGestureDetector_SetPanGestureProperties(PanGesture.getCPtr(pan));
472             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
473         }
474
475         public Vector2 ScreenPosition
476         {
477             get
478             {
479                 Vector2 temp = new Vector2(0.0f, 0.0f);
480                 Tizen.NUI.Object.GetProperty(swigCPtr, PanGestureDetector.Property.SCREEN_POSITION).Get(temp);
481                 return temp;
482             }
483         }
484         public Vector2 ScreenDisplacement
485         {
486             get
487             {
488                 Vector2 temp = new Vector2(0.0f, 0.0f);
489                 Tizen.NUI.Object.GetProperty(swigCPtr, PanGestureDetector.Property.SCREEN_DISPLACEMENT).Get(temp);
490                 return temp;
491             }
492         }
493         public Vector2 ScreenVelocity
494         {
495             get
496             {
497                 Vector2 temp = new Vector2(0.0f, 0.0f);
498                 Tizen.NUI.Object.GetProperty(swigCPtr, PanGestureDetector.Property.SCREEN_VELOCITY).Get(temp);
499                 return temp;
500             }
501         }
502         public Vector2 LocalPosition
503         {
504             get
505             {
506                 Vector2 temp = new Vector2(0.0f, 0.0f);
507                 Tizen.NUI.Object.GetProperty(swigCPtr, PanGestureDetector.Property.LOCAL_POSITION).Get(temp);
508                 return temp;
509             }
510         }
511         public Vector2 LocalDisplacement
512         {
513             get
514             {
515                 Vector2 temp = new Vector2(0.0f, 0.0f);
516                 Tizen.NUI.Object.GetProperty(swigCPtr, PanGestureDetector.Property.LOCAL_DISPLACEMENT).Get(temp);
517                 return temp;
518             }
519         }
520         public Vector2 LocalVelocity
521         {
522             get
523             {
524                 Vector2 temp = new Vector2(0.0f, 0.0f);
525                 Tizen.NUI.Object.GetProperty(swigCPtr, PanGestureDetector.Property.LOCAL_VELOCITY).Get(temp);
526                 return temp;
527             }
528         }
529         public bool Panning
530         {
531             get
532             {
533                 bool temp = false;
534                 Tizen.NUI.Object.GetProperty(swigCPtr, PanGestureDetector.Property.PANNING).Get(out temp);
535                 return temp;
536             }
537         }
538     }
539
540 }