Merge "[NUI] Add Extents type Padding in View"
[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         /// <since_tizen> 3 </since_tizen>
76         public class DetectedEventArgs : EventArgs
77         {
78             private View _view;
79             private PinchGesture _pinchGesture;
80
81             /// <since_tizen> 3 </since_tizen>
82             public View View
83             {
84                 get
85                 {
86                     return _view;
87                 }
88                 set
89                 {
90                     _view = value;
91                 }
92             }
93
94             /// <since_tizen> 3 </since_tizen>
95             public PinchGesture PinchGesture
96             {
97                 get
98                 {
99                     return _pinchGesture;
100                 }
101                 set
102                 {
103                     _pinchGesture = value;
104                 }
105             }
106         }
107
108         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
109         private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr pinchGesture);
110         private DaliEventHandler<object, DetectedEventArgs> _pinchGestureEventHandler;
111         private DetectedCallbackDelegate _pinchGestureCallbackDelegate;
112
113
114         public event DaliEventHandler<object, DetectedEventArgs> Detected
115         {
116             add
117             {
118                 lock (this)
119                 {
120                     // Restricted to only one listener
121                     if (_pinchGestureEventHandler == null)
122                     {
123                         _pinchGestureEventHandler += value;
124
125                         _pinchGestureCallbackDelegate = new DetectedCallbackDelegate(OnPinchGestureDetected);
126                         this.DetectedSignal().Connect(_pinchGestureCallbackDelegate);
127                     }
128                 }
129             }
130
131             remove
132             {
133                 lock (this)
134                 {
135                     if (_pinchGestureEventHandler != null)
136                     {
137                         this.DetectedSignal().Disconnect(_pinchGestureCallbackDelegate);
138                     }
139
140                     _pinchGestureEventHandler -= value;
141                 }
142             }
143         }
144
145         private void OnPinchGestureDetected(IntPtr actor, IntPtr pinchGesture)
146         {
147             DetectedEventArgs e = new DetectedEventArgs();
148
149             // Populate all members of "e" (DetectedEventArgs) with real data
150             e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
151             e.PinchGesture = Tizen.NUI.PinchGesture.GetPinchGestureFromPtr(pinchGesture);
152
153             if (_pinchGestureEventHandler != null)
154             {
155                 //here we send all data to user event handlers
156                 _pinchGestureEventHandler(this, e);
157             }
158
159         }
160
161
162         public static PinchGestureDetector GetPinchGestureDetectorFromPtr(global::System.IntPtr cPtr)
163         {
164             PinchGestureDetector ret = new PinchGestureDetector(cPtr, false);
165             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
166             return ret;
167         }
168
169
170         public PinchGestureDetector() : this(NDalicPINVOKE.PinchGestureDetector_New(), true)
171         {
172             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
173
174         }
175         public new static PinchGestureDetector DownCast(BaseHandle handle)
176         {
177             PinchGestureDetector ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as PinchGestureDetector;
178             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
179             return ret;
180         }
181
182         public PinchGestureDetector(PinchGestureDetector handle) : this(NDalicPINVOKE.new_PinchGestureDetector__SWIG_1(PinchGestureDetector.getCPtr(handle)), true)
183         {
184             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185         }
186
187         public PinchGestureDetector Assign(PinchGestureDetector rhs)
188         {
189             PinchGestureDetector ret = new PinchGestureDetector(NDalicPINVOKE.PinchGestureDetector_Assign(swigCPtr, PinchGestureDetector.getCPtr(rhs)), false);
190             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191             return ret;
192         }
193
194         internal PinchGestureDetectedSignal DetectedSignal()
195         {
196             PinchGestureDetectedSignal ret = new PinchGestureDetectedSignal(NDalicPINVOKE.PinchGestureDetector_DetectedSignal(swigCPtr), false);
197             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198             return ret;
199         }
200
201     }
202
203 }