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