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