/* * Copyright(c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ using System; using System.Runtime.InteropServices; using Tizen.NUI.BaseComponents; using System.ComponentModel; namespace Tizen.NUI { /// /// It tries to detect when the user moves two touch points towards or away from each other. /// /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public class PinchGestureDetector : GestureDetector { /// /// Creates an initialized PinchGestureDetector. /// /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public PinchGestureDetector() : this(Interop.PinchGesture.PinchGestureDetectorNew(), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } /// /// The copy constructor. /// /// A reference to the copied handle /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public PinchGestureDetector(PinchGestureDetector handle) : this(Interop.PinchGesture.NewPinchGestureDetector(PinchGestureDetector.getCPtr(handle)), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal PinchGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PinchGesture.PinchGestureDetectorUpcast(cPtr), cMemoryOwn) { } private DaliEventHandler detectedEventHandler; [UnmanagedFunctionPointer(CallingConvention.StdCall)] private delegate void DetectedCallbackType(IntPtr actor, IntPtr pinchGesture); private DetectedCallbackType detectedCallback; /// /// This signal is emitted when the specified pinch is detected on the attached view. /// /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public event DaliEventHandler Detected { add { if (detectedEventHandler == null) { detectedCallback = OnPinchGestureDetected; DetectedSignal().Connect(detectedCallback); } detectedEventHandler += value; } remove { detectedEventHandler -= value; if (detectedEventHandler == null && DetectedSignal().Empty() == false) { DetectedSignal().Disconnect(detectedCallback); } } } internal static PinchGestureDetector GetPinchGestureDetectorFromPtr(global::System.IntPtr cPtr) { PinchGestureDetector ret = new PinchGestureDetector(cPtr, false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal new static PinchGestureDetector DownCast(BaseHandle handle) { PinchGestureDetector ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as PinchGestureDetector; if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal PinchGestureDetector Assign(PinchGestureDetector rhs) { PinchGestureDetector ret = new PinchGestureDetector(Interop.PinchGesture.PinchGestureDetectorAssign(SwigCPtr, PinchGestureDetector.getCPtr(rhs)), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } internal PinchGestureDetectedSignal DetectedSignal() { PinchGestureDetectedSignal ret = new PinchGestureDetectedSignal(Interop.PinchGesture.PinchGestureDetectorDetectedSignal(SwigCPtr), false); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// This will not be public opened. [EditorBrowsable(EditorBrowsableState.Never)] protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr) { if (detectedCallback != null) { DetectedSignal().Disconnect(detectedCallback); } Interop.PinchGesture.DeletePinchGestureDetector(swigCPtr); } private void OnPinchGestureDetected(IntPtr actor, IntPtr pinchGesture) { if (detectedEventHandler != null) { DetectedEventArgs e = new DetectedEventArgs(); // Populate all members of "e" (DetectedEventArgs) with real data. e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View; if (null == e.View) { e.View = Registry.GetManagedBaseHandleFromRefObject(actor) as View; } e.PinchGesture = Tizen.NUI.PinchGesture.GetPinchGestureFromPtr(pinchGesture); //Here we send all data to user event handlers. detectedEventHandler(this, e); } } /// /// Event arguments that passed via the PinchGestureEvent signal. /// /// 5 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public class DetectedEventArgs : EventArgs { private View view; private PinchGesture pinchGesture; private bool handled = true; /// /// The attached view. /// /// 5 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public View View { get { return view; } set { view = value; } } /// /// The PinchGesture. /// /// 5 /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API. [EditorBrowsable(EditorBrowsableState.Never)] public PinchGesture PinchGesture { get { return pinchGesture; } set { pinchGesture = value; } } /// /// 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. /// [EditorBrowsable(EditorBrowsableState.Never)] public bool Handled { get => handled; set { handled = value; Interop.Actor.SetNeedGesturePropagation(View.getCPtr(view), !value); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } } } } }