Release 4.0.0-preview1-00051
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / internal / LongPressGestureDetector.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 LongPressGestureDetector : GestureDetector
25     {
26         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
27
28         internal LongPressGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.LongPressGestureDetector_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(LongPressGestureDetector 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_LongPressGestureDetector(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 LongPressGesture _longPressGesture;
75
76             public View View
77             {
78                 get
79                 {
80                     return _view;
81                 }
82                 set
83                 {
84                     _view = value;
85                 }
86             }
87
88             public LongPressGesture LongPressGesture
89             {
90                 get
91                 {
92                     return _longPressGesture;
93                 }
94                 set
95                 {
96                     _longPressGesture = value;
97                 }
98             }
99         }
100
101         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
102         private delegate void DetectedCallbackDelegate(IntPtr actor, IntPtr longPressGesture);
103         private DaliEventHandler<object, DetectedEventArgs> _longPressGestureEventHandler;
104         private DetectedCallbackDelegate _longPressGestureCallbackDelegate;
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 (_longPressGestureEventHandler == null)
115                     {
116                         _longPressGestureEventHandler += value;
117
118                         _longPressGestureCallbackDelegate = new DetectedCallbackDelegate(OnLongPressGestureDetected);
119                         this.DetectedSignal().Connect(_longPressGestureCallbackDelegate);
120                     }
121                 }
122             }
123
124             remove
125             {
126                 lock (this)
127                 {
128                     if (_longPressGestureEventHandler != null)
129                     {
130                         this.DetectedSignal().Disconnect(_longPressGestureCallbackDelegate);
131                     }
132
133                     _longPressGestureEventHandler -= value;
134                 }
135             }
136         }
137
138         private void OnLongPressGestureDetected(IntPtr actor, IntPtr longPressGesture)
139         {
140             DetectedEventArgs e = new DetectedEventArgs();
141
142             // Populate all members of "e" (LongPressGestureEventArgs) with real data
143             e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
144             e.LongPressGesture = Tizen.NUI.LongPressGesture.GetLongPressGestureFromPtr(longPressGesture);
145
146             if (_longPressGestureEventHandler != null)
147             {
148                 //here we send all data to user event handlers
149                 _longPressGestureEventHandler(this, e);
150             }
151
152         }
153
154
155         public static LongPressGestureDetector GetLongPressGestureDetectorFromPtr(global::System.IntPtr cPtr)
156         {
157             LongPressGestureDetector ret = new LongPressGestureDetector(cPtr, false);
158             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
159             return ret;
160         }
161
162
163         public LongPressGestureDetector() : this(NDalicPINVOKE.LongPressGestureDetector_New__SWIG_0(), true)
164         {
165             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
166
167         }
168         public LongPressGestureDetector(uint touchesRequired) : this(NDalicPINVOKE.LongPressGestureDetector_New__SWIG_1(touchesRequired), true)
169         {
170             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171
172         }
173         public LongPressGestureDetector(uint minTouches, uint maxTouches) : this(NDalicPINVOKE.LongPressGestureDetector_New__SWIG_2(minTouches, maxTouches), true)
174         {
175             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176
177         }
178         public new static LongPressGestureDetector DownCast(BaseHandle handle)
179         {
180             LongPressGestureDetector ret =  Registry.GetManagedBaseHandleFromNativePtr(handle) as LongPressGestureDetector;
181             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
182             return ret;
183         }
184
185         public LongPressGestureDetector(LongPressGestureDetector handle) : this(NDalicPINVOKE.new_LongPressGestureDetector__SWIG_1(LongPressGestureDetector.getCPtr(handle)), true)
186         {
187             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
188         }
189
190         public LongPressGestureDetector Assign(LongPressGestureDetector rhs)
191         {
192             LongPressGestureDetector ret = new LongPressGestureDetector(NDalicPINVOKE.LongPressGestureDetector_Assign(swigCPtr, LongPressGestureDetector.getCPtr(rhs)), false);
193             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
194             return ret;
195         }
196
197         public void SetTouchesRequired(uint touches)
198         {
199             NDalicPINVOKE.LongPressGestureDetector_SetTouchesRequired__SWIG_0(swigCPtr, touches);
200             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
201         }
202
203         public void SetTouchesRequired(uint minTouches, uint maxTouches)
204         {
205             NDalicPINVOKE.LongPressGestureDetector_SetTouchesRequired__SWIG_1(swigCPtr, minTouches, maxTouches);
206             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
207         }
208
209         public uint GetMinimumTouchesRequired()
210         {
211             uint ret = NDalicPINVOKE.LongPressGestureDetector_GetMinimumTouchesRequired(swigCPtr);
212             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213             return ret;
214         }
215
216         public uint GetMaximumTouchesRequired()
217         {
218             uint ret = NDalicPINVOKE.LongPressGestureDetector_GetMaximumTouchesRequired(swigCPtr);
219             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220             return ret;
221         }
222
223         internal LongPressGestureDetectedSignal DetectedSignal()
224         {
225             LongPressGestureDetectedSignal ret = new LongPressGestureDetectedSignal(NDalicPINVOKE.LongPressGestureDetector_DetectedSignal(swigCPtr), false);
226             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
227             return ret;
228         }
229
230     }
231
232 }