Follow formatting NUI
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / UIComponents / ScrollViewEvent.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
18 using System;
19 using System.ComponentModel;
20 using System.Runtime.InteropServices;
21
22 namespace Tizen.NUI
23 {
24     /// <summary>
25     /// ScrollView contains views that can be scrolled manually (via touch).
26     /// </summary>
27     /// <since_tizen> 3 </since_tizen>
28     public partial class ScrollView
29     {
30         private DaliEventHandler<object, SnapStartedEventArgs> _scrollViewSnapStartedEventHandler;
31         private SnapStartedCallbackDelegate _scrollViewSnapStartedCallbackDelegate;
32
33         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
34         private delegate void SnapStartedCallbackDelegate(IntPtr data);
35
36         /// <summary>
37         /// SnapStarted can be used to subscribe or unsubscribe the event handler
38         /// The SnapStarted signal is emitted when the ScrollView has started to snap or flick (it tells the target
39         ///  position, scale, rotation for the snap or flick).
40         /// </summary>
41         /// <since_tizen> 3 </since_tizen>
42         /// This will be deprecated
43         [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
44         [EditorBrowsable(EditorBrowsableState.Never)]
45         public event DaliEventHandler<object, SnapStartedEventArgs> SnapStarted
46         {
47             add
48             {
49                 lock (this)
50                 {
51                     // Restricted to only one listener
52                     if (_scrollViewSnapStartedEventHandler == null)
53                     {
54                         _scrollViewSnapStartedEventHandler += value;
55
56                         _scrollViewSnapStartedCallbackDelegate = new SnapStartedCallbackDelegate(OnSnapStarted);
57                         this.SnapStartedSignal().Connect(_scrollViewSnapStartedCallbackDelegate);
58                     }
59                 }
60             }
61
62             remove
63             {
64                 lock (this)
65                 {
66                     if (_scrollViewSnapStartedEventHandler != null)
67                     {
68                         this.SnapStartedSignal().Disconnect(_scrollViewSnapStartedCallbackDelegate);
69                     }
70
71                     _scrollViewSnapStartedEventHandler -= value;
72                 }
73             }
74         }
75
76         internal ScrollViewSnapStartedSignal SnapStartedSignal()
77         {
78             ScrollViewSnapStartedSignal ret = new ScrollViewSnapStartedSignal(Interop.ScrollView.ScrollView_SnapStartedSignal(swigCPtr), false);
79             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
80             return ret;
81         }
82
83         // Callback for ScrollView SnapStarted signal
84         private void OnSnapStarted(IntPtr data)
85         {
86             SnapStartedEventArgs e = new SnapStartedEventArgs();
87
88             // Populate all members of "e" (SnapStartedEventArgs) with real data
89             e.SnapEventInfo = SnapEvent.GetSnapEventFromPtr(data);
90
91             if (_scrollViewSnapStartedEventHandler != null)
92             {
93                 //here we send all data to user event handlers
94                 _scrollViewSnapStartedEventHandler(this, e);
95             }
96         }
97
98         /// <summary>
99         /// Snaps signal event's data.
100         /// </summary>
101         /// <since_tizen> 3 </since_tizen>
102         /// This will be deprecated
103         [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
104         [EditorBrowsable(EditorBrowsableState.Never)]
105         public class SnapEvent : Disposable
106         {
107             /// <summary>
108             /// swigCMemOwn
109             /// </summary>
110             /// <since_tizen> 3 </since_tizen>
111             /// This will be deprecated
112             [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
113             [EditorBrowsable(EditorBrowsableState.Never)]
114             protected bool swigCMemOwn;
115             private global::System.Runtime.InteropServices.HandleRef swigCPtr;
116
117             /// <summary>
118             /// Create an instance of SnapEvent.
119             /// </summary>
120             /// <since_tizen> 3 </since_tizen>
121             /// This will be deprecated
122             [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
123             [EditorBrowsable(EditorBrowsableState.Never)]
124             public SnapEvent() : this(Interop.ScrollView.new_ScrollView_SnapEvent(), true)
125             {
126                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
127             }
128
129             internal SnapEvent(global::System.IntPtr cPtr, bool cMemoryOwn)
130             {
131                 swigCMemOwn = cMemoryOwn;
132                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
133             }
134
135             /// <summary>
136             /// Scroll position.
137             /// </summary>
138             /// <since_tizen> 3 </since_tizen>
139             /// This will be deprecated
140             [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
141             [EditorBrowsable(EditorBrowsableState.Never)]
142             public Vector2 position
143             {
144                 set
145                 {
146                     Interop.ScrollView.ScrollView_SnapEvent_position_set(swigCPtr, Vector2.getCPtr(value));
147                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
148                 }
149                 get
150                 {
151                     global::System.IntPtr cPtr = Interop.ScrollView.ScrollView_SnapEvent_position_get(swigCPtr);
152                     Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
153                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
154                     return ret;
155                 }
156             }
157
158             /// <summary>
159             /// Scroll duration.
160             /// </summary>
161             /// <since_tizen> 3 </since_tizen>
162             /// This will be deprecated
163             [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
164             [EditorBrowsable(EditorBrowsableState.Never)]
165             public float duration
166             {
167                 set
168                 {
169                     Interop.ScrollView.ScrollView_SnapEvent_duration_set(swigCPtr, value);
170                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171                 }
172                 get
173                 {
174                     float ret = Interop.ScrollView.ScrollView_SnapEvent_duration_get(swigCPtr);
175                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
176                     return ret;
177                 }
178             }
179
180             internal SnapType type
181             {
182                 set
183                 {
184                     Interop.ScrollView.ScrollView_SnapEvent_type_set(swigCPtr, (int)value);
185                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186                 }
187                 get
188                 {
189                     SnapType ret = (SnapType)Interop.ScrollView.ScrollView_SnapEvent_type_get(swigCPtr);
190                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
191                     return ret;
192                 }
193             }
194
195             /// <summary>
196             /// Get SnapEvent From Ptr
197             /// </summary>
198             /// <since_tizen> 3 </since_tizen>
199             /// This will be deprecated
200             [Obsolete("Deprecated in API6, Will be removed in API9, " +
201                 "Please use SnapStarted event instead!" +
202                 "IntPtr(native integer pointer) is supposed to be not used in Application!")]
203             [EditorBrowsable(EditorBrowsableState.Never)]
204             public static SnapEvent GetSnapEventFromPtr(global::System.IntPtr cPtr)
205             {
206                 SnapEvent ret = new SnapEvent(cPtr, false);
207                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
208                 return ret;
209             }
210
211             internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SnapEvent obj)
212             {
213                 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
214             }
215
216             /// <summary>
217             /// Dispose
218             /// </summary>
219             /// <param name="type">the dispose type</param>
220             /// <since_tizen> 3 </since_tizen>
221             /// This will be deprecated
222             [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
223             [EditorBrowsable(EditorBrowsableState.Never)]
224             protected override void Dispose(DisposeTypes type)
225             {
226                 if (disposed)
227                 {
228                     return;
229                 }
230
231                 //Release your own unmanaged resources here.
232                 //You should not access any managed member here except static instance.
233                 //because the execution order of Finalizes is non-deterministic.
234
235                 if (swigCPtr.Handle != global::System.IntPtr.Zero)
236                 {
237                     if (swigCMemOwn)
238                     {
239                         swigCMemOwn = false;
240                         Interop.ScrollView.delete_ScrollView_SnapEvent(swigCPtr);
241                     }
242                     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
243                 }
244
245                 base.Dispose(type);
246             }
247
248         }
249
250         /// <summary>
251         /// Event arguments that passed via the SnapStarted signal.
252         /// </summary>
253         /// <since_tizen> 3 </since_tizen>
254         /// This will be deprecated
255         [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
256         [EditorBrowsable(EditorBrowsableState.Never)]
257         public class SnapStartedEventArgs : EventArgs
258         {
259             private Tizen.NUI.ScrollView.SnapEvent _snapEvent;
260
261             /// <summary>
262             /// SnapEventInfo is the SnapEvent information like snap or flick (it tells the target position, scale, rotation for the snap or flick).
263             /// </summary>
264             /// <since_tizen> 3 </since_tizen>
265             /// This will be deprecated
266             [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
267             [EditorBrowsable(EditorBrowsableState.Never)]
268             public Tizen.NUI.ScrollView.SnapEvent SnapEventInfo
269             {
270                 get
271                 {
272                     return _snapEvent;
273                 }
274                 set
275                 {
276                     _snapEvent = value;
277                 }
278             }
279         }
280     }
281 }