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