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