1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
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
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 namespace Tizen.NUI.UIComponents
21 using System.Runtime.InteropServices;
22 using Tizen.NUI.BaseComponents;
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>
28 public class ScrollBar : View
30 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
32 internal ScrollBar(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.ScrollBar_SWIGUpcast(cPtr), cMemoryOwn)
34 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
37 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ScrollBar obj)
39 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
43 /// To make ScrollBar instance be disposed.
45 protected override void Dispose(DisposeTypes type)
52 if(type == DisposeTypes.Explicit)
55 //Release your own managed resources here.
56 //You should release all of your own disposable objects here.
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.
63 if (swigCPtr.Handle != global::System.IntPtr.Zero)
68 NDalicPINVOKE.delete_ScrollBar(swigCPtr);
70 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
77 /// Event arguments that passed via PanFinished event
79 public class PanFinishedEventArgs : EventArgs
84 /// Event arguments that passed via ScrollPositionIntervalReached event
86 public class ScrollIntervalEventArgs : EventArgs
88 private float _currentScrollPosition;
91 /// current scroll position of the scrollable content
93 public float CurrentScrollPosition
97 return _currentScrollPosition;
101 _currentScrollPosition = value;
106 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
107 private delegate void PanFinishedEventCallbackDelegate();
108 private EventHandler<PanFinishedEventArgs> _scrollBarPanFinishedEventHandler;
109 private PanFinishedEventCallbackDelegate _scrollBarPanFinishedEventCallbackDelegate;
111 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
112 private delegate void ScrollPositionIntervalReachedEventCallbackDelegate();
113 private EventHandler<ScrollIntervalEventArgs> _scrollBarScrollPositionIntervalReachedEventHandler;
114 private ScrollPositionIntervalReachedEventCallbackDelegate _scrollBarScrollPositionIntervalReachedEventCallbackDelegate;
117 /// Event emitted when panning is finished on the scroll indicator.
119 public event EventHandler<PanFinishedEventArgs> PanFinished
123 if (_scrollBarPanFinishedEventHandler == null)
125 _scrollBarPanFinishedEventCallbackDelegate = (OnScrollBarPanFinished);
126 PanFinishedSignal().Connect(_scrollBarPanFinishedEventCallbackDelegate);
128 _scrollBarPanFinishedEventHandler += value;
132 _scrollBarPanFinishedEventHandler -= value;
133 if (_scrollBarPanFinishedEventHandler == null && PanFinishedSignal().Empty() == false)
135 PanFinishedSignal().Disconnect(_scrollBarPanFinishedEventCallbackDelegate);
140 // Callback for ScrollBar PanFinishedSignal
141 private void OnScrollBarPanFinished()
143 PanFinishedEventArgs e = new PanFinishedEventArgs();
145 if (_scrollBarPanFinishedEventHandler != null)
147 //here we send all data to user event handlers
148 _scrollBarPanFinishedEventHandler(this, e);
154 /// Event emitted when the current scroll position of the scrollable content
156 public event EventHandler<ScrollIntervalEventArgs> ScrollInterval
160 if (_scrollBarScrollPositionIntervalReachedEventHandler == null)
162 _scrollBarScrollPositionIntervalReachedEventCallbackDelegate = (OnScrollBarScrollPositionIntervalReached);
163 ScrollPositionIntervalReachedSignal().Connect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
165 _scrollBarScrollPositionIntervalReachedEventHandler += value;
169 _scrollBarScrollPositionIntervalReachedEventHandler -= value;
170 if (_scrollBarScrollPositionIntervalReachedEventHandler == null && ScrollPositionIntervalReachedSignal().Empty() == false)
172 ScrollPositionIntervalReachedSignal().Disconnect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
177 // Callback for ScrollBar ScrollPositionIntervalReachedSignal
178 private void OnScrollBarScrollPositionIntervalReached()
180 ScrollIntervalEventArgs e = new ScrollIntervalEventArgs();
182 if (_scrollBarScrollPositionIntervalReachedEventHandler != null)
184 //here we send all data to user event handlers
185 _scrollBarScrollPositionIntervalReachedEventHandler(this, e);
190 internal class Property
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();
204 /// Creates an initialized ScrollBar.
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)
209 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
213 /// Creates an uninitialized ScrollBar
215 public ScrollBar() : this(NDalicPINVOKE.ScrollBar_New__SWIG_1(), true)
217 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
220 internal ScrollBar(ScrollBar scrollBar) : this(NDalicPINVOKE.new_ScrollBar__SWIG_1(ScrollBar.getCPtr(scrollBar)), true)
222 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
225 [Obsolete("Please do not use! this will be deprecated")]
226 public new static ScrollBar DownCast(BaseHandle handle)
228 ScrollBar ret = new ScrollBar(NDalicPINVOKE.ScrollBar_DownCast(BaseHandle.getCPtr(handle)), true);
229 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
233 internal void SetScrollPropertySource(Animatable handle, int propertyScrollPosition, int propertyMinScrollPosition, int propertyMaxScrollPosition, int propertyScrollContentSize)
235 NDalicPINVOKE.ScrollBar_SetScrollPropertySource(swigCPtr, Animatable.getCPtr(handle), propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239 internal void SetScrollIndicator(View indicator)
241 NDalicPINVOKE.ScrollBar_SetScrollIndicator(swigCPtr, View.getCPtr(indicator));
242 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245 internal View GetScrollIndicator()
247 View ret = new View(NDalicPINVOKE.ScrollBar_GetScrollIndicator(swigCPtr), true);
248 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
252 internal void SetScrollDirection(ScrollBar.Direction direction)
254 NDalicPINVOKE.ScrollBar_SetScrollDirection(swigCPtr, (int)direction);
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
258 internal ScrollBar.Direction GetScrollDirection()
260 ScrollBar.Direction ret = (ScrollBar.Direction)NDalicPINVOKE.ScrollBar_GetScrollDirection(swigCPtr);
261 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 internal void SetIndicatorHeightPolicy(ScrollBar.IndicatorHeightPolicyType policy)
267 NDalicPINVOKE.ScrollBar_SetIndicatorHeightPolicy(swigCPtr, (int)policy);
268 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271 internal ScrollBar.IndicatorHeightPolicyType GetIndicatorHeightPolicy()
273 ScrollBar.IndicatorHeightPolicyType ret = (ScrollBar.IndicatorHeightPolicyType)NDalicPINVOKE.ScrollBar_GetIndicatorHeightPolicy(swigCPtr);
274 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278 internal void SetIndicatorFixedHeight(float height)
280 NDalicPINVOKE.ScrollBar_SetIndicatorFixedHeight(swigCPtr, height);
281 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284 internal float GetIndicatorFixedHeight()
286 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorFixedHeight(swigCPtr);
287 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291 internal void SetIndicatorShowDuration(float durationSeconds)
293 NDalicPINVOKE.ScrollBar_SetIndicatorShowDuration(swigCPtr, durationSeconds);
294 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297 internal float GetIndicatorShowDuration()
299 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorShowDuration(swigCPtr);
300 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 internal void SetIndicatorHideDuration(float durationSeconds)
306 NDalicPINVOKE.ScrollBar_SetIndicatorHideDuration(swigCPtr, durationSeconds);
307 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310 internal float GetIndicatorHideDuration()
312 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorHideDuration(swigCPtr);
313 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 internal void ShowIndicator()
319 NDalicPINVOKE.ScrollBar_ShowIndicator(swigCPtr);
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323 internal void HideIndicator()
325 NDalicPINVOKE.ScrollBar_HideIndicator(swigCPtr);
326 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
329 internal VoidSignal PanFinishedSignal()
331 VoidSignal ret = new VoidSignal(NDalicPINVOKE.ScrollBar_PanFinishedSignal(swigCPtr), false);
332 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336 internal FloatSignal ScrollPositionIntervalReachedSignal()
338 FloatSignal ret = new FloatSignal(NDalicPINVOKE.ScrollBar_ScrollPositionIntervalReachedSignal(swigCPtr), false);
339 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344 /// Direction of scroll bar
346 public enum Direction
353 /// Indicator height policy.
355 public enum IndicatorHeightPolicyType
362 /// Direction of scroll bar
364 public Direction ScrollDirection
369 if (GetProperty(ScrollBar.Property.SCROLL_DIRECTION).Get(out temp) == false)
371 NUILog.Error("ScrollDirection get error!");
377 return Direction.Vertical;
379 return Direction.Horizontal;
381 return Direction.Vertical;
386 string valueToString = "";
389 case Direction.Vertical:
391 valueToString = "Vertical";
394 case Direction.Horizontal:
396 valueToString = "Horizontal";
401 valueToString = "Vertical";
405 SetProperty(ScrollBar.Property.SCROLL_DIRECTION, new Tizen.NUI.PropertyValue(valueToString));
410 /// Indicator height policy.
412 public IndicatorHeightPolicyType IndicatorHeightPolicy
417 if (GetProperty(ScrollBar.Property.INDICATOR_HEIGHT_POLICY).Get(out temp) == false)
419 NUILog.Error("IndicatorHeightPolicy get error!");
425 return IndicatorHeightPolicyType.Variable;
427 return IndicatorHeightPolicyType.Fixed;
429 return IndicatorHeightPolicyType.Variable;
434 string valueToString = "";
437 case IndicatorHeightPolicyType.Variable:
439 valueToString = "Variable";
442 case IndicatorHeightPolicyType.Fixed:
444 valueToString = "Fixed";
449 valueToString = "Variable";
453 SetProperty(ScrollBar.Property.INDICATOR_HEIGHT_POLICY, new Tizen.NUI.PropertyValue(valueToString));
458 /// the fixed height of scroll indicator.
460 public float IndicatorFixedHeight
465 GetProperty(ScrollBar.Property.INDICATOR_FIXED_HEIGHT).Get(out temp);
470 SetProperty(ScrollBar.Property.INDICATOR_FIXED_HEIGHT, new Tizen.NUI.PropertyValue(value));
475 /// the duration in seconds for the scroll indicator to become fully visible.
477 public float IndicatorShowDuration
482 GetProperty(ScrollBar.Property.INDICATOR_SHOW_DURATION).Get(out temp);
487 SetProperty(ScrollBar.Property.INDICATOR_SHOW_DURATION, new Tizen.NUI.PropertyValue(value));
492 /// the duration in seconds for the scroll indicator to become fully invisible.
494 public float IndicatorHideDuration
499 GetProperty(ScrollBar.Property.INDICATOR_HIDE_DURATION).Get(out temp);
504 SetProperty(ScrollBar.Property.INDICATOR_HIDE_DURATION, new Tizen.NUI.PropertyValue(value));
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.
511 public Tizen.NUI.PropertyArray ScrollPositionIntervals
515 Tizen.NUI.PropertyArray temp = new Tizen.NUI.PropertyArray();
516 GetProperty(ScrollBar.Property.SCROLL_POSITION_INTERVALS).Get(temp);
521 SetProperty(ScrollBar.Property.SCROLL_POSITION_INTERVALS, new Tizen.NUI.PropertyValue(value));
526 /// The minimum height for a variable size indicator.
528 public float IndicatorMinimumHeight
533 GetProperty(ScrollBar.Property.INDICATOR_MINIMUM_HEIGHT).Get(out temp);
538 SetProperty(ScrollBar.Property.INDICATOR_MINIMUM_HEIGHT, new Tizen.NUI.PropertyValue(value));
543 /// The padding at the start of the indicator. For example, the top if scrollDirection is Vertical.
545 public float IndicatorStartPadding
550 GetProperty(ScrollBar.Property.INDICATOR_START_PADDING).Get(out temp);
555 SetProperty(ScrollBar.Property.INDICATOR_START_PADDING, new Tizen.NUI.PropertyValue(value));
560 /// The padding at the end of the indicator. For example, the bottom if scrollDirection is Vertical.
562 public float IndicatorEndPadding
567 GetProperty(ScrollBar.Property.INDICATOR_END_PADDING).Get(out temp);
572 SetProperty(ScrollBar.Property.INDICATOR_END_PADDING, new Tizen.NUI.PropertyValue(value));