Ensuring that Registry.Unregister is called from the most derived class before the...
[platform/core/csapi/nui.git] / Tizen.NUI / src / public / BaseComponents / Scrollable.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 namespace Tizen.NUI.BaseComponents
18 {
19
20     using System;
21     using System.Runtime.InteropServices;
22
23     public class Scrollable : View
24     {
25         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
26
27         internal Scrollable(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Scrollable_SWIGUpcast(cPtr), cMemoryOwn)
28         {
29             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
30         }
31
32         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Scrollable obj)
33         {
34             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
35         }
36
37         protected override void Dispose(DisposeTypes type)
38         {
39             if (disposed)
40             {
41                 return;
42             }
43
44             if (type == DisposeTypes.Explicit)
45             {
46                 //Called by User
47                 //Release your own managed resources here.
48                 //You should release all of your own disposable objects here.
49
50             }
51
52             //Release your own unmanaged resources here.
53             //You should not access any managed member here except static instance.
54             //because the execution order of Finalizes is non-deterministic.
55
56             if (swigCPtr.Handle != global::System.IntPtr.Zero)
57             {
58                 if (swigCMemOwn)
59                 {
60                     swigCMemOwn = false;
61
62                     //Unreference this instance from Registry.
63                     Registry.Unregister(this);
64
65                     NDalicPINVOKE.delete_Scrollable(swigCPtr);
66                 }
67                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
68             }
69
70             base.Dispose(type);
71         }
72
73         public class StartedEventArgs : EventArgs
74         {
75             private Vector2 _vector2;
76
77             public Vector2 Vector2
78             {
79                 get
80                 {
81                     return _vector2;
82                 }
83                 set
84                 {
85                     _vector2 = value;
86                 }
87             }
88         }
89
90         public class UpdatedEventArgs : EventArgs
91         {
92             private Vector2 _vector2;
93
94             public Vector2 Vector2
95             {
96                 get
97                 {
98                     return _vector2;
99                 }
100                 set
101                 {
102                     _vector2 = value;
103                 }
104             }
105         }
106
107         public class CompletedEventArgs : EventArgs
108         {
109             private Vector2 _vector2;
110
111             public Vector2 Vector2
112             {
113                 get
114                 {
115                     return _vector2;
116                 }
117                 set
118                 {
119                     _vector2 = value;
120                 }
121             }
122         }
123
124         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
125         private delegate void StartedCallbackDelegate(IntPtr vector2);
126         private DaliEventHandler<object, StartedEventArgs> _scrollableStartedEventHandler;
127         private StartedCallbackDelegate _scrollableStartedCallbackDelegate;
128
129         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
130         private delegate void UpdatedCallbackDelegate(IntPtr vector2);
131         private DaliEventHandler<object, UpdatedEventArgs> _scrollableUpdatedEventHandler;
132         private UpdatedCallbackDelegate _scrollableUpdatedCallbackDelegate;
133
134         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
135         private delegate void CompletedCallbackDelegate(IntPtr vector2);
136         private DaliEventHandler<object, CompletedEventArgs> _scrollableCompletedEventHandler;
137         private CompletedCallbackDelegate _scrollableCompletedCallbackDelegate;
138
139         public event DaliEventHandler<object, StartedEventArgs> ScrollStarted
140         {
141             add
142             {
143                 lock (this)
144                 {
145                     // Restricted to only one listener
146                     if (_scrollableStartedEventHandler == null)
147                     {
148                         _scrollableStartedEventHandler += value;
149
150                         _scrollableStartedCallbackDelegate = new StartedCallbackDelegate(OnStarted);
151                         this.ScrollStartedSignal().Connect(_scrollableStartedCallbackDelegate);
152                     }
153                 }
154             }
155
156             remove
157             {
158                 lock (this)
159                 {
160                     if (_scrollableStartedEventHandler != null)
161                     {
162                         this.ScrollStartedSignal().Disconnect(_scrollableStartedCallbackDelegate);
163                     }
164
165                     _scrollableStartedEventHandler -= value;
166                 }
167             }
168         }
169
170         private void OnStarted(IntPtr vector2)
171         {
172             StartedEventArgs e = new StartedEventArgs();
173
174             // Populate all members of "e" (StartedEventArgs) with real data
175             e.Vector2 = Tizen.NUI.Vector2.GetVector2FromPtr(vector2);
176
177             if (_scrollableStartedEventHandler != null)
178             {
179                 //here we send all data to user event handlers
180                 _scrollableStartedEventHandler(this, e);
181             }
182
183         }
184
185         public event DaliEventHandler<object, UpdatedEventArgs> ScrollUpdated
186         {
187             add
188             {
189                 lock (this)
190                 {
191                     // Restricted to only one listener
192                     if (_scrollableUpdatedEventHandler == null)
193                     {
194                         _scrollableUpdatedEventHandler += value;
195
196                         _scrollableUpdatedCallbackDelegate = new UpdatedCallbackDelegate(OnUpdated);
197                         this.ScrollUpdatedSignal().Connect(_scrollableUpdatedCallbackDelegate);
198                     }
199                 }
200             }
201
202             remove
203             {
204                 lock (this)
205                 {
206                     if (_scrollableUpdatedEventHandler != null)
207                     {
208                         this.ScrollUpdatedSignal().Disconnect(_scrollableUpdatedCallbackDelegate);
209                     }
210
211                     _scrollableUpdatedEventHandler -= value;
212                 }
213             }
214         }
215
216         private void OnUpdated(IntPtr vector2)
217         {
218             UpdatedEventArgs e = new UpdatedEventArgs();
219
220             // Populate all members of "e" (UpdatedEventArgs) with real data
221             e.Vector2 = Tizen.NUI.Vector2.GetVector2FromPtr(vector2);
222
223             if (_scrollableUpdatedEventHandler != null)
224             {
225                 //here we send all data to user event handlers
226                 _scrollableUpdatedEventHandler(this, e);
227             }
228
229         }
230
231         public event DaliEventHandler<object, CompletedEventArgs> ScrollCompleted
232         {
233             add
234             {
235                 lock (this)
236                 {
237                     // Restricted to only one listener
238                     if (_scrollableCompletedEventHandler == null)
239                     {
240                         _scrollableCompletedEventHandler += value;
241
242                         _scrollableCompletedCallbackDelegate = new CompletedCallbackDelegate(OnCompleted);
243                         this.ScrollCompletedSignal().Connect(_scrollableCompletedCallbackDelegate);
244                     }
245                 }
246             }
247
248             remove
249             {
250                 lock (this)
251                 {
252                     if (_scrollableCompletedEventHandler != null)
253                     {
254                         this.ScrollCompletedSignal().Disconnect(_scrollableCompletedCallbackDelegate);
255                     }
256
257                     _scrollableCompletedEventHandler -= value;
258                 }
259             }
260         }
261
262         private void OnCompleted(IntPtr vector2)
263         {
264             CompletedEventArgs e = new CompletedEventArgs();
265
266             // Populate all members of "e" (CompletedEventArgs) with real data
267             e.Vector2 = Tizen.NUI.Vector2.GetVector2FromPtr(vector2);
268
269             if (_scrollableCompletedEventHandler != null)
270             {
271                 //here we send all data to user event handlers
272                 _scrollableCompletedEventHandler(this, e);
273             }
274
275         }
276
277
278         public class Property
279         {
280             public static readonly int OVERSHOOT_EFFECT_COLOR = NDalicPINVOKE.Scrollable_Property_OVERSHOOT_EFFECT_COLOR_get();
281             public static readonly int OVERSHOOT_ANIMATION_SPEED = NDalicPINVOKE.Scrollable_Property_OVERSHOOT_ANIMATION_SPEED_get();
282             public static readonly int OVERSHOOT_ENABLED = NDalicPINVOKE.Scrollable_Property_OVERSHOOT_ENABLED_get();
283             public static readonly int OVERSHOOT_SIZE = NDalicPINVOKE.Scrollable_Property_OVERSHOOT_SIZE_get();
284             public static readonly int SCROLL_TO_ALPHA_FUNCTION = NDalicPINVOKE.Scrollable_Property_SCROLL_TO_ALPHA_FUNCTION_get();
285             public static readonly int SCROLL_RELATIVE_POSITION = NDalicPINVOKE.Scrollable_Property_SCROLL_RELATIVE_POSITION_get();
286             public static readonly int SCROLL_POSITION_MIN = NDalicPINVOKE.Scrollable_Property_SCROLL_POSITION_MIN_get();
287             public static readonly int SCROLL_POSITION_MIN_X = NDalicPINVOKE.Scrollable_Property_SCROLL_POSITION_MIN_X_get();
288             public static readonly int SCROLL_POSITION_MIN_Y = NDalicPINVOKE.Scrollable_Property_SCROLL_POSITION_MIN_Y_get();
289             public static readonly int SCROLL_POSITION_MAX = NDalicPINVOKE.Scrollable_Property_SCROLL_POSITION_MAX_get();
290             public static readonly int SCROLL_POSITION_MAX_X = NDalicPINVOKE.Scrollable_Property_SCROLL_POSITION_MAX_X_get();
291             public static readonly int SCROLL_POSITION_MAX_Y = NDalicPINVOKE.Scrollable_Property_SCROLL_POSITION_MAX_Y_get();
292             public static readonly int CAN_SCROLL_VERTICAL = NDalicPINVOKE.Scrollable_Property_CAN_SCROLL_VERTICAL_get();
293             public static readonly int CAN_SCROLL_HORIZONTAL = NDalicPINVOKE.Scrollable_Property_CAN_SCROLL_HORIZONTAL_get();
294
295         }
296
297         public Scrollable() : this(NDalicPINVOKE.new_Scrollable__SWIG_0(), true)
298         {
299             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
300         }
301
302         private bool IsOvershootEnabled()
303         {
304             bool ret = NDalicPINVOKE.Scrollable_IsOvershootEnabled(swigCPtr);
305             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
306             return ret;
307         }
308
309         private void SetOvershootEnabled(bool enable)
310         {
311             NDalicPINVOKE.Scrollable_SetOvershootEnabled(swigCPtr, enable);
312             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
313         }
314
315         private void SetOvershootEffectColor(Vector4 color)
316         {
317             NDalicPINVOKE.Scrollable_SetOvershootEffectColor(swigCPtr, Vector4.getCPtr(color));
318             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
319         }
320
321         private Vector4 GetOvershootEffectColor()
322         {
323             Vector4 ret = new Vector4(NDalicPINVOKE.Scrollable_GetOvershootEffectColor(swigCPtr), true);
324             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325             return ret;
326         }
327
328         private void SetOvershootAnimationSpeed(float pixelsPerSecond)
329         {
330             NDalicPINVOKE.Scrollable_SetOvershootAnimationSpeed(swigCPtr, pixelsPerSecond);
331             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
332         }
333
334         private float GetOvershootAnimationSpeed()
335         {
336             float ret = NDalicPINVOKE.Scrollable_GetOvershootAnimationSpeed(swigCPtr);
337             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
338             return ret;
339         }
340
341         internal ScrollableSignal ScrollStartedSignal()
342         {
343             ScrollableSignal ret = new ScrollableSignal(NDalicPINVOKE.Scrollable_ScrollStartedSignal(swigCPtr), false);
344             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
345             return ret;
346         }
347
348         internal ScrollableSignal ScrollUpdatedSignal()
349         {
350             ScrollableSignal ret = new ScrollableSignal(NDalicPINVOKE.Scrollable_ScrollUpdatedSignal(swigCPtr), false);
351             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
352             return ret;
353         }
354
355         internal ScrollableSignal ScrollCompletedSignal()
356         {
357             ScrollableSignal ret = new ScrollableSignal(NDalicPINVOKE.Scrollable_ScrollCompletedSignal(swigCPtr), false);
358             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
359             return ret;
360         }
361
362         public Vector4 OvershootEffectColor
363         {
364             get
365             {
366                 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
367                 GetProperty(Scrollable.Property.OVERSHOOT_EFFECT_COLOR).Get(temp);
368                 return temp;
369             }
370             set
371             {
372                 SetProperty(Scrollable.Property.OVERSHOOT_EFFECT_COLOR, new Tizen.NUI.PropertyValue(value));
373             }
374         }
375         public float OvershootAnimationSpeed
376         {
377             get
378             {
379                 float temp = 0.0f;
380                 GetProperty(Scrollable.Property.OVERSHOOT_ANIMATION_SPEED).Get(out temp);
381                 return temp;
382             }
383             set
384             {
385                 SetProperty(Scrollable.Property.OVERSHOOT_ANIMATION_SPEED, new Tizen.NUI.PropertyValue(value));
386             }
387         }
388         public bool OvershootEnabled
389         {
390             get
391             {
392                 bool temp = false;
393                 GetProperty(Scrollable.Property.OVERSHOOT_ENABLED).Get(out temp);
394                 return temp;
395             }
396             set
397             {
398                 SetProperty(Scrollable.Property.OVERSHOOT_ENABLED, new Tizen.NUI.PropertyValue(value));
399             }
400         }
401         public Vector2 OvershootSize
402         {
403             get
404             {
405                 Vector2 temp = new Vector2(0.0f, 0.0f);
406                 GetProperty(Scrollable.Property.OVERSHOOT_SIZE).Get(temp);
407                 return temp;
408             }
409             set
410             {
411                 SetProperty(Scrollable.Property.OVERSHOOT_SIZE, new Tizen.NUI.PropertyValue(value));
412             }
413         }
414         public int ScrollToAlphaFunction
415         {
416             get
417             {
418                 int temp = 0;
419                 GetProperty(Scrollable.Property.SCROLL_TO_ALPHA_FUNCTION).Get(out temp);
420                 return temp;
421             }
422             set
423             {
424                 SetProperty(Scrollable.Property.SCROLL_TO_ALPHA_FUNCTION, new Tizen.NUI.PropertyValue(value));
425             }
426         }
427         public Vector2 ScrollRelativePosition
428         {
429             get
430             {
431                 Vector2 temp = new Vector2(0.0f, 0.0f);
432                 GetProperty(Scrollable.Property.SCROLL_RELATIVE_POSITION).Get(temp);
433                 return temp;
434             }
435             set
436             {
437                 SetProperty(Scrollable.Property.SCROLL_RELATIVE_POSITION, new Tizen.NUI.PropertyValue(value));
438             }
439         }
440         public Vector2 ScrollPositionMin
441         {
442             get
443             {
444                 Vector2 temp = new Vector2(0.0f, 0.0f);
445                 GetProperty(Scrollable.Property.SCROLL_POSITION_MIN).Get(temp);
446                 return temp;
447             }
448             set
449             {
450                 SetProperty(Scrollable.Property.SCROLL_POSITION_MIN, new Tizen.NUI.PropertyValue(value));
451             }
452         }
453         public Vector2 ScrollPositionMax
454         {
455             get
456             {
457                 Vector2 temp = new Vector2(0.0f, 0.0f);
458                 GetProperty(Scrollable.Property.SCROLL_POSITION_MAX).Get(temp);
459                 return temp;
460             }
461             set
462             {
463                 SetProperty(Scrollable.Property.SCROLL_POSITION_MAX, new Tizen.NUI.PropertyValue(value));
464             }
465         }
466         public bool CanScrollVertical
467         {
468             get
469             {
470                 bool temp = false;
471                 GetProperty(Scrollable.Property.CAN_SCROLL_VERTICAL).Get(out temp);
472                 return temp;
473             }
474             set
475             {
476                 SetProperty(Scrollable.Property.CAN_SCROLL_VERTICAL, new Tizen.NUI.PropertyValue(value));
477             }
478         }
479         public bool CanScrollHorizontal
480         {
481             get
482             {
483                 bool temp = false;
484                 GetProperty(Scrollable.Property.CAN_SCROLL_HORIZONTAL).Get(out temp);
485                 return temp;
486             }
487             set
488             {
489                 SetProperty(Scrollable.Property.CAN_SCROLL_HORIZONTAL, new Tizen.NUI.PropertyValue(value));
490             }
491         }
492
493     }
494
495 }