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