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