Merge "[NUI] Add Extents type Padding in View"
[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         /// <since_tizen> 3 </since_tizen>
73         public class DetectedEventArgs : EventArgs
74         {
75             private View _view;
76             private TapGesture _tapGesture;
77
78             /// <since_tizen> 3 </since_tizen>
79             public View View
80             {
81                 get
82                 {
83                     return _view;
84                 }
85                 set
86                 {
87                     _view = value;
88                 }
89             }
90
91             /// <since_tizen> 3 </since_tizen>
92             public TapGesture TapGesture
93             {
94                 get
95                 {
96                     return _tapGesture;
97                 }
98                 set
99                 {
100                     _tapGesture = value;
101                 }
102             }
103         }
104
105         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
106         private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr TapGesture);
107         private DaliEventHandler<object, DetectedEventArgs> _tapGestureEventHandler;
108         private DetectedCallbackDelegate _tapGestureCallbackDelegate;
109
110
111         public event DaliEventHandler<object, DetectedEventArgs> Detected
112         {
113             add
114             {
115                 lock (this)
116                 {
117                     // Restricted to only one listener
118                     if (_tapGestureEventHandler == null)
119                     {
120                         _tapGestureEventHandler += value;
121
122                         _tapGestureCallbackDelegate = new DetectedCallbackDelegate(OnTapGestureDetected);
123                         this.DetectedSignal().Connect(_tapGestureCallbackDelegate);
124                     }
125                 }
126             }
127
128             remove
129             {
130                 lock (this)
131                 {
132                     if (_tapGestureEventHandler != null)
133                     {
134                         this.DetectedSignal().Disconnect(_tapGestureCallbackDelegate);
135                     }
136
137                     _tapGestureEventHandler -= value;
138                 }
139             }
140         }
141
142         private void OnTapGestureDetected(IntPtr actor, IntPtr tapGesture)
143         {
144             DetectedEventArgs e = new DetectedEventArgs();
145
146             // Populate all members of "e" (DetectedEventArgs) with real data
147             e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
148             e.TapGesture = Tizen.NUI.TapGesture.GetTapGestureFromPtr(tapGesture);
149
150             if (_tapGestureEventHandler != null)
151             {
152                 //here we send all data to user event handlers
153                 _tapGestureEventHandler(this, e);
154             }
155
156         }
157
158
159         public static TapGestureDetector GetTapGestureDetectorFromPtr(global::System.IntPtr cPtr)
160         {
161             TapGestureDetector ret = new TapGestureDetector(cPtr, false);
162             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163             return ret;
164         }
165
166
167         public TapGestureDetector() : this(NDalicPINVOKE.TapGestureDetector_New__SWIG_0(), true)
168         {
169             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
170
171         }
172         public TapGestureDetector(uint tapsRequired) : this(NDalicPINVOKE.TapGestureDetector_New__SWIG_1(tapsRequired), true)
173         {
174             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
175
176         }
177         public new static TapGestureDetector DownCast(BaseHandle handle)
178         {
179             TapGestureDetector ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as TapGestureDetector;
180             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
181             return ret;
182         }
183
184         public TapGestureDetector(TapGestureDetector handle) : this(NDalicPINVOKE.new_TapGestureDetector__SWIG_1(TapGestureDetector.getCPtr(handle)), true)
185         {
186             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187         }
188
189         public TapGestureDetector Assign(TapGestureDetector rhs)
190         {
191             TapGestureDetector ret = new TapGestureDetector(NDalicPINVOKE.TapGestureDetector_Assign(swigCPtr, TapGestureDetector.getCPtr(rhs)), false);
192             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193             return ret;
194         }
195
196         public void SetMinimumTapsRequired(uint minimumTaps)
197         {
198             NDalicPINVOKE.TapGestureDetector_SetMinimumTapsRequired(swigCPtr, minimumTaps);
199             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
200         }
201
202         public void SetMaximumTapsRequired(uint maximumTaps)
203         {
204             NDalicPINVOKE.TapGestureDetector_SetMaximumTapsRequired(swigCPtr, maximumTaps);
205             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206         }
207
208         public uint GetMinimumTapsRequired()
209         {
210             uint ret = NDalicPINVOKE.TapGestureDetector_GetMinimumTapsRequired(swigCPtr);
211             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
212             return ret;
213         }
214
215         public uint GetMaximumTapsRequired()
216         {
217             uint ret = NDalicPINVOKE.TapGestureDetector_GetMaximumTapsRequired(swigCPtr);
218             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
219             return ret;
220         }
221
222         internal TapGestureDetectedSignal DetectedSignal()
223         {
224             TapGestureDetectedSignal ret = new TapGestureDetectedSignal(NDalicPINVOKE.TapGestureDetector_DetectedSignal(swigCPtr), false);
225             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
226             return ret;
227         }
228
229     }
230
231 }