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 slider is a control to enable sliding an indicator between two values.
28 /// <since_tizen> 3 </since_tizen>
29 public class Slider : View
31 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
33 internal Slider(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.Slider_SWIGUpcast(cPtr), cMemoryOwn)
35 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
38 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Slider obj)
40 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
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.
62 //Release your own unmanaged resources here.
63 //You should not access any managed member here except static instance.
64 //because the execution order of Finalizes is non-deterministic.
67 if (_sliderValueChangedCallbackDelegate != null)
69 ValueChangedSignal().Disconnect(_sliderValueChangedCallbackDelegate);
72 if (_sliderSlidingFinishedCallbackDelegate != null)
74 SlidingFinishedSignal().Disconnect(_sliderSlidingFinishedCallbackDelegate);
77 if (_sliderMarkReachedCallbackDelegate != null)
79 MarkReachedSignal().Disconnect(_sliderMarkReachedCallbackDelegate);
83 if (swigCPtr.Handle != global::System.IntPtr.Zero)
88 NDalicPINVOKE.delete_Slider(swigCPtr);
90 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
97 /// The ValueChanged event arguments.
99 /// <since_tizen> 3 </since_tizen>
100 public class ValueChangedEventArgs : EventArgs
102 private Slider _slider;
103 private float _slideValue;
108 /// <since_tizen> 3 </since_tizen>
122 /// The slider value.
124 /// <since_tizen> 3 </since_tizen>
125 public float SlideValue
139 /// The SlidingFinished event arguments.
141 /// <since_tizen> 3 </since_tizen>
142 public class SlidingFinishedEventArgs : EventArgs
144 private Slider _slider;
145 private float _slideValue;
150 /// <since_tizen> 3 </since_tizen>
164 /// The slider value.
166 /// <since_tizen> 3 </since_tizen>
167 public float SlideValue
181 /// The MarkReached event arguments.
183 /// <since_tizen> 3 </since_tizen>
184 public class MarkReachedEventArgs : EventArgs
186 private Slider _slider;
187 private int _slideValue;
192 /// <since_tizen> 3 </since_tizen>
206 /// The slider value.
208 /// <since_tizen> 3 </since_tizen>
209 public int SlideValue
223 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
224 private delegate bool ValueChangedCallbackDelegate(IntPtr slider, float slideValue);
225 private EventHandlerWithReturnType<object, ValueChangedEventArgs, bool> _sliderValueChangedEventHandler;
226 private ValueChangedCallbackDelegate _sliderValueChangedCallbackDelegate;
228 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
229 private delegate bool SlidingFinishedCallbackDelegate(IntPtr slider, float slideValue);
230 private EventHandlerWithReturnType<object, SlidingFinishedEventArgs, bool> _sliderSlidingFinishedEventHandler;
231 private SlidingFinishedCallbackDelegate _sliderSlidingFinishedCallbackDelegate;
233 [UnmanagedFunctionPointer(CallingConvention.StdCall)]
234 private delegate bool MarkReachedCallbackDelegate(IntPtr slider, int slideValue);
235 private EventHandlerWithReturnType<object, MarkReachedEventArgs, bool> _sliderMarkReachedEventHandler;
236 private MarkReachedCallbackDelegate _sliderMarkReachedCallbackDelegate;
239 /// An event emitted when the slider value changes.
241 /// <since_tizen> 3 </since_tizen>
242 public event EventHandlerWithReturnType<object, ValueChangedEventArgs, bool> ValueChanged
246 if (_sliderValueChangedEventHandler == null)
248 _sliderValueChangedCallbackDelegate = (OnValueChanged);
249 ValueChangedSignal().Connect(_sliderValueChangedCallbackDelegate);
251 _sliderValueChangedEventHandler += value;
255 _sliderValueChangedEventHandler -= value;
256 if (_sliderValueChangedEventHandler == null && ValueChangedSignal().Empty() == false)
258 ValueChangedSignal().Disconnect(_sliderValueChangedCallbackDelegate);
263 // Callback for Slider ValueChanged signal
264 private bool OnValueChanged(IntPtr slider, float slideValue)
266 ValueChangedEventArgs e = new ValueChangedEventArgs();
268 // Populate all members of "e" (ValueChangedEventArgs) with real page
269 e.Slider = Slider.GetSliderFromPtr(slider);
270 e.SlideValue = slideValue;
272 if (_sliderValueChangedEventHandler != null)
274 //here we send all page to user event handlers
275 return _sliderValueChangedEventHandler(this, e);
281 /// An event emitted when the sliding is finished.
283 /// <since_tizen> 3 </since_tizen>
284 public event EventHandlerWithReturnType<object, SlidingFinishedEventArgs, bool> SlidingFinished
288 if (_sliderSlidingFinishedEventHandler == null)
290 _sliderSlidingFinishedCallbackDelegate = (OnSlidingFinished);
291 SlidingFinishedSignal().Connect(_sliderSlidingFinishedCallbackDelegate);
293 _sliderSlidingFinishedEventHandler += value;
297 _sliderSlidingFinishedEventHandler -= value;
298 if (_sliderSlidingFinishedEventHandler == null && SlidingFinishedSignal().Empty() == false)
300 SlidingFinishedSignal().Disconnect(_sliderSlidingFinishedCallbackDelegate);
305 // Callback for Slider SlidingFinished signal
306 private bool OnSlidingFinished(IntPtr slider, float slideValue)
308 SlidingFinishedEventArgs e = new SlidingFinishedEventArgs();
310 // Populate all members of "e" (SlidingFinishedEventArgs) with real page
311 e.Slider = Slider.GetSliderFromPtr(slider);
312 e.SlideValue = slideValue;
314 if (_sliderSlidingFinishedEventHandler != null)
316 //here we send all page to user event handlers
317 return _sliderSlidingFinishedEventHandler(this, e);
323 /// An event emitted when the slider handle reaches a mark.
325 /// <since_tizen> 3 </since_tizen>
326 public event EventHandlerWithReturnType<object, MarkReachedEventArgs, bool> MarkReached
330 if (_sliderMarkReachedEventHandler == null)
332 _sliderMarkReachedCallbackDelegate = (OnMarkReached);
333 MarkReachedSignal().Connect(_sliderMarkReachedCallbackDelegate);
335 _sliderMarkReachedEventHandler += value;
339 _sliderMarkReachedEventHandler -= value;
340 if (_sliderMarkReachedEventHandler == null && MarkReachedSignal().Empty() == false)
342 MarkReachedSignal().Disconnect(_sliderMarkReachedCallbackDelegate);
347 // Callback for Slider MarkReached signal
348 private bool OnMarkReached(IntPtr slider, int slideValue)
350 MarkReachedEventArgs e = new MarkReachedEventArgs();
352 // Populate all members of "e" (MarkReachedEventArgs) with real page
353 e.Slider = Slider.GetSliderFromPtr(slider);
354 e.SlideValue = slideValue;
356 if (_sliderMarkReachedEventHandler != null)
358 //here we send all page to user event handlers
359 return _sliderMarkReachedEventHandler(this, e);
365 /// Gets the slider from the pointer.
367 /// <param name="cPtr">The pointer of the slider.</param>
368 /// <returns>The object of the slider type.</returns>
369 internal static Slider GetSliderFromPtr(global::System.IntPtr cPtr)
371 Slider ret = new Slider(cPtr, false);
372 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
376 internal new class Property : global::System.IDisposable
378 private global::System.Runtime.InteropServices.HandleRef swigCPtr;
379 protected bool swigCMemOwn;
381 internal Property(global::System.IntPtr cPtr, bool cMemoryOwn)
383 swigCMemOwn = cMemoryOwn;
384 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
387 internal static global::System.Runtime.InteropServices.HandleRef getCPtr(Property obj)
389 return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
392 //A Flag to check who called Dispose(). (By User or DisposeQueue)
393 private bool isDisposeQueued = false;
394 //A Flat to check if it is already disposed.
395 protected bool disposed = false;
399 if (!isDisposeQueued)
401 isDisposeQueued = true;
402 DisposeQueue.Instance.Add(this);
406 /// <since_tizen> 3 </since_tizen>
407 public void Dispose()
409 //Throw excpetion if Dispose() is called in separate thread.
410 if (!Window.IsInstalled())
412 throw new System.InvalidOperationException("This API called from separate thread. This API must be called from MainThread.");
417 Dispose(DisposeTypes.Implicit);
421 Dispose(DisposeTypes.Explicit);
422 System.GC.SuppressFinalize(this);
426 protected virtual void Dispose(DisposeTypes type)
433 if (type == DisposeTypes.Explicit)
436 //Release your own managed resources here.
437 //You should release all of your own disposable objects here.
441 //Release your own unmanaged resources here.
442 //You should not access any managed member here except static instance.
443 //because the execution order of Finalizes is non-deterministic.
445 if (swigCPtr.Handle != global::System.IntPtr.Zero)
450 NDalicPINVOKE.delete_Slider_Property(swigCPtr);
452 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
458 internal Property() : this(NDalicPINVOKE.new_Slider_Property(), true)
460 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
463 internal static readonly int LOWER_BOUND = NDalicPINVOKE.Slider_Property_LOWER_BOUND_get();
464 internal static readonly int UPPER_BOUND = NDalicPINVOKE.Slider_Property_UPPER_BOUND_get();
465 internal static readonly int VALUE = NDalicPINVOKE.Slider_Property_VALUE_get();
466 internal static readonly int TRACK_VISUAL = NDalicPINVOKE.Slider_Property_TRACK_VISUAL_get();
467 internal static readonly int HANDLE_VISUAL = NDalicPINVOKE.Slider_Property_HANDLE_VISUAL_get();
468 internal static readonly int PROGRESS_VISUAL = NDalicPINVOKE.Slider_Property_PROGRESS_VISUAL_get();
469 internal static readonly int POPUP_VISUAL = NDalicPINVOKE.Slider_Property_POPUP_VISUAL_get();
470 internal static readonly int POPUP_ARROW_VISUAL = NDalicPINVOKE.Slider_Property_POPUP_ARROW_VISUAL_get();
471 internal static readonly int DISABLED_COLOR = NDalicPINVOKE.Slider_Property_DISABLED_COLOR_get();
472 internal static readonly int VALUE_PRECISION = NDalicPINVOKE.Slider_Property_VALUE_PRECISION_get();
473 internal static readonly int SHOW_POPUP = NDalicPINVOKE.Slider_Property_SHOW_POPUP_get();
474 internal static readonly int SHOW_VALUE = NDalicPINVOKE.Slider_Property_SHOW_VALUE_get();
475 internal static readonly int MARKS = NDalicPINVOKE.Slider_Property_MARKS_get();
476 internal static readonly int SNAP_TO_MARKS = NDalicPINVOKE.Slider_Property_SNAP_TO_MARKS_get();
477 internal static readonly int MARK_TOLERANCE = NDalicPINVOKE.Slider_Property_MARK_TOLERANCE_get();
482 /// Creates the slider control.
484 /// <since_tizen> 3 </since_tizen>
485 public Slider() : this(NDalicPINVOKE.Slider_New(), true)
487 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
490 internal Slider(Slider handle) : this(NDalicPINVOKE.new_Slider__SWIG_1(Slider.getCPtr(handle)), true)
492 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
495 internal Slider Assign(Slider handle)
497 Slider ret = new Slider(NDalicPINVOKE.Slider_Assign(swigCPtr, Slider.getCPtr(handle)), false);
498 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
503 /// Downcasts an object handle to the slider.<br />
504 /// If the handle points to a slider, then the downcast produces a valid handle.<br />
505 /// If not, then the returned handle is left uninitialized.<br />
507 /// <param name="handle">The handle to an object.</param>
508 /// <returns>The handle to a slider or an uninitialized handle.</returns>
509 /// <since_tizen> 3 </since_tizen>
510 public static Slider DownCast(BaseHandle handle)
512 Slider ret = Registry.GetManagedBaseHandleFromNativePtr(handle) as Slider;
513 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
517 internal SliderValueChangedSignal ValueChangedSignal()
519 SliderValueChangedSignal ret = new SliderValueChangedSignal(NDalicPINVOKE.Slider_ValueChangedSignal(swigCPtr), false);
520 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
524 internal SliderValueChangedSignal SlidingFinishedSignal()
526 SliderValueChangedSignal ret = new SliderValueChangedSignal(NDalicPINVOKE.Slider_SlidingFinishedSignal(swigCPtr), false);
527 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
531 internal SliderMarkReachedSignal MarkReachedSignal()
533 SliderMarkReachedSignal ret = new SliderMarkReachedSignal(NDalicPINVOKE.Slider_MarkReachedSignal(swigCPtr), false);
534 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
539 /// The lower bound property.
541 /// <since_tizen> 3 </since_tizen>
542 public float LowerBound
547 GetProperty(Slider.Property.LOWER_BOUND).Get(out temp);
552 SetProperty(Slider.Property.LOWER_BOUND, new Tizen.NUI.PropertyValue(value));
557 /// The upper bound property.
559 /// <since_tizen> 3 </since_tizen>
560 public float UpperBound
565 GetProperty(Slider.Property.UPPER_BOUND).Get(out temp);
570 SetProperty(Slider.Property.UPPER_BOUND, new Tizen.NUI.PropertyValue(value));
575 /// The value property.
577 /// <since_tizen> 3 </since_tizen>
583 GetProperty(Slider.Property.VALUE).Get(out temp);
588 SetProperty(Slider.Property.VALUE, new Tizen.NUI.PropertyValue(value));
593 /// The track visual property.
595 /// <since_tizen> 3 </since_tizen>
596 public PropertyMap TrackVisual
600 PropertyMap temp = new PropertyMap();
601 GetProperty(Slider.Property.TRACK_VISUAL).Get(temp);
606 SetProperty(Slider.Property.TRACK_VISUAL, new Tizen.NUI.PropertyValue(value));
611 /// The handle visual property.
613 /// <since_tizen> 3 </since_tizen>
614 public PropertyMap HandleVisual
618 PropertyMap temp = new PropertyMap();
619 GetProperty(Slider.Property.HANDLE_VISUAL).Get(temp);
624 SetProperty(Slider.Property.HANDLE_VISUAL, new Tizen.NUI.PropertyValue(value));
629 /// The progress visual property.
631 /// <since_tizen> 3 </since_tizen>
632 public PropertyMap ProgressVisual
636 PropertyMap temp = new PropertyMap();
637 GetProperty(Slider.Property.PROGRESS_VISUAL).Get(temp);
642 SetProperty(Slider.Property.PROGRESS_VISUAL, new Tizen.NUI.PropertyValue(value));
647 /// The popup visual property.
649 /// <since_tizen> 3 </since_tizen>
650 public PropertyMap PopupVisual
654 PropertyMap temp = new PropertyMap();
655 GetProperty(Slider.Property.POPUP_VISUAL).Get(temp);
660 SetProperty(Slider.Property.POPUP_VISUAL, new Tizen.NUI.PropertyValue(value));
665 /// The popup arrow visual property.
667 /// <since_tizen> 3 </since_tizen>
668 public PropertyMap PopupArrowVisual
672 PropertyMap temp = new PropertyMap();
673 GetProperty(Slider.Property.POPUP_ARROW_VISUAL).Get(temp);
678 SetProperty(Slider.Property.POPUP_ARROW_VISUAL, new Tizen.NUI.PropertyValue(value));
683 /// The disable color property.
685 /// <since_tizen> 3 </since_tizen>
686 public Vector4 DisabledColor
690 Vector4 temp = new Vector4(0.0f, 0.0f, 0.0f, 0.0f);
691 GetProperty(Slider.Property.DISABLED_COLOR).Get(temp);
696 SetProperty(Slider.Property.DISABLED_COLOR, new Tizen.NUI.PropertyValue(value));
701 /// The value precision property.
703 /// <since_tizen> 3 </since_tizen>
704 public int ValuePrecision
709 GetProperty(Slider.Property.VALUE_PRECISION).Get(out temp);
714 SetProperty(Slider.Property.VALUE_PRECISION, new Tizen.NUI.PropertyValue(value));
719 /// The show popup property.
721 /// <since_tizen> 3 </since_tizen>
722 public bool ShowPopup
727 GetProperty(Slider.Property.SHOW_POPUP).Get(out temp);
732 SetProperty(Slider.Property.SHOW_POPUP, new Tizen.NUI.PropertyValue(value));
737 /// The show value property.
739 /// <since_tizen> 3 </since_tizen>
740 public bool ShowValue
745 GetProperty(Slider.Property.SHOW_VALUE).Get(out temp);
750 SetProperty(Slider.Property.SHOW_VALUE, new Tizen.NUI.PropertyValue(value));
755 /// The marks property.
757 /// <since_tizen> 3 </since_tizen>
758 public Tizen.NUI.PropertyArray Marks
762 Tizen.NUI.PropertyArray temp = new Tizen.NUI.PropertyArray();
763 GetProperty(Slider.Property.MARKS).Get(temp);
768 SetProperty(Slider.Property.MARKS, new Tizen.NUI.PropertyValue(value));
773 /// The snap to marks property.
775 /// <since_tizen> 3 </since_tizen>
776 public bool SnapToMarks
781 GetProperty(Slider.Property.SNAP_TO_MARKS).Get(out temp);
786 SetProperty(Slider.Property.SNAP_TO_MARKS, new Tizen.NUI.PropertyValue(value));
791 /// The mark tolerance property.
793 /// <since_tizen> 3 </since_tizen>
794 public float MarkTolerance
799 GetProperty(Slider.Property.MARK_TOLERANCE).Get(out temp);
804 SetProperty(Slider.Property.MARK_TOLERANCE, new Tizen.NUI.PropertyValue(value));