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 /// 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 (swigCPtr.Handle != global::System.IntPtr.Zero)
68 NDalicPINVOKE.delete_Slider(swigCPtr);
70 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
77 /// Value changed event arguments.
79 public class ValueChangedEventArgs : EventArgs
81 private Slider _slider;
82 private float _slideValue;
102 public float SlideValue
116 /// Sliding finished event arguments.
118 public class SlidingFinishedEventArgs : EventArgs
120 private Slider _slider;
121 private float _slideValue;
141 public float SlideValue
155 /// Mark reached event arguments.
157 public class MarkReachedEventArgs : EventArgs
159 private Slider _slider;
160 private int _slideValue;
180 public int SlideValue
194 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
195 private delegate bool ValueChangedCallbackDelegate(IntPtr slider, float slideValue);
196 private EventHandlerWithReturnType<object, ValueChangedEventArgs, bool> _sliderValueChangedEventHandler;
197 private ValueChangedCallbackDelegate _sliderValueChangedCallbackDelegate;
199 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
200 private delegate bool SlidingFinishedCallbackDelegate(IntPtr slider, float slideValue);
201 private EventHandlerWithReturnType<object, SlidingFinishedEventArgs, bool> _sliderSlidingFinishedEventHandler;
202 private SlidingFinishedCallbackDelegate _sliderSlidingFinishedCallbackDelegate;
204 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
205 private delegate bool MarkReachedCallbackDelegate(IntPtr slider, int slideValue);
206 private EventHandlerWithReturnType<object, MarkReachedEventArgs, bool> _sliderMarkReachedEventHandler;
207 private MarkReachedCallbackDelegate _sliderMarkReachedCallbackDelegate;
210 /// Event emitted when the slider value changes.
212 public event EventHandlerWithReturnType<object, ValueChangedEventArgs, bool> ValueChanged
216 if (_sliderValueChangedEventHandler == null)
218 _sliderValueChangedCallbackDelegate = (OnValueChanged);
219 ValueChangedSignal().Connect(_sliderValueChangedCallbackDelegate);
221 _sliderValueChangedEventHandler += value;
225 _sliderValueChangedEventHandler -= value;
226 if (_sliderValueChangedEventHandler == null && ValueChangedSignal().Empty() == false)
228 ValueChangedSignal().Disconnect(_sliderValueChangedCallbackDelegate);
233 // Callback for Slider ValueChanged signal
234 private bool OnValueChanged(IntPtr slider, float slideValue)
236 ValueChangedEventArgs e = new ValueChangedEventArgs();
238 // Populate all members of "e" (ValueChangedEventArgs) with real page
239 e.Slider = Slider.GetSliderFromPtr(slider);
240 e.SlideValue = slideValue;
242 if (_sliderValueChangedEventHandler != null)
244 //here we send all page to user event handlers
245 return _sliderValueChangedEventHandler(this, e);
251 /// Event emitted when the sliding is finished.
253 public event EventHandlerWithReturnType<object, SlidingFinishedEventArgs, bool> SlidingFinished
257 if (_sliderSlidingFinishedEventHandler == null)
259 _sliderSlidingFinishedCallbackDelegate = (OnSlidingFinished);
260 SlidingFinishedSignal().Connect(_sliderSlidingFinishedCallbackDelegate);
262 _sliderSlidingFinishedEventHandler += value;
266 _sliderSlidingFinishedEventHandler -= value;
267 if (_sliderSlidingFinishedEventHandler == null && SlidingFinishedSignal().Empty() == false)
269 SlidingFinishedSignal().Disconnect(_sliderSlidingFinishedCallbackDelegate);
274 // Callback for Slider SlidingFinished signal
275 private bool OnSlidingFinished(IntPtr slider, float slideValue)
277 SlidingFinishedEventArgs e = new SlidingFinishedEventArgs();
279 // Populate all members of "e" (SlidingFinishedEventArgs) with real page
280 e.Slider = Slider.GetSliderFromPtr(slider);
281 e.SlideValue = slideValue;
283 if (_sliderSlidingFinishedEventHandler != null)
285 //here we send all page to user event handlers
286 return _sliderSlidingFinishedEventHandler(this, e);
292 /// Event emitted when the slider handle reaches a mark.
294 public event EventHandlerWithReturnType<object, MarkReachedEventArgs, bool> MarkReached
298 if (_sliderMarkReachedEventHandler == null)
300 _sliderMarkReachedCallbackDelegate = (OnMarkReached);
301 MarkReachedSignal().Connect(_sliderMarkReachedCallbackDelegate);
303 _sliderMarkReachedEventHandler += value;
307 _sliderMarkReachedEventHandler -= value;
308 if (_sliderMarkReachedEventHandler == null && MarkReachedSignal().Empty() == false)
310 MarkReachedSignal().Disconnect(_sliderMarkReachedCallbackDelegate);
315 // Callback for Slider MarkReached signal
316 private bool OnMarkReached(IntPtr slider, int slideValue)
318 MarkReachedEventArgs e = new MarkReachedEventArgs();
320 // Populate all members of "e" (MarkReachedEventArgs) with real page
321 e.Slider = Slider.GetSliderFromPtr(slider);
322 e.SlideValue = slideValue;
324 if (_sliderMarkReachedEventHandler != null)
326 //here we send all page to user event handlers
327 return _sliderMarkReachedEventHandler(this, e);
333 /// Get Slider from the pointer.
335 /// <param name="cPtr">The pointer of Slider</param>
336 /// <returns>Object of Slider type</returns>
337 internal static Slider GetSliderFromPtr(global::System.IntPtr cPtr)
339 Slider ret = new Slider(cPtr, false);
340 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
344 internal class Property : global::System.IDisposable
346 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
347 protected bool swigCMemOwn;
349 internal Property(global::System.IntPtr cPtr, bool cMemoryOwn)
351 swigCMemOwn = cMemoryOwn;
352 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
355 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Property obj)
357 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
360 //A Flag to check who called Dispose(). (By User or DisposeQueue)
361 private bool isDisposeQueued = false;
362 //A Flat to check if it is already disposed.
363 protected bool disposed = false;
367 if (!isDisposeQueued)
369 isDisposeQueued = true;
370 DisposeQueue.Instance.Add(this);
374 public void Dispose()
376 //Throw excpetion if Dispose() is called in separate thread.
377 if (!Window.IsInstalled())
379 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
384 Dispose(DisposeTypes.Implicit);
388 Dispose(DisposeTypes.Explicit);
389 System.GC.SuppressFinalize(this);
393 protected virtual void Dispose(DisposeTypes type)
400 if (type == DisposeTypes.Explicit)
403 //Release your own managed resources here.
404 //You should release all of your own disposable objects here.
408 //Release your own unmanaged resources here.
409 //You should not access any managed member here except static instance.
410 //because the execution order of Finalizes is non-deterministic.
412 if (swigCPtr.Handle != global::System.IntPtr.Zero)
417 NDalicPINVOKE.delete_Slider_Property(swigCPtr);
419 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
425 internal Property() : this(NDalicPINVOKE.new_Slider_Property(), true)
427 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
430 internal static readonly int LOWER_BOUND = NDalicPINVOKE.Slider_Property_LOWER_BOUND_get();
431 internal static readonly int UPPER_BOUND = NDalicPINVOKE.Slider_Property_UPPER_BOUND_get();
432 internal static readonly int VALUE = NDalicPINVOKE.Slider_Property_VALUE_get();
433 internal static readonly int TRACK_VISUAL = NDalicPINVOKE.Slider_Property_TRACK_VISUAL_get();
434 internal static readonly int HANDLE_VISUAL = NDalicPINVOKE.Slider_Property_HANDLE_VISUAL_get();
435 internal static readonly int PROGRESS_VISUAL = NDalicPINVOKE.Slider_Property_PROGRESS_VISUAL_get();
436 internal static readonly int POPUP_VISUAL = NDalicPINVOKE.Slider_Property_POPUP_VISUAL_get();
437 internal static readonly int POPUP_ARROW_VISUAL = NDalicPINVOKE.Slider_Property_POPUP_ARROW_VISUAL_get();
438 internal static readonly int DISABLED_COLOR = NDalicPINVOKE.Slider_Property_DISABLED_COLOR_get();
439 internal static readonly int VALUE_PRECISION = NDalicPINVOKE.Slider_Property_VALUE_PRECISION_get();
440 internal static readonly int SHOW_POPUP = NDalicPINVOKE.Slider_Property_SHOW_POPUP_get();
441 internal static readonly int SHOW_VALUE = NDalicPINVOKE.Slider_Property_SHOW_VALUE_get();
442 internal static readonly int MARKS = NDalicPINVOKE.Slider_Property_MARKS_get();
443 internal static readonly int SNAP_TO_MARKS = NDalicPINVOKE.Slider_Property_SNAP_TO_MARKS_get();
444 internal static readonly int MARK_TOLERANCE = NDalicPINVOKE.Slider_Property_MARK_TOLERANCE_get();
449 /// Creates the Slider control.
451 public Slider() : this(NDalicPINVOKE.Slider_New(), true)
453 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
456 internal Slider(Slider handle) : this(NDalicPINVOKE.new_Slider__SWIG_1(Slider.getCPtr(handle)), true)
458 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
461 internal Slider Assign(Slider handle)
463 Slider ret = new Slider(NDalicPINVOKE.Slider_Assign(swigCPtr, Slider.getCPtr(handle)), false);
464 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
469 /// Downcasts an Object handle to Slider.<br>
470 /// If handle points to a Slider, the downcast produces valid handle.<br>
471 /// If not, the returned handle is left uninitialized.<br>
473 /// <param name="handle">Handle to an object</param>
474 /// <returns>Handle to a Slider or an uninitialized handle</returns>
475 public new static Slider DownCast(BaseHandle handle)
477 Slider ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Slider;
478 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
482 internal SliderValueChangedSignal ValueChangedSignal()
484 SliderValueChangedSignal ret = new SliderValueChangedSignal(NDalicPINVOKE.Slider_ValueChangedSignal(swigCPtr), false);
485 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
489 internal SliderValueChangedSignal SlidingFinishedSignal()
491 SliderValueChangedSignal ret = new SliderValueChangedSignal(NDalicPINVOKE.Slider_SlidingFinishedSignal(swigCPtr), false);
492 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
496 internal SliderMarkReachedSignal MarkReachedSignal()
498 SliderMarkReachedSignal ret = new SliderMarkReachedSignal(NDalicPINVOKE.Slider_MarkReachedSignal(swigCPtr), false);
499 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
504 /// Lower bound property
506 public float LowerBound
511 GetProperty(Slider.Property.LOWER_BOUND).Get(out temp);
516 SetProperty(Slider.Property.LOWER_BOUND, new Tizen.NUI.PropertyValue(value));
521 /// Upper bound property
523 public float UpperBound
528 GetProperty(Slider.Property.UPPER_BOUND).Get(out temp);
533 SetProperty(Slider.Property.UPPER_BOUND, new Tizen.NUI.PropertyValue(value));
545 GetProperty(Slider.Property.VALUE).Get(out temp);
550 SetProperty(Slider.Property.VALUE, new Tizen.NUI.PropertyValue(value));
555 /// Track visual property
557 public PropertyMap TrackVisual
561 PropertyMap temp = new PropertyMap();
562 GetProperty(Slider.Property.TRACK_VISUAL).Get(temp);
567 SetProperty(Slider.Property.TRACK_VISUAL, new Tizen.NUI.PropertyValue(value));
572 /// Handle visual property
574 public PropertyMap HandleVisual
578 PropertyMap temp = new PropertyMap();
579 GetProperty(Slider.Property.HANDLE_VISUAL).Get(temp);
584 SetProperty(Slider.Property.HANDLE_VISUAL, new Tizen.NUI.PropertyValue(value));
589 /// Progress visual property
591 public PropertyMap ProgressVisual
595 PropertyMap temp = new PropertyMap();
596 GetProperty(Slider.Property.PROGRESS_VISUAL).Get(temp);
601 SetProperty(Slider.Property.PROGRESS_VISUAL, new Tizen.NUI.PropertyValue(value));
606 /// Popup visual property
608 public PropertyMap PopupVisual
612 PropertyMap temp = new PropertyMap();
613 GetProperty(Slider.Property.POPUP_VISUAL).Get(temp);
618 SetProperty(Slider.Property.POPUP_VISUAL, new Tizen.NUI.PropertyValue(value));
623 /// Popup arrow visual property
625 public PropertyMap PopupArrowVisual
629 PropertyMap temp = new PropertyMap();
630 GetProperty(Slider.Property.POPUP_ARROW_VISUAL).Get(temp);
635 SetProperty(Slider.Property.POPUP_ARROW_VISUAL, new Tizen.NUI.PropertyValue(value));
640 /// Disable color property
642 public Vector4 DisabledColor
646 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
647 GetProperty(Slider.Property.DISABLED_COLOR).Get(temp);
652 SetProperty(Slider.Property.DISABLED_COLOR, new Tizen.NUI.PropertyValue(value));
657 /// Value presicion property
659 public int ValuePrecision
664 GetProperty(Slider.Property.VALUE_PRECISION).Get(out temp);
669 SetProperty(Slider.Property.VALUE_PRECISION, new Tizen.NUI.PropertyValue(value));
674 /// Show popup property
676 public bool ShowPopup
681 GetProperty(Slider.Property.SHOW_POPUP).Get(out temp);
686 SetProperty(Slider.Property.SHOW_POPUP, new Tizen.NUI.PropertyValue(value));
691 /// Show value property
693 public bool ShowValue
698 GetProperty(Slider.Property.SHOW_VALUE).Get(out temp);
703 SetProperty(Slider.Property.SHOW_VALUE, new Tizen.NUI.PropertyValue(value));
710 public Tizen.NUI.PropertyArray Marks
714 Tizen.NUI.PropertyArray temp = new Tizen.NUI.PropertyArray();
715 GetProperty(Slider.Property.MARKS).Get(temp);
720 SetProperty(Slider.Property.MARKS, new Tizen.NUI.PropertyValue(value));
725 /// Snap to marks property
727 public bool SnapToMarks
732 GetProperty(Slider.Property.SNAP_TO_MARKS).Get(out temp);
737 SetProperty(Slider.Property.SNAP_TO_MARKS, new Tizen.NUI.PropertyValue(value));
742 /// Mark tolerance property
744 public float MarkTolerance
749 GetProperty(Slider.Property.MARK_TOLERANCE).Get(out temp);
754 SetProperty(Slider.Property.MARK_TOLERANCE, new Tizen.NUI.PropertyValue(value));