Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / TapGestureDetector.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 namespace Tizen.NUI
18 {
19
20     using System;
21     using System.Runtime.InteropServices;
22     using Tizen.NUI.BaseComponents;
23
24     internal class TapGestureDetector : GestureDetector
25     {
26         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
27
28         internal TapGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.TapGestureDetector_SWIGUpcast(cPtr), cMemoryOwn)
29         {
30             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
31         }
32
33         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(TapGestureDetector obj)
34         {
35             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
36         }
37
38         protected override void Dispose(DisposeTypes type)
39         {
40             if (disposed)
41             {
42                 return;
43             }
44
45             if (type == DisposeTypes.Explicit)
46             {
47                 //Called by User
48                 //Release your own managed resources here.
49                 //You should release all of your own disposable objects here.
50
51             }
52
53             //Release your own unmanaged resources here.
54             //You should not access any managed member here except static instance.
55             //because the execution order of Finalizes is non-deterministic.
56
57             if (swigCPtr.Handle != global::System.IntPtr.Zero)
58             {
59                 if (swigCMemOwn)
60                 {
61                     swigCMemOwn = false;
62                     NDalicPINVOKE.delete_TapGestureDetector(swigCPtr);
63                 }
64                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
65             }
66
67             base.Dispose(type);
68         }
69
70
71         public class DetectedEventArgs : EventArgs
72         {
73             private View _view;
74             private TapGesture _tapGesture;
75
76             public View View
77             {
78                 get
79                 {
80                     return _view;
81                 }
82                 set
83                 {
84                     _view = value;
85                 }
86             }
87
88             public TapGesture TapGesture
89             {
90                 get
91                 {
92                     return _tapGesture;
93                 }
94                 set
95                 {
96                     _tapGesture = value;
97                 }
98             }
99         }
100
101         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
102         private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr TapGesture);
103         private DaliEventHandler<object, DetectedEventArgs> _tapGestureEventHandler;
104         private DetectedCallbackDelegate _tapGestureCallbackDelegate;
105
106
107         public event DaliEventHandler<object, DetectedEventArgs> Detected
108         {
109             add
110             {
111                 lock (this)
112                 {
113                     // Restricted to only one listener
114                     if (_tapGestureEventHandler == null)
115                     {
116                         _tapGestureEventHandler += value;
117
118                         _tapGestureCallbackDelegate = new DetectedCallbackDelegate(OnTapGestureDetected);
119                         this.DetectedSignal().Connect(_tapGestureCallbackDelegate);
120                     }
121                 }
122             }
123
124             remove
125             {
126                 lock (this)
127                 {
128                     if (_tapGestureEventHandler != null)
129                     {
130                         this.DetectedSignal().Disconnect(_tapGestureCallbackDelegate);
131                     }
132
133                     _tapGestureEventHandler -= value;
134                 }
135             }
136         }
137
138         private void OnTapGestureDetected(IntPtr actor, IntPtr tapGesture)
139         {
140             DetectedEventArgs e = new DetectedEventArgs();
141
142             // Populate all members of "e" (DetectedEventArgs) with real data
143             e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
144             e.TapGesture = Tizen.NUI.TapGesture.GetTapGestureFromPtr(tapGesture);
145
146             if (_tapGestureEventHandler != null)
147             {
148                 //here we send all data to user event handlers
149                 _tapGestureEventHandler(this, e);
150             }
151
152         }
153
154
155         public static TapGestureDetector GetTapGestureDetectorFromPtr(global::System.IntPtr cPtr)
156         {
157             TapGestureDetector ret = new TapGestureDetector(cPtr, false);
158             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159             return ret;
160         }
161
162
163         public TapGestureDetector() : this(NDalicPINVOKE.TapGestureDetector_New__SWIG_0(), true)
164         {
165             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
166
167         }
168         public TapGestureDetector(uint tapsRequired) : this(NDalicPINVOKE.TapGestureDetector_New__SWIG_1(tapsRequired), true)
169         {
170             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171
172         }
173         public new static TapGestureDetector DownCast(BaseHandle handle)
174         {
175             TapGestureDetector ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as TapGestureDetector;
176             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
177             return ret;
178         }
179
180         public TapGestureDetector(TapGestureDetector handle) : this(NDalicPINVOKE.new_TapGestureDetector__SWIG_1(TapGestureDetector.getCPtr(handle)), true)
181         {
182             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
183         }
184
185         public TapGestureDetector Assign(TapGestureDetector rhs)
186         {
187             TapGestureDetector ret = new TapGestureDetector(NDalicPINVOKE.TapGestureDetector_Assign(swigCPtr, TapGestureDetector.getCPtr(rhs)), false);
188             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
189             return ret;
190         }
191
192         public void SetMinimumTapsRequired(uint minimumTaps)
193         {
194             NDalicPINVOKE.TapGestureDetector_SetMinimumTapsRequired(swigCPtr, minimumTaps);
195             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196         }
197
198         public void SetMaximumTapsRequired(uint maximumTaps)
199         {
200             NDalicPINVOKE.TapGestureDetector_SetMaximumTapsRequired(swigCPtr, maximumTaps);
201             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
202         }
203
204         public uint GetMinimumTapsRequired()
205         {
206             uint ret = NDalicPINVOKE.TapGestureDetector_GetMinimumTapsRequired(swigCPtr);
207             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208             return ret;
209         }
210
211         public uint GetMaximumTapsRequired()
212         {
213             uint ret = NDalicPINVOKE.TapGestureDetector_GetMaximumTapsRequired(swigCPtr);
214             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
215             return ret;
216         }
217
218         internal TapGestureDetectedSignal DetectedSignal()
219         {
220             TapGestureDetectedSignal ret = new TapGestureDetectedSignal(NDalicPINVOKE.TapGestureDetector_DetectedSignal(swigCPtr), false);
221             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
222             return ret;
223         }
224
225     }
226
227 }