682975362e7a8e12b7582ec6e881064f1092e2be
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / LongPressGestureDetector.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     /// <summary>
25     /// This class emits a signals when a long press gesture occurs that meets the requirements set by the application.<br />
26     /// For any valid long press, two signals will be emitted:<br />
27     /// - First identifying the beginning (state = Started) i.e. when fingers held down for the required time.<br />
28     /// - Second identifying the ending (state = Finished) i.e. when fingers are released.<br />
29     /// </summary>
30     /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
31     [EditorBrowsable(EditorBrowsableState.Never)]
32     public class LongPressGestureDetector : GestureDetector
33     {
34         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
35
36         private DaliEventHandler<object, DetectedEventArgs> _longPressGestureEventHandler;
37         private DetectedCallbackDelegate _longPressGestureCallbackDelegate;
38
39         /// <summary>
40         /// Constructor.
41         /// </summary>
42         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
43         [EditorBrowsable(EditorBrowsableState.Never)]
44         public LongPressGestureDetector() : this(Interop.LongPressGestureDetector.LongPressGestureDetector_New__SWIG_0(), true)
45         {
46             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
47         }
48
49         /// <summary>
50         /// Creates an initialized LongPressGestureDetector with the number of touches required.<br />
51         /// A long press gesture will be emitted from this detector if the number of fingers touching the screen is equal to the touches required.<br />
52         /// </summary>
53         /// <param name="touchesRequired">The number of touches required.</param>
54         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
55         [EditorBrowsable(EditorBrowsableState.Never)]
56         public LongPressGestureDetector(uint touchesRequired) : this(Interop.LongPressGestureDetector.LongPressGestureDetector_New__SWIG_1(touchesRequired), true)
57         {
58             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
59         }
60
61         /// <summary>
62         /// Creates an initialized LongPressGestureDetector with the minimum and maximum number of touches required.<br />
63         /// A long press gesture will be emitted from this detector if the number of fingers touching the screen falls between the minimum and maximum touches set.<br />
64         /// </summary>
65         /// <param name="minTouches">The minimum number of touches required.</param>
66         /// <param name="maxTouches">The maximum number of touches required.</param>
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 LongPressGestureDetector(uint minTouches, uint maxTouches) : this(Interop.LongPressGestureDetector.LongPressGestureDetector_New__SWIG_2(minTouches, maxTouches), true)
70         {
71             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
72         }
73
74         /// <summary>
75         /// The copy constructor.
76         /// </summary>
77         /// <param name="handle">A reference to the copied handle</param>
78         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
79         [EditorBrowsable(EditorBrowsableState.Never)]
80         public LongPressGestureDetector(LongPressGestureDetector handle) : this(Interop.LongPressGestureDetector.new_LongPressGestureDetector__SWIG_1(LongPressGestureDetector.getCPtr(handle)), true)
81         {
82             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
83         }
84
85         internal LongPressGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.LongPressGestureDetector.LongPressGestureDetector_SWIGUpcast(cPtr), cMemoryOwn)
86         {
87             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
88         }
89
90         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
91         private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr longPressGesture);
92
93         /// <summary>
94         /// This signal is emitted when the specified long press is detected on the attached view.
95         /// </summary>
96         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
97         [EditorBrowsable(EditorBrowsableState.Never)]
98         public event DaliEventHandler<object, DetectedEventArgs> Detected
99         {
100             add
101             {
102                 lock (this)
103                 {
104                     // Restricted to only one listener.
105                     if (_longPressGestureEventHandler == null)
106                     {
107                         _longPressGestureEventHandler += value;
108
109                         _longPressGestureCallbackDelegate = new DetectedCallbackDelegate(OnLongPressGestureDetected);
110                         this.DetectedSignal().Connect(_longPressGestureCallbackDelegate);
111                     }
112                 }
113             }
114
115             remove
116             {
117                 lock (this)
118                 {
119                     if (_longPressGestureEventHandler != null)
120                     {
121                         this.DetectedSignal().Disconnect(_longPressGestureCallbackDelegate);
122                     }
123
124                     _longPressGestureEventHandler -= value;
125                 }
126             }
127         }
128
129         /// <summary>
130         /// Sets the number of touches required.<br />
131         /// The number of touches corresponds to the number of fingers a user has on the screen. The default is 1.<br />
132         /// </summary>
133         /// <param name="touches">Touches required</param>
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 void SetTouchesRequired(uint touches)
137         {
138             Interop.LongPressGestureDetector.LongPressGestureDetector_SetTouchesRequired__SWIG_0(swigCPtr, touches);
139             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140         }
141
142         /// <summary>
143         /// Sets the minimum and maximum touches required.
144         /// </summary>
145         /// <param name="minTouches">Minimum touches required.</param>
146         /// <param name="maxTouches">Maximum touches required.</param>
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 void SetTouchesRequired(uint minTouches, uint maxTouches)
150         {
151             Interop.LongPressGestureDetector.LongPressGestureDetector_SetTouchesRequired__SWIG_1(swigCPtr, minTouches, maxTouches);
152             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153         }
154
155         /// <summary>
156         /// Retrieves the minimum number of touches required.
157         /// </summary>
158         /// <returns>The minimum number of touches required.</returns>
159         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
160         [EditorBrowsable(EditorBrowsableState.Never)]
161         public uint GetMinimumTouchesRequired()
162         {
163             uint ret = Interop.LongPressGestureDetector.LongPressGestureDetector_GetMinimumTouchesRequired(swigCPtr);
164             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
165             return ret;
166         }
167
168         /// <summary>
169         /// Retrieves the maximum number of touches required.
170         /// </summary>
171         /// <returns>The maximum number of touches required.</returns>
172         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
173         [EditorBrowsable(EditorBrowsableState.Never)]
174         public uint GetMaximumTouchesRequired()
175         {
176             uint ret = Interop.LongPressGestureDetector.LongPressGestureDetector_GetMaximumTouchesRequired(swigCPtr);
177             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
178             return ret;
179         }
180
181         internal static LongPressGestureDetector GetLongPressGestureDetectorFromPtr(global::System.IntPtr cPtr)
182         {
183             LongPressGestureDetector ret = new LongPressGestureDetector(cPtr, false);
184             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185             return ret;
186         }
187
188         internal new static LongPressGestureDetector DownCast(BaseHandle handle)
189         {
190             LongPressGestureDetector ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as LongPressGestureDetector;
191             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
192             return ret;
193         }
194
195         internal LongPressGestureDetector Assign(LongPressGestureDetector rhs)
196         {
197             LongPressGestureDetector ret = new LongPressGestureDetector(Interop.LongPressGestureDetector.LongPressGestureDetector_Assign(swigCPtr, LongPressGestureDetector.getCPtr(rhs)), false);
198             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199             return ret;
200         }
201
202         internal LongPressGestureDetectedSignal DetectedSignal()
203         {
204             LongPressGestureDetectedSignal ret = new LongPressGestureDetectedSignal(Interop.LongPressGestureDetector.LongPressGestureDetector_DetectedSignal(swigCPtr), false);
205             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206             return ret;
207         }
208
209         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(LongPressGestureDetector obj)
210         {
211             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
212         }
213
214         /// <summary>
215         /// Dispose.
216         /// </summary>
217         /// <param name="type">The dispose type</param>
218         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
219         [EditorBrowsable(EditorBrowsableState.Never)]
220         protected override void Dispose(DisposeTypes type)
221         {
222             if (disposed)
223             {
224                 return;
225             }
226
227             //Release your own unmanaged resources here.
228             //You should not access any managed member here except static instance.
229             //because the execution order of Finalizes is non-deterministic.
230
231             if (swigCPtr.Handle != global::System.IntPtr.Zero)
232             {
233                 if (swigCMemOwn)
234                 {
235                     swigCMemOwn = false;
236                     Interop.LongPressGestureDetector.delete_LongPressGestureDetector(swigCPtr);
237                 }
238                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
239             }
240
241             base.Dispose(type);
242         }
243
244         private void OnLongPressGestureDetected(IntPtr actor, IntPtr longPressGesture)
245         {
246             DetectedEventArgs e = new DetectedEventArgs();
247
248             // Populate all members of "e" (LongPressGestureEventArgs) with real data.
249             e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
250             if (null == e.View)
251             {
252                 e.View = Registry.GetManagedBaseHandleFromRefObject(actor) as View;
253             }
254
255             e.LongPressGesture = Tizen.NUI.LongPressGesture.GetLongPressGestureFromPtr(longPressGesture);
256
257             if (_longPressGestureEventHandler != null)
258             {
259                 //Here we send all data to user event handlers.
260                 _longPressGestureEventHandler(this, e);
261             }
262         }
263
264         /// <summary>
265         /// Event arguments that passed via the LongPressGestureEvent signal.
266         /// </summary>
267         /// <since_tizen> 5 </since_tizen>
268         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
269         [EditorBrowsable(EditorBrowsableState.Never)]
270         public class DetectedEventArgs : EventArgs
271         {
272             private View _view;
273             private LongPressGesture _longPressGesture;
274
275             /// <summary>
276             /// View the attached view.
277             /// </summary>
278             /// <since_tizen> 5 </since_tizen>
279             /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
280             [EditorBrowsable(EditorBrowsableState.Never)]
281             public View View
282             {
283                 get
284                 {
285                     return _view;
286                 }
287                 set
288                 {
289                     _view = value;
290                 }
291             }
292
293             /// <summary>
294             /// The LongPressGesture.
295             /// </summary>
296             /// <since_tizen> 5 </since_tizen>
297             /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
298             [EditorBrowsable(EditorBrowsableState.Never)]
299             public LongPressGesture LongPressGesture
300             {
301                 get
302                 {
303                     return _longPressGesture;
304                 }
305                 set
306                 {
307                     _longPressGesture = value;
308                 }
309             }
310         }
311     }
312 }