384b840a260b77ad34b2e66e44db25acf1957a1d
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / PinchGestureDetector.cs
1 /*
2  * Copyright(c) 2018 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 using System;
18 using System.Runtime.InteropServices;
19 using Tizen.NUI.BaseComponents;
20 using System.ComponentModel;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// It tries to detect when the user moves two touch points towards or away from each other.
26     /// </summary>
27     /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
28     [EditorBrowsable(EditorBrowsableState.Never)]
29     public class PinchGestureDetector : GestureDetector
30     {
31         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32
33         private DaliEventHandler<object, DetectedEventArgs> _pinchGestureEventHandler;
34         private DetectedCallbackDelegate _pinchGestureCallbackDelegate;
35
36
37         /// <summary>
38         /// Creates an initialized PinchGestureDetector.
39         /// </summary>
40         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
41         [EditorBrowsable(EditorBrowsableState.Never)]
42         public PinchGestureDetector() : this(Interop.PinchGesture.PinchGestureDetector_New(), true)
43         {
44             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
45
46         }
47
48         /// <summary>
49         /// The copy constructor.
50         /// </summary>
51         /// <param name="handle">A reference to the copied handle</param>
52         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
53         [EditorBrowsable(EditorBrowsableState.Never)]
54         public PinchGestureDetector(PinchGestureDetector handle) : this(Interop.PinchGesture.new_PinchGestureDetector__SWIG_1(PinchGestureDetector.getCPtr(handle)), true)
55         {
56             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
57         }
58
59         internal PinchGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PinchGesture.PinchGestureDetector_SWIGUpcast(cPtr), cMemoryOwn)
60         {
61             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
62         }
63
64         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
65         private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr pinchGesture);
66
67         /// <summary>
68         /// This signal is emitted when the specified pinch is detected on the attached view.
69         /// </summary>
70         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
71         [EditorBrowsable(EditorBrowsableState.Never)]
72         public event DaliEventHandler<object, DetectedEventArgs> Detected
73         {
74             add
75             {
76                 lock (this)
77                 {
78                     // Restricted to only one listener
79                     if (_pinchGestureEventHandler == null)
80                     {
81                         _pinchGestureEventHandler += value;
82
83                         _pinchGestureCallbackDelegate = new DetectedCallbackDelegate(OnPinchGestureDetected);
84                         this.DetectedSignal().Connect(_pinchGestureCallbackDelegate);
85                     }
86                 }
87             }
88
89             remove
90             {
91                 lock (this)
92                 {
93                     if (_pinchGestureEventHandler != null)
94                     {
95                         this.DetectedSignal().Disconnect(_pinchGestureCallbackDelegate);
96                     }
97
98                     _pinchGestureEventHandler -= value;
99                 }
100             }
101         }
102
103
104         internal static PinchGestureDetector GetPinchGestureDetectorFromPtr(global::System.IntPtr cPtr)
105         {
106             PinchGestureDetector ret = new PinchGestureDetector(cPtr, false);
107             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
108             return ret;
109         }
110
111         internal new static PinchGestureDetector DownCast(BaseHandle handle)
112         {
113             PinchGestureDetector ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as PinchGestureDetector;
114             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
115             return ret;
116         }
117
118         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PinchGestureDetector obj)
119         {
120             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
121         }
122
123         internal PinchGestureDetector Assign(PinchGestureDetector rhs)
124         {
125             PinchGestureDetector ret = new PinchGestureDetector(Interop.PinchGesture.PinchGestureDetector_Assign(swigCPtr, PinchGestureDetector.getCPtr(rhs)), false);
126             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127             return ret;
128         }
129
130         internal PinchGestureDetectedSignal DetectedSignal()
131         {
132             PinchGestureDetectedSignal ret = new PinchGestureDetectedSignal(Interop.PinchGesture.PinchGestureDetector_DetectedSignal(swigCPtr), false);
133             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
134             return ret;
135         }
136
137         /// <summary>
138         /// Dispose.
139         /// </summary>
140         /// <param name="type">The dispose type</param>
141         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
142         [EditorBrowsable(EditorBrowsableState.Never)]
143         protected override void Dispose(DisposeTypes type)
144         {
145             if (disposed)
146             {
147                 return;
148             }
149
150             if (type == DisposeTypes.Explicit)
151             {
152                 //Called by User
153                 //Release your own managed resources here.
154                 //You should release all of your own disposable objects here.
155
156             }
157
158             //Release your own unmanaged resources here.
159             //You should not access any managed member here except static instance.
160             //Because the execution order of Finalizes is non-deterministic.
161
162
163             if (swigCPtr.Handle != global::System.IntPtr.Zero)
164             {
165                 if (swigCMemOwn)
166                 {
167                     swigCMemOwn = false;
168                     Interop.PinchGesture.delete_PinchGestureDetector(swigCPtr);
169                 }
170                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
171             }
172
173             base.Dispose(type);
174         }
175
176         private void OnPinchGestureDetected(IntPtr actor, IntPtr pinchGesture)
177         {
178             DetectedEventArgs e = new DetectedEventArgs();
179
180             // Populate all members of "e" (DetectedEventArgs) with real data.
181             e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
182             e.PinchGesture = Tizen.NUI.PinchGesture.GetPinchGestureFromPtr(pinchGesture);
183
184             if (_pinchGestureEventHandler != null)
185             {
186                 //Here we send all data to user event handlers.
187                 _pinchGestureEventHandler(this, e);
188             }
189
190         }
191
192         /// <summary>
193         /// Event arguments that passed via the PinchGestureEvent signal.
194         /// </summary>
195         /// <since_tizen> 5 </since_tizen>
196         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
197         [EditorBrowsable(EditorBrowsableState.Never)]
198         public class DetectedEventArgs : EventArgs
199         {
200             private View _view;
201             private PinchGesture _pinchGesture;
202
203             /// <summary>
204             /// The attached view.
205             /// </summary>
206             /// <since_tizen> 5 </since_tizen>
207             /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
208             [EditorBrowsable(EditorBrowsableState.Never)]
209             public View View
210             {
211                 get
212                 {
213                     return _view;
214                 }
215                 set
216                 {
217                     _view = value;
218                 }
219             }
220
221             /// <summary>
222             /// The PinchGesture.
223             /// </summary>
224             /// <since_tizen> 5 </since_tizen>
225             /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
226             [EditorBrowsable(EditorBrowsableState.Never)]
227             public PinchGesture PinchGesture
228             {
229                 get
230                 {
231                     return _pinchGesture;
232                 }
233                 set
234                 {
235                     _pinchGesture = value;
236                 }
237             }
238         }
239
240     }
241
242 }