Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / PinchGestureDetector.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     using System;
21     using System.Runtime.InteropServices;
22     using Tizen.NUI.BaseComponents;
23
24
25     internal class PinchGestureDetector : GestureDetector
26     {
27         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
28
29         internal PinchGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PinchGestureDetector_SWIGUpcast(cPtr), cMemoryOwn)
30         {
31             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
32         }
33
34         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PinchGestureDetector obj)
35         {
36             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
37         }
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
60             if (swigCPtr.Handle != global::System.IntPtr.Zero)
61             {
62                 if (swigCMemOwn)
63                 {
64                     swigCMemOwn = false;
65                     NDalicPINVOKE.delete_PinchGestureDetector(swigCPtr);
66                 }
67                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
68             }
69
70             base.Dispose(type);
71         }
72
73
74         public class DetectedEventArgs : EventArgs
75         {
76             private View _view;
77             private PinchGesture _pinchGesture;
78
79             public View View
80             {
81                 get
82                 {
83                     return _view;
84                 }
85                 set
86                 {
87                     _view = value;
88                 }
89             }
90
91             public PinchGesture PinchGesture
92             {
93                 get
94                 {
95                     return _pinchGesture;
96                 }
97                 set
98                 {
99                     _pinchGesture = value;
100                 }
101             }
102         }
103
104         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
105         private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr pinchGesture);
106         private DaliEventHandler<object, DetectedEventArgs> _pinchGestureEventHandler;
107         private DetectedCallbackDelegate _pinchGestureCallbackDelegate;
108
109
110         public event DaliEventHandler<object, DetectedEventArgs> Detected
111         {
112             add
113             {
114                 lock (this)
115                 {
116                     // Restricted to only one listener
117                     if (_pinchGestureEventHandler == null)
118                     {
119                         _pinchGestureEventHandler += value;
120
121                         _pinchGestureCallbackDelegate = new DetectedCallbackDelegate(OnPinchGestureDetected);
122                         this.DetectedSignal().Connect(_pinchGestureCallbackDelegate);
123                     }
124                 }
125             }
126
127             remove
128             {
129                 lock (this)
130                 {
131                     if (_pinchGestureEventHandler != null)
132                     {
133                         this.DetectedSignal().Disconnect(_pinchGestureCallbackDelegate);
134                     }
135
136                     _pinchGestureEventHandler -= value;
137                 }
138             }
139         }
140
141         private void OnPinchGestureDetected(IntPtr actor, IntPtr pinchGesture)
142         {
143             DetectedEventArgs e = new DetectedEventArgs();
144
145             // Populate all members of "e" (DetectedEventArgs) with real data
146             e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
147             e.PinchGesture = Tizen.NUI.PinchGesture.GetPinchGestureFromPtr(pinchGesture);
148
149             if (_pinchGestureEventHandler != null)
150             {
151                 //here we send all data to user event handlers
152                 _pinchGestureEventHandler(this, e);
153             }
154
155         }
156
157
158         public static PinchGestureDetector GetPinchGestureDetectorFromPtr(global::System.IntPtr cPtr)
159         {
160             PinchGestureDetector ret = new PinchGestureDetector(cPtr, false);
161             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
162             return ret;
163         }
164
165
166         public PinchGestureDetector() : this(NDalicPINVOKE.PinchGestureDetector_New(), true)
167         {
168             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
169
170         }
171         public new static PinchGestureDetector DownCast(BaseHandle handle)
172         {
173             PinchGestureDetector ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as PinchGestureDetector;
174             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175             return ret;
176         }
177
178         public PinchGestureDetector(PinchGestureDetector handle) : this(NDalicPINVOKE.new_PinchGestureDetector__SWIG_1(PinchGestureDetector.getCPtr(handle)), true)
179         {
180             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181         }
182
183         public PinchGestureDetector Assign(PinchGestureDetector rhs)
184         {
185             PinchGestureDetector ret = new PinchGestureDetector(NDalicPINVOKE.PinchGestureDetector_Assign(swigCPtr, PinchGestureDetector.getCPtr(rhs)), false);
186             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187             return ret;
188         }
189
190         internal PinchGestureDetectedSignal DetectedSignal()
191         {
192             PinchGestureDetectedSignal ret = new PinchGestureDetectedSignal(NDalicPINVOKE.PinchGestureDetector_DetectedSignal(swigCPtr), false);
193             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194             return ret;
195         }
196
197     }
198
199 }