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