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