[NUI] Remove duplicate getCPtr from BaseHandle subclasses (#3545)
[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.StdCall)]
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         /// This will not be public opened.
185         [EditorBrowsable(EditorBrowsableState.Never)]
186         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
187         {
188             if (_detectedCallback != null)
189             {
190                 DetectedSignal().Disconnect(_detectedCallback);
191             }
192
193             Interop.TapGestureDetector.DeleteTapGestureDetector(swigCPtr);
194         }
195
196         private void OnTapGestureDetected(IntPtr actor, IntPtr tapGesture)
197         {
198             DetectedEventArgs e = new DetectedEventArgs();
199
200             // Populate all members of "e" (DetectedEventArgs) with real data
201             e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
202
203             if (null == e.View)
204             {
205                 e.View = Registry.GetManagedBaseHandleFromRefObject(actor) as View;
206             }
207
208             e.TapGesture = Tizen.NUI.TapGesture.GetTapGestureFromPtr(tapGesture);
209
210             if (_detectedEventHandler != null)
211             {
212                 e.Handled = true;
213                 //here we send all data to user event handlers
214                 _detectedEventHandler(this, e);
215             }
216         }
217
218         /// <summary>
219         /// Event arguments that are passed via the TapGestureEvent signal.
220         /// </summary>
221         /// <since_tizen> 5 </since_tizen>
222         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
223         [EditorBrowsable(EditorBrowsableState.Never)]
224         public class DetectedEventArgs : EventArgs
225         {
226             private View _view;
227             private TapGesture _tapGesture;
228             private bool handled = true;
229
230             /// <summary>
231             /// The attached view.
232             /// </summary>
233             /// <since_tizen> 5 </since_tizen>
234             /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
235             [EditorBrowsable(EditorBrowsableState.Never)]
236             public View View
237             {
238                 get
239                 {
240                     return _view;
241                 }
242                 set
243                 {
244                     _view = value;
245                 }
246             }
247
248             /// <summary>
249             /// The TapGesture.
250             /// </summary>
251             /// <since_tizen> 5 </since_tizen>
252             /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
253             [EditorBrowsable(EditorBrowsableState.Never)]
254             public TapGesture TapGesture
255             {
256                 get
257                 {
258                     return _tapGesture;
259                 }
260                 set
261                 {
262                     _tapGesture = value;
263                 }
264             }
265
266             /// <summary>
267             /// 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.
268             /// </summary>
269             [EditorBrowsable(EditorBrowsableState.Never)]
270             public bool Handled
271             {
272                 get => handled;
273                 set
274                 {
275                     handled = value;
276                     Interop.Actor.SetNeedGesturePropagation(View.getCPtr(_view), !value);
277                     if (NDalicPINVOKE.SWIGPendingException.Pending)
278                         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
279                 }
280             }
281         }
282     }
283 }