[NUI] Change all CallingConvention to `Cdecl`
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Events / RotationGestureDetector.cs
1 /*
2  * Copyright(c) 2021 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 using System;
18 using System.Runtime.InteropServices;
19 using Tizen.NUI.BaseComponents;
20 using System.ComponentModel;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// It tries to detect when the user moves two touch points in a circular motion.
26     /// </summary>
27     /// This will be made public in the next tizen release after an ACR is done. Till then, it needs to be hidden as an inhouse API.
28     [EditorBrowsable(EditorBrowsableState.Never)]
29     public class RotationGestureDetector : GestureDetector
30     {
31         /// <summary>
32         /// Creates an initialized RotationGestureDetector.
33         /// </summary>
34         /// This will be made public in the next tizen release after an ACR is done. Till then, it needs to be hidden as an inhouse API.
35         [EditorBrowsable(EditorBrowsableState.Never)]
36         public RotationGestureDetector() : this(Interop.RotationGesture.RotationGestureDetectorNew(), true)
37         {
38             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
39
40         }
41
42         /// <summary>
43         /// The copy constructor.
44         /// </summary>
45         /// <param name="handle">A reference to the copied handle</param>
46         /// This will be made public in the next tizen release after an ACR is done. Till then, it needs to be hidden as an inhouse API.
47         [EditorBrowsable(EditorBrowsableState.Never)]
48         public RotationGestureDetector(RotationGestureDetector handle) : this(Interop.RotationGesture.NewRotationGestureDetector(RotationGestureDetector.getCPtr(handle)), true)
49         {
50             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
51         }
52
53         internal RotationGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.RotationGesture.RotationGestureDetectorUpcast(cPtr), cMemoryOwn)
54         {
55         }
56
57         private DaliEventHandler<object, DetectedEventArgs> detectedEventHandler;
58         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
59         private delegate void DetectedCallbackType(IntPtr actor, IntPtr rotationGesture);
60         private DetectedCallbackType detectedCallback;
61
62         /// <summary>
63         /// This signal is emitted when the specified rotation is detected on the attached view.
64         /// </summary>
65         /// This will be made public in the next tizen release after an ACR is done. Till then, it needs to be hidden as an inhouse API.
66         [EditorBrowsable(EditorBrowsableState.Never)]
67         public event DaliEventHandler<object, DetectedEventArgs> Detected
68         {
69             add
70             {
71                 if (detectedEventHandler == null)
72                 {
73                     detectedCallback = OnRotationGestureDetected;
74                     DetectedSignal().Connect(detectedCallback);
75                 }
76
77                 detectedEventHandler += value;
78             }
79
80             remove
81             {
82                 detectedEventHandler -= value;
83
84                 if (detectedEventHandler == null && DetectedSignal().Empty() == false)
85                 {
86                     DetectedSignal().Disconnect(detectedCallback);
87                 }
88             }
89         }
90
91
92         internal static RotationGestureDetector GetRotationGestureDetectorFromPtr(global::System.IntPtr cPtr)
93         {
94             RotationGestureDetector ret = new RotationGestureDetector(cPtr, false);
95             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
96             return ret;
97         }
98
99         internal new static RotationGestureDetector DownCast(BaseHandle handle)
100         {
101             RotationGestureDetector ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as RotationGestureDetector;
102             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
103             return ret;
104         }
105
106         internal RotationGestureDetector Assign(RotationGestureDetector rhs)
107         {
108             RotationGestureDetector ret = new RotationGestureDetector(Interop.RotationGesture.RotationGestureDetectorAssign(SwigCPtr, RotationGestureDetector.getCPtr(rhs)), false);
109             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
110             return ret;
111         }
112
113         internal RotationGestureDetectedSignal DetectedSignal()
114         {
115             RotationGestureDetectedSignal ret = new RotationGestureDetectedSignal(Interop.RotationGesture.RotationGestureDetectorDetectedSignal(SwigCPtr), false);
116             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
117             return ret;
118         }
119
120         /// <summary>
121         /// override it to clean-up your own resources.
122         /// </summary>
123         /// <param name="type"></param>
124         [EditorBrowsable(EditorBrowsableState.Never)]
125         protected override void Dispose(DisposeTypes type)
126         {
127             if (disposed)
128             {
129                 return;
130             }
131
132             if (type == DisposeTypes.Explicit)
133             {
134                 //Called by User
135                 //Release your own managed resources here.
136                 //You should release all of your own disposable objects here.
137             }
138
139             //Release your own unmanaged resources here.
140             //You should not access any managed member here except static instance.
141             //because the execution order of Finalizes is non-deterministic.
142
143             if (HasBody())
144             {
145                 if (detectedCallback != null)
146                 {
147                     using RotationGestureDetectedSignal signal = new RotationGestureDetectedSignal(Interop.RotationGesture.RotationGestureDetectorDetectedSignal(GetBaseHandleCPtrHandleRef), false);
148                     signal?.Disconnect(detectedCallback);
149                     detectedCallback = null;
150                 }
151             }
152             base.Dispose(type);
153         }
154
155         /// This will not be public opened.
156         [EditorBrowsable(EditorBrowsableState.Never)]
157         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
158         {
159             Interop.RotationGesture.DeleteRotationGestureDetector(swigCPtr);
160         }
161
162         private void OnRotationGestureDetected(IntPtr actor, IntPtr rotationGesture)
163         {
164             if (detectedEventHandler != null)
165             {
166                 DetectedEventArgs e = new DetectedEventArgs();
167
168                 // Populate all members of "e" (DetectedEventArgs) with real data.
169                 e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
170                 if (null == e.View)
171                 {
172                     e.View = Registry.GetManagedBaseHandleFromRefObject(actor) as View;
173                 }
174
175                 // If DispatchGestureEvents is false, no gesture events are dispatched.
176                 if (e.View != null && e.View.DispatchGestureEvents == false)
177                 {
178                     return;
179                 }
180
181                 e.RotationGesture = Tizen.NUI.RotationGesture.GetRotationGestureFromPtr(rotationGesture);
182                 //Here we send all data to user event handlers.
183                 detectedEventHandler(this, e);
184             }
185         }
186
187         /// <summary>
188         /// Event arguments that passed via the RotationGestureEvent signal.
189         /// </summary>
190         /// <since_tizen> 5 </since_tizen>
191         /// This will be made public in the next tizen release after an ACR is done. Till then, it needs to be hidden as an inhouse API.
192         [EditorBrowsable(EditorBrowsableState.Never)]
193         public class DetectedEventArgs : EventArgs
194         {
195             private View view;
196             private RotationGesture rotationGesture;
197             private bool handled = true;
198
199             /// <summary>
200             /// The attached view.
201             /// </summary>
202             /// <since_tizen> 5 </since_tizen>
203             /// This will be made public in the next tizen release after an ACR is done. Till then, it needs to be hidden as an inhouse API.
204             [EditorBrowsable(EditorBrowsableState.Never)]
205             public View View
206             {
207                 get
208                 {
209                     return view;
210                 }
211                 set
212                 {
213                     view = value;
214                 }
215             }
216
217             /// <summary>
218             /// The RotationGesture.
219             /// </summary>
220             /// <since_tizen> 5 </since_tizen>
221             /// This will be made public in the next tizen release after an ACR is done. Till then, it needs to be hidden as an inhouse API.
222             [EditorBrowsable(EditorBrowsableState.Never)]
223             public RotationGesture RotationGesture
224             {
225                 get
226                 {
227                     return rotationGesture;
228                 }
229                 set
230                 {
231                     rotationGesture = value;
232                 }
233             }
234
235             /// <summary>
236             /// Gets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing.
237             /// </summary>
238             [EditorBrowsable(EditorBrowsableState.Never)]
239             public bool Handled
240             {
241                 get => handled;
242                 set
243                 {
244                     handled = value;
245                     Interop.Actor.SetNeedGesturePropagation(View.getCPtr(view), !value);
246                     if (NDalicPINVOKE.SWIGPendingException.Pending)
247                         throw NDalicPINVOKE.SWIGPendingException.Retrieve();
248                 }
249             }
250         }
251
252     }
253
254 }