Release 4.0.0-preview1-00301
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / PinchGestureDetector.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 PinchGestureDetector : GestureDetector
27     {
28         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
29
30         internal PinchGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.PinchGestureDetector_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(PinchGestureDetector obj)
36         {
37             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
38         }
39
40
41         protected override void Dispose(DisposeTypes type)
42         {
43             if (disposed)
44             {
45                 return;
46             }
47
48             if (type == DisposeTypes.Explicit)
49             {
50                 //Called by User
51                 //Release your own managed resources here.
52                 //You should release all of your own disposable objects here.
53
54             }
55
56             //Release your own unmanaged resources here.
57             //You should not access any managed member here except static instance.
58             //because the execution order of Finalizes is non-deterministic.
59
60
61             if (swigCPtr.Handle != global::System.IntPtr.Zero)
62             {
63                 if (swigCMemOwn)
64                 {
65                     swigCMemOwn = false;
66                     NDalicPINVOKE.delete_PinchGestureDetector(swigCPtr);
67                 }
68                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
69             }
70
71             base.Dispose(type);
72         }
73
74
75         public class DetectedEventArgs : EventArgs
76         {
77             private View _view;
78             private PinchGesture _pinchGesture;
79
80             public View View
81             {
82                 get
83                 {
84                     return _view;
85                 }
86                 set
87                 {
88                     _view = value;
89                 }
90             }
91
92             public PinchGesture PinchGesture
93             {
94                 get
95                 {
96                     return _pinchGesture;
97                 }
98                 set
99                 {
100                     _pinchGesture = value;
101                 }
102             }
103         }
104
105         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
106         private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr pinchGesture);
107         private DaliEventHandler<object, DetectedEventArgs> _pinchGestureEventHandler;
108         private DetectedCallbackDelegate _pinchGestureCallbackDelegate;
109
110
111         public event DaliEventHandler<object, DetectedEventArgs> Detected
112         {
113             add
114             {
115                 lock (this)
116                 {
117                     // Restricted to only one listener
118                     if (_pinchGestureEventHandler == null)
119                     {
120                         _pinchGestureEventHandler += value;
121
122                         _pinchGestureCallbackDelegate = new DetectedCallbackDelegate(OnPinchGestureDetected);
123                         this.DetectedSignal().Connect(_pinchGestureCallbackDelegate);
124                     }
125                 }
126             }
127
128             remove
129             {
130                 lock (this)
131                 {
132                     if (_pinchGestureEventHandler != null)
133                     {
134                         this.DetectedSignal().Disconnect(_pinchGestureCallbackDelegate);
135                     }
136
137                     _pinchGestureEventHandler -= value;
138                 }
139             }
140         }
141
142         private void OnPinchGestureDetected(IntPtr actor, IntPtr pinchGesture)
143         {
144             DetectedEventArgs e = new DetectedEventArgs();
145
146             // Populate all members of "e" (DetectedEventArgs) with real data
147             e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
148             e.PinchGesture = Tizen.NUI.PinchGesture.GetPinchGestureFromPtr(pinchGesture);
149
150             if (_pinchGestureEventHandler != null)
151             {
152                 //here we send all data to user event handlers
153                 _pinchGestureEventHandler(this, e);
154             }
155
156         }
157
158
159         public static PinchGestureDetector GetPinchGestureDetectorFromPtr(global::System.IntPtr cPtr)
160         {
161             PinchGestureDetector ret = new PinchGestureDetector(cPtr, false);
162             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163             return ret;
164         }
165
166
167         public PinchGestureDetector() : this(NDalicPINVOKE.PinchGestureDetector_New(), true)
168         {
169             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170
171         }
172         public new static PinchGestureDetector DownCast(BaseHandle handle)
173         {
174             PinchGestureDetector ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as PinchGestureDetector;
175             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176             return ret;
177         }
178
179         public PinchGestureDetector(PinchGestureDetector handle) : this(NDalicPINVOKE.new_PinchGestureDetector__SWIG_1(PinchGestureDetector.getCPtr(handle)), true)
180         {
181             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182         }
183
184         public PinchGestureDetector Assign(PinchGestureDetector rhs)
185         {
186             PinchGestureDetector ret = new PinchGestureDetector(NDalicPINVOKE.PinchGestureDetector_Assign(swigCPtr, PinchGestureDetector.getCPtr(rhs)), false);
187             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188             return ret;
189         }
190
191         internal PinchGestureDetectedSignal DetectedSignal()
192         {
193             PinchGestureDetectedSignal ret = new PinchGestureDetectedSignal(NDalicPINVOKE.PinchGestureDetector_DetectedSignal(swigCPtr), false);
194             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
195             return ret;
196         }
197
198     }
199
200 }