[NUI] Refactor dispose pattern to reduce duplication (#1112)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / TapGestureDetector.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
25     /// <summary>
26     /// This class emits a signal when a tap gesture occurs that meets the requirements set by the application.<br />
27     /// A TapGesture is a discrete gesture, which means it does not have any state information attached.<br />
28     /// </summary>
29     /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
30     [EditorBrowsable(EditorBrowsableState.Never)]
31     public class TapGestureDetector : GestureDetector
32     {
33         private DaliEventHandler<object, DetectedEventArgs> _tapGestureEventHandler;
34         private DetectedCallbackDelegate _tapGestureCallbackDelegate;
35
36         /// <summary>
37         /// Creates an initialized TapGestureDetector.
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 TapGestureDetector() : this(Interop.TapGestureDetector.TapGestureDetector_New__SWIG_0(), true)
42         {
43             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
44         }
45
46         /// <summary>
47         /// Creates an initialized TapGestureDetector with the specified parameters.
48         /// </summary>
49         /// <param name="tapsRequired">The minimum and maximum number of taps required</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 TapGestureDetector(uint tapsRequired) : this(Interop.TapGestureDetector.TapGestureDetector_New__SWIG_1(tapsRequired), true)
53         {
54             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
55
56         }
57
58         internal TapGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.TapGestureDetector.TapGestureDetector_SWIGUpcast(cPtr), cMemoryOwn)
59         {
60         }
61
62         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
63         private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr TapGesture);
64
65         /// <summary>
66         /// This signal is emitted when the specified tap is detected on the attached view.
67         /// </summary>
68         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
69         [EditorBrowsable(EditorBrowsableState.Never)]
70         public event DaliEventHandler<object, DetectedEventArgs> Detected
71         {
72             add
73             {
74                 lock (this)
75                 {
76                     // Restricted to only one listener
77                     if (_tapGestureEventHandler == null)
78                     {
79                         _tapGestureEventHandler += value;
80
81                         _tapGestureCallbackDelegate = new DetectedCallbackDelegate(OnTapGestureDetected);
82                         this.DetectedSignal().Connect(_tapGestureCallbackDelegate);
83                     }
84                 }
85             }
86
87             remove
88             {
89                 lock (this)
90                 {
91                     if (_tapGestureEventHandler != null)
92                     {
93                         this.DetectedSignal().Disconnect(_tapGestureCallbackDelegate);
94                     }
95
96                     _tapGestureEventHandler -= value;
97                 }
98             }
99         }
100
101         /// <summary>
102         /// The copy constructor.
103         /// </summary>
104         /// <param name="handle">A reference to the copied handle</param>
105         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
106         [EditorBrowsable(EditorBrowsableState.Never)]
107         public TapGestureDetector(TapGestureDetector handle) : this(Interop.TapGestureDetector.new_TapGestureDetector__SWIG_1(TapGestureDetector.getCPtr(handle)), true)
108         {
109             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110         }
111
112         /// <summary>
113         /// Sets the minimum number of taps required. The tap count is the number of times a user should "tap" the screen.<br />
114         /// The default is 1.<br />
115         /// </summary>
116         /// <param name="minimumTaps">The minimum taps required</param>
117         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
118         [EditorBrowsable(EditorBrowsableState.Never)]
119         public void SetMinimumTapsRequired(uint minimumTaps)
120         {
121             Interop.TapGestureDetector.TapGestureDetector_SetMinimumTapsRequired(swigCPtr, minimumTaps);
122             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123         }
124
125         /// <summary>
126         /// Sets the maximum number of taps required. The tap count is the number of times a user should "tap" the screen.<br />
127         /// The default is 1.<br />
128         /// </summary>
129         /// <param name="maximumTaps">The maximum taps required</param>
130         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
131         [EditorBrowsable(EditorBrowsableState.Never)]
132         public void SetMaximumTapsRequired(uint maximumTaps)
133         {
134             Interop.TapGestureDetector.TapGestureDetector_SetMaximumTapsRequired(swigCPtr, maximumTaps);
135             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136         }
137
138         /// <summary>
139         /// Retrieves the minimum number of taps required.
140         /// </summary>
141         /// <returns>The minimum taps required</returns>
142         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
143         [EditorBrowsable(EditorBrowsableState.Never)]
144         public uint GetMinimumTapsRequired()
145         {
146             uint ret = Interop.TapGestureDetector.TapGestureDetector_GetMinimumTapsRequired(swigCPtr);
147             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
148             return ret;
149         }
150
151         /// <summary>
152         /// Retrieves the maximum number of taps required.
153         /// </summary>
154         /// <returns>The maximum taps required</returns>
155         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
156         [EditorBrowsable(EditorBrowsableState.Never)]
157         public uint GetMaximumTapsRequired()
158         {
159             uint ret = Interop.TapGestureDetector.TapGestureDetector_GetMaximumTapsRequired(swigCPtr);
160             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
161             return ret;
162         }
163
164         internal new static TapGestureDetector DownCast(BaseHandle handle)
165         {
166             TapGestureDetector ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as TapGestureDetector;
167             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168             return ret;
169         }
170
171         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TapGestureDetector obj)
172         {
173             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
174         }
175
176         internal static TapGestureDetector GetTapGestureDetectorFromPtr(global::System.IntPtr cPtr)
177         {
178             TapGestureDetector ret = new TapGestureDetector(cPtr, false);
179             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180             return ret;
181         }
182
183         internal TapGestureDetectedSignal DetectedSignal()
184         {
185             TapGestureDetectedSignal ret = new TapGestureDetectedSignal(Interop.TapGestureDetector.TapGestureDetector_DetectedSignal(swigCPtr), false);
186             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187             return ret;
188         }
189
190         internal TapGestureDetector Assign(TapGestureDetector rhs)
191         {
192             TapGestureDetector ret = new TapGestureDetector(Interop.TapGestureDetector.TapGestureDetector_Assign(swigCPtr, TapGestureDetector.getCPtr(rhs)), false);
193             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194             return ret;
195         }
196
197         /// This will not be public opened.
198         [EditorBrowsable(EditorBrowsableState.Never)]
199         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
200         {
201             Interop.TapGestureDetector.delete_TapGestureDetector(swigCPtr);
202         }
203
204         private void OnTapGestureDetected(IntPtr actor, IntPtr tapGesture)
205         {
206             DetectedEventArgs e = new DetectedEventArgs();
207
208             // Populate all members of "e" (DetectedEventArgs) with real data
209             e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
210
211             if (null == e.View)
212             {
213                 e.View = Registry.GetManagedBaseHandleFromRefObject(actor) as View;
214             }
215
216             e.TapGesture = Tizen.NUI.TapGesture.GetTapGestureFromPtr(tapGesture);
217
218             if (_tapGestureEventHandler != null)
219             {
220                 //here we send all data to user event handlers
221                 _tapGestureEventHandler(this, e);
222             }
223         }
224
225         /// <summary>
226         /// Event arguments that are passed via the TapGestureEvent signal.
227         /// </summary>
228         /// <since_tizen> 5 </since_tizen>
229         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
230         [EditorBrowsable(EditorBrowsableState.Never)]
231         public class DetectedEventArgs : EventArgs
232         {
233             private View _view;
234             private TapGesture _tapGesture;
235
236             /// <summary>
237             /// The attached view.
238             /// </summary>
239             /// <since_tizen> 5 </since_tizen>
240             /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
241             [EditorBrowsable(EditorBrowsableState.Never)]
242             public View View
243             {
244                 get
245                 {
246                     return _view;
247                 }
248                 set
249                 {
250                     _view = value;
251                 }
252             }
253
254             /// <summary>
255             /// The TapGesture.
256             /// </summary>
257             /// <since_tizen> 5 </since_tizen>
258             /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
259             [EditorBrowsable(EditorBrowsableState.Never)]
260             public TapGesture TapGesture
261             {
262                 get
263                 {
264                     return _tapGesture;
265                 }
266                 set
267                 {
268                     _tapGesture = value;
269                 }
270             }
271         }
272     }
273 }