[Tizen] Ensuring that Registry.Unregister is called from the most derived class befor...
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / UIComponents / ScrollBar.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.UIComponents
18 {
19
20     using System;
21     using System.Runtime.InteropServices;
22     using Tizen.NUI.BaseComponents;
23
24     /// <summary>
25     /// ScrollBar is a UI component that can be linked to the scrollable objects
26     /// indicating the current scroll position of the scrollable object.<br>
27     /// </summary>
28     public class ScrollBar : View
29     {
30         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31
32         internal ScrollBar(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.ScrollBar_SWIGUpcast(cPtr), cMemoryOwn)
33         {
34             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
35         }
36
37         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ScrollBar obj)
38         {
39             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
40         }
41
42         /// <summary>
43         /// To make ScrollBar instance be disposed.
44         /// </summary>
45         protected override void Dispose(DisposeTypes type)
46         {
47             if (disposed)
48             {
49                 return;
50             }
51
52             if(type == DisposeTypes.Explicit)
53             {
54                 //Called by User
55                 //Release your own managed resources here.
56                 //You should release all of your own disposable objects here.
57             }
58
59             //Release your own unmanaged resources here.
60             //You should not access any managed member here except static instance.
61             //because the execution order of Finalizes is non-deterministic.
62
63             if (swigCPtr.Handle != global::System.IntPtr.Zero)
64             {
65                 if (swigCMemOwn)
66                 {
67                     swigCMemOwn = false;
68
69                     //Unreference this instance from Registry.
70                     Registry.Unregister(this);
71
72                     NDalicPINVOKE.delete_ScrollBar(swigCPtr);
73                 }
74                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
75             }
76
77             base.Dispose(type);
78         }
79
80         /// <summary>
81         /// Event arguments that passed via PanFinished event
82         /// </summary>
83         public class PanFinishedEventArgs : EventArgs
84         {
85         }
86
87         /// <summary>
88         /// Event arguments that passed via ScrollPositionIntervalReached event
89         /// </summary>
90         public class ScrollIntervalEventArgs : EventArgs
91         {
92             private float _currentScrollPosition;
93
94             /// <summary>
95             /// current scroll position of the scrollable content
96             /// </summary>
97             public float CurrentScrollPosition
98             {
99                 get
100                 {
101                     return _currentScrollPosition;
102                 }
103                 set
104                 {
105                     _currentScrollPosition = value;
106                 }
107             }
108         }
109
110         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
111         private delegate void PanFinishedEventCallbackDelegate();
112         private EventHandler<PanFinishedEventArgs> _scrollBarPanFinishedEventHandler;
113         private PanFinishedEventCallbackDelegate _scrollBarPanFinishedEventCallbackDelegate;
114
115         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
116         private delegate void ScrollPositionIntervalReachedEventCallbackDelegate();
117         private EventHandler<ScrollIntervalEventArgs> _scrollBarScrollPositionIntervalReachedEventHandler;
118         private ScrollPositionIntervalReachedEventCallbackDelegate _scrollBarScrollPositionIntervalReachedEventCallbackDelegate;
119
120         /// <summary>
121         /// Event emitted when panning is finished on the scroll indicator.
122         /// </summary>
123         public event EventHandler<PanFinishedEventArgs> PanFinished
124         {
125             add
126             {
127                 if (_scrollBarPanFinishedEventHandler == null)
128                 {
129                     _scrollBarPanFinishedEventCallbackDelegate = (OnScrollBarPanFinished);
130                     PanFinishedSignal().Connect(_scrollBarPanFinishedEventCallbackDelegate);
131                 }
132                 _scrollBarPanFinishedEventHandler += value;
133             }
134             remove
135             {
136                 _scrollBarPanFinishedEventHandler -= value;
137                 if (_scrollBarPanFinishedEventHandler == null && PanFinishedSignal().Empty() == false)
138                 {
139                     PanFinishedSignal().Disconnect(_scrollBarPanFinishedEventCallbackDelegate);
140                 }
141             }
142         }
143
144         // Callback for ScrollBar PanFinishedSignal
145         private void OnScrollBarPanFinished()
146         {
147             PanFinishedEventArgs e = new PanFinishedEventArgs();
148
149             if (_scrollBarPanFinishedEventHandler != null)
150             {
151                 //here we send all data to user event handlers
152                 _scrollBarPanFinishedEventHandler(this, e);
153             }
154         }
155
156
157         /// <summary>
158         /// Event emitted when the current scroll position of the scrollable content
159         /// </summary>
160         public event EventHandler<ScrollIntervalEventArgs> ScrollInterval
161         {
162             add
163             {
164                 if (_scrollBarScrollPositionIntervalReachedEventHandler == null)
165                 {
166                     _scrollBarScrollPositionIntervalReachedEventCallbackDelegate = (OnScrollBarScrollPositionIntervalReached);
167                     ScrollPositionIntervalReachedSignal().Connect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
168                 }
169                 _scrollBarScrollPositionIntervalReachedEventHandler += value;
170             }
171             remove
172             {
173                 _scrollBarScrollPositionIntervalReachedEventHandler -= value;
174                 if (_scrollBarScrollPositionIntervalReachedEventHandler == null && ScrollPositionIntervalReachedSignal().Empty() == false)
175                 {
176                     ScrollPositionIntervalReachedSignal().Disconnect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
177                 }
178             }
179         }
180
181         // Callback for ScrollBar ScrollPositionIntervalReachedSignal
182         private void OnScrollBarScrollPositionIntervalReached()
183         {
184             ScrollIntervalEventArgs e = new ScrollIntervalEventArgs();
185
186             if (_scrollBarScrollPositionIntervalReachedEventHandler != null)
187             {
188                 //here we send all data to user event handlers
189                 _scrollBarScrollPositionIntervalReachedEventHandler(this, e);
190             }
191         }
192
193
194         internal class Property
195         {
196             internal static readonly int SCROLL_DIRECTION = NDalicPINVOKE.ScrollBar_Property_SCROLL_DIRECTION_get();
197             internal static readonly int INDICATOR_HEIGHT_POLICY = NDalicPINVOKE.ScrollBar_Property_INDICATOR_HEIGHT_POLICY_get();
198             internal static readonly int INDICATOR_FIXED_HEIGHT = NDalicPINVOKE.ScrollBar_Property_INDICATOR_FIXED_HEIGHT_get();
199             internal static readonly int INDICATOR_SHOW_DURATION = NDalicPINVOKE.ScrollBar_Property_INDICATOR_SHOW_DURATION_get();
200             internal static readonly int INDICATOR_HIDE_DURATION = NDalicPINVOKE.ScrollBar_Property_INDICATOR_HIDE_DURATION_get();
201             internal static readonly int SCROLL_POSITION_INTERVALS = NDalicPINVOKE.ScrollBar_Property_SCROLL_POSITION_INTERVALS_get();
202             internal static readonly int INDICATOR_MINIMUM_HEIGHT = NDalicPINVOKE.ScrollBar_Property_INDICATOR_MINIMUM_HEIGHT_get();
203             internal static readonly int INDICATOR_START_PADDING = NDalicPINVOKE.ScrollBar_Property_INDICATOR_START_PADDING_get();
204             internal static readonly int INDICATOR_END_PADDING = NDalicPINVOKE.ScrollBar_Property_INDICATOR_END_PADDING_get();
205         }
206
207         /// <summary>
208         /// Creates an initialized ScrollBar.
209         /// </summary>
210         /// <param name="direction">The direction of scroll bar (either vertically or horizontally)</param>
211         public ScrollBar(ScrollBar.Direction direction) : this(NDalicPINVOKE.ScrollBar_New__SWIG_0((int)direction), true)
212         {
213             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
214         }
215
216         /// <summary>
217         /// Creates an uninitialized ScrollBar
218         /// </summary>
219         public ScrollBar() : this(NDalicPINVOKE.ScrollBar_New__SWIG_1(), true)
220         {
221             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
222
223         }
224         internal ScrollBar(ScrollBar scrollBar) : this(NDalicPINVOKE.new_ScrollBar__SWIG_1(ScrollBar.getCPtr(scrollBar)), true)
225         {
226             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
227         }
228
229         [Obsolete("Please do not use! this will be deprecated")]
230         public new static ScrollBar DownCast(BaseHandle handle)
231         {
232             ScrollBar ret = new ScrollBar(NDalicPINVOKE.ScrollBar_DownCast(BaseHandle.getCPtr(handle)), true);
233             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234             return ret;
235         }
236
237         internal void SetScrollPropertySource(Animatable handle, int propertyScrollPosition, int propertyMinScrollPosition, int propertyMaxScrollPosition, int propertyScrollContentSize)
238         {
239             NDalicPINVOKE.ScrollBar_SetScrollPropertySource(swigCPtr, Animatable.getCPtr(handle), propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
240             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
241         }
242
243         internal void SetScrollIndicator(View indicator)
244         {
245             NDalicPINVOKE.ScrollBar_SetScrollIndicator(swigCPtr, View.getCPtr(indicator));
246             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
247         }
248
249         internal View GetScrollIndicator()
250         {
251             View ret = new View(NDalicPINVOKE.ScrollBar_GetScrollIndicator(swigCPtr), true);
252             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253             return ret;
254         }
255
256         internal void SetScrollDirection(ScrollBar.Direction direction)
257         {
258             NDalicPINVOKE.ScrollBar_SetScrollDirection(swigCPtr, (int)direction);
259             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260         }
261
262         internal ScrollBar.Direction GetScrollDirection()
263         {
264             ScrollBar.Direction ret = (ScrollBar.Direction)NDalicPINVOKE.ScrollBar_GetScrollDirection(swigCPtr);
265             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
266             return ret;
267         }
268
269         internal void SetIndicatorHeightPolicy(ScrollBar.IndicatorHeightPolicyType policy)
270         {
271             NDalicPINVOKE.ScrollBar_SetIndicatorHeightPolicy(swigCPtr, (int)policy);
272             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
273         }
274
275         internal ScrollBar.IndicatorHeightPolicyType GetIndicatorHeightPolicy()
276         {
277             ScrollBar.IndicatorHeightPolicyType ret = (ScrollBar.IndicatorHeightPolicyType)NDalicPINVOKE.ScrollBar_GetIndicatorHeightPolicy(swigCPtr);
278             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
279             return ret;
280         }
281
282         internal void SetIndicatorFixedHeight(float height)
283         {
284             NDalicPINVOKE.ScrollBar_SetIndicatorFixedHeight(swigCPtr, height);
285             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
286         }
287
288         internal float GetIndicatorFixedHeight()
289         {
290             float ret = NDalicPINVOKE.ScrollBar_GetIndicatorFixedHeight(swigCPtr);
291             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292             return ret;
293         }
294
295         internal void SetIndicatorShowDuration(float durationSeconds)
296         {
297             NDalicPINVOKE.ScrollBar_SetIndicatorShowDuration(swigCPtr, durationSeconds);
298             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299         }
300
301         internal float GetIndicatorShowDuration()
302         {
303             float ret = NDalicPINVOKE.ScrollBar_GetIndicatorShowDuration(swigCPtr);
304             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
305             return ret;
306         }
307
308         internal void SetIndicatorHideDuration(float durationSeconds)
309         {
310             NDalicPINVOKE.ScrollBar_SetIndicatorHideDuration(swigCPtr, durationSeconds);
311             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
312         }
313
314         internal float GetIndicatorHideDuration()
315         {
316             float ret = NDalicPINVOKE.ScrollBar_GetIndicatorHideDuration(swigCPtr);
317             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
318             return ret;
319         }
320
321         internal void ShowIndicator()
322         {
323             NDalicPINVOKE.ScrollBar_ShowIndicator(swigCPtr);
324             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
325         }
326
327         internal void HideIndicator()
328         {
329             NDalicPINVOKE.ScrollBar_HideIndicator(swigCPtr);
330             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
331         }
332
333         internal VoidSignal PanFinishedSignal()
334         {
335             VoidSignal ret = new VoidSignal(NDalicPINVOKE.ScrollBar_PanFinishedSignal(swigCPtr), false);
336             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
337             return ret;
338         }
339
340         internal FloatSignal ScrollPositionIntervalReachedSignal()
341         {
342             FloatSignal ret = new FloatSignal(NDalicPINVOKE.ScrollBar_ScrollPositionIntervalReachedSignal(swigCPtr), false);
343             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344             return ret;
345         }
346
347         /// <summary>
348         /// Direction of scroll bar
349         /// </summary>
350         public enum Direction
351         {
352             Vertical = 0,
353             Horizontal
354         }
355
356         /// <summary>
357         /// Indicator height policy.
358         /// </summary>
359         public enum IndicatorHeightPolicyType
360         {
361             Variable = 0,
362             Fixed
363         }
364
365         /// <summary>
366         /// Direction of scroll bar
367         /// </summary>
368         public Direction ScrollDirection
369         {
370             get
371             {
372                 string temp;
373                 if (GetProperty(ScrollBar.Property.SCROLL_DIRECTION).Get(out temp) == false)
374                 {
375                     NUILog.Error("ScrollDirection get error!");
376                 }
377
378                 switch (temp)
379                 {
380                     case "Vertical":
381                         return Direction.Vertical;
382                     case "Horizontal":
383                         return Direction.Horizontal;
384                     default:
385                         return Direction.Vertical;
386                 }
387             }
388             set
389             {
390                 string valueToString = "";
391                 switch (value)
392                 {
393                     case Direction.Vertical:
394                     {
395                         valueToString = "Vertical";
396                         break;
397                     }
398                     case Direction.Horizontal:
399                     {
400                         valueToString = "Horizontal";
401                         break;
402                     }
403                     default:
404                     {
405                         valueToString = "Vertical";
406                         break;
407                     }
408                 }
409                 SetProperty(ScrollBar.Property.SCROLL_DIRECTION, new Tizen.NUI.PropertyValue(valueToString));
410             }
411         }
412
413         /// <summary>
414         /// Indicator height policy.
415         /// </summary>
416         public IndicatorHeightPolicyType IndicatorHeightPolicy
417         {
418             get
419             {
420                 string temp;
421                 if (GetProperty(ScrollBar.Property.INDICATOR_HEIGHT_POLICY).Get(out temp) == false)
422                 {
423                     NUILog.Error("IndicatorHeightPolicy get error!");
424                 }
425
426                 switch (temp)
427                 {
428                     case "Variable":
429                         return IndicatorHeightPolicyType.Variable;
430                     case "Fixed":
431                         return IndicatorHeightPolicyType.Fixed;
432                     default:
433                         return IndicatorHeightPolicyType.Variable;
434                 }
435             }
436             set
437             {
438                 string valueToString = "";
439                 switch (value)
440                 {
441                     case IndicatorHeightPolicyType.Variable:
442                     {
443                         valueToString = "Variable";
444                         break;
445                     }
446                     case IndicatorHeightPolicyType.Fixed:
447                     {
448                         valueToString = "Fixed";
449                         break;
450                     }
451                     default:
452                     {
453                         valueToString = "Variable";
454                         break;
455                     }
456                 }
457                 SetProperty(ScrollBar.Property.INDICATOR_HEIGHT_POLICY, new Tizen.NUI.PropertyValue(valueToString));
458             }
459         }
460
461         /// <summary>
462         /// the fixed height of scroll indicator.
463         /// </summary>
464         public float IndicatorFixedHeight
465         {
466             get
467             {
468                 float temp = 0.0f;
469                 GetProperty(ScrollBar.Property.INDICATOR_FIXED_HEIGHT).Get(out temp);
470                 return temp;
471             }
472             set
473             {
474                 SetProperty(ScrollBar.Property.INDICATOR_FIXED_HEIGHT, new Tizen.NUI.PropertyValue(value));
475             }
476         }
477
478         /// <summary>
479         /// the duration in seconds for the scroll indicator to become fully visible.
480         /// </summary>
481         public float IndicatorShowDuration
482         {
483             get
484             {
485                 float temp = 0.0f;
486                 GetProperty(ScrollBar.Property.INDICATOR_SHOW_DURATION).Get(out temp);
487                 return temp;
488             }
489             set
490             {
491                 SetProperty(ScrollBar.Property.INDICATOR_SHOW_DURATION, new Tizen.NUI.PropertyValue(value));
492             }
493         }
494
495         /// <summary>
496         /// the duration in seconds for the scroll indicator to become fully invisible.
497         /// </summary>
498         public float IndicatorHideDuration
499         {
500             get
501             {
502                 float temp = 0.0f;
503                 GetProperty(ScrollBar.Property.INDICATOR_HIDE_DURATION).Get(out temp);
504                 return temp;
505             }
506             set
507             {
508                 SetProperty(ScrollBar.Property.INDICATOR_HIDE_DURATION, new Tizen.NUI.PropertyValue(value));
509             }
510         }
511
512         /// <summary>
513         /// the list of values to get notification when the current scroll position of the scrollable object goes above or below any of these values.
514         /// </summary>
515         public Tizen.NUI.PropertyArray ScrollPositionIntervals
516         {
517             get
518             {
519                 Tizen.NUI.PropertyArray temp = new Tizen.NUI.PropertyArray();
520                 GetProperty(ScrollBar.Property.SCROLL_POSITION_INTERVALS).Get(temp);
521                 return temp;
522             }
523             set
524             {
525                 SetProperty(ScrollBar.Property.SCROLL_POSITION_INTERVALS, new Tizen.NUI.PropertyValue(value));
526             }
527         }
528
529         /// <summary>
530         /// The minimum height for a variable size indicator.
531         /// </summary>
532         public float IndicatorMinimumHeight
533         {
534             get
535             {
536                 float temp = 0.0f;
537                 GetProperty(ScrollBar.Property.INDICATOR_MINIMUM_HEIGHT).Get(out temp);
538                 return temp;
539             }
540             set
541             {
542                 SetProperty(ScrollBar.Property.INDICATOR_MINIMUM_HEIGHT, new Tizen.NUI.PropertyValue(value));
543             }
544         }
545
546         /// <summary>
547         /// The padding at the start of the indicator. For example, the top if scrollDirection is Vertical.
548         /// </summary>
549         public float IndicatorStartPadding
550         {
551             get
552             {
553                 float temp = 0.0f;
554                 GetProperty(ScrollBar.Property.INDICATOR_START_PADDING).Get(out temp);
555                 return temp;
556             }
557             set
558             {
559                 SetProperty(ScrollBar.Property.INDICATOR_START_PADDING, new Tizen.NUI.PropertyValue(value));
560             }
561         }
562
563         /// <summary>
564         /// The padding at the end of the indicator. For example, the bottom if scrollDirection is Vertical.
565         /// </summary>
566         public float IndicatorEndPadding
567         {
568             get
569             {
570                 float temp = 0.0f;
571                 GetProperty(ScrollBar.Property.INDICATOR_END_PADDING).Get(out temp);
572                 return temp;
573             }
574             set
575             {
576                 SetProperty(ScrollBar.Property.INDICATOR_END_PADDING, new Tizen.NUI.PropertyValue(value));
577             }
578         }
579
580     }
581
582 }