[NUI] Change all CallingConvention to `Cdecl`
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / Utility / ScrollViewEvent.cs
1 /*
2  * Copyright(c) 2021 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     public partial class ScrollView
28     {
29         private DaliEventHandler<object, SnapStartedEventArgs> scrollViewSnapStartedEventHandler;
30         private SnapStartedCallbackDelegate scrollViewSnapStartedCallbackDelegate;
31
32         [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
33         private delegate void SnapStartedCallbackDelegate(IntPtr data);
34
35         /// <summary>
36         /// SnapStarted can be used to subscribe or unsubscribe the event handler
37         /// The SnapStarted signal is emitted when the ScrollView has started to snap or flick (it tells the target
38         ///  position, scale, rotation for the snap or flick).
39         /// </summary>
40         [EditorBrowsable(EditorBrowsableState.Never)]
41         public event DaliEventHandler<object, SnapStartedEventArgs> SnapStarted
42         {
43             add
44             {
45                 // Restricted to only one listener
46                 if (scrollViewSnapStartedEventHandler == null)
47                 {
48                     scrollViewSnapStartedEventHandler += value;
49
50                     scrollViewSnapStartedCallbackDelegate = new SnapStartedCallbackDelegate(OnSnapStarted);
51                     ScrollViewSnapStartedSignal snapStarted = this.SnapStartedSignal();
52                     snapStarted?.Connect(scrollViewSnapStartedCallbackDelegate);
53                     snapStarted?.Dispose();
54                 }
55             }
56
57             remove
58             {
59                 if (scrollViewSnapStartedEventHandler != null)
60                 {
61                     ScrollViewSnapStartedSignal snapStarted = this.SnapStartedSignal();
62                     snapStarted?.Disconnect(scrollViewSnapStartedCallbackDelegate);
63                     snapStarted?.Dispose();
64                 }
65
66                 scrollViewSnapStartedEventHandler -= value;
67             }
68         }
69
70         internal ScrollViewSnapStartedSignal SnapStartedSignal()
71         {
72             ScrollViewSnapStartedSignal ret = new ScrollViewSnapStartedSignal(Interop.ScrollView.SnapStartedSignal(SwigCPtr), false);
73             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74             return ret;
75         }
76
77         // Callback for ScrollView SnapStarted signal
78         private void OnSnapStarted(IntPtr data)
79         {
80             SnapStartedEventArgs e = new SnapStartedEventArgs();
81
82             // Populate all members of "e" (SnapStartedEventArgs) with real data
83             e.SnapEventInfo = SnapEvent.GetSnapEventFromPtr(data);
84
85             if (scrollViewSnapStartedEventHandler != null)
86             {
87                 //here we send all data to user event handlers
88                 scrollViewSnapStartedEventHandler(this, e);
89             }
90         }
91
92         /// <summary>
93         /// Snaps signal event's data.
94         /// </summary>
95         [EditorBrowsable(EditorBrowsableState.Never)]
96         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
97         public class SnapEvent : Disposable
98         {
99             /// <summary>
100             /// swigCMemOwn
101             /// </summary>
102             [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
103             [EditorBrowsable(EditorBrowsableState.Never)]
104             protected bool swigCMemOwn;
105             private global::System.Runtime.InteropServices.HandleRef swigCPtr;
106
107             /// <summary>
108             /// Create an instance of SnapEvent.
109             /// </summary>
110             [EditorBrowsable(EditorBrowsableState.Never)]
111             public SnapEvent() : this(Interop.ScrollView.NewScrollViewSnapEvent(), true)
112             {
113                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
114             }
115
116             internal SnapEvent(global::System.IntPtr cPtr, bool cMemoryOwn)
117             {
118                 swigCMemOwn = cMemoryOwn;
119                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
120             }
121
122             /// <summary>
123             /// Scroll position.
124             /// </summary>
125             [EditorBrowsable(EditorBrowsableState.Never)]
126             public Vector2 position
127             {
128                 set
129                 {
130                     Interop.ScrollView.SnapEventPositionSet(swigCPtr, Vector2.getCPtr(value));
131                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
132                 }
133                 get
134                 {
135                     global::System.IntPtr cPtr = Interop.ScrollView.SnapEventPositionGet(swigCPtr);
136                     Vector2 ret = (cPtr == global::System.IntPtr.Zero) ? null : new Vector2(cPtr, false);
137                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
138                     return ret;
139                 }
140             }
141
142             /// <summary>
143             /// Scroll duration.
144             /// </summary>
145             [EditorBrowsable(EditorBrowsableState.Never)]
146             public float duration
147             {
148                 set
149                 {
150                     Interop.ScrollView.SnapEventDurationSet(swigCPtr, value);
151                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
152                 }
153                 get
154                 {
155                     float ret = Interop.ScrollView.SnapEventDurationGet(swigCPtr);
156                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw new InvalidOperationException("FATAL: get Exception", NDalicPINVOKE.SWIGPendingException.Retrieve());
157                     return ret;
158                 }
159             }
160
161             internal SnapType type
162             {
163                 set
164                 {
165                     Interop.ScrollView.SnapEventTypeSet(swigCPtr, (int)value);
166                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
167                 }
168                 get
169                 {
170                     SnapType ret = (SnapType)Interop.ScrollView.SnapEventTypeGet(swigCPtr);
171                     if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
172                     return ret;
173                 }
174             }
175
176             /// <summary>
177             /// Get SnapEvent From Ptr
178             /// </summary>
179             [EditorBrowsable(EditorBrowsableState.Never)]
180             public static SnapEvent GetSnapEventFromPtr(global::System.IntPtr cPtr)
181             {
182                 SnapEvent ret = new SnapEvent(cPtr, false);
183                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
184                 return ret;
185             }
186
187             /// <summary>
188             /// Dispose
189             /// </summary>
190             /// <param name="type">the dispose type</param>
191             [EditorBrowsable(EditorBrowsableState.Never)]
192             protected override void Dispose(DisposeTypes type)
193             {
194                 if (disposed)
195                 {
196                     return;
197                 }
198
199                 //Release your own unmanaged resources here.
200                 //You should not access any managed member here except static instance.
201                 //because the execution order of Finalizes is non-deterministic.
202
203                 if (swigCPtr.Handle != global::System.IntPtr.Zero)
204                 {
205                     if (swigCMemOwn)
206                     {
207                         swigCMemOwn = false;
208                         Interop.ScrollView.DeleteScrollViewSnapEvent(swigCPtr);
209                     }
210                     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
211                 }
212
213                 base.Dispose(type);
214             }
215
216         }
217
218         /// <summary>
219         /// Event arguments that passed via the SnapStarted signal.
220         /// </summary>
221         [EditorBrowsable(EditorBrowsableState.Never)]
222         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
223         public class SnapStartedEventArgs : EventArgs
224         {
225             private Tizen.NUI.ScrollView.SnapEvent snapEvent;
226
227             /// <summary>
228             /// SnapEventInfo is the SnapEvent information like snap or flick (it tells the target position, scale, rotation for the snap or flick).
229             /// </summary>
230             [EditorBrowsable(EditorBrowsableState.Never)]
231             public Tizen.NUI.ScrollView.SnapEvent SnapEventInfo
232             {
233                 get
234                 {
235                     return snapEvent;
236                 }
237                 set
238                 {
239                     snapEvent = value;
240                 }
241             }
242         }
243     }
244 }