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 /// The slider is a control to enable sliding an indicator between two values.
27 public class Slider : View
29 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
31 internal Slider(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Slider_SWIGUpcast(cPtr), cMemoryOwn)
33 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
36 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Slider obj)
38 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
44 protected override void Dispose(DisposeTypes type)
51 if (type == DisposeTypes.Explicit)
54 //Release your own managed resources here.
55 //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 (_sliderValueChangedCallbackDelegate != null)
65 ValueChangedSignal().Disconnect(_sliderValueChangedCallbackDelegate);
68 if (_sliderSlidingFinishedCallbackDelegate != null)
70 SlidingFinishedSignal().Disconnect(_sliderSlidingFinishedCallbackDelegate);
73 if (_sliderMarkReachedCallbackDelegate != null)
75 MarkReachedSignal().Disconnect(_sliderMarkReachedCallbackDelegate);
78 if (swigCPtr.Handle != global::System.IntPtr.Zero)
83 NDalicPINVOKE.delete_Slider(swigCPtr);
85 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
92 /// The ValueChanged event arguments.
94 public class ValueChangedEventArgs : EventArgs
96 private Slider _slider;
97 private float _slideValue;
102 /// <since_tizen> 3 </since_tizen>
116 /// The slider value.
118 /// <since_tizen> 3 </since_tizen>
119 public float SlideValue
133 /// The SlidingFinished event arguments.
135 public class SlidingFinishedEventArgs : EventArgs
137 private Slider _slider;
138 private float _slideValue;
143 /// <since_tizen> 3 </since_tizen>
157 /// The slider value.
159 /// <since_tizen> 3 </since_tizen>
160 public float SlideValue
174 /// The MarkReached event arguments.
176 public class MarkReachedEventArgs : EventArgs
178 private Slider _slider;
179 private int _slideValue;
184 /// <since_tizen> 3 </since_tizen>
198 /// The slider value.
200 /// <since_tizen> 3 </since_tizen>
201 public int SlideValue
215 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
216 private delegate bool ValueChangedCallbackDelegate(IntPtr slider, float slideValue);
217 private EventHandlerWithReturnType<object, ValueChangedEventArgs, bool> _sliderValueChangedEventHandler;
218 private ValueChangedCallbackDelegate _sliderValueChangedCallbackDelegate;
220 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
221 private delegate bool SlidingFinishedCallbackDelegate(IntPtr slider, float slideValue);
222 private EventHandlerWithReturnType<object, SlidingFinishedEventArgs, bool> _sliderSlidingFinishedEventHandler;
223 private SlidingFinishedCallbackDelegate _sliderSlidingFinishedCallbackDelegate;
225 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
226 private delegate bool MarkReachedCallbackDelegate(IntPtr slider, int slideValue);
227 private EventHandlerWithReturnType<object, MarkReachedEventArgs, bool> _sliderMarkReachedEventHandler;
228 private MarkReachedCallbackDelegate _sliderMarkReachedCallbackDelegate;
231 /// An event emitted when the slider value changes.
233 /// <since_tizen> 3 </since_tizen>
234 public event EventHandlerWithReturnType<object, ValueChangedEventArgs, bool> ValueChanged
238 if (_sliderValueChangedEventHandler == null)
240 _sliderValueChangedCallbackDelegate = (OnValueChanged);
241 ValueChangedSignal().Connect(_sliderValueChangedCallbackDelegate);
243 _sliderValueChangedEventHandler += value;
247 _sliderValueChangedEventHandler -= value;
248 if (_sliderValueChangedEventHandler == null && ValueChangedSignal().Empty() == false)
250 ValueChangedSignal().Disconnect(_sliderValueChangedCallbackDelegate);
255 // Callback for Slider ValueChanged signal
256 private bool OnValueChanged(IntPtr slider, float slideValue)
258 ValueChangedEventArgs e = new ValueChangedEventArgs();
260 // Populate all members of "e" (ValueChangedEventArgs) with real page
261 e.Slider = Slider.GetSliderFromPtr(slider);
262 e.SlideValue = slideValue;
264 if (_sliderValueChangedEventHandler != null)
266 //here we send all page to user event handlers
267 return _sliderValueChangedEventHandler(this, e);
273 /// An event emitted when the sliding is finished.
275 /// <since_tizen> 3 </since_tizen>
276 public event EventHandlerWithReturnType<object, SlidingFinishedEventArgs, bool> SlidingFinished
280 if (_sliderSlidingFinishedEventHandler == null)
282 _sliderSlidingFinishedCallbackDelegate = (OnSlidingFinished);
283 SlidingFinishedSignal().Connect(_sliderSlidingFinishedCallbackDelegate);
285 _sliderSlidingFinishedEventHandler += value;
289 _sliderSlidingFinishedEventHandler -= value;
290 if (_sliderSlidingFinishedEventHandler == null && SlidingFinishedSignal().Empty() == false)
292 SlidingFinishedSignal().Disconnect(_sliderSlidingFinishedCallbackDelegate);
297 // Callback for Slider SlidingFinished signal
298 private bool OnSlidingFinished(IntPtr slider, float slideValue)
300 SlidingFinishedEventArgs e = new SlidingFinishedEventArgs();
302 // Populate all members of "e" (SlidingFinishedEventArgs) with real page
303 e.Slider = Slider.GetSliderFromPtr(slider);
304 e.SlideValue = slideValue;
306 if (_sliderSlidingFinishedEventHandler != null)
308 //here we send all page to user event handlers
309 return _sliderSlidingFinishedEventHandler(this, e);
315 /// An event emitted when the slider handle reaches a mark.
317 /// <since_tizen> 3 </since_tizen>
318 public event EventHandlerWithReturnType<object, MarkReachedEventArgs, bool> MarkReached
322 if (_sliderMarkReachedEventHandler == null)
324 _sliderMarkReachedCallbackDelegate = (OnMarkReached);
325 MarkReachedSignal().Connect(_sliderMarkReachedCallbackDelegate);
327 _sliderMarkReachedEventHandler += value;
331 _sliderMarkReachedEventHandler -= value;
332 if (_sliderMarkReachedEventHandler == null && MarkReachedSignal().Empty() == false)
334 MarkReachedSignal().Disconnect(_sliderMarkReachedCallbackDelegate);
339 // Callback for Slider MarkReached signal
340 private bool OnMarkReached(IntPtr slider, int slideValue)
342 MarkReachedEventArgs e = new MarkReachedEventArgs();
344 // Populate all members of "e" (MarkReachedEventArgs) with real page
345 e.Slider = Slider.GetSliderFromPtr(slider);
346 e.SlideValue = slideValue;
348 if (_sliderMarkReachedEventHandler != null)
350 //here we send all page to user event handlers
351 return _sliderMarkReachedEventHandler(this, e);
357 /// Gets the slider from the pointer.
359 /// <param name="cPtr">The pointer of the slider.</param>
360 /// <returns>The object of the slider type.</returns>
361 internal static Slider GetSliderFromPtr(global::System.IntPtr cPtr)
363 Slider ret = new Slider(cPtr, false);
364 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
368 internal new class Property : global::System.IDisposable
370 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
371 protected bool swigCMemOwn;
373 internal Property(global::System.IntPtr cPtr, bool cMemoryOwn)
375 swigCMemOwn = cMemoryOwn;
376 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
379 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Property obj)
381 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
384 //A Flag to check who called Dispose(). (By User or DisposeQueue)
385 private bool isDisposeQueued = false;
386 //A Flat to check if it is already disposed.
387 protected bool disposed = false;
391 if (!isDisposeQueued)
393 isDisposeQueued = true;
394 DisposeQueue.Instance.Add(this);
398 /// <since_tizen> 3 </since_tizen>
399 public void Dispose()
401 //Throw excpetion if Dispose() is called in separate thread.
402 if (!Window.IsInstalled())
404 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
409 Dispose(DisposeTypes.Implicit);
413 Dispose(DisposeTypes.Explicit);
414 System.GC.SuppressFinalize(this);
418 protected virtual void Dispose(DisposeTypes type)
425 if (type == DisposeTypes.Explicit)
428 //Release your own managed resources here.
429 //You should release all of your own disposable objects here.
433 //Release your own unmanaged resources here.
434 //You should not access any managed member here except static instance.
435 //because the execution order of Finalizes is non-deterministic.
437 if (swigCPtr.Handle != global::System.IntPtr.Zero)
442 NDalicPINVOKE.delete_Slider_Property(swigCPtr);
444 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
450 internal Property() : this(NDalicPINVOKE.new_Slider_Property(), true)
452 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
455 internal static readonly int LOWER_BOUND = NDalicPINVOKE.Slider_Property_LOWER_BOUND_get();
456 internal static readonly int UPPER_BOUND = NDalicPINVOKE.Slider_Property_UPPER_BOUND_get();
457 internal static readonly int VALUE = NDalicPINVOKE.Slider_Property_VALUE_get();
458 internal static readonly int TRACK_VISUAL = NDalicPINVOKE.Slider_Property_TRACK_VISUAL_get();
459 internal static readonly int HANDLE_VISUAL = NDalicPINVOKE.Slider_Property_HANDLE_VISUAL_get();
460 internal static readonly int PROGRESS_VISUAL = NDalicPINVOKE.Slider_Property_PROGRESS_VISUAL_get();
461 internal static readonly int POPUP_VISUAL = NDalicPINVOKE.Slider_Property_POPUP_VISUAL_get();
462 internal static readonly int POPUP_ARROW_VISUAL = NDalicPINVOKE.Slider_Property_POPUP_ARROW_VISUAL_get();
463 internal static readonly int DISABLED_COLOR = NDalicPINVOKE.Slider_Property_DISABLED_COLOR_get();
464 internal static readonly int VALUE_PRECISION = NDalicPINVOKE.Slider_Property_VALUE_PRECISION_get();
465 internal static readonly int SHOW_POPUP = NDalicPINVOKE.Slider_Property_SHOW_POPUP_get();
466 internal static readonly int SHOW_VALUE = NDalicPINVOKE.Slider_Property_SHOW_VALUE_get();
467 internal static readonly int MARKS = NDalicPINVOKE.Slider_Property_MARKS_get();
468 internal static readonly int SNAP_TO_MARKS = NDalicPINVOKE.Slider_Property_SNAP_TO_MARKS_get();
469 internal static readonly int MARK_TOLERANCE = NDalicPINVOKE.Slider_Property_MARK_TOLERANCE_get();
474 /// Creates the slider control.
476 /// <since_tizen> 3 </since_tizen>
477 public Slider() : this(NDalicPINVOKE.Slider_New(), true)
479 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
482 internal Slider(Slider handle) : this(NDalicPINVOKE.new_Slider__SWIG_1(Slider.getCPtr(handle)), true)
484 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
487 internal Slider Assign(Slider handle)
489 Slider ret = new Slider(NDalicPINVOKE.Slider_Assign(swigCPtr, Slider.getCPtr(handle)), false);
490 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
495 /// Downcasts an object handle to the slider.<br>
496 /// If the handle points to a slider, then the downcast produces a valid handle.<br>
497 /// If not, then the returned handle is left uninitialized.<br>
499 /// <param name="handle">The handle to an object.</param>
500 /// <returns>The handle to a slider or an uninitialized handle.</returns>
501 /// <since_tizen> 3 </since_tizen>
502 public new static Slider DownCast(BaseHandle handle)
504 Slider ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Slider;
505 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
509 internal SliderValueChangedSignal ValueChangedSignal()
511 SliderValueChangedSignal ret = new SliderValueChangedSignal(NDalicPINVOKE.Slider_ValueChangedSignal(swigCPtr), false);
512 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
516 internal SliderValueChangedSignal SlidingFinishedSignal()
518 SliderValueChangedSignal ret = new SliderValueChangedSignal(NDalicPINVOKE.Slider_SlidingFinishedSignal(swigCPtr), false);
519 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
523 internal SliderMarkReachedSignal MarkReachedSignal()
525 SliderMarkReachedSignal ret = new SliderMarkReachedSignal(NDalicPINVOKE.Slider_MarkReachedSignal(swigCPtr), false);
526 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
531 /// The lower bound property.
533 /// <since_tizen> 3 </since_tizen>
534 public float LowerBound
539 GetProperty(Slider.Property.LOWER_BOUND).Get(out temp);
544 SetProperty(Slider.Property.LOWER_BOUND, new Tizen.NUI.PropertyValue(value));
549 /// The upper bound property.
551 /// <since_tizen> 3 </since_tizen>
552 public float UpperBound
557 GetProperty(Slider.Property.UPPER_BOUND).Get(out temp);
562 SetProperty(Slider.Property.UPPER_BOUND, new Tizen.NUI.PropertyValue(value));
567 /// The value property.
569 /// <since_tizen> 3 </since_tizen>
575 GetProperty(Slider.Property.VALUE).Get(out temp);
580 SetProperty(Slider.Property.VALUE, new Tizen.NUI.PropertyValue(value));
585 /// The track visual property.
587 /// <since_tizen> 3 </since_tizen>
588 public PropertyMap TrackVisual
592 PropertyMap temp = new PropertyMap();
593 GetProperty(Slider.Property.TRACK_VISUAL).Get(temp);
598 SetProperty(Slider.Property.TRACK_VISUAL, new Tizen.NUI.PropertyValue(value));
603 /// The handle visual property.
605 /// <since_tizen> 3 </since_tizen>
606 public PropertyMap HandleVisual
610 PropertyMap temp = new PropertyMap();
611 GetProperty(Slider.Property.HANDLE_VISUAL).Get(temp);
616 SetProperty(Slider.Property.HANDLE_VISUAL, new Tizen.NUI.PropertyValue(value));
621 /// The progress visual property.
623 /// <since_tizen> 3 </since_tizen>
624 public PropertyMap ProgressVisual
628 PropertyMap temp = new PropertyMap();
629 GetProperty(Slider.Property.PROGRESS_VISUAL).Get(temp);
634 SetProperty(Slider.Property.PROGRESS_VISUAL, new Tizen.NUI.PropertyValue(value));
639 /// The popup visual property.
641 /// <since_tizen> 3 </since_tizen>
642 public PropertyMap PopupVisual
646 PropertyMap temp = new PropertyMap();
647 GetProperty(Slider.Property.POPUP_VISUAL).Get(temp);
652 SetProperty(Slider.Property.POPUP_VISUAL, new Tizen.NUI.PropertyValue(value));
657 /// The popup arrow visual property.
659 /// <since_tizen> 3 </since_tizen>
660 public PropertyMap PopupArrowVisual
664 PropertyMap temp = new PropertyMap();
665 GetProperty(Slider.Property.POPUP_ARROW_VISUAL).Get(temp);
670 SetProperty(Slider.Property.POPUP_ARROW_VISUAL, new Tizen.NUI.PropertyValue(value));
675 /// The disable color property.
677 /// <since_tizen> 3 </since_tizen>
678 public Vector4 DisabledColor
682 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
683 GetProperty(Slider.Property.DISABLED_COLOR).Get(temp);
688 SetProperty(Slider.Property.DISABLED_COLOR, new Tizen.NUI.PropertyValue(value));
693 /// The value precision property.
695 /// <since_tizen> 3 </since_tizen>
696 public int ValuePrecision
701 GetProperty(Slider.Property.VALUE_PRECISION).Get(out temp);
706 SetProperty(Slider.Property.VALUE_PRECISION, new Tizen.NUI.PropertyValue(value));
711 /// The show popup property.
713 /// <since_tizen> 3 </since_tizen>
714 public bool ShowPopup
719 GetProperty(Slider.Property.SHOW_POPUP).Get(out temp);
724 SetProperty(Slider.Property.SHOW_POPUP, new Tizen.NUI.PropertyValue(value));
729 /// The show value property.
731 /// <since_tizen> 3 </since_tizen>
732 public bool ShowValue
737 GetProperty(Slider.Property.SHOW_VALUE).Get(out temp);
742 SetProperty(Slider.Property.SHOW_VALUE, new Tizen.NUI.PropertyValue(value));
747 /// The marks property.
749 /// <since_tizen> 3 </since_tizen>
750 public Tizen.NUI.PropertyArray Marks
754 Tizen.NUI.PropertyArray temp = new Tizen.NUI.PropertyArray();
755 GetProperty(Slider.Property.MARKS).Get(temp);
760 SetProperty(Slider.Property.MARKS, new Tizen.NUI.PropertyValue(value));
765 /// The snap to marks property.
767 /// <since_tizen> 3 </since_tizen>
768 public bool SnapToMarks
773 GetProperty(Slider.Property.SNAP_TO_MARKS).Get(out temp);
778 SetProperty(Slider.Property.SNAP_TO_MARKS, new Tizen.NUI.PropertyValue(value));
783 /// The mark tolerance property.
785 /// <since_tizen> 3 </since_tizen>
786 public float MarkTolerance
791 GetProperty(Slider.Property.MARK_TOLERANCE).Get(out temp);
796 SetProperty(Slider.Property.MARK_TOLERANCE, new Tizen.NUI.PropertyValue(value));