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 using System.ComponentModel;
19 using System.Runtime.InteropServices;
20 using Tizen.NUI.BaseComponents;
22 namespace Tizen.NUI.UIComponents
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 />
28 /// <since_tizen> 3 </since_tizen>
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 /// <since_tizen> 3 </since_tizen>
47 protected override void Dispose(DisposeTypes type)
54 if(type == DisposeTypes.Explicit)
57 //Release your own managed resources here.
58 //You should release all of your own disposable objects here.
61 //Release your own unmanaged resources here.
62 //You should not access any managed member here except static instance.
63 //because the execution order of Finalizes is non-deterministic.
65 if (_scrollBarScrollPositionIntervalReachedEventCallbackDelegate != null)
67 ScrollPositionIntervalReachedSignal().Disconnect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
70 if (_scrollBarPanFinishedEventCallbackDelegate != null)
72 PanFinishedSignal().Disconnect(_scrollBarPanFinishedEventCallbackDelegate);
75 if (swigCPtr.Handle != global::System.IntPtr.Zero)
80 NDalicPINVOKE.delete_ScrollBar(swigCPtr);
82 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
89 /// Event arguments that passed via the PanFinished event.
91 /// <since_tizen> 3 </since_tizen>
92 public class PanFinishedEventArgs : EventArgs
97 /// Event arguments that passed via the ScrollPositionIntervalReached event.
99 /// <since_tizen> 3 </since_tizen>
100 public class ScrollIntervalEventArgs : EventArgs
102 private float _currentScrollPosition;
105 /// The current scroll position of the scrollable content.
107 /// <since_tizen> 3 </since_tizen>
108 public float CurrentScrollPosition
112 return _currentScrollPosition;
116 _currentScrollPosition = value;
121 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
122 private delegate void PanFinishedEventCallbackDelegate();
123 private EventHandler<PanFinishedEventArgs> _scrollBarPanFinishedEventHandler;
124 private PanFinishedEventCallbackDelegate _scrollBarPanFinishedEventCallbackDelegate;
126 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
127 private delegate void ScrollPositionIntervalReachedEventCallbackDelegate();
128 private EventHandler<ScrollIntervalEventArgs> _scrollBarScrollPositionIntervalReachedEventHandler;
129 private ScrollPositionIntervalReachedEventCallbackDelegate _scrollBarScrollPositionIntervalReachedEventCallbackDelegate;
132 /// The event emitted when panning is finished on the scroll indicator.
134 /// <since_tizen> 3 </since_tizen>
135 public event EventHandler<PanFinishedEventArgs> PanFinished
139 if (_scrollBarPanFinishedEventHandler == null)
141 _scrollBarPanFinishedEventCallbackDelegate = (OnScrollBarPanFinished);
142 PanFinishedSignal().Connect(_scrollBarPanFinishedEventCallbackDelegate);
144 _scrollBarPanFinishedEventHandler += value;
148 _scrollBarPanFinishedEventHandler -= value;
149 if (_scrollBarPanFinishedEventHandler == null && PanFinishedSignal().Empty() == false)
151 PanFinishedSignal().Disconnect(_scrollBarPanFinishedEventCallbackDelegate);
156 // Callback for ScrollBar PanFinishedSignal
157 private void OnScrollBarPanFinished()
159 PanFinishedEventArgs e = new PanFinishedEventArgs();
161 if (_scrollBarPanFinishedEventHandler != null)
163 //here we send all data to user event handlers
164 _scrollBarPanFinishedEventHandler(this, e);
170 /// This is the event emitted when the current scroll position of the scrollable content.
172 /// <since_tizen> 3 </since_tizen>
173 public event EventHandler<ScrollIntervalEventArgs> ScrollInterval
177 if (_scrollBarScrollPositionIntervalReachedEventHandler == null)
179 _scrollBarScrollPositionIntervalReachedEventCallbackDelegate = (OnScrollBarScrollPositionIntervalReached);
180 ScrollPositionIntervalReachedSignal().Connect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
182 _scrollBarScrollPositionIntervalReachedEventHandler += value;
186 _scrollBarScrollPositionIntervalReachedEventHandler -= value;
187 if (_scrollBarScrollPositionIntervalReachedEventHandler == null && ScrollPositionIntervalReachedSignal().Empty() == false)
189 ScrollPositionIntervalReachedSignal().Disconnect(_scrollBarScrollPositionIntervalReachedEventCallbackDelegate);
194 // Callback for ScrollBar ScrollPositionIntervalReachedSignal
195 private void OnScrollBarScrollPositionIntervalReached()
197 ScrollIntervalEventArgs e = new ScrollIntervalEventArgs();
199 if (_scrollBarScrollPositionIntervalReachedEventHandler != null)
201 //here we send all data to user event handlers
202 _scrollBarScrollPositionIntervalReachedEventHandler(this, e);
207 internal new class Property
209 internal static readonly int SCROLL_DIRECTION = NDalicPINVOKE.ScrollBar_Property_SCROLL_DIRECTION_get();
210 internal static readonly int INDICATOR_HEIGHT_POLICY = NDalicPINVOKE.ScrollBar_Property_INDICATOR_HEIGHT_POLICY_get();
211 internal static readonly int INDICATOR_FIXED_HEIGHT = NDalicPINVOKE.ScrollBar_Property_INDICATOR_FIXED_HEIGHT_get();
212 internal static readonly int INDICATOR_SHOW_DURATION = NDalicPINVOKE.ScrollBar_Property_INDICATOR_SHOW_DURATION_get();
213 internal static readonly int INDICATOR_HIDE_DURATION = NDalicPINVOKE.ScrollBar_Property_INDICATOR_HIDE_DURATION_get();
214 internal static readonly int SCROLL_POSITION_INTERVALS = NDalicPINVOKE.ScrollBar_Property_SCROLL_POSITION_INTERVALS_get();
215 internal static readonly int INDICATOR_MINIMUM_HEIGHT = NDalicPINVOKE.ScrollBar_Property_INDICATOR_MINIMUM_HEIGHT_get();
216 internal static readonly int INDICATOR_START_PADDING = NDalicPINVOKE.ScrollBar_Property_INDICATOR_START_PADDING_get();
217 internal static readonly int INDICATOR_END_PADDING = NDalicPINVOKE.ScrollBar_Property_INDICATOR_END_PADDING_get();
221 /// Creates an initialized scrollbar.
223 /// <param name="direction">The direction of the scrollbar (either vertically or horizontally).</param>
224 /// <since_tizen> 3 </since_tizen>
225 public ScrollBar(ScrollBar.Direction direction) : this(NDalicPINVOKE.ScrollBar_New__SWIG_0((int)direction), true)
227 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
231 /// Creates an uninitialized scrollbar.
233 /// <since_tizen> 3 </since_tizen>
234 public ScrollBar() : this(NDalicPINVOKE.ScrollBar_New__SWIG_1(), true)
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239 internal ScrollBar(ScrollBar scrollBar) : this(NDalicPINVOKE.new_ScrollBar__SWIG_1(ScrollBar.getCPtr(scrollBar)), true)
241 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
245 /// Downcasts a handle to scrollBar handle.
247 /// <since_tizen> 3 </since_tizen>
248 /// Please do not use! this will be deprecated!
249 /// Instead please use as keyword.
250 [Obsolete("Please do not use! This will be deprecated! Please use as keyword instead!")]
251 [EditorBrowsable(EditorBrowsableState.Never)]
252 public new static ScrollBar DownCast(BaseHandle handle)
254 ScrollBar ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as ScrollBar;
255 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
259 internal void SetScrollPropertySource(Animatable handle, int propertyScrollPosition, int propertyMinScrollPosition, int propertyMaxScrollPosition, int propertyScrollContentSize)
261 NDalicPINVOKE.ScrollBar_SetScrollPropertySource(swigCPtr, Animatable.getCPtr(handle), propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
262 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 internal void SetScrollIndicator(View indicator)
267 NDalicPINVOKE.ScrollBar_SetScrollIndicator(swigCPtr, View.getCPtr(indicator));
268 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
271 internal View GetScrollIndicator()
273 View ret = new View(NDalicPINVOKE.ScrollBar_GetScrollIndicator(swigCPtr), true);
274 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
278 internal void SetScrollDirection(ScrollBar.Direction direction)
280 NDalicPINVOKE.ScrollBar_SetScrollDirection(swigCPtr, (int)direction);
281 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
284 internal ScrollBar.Direction GetScrollDirection()
286 ScrollBar.Direction ret = (ScrollBar.Direction)NDalicPINVOKE.ScrollBar_GetScrollDirection(swigCPtr);
287 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
291 internal void SetIndicatorHeightPolicy(ScrollBar.IndicatorHeightPolicyType policy)
293 NDalicPINVOKE.ScrollBar_SetIndicatorHeightPolicy(swigCPtr, (int)policy);
294 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297 internal ScrollBar.IndicatorHeightPolicyType GetIndicatorHeightPolicy()
299 ScrollBar.IndicatorHeightPolicyType ret = (ScrollBar.IndicatorHeightPolicyType)NDalicPINVOKE.ScrollBar_GetIndicatorHeightPolicy(swigCPtr);
300 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
304 internal void SetIndicatorFixedHeight(float height)
306 NDalicPINVOKE.ScrollBar_SetIndicatorFixedHeight(swigCPtr, height);
307 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310 internal float GetIndicatorFixedHeight()
312 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorFixedHeight(swigCPtr);
313 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
317 internal void SetIndicatorShowDuration(float durationSeconds)
319 NDalicPINVOKE.ScrollBar_SetIndicatorShowDuration(swigCPtr, durationSeconds);
320 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
323 internal float GetIndicatorShowDuration()
325 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorShowDuration(swigCPtr);
326 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
330 internal void SetIndicatorHideDuration(float durationSeconds)
332 NDalicPINVOKE.ScrollBar_SetIndicatorHideDuration(swigCPtr, durationSeconds);
333 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
336 internal float GetIndicatorHideDuration()
338 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorHideDuration(swigCPtr);
339 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
343 internal void ShowIndicator()
345 NDalicPINVOKE.ScrollBar_ShowIndicator(swigCPtr);
346 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
349 internal void HideIndicator()
351 NDalicPINVOKE.ScrollBar_HideIndicator(swigCPtr);
352 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355 internal VoidSignal PanFinishedSignal()
357 VoidSignal ret = new VoidSignal(NDalicPINVOKE.ScrollBar_PanFinishedSignal(swigCPtr), false);
358 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
362 internal FloatSignal ScrollPositionIntervalReachedSignal()
364 FloatSignal ret = new FloatSignal(NDalicPINVOKE.ScrollBar_ScrollPositionIntervalReachedSignal(swigCPtr), false);
365 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
370 /// The direction of the scrollbar.
372 /// <since_tizen> 3 </since_tizen>
373 public enum Direction
376 /// Scroll in the vertical direction
378 /// <since_tizen> 3 </since_tizen>
381 /// Scroll in the horizontal direction
383 /// <since_tizen> 3 </since_tizen>
388 /// The indicator height policy.
390 /// <since_tizen> 3 </since_tizen>
391 public enum IndicatorHeightPolicyType
394 /// Variable height changed dynamically according to the length of scroll content
396 /// <since_tizen> 3 </since_tizen>
399 /// Fixed height regardless of the length of scroll content
401 /// <since_tizen> 3 </since_tizen>
406 /// The direction of the scrollbar.
408 /// <since_tizen> 3 </since_tizen>
409 public Direction ScrollDirection
414 if (GetProperty(ScrollBar.Property.SCROLL_DIRECTION).Get(out temp) == false)
416 NUILog.Error("ScrollDirection get error!");
422 return Direction.Vertical;
424 return Direction.Horizontal;
426 return Direction.Vertical;
431 string valueToString = "";
434 case Direction.Vertical:
436 valueToString = "Vertical";
439 case Direction.Horizontal:
441 valueToString = "Horizontal";
446 valueToString = "Vertical";
450 SetProperty(ScrollBar.Property.SCROLL_DIRECTION, new Tizen.NUI.PropertyValue(valueToString));
455 /// The indicator height policy.
457 /// <since_tizen> 3 </since_tizen>
458 public IndicatorHeightPolicyType IndicatorHeightPolicy
463 if (GetProperty(ScrollBar.Property.INDICATOR_HEIGHT_POLICY).Get(out temp) == false)
465 NUILog.Error("IndicatorHeightPolicy get error!");
471 return IndicatorHeightPolicyType.Variable;
473 return IndicatorHeightPolicyType.Fixed;
475 return IndicatorHeightPolicyType.Variable;
480 string valueToString = "";
483 case IndicatorHeightPolicyType.Variable:
485 valueToString = "Variable";
488 case IndicatorHeightPolicyType.Fixed:
490 valueToString = "Fixed";
495 valueToString = "Variable";
499 SetProperty(ScrollBar.Property.INDICATOR_HEIGHT_POLICY, new Tizen.NUI.PropertyValue(valueToString));
504 /// The fixed height of the scroll indicator.
506 /// <since_tizen> 3 </since_tizen>
507 public float IndicatorFixedHeight
512 GetProperty(ScrollBar.Property.INDICATOR_FIXED_HEIGHT).Get(out temp);
517 SetProperty(ScrollBar.Property.INDICATOR_FIXED_HEIGHT, new Tizen.NUI.PropertyValue(value));
522 /// The duration in seconds for the scroll indicator to become fully visible.
524 /// <since_tizen> 3 </since_tizen>
525 public float IndicatorShowDuration
530 GetProperty(ScrollBar.Property.INDICATOR_SHOW_DURATION).Get(out temp);
535 SetProperty(ScrollBar.Property.INDICATOR_SHOW_DURATION, new Tizen.NUI.PropertyValue(value));
540 /// The duration in seconds for the scroll indicator to become fully invisible.
542 /// <since_tizen> 3 </since_tizen>
543 public float IndicatorHideDuration
548 GetProperty(ScrollBar.Property.INDICATOR_HIDE_DURATION).Get(out temp);
553 SetProperty(ScrollBar.Property.INDICATOR_HIDE_DURATION, new Tizen.NUI.PropertyValue(value));
558 /// 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.
560 /// <since_tizen> 3 </since_tizen>
561 public Tizen.NUI.PropertyArray ScrollPositionIntervals
565 Tizen.NUI.PropertyArray temp = new Tizen.NUI.PropertyArray();
566 GetProperty(ScrollBar.Property.SCROLL_POSITION_INTERVALS).Get(temp);
571 SetProperty(ScrollBar.Property.SCROLL_POSITION_INTERVALS, new Tizen.NUI.PropertyValue(value));
576 /// The minimum height for a variable size indicator.
578 /// <since_tizen> 3 </since_tizen>
579 public float IndicatorMinimumHeight
584 GetProperty(ScrollBar.Property.INDICATOR_MINIMUM_HEIGHT).Get(out temp);
589 SetProperty(ScrollBar.Property.INDICATOR_MINIMUM_HEIGHT, new Tizen.NUI.PropertyValue(value));
594 /// The padding at the start of the indicator. For example, the top if the scrollDirection is vertical.
596 /// <since_tizen> 3 </since_tizen>
597 public float IndicatorStartPadding
602 GetProperty(ScrollBar.Property.INDICATOR_START_PADDING).Get(out temp);
607 SetProperty(ScrollBar.Property.INDICATOR_START_PADDING, new Tizen.NUI.PropertyValue(value));
612 /// The padding at the end of the indicator. For example, the bottom if the scrollDirection is vertical.
614 /// <since_tizen> 3 </since_tizen>
615 public float IndicatorEndPadding
620 GetProperty(ScrollBar.Property.INDICATOR_END_PADDING).Get(out temp);
625 SetProperty(ScrollBar.Property.INDICATOR_END_PADDING, new Tizen.NUI.PropertyValue(value));