2 * Copyright(c) 2017 Samsung Electronics Co., Ltd.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 namespace Tizen.NUI.UIComponents
22 using System.Runtime.InteropServices;
23 using Tizen.NUI.BaseComponents;
26 /// The ScrollBar is a UI component that can be linked to the scrollable objects
27 /// indicating the current scroll position of the scrollable object.<br />
29 public class ScrollBar : View
31 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
33 internal ScrollBar(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.ScrollBar_SWIGUpcast(cPtr), cMemoryOwn)
35 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
38 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ScrollBar obj)
40 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
44 /// To dispose the ScrollBar instance.
46 protected override void Dispose(DisposeTypes type)
53 if(type == DisposeTypes.Explicit)
56 //Release your own managed resources here.
57 //You should release all of your own disposable objects here.
60 //Release your own unmanaged resources here.
61 //You should not access any managed member here except static instance.
62 //because the execution order of Finalizes is non-deterministic.
64 if (_scrollBarScrollPositionIntervalReachedEventCallbackDelegate != null)
66 ScrollPositionIntervalReachedSignal().Disconnect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
69 if (_scrollBarPanFinishedEventCallbackDelegate != null)
71 PanFinishedSignal().Disconnect(_scrollBarPanFinishedEventCallbackDelegate);
74 if (swigCPtr.Handle != global::System.IntPtr.Zero)
79 NDalicPINVOKE.delete_ScrollBar(swigCPtr);
81 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
88 /// Event arguments that passed via the PanFinished event.
90 public class PanFinishedEventArgs : EventArgs
95 /// Event arguments that passed via the ScrollPositionIntervalReached event.
97 public class ScrollIntervalEventArgs : EventArgs
99 private float _currentScrollPosition;
102 /// The current scroll position of the scrollable content.
104 /// <since_tizen> 3 </since_tizen>
105 public float CurrentScrollPosition
109 return _currentScrollPosition;
113 _currentScrollPosition = value;
118 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
119 private delegate void PanFinishedEventCallbackDelegate();
120 private EventHandler<PanFinishedEventArgs> _scrollBarPanFinishedEventHandler;
121 private PanFinishedEventCallbackDelegate _scrollBarPanFinishedEventCallbackDelegate;
123 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
124 private delegate void ScrollPositionIntervalReachedEventCallbackDelegate();
125 private EventHandler<ScrollIntervalEventArgs> _scrollBarScrollPositionIntervalReachedEventHandler;
126 private ScrollPositionIntervalReachedEventCallbackDelegate _scrollBarScrollPositionIntervalReachedEventCallbackDelegate;
129 /// The event emitted when panning is finished on the scroll indicator.
131 /// <since_tizen> 3 </since_tizen>
132 public event EventHandler<PanFinishedEventArgs> PanFinished
136 if (_scrollBarPanFinishedEventHandler == null)
138 _scrollBarPanFinishedEventCallbackDelegate = (OnScrollBarPanFinished);
139 PanFinishedSignal().Connect(_scrollBarPanFinishedEventCallbackDelegate);
141 _scrollBarPanFinishedEventHandler += value;
145 _scrollBarPanFinishedEventHandler -= value;
146 if (_scrollBarPanFinishedEventHandler == null && PanFinishedSignal().Empty() == false)
148 PanFinishedSignal().Disconnect(_scrollBarPanFinishedEventCallbackDelegate);
153 // Callback for ScrollBar PanFinishedSignal
154 private void OnScrollBarPanFinished()
156 PanFinishedEventArgs e = new PanFinishedEventArgs();
158 if (_scrollBarPanFinishedEventHandler != null)
160 //here we send all data to user event handlers
161 _scrollBarPanFinishedEventHandler(this, e);
167 /// This is the event emitted when the current scroll position of the scrollable content.
169 /// <since_tizen> 4 </since_tizen>
170 public event EventHandler<ScrollIntervalEventArgs> ScrollInterval
174 if (_scrollBarScrollPositionIntervalReachedEventHandler == null)
176 _scrollBarScrollPositionIntervalReachedEventCallbackDelegate = (OnScrollBarScrollPositionIntervalReached);
177 ScrollPositionIntervalReachedSignal().Connect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
179 _scrollBarScrollPositionIntervalReachedEventHandler += value;
183 _scrollBarScrollPositionIntervalReachedEventHandler -= value;
184 if (_scrollBarScrollPositionIntervalReachedEventHandler == null && ScrollPositionIntervalReachedSignal().Empty() == false)
186 ScrollPositionIntervalReachedSignal().Disconnect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
191 // Callback for ScrollBar ScrollPositionIntervalReachedSignal
192 private void OnScrollBarScrollPositionIntervalReached()
194 ScrollIntervalEventArgs e = new ScrollIntervalEventArgs();
196 if (_scrollBarScrollPositionIntervalReachedEventHandler != null)
198 //here we send all data to user event handlers
199 _scrollBarScrollPositionIntervalReachedEventHandler(this, e);
204 internal new class Property
206 internal static readonly int SCROLL_DIRECTION = NDalicPINVOKE.ScrollBar_Property_SCROLL_DIRECTION_get();
207 internal static readonly int INDICATOR_HEIGHT_POLICY = NDalicPINVOKE.ScrollBar_Property_INDICATOR_HEIGHT_POLICY_get();
208 internal static readonly int INDICATOR_FIXED_HEIGHT = NDalicPINVOKE.ScrollBar_Property_INDICATOR_FIXED_HEIGHT_get();
209 internal static readonly int INDICATOR_SHOW_DURATION = NDalicPINVOKE.ScrollBar_Property_INDICATOR_SHOW_DURATION_get();
210 internal static readonly int INDICATOR_HIDE_DURATION = NDalicPINVOKE.ScrollBar_Property_INDICATOR_HIDE_DURATION_get();
211 internal static readonly int SCROLL_POSITION_INTERVALS = NDalicPINVOKE.ScrollBar_Property_SCROLL_POSITION_INTERVALS_get();
212 internal static readonly int INDICATOR_MINIMUM_HEIGHT = NDalicPINVOKE.ScrollBar_Property_INDICATOR_MINIMUM_HEIGHT_get();
213 internal static readonly int INDICATOR_START_PADDING = NDalicPINVOKE.ScrollBar_Property_INDICATOR_START_PADDING_get();
214 internal static readonly int INDICATOR_END_PADDING = NDalicPINVOKE.ScrollBar_Property_INDICATOR_END_PADDING_get();
218 /// Creates an initialized scrollbar.
220 /// <param name="direction">The direction of the scrollbar (either vertically or horizontally).</param>
221 /// <since_tizen> 3 </since_tizen>
222 public ScrollBar(ScrollBar.Direction direction) : this(NDalicPINVOKE.ScrollBar_New__SWIG_0((int)direction), true)
224 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
228 /// Creates an uninitialized scrollbar.
230 /// <since_tizen> 3 </since_tizen>
231 public ScrollBar() : this(NDalicPINVOKE.ScrollBar_New__SWIG_1(), true)
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
236 internal ScrollBar(ScrollBar scrollBar) : this(NDalicPINVOKE.new_ScrollBar__SWIG_1(ScrollBar.getCPtr(scrollBar)), true)
238 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
242 /// Please do not use! this will be deprecated
244 /// <since_tizen> 3 </since_tizen>
245 [Obsolete("Please do not use! this will be deprecated")]
246 public new static ScrollBar DownCast(BaseHandle handle)
248 ScrollBar ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ScrollBar;
249 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
253 internal void SetScrollPropertySource(Animatable handle, int propertyScrollPosition, int propertyMinScrollPosition, int propertyMaxScrollPosition, int propertyScrollContentSize)
255 NDalicPINVOKE.ScrollBar_SetScrollPropertySource(swigCPtr, Animatable.getCPtr(handle), propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
256 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 internal void SetScrollIndicator(View indicator)
261 NDalicPINVOKE.ScrollBar_SetScrollIndicator(swigCPtr, View.getCPtr(indicator));
262 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 internal View GetScrollIndicator()
267 View ret = new View(NDalicPINVOKE.ScrollBar_GetScrollIndicator(swigCPtr), true);
268 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272 internal void SetScrollDirection(ScrollBar.Direction direction)
274 NDalicPINVOKE.ScrollBar_SetScrollDirection(swigCPtr, (int)direction);
275 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278 internal ScrollBar.Direction GetScrollDirection()
280 ScrollBar.Direction ret = (ScrollBar.Direction)NDalicPINVOKE.ScrollBar_GetScrollDirection(swigCPtr);
281 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285 internal void SetIndicatorHeightPolicy(ScrollBar.IndicatorHeightPolicyType policy)
287 NDalicPINVOKE.ScrollBar_SetIndicatorHeightPolicy(swigCPtr, (int)policy);
288 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291 internal ScrollBar.IndicatorHeightPolicyType GetIndicatorHeightPolicy()
293 ScrollBar.IndicatorHeightPolicyType ret = (ScrollBar.IndicatorHeightPolicyType)NDalicPINVOKE.ScrollBar_GetIndicatorHeightPolicy(swigCPtr);
294 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
298 internal void SetIndicatorFixedHeight(float height)
300 NDalicPINVOKE.ScrollBar_SetIndicatorFixedHeight(swigCPtr, height);
301 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 internal float GetIndicatorFixedHeight()
306 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorFixedHeight(swigCPtr);
307 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
311 internal void SetIndicatorShowDuration(float durationSeconds)
313 NDalicPINVOKE.ScrollBar_SetIndicatorShowDuration(swigCPtr, durationSeconds);
314 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 internal float GetIndicatorShowDuration()
319 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorShowDuration(swigCPtr);
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
324 internal void SetIndicatorHideDuration(float durationSeconds)
326 NDalicPINVOKE.ScrollBar_SetIndicatorHideDuration(swigCPtr, durationSeconds);
327 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330 internal float GetIndicatorHideDuration()
332 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorHideDuration(swigCPtr);
333 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
337 internal void ShowIndicator()
339 NDalicPINVOKE.ScrollBar_ShowIndicator(swigCPtr);
340 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343 internal void HideIndicator()
345 NDalicPINVOKE.ScrollBar_HideIndicator(swigCPtr);
346 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349 internal VoidSignal PanFinishedSignal()
351 VoidSignal ret = new VoidSignal(NDalicPINVOKE.ScrollBar_PanFinishedSignal(swigCPtr), false);
352 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
356 internal FloatSignal ScrollPositionIntervalReachedSignal()
358 FloatSignal ret = new FloatSignal(NDalicPINVOKE.ScrollBar_ScrollPositionIntervalReachedSignal(swigCPtr), false);
359 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
364 /// The direction of the scrollbar.
366 /// <since_tizen> 3 </since_tizen>
367 public enum Direction
370 /// Scroll in the vertical direction
372 /// <since_tizen> 3 </since_tizen>
375 /// Scroll in the horizontal direction
377 /// <since_tizen> 3 </since_tizen>
382 /// The indicator height policy.
384 /// <since_tizen> 3 </since_tizen>
385 public enum IndicatorHeightPolicyType
388 /// Variable height changed dynamically according to the length of scroll content
390 /// <since_tizen> 3 </since_tizen>
393 /// Fixed height regardless of the length of scroll content
395 /// <since_tizen> 3 </since_tizen>
400 /// The direction of the scrollbar.
402 /// <since_tizen> 3 </since_tizen>
403 public Direction ScrollDirection
408 if (GetProperty(ScrollBar.Property.SCROLL_DIRECTION).Get(out temp) == false)
410 NUILog.Error("ScrollDirection get error!");
416 return Direction.Vertical;
418 return Direction.Horizontal;
420 return Direction.Vertical;
425 string valueToString = "";
428 case Direction.Vertical:
430 valueToString = "Vertical";
433 case Direction.Horizontal:
435 valueToString = "Horizontal";
440 valueToString = "Vertical";
444 SetProperty(ScrollBar.Property.SCROLL_DIRECTION, new Tizen.NUI.PropertyValue(valueToString));
449 /// The indicator height policy.
451 /// <since_tizen> 3 </since_tizen>
452 public IndicatorHeightPolicyType IndicatorHeightPolicy
457 if (GetProperty(ScrollBar.Property.INDICATOR_HEIGHT_POLICY).Get(out temp) == false)
459 NUILog.Error("IndicatorHeightPolicy get error!");
465 return IndicatorHeightPolicyType.Variable;
467 return IndicatorHeightPolicyType.Fixed;
469 return IndicatorHeightPolicyType.Variable;
474 string valueToString = "";
477 case IndicatorHeightPolicyType.Variable:
479 valueToString = "Variable";
482 case IndicatorHeightPolicyType.Fixed:
484 valueToString = "Fixed";
489 valueToString = "Variable";
493 SetProperty(ScrollBar.Property.INDICATOR_HEIGHT_POLICY, new Tizen.NUI.PropertyValue(valueToString));
498 /// The fixed height of the scroll indicator.
500 /// <since_tizen> 3 </since_tizen>
501 public float IndicatorFixedHeight
506 GetProperty(ScrollBar.Property.INDICATOR_FIXED_HEIGHT).Get(out temp);
511 SetProperty(ScrollBar.Property.INDICATOR_FIXED_HEIGHT, new Tizen.NUI.PropertyValue(value));
516 /// The duration in seconds for the scroll indicator to become fully visible.
518 /// <since_tizen> 3 </since_tizen>
519 public float IndicatorShowDuration
524 GetProperty(ScrollBar.Property.INDICATOR_SHOW_DURATION).Get(out temp);
529 SetProperty(ScrollBar.Property.INDICATOR_SHOW_DURATION, new Tizen.NUI.PropertyValue(value));
534 /// The duration in seconds for the scroll indicator to become fully invisible.
536 /// <since_tizen> 3 </since_tizen>
537 public float IndicatorHideDuration
542 GetProperty(ScrollBar.Property.INDICATOR_HIDE_DURATION).Get(out temp);
547 SetProperty(ScrollBar.Property.INDICATOR_HIDE_DURATION, new Tizen.NUI.PropertyValue(value));
552 /// 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.
554 /// <since_tizen> 3 </since_tizen>
555 public Tizen.NUI.PropertyArray ScrollPositionIntervals
559 Tizen.NUI.PropertyArray temp = new Tizen.NUI.PropertyArray();
560 GetProperty(ScrollBar.Property.SCROLL_POSITION_INTERVALS).Get(temp);
565 SetProperty(ScrollBar.Property.SCROLL_POSITION_INTERVALS, new Tizen.NUI.PropertyValue(value));
570 /// The minimum height for a variable size indicator.
572 /// <since_tizen> 3 </since_tizen>
573 public float IndicatorMinimumHeight
578 GetProperty(ScrollBar.Property.INDICATOR_MINIMUM_HEIGHT).Get(out temp);
583 SetProperty(ScrollBar.Property.INDICATOR_MINIMUM_HEIGHT, new Tizen.NUI.PropertyValue(value));
588 /// The padding at the start of the indicator. For example, the top if the scrollDirection is vertical.
590 /// <since_tizen> 3 </since_tizen>
591 public float IndicatorStartPadding
596 GetProperty(ScrollBar.Property.INDICATOR_START_PADDING).Get(out temp);
601 SetProperty(ScrollBar.Property.INDICATOR_START_PADDING, new Tizen.NUI.PropertyValue(value));
606 /// The padding at the end of the indicator. For example, the bottom if the scrollDirection is vertical.
608 /// <since_tizen> 3 </since_tizen>
609 public float IndicatorEndPadding
614 GetProperty(ScrollBar.Property.INDICATOR_END_PADDING).Get(out temp);
619 SetProperty(ScrollBar.Property.INDICATOR_END_PADDING, new Tizen.NUI.PropertyValue(value));