[NUI] Fix Tizen.NUI.Samples build errors
[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.StdCall)]
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             internal static global::System.Runtime.InteropServices.HandleRef getCPtr(SnapEvent obj)
188             {
189                 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
190             }
191
192             /// <summary>
193             /// Dispose
194             /// </summary>
195             /// <param name="type">the dispose type</param>
196             [EditorBrowsable(EditorBrowsableState.Never)]
197             protected override void Dispose(DisposeTypes type)
198             {
199                 if (disposed)
200                 {
201                     return;
202                 }
203
204                 //Release your own unmanaged resources here.
205                 //You should not access any managed member here except static instance.
206                 //because the execution order of Finalizes is non-deterministic.
207
208                 if (swigCPtr.Handle != global::System.IntPtr.Zero)
209                 {
210                     if (swigCMemOwn)
211                     {
212                         swigCMemOwn = false;
213                         Interop.ScrollView.DeleteScrollViewSnapEvent(swigCPtr);
214                     }
215                     swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
216                 }
217
218                 base.Dispose(type);
219             }
220
221         }
222
223         /// <summary>
224         /// Event arguments that passed via the SnapStarted signal.
225         /// </summary>
226         [EditorBrowsable(EditorBrowsableState.Never)]
227         [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
228         public class SnapStartedEventArgs : EventArgs
229         {
230             private Tizen.NUI.ScrollView.SnapEvent snapEvent;
231
232             /// <summary>
233             /// SnapEventInfo is the SnapEvent information like snap or flick (it tells the target position, scale, rotation for the snap or flick).
234             /// </summary>
235             [EditorBrowsable(EditorBrowsableState.Never)]
236             public Tizen.NUI.ScrollView.SnapEvent SnapEventInfo
237             {
238                 get
239                 {
240                     return snapEvent;
241                 }
242                 set
243                 {
244                     snapEvent = value;
245                 }
246             }
247         }
248     }
249 }