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();
244 internal void SetScrollPropertySource(Animatable handle, int propertyScrollPosition, int propertyMinScrollPosition, int propertyMaxScrollPosition, int propertyScrollContentSize)
246 NDalicPINVOKE.ScrollBar_SetScrollPropertySource(swigCPtr, Animatable.getCPtr(handle), propertyScrollPosition, propertyMinScrollPosition, propertyMaxScrollPosition, propertyScrollContentSize);
247 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
250 internal void SetScrollIndicator(View indicator)
252 NDalicPINVOKE.ScrollBar_SetScrollIndicator(swigCPtr, View.getCPtr(indicator));
253 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
256 internal View GetScrollIndicator()
258 View ret = new View(NDalicPINVOKE.ScrollBar_GetScrollIndicator(swigCPtr), true);
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
263 internal void SetScrollDirection(ScrollBar.Direction direction)
265 NDalicPINVOKE.ScrollBar_SetScrollDirection(swigCPtr, (int)direction);
266 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
269 internal ScrollBar.Direction GetScrollDirection()
271 ScrollBar.Direction ret = (ScrollBar.Direction)NDalicPINVOKE.ScrollBar_GetScrollDirection(swigCPtr);
272 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276 internal void SetIndicatorHeightPolicy(ScrollBar.IndicatorHeightPolicyType policy)
278 NDalicPINVOKE.ScrollBar_SetIndicatorHeightPolicy(swigCPtr, (int)policy);
279 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
282 internal ScrollBar.IndicatorHeightPolicyType GetIndicatorHeightPolicy()
284 ScrollBar.IndicatorHeightPolicyType ret = (ScrollBar.IndicatorHeightPolicyType)NDalicPINVOKE.ScrollBar_GetIndicatorHeightPolicy(swigCPtr);
285 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289 internal void SetIndicatorFixedHeight(float height)
291 NDalicPINVOKE.ScrollBar_SetIndicatorFixedHeight(swigCPtr, height);
292 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
295 internal float GetIndicatorFixedHeight()
297 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorFixedHeight(swigCPtr);
298 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
302 internal void SetIndicatorShowDuration(float durationSeconds)
304 NDalicPINVOKE.ScrollBar_SetIndicatorShowDuration(swigCPtr, durationSeconds);
305 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
308 internal float GetIndicatorShowDuration()
310 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorShowDuration(swigCPtr);
311 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
315 internal void SetIndicatorHideDuration(float durationSeconds)
317 NDalicPINVOKE.ScrollBar_SetIndicatorHideDuration(swigCPtr, durationSeconds);
318 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
321 internal float GetIndicatorHideDuration()
323 float ret = NDalicPINVOKE.ScrollBar_GetIndicatorHideDuration(swigCPtr);
324 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
328 internal void ShowIndicator()
330 NDalicPINVOKE.ScrollBar_ShowIndicator(swigCPtr);
331 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 internal void HideIndicator()
336 NDalicPINVOKE.ScrollBar_HideIndicator(swigCPtr);
337 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
340 internal VoidSignal PanFinishedSignal()
342 VoidSignal ret = new VoidSignal(NDalicPINVOKE.ScrollBar_PanFinishedSignal(swigCPtr), false);
343 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
347 internal FloatSignal ScrollPositionIntervalReachedSignal()
349 FloatSignal ret = new FloatSignal(NDalicPINVOKE.ScrollBar_ScrollPositionIntervalReachedSignal(swigCPtr), false);
350 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355 /// The direction of the scrollbar.
357 /// <since_tizen> 3 </since_tizen>
358 public enum Direction
361 /// Scroll in the vertical direction
363 /// <since_tizen> 3 </since_tizen>
366 /// Scroll in the horizontal direction
368 /// <since_tizen> 3 </since_tizen>
373 /// The indicator height policy.
375 /// <since_tizen> 3 </since_tizen>
376 public enum IndicatorHeightPolicyType
379 /// Variable height changed dynamically according to the length of scroll content
381 /// <since_tizen> 3 </since_tizen>
384 /// Fixed height regardless of the length of scroll content
386 /// <since_tizen> 3 </since_tizen>
391 /// The direction of the scrollbar.
393 /// <since_tizen> 3 </since_tizen>
394 public Direction ScrollDirection
399 if (GetProperty(ScrollBar.Property.SCROLL_DIRECTION).Get(out temp) == false)
401 NUILog.Error("ScrollDirection get error!");
407 return Direction.Vertical;
409 return Direction.Horizontal;
411 return Direction.Vertical;
416 string valueToString = "";
419 case Direction.Vertical:
421 valueToString = "Vertical";
424 case Direction.Horizontal:
426 valueToString = "Horizontal";
431 valueToString = "Vertical";
435 SetProperty(ScrollBar.Property.SCROLL_DIRECTION, new Tizen.NUI.PropertyValue(valueToString));
440 /// The indicator height policy.
442 /// <since_tizen> 3 </since_tizen>
443 public IndicatorHeightPolicyType IndicatorHeightPolicy
448 if (GetProperty(ScrollBar.Property.INDICATOR_HEIGHT_POLICY).Get(out temp) == false)
450 NUILog.Error("IndicatorHeightPolicy get error!");
456 return IndicatorHeightPolicyType.Variable;
458 return IndicatorHeightPolicyType.Fixed;
460 return IndicatorHeightPolicyType.Variable;
465 string valueToString = "";
468 case IndicatorHeightPolicyType.Variable:
470 valueToString = "Variable";
473 case IndicatorHeightPolicyType.Fixed:
475 valueToString = "Fixed";
480 valueToString = "Variable";
484 SetProperty(ScrollBar.Property.INDICATOR_HEIGHT_POLICY, new Tizen.NUI.PropertyValue(valueToString));
489 /// The fixed height of the scroll indicator.
491 /// <since_tizen> 3 </since_tizen>
492 public float IndicatorFixedHeight
497 GetProperty(ScrollBar.Property.INDICATOR_FIXED_HEIGHT).Get(out temp);
502 SetProperty(ScrollBar.Property.INDICATOR_FIXED_HEIGHT, new Tizen.NUI.PropertyValue(value));
507 /// The duration in seconds for the scroll indicator to become fully visible.
509 /// <since_tizen> 3 </since_tizen>
510 public float IndicatorShowDuration
515 GetProperty(ScrollBar.Property.INDICATOR_SHOW_DURATION).Get(out temp);
520 SetProperty(ScrollBar.Property.INDICATOR_SHOW_DURATION, new Tizen.NUI.PropertyValue(value));
525 /// The duration in seconds for the scroll indicator to become fully invisible.
527 /// <since_tizen> 3 </since_tizen>
528 public float IndicatorHideDuration
533 GetProperty(ScrollBar.Property.INDICATOR_HIDE_DURATION).Get(out temp);
538 SetProperty(ScrollBar.Property.INDICATOR_HIDE_DURATION, new Tizen.NUI.PropertyValue(value));
543 /// 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.
545 /// <since_tizen> 3 </since_tizen>
546 public Tizen.NUI.PropertyArray ScrollPositionIntervals
550 Tizen.NUI.PropertyArray temp = new Tizen.NUI.PropertyArray();
551 GetProperty(ScrollBar.Property.SCROLL_POSITION_INTERVALS).Get(temp);
556 SetProperty(ScrollBar.Property.SCROLL_POSITION_INTERVALS, new Tizen.NUI.PropertyValue(value));
561 /// The minimum height for a variable size indicator.
563 /// <since_tizen> 3 </since_tizen>
564 public float IndicatorMinimumHeight
569 GetProperty(ScrollBar.Property.INDICATOR_MINIMUM_HEIGHT).Get(out temp);
574 SetProperty(ScrollBar.Property.INDICATOR_MINIMUM_HEIGHT, new Tizen.NUI.PropertyValue(value));
579 /// The padding at the start of the indicator. For example, the top if the scrollDirection is vertical.
581 /// <since_tizen> 3 </since_tizen>
582 public float IndicatorStartPadding
587 GetProperty(ScrollBar.Property.INDICATOR_START_PADDING).Get(out temp);
592 SetProperty(ScrollBar.Property.INDICATOR_START_PADDING, new Tizen.NUI.PropertyValue(value));
597 /// The padding at the end of the indicator. For example, the bottom if the scrollDirection is vertical.
599 /// <since_tizen> 3 </since_tizen>
600 public float IndicatorEndPadding
605 GetProperty(ScrollBar.Property.INDICATOR_END_PADDING).Get(out temp);
610 SetProperty(ScrollBar.Property.INDICATOR_END_PADDING, new Tizen.NUI.PropertyValue(value));