[NUI] Fix CA2000 Warnings
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / PinchGestureDetector.cs
1 /*
2  * Copyright(c) 2019 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 towards or away from each other.
26     /// </summary>
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
30     {
31         /// <summary>
32         /// Creates an initialized PinchGestureDetector.
33         /// </summary>
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)
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 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)
49         {
50             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
51         }
52
53         internal PinchGestureDetector(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.PinchGesture.PinchGestureDetectorUpcast(cPtr), cMemoryOwn)
54         {
55         }
56
57         private DaliEventHandler<object, DetectedEventArgs> _detectedEventHandler;
58         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
59         private delegate void DetectedCallbackType(IntPtr actor, IntPtr pinchGesture);
60         private DetectedCallbackType _detectedCallback;
61         private PinchGestureDetectedSignal detectedSignal;
62
63         /// <summary>
64         /// This signal is emitted when the specified pinch is detected on the attached view.
65         /// </summary>
66         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
67         [EditorBrowsable(EditorBrowsableState.Never)]
68         public event DaliEventHandler<object, DetectedEventArgs> Detected
69         {
70             add
71             {
72                 if (_detectedEventHandler == null)
73                 {
74                     _detectedCallback = OnPinchGestureDetected;
75                     detectedSignal = DetectedSignal();
76                     detectedSignal.Connect(_detectedCallback);
77                 }
78
79                 _detectedEventHandler += value;
80             }
81
82             remove
83             {
84                 _detectedEventHandler -= value;
85
86                 if (_detectedEventHandler == null && detectedSignal?.Empty() == false)
87                 {
88                     detectedSignal.Disconnect(_detectedCallback);
89                     detectedSignal.Dispose();
90                     detectedSignal = null;
91                 }
92             }
93         }
94
95
96         internal static PinchGestureDetector GetPinchGestureDetectorFromPtr(global::System.IntPtr cPtr)
97         {
98             PinchGestureDetector ret = new PinchGestureDetector(cPtr, false);
99             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
100             return ret;
101         }
102
103         internal new static PinchGestureDetector DownCast(BaseHandle handle)
104         {
105             PinchGestureDetector ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as PinchGestureDetector;
106             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
107             return ret;
108         }
109
110         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(PinchGestureDetector obj)
111         {
112             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.SwigCPtr;
113         }
114
115         internal PinchGestureDetector Assign(PinchGestureDetector rhs)
116         {
117             PinchGestureDetector ret = new PinchGestureDetector(Interop.PinchGesture.PinchGestureDetectorAssign(SwigCPtr, PinchGestureDetector.getCPtr(rhs)), false);
118             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
119             return ret;
120         }
121
122         internal PinchGestureDetectedSignal DetectedSignal()
123         {
124             PinchGestureDetectedSignal ret = new PinchGestureDetectedSignal(Interop.PinchGesture.PinchGestureDetectorDetectedSignal(SwigCPtr), false);
125             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
126             return ret;
127         }
128
129         /// This will not be public opened.
130         [EditorBrowsable(EditorBrowsableState.Never)]
131         protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
132         {
133             if (_detectedCallback != null)
134             {
135                 detectedSignal?.Disconnect(_detectedCallback);
136                 detectedSignal?.Dispose();
137             }
138
139             Interop.PinchGesture.DeletePinchGestureDetector(swigCPtr);
140         }
141
142         private void OnPinchGestureDetected(IntPtr actor, IntPtr pinchGesture)
143         {
144             DetectedEventArgs e = new DetectedEventArgs();
145
146             // Populate all members of "e" (DetectedEventArgs) with real data.
147             e.View = Registry.GetManagedBaseHandleFromNativePtr(actor) as View;
148             if (null == e.View)
149             {
150                 e.View = Registry.GetManagedBaseHandleFromRefObject(actor) as View;
151             }
152
153             e.PinchGesture = Tizen.NUI.PinchGesture.GetPinchGestureFromPtr(pinchGesture);
154
155             if (_detectedEventHandler != null)
156             {
157                 //Here we send all data to user event handlers.
158                 _detectedEventHandler(this, e);
159             }
160         }
161
162         /// <summary>
163         /// Event arguments that passed via the PinchGestureEvent signal.
164         /// </summary>
165         /// <since_tizen> 5 </since_tizen>
166         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
167         [EditorBrowsable(EditorBrowsableState.Never)]
168         public class DetectedEventArgs : EventArgs
169         {
170             private View _view;
171             private PinchGesture _pinchGesture;
172
173             /// <summary>
174             /// The attached view.
175             /// </summary>
176             /// <since_tizen> 5 </since_tizen>
177             /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
178             [EditorBrowsable(EditorBrowsableState.Never)]
179             public View View
180             {
181                 get
182                 {
183                     return _view;
184                 }
185                 set
186                 {
187                     _view = value;
188                 }
189             }
190
191             /// <summary>
192             /// The PinchGesture.
193             /// </summary>
194             /// <since_tizen> 5 </since_tizen>
195             /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
196             [EditorBrowsable(EditorBrowsableState.Never)]
197             public PinchGesture PinchGesture
198             {
199                 get
200                 {
201                     return _pinchGesture;
202                 }
203                 set
204                 {
205                     _pinchGesture = value;
206                 }
207             }
208         }
209     }
210 }