2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.Runtime.InteropServices;
19 using Tizen.NUI.BaseComponents;
20 using System.ComponentModel;
25 /// It tries to detect when the user moves two touch points towards or away from each other.
27 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public class PinchGestureDetector : GestureDetector
32 /// Creates an initialized PinchGestureDetector.
34 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
35 [EditorBrowsable(EditorBrowsableState.Never)]
36 public PinchGestureDetector() : this(Interop.PinchGesture.PinchGestureDetectorNew(), true)
38 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
43 /// The copy constructor.
45 /// <param name="handle">A reference to the copied handle</param>
46 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
47 [EditorBrowsable(EditorBrowsableState.Never)]
48 public PinchGestureDetector(PinchGestureDetector handle) : this(Interop.PinchGesture.NewPinchGestureDetector(PinchGestureDetector.getCPtr(handle)), true)
50 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
53 internal PinchGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PinchGesture.PinchGestureDetectorUpcast(cPtr), cMemoryOwn)
57 private DaliEventHandler<object, DetectedEventArgs> detectedEventHandler;
58 [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
59 private delegate void DetectedCallbackType(IntPtr actor, IntPtr pinchGesture);
60 private DetectedCallbackType detectedCallback;
63 /// This signal is emitted when the specified pinch is detected on the attached view.
65 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
66 [EditorBrowsable(EditorBrowsableState.Never)]
67 public event DaliEventHandler<object, DetectedEventArgs> Detected
71 if (detectedEventHandler == null)
73 detectedCallback = OnPinchGestureDetected;
74 DetectedSignal().Connect(detectedCallback);
77 detectedEventHandler += value;
82 detectedEventHandler -= value;
84 if (detectedEventHandler == null && DetectedSignal().Empty() == false)
86 DetectedSignal().Disconnect(detectedCallback);
92 internal static PinchGestureDetector GetPinchGestureDetectorFromPtr(global::System.IntPtr cPtr)
94 PinchGestureDetector ret = new PinchGestureDetector(cPtr, false);
95 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
99 internal new static PinchGestureDetector DownCast(BaseHandle handle)
101 PinchGestureDetector ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as PinchGestureDetector;
102 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
106 internal PinchGestureDetector Assign(PinchGestureDetector rhs)
108 PinchGestureDetector ret = new PinchGestureDetector(Interop.PinchGesture.PinchGestureDetectorAssign(SwigCPtr, PinchGestureDetector.getCPtr(rhs)), false);
109 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
113 internal PinchGestureDetectedSignal DetectedSignal()
115 PinchGestureDetectedSignal ret = new PinchGestureDetectedSignal(Interop.PinchGesture.PinchGestureDetectorDetectedSignal(SwigCPtr), false);
116 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
121 /// override it to clean-up your own resources.
123 /// <param name="type"></param>
124 [EditorBrowsable(EditorBrowsableState.Never)]
125 protected override void Dispose(DisposeTypes type)
132 if (type == DisposeTypes.Explicit)
135 //Release your own managed resources here.
136 //You should release all of your own disposable objects here.
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.
145 if (detectedCallback != null)
147 using PinchGestureDetectedSignal signal = new PinchGestureDetectedSignal(Interop.PinchGesture.PinchGestureDetectorDetectedSignal(GetBaseHandleCPtrHandleRef), false);
148 signal?.Disconnect(detectedCallback);
149 detectedCallback = null;
155 /// This will not be public opened.
156 [EditorBrowsable(EditorBrowsableState.Never)]
157 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
159 Interop.PinchGesture.DeletePinchGestureDetector(swigCPtr);
162 private void OnPinchGestureDetected(IntPtr actor, IntPtr pinchGesture)
164 if (detectedEventHandler != null)
166 DetectedEventArgs e = new DetectedEventArgs();
168 // Populate all members of "e" (DetectedEventArgs) with real data.
169 e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
172 e.View = Registry.GetManagedBaseHandleFromRefObject(actor) as View;
175 // If DispatchGestureEvents is false, no gesture events are dispatched.
176 if (e.View != null && e.View.DispatchGestureEvents == false)
181 e.PinchGesture = Tizen.NUI.PinchGesture.GetPinchGestureFromPtr(pinchGesture);
182 //Here we send all data to user event handlers.
183 detectedEventHandler(this, e);
188 /// Event arguments that passed via the PinchGestureEvent signal.
190 /// <since_tizen> 5 </since_tizen>
191 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
192 [EditorBrowsable(EditorBrowsableState.Never)]
193 public class DetectedEventArgs : EventArgs
196 private PinchGesture pinchGesture;
197 private bool handled = true;
200 /// The attached view.
202 /// <since_tizen> 5 </since_tizen>
203 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
204 [EditorBrowsable(EditorBrowsableState.Never)]
218 /// The PinchGesture.
220 /// <since_tizen> 5 </since_tizen>
221 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
222 [EditorBrowsable(EditorBrowsableState.Never)]
223 public PinchGesture PinchGesture
231 pinchGesture = value;
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.
238 [EditorBrowsable(EditorBrowsableState.Never)]
245 Interop.Actor.SetNeedGesturePropagation(View.getCPtr(view), !value);
246 if (NDalicPINVOKE.SWIGPendingException.Pending)
247 throw NDalicPINVOKE.SWIGPendingException.Retrieve();