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