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