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)
69 //Unreference this instance from Registry.
70 Registry.Unregister(this);
72 NDalicPINVOKE.delete_ScrollBar(swigCPtr);
74 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
81 /// Event arguments that passed via PanFinished event
83 public class PanFinishedEventArgs : EventArgs
88 /// Event arguments that passed via ScrollPositionIntervalReached event
90 public class ScrollIntervalEventArgs : EventArgs
92 private float _currentScrollPosition;
95 /// current scroll position of the scrollable content
97 public float CurrentScrollPosition
101 return _currentScrollPosition;
105 _currentScrollPosition = value;
110 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
111 private delegate void PanFinishedEventCallbackDelegate();
112 private EventHandler<PanFinishedEventArgs> _scrollBarPanFinishedEventHandler;
113 private PanFinishedEventCallbackDelegate _scrollBarPanFinishedEventCallbackDelegate;
115 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
116 private delegate void ScrollPositionIntervalReachedEventCallbackDelegate();
117 private EventHandler<ScrollIntervalEventArgs> _scrollBarScrollPositionIntervalReachedEventHandler;
118 private ScrollPositionIntervalReachedEventCallbackDelegate _scrollBarScrollPositionIntervalReachedEventCallbackDelegate;
121 /// Event emitted when panning is finished on the scroll indicator.
123 public event EventHandler<PanFinishedEventArgs> PanFinished
127 if (_scrollBarPanFinishedEventHandler == null)
129 _scrollBarPanFinishedEventCallbackDelegate = (OnScrollBarPanFinished);
130 PanFinishedSignal().Connect(_scrollBarPanFinishedEventCallbackDelegate);
132 _scrollBarPanFinishedEventHandler += value;
136 _scrollBarPanFinishedEventHandler -= value;
137 if (_scrollBarPanFinishedEventHandler == null && PanFinishedSignal().Empty() == false)
139 PanFinishedSignal().Disconnect(_scrollBarPanFinishedEventCallbackDelegate);
144 // Callback for ScrollBar PanFinishedSignal
145 private void OnScrollBarPanFinished()
147 PanFinishedEventArgs e = new PanFinishedEventArgs();
149 if (_scrollBarPanFinishedEventHandler != null)
151 //here we send all data to user event handlers
152 _scrollBarPanFinishedEventHandler(this, e);
158 /// Event emitted when the current scroll position of the scrollable content
160 public event EventHandler<ScrollIntervalEventArgs> ScrollInterval
164 if (_scrollBarScrollPositionIntervalReachedEventHandler == null)
166 _scrollBarScrollPositionIntervalReachedEventCallbackDelegate = (OnScrollBarScrollPositionIntervalReached);
167 ScrollPositionIntervalReachedSignal().Connect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
169 _scrollBarScrollPositionIntervalReachedEventHandler += value;
173 _scrollBarScrollPositionIntervalReachedEventHandler -= value;
174 if (_scrollBarScrollPositionIntervalReachedEventHandler == null && ScrollPositionIntervalReachedSignal().Empty() == false)
176 ScrollPositionIntervalReachedSignal().Disconnect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
181 // Callback for ScrollBar ScrollPositionIntervalReachedSignal
182 private void OnScrollBarScrollPositionIntervalReached()
184 ScrollIntervalEventArgs e = new ScrollIntervalEventArgs();
186 if (_scrollBarScrollPositionIntervalReachedEventHandler != null)
188 //here we send all data to user event handlers
189 _scrollBarScrollPositionIntervalReachedEventHandler(this, e);
194 internal class Property
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();
208 /// Creates an initialized ScrollBar.
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)
213 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
217 /// Creates an uninitialized ScrollBar
219 public ScrollBar() : this(NDalicPINVOKE.ScrollBar_New__SWIG_1(), true)
221 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
224 internal ScrollBar(ScrollBar scrollBar) : this(NDalicPINVOKE.new_ScrollBar__SWIG_1(ScrollBar.getCPtr(scrollBar)), true)
226 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
229 [Obsolete("Please do not use! this will be deprecated")]
230 public new static ScrollBar DownCast(BaseHandle handle)
232 ScrollBar ret = new ScrollBar(NDalicPINVOKE.ScrollBar_DownCast(BaseHandle.getCPtr(handle)), true);
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
237 internal void SetScrollPropertySource(Animatable handle, int propertyScrollPosition, int propertyMinScrollPosition, int propertyMaxScrollPosition, int propertyScrollContentSize)
239 NDalicPINVOKE.ScrollBar_SetScrollPropertySource(swigCPtr, Animatable.getCPtr(handle), propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
240 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
243 internal void SetScrollIndicator(View indicator)
245 NDalicPINVOKE.ScrollBar_SetScrollIndicator(swigCPtr, View.getCPtr(indicator));
246 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
249 internal View GetScrollIndicator()
251 View ret = new View(NDalicPINVOKE.ScrollBar_GetScrollIndicator(swigCPtr), true);
252 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256 internal void SetScrollDirection(ScrollBar.Direction direction)
258 NDalicPINVOKE.ScrollBar_SetScrollDirection(swigCPtr, (int)direction);
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
262 internal ScrollBar.Direction GetScrollDirection()
264 ScrollBar.Direction ret = (ScrollBar.Direction)NDalicPINVOKE.ScrollBar_GetScrollDirection(swigCPtr);
265 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269 internal void SetIndicatorHeightPolicy(ScrollBar.IndicatorHeightPolicyType policy)
271 NDalicPINVOKE.ScrollBar_SetIndicatorHeightPolicy(swigCPtr, (int)policy);
272 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
275 internal ScrollBar.IndicatorHeightPolicyType GetIndicatorHeightPolicy()
277 ScrollBar.IndicatorHeightPolicyType ret = (ScrollBar.IndicatorHeightPolicyType)NDalicPINVOKE.ScrollBar_GetIndicatorHeightPolicy(swigCPtr);
278 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282 internal void SetIndicatorFixedHeight(float height)
284 NDalicPINVOKE.ScrollBar_SetIndicatorFixedHeight(swigCPtr, height);
285 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
288 internal float GetIndicatorFixedHeight()
290 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorFixedHeight(swigCPtr);
291 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295 internal void SetIndicatorShowDuration(float durationSeconds)
297 NDalicPINVOKE.ScrollBar_SetIndicatorShowDuration(swigCPtr, durationSeconds);
298 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301 internal float GetIndicatorShowDuration()
303 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorShowDuration(swigCPtr);
304 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 internal void SetIndicatorHideDuration(float durationSeconds)
310 NDalicPINVOKE.ScrollBar_SetIndicatorHideDuration(swigCPtr, durationSeconds);
311 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
314 internal float GetIndicatorHideDuration()
316 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorHideDuration(swigCPtr);
317 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
321 internal void ShowIndicator()
323 NDalicPINVOKE.ScrollBar_ShowIndicator(swigCPtr);
324 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
327 internal void HideIndicator()
329 NDalicPINVOKE.ScrollBar_HideIndicator(swigCPtr);
330 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
333 internal VoidSignal PanFinishedSignal()
335 VoidSignal ret = new VoidSignal(NDalicPINVOKE.ScrollBar_PanFinishedSignal(swigCPtr), false);
336 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340 internal FloatSignal ScrollPositionIntervalReachedSignal()
342 FloatSignal ret = new FloatSignal(NDalicPINVOKE.ScrollBar_ScrollPositionIntervalReachedSignal(swigCPtr), false);
343 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
348 /// Direction of scroll bar
350 public enum Direction
357 /// Indicator height policy.
359 public enum IndicatorHeightPolicyType
366 /// Direction of scroll bar
368 public Direction ScrollDirection
373 if (GetProperty(ScrollBar.Property.SCROLL_DIRECTION).Get(out temp) == false)
375 NUILog.Error("ScrollDirection get error!");
381 return Direction.Vertical;
383 return Direction.Horizontal;
385 return Direction.Vertical;
390 string valueToString = "";
393 case Direction.Vertical:
395 valueToString = "Vertical";
398 case Direction.Horizontal:
400 valueToString = "Horizontal";
405 valueToString = "Vertical";
409 SetProperty(ScrollBar.Property.SCROLL_DIRECTION, new Tizen.NUI.PropertyValue(valueToString));
414 /// Indicator height policy.
416 public IndicatorHeightPolicyType IndicatorHeightPolicy
421 if (GetProperty(ScrollBar.Property.INDICATOR_HEIGHT_POLICY).Get(out temp) == false)
423 NUILog.Error("IndicatorHeightPolicy get error!");
429 return IndicatorHeightPolicyType.Variable;
431 return IndicatorHeightPolicyType.Fixed;
433 return IndicatorHeightPolicyType.Variable;
438 string valueToString = "";
441 case IndicatorHeightPolicyType.Variable:
443 valueToString = "Variable";
446 case IndicatorHeightPolicyType.Fixed:
448 valueToString = "Fixed";
453 valueToString = "Variable";
457 SetProperty(ScrollBar.Property.INDICATOR_HEIGHT_POLICY, new Tizen.NUI.PropertyValue(valueToString));
462 /// the fixed height of scroll indicator.
464 public float IndicatorFixedHeight
469 GetProperty(ScrollBar.Property.INDICATOR_FIXED_HEIGHT).Get(out temp);
474 SetProperty(ScrollBar.Property.INDICATOR_FIXED_HEIGHT, new Tizen.NUI.PropertyValue(value));
479 /// the duration in seconds for the scroll indicator to become fully visible.
481 public float IndicatorShowDuration
486 GetProperty(ScrollBar.Property.INDICATOR_SHOW_DURATION).Get(out temp);
491 SetProperty(ScrollBar.Property.INDICATOR_SHOW_DURATION, new Tizen.NUI.PropertyValue(value));
496 /// the duration in seconds for the scroll indicator to become fully invisible.
498 public float IndicatorHideDuration
503 GetProperty(ScrollBar.Property.INDICATOR_HIDE_DURATION).Get(out temp);
508 SetProperty(ScrollBar.Property.INDICATOR_HIDE_DURATION, new Tizen.NUI.PropertyValue(value));
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.
515 public Tizen.NUI.PropertyArray ScrollPositionIntervals
519 Tizen.NUI.PropertyArray temp = new Tizen.NUI.PropertyArray();
520 GetProperty(ScrollBar.Property.SCROLL_POSITION_INTERVALS).Get(temp);
525 SetProperty(ScrollBar.Property.SCROLL_POSITION_INTERVALS, new Tizen.NUI.PropertyValue(value));
530 /// The minimum height for a variable size indicator.
532 public float IndicatorMinimumHeight
537 GetProperty(ScrollBar.Property.INDICATOR_MINIMUM_HEIGHT).Get(out temp);
542 SetProperty(ScrollBar.Property.INDICATOR_MINIMUM_HEIGHT, new Tizen.NUI.PropertyValue(value));
547 /// The padding at the start of the indicator. For example, the top if scrollDirection is Vertical.
549 public float IndicatorStartPadding
554 GetProperty(ScrollBar.Property.INDICATOR_START_PADDING).Get(out temp);
559 SetProperty(ScrollBar.Property.INDICATOR_START_PADDING, new Tizen.NUI.PropertyValue(value));
564 /// The padding at the end of the indicator. For example, the bottom if scrollDirection is Vertical.
566 public float IndicatorEndPadding
571 GetProperty(ScrollBar.Property.INDICATOR_END_PADDING).Get(out temp);
576 SetProperty(ScrollBar.Property.INDICATOR_END_PADDING, new Tizen.NUI.PropertyValue(value));