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