0aacaa3c523132c58cd333614754f5f7e4f3f24c
[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                 // Restricted to only one listener
50                 if (_scrollViewSnapStartedEventHandler == null)
51                 {
52                     _scrollViewSnapStartedEventHandler += value;
53
54                     _scrollViewSnapStartedCallbackDelegate = new SnapStartedCallbackDelegate(OnSnapStarted);
55                     ScrollViewSnapStartedSignal snapStarted = this.SnapStartedSignal();
56                     snapStarted?.Connect(_scrollViewSnapStartedCallbackDelegate);
57                     snapStarted?.Dispose();
58                 }
59             }
60
61             remove
62             {
63                 if (_scrollViewSnapStartedEventHandler != null)
64                 {
65                     ScrollViewSnapStartedSignal snapStarted = this.SnapStartedSignal();
66                     snapStarted?.Disconnect(_scrollViewSnapStartedCallbackDelegate);
67                     snapStarted?.Dispose();
68                 }
69
70                 _scrollViewSnapStartedEventHandler -= value;
71             }
72         }
73
74         internal ScrollViewSnapStartedSignal SnapStartedSignal()
75         {
76             ScrollViewSnapStartedSignal ret = new ScrollViewSnapStartedSignal(Interop.ScrollView.SnapStartedSignal(SwigCPtr), false);
77             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
78             return ret;
79         }
80
81         // Callback for ScrollView SnapStarted signal
82         private void OnSnapStarted(IntPtr data)
83         {
84             SnapStartedEventArgs e = new SnapStartedEventArgs();
85
86             // Populate all members of "e" (SnapStartedEventArgs) with real data
87             e.SnapEventInfo = SnapEvent.GetSnapEventFromPtr(data);
88
89             if (_scrollViewSnapStartedEventHandler != null)
90             {
91                 //here we send all data to user event handlers
92                 _scrollViewSnapStartedEventHandler(this, e);
93             }
94         }
95
96         /// <summary>
97         /// Snaps signal event's data.
98         /// </summary>
99         /// <since_tizen> 3 </since_tizen>
100         /// This will be deprecated
101         [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
102         [EditorBrowsable(EditorBrowsableState.Never)]
103         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
104         public class SnapEvent : Disposable
105         {
106             /// <summary>
107             /// swigCMemOwn
108             /// </summary>
109             /// <since_tizen> 3 </since_tizen>
110             /// It will be removed in API9
111             // ToDo : will proceed ACR as private bool swigCMemOwn;
112             [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
113             [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
114             [EditorBrowsable(EditorBrowsableState.Never)]
115             protected bool swigCMemOwn;
116             private global::System.Runtime.InteropServices.HandleRef swigCPtr;
117
118             /// <summary>
119             /// Create an instance of SnapEvent.
120             /// </summary>
121             /// <since_tizen> 3 </since_tizen>
122             /// This will be deprecated
123             [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
124             [EditorBrowsable(EditorBrowsableState.Never)]
125             public SnapEvent() : this(Interop.ScrollView.NewScrollViewSnapEvent(), true)
126             {
127                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
128             }
129
130             internal SnapEvent(global::System.IntPtr cPtr, bool cMemoryOwn)
131             {
132                 swigCMemOwn = cMemoryOwn;
133                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
134             }
135
136             /// <summary>
137             /// Scroll position.
138             /// </summary>
139             /// <since_tizen> 3 </since_tizen>
140             /// This will be deprecated
141             [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
142             [EditorBrowsable(EditorBrowsableState.Never)]
143             public Vector2 position
144             {
145                 set
146                 {
147                     Interop.ScrollView.SnapEventPositionSet(swigCPtr, Vector2.getCPtr(value));
148                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
149                 }
150                 get
151                 {
152                     global::System.IntPtr cPtr = Interop.ScrollView.SnapEventPositionGet(swigCPtr);
153                     Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
154                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
155                     return ret;
156                 }
157             }
158
159             /// <summary>
160             /// Scroll duration.
161             /// </summary>
162             /// <since_tizen> 3 </since_tizen>
163             /// This will be deprecated
164             [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
165             [EditorBrowsable(EditorBrowsableState.Never)]
166             public float duration
167             {
168                 set
169                 {
170                     Interop.ScrollView.SnapEventDurationSet(swigCPtr, value);
171                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172                 }
173                 get
174                 {
175                     float ret = Interop.ScrollView.SnapEventDurationGet(swigCPtr);
176                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
177                     return ret;
178                 }
179             }
180
181             internal SnapType type
182             {
183                 set
184                 {
185                     Interop.ScrollView.SnapEventTypeSet(swigCPtr, (int)value);
186                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
187                 }
188                 get
189                 {
190                     SnapType ret = (SnapType)Interop.ScrollView.SnapEventTypeGet(swigCPtr);
191                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
192                     return ret;
193                 }
194             }
195
196             /// <summary>
197             /// Get SnapEvent From Ptr
198             /// </summary>
199             /// <since_tizen> 3 </since_tizen>
200             /// This will be deprecated
201             [Obsolete("Deprecated in API6, Will be removed in API9, " +
202                 "Please use SnapStarted event instead!" +
203                 "IntPtr(native integer pointer) is supposed to be not used in Application!")]
204             [EditorBrowsable(EditorBrowsableState.Never)]
205             public static SnapEvent GetSnapEventFromPtr(global::System.IntPtr cPtr)
206             {
207                 SnapEvent ret = new SnapEvent(cPtr, false);
208                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
209                 return ret;
210             }
211
212             internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SnapEvent obj)
213             {
214                 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
215             }
216
217             /// <summary>
218             /// Dispose
219             /// </summary>
220             /// <param name="type">the dispose type</param>
221             /// <since_tizen> 3 </since_tizen>
222             /// This will be deprecated
223             [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
224             [EditorBrowsable(EditorBrowsableState.Never)]
225             protected override void Dispose(DisposeTypes type)
226             {
227                 if (disposed)
228                 {
229                     return;
230                 }
231
232                 //Release your own unmanaged resources here.
233                 //You should not access any managed member here except static instance.
234                 //because the execution order of Finalizes is non-deterministic.
235
236                 if (swigCPtr.Handle != global::System.IntPtr.Zero)
237                 {
238                     if (swigCMemOwn)
239                     {
240                         swigCMemOwn = false;
241                         Interop.ScrollView.DeleteScrollViewSnapEvent(swigCPtr);
242                     }
243                     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
244                 }
245
246                 base.Dispose(type);
247             }
248
249         }
250
251         /// <summary>
252         /// Event arguments that passed via the SnapStarted signal.
253         /// </summary>
254         /// <since_tizen> 3 </since_tizen>
255         /// This will be deprecated
256         [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
257         [EditorBrowsable(EditorBrowsableState.Never)]
258         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
259         public class SnapStartedEventArgs : EventArgs
260         {
261             private Tizen.NUI.ScrollView.SnapEvent _snapEvent;
262
263             /// <summary>
264             /// SnapEventInfo is the SnapEvent information like snap or flick (it tells the target position, scale, rotation for the snap or flick).
265             /// </summary>
266             /// <since_tizen> 3 </since_tizen>
267             /// This will be deprecated
268             [Obsolete("Deprecated in API6; Will be removed in API9. Please use Tizen.NUI.Components")]
269             [EditorBrowsable(EditorBrowsableState.Never)]
270             public Tizen.NUI.ScrollView.SnapEvent SnapEventInfo
271             {
272                 get
273                 {
274                     return _snapEvent;
275                 }
276                 set
277                 {
278                     _snapEvent = value;
279                 }
280             }
281         }
282     }
283 }