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 (_scrollBarScrollPositionIntervalReachedEventCallbackDelegate != null)
65 ScrollPositionIntervalReachedSignal().Disconnect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
68 if (_scrollBarPanFinishedEventCallbackDelegate != null)
70 PanFinishedSignal().Disconnect(_scrollBarPanFinishedEventCallbackDelegate);
73 if (swigCPtr.Handle != global::System.IntPtr.Zero)
78 NDalicPINVOKE.delete_ScrollBar(swigCPtr);
80 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
87 /// Event arguments that passed via PanFinished event
89 public class PanFinishedEventArgs : EventArgs
94 /// Event arguments that passed via ScrollPositionIntervalReached event
96 public class ScrollIntervalEventArgs : EventArgs
98 private float _currentScrollPosition;
101 /// current scroll position of the scrollable content
103 public float CurrentScrollPosition
107 return _currentScrollPosition;
111 _currentScrollPosition = value;
116 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
117 private delegate void PanFinishedEventCallbackDelegate();
118 private EventHandler<PanFinishedEventArgs> _scrollBarPanFinishedEventHandler;
119 private PanFinishedEventCallbackDelegate _scrollBarPanFinishedEventCallbackDelegate;
121 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
122 private delegate void ScrollPositionIntervalReachedEventCallbackDelegate();
123 private EventHandler<ScrollIntervalEventArgs> _scrollBarScrollPositionIntervalReachedEventHandler;
124 private ScrollPositionIntervalReachedEventCallbackDelegate _scrollBarScrollPositionIntervalReachedEventCallbackDelegate;
127 /// Event emitted when panning is finished on the scroll indicator.
129 public event EventHandler<PanFinishedEventArgs> PanFinished
133 if (_scrollBarPanFinishedEventHandler == null)
135 _scrollBarPanFinishedEventCallbackDelegate = (OnScrollBarPanFinished);
136 PanFinishedSignal().Connect(_scrollBarPanFinishedEventCallbackDelegate);
138 _scrollBarPanFinishedEventHandler += value;
142 _scrollBarPanFinishedEventHandler -= value;
143 if (_scrollBarPanFinishedEventHandler == null && PanFinishedSignal().Empty() == false)
145 PanFinishedSignal().Disconnect(_scrollBarPanFinishedEventCallbackDelegate);
150 // Callback for ScrollBar PanFinishedSignal
151 private void OnScrollBarPanFinished()
153 PanFinishedEventArgs e = new PanFinishedEventArgs();
155 if (_scrollBarPanFinishedEventHandler != null)
157 //here we send all data to user event handlers
158 _scrollBarPanFinishedEventHandler(this, e);
164 /// Event emitted when the current scroll position of the scrollable content
166 public event EventHandler<ScrollIntervalEventArgs> ScrollInterval
170 if (_scrollBarScrollPositionIntervalReachedEventHandler == null)
172 _scrollBarScrollPositionIntervalReachedEventCallbackDelegate = (OnScrollBarScrollPositionIntervalReached);
173 ScrollPositionIntervalReachedSignal().Connect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
175 _scrollBarScrollPositionIntervalReachedEventHandler += value;
179 _scrollBarScrollPositionIntervalReachedEventHandler -= value;
180 if (_scrollBarScrollPositionIntervalReachedEventHandler == null && ScrollPositionIntervalReachedSignal().Empty() == false)
182 ScrollPositionIntervalReachedSignal().Disconnect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
187 // Callback for ScrollBar ScrollPositionIntervalReachedSignal
188 private void OnScrollBarScrollPositionIntervalReached()
190 ScrollIntervalEventArgs e = new ScrollIntervalEventArgs();
192 if (_scrollBarScrollPositionIntervalReachedEventHandler != null)
194 //here we send all data to user event handlers
195 _scrollBarScrollPositionIntervalReachedEventHandler(this, e);
200 internal new class Property
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();
214 /// Creates an initialized ScrollBar.
216 /// <param name="direction">The direction of scroll bar (either vertically or horizontally)</param>
217 public ScrollBar(ScrollBar.Direction direction) : this(NDalicPINVOKE.ScrollBar_New__SWIG_0((int)direction), true)
219 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
223 /// Creates an uninitialized ScrollBar
225 public ScrollBar() : this(NDalicPINVOKE.ScrollBar_New__SWIG_1(), true)
227 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
230 internal ScrollBar(ScrollBar scrollBar) : this(NDalicPINVOKE.new_ScrollBar__SWIG_1(ScrollBar.getCPtr(scrollBar)), true)
232 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
235 [Obsolete("Please do not use! this will be deprecated")]
236 public new static ScrollBar DownCast(BaseHandle handle)
238 ScrollBar ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ScrollBar;
239 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243 internal void SetScrollPropertySource(Animatable handle, int propertyScrollPosition, int propertyMinScrollPosition, int propertyMaxScrollPosition, int propertyScrollContentSize)
245 NDalicPINVOKE.ScrollBar_SetScrollPropertySource(swigCPtr, Animatable.getCPtr(handle), propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
246 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249 internal void SetScrollIndicator(View indicator)
251 NDalicPINVOKE.ScrollBar_SetScrollIndicator(swigCPtr, View.getCPtr(indicator));
252 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
255 internal View GetScrollIndicator()
257 View ret = new View(NDalicPINVOKE.ScrollBar_GetScrollIndicator(swigCPtr), true);
258 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262 internal void SetScrollDirection(ScrollBar.Direction direction)
264 NDalicPINVOKE.ScrollBar_SetScrollDirection(swigCPtr, (int)direction);
265 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
268 internal ScrollBar.Direction GetScrollDirection()
270 ScrollBar.Direction ret = (ScrollBar.Direction)NDalicPINVOKE.ScrollBar_GetScrollDirection(swigCPtr);
271 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 internal void SetIndicatorHeightPolicy(ScrollBar.IndicatorHeightPolicyType policy)
277 NDalicPINVOKE.ScrollBar_SetIndicatorHeightPolicy(swigCPtr, (int)policy);
278 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
281 internal ScrollBar.IndicatorHeightPolicyType GetIndicatorHeightPolicy()
283 ScrollBar.IndicatorHeightPolicyType ret = (ScrollBar.IndicatorHeightPolicyType)NDalicPINVOKE.ScrollBar_GetIndicatorHeightPolicy(swigCPtr);
284 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288 internal void SetIndicatorFixedHeight(float height)
290 NDalicPINVOKE.ScrollBar_SetIndicatorFixedHeight(swigCPtr, height);
291 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
294 internal float GetIndicatorFixedHeight()
296 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorFixedHeight(swigCPtr);
297 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301 internal void SetIndicatorShowDuration(float durationSeconds)
303 NDalicPINVOKE.ScrollBar_SetIndicatorShowDuration(swigCPtr, durationSeconds);
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
307 internal float GetIndicatorShowDuration()
309 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorShowDuration(swigCPtr);
310 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
314 internal void SetIndicatorHideDuration(float durationSeconds)
316 NDalicPINVOKE.ScrollBar_SetIndicatorHideDuration(swigCPtr, durationSeconds);
317 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
320 internal float GetIndicatorHideDuration()
322 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorHideDuration(swigCPtr);
323 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
327 internal void ShowIndicator()
329 NDalicPINVOKE.ScrollBar_ShowIndicator(swigCPtr);
330 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333 internal void HideIndicator()
335 NDalicPINVOKE.ScrollBar_HideIndicator(swigCPtr);
336 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
339 internal VoidSignal PanFinishedSignal()
341 VoidSignal ret = new VoidSignal(NDalicPINVOKE.ScrollBar_PanFinishedSignal(swigCPtr), false);
342 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
346 internal FloatSignal ScrollPositionIntervalReachedSignal()
348 FloatSignal ret = new FloatSignal(NDalicPINVOKE.ScrollBar_ScrollPositionIntervalReachedSignal(swigCPtr), false);
349 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
354 /// Direction of scroll bar
356 public enum Direction
363 /// Indicator height policy.
365 public enum IndicatorHeightPolicyType
372 /// Direction of scroll bar
374 public Direction ScrollDirection
379 if (GetProperty(ScrollBar.Property.SCROLL_DIRECTION).Get(out temp) == false)
381 NUILog.Error("ScrollDirection get error!");
387 return Direction.Vertical;
389 return Direction.Horizontal;
391 return Direction.Vertical;
396 string valueToString = "";
399 case Direction.Vertical:
401 valueToString = "Vertical";
404 case Direction.Horizontal:
406 valueToString = "Horizontal";
411 valueToString = "Vertical";
415 SetProperty(ScrollBar.Property.SCROLL_DIRECTION, new Tizen.NUI.PropertyValue(valueToString));
420 /// Indicator height policy.
422 public IndicatorHeightPolicyType IndicatorHeightPolicy
427 if (GetProperty(ScrollBar.Property.INDICATOR_HEIGHT_POLICY).Get(out temp) == false)
429 NUILog.Error("IndicatorHeightPolicy get error!");
435 return IndicatorHeightPolicyType.Variable;
437 return IndicatorHeightPolicyType.Fixed;
439 return IndicatorHeightPolicyType.Variable;
444 string valueToString = "";
447 case IndicatorHeightPolicyType.Variable:
449 valueToString = "Variable";
452 case IndicatorHeightPolicyType.Fixed:
454 valueToString = "Fixed";
459 valueToString = "Variable";
463 SetProperty(ScrollBar.Property.INDICATOR_HEIGHT_POLICY, new Tizen.NUI.PropertyValue(valueToString));
468 /// the fixed height of scroll indicator.
470 public float IndicatorFixedHeight
475 GetProperty(ScrollBar.Property.INDICATOR_FIXED_HEIGHT).Get(out temp);
480 SetProperty(ScrollBar.Property.INDICATOR_FIXED_HEIGHT, new Tizen.NUI.PropertyValue(value));
485 /// the duration in seconds for the scroll indicator to become fully visible.
487 public float IndicatorShowDuration
492 GetProperty(ScrollBar.Property.INDICATOR_SHOW_DURATION).Get(out temp);
497 SetProperty(ScrollBar.Property.INDICATOR_SHOW_DURATION, new Tizen.NUI.PropertyValue(value));
502 /// the duration in seconds for the scroll indicator to become fully invisible.
504 public float IndicatorHideDuration
509 GetProperty(ScrollBar.Property.INDICATOR_HIDE_DURATION).Get(out temp);
514 SetProperty(ScrollBar.Property.INDICATOR_HIDE_DURATION, new Tizen.NUI.PropertyValue(value));
519 /// the list of values to get notification when the current scroll position of the scrollable object goes above or below any of these values.
521 public Tizen.NUI.PropertyArray ScrollPositionIntervals
525 Tizen.NUI.PropertyArray temp = new Tizen.NUI.PropertyArray();
526 GetProperty(ScrollBar.Property.SCROLL_POSITION_INTERVALS).Get(temp);
531 SetProperty(ScrollBar.Property.SCROLL_POSITION_INTERVALS, new Tizen.NUI.PropertyValue(value));
536 /// The minimum height for a variable size indicator.
538 public float IndicatorMinimumHeight
543 GetProperty(ScrollBar.Property.INDICATOR_MINIMUM_HEIGHT).Get(out temp);
548 SetProperty(ScrollBar.Property.INDICATOR_MINIMUM_HEIGHT, new Tizen.NUI.PropertyValue(value));
553 /// The padding at the start of the indicator. For example, the top if scrollDirection is Vertical.
555 public float IndicatorStartPadding
560 GetProperty(ScrollBar.Property.INDICATOR_START_PADDING).Get(out temp);
565 SetProperty(ScrollBar.Property.INDICATOR_START_PADDING, new Tizen.NUI.PropertyValue(value));
570 /// The padding at the end of the indicator. For example, the bottom if scrollDirection is Vertical.
572 public float IndicatorEndPadding
577 GetProperty(ScrollBar.Property.INDICATOR_END_PADDING).Get(out temp);
582 SetProperty(ScrollBar.Property.INDICATOR_END_PADDING, new Tizen.NUI.PropertyValue(value));