19a5641cadbd37a845fc80b2c67ca8c649b56041
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / Slider.cs
1 /*
2  * Copyright(c) 2022 Samsung Electronics Co., Ltd.
3  *
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
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
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.
15  *
16  */
17 using System;
18 using Tizen.NUI.BaseComponents;
19 using System.ComponentModel;
20 using Tizen.NUI.Binding;
21
22 namespace Tizen.NUI.Components
23 {
24     /// <summary>
25     /// Slider value changed event data.
26     /// </summary>
27     /// <since_tizen> 8 </since_tizen>
28     public class SliderValueChangedEventArgs : EventArgs
29     {
30         /// <summary>
31         /// Current Slider value
32         /// </summary>
33         /// <since_tizen> 8 </since_tizen>
34         public float CurrentValue { get; set; }
35     }
36
37     /// <summary>
38     /// Slider sliding started event data.
39     /// </summary>
40     /// <since_tizen> 8 </since_tizen>
41     public class SliderSlidingStartedEventArgs : EventArgs
42     {
43         /// <summary>
44         /// Current Slider value
45         /// </summary>
46         /// <since_tizen> 8 </since_tizen>
47         public float CurrentValue { get; set; }
48     }
49
50     /// <summary>
51     /// Slider sliding finished event data.
52     /// </summary>
53     /// <since_tizen> 8 </since_tizen>
54     public class SliderSlidingFinishedEventArgs : EventArgs
55     {
56         /// <summary>
57         /// Current Slider value
58         /// </summary>
59         /// <since_tizen> 8 </since_tizen>
60         public float CurrentValue { get; set; }
61     }
62
63     /// <summary>
64     /// A slider lets users select a value from a continuous or discrete range of values by moving the slider thumb.
65     /// </summary>
66     /// <since_tizen> 6 </since_tizen>
67     public partial class Slider : Control
68     {
69         /// <summary>
70         /// SpaceBetweenTrackAndIndicatorProperty
71         /// </summary>
72         [EditorBrowsable(EditorBrowsableState.Never)]
73         public static readonly BindableProperty IndicatorProperty = BindableProperty.Create(nameof(Indicator), typeof(IndicatorType), typeof(Slider), IndicatorType.None, propertyChanged: (bindable, oldValue, newValue) =>
74         {
75             var instance = (Slider)bindable;
76             if (newValue != null)
77             {
78                 instance.privateIndicatorType = (IndicatorType)newValue;
79             }
80         },
81         defaultValueCreator: (bindable) =>
82         {
83             var instance = (Slider)bindable;
84             return instance.privateIndicatorType;
85         });
86
87         /// <summary>
88         /// SpaceBetweenTrackAndIndicatorProperty
89         /// </summary>
90         [EditorBrowsable(EditorBrowsableState.Never)]
91         public static readonly BindableProperty SpaceBetweenTrackAndIndicatorProperty = BindableProperty.Create(nameof(SpaceBetweenTrackAndIndicator), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
92         {
93             var instance = (Slider)bindable;
94             if (newValue != null)
95             {
96                 instance.privateSpaceBetweenTrackAndIndicator = (uint)newValue;
97             }
98         },
99         defaultValueCreator: (bindable) =>
100         {
101             var instance = (Slider)bindable;
102             return instance.privateSpaceBetweenTrackAndIndicator;
103         });
104
105         /// <summary>
106         /// TrackThicknessProperty
107         /// </summary>
108         [EditorBrowsable(EditorBrowsableState.Never)]
109         public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create(nameof(TrackThickness), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
110         {
111             var instance = (Slider)bindable;
112             if (newValue != null)
113             {
114                 instance.privateTrackThickness = (uint)newValue;
115             }
116         },
117         defaultValueCreator: (bindable) =>
118         {
119             var instance = (Slider)bindable;
120             return instance.privateTrackThickness;
121         });
122
123         /// <summary>
124         /// IsValueShownProperty
125         /// </summary>
126         [EditorBrowsable(EditorBrowsableState.Never)]
127         public static readonly BindableProperty IsValueShownProperty = BindableProperty.Create(nameof(IsValueShown), typeof(bool), typeof(Slider), true, propertyChanged: (bindable, oldValue, newValue) =>
128         {
129             var instance = (Slider)bindable;
130             if (newValue != null)
131             {
132                 bool newValueShown = (bool)newValue;
133                 if (instance.isValueShown != newValueShown)
134                 {
135                     instance.isValueShown = newValueShown;
136                 }
137             }
138         },
139         defaultValueCreator: (bindable) =>
140         {
141             var instance = (Slider)bindable;
142             return instance.isValueShown;
143         });
144
145         /// <summary>
146         /// ValueIndicatorTextProperty
147         /// </summary>
148         [EditorBrowsable(EditorBrowsableState.Never)]
149         public static readonly BindableProperty ValueIndicatorTextProperty = BindableProperty.Create(nameof(ValueIndicatorText), typeof(string), typeof(Slider), string.Empty, propertyChanged: (bindable, oldValue, newValue) =>
150         {
151             var instance = (Slider)bindable;
152             if (newValue != null)
153             {
154                 string newText = (string)newValue;
155                 instance.valueIndicatorText.Text = newText;
156             }
157         },
158         defaultValueCreator: (bindable) =>
159         {
160             var instance = (Slider)bindable;
161             return instance.valueIndicatorText.Text;
162         });
163
164         /// <summary>
165         /// Bindable property of CurrentValue
166         /// <remark>
167         /// Hidden API, used for NUI XAML data binding
168         /// </remark>
169         /// </summary>
170         [EditorBrowsable(EditorBrowsableState.Never)]
171         public static readonly BindableProperty CurrentValueProperty = BindableProperty.Create(nameof(CurrentValue), typeof(float), typeof(Slider), 0.0f, BindingMode.TwoWay,
172             propertyChanged: (bindable, oldValue, newValue) =>
173             {
174                 var instance = (Slider)bindable;
175
176                 if (newValue != null)
177                 {
178                     instance.curValue = (float)newValue;
179                     if (Accessibility.Accessibility.IsEnabled && instance.IsHighlighted)
180                     {
181                         instance.EmitAccessibilityEvent(AccessibilityPropertyChangeEvent.Value);
182                     }
183                     instance.UpdateValue();
184                 }
185             },
186             defaultValueCreator: (bindable) =>
187             {
188                 var instance = (Slider)bindable;
189                 return instance.curValue;
190             }
191         );
192
193         static Slider() { }
194
195         /// <summary>
196         /// The constructor of the Slider class.
197         /// </summary>
198         /// <since_tizen> 6 </since_tizen>
199         public Slider()
200         {
201             Focusable = true;
202             Initialize();
203         }
204
205         /// <summary>
206         /// The constructor of the Slider class with specific style.
207         /// </summary>
208         /// <param name="style">The string to initialize the Slider</param>
209         /// <since_tizen> 8 </since_tizen>
210         public Slider(string style) : base(style)
211         {
212             Focusable = true;
213             Initialize();
214         }
215
216         /// <summary>
217         /// The constructor of the Slider class with specific style.
218         /// </summary>
219         /// <param name="sliderStyle">The style object to initialize the Slider</param>
220         /// <since_tizen> 8 </since_tizen>
221         public Slider(SliderStyle sliderStyle) : base(sliderStyle)
222         {
223             Focusable = true;
224             Initialize();
225         }
226
227         /// <summary>
228         /// The value changed event handler.
229         /// </summary>
230         /// <since_tizen> 6 </since_tizen>
231         [Obsolete("Deprecated in API8; Will be removed in API10. Please use ValueChanged event instead.")]
232         public event EventHandler<ValueChangedArgs> ValueChangedEvent
233         {
234             add
235             {
236                 valueChangedHandler += value;
237             }
238             remove
239             {
240                 valueChangedHandler -= value;
241             }
242         }
243
244         /// <summary>
245         /// The sliding finished event handler.
246         /// </summary>
247         /// <since_tizen> 6 </since_tizen>
248         [Obsolete("Deprecated in API8; Will be removed in API10. Please use SlidingFinished event instead.")]
249         public event EventHandler<SlidingFinishedArgs> SlidingFinishedEvent
250         {
251             add
252             {
253                 slidingFinishedHandler += value;
254             }
255             remove
256             {
257                 slidingFinishedHandler -= value;
258             }
259         }
260
261         /// <summary>
262         /// The value changed event handler.
263         /// </summary>
264         /// <since_tizen> 8 </since_tizen>
265         public event EventHandler<SliderValueChangedEventArgs> ValueChanged
266         {
267             add
268             {
269                 sliderValueChangedHandler += value;
270             }
271             remove
272             {
273                 sliderValueChangedHandler -= value;
274             }
275         }
276
277         /// <summary>
278         /// The sliding started event handler.
279         /// </summary>
280         /// <since_tizen> 8 </since_tizen>
281         public event EventHandler<SliderSlidingStartedEventArgs> SlidingStarted
282         {
283             add
284             {
285                 sliderSlidingStartedHandler += value;
286             }
287             remove
288             {
289                 sliderSlidingStartedHandler -= value;
290             }
291         }
292
293         /// <summary>
294         /// The sliding finished event handler.
295         /// </summary>
296         /// <since_tizen> 8 </since_tizen>
297         public event EventHandler<SliderSlidingFinishedEventArgs> SlidingFinished
298         {
299             add
300             {
301                 sliderSlidingFinishedHandler += value;
302             }
303             remove
304             {
305                 sliderSlidingFinishedHandler -= value;
306             }
307         }
308
309         /// <summary>
310         /// The state changed event handler.
311         /// </summary>
312         /// <since_tizen> 6 </since_tizen>
313         [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEvent")]
314         public event EventHandler<StateChangedArgs> StateChangedEvent
315         {
316             add
317             {
318                 stateChangedHandler += value;
319             }
320             remove
321             {
322                 stateChangedHandler -= value;
323             }
324         }
325
326         /// <summary>
327         /// The direction type of slider.
328         /// </summary>
329         /// <since_tizen> 6 </since_tizen>
330         public enum DirectionType
331         {
332             /// <summary>
333             /// The Horizontal type.
334             /// </summary>
335             /// <since_tizen> 6 </since_tizen>
336             Horizontal,
337
338             /// <summary>
339             /// The Vertical type.
340             /// </summary>
341             /// <since_tizen> 6 </since_tizen>
342             Vertical
343         }
344
345         /// <summary>
346         /// The indicator type of slider.
347         /// </summary>
348         /// <since_tizen> 6 </since_tizen>
349         public enum IndicatorType
350         {
351             /// <summary> Only contains slider bar.</summary>
352             /// <since_tizen> 6 </since_tizen>
353             None,
354
355             /// <summary> Contains slider bar, IndicatorImage.</summary>
356             /// <since_tizen> 6 </since_tizen>
357             Image,
358
359             /// <summary> Contains slider bar, IndicatorText.</summary>
360             /// <since_tizen> 6 </since_tizen>
361             Text
362         }
363
364         /// <summary>
365         /// Return currently applied style.
366         /// </summary>
367         /// <remarks>
368         /// Modifying contents in style may cause unexpected behaviour.
369         /// </remarks>
370         /// <since_tizen> 8 </since_tizen>
371         public SliderStyle Style => (SliderStyle)(ViewStyle as SliderStyle)?.Clone();
372
373         /// <summary>
374         /// Gets or sets the direction type of slider.
375         /// </summary>
376         /// <since_tizen> 6 </since_tizen>
377         public DirectionType Direction
378         {
379             get
380             {
381                 return (DirectionType)GetValue(DirectionProperty);
382             }
383             set
384             {
385                 SetValue(DirectionProperty, value);
386                 NotifyPropertyChanged();
387             }
388         }
389         private DirectionType InternalDirection
390         {
391             get
392             {
393                 return direction;
394             }
395             set
396             {
397                 if (direction == value)
398                 {
399                     return;
400                 }
401                 direction = value;
402                 RelayoutBaseComponent(false);
403                 UpdateBgTrackSize();
404                 UpdateBgTrackPosition();
405                 UpdateWarningTrackSize();
406                 UpdateValue();
407             }
408         }
409
410         /// <summary>
411         /// Gets or sets the indicator type, arrow or sign.
412         /// </summary>
413         /// <since_tizen> 6 </since_tizen>
414         public IndicatorType Indicator
415         {
416             get
417             {
418                 return (IndicatorType)GetValue(IndicatorProperty);
419             }
420             set
421             {
422                 SetValue(IndicatorProperty, value);
423             }
424         }
425
426         /// <summary>
427         /// Gets or sets the minimum value of slider.
428         /// </summary>
429         /// <since_tizen> 6 </since_tizen>
430         public float MinValue
431         {
432             get
433             {
434                 return (float)GetValue(MinValueProperty);
435             }
436             set
437             {
438                 SetValue(MinValueProperty, value);
439                 NotifyPropertyChanged();
440             }
441         }
442         private float InternalMinValue
443         {
444             get
445             {
446                 return minValue;
447             }
448             set
449             {
450                 minValue = value;
451                 UpdateValue();
452             }
453         }
454
455         /// <summary>
456         /// Gets or sets the maximum value of slider.
457         /// </summary>
458         /// <since_tizen> 6 </since_tizen>
459         public float MaxValue
460         {
461             get
462             {
463                 return (float)GetValue(MaxValueProperty);
464             }
465             set
466             {
467                 SetValue(MaxValueProperty, value);
468                 NotifyPropertyChanged();
469             }
470         }
471         private float InternalMaxValue
472         {
473             get
474             {
475                 return maxValue;
476             }
477             set
478             {
479                 maxValue = value;
480                 UpdateValue();
481             }
482         }
483
484         /// <summary>
485         /// Gets or sets the current value of slider.
486         /// </summary>
487         /// <since_tizen> 6 </since_tizen>
488         public float CurrentValue
489         {
490             get
491             {
492                 return (float)GetValue(CurrentValueProperty);
493             }
494             set
495             {
496                 SetValue(CurrentValueProperty, value);
497             }
498         }
499
500         /// <summary>
501         /// Gets or sets the size of the thumb image object.
502         /// </summary>
503         /// <since_tizen> 6 </since_tizen>
504         public Size ThumbSize
505         {
506             get
507             {
508                 return GetValue(ThumbSizeProperty) as Size;
509             }
510             set
511             {
512                 SetValue(ThumbSizeProperty, value);
513                 NotifyPropertyChanged();
514             }
515         }
516         private Size InternalThumbSize
517         {
518             get
519             {
520                 return thumbImage?.Size;
521             }
522             set
523             {
524                 if (null != thumbImage)
525                 {
526                     thumbImage.Size = value;
527                     thumbSize = value;
528                 }
529             }
530         }
531
532         /// <summary>
533         /// Gets or sets the resource url of the thumb image object.
534         ///
535         /// Please use ThumbImageUrl property.
536         /// </summary>
537         /// <since_tizen> 6 </since_tizen>
538         public string ThumbImageURL
539         {
540             get
541             {
542                 return GetValue(ThumbImageURLProperty) as string;
543             }
544             set
545             {
546                 SetValue(ThumbImageURLProperty, value);
547                 NotifyPropertyChanged();
548             }
549         }
550         private string InternalThumbImageURL
551         {
552             get
553             {
554                 return thumbImage?.ResourceUrl;
555             }
556             set
557             {
558                 if (null != thumbImage)
559                 {
560                     thumbImage.ResourceUrl = value;
561                     thumbImageUrl = value;
562                 }
563             }
564         }
565
566         /// <summary>
567         /// Gets or sets the resource url selector of the thumb image object.
568         /// Getter returns copied selector value if exist, null otherwise.
569         ///
570         /// Please use ThumbImageUrl property.
571         /// </summary>
572         /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
573         /// <since_tizen> 6 </since_tizen>
574         public StringSelector ThumbImageURLSelector
575         {
576             get
577             {
578                 return GetValue(ThumbImageURLSelectorProperty) as StringSelector;
579             }
580             set
581             {
582                 SetValue(ThumbImageURLSelectorProperty, value);
583                 NotifyPropertyChanged();
584             }
585         }
586         private StringSelector InternalThumbImageURLSelector
587         {
588             get => thumbImage?.ResourceUrlSelector == null ? null : new StringSelector(thumbImage.ResourceUrlSelector);
589             set
590             {
591                 if (value == null || thumbImage == null)
592                 {
593                     throw new NullReferenceException("Slider.ThumbImageURLSelector is null");
594                 }
595                 else
596                 {
597                     thumbImage.ResourceUrlSelector = value;
598                 }
599             }
600         }
601
602         /// <summary>
603         /// Gets or sets the Url of the thumb image.
604         /// </summary>
605         /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
606         /// <since_tizen> 9 </since_tizen>
607         public Selector<string> ThumbImageUrl
608         {
609             get
610             {
611                 return GetValue(ThumbImageUrlProperty) as Selector<string>;
612             }
613             set
614             {
615                 SetValue(ThumbImageUrlProperty, value);
616                 NotifyPropertyChanged();
617             }
618         }
619         private Selector<string> InternalThumbImageUrl
620         {
621             get
622             {
623                 if (thumbImage == null)
624                 {
625                     return null;
626                 }
627                 else
628                 {
629                     return thumbImage.ResourceUrlSelector;
630                 }
631             }
632             set
633             {
634                 if (value == null || thumbImage == null)
635                 {
636                     throw new NullReferenceException("Slider.ThumbImageUrl is null");
637                 }
638                 else
639                 {
640                     thumbImage.ResourceUrlSelector = value;
641                 }
642             }
643         }
644
645         /// <summary>
646         /// Gets or sets the color of the thumb image object.
647         /// </summary>
648         /// <since_tizen> 8 </since_tizen>
649         public Color ThumbColor
650         {
651             get
652             {
653                 return GetValue(ThumbColorProperty) as Color;
654             }
655             set
656             {
657                 SetValue(ThumbColorProperty, value);
658                 NotifyPropertyChanged();
659             }
660         }
661         private Color InternalThumbColor
662         {
663             get
664             {
665                 return thumbImage?.Color;
666             }
667             set
668             {
669                 if (null != thumbImage)
670                 {
671                     thumbImage.BackgroundColor = value;
672                     thumbColor = value;
673                 }
674             }
675         }
676
677         /// <summary>
678         /// Gets or sets the color of the background track image object.
679         /// </summary>
680         /// <since_tizen> 6 </since_tizen>
681         public Color BgTrackColor
682         {
683             get
684             {
685                 return GetValue(BgTrackColorProperty) as Color;
686             }
687             set
688             {
689                 SetValue(BgTrackColorProperty, value);
690                 NotifyPropertyChanged();
691             }
692         }
693         private Color InternalBgTrackColor
694         {
695             get
696             {
697                 return bgTrackImage?.BackgroundColor;
698             }
699             set
700             {
701                 if (null != bgTrackImage)
702                 {
703                     bgTrackImage.BackgroundColor = value;
704                 }
705             }
706         }
707
708         /// <summary>
709         /// Gets or sets the color of the slided track image object.
710         /// </summary>
711         /// <since_tizen> 6 </since_tizen>
712         public Color SlidedTrackColor
713         {
714             get
715             {
716                 return GetValue(SlidedTrackColorProperty) as Color;
717             }
718             set
719             {
720                 SetValue(SlidedTrackColorProperty, value);
721                 NotifyPropertyChanged();
722             }
723         }
724         private Color InternalSlidedTrackColor
725         {
726             get
727             {
728                 return slidedTrackImage?.BackgroundColor;
729             }
730             set
731             {
732                 if (null != slidedTrackImage)
733                 {
734                     slidedTrackImage.BackgroundColor = value;
735                 }
736             }
737         }
738
739         /// <summary>
740         /// Gets or sets the thickness value of the track.
741         /// </summary>
742         /// <since_tizen> 6 </since_tizen>
743         public uint TrackThickness
744         {
745             get
746             {
747                 return (uint)GetValue(TrackThicknessProperty);
748             }
749             set
750             {
751                 SetValue(TrackThicknessProperty, value);
752             }
753         }
754
755         /// <summary>
756         /// Gets or sets the warning start value between minimum value and maximum value of slider.
757         /// </summary>
758         /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
759         [EditorBrowsable(EditorBrowsableState.Never)]
760         public float WarningStartValue
761         {
762             get
763             {
764                 return (float)GetValue(WarningStartValueProperty);
765             }
766             set
767             {
768                 SetValue(WarningStartValueProperty, value);
769                 NotifyPropertyChanged();
770             }
771         }
772         private float InternalWarningStartValue
773         {
774             get
775             {
776                 return warningStartValue;
777             }
778             set
779             {
780                 warningStartValue = value;
781                 UpdateValue();
782             }
783         }
784
785         /// <summary>
786         /// Gets or sets the color of the warning track image object.
787         /// </summary>
788         /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
789         [EditorBrowsable(EditorBrowsableState.Never)]
790         public Color WarningTrackColor
791         {
792             get
793             {
794                 return GetValue(WarningTrackColorProperty) as Color;
795             }
796             set
797             {
798                 SetValue(WarningTrackColorProperty, value);
799                 NotifyPropertyChanged();
800             }
801         }
802         private Color InternalWarningTrackColor
803         {
804             get
805             {
806                 return warningTrackImage?.BackgroundColor;
807             }
808             set
809             {
810                 if (null != warningTrackImage)
811                 {
812                     warningTrackImage.BackgroundColor = value;
813                 }
814             }
815         }
816
817         /// <summary>
818         /// Gets or sets the color of the warning slided track image object.
819         /// </summary>
820         /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
821         [EditorBrowsable(EditorBrowsableState.Never)]
822         public Color WarningSlidedTrackColor
823         {
824             get
825             {
826                 return GetValue(WarningSlidedTrackColorProperty) as Color;
827             }
828             set
829             {
830                 SetValue(WarningSlidedTrackColorProperty, value);
831                 NotifyPropertyChanged();
832             }
833         }
834         private Color InternalWarningSlidedTrackColor
835         {
836             get
837             {
838                 return warningSlidedTrackImage?.BackgroundColor;
839             }
840             set
841             {
842                 if (null != warningSlidedTrackImage)
843                 {
844                     warningSlidedTrackImage.BackgroundColor = value;
845                 }
846             }
847         }
848
849         /// <summary>
850         /// Gets or sets the Url of the warning thumb image.
851         /// </summary>
852         /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
853         /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
854         [EditorBrowsable(EditorBrowsableState.Never)]
855         public Selector<string> WarningThumbImageUrl
856         {
857             get
858             {
859                 return GetValue(WarningThumbImageUrlProperty) as Selector<string>;
860             }
861             set
862             {
863                 SetValue(WarningThumbImageUrlProperty, value);
864                 NotifyPropertyChanged();
865             }
866         }
867         private Selector<string> InternalWarningThumbImageUrl
868         {
869             get
870             {
871                 return warningThumbImageUrlSelector;
872             }
873             set
874             {
875                 if (value == null || thumbImage == null)
876                 {
877                     throw new NullReferenceException("Slider.WarningThumbImageUrl is null");
878                 }
879                 else
880                 {
881                     warningThumbImageUrlSelector = value;
882                 }
883             }
884         }
885
886         /// <summary>
887         /// Gets or sets the color of the warning thumb image object.
888         /// </summary>
889         /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
890         [EditorBrowsable(EditorBrowsableState.Never)]
891         public Color WarningThumbColor
892         {
893             get
894             {
895                 return GetValue(WarningThumbColorProperty) as Color;
896             }
897             set
898             {
899                 SetValue(WarningThumbColorProperty, value);
900                 NotifyPropertyChanged();
901             }
902         }
903         private Color InternalWarningThumbColor
904         {
905             get
906             {
907                 return warningThumbColor;
908             }
909             set
910             {
911                 warningThumbColor = value;
912             }
913         }
914
915         /// <summary>
916         /// Gets or sets the resource url of the low indicator image object.
917         /// </summary>
918         /// <since_tizen> 6 </since_tizen>
919         public string LowIndicatorImageURL
920         {
921             get
922             {
923                 return GetValue(LowIndicatorImageURLProperty) as string;
924             }
925             set
926             {
927                 SetValue(LowIndicatorImageURLProperty, value);
928                 NotifyPropertyChanged();
929             }
930         }
931         private string InternalLowIndicatorImageURL
932         {
933             get
934             {
935                 return lowIndicatorImage?.ResourceUrl;
936             }
937             set
938             {
939                 if (null == lowIndicatorImage) lowIndicatorImage = new ImageView();
940                 lowIndicatorImage.ResourceUrl = value;
941             }
942         }
943
944         /// <summary>
945         /// Gets or sets the resource url of the high indicator image object.
946         /// </summary>
947         /// <since_tizen> 6 </since_tizen>
948         public string HighIndicatorImageURL
949         {
950             get
951             {
952                 return GetValue(HighIndicatorImageURLProperty) as string;
953             }
954             set
955             {
956                 SetValue(HighIndicatorImageURLProperty, value);
957                 NotifyPropertyChanged();
958             }
959         }
960         private string InternalHighIndicatorImageURL
961         {
962             get
963             {
964                 return highIndicatorImage?.ResourceUrl;
965             }
966             set
967             {
968                 if (null == highIndicatorImage) highIndicatorImage = new ImageView();
969                 highIndicatorImage.ResourceUrl = value;
970             }
971         }
972
973         /// <summary>
974         /// Gets or sets the text content of the low indicator text object.
975         /// </summary>
976         /// <since_tizen> 6 </since_tizen>
977         public string LowIndicatorTextContent
978         {
979             get
980             {
981                 return GetValue(LowIndicatorTextContentProperty) as string;
982             }
983             set
984             {
985                 SetValue(LowIndicatorTextContentProperty, value);
986                 NotifyPropertyChanged();
987             }
988         }
989         private string InternalLowIndicatorTextContent
990         {
991             get
992             {
993                 return lowIndicatorText?.Text;
994             }
995             set
996             {
997                 if (null != lowIndicatorText)
998                 {
999                     lowIndicatorText.Text = value;
1000                 }
1001             }
1002         }
1003
1004         /// <summary>
1005         /// Gets or sets the text content of the high indicator text object.
1006         /// </summary>
1007         /// <since_tizen> 6 </since_tizen>
1008         public string HighIndicatorTextContent
1009         {
1010             get
1011             {
1012                 return GetValue(HighIndicatorTextContentProperty) as string;
1013             }
1014             set
1015             {
1016                 SetValue(HighIndicatorTextContentProperty, value);
1017                 NotifyPropertyChanged();
1018             }
1019         }
1020         private string InternalHighIndicatorTextContent
1021         {
1022             get
1023             {
1024                 return highIndicatorText?.Text;
1025             }
1026             set
1027             {
1028                 if (null != highIndicatorText)
1029                 {
1030                     highIndicatorText.Text = value;
1031                 }
1032             }
1033         }
1034
1035         /// <summary>
1036         /// Gets or sets the size of the low indicator object(image or text).
1037         /// </summary>
1038         /// <since_tizen> 6 </since_tizen>
1039         public Size LowIndicatorSize
1040         {
1041             get
1042             {
1043                 return GetValue(LowIndicatorSizeProperty) as Size;
1044             }
1045             set
1046             {
1047                 SetValue(LowIndicatorSizeProperty, value);
1048                 NotifyPropertyChanged();
1049             }
1050         }
1051         private Size InternalLowIndicatorSize
1052         {
1053             get
1054             {
1055                 return lowIndicatorSize;
1056             }
1057             set
1058             {
1059                 lowIndicatorSize = value;
1060                 UpdateLowIndicatorSize();
1061                 UpdateBgTrackSize();
1062                 UpdateBgTrackPosition();
1063                 UpdateValue();
1064             }
1065         }
1066
1067         /// <summary>
1068         /// Gets or sets the size of the high indicator object(image or text).
1069         /// </summary>
1070         /// <since_tizen> 6 </since_tizen>
1071         public Size HighIndicatorSize
1072         {
1073             get
1074             {
1075                 return GetValue(HighIndicatorSizeProperty) as Size;
1076             }
1077             set
1078             {
1079                 SetValue(HighIndicatorSizeProperty, value);
1080                 NotifyPropertyChanged();
1081             }
1082         }
1083         private Size InternalHighIndicatorSize
1084         {
1085             get
1086             {
1087                 return highIndicatorText?.Size;
1088             }
1089             set
1090             {
1091                 if (null != highIndicatorText)
1092                 {
1093                     highIndicatorText.Size = value;
1094                 }
1095             }
1096         }
1097
1098         /// <summary>
1099         /// Gets or sets the value of the space between track and indicator.
1100         /// </summary>
1101         /// <since_tizen> 6 </since_tizen>
1102         public uint SpaceBetweenTrackAndIndicator
1103         {
1104             get
1105             {
1106                 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
1107             }
1108             set
1109             {
1110                 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
1111             }
1112         }
1113
1114         /// <summary>
1115         /// Flag to decide whether the value indicator is shown
1116         /// </summary>
1117         /// <since_tizen> 9 </since_tizen>
1118         public bool IsValueShown
1119         {
1120             get
1121             {
1122                 return (bool)GetValue(IsValueShownProperty);
1123             }
1124             set
1125             {
1126                 SetValue(IsValueShownProperty, value);
1127             }
1128         }
1129
1130         /// <summary>
1131         /// Gets or sets the text of value indicator.
1132         /// </summary>
1133         /// <since_tizen> 9 </since_tizen>
1134         public string ValueIndicatorText
1135         {
1136             get
1137             {
1138                 return (string)GetValue(ValueIndicatorTextProperty);
1139             }
1140             set
1141             {
1142                 SetValue(ValueIndicatorTextProperty, value);
1143             }
1144         }
1145
1146         /// <summary>
1147         /// Gets or sets the size of the value indicator image object.
1148         /// </summary>
1149         /// <since_tizen> 9 </since_tizen>
1150         public Size ValueIndicatorSize
1151         {
1152             get
1153             {
1154                 return GetValue(ValueIndicatorSizeProperty) as Size;
1155             }
1156             set
1157             {
1158                 SetValue(ValueIndicatorSizeProperty, value);
1159                 NotifyPropertyChanged();
1160             }
1161         }
1162         private Size InternalValueIndicatorSize
1163         {
1164             get
1165             {
1166                 return valueIndicatorImage?.Size;
1167             }
1168             set
1169             {
1170                 if (null != valueIndicatorImage)
1171                 {
1172                     valueIndicatorImage.Size = value;
1173                 }
1174             }
1175         }
1176
1177         /// <summary>
1178         /// Gets or sets the resource url of the value indicator image object.
1179         /// </summary>
1180         /// <since_tizen> 9 </since_tizen>
1181         public string ValueIndicatorUrl
1182         {
1183             get
1184             {
1185                 return GetValue(ValueIndicatorUrlProperty) as string;
1186             }
1187             set
1188             {
1189                 SetValue(ValueIndicatorUrlProperty, value);
1190                 NotifyPropertyChanged();
1191             }
1192         }
1193         private string InternalValueIndicatorUrl
1194         {
1195             get
1196             {
1197                 return valueIndicatorImage?.ResourceUrl;
1198             }
1199             set
1200             {
1201                 if (null != valueIndicatorImage)
1202                 {
1203                     valueIndicatorImage.ResourceUrl = value;
1204                 }
1205             }
1206         }
1207
1208         /// <summary>
1209         /// Flag to decide whether the thumb snaps to the nearest discrete value when the user drags the thumb or taps.
1210         ///
1211         /// The default value is false.
1212         /// </summary>
1213         /// <since_tizen> 9 </since_tizen>
1214         public bool IsDiscrete
1215         {
1216             get
1217             {
1218                 return (bool)GetValue(IsDiscreteProperty);
1219             }
1220             set
1221             {
1222                 SetValue(IsDiscreteProperty, value);
1223                 NotifyPropertyChanged();
1224             }
1225         }
1226         private bool InternalIsDiscrete { get; set; } = false;
1227
1228         /// <summary>
1229         /// Gets or sets the discrete value of slider.
1230         /// </summary>
1231         /// <remarks>
1232         /// The discrete value is evenly spaced between MinValue and MaxValue.
1233         /// For example, MinValue is 0, MaxValue is 100, and DiscreteValue is 20.
1234         /// Then, the thumb can only go to 0, 20, 40, 60, 80, and 100.
1235         /// The default is 0.
1236         /// </remarks>
1237         /// <since_tizen> 9 </since_tizen>
1238         public float DiscreteValue
1239         {
1240             get
1241             {
1242                 return (float)GetValue(DiscreteValueProperty);
1243             }
1244             set
1245             {
1246                 SetValue(DiscreteValueProperty, value);
1247                 NotifyPropertyChanged();
1248             }
1249         }
1250         private float InternalDiscreteValue
1251         {
1252             get
1253             {
1254                 return discreteValue;
1255             }
1256             set
1257             {
1258                 discreteValue = value;
1259                 UpdateValue();
1260             }
1261         }
1262
1263         private Extents spaceBetweenTrackAndIndicator
1264         {
1265             get
1266             {
1267                 if (null == spaceTrackIndicator)
1268                 {
1269                     spaceTrackIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
1270                     {
1271                         Extents extents = new Extents(start, end, top, bottom);
1272                         spaceTrackIndicator.CopyFrom(extents);
1273                     }, 0, 0, 0, 0);
1274                 }
1275
1276                 return spaceTrackIndicator;
1277             }
1278         }
1279
1280         private IndicatorType privateIndicatorType
1281         {
1282             get
1283             {
1284                 return indicatorType;
1285             }
1286             set
1287             {
1288                 if (indicatorType == value)
1289                 {
1290                     return;
1291                 }
1292                 indicatorType = value;
1293                 RelayoutBaseComponent(false);
1294                 UpdateBgTrackSize();
1295                 UpdateBgTrackPosition();
1296                 UpdateValue();
1297             }
1298         }
1299
1300         private uint privateTrackThickness
1301         {
1302             get
1303             {
1304                 return trackThickness ?? 0;
1305             }
1306             set
1307             {
1308                 trackThickness = value;
1309                 if (bgTrackImage != null)
1310                 {
1311                     if (direction == DirectionType.Horizontal)
1312                     {
1313                         bgTrackImage.SizeHeight = (float)trackThickness.Value;
1314                     }
1315                     else if (direction == DirectionType.Vertical)
1316                     {
1317                         bgTrackImage.SizeWidth = (float)trackThickness.Value;
1318                     }
1319                 }
1320                 if (slidedTrackImage != null)
1321                 {
1322                     if (direction == DirectionType.Horizontal)
1323                     {
1324                         slidedTrackImage.SizeHeight = (float)trackThickness.Value;
1325                     }
1326                     else if (direction == DirectionType.Vertical)
1327                     {
1328                         slidedTrackImage.SizeWidth = (float)trackThickness.Value;
1329                     }
1330                 }
1331                 if (warningTrackImage != null)
1332                 {
1333                     if (direction == DirectionType.Horizontal)
1334                     {
1335                         warningTrackImage.SizeHeight = (float)trackThickness.Value;
1336                     }
1337                     else if (direction == DirectionType.Vertical)
1338                     {
1339                         warningTrackImage.SizeWidth = (float)trackThickness.Value;
1340                     }
1341                 }
1342                 if (warningSlidedTrackImage != null)
1343                 {
1344                     if (direction == DirectionType.Horizontal)
1345                     {
1346                         warningSlidedTrackImage.SizeHeight = (float)trackThickness.Value;
1347                     }
1348                     else if (direction == DirectionType.Vertical)
1349                     {
1350                         warningSlidedTrackImage.SizeWidth = (float)trackThickness.Value;
1351                     }
1352                 }
1353             }
1354         }
1355
1356         private uint privateSpaceBetweenTrackAndIndicator
1357         {
1358             get
1359             {
1360                 return privateTrackPadding.Start;
1361             }
1362             set
1363             {
1364                 ushort val = (ushort)value;
1365                 privateTrackPadding = new Extents(val, val, val, val);
1366             }
1367         }
1368
1369         private Extents privateTrackPadding
1370         {
1371             get
1372             {
1373                 return spaceBetweenTrackAndIndicator;
1374             }
1375             set
1376             {
1377                 spaceBetweenTrackAndIndicator.CopyFrom(value);
1378                 UpdateComponentByIndicatorTypeChanged();
1379                 UpdateBgTrackSize();
1380                 UpdateBgTrackPosition();
1381                 UpdateValue();
1382             }
1383         }
1384
1385         /// <summary>
1386         /// Focus gained callback.
1387         /// </summary>
1388         /// <since_tizen> 8 </since_tizen>
1389         public override void OnFocusGained()
1390         {
1391             //State = ControlStates.Focused;
1392             UpdateState(true, isPressed);
1393             base.OnFocusGained();
1394         }
1395
1396         /// <summary>
1397         /// Focus Lost callback.
1398         /// </summary>
1399         /// <since_tizen> 8 </since_tizen>
1400         public override void OnFocusLost()
1401         {
1402             //State = ControlStates.Normal;
1403             UpdateState(false, isPressed);
1404             base.OnFocusLost();
1405         }
1406
1407         private bool editMode = false;
1408         private View recoverIndicator;
1409         private View editModeIndicator;
1410
1411         /// <inheritdoc/>
1412         [EditorBrowsable(EditorBrowsableState.Never)]
1413         public override bool OnKeyboardEnter()
1414         {
1415             if (!IsEnabled)
1416             {
1417                 return false;
1418             }
1419             if (editMode)
1420             {
1421                 //set editMode false (toggle the mode)
1422                 editMode = false;
1423                 FocusManager.Instance.FocusIndicator = recoverIndicator;
1424             }
1425             else
1426             {
1427                 //set editMode true (toggle the mode)
1428                 editMode = true;
1429                 if (editModeIndicator == null)
1430                 {
1431                     editModeIndicator = new View()
1432                     {
1433                         PositionUsesPivotPoint = true,
1434                         PivotPoint = new Position(0, 0, 0),
1435                         WidthResizePolicy = ResizePolicyType.FillToParent,
1436                         HeightResizePolicy = ResizePolicyType.FillToParent,
1437                         BorderlineColor = Color.Red,
1438                         BorderlineWidth = 6.0f,
1439                         BorderlineOffset = -1f,
1440                         BackgroundColor = new Color(0.2f, 0.2f, 0.2f, 0.4f),
1441                     };
1442                 }
1443                 recoverIndicator = FocusManager.Instance.FocusIndicator;
1444                 FocusManager.Instance.FocusIndicator = editModeIndicator;
1445             }
1446             return true;
1447         }
1448
1449         /// <inheritdoc/>
1450         [EditorBrowsable(EditorBrowsableState.Never)]
1451         public override bool OnKey(Key key)
1452         {
1453             if (!IsEnabled || null == key)
1454             {
1455                 return false;
1456             }
1457
1458             if (key.State == Key.StateType.Down)
1459             {
1460                 if ((direction == DirectionType.Horizontal && key.KeyPressedName == "Left") ||
1461                     (direction == DirectionType.Vertical && key.KeyPressedName == "Down"))
1462                 {
1463                     if (editMode)
1464                     {
1465                         if (MinValue < CurrentValue)
1466                         {
1467                             isPressed = true;
1468                             if (IsDiscrete)
1469                             {
1470                                 float value = CurrentValue - discreteValue;
1471                                 CurrentValue = value < MinValue ? MinValue : value;
1472                             }
1473                             else
1474                             {
1475                                 CurrentValue -= 1;
1476                             }
1477                         }
1478                         return true; // Consumed
1479                     }
1480                 }
1481                 else if ((direction == DirectionType.Horizontal && key.KeyPressedName == "Right") ||
1482                          (direction == DirectionType.Vertical && key.KeyPressedName == "Up"))
1483                 {
1484                     if (editMode)
1485                     {
1486                         if (MaxValue > CurrentValue)
1487                         {
1488                             isPressed = true;
1489                             if (IsDiscrete)
1490                             {
1491                                 float value = CurrentValue + discreteValue;
1492                                 CurrentValue = value > MaxValue ? MaxValue : value;
1493                             }
1494                             else
1495                             {
1496                                 CurrentValue += 1;
1497                             }
1498                         }
1499                         return true; // Consumed
1500                     }
1501                 }
1502             }
1503             else if (key.State == Key.StateType.Up)
1504             {
1505                 isPressed = false;
1506             }
1507
1508             if (key.KeyPressedName == "Up" || key.KeyPressedName == "Right" || key.KeyPressedName == "Down" || key.KeyPressedName == "Left")
1509             {
1510                 if (editMode)
1511                 {
1512                     return true;
1513                 }
1514             }
1515             return false;
1516         }
1517
1518         /// <summary>
1519         /// Apply style to scrollbar.
1520         /// </summary>
1521         /// <param name="viewStyle">The style to apply.</param>
1522         /// <since_tizen> 8 </since_tizen>
1523         public override void ApplyStyle(ViewStyle viewStyle)
1524         {
1525             base.ApplyStyle(viewStyle);
1526
1527             SliderStyle sliderStyle = viewStyle as SliderStyle;
1528
1529             if (null != sliderStyle?.Progress)
1530             {
1531                 CreateSlidedTrack().ApplyStyle(sliderStyle.Progress);
1532             }
1533
1534             if (null != sliderStyle?.LowIndicator)
1535             {
1536                 CreateLowIndicatorText().ApplyStyle(sliderStyle.LowIndicator);
1537             }
1538
1539             if (null != sliderStyle?.HighIndicator)
1540             {
1541                 CreateHighIndicatorText().ApplyStyle(sliderStyle.HighIndicator);
1542             }
1543
1544             if (null != sliderStyle?.Track)
1545             {
1546                 CreateBackgroundTrack().ApplyStyle(sliderStyle.Track);
1547             }
1548
1549             if (null != sliderStyle?.Thumb)
1550             {
1551                 CreateThumb().ApplyStyle(sliderStyle.Thumb);
1552             }
1553
1554             if (null != sliderStyle?.ValueIndicatorText)
1555             {
1556                 CreateValueIndicatorText().ApplyStyle(sliderStyle.ValueIndicatorText);
1557             }
1558
1559             if (null != sliderStyle?.ValueIndicatorImage)
1560             {
1561                 CreateValueIndicator().ApplyStyle(sliderStyle.ValueIndicatorImage);
1562             }
1563
1564             if (null != sliderStyle?.WarningTrack)
1565             {
1566                 CreateWarningTrack().ApplyStyle(sliderStyle.WarningTrack);
1567             }
1568
1569             if (null != sliderStyle?.WarningProgress)
1570             {
1571                 CreateWarningSlidedTrack().ApplyStyle(sliderStyle.WarningProgress);
1572             }
1573
1574             EnableControlStatePropagation = true;
1575         }
1576
1577         /// <summary>
1578         /// Prevents from showing child widgets in AT-SPI tree.
1579         /// </summary>
1580         [EditorBrowsable(EditorBrowsableState.Never)]
1581         protected override bool AccessibilityShouldReportZeroChildren()
1582         {
1583             return true;
1584         }
1585
1586         /// <summary>
1587         /// Gets minimum value for Accessibility.
1588         /// </summary>
1589         [EditorBrowsable(EditorBrowsableState.Never)]
1590         protected override double AccessibilityGetMinimum()
1591         {
1592             return (double)MinValue;
1593         }
1594
1595         /// <summary>
1596         /// Gets the current value for Accessibility.
1597         /// </summary>
1598         [EditorBrowsable(EditorBrowsableState.Never)]
1599         protected override double AccessibilityGetCurrent()
1600         {
1601             return (double)CurrentValue;
1602         }
1603
1604         /// <summary>
1605         /// Gets maximum value for Accessibility.
1606         /// </summary>
1607         [EditorBrowsable(EditorBrowsableState.Never)]
1608         protected override double AccessibilityGetMaximum()
1609         {
1610             return (double)MaxValue;
1611         }
1612
1613         /// <summary>
1614         /// Sets the current value using Accessibility.
1615         /// </summary>
1616         [EditorBrowsable(EditorBrowsableState.Never)]
1617         protected override bool AccessibilitySetCurrent(double value)
1618         {
1619             var current = (float)value;
1620
1621             if (current >= MinValue && current <= MaxValue)
1622             {
1623                 CurrentValue = current;
1624                 if (sliderValueChangedHandler != null)
1625                 {
1626                     sliderValueChangedHandler(this, new SliderValueChangedEventArgs { CurrentValue = current });
1627                 }
1628                 return true;
1629             }
1630
1631             return false;
1632         }
1633
1634         /// <summary>
1635         /// Gets minimum increment for Accessibility.
1636         /// </summary>
1637         [EditorBrowsable(EditorBrowsableState.Never)]
1638         protected override double AccessibilityGetMinimumIncrement()
1639         {
1640             // FIXME
1641             return (MaxValue - MinValue) / 20.0;
1642         }
1643
1644         /// <summary>
1645         /// Initialize AT-SPI object.
1646         /// </summary>
1647         [EditorBrowsable(EditorBrowsableState.Never)]
1648         public override void OnInitialize()
1649         {
1650             base.OnInitialize();
1651             SetAccessibilityConstructor(Role.Slider, AccessibilityInterface.Value);
1652         }
1653
1654         /// <summary>
1655         /// Get Slider style.
1656         /// </summary>
1657         /// <returns>The default slider style.</returns>
1658         /// <since_tizen> 8 </since_tizen>
1659         protected override ViewStyle CreateViewStyle()
1660         {
1661             return new SliderStyle();
1662         }
1663
1664         /// <summary>
1665         /// Dispose Slider.
1666         /// </summary>
1667         /// <param name="type">Dispose type.</param>
1668         /// <since_tizen> 6 </since_tizen>
1669         protected override void Dispose(DisposeTypes type)
1670         {
1671             if (disposed)
1672             {
1673                 return;
1674             }
1675
1676             if (type == DisposeTypes.Explicit)
1677             {
1678                 if (null != panGestureDetector)
1679                 {
1680                     panGestureDetector.Detach(this);
1681                     panGestureDetector.Detected -= OnPanGestureDetected;
1682                     panGestureDetector.Dispose();
1683                     panGestureDetector = null;
1684                 }
1685
1686                 if (null != thumbImage)
1687                 {
1688                     thumbImage.TouchEvent -= OnTouchEventForThumb;
1689                     Utility.Dispose(thumbImage);
1690                 }
1691                 Utility.Dispose(warningSlidedTrackImage);
1692                 Utility.Dispose(warningTrackImage);
1693                 Utility.Dispose(slidedTrackImage);
1694                 Utility.Dispose(bgTrackImage);
1695                 Utility.Dispose(lowIndicatorImage);
1696                 Utility.Dispose(highIndicatorImage);
1697                 Utility.Dispose(lowIndicatorText);
1698                 Utility.Dispose(highIndicatorText);
1699                 Utility.Dispose(valueIndicatorImage);
1700                 Utility.Dispose(valueIndicatorText);
1701
1702                 this.TouchEvent -= OnTouchEventForTrack;
1703
1704                 recoverIndicator = null;
1705                 editModeIndicator.Dispose();
1706                 editModeIndicator = null;
1707             }
1708
1709             base.Dispose(type);
1710         }
1711
1712         /// <summary>
1713         /// Update Slider by style.
1714         /// </summary>
1715         /// This will be public opened later after ACR done. Before ACR, need to be hidden as inhouse API.
1716         [EditorBrowsable(EditorBrowsableState.Never)]
1717         protected override void OnUpdate()
1718         {
1719             RelayoutBaseComponent();
1720
1721             UpdateComponentByIndicatorTypeChanged();
1722             UpdateBgTrackSize();
1723             UpdateBgTrackPosition();
1724             UpdateWarningTrackSize();
1725             UpdateLowIndicatorSize();
1726             UpdateValue();
1727         }
1728
1729         /// <inheritdoc/>
1730         [EditorBrowsable(EditorBrowsableState.Never)]
1731         protected override void OnEnabled(bool enabled)
1732         {
1733             base.OnEnabled(enabled);
1734             UpdateValue();
1735         }
1736
1737         private void CalculateCurrentValueByGesture(float offset)
1738         {
1739             currentSlidedOffset += offset;
1740
1741             if (currentSlidedOffset <= 0)
1742             {
1743                 this.CurrentValue = minValue;
1744             }
1745             else if (currentSlidedOffset >= BgTrackLength())
1746             {
1747                 this.CurrentValue = maxValue;
1748             }
1749             else
1750             {
1751                 int bgTrackLength = BgTrackLength();
1752                 if (bgTrackLength != 0)
1753                 {
1754                     this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
1755                 }
1756             }
1757
1758             if (IsDiscrete)
1759             {
1760                 this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1761             }
1762
1763             if (valueChangedHandler != null)
1764             {
1765                 ValueChangedArgs args = new ValueChangedArgs();
1766                 args.CurrentValue = this.CurrentValue;
1767                 valueChangedHandler(this, args);
1768             }
1769
1770             if (sliderValueChangedHandler != null)
1771             {
1772                 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1773                 args.CurrentValue = this.CurrentValue;
1774                 sliderValueChangedHandler(this, args);
1775             }
1776         }
1777
1778         private bool OnTouchEventForTrack(object source, TouchEventArgs e)
1779         {
1780             if (!IsEnabled)
1781             {
1782                 return false;
1783             }
1784
1785             PointStateType state = e.Touch.GetState(0);
1786             if (state == PointStateType.Down)
1787             {
1788                 if (isValueShown)
1789                 {
1790                     valueIndicatorImage.Show();
1791                 }
1792
1793                 Vector2 pos = e.Touch.GetLocalPosition(0);
1794                 CalculateCurrentValueByTouch(pos);
1795                 UpdateValue();
1796                 if (null != slidingFinishedHandler)
1797                 {
1798                     SlidingFinishedArgs args = new SlidingFinishedArgs();
1799                     args.CurrentValue = curValue;
1800                     slidingFinishedHandler(this, args);
1801                 }
1802
1803                 if (null != sliderSlidingFinishedHandler)
1804                 {
1805                     SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
1806                     args.CurrentValue = curValue;
1807                     sliderSlidingFinishedHandler(this, args);
1808                 }
1809             }
1810             else if (state == PointStateType.Up)
1811             {
1812                 if (isValueShown)
1813                 {
1814                     valueIndicatorImage.Hide();
1815                 }
1816             }
1817             return false;
1818         }
1819
1820         private bool OnTouchEventForThumb(object source, TouchEventArgs e)
1821         {
1822             PointStateType state = e.Touch.GetState(0);
1823             if (state == PointStateType.Down)
1824             {
1825                 UpdateState(isFocused, true);
1826             }
1827             else if (state == PointStateType.Up)
1828             {
1829                 UpdateState(isFocused, false);
1830             }
1831             return true;
1832         }
1833
1834         private void CalculateCurrentValueByTouch(Vector2 pos)
1835         {
1836             int bgTrackLength = BgTrackLength();
1837             if (direction == DirectionType.Horizontal)
1838             {
1839                 currentSlidedOffset = pos.X;
1840             }
1841             else if (direction == DirectionType.Vertical)
1842             {
1843                 currentSlidedOffset = bgTrackLength - pos.Y;
1844             }
1845
1846             if (bgTrackLength != 0)
1847             {
1848                 this.CurrentValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
1849
1850                 if (IsDiscrete)
1851                 {
1852                     this.CurrentValue = CalculateDiscreteValue(this.CurrentValue);
1853                 }
1854
1855                 if (null != valueChangedHandler)
1856                 {
1857                     ValueChangedArgs args = new ValueChangedArgs();
1858                     args.CurrentValue = this.CurrentValue;
1859                     valueChangedHandler(this, args);
1860                 }
1861
1862                 if (null != sliderValueChangedHandler)
1863                 {
1864                     SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1865                     args.CurrentValue = this.CurrentValue;
1866                     sliderValueChangedHandler(this, args);
1867                 }
1868             }
1869         }
1870
1871         private float CalculateDiscreteValue(float value)
1872         {
1873             return ((float)Math.Round((value / discreteValue)) * discreteValue);
1874         }
1875
1876         private void UpdateState(bool isFocusedNew, bool isPressedNew)
1877         {
1878             if (isFocused == isFocusedNew && isPressed == isPressedNew)
1879             {
1880                 return;
1881             }
1882             if (thumbImage == null || Style == null)
1883             {
1884                 return;
1885             }
1886             isFocused = isFocusedNew;
1887             isPressed = isPressedNew;
1888
1889             if (!IsEnabled) // Disabled
1890             {
1891                 ControlState = ControlState.Disabled;
1892
1893                 if (stateChangedHandler != null)
1894                 {
1895                     StateChangedArgs args = new StateChangedArgs();
1896                     args.CurrentState = (ControlStates)ControlStates.Disabled;
1897                     stateChangedHandler(this, args);
1898                 }
1899             }
1900             else if (!isFocused && !isPressed)
1901             {
1902                 ControlState = ControlState.Normal;
1903
1904                 if (stateChangedHandler != null)
1905                 {
1906                     StateChangedArgs args = new StateChangedArgs();
1907                     args.CurrentState = (ControlStates)ControlStates.Normal;
1908                     stateChangedHandler(this, args);
1909                 }
1910             }
1911             else if (isPressed)
1912             {
1913                 ControlState = ControlState.Pressed;
1914
1915                 if (stateChangedHandler != null)
1916                 {
1917                     StateChangedArgs args = new StateChangedArgs();
1918                     args.CurrentState = (ControlStates)ControlStates.Pressed;
1919                     stateChangedHandler(this, args);
1920                 }
1921             }
1922             else if (!isPressed && isFocused)
1923             {
1924                 ControlState = ControlState.Focused;
1925
1926                 if (stateChangedHandler != null)
1927                 {
1928                     StateChangedArgs args = new StateChangedArgs();
1929                     args.CurrentState = (ControlStates)ControlStates.Focused;
1930                     stateChangedHandler(this, args);
1931                 }
1932             }
1933         }
1934
1935         private void UpdateComponentByIndicatorTypeChanged()
1936         {
1937             IndicatorType type = CurrentIndicatorType();
1938             if (type == IndicatorType.None)
1939             {
1940                 if (lowIndicatorImage != null)
1941                 {
1942                     lowIndicatorImage.Hide();
1943                 }
1944                 if (highIndicatorImage != null)
1945                 {
1946                     highIndicatorImage.Hide();
1947                 }
1948                 if (lowIndicatorText != null)
1949                 {
1950                     lowIndicatorText.Hide();
1951                 }
1952                 if (highIndicatorText != null)
1953                 {
1954                     highIndicatorText.Hide();
1955                 }
1956             }
1957             else if (type == IndicatorType.Image)
1958             {
1959                 if (lowIndicatorImage != null)
1960                 {
1961                     lowIndicatorImage.Show();
1962                 }
1963                 if (highIndicatorImage != null)
1964                 {
1965                     highIndicatorImage.Show();
1966                 }
1967                 if (lowIndicatorText != null)
1968                 {
1969                     lowIndicatorText.Hide();
1970                 }
1971                 if (highIndicatorText != null)
1972                 {
1973                     highIndicatorText.Hide();
1974                 }
1975             }
1976             else if (type == IndicatorType.Text)
1977             {
1978                 if (lowIndicatorText != null)
1979                 {
1980                     lowIndicatorText.Show();
1981                 }
1982                 if (highIndicatorText != null)
1983                 {
1984                     highIndicatorText.Show();
1985                 }
1986                 if (lowIndicatorImage != null)
1987                 {
1988                     lowIndicatorImage.Hide();
1989                 }
1990                 if (highIndicatorImage != null)
1991                 {
1992                     highIndicatorImage.Hide();
1993                 }
1994             }
1995         }
1996
1997         /// <summary>
1998         /// Value Changed event data.
1999         /// </summary>
2000         /// <since_tizen> 6 </since_tizen>
2001         [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs instead.")]
2002         [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
2003         public class ValueChangedArgs : EventArgs
2004         {
2005             /// <summary>
2006             /// Current value
2007             /// </summary>
2008             /// <since_tizen> 6 </since_tizen>
2009             /// It will be removed in API10
2010             [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
2011             [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs.CurrentValue instead.")]
2012             public float CurrentValue;
2013         }
2014
2015         /// <summary>
2016         /// Value Changed event data.
2017         /// </summary>
2018         /// <since_tizen> 6 </since_tizen>
2019         [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs instead.")]
2020         [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
2021         public class SlidingFinishedArgs : EventArgs
2022         {
2023             /// <summary>
2024             /// Current value
2025             /// </summary>
2026             /// <since_tizen> 6 </since_tizen>
2027             /// It will be removed in API10
2028             [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
2029             [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs.CurrentValue instead.")]
2030             public float CurrentValue;
2031         }
2032
2033         /// <summary>
2034         /// State Changed event data.
2035         /// </summary>
2036         /// <since_tizen> 6 </since_tizen>
2037         [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEventArgs")]
2038         [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1034:NestedTypesShouldNotBeVisible")]
2039         public class StateChangedArgs : EventArgs
2040         {
2041             /// <summary>
2042             /// Current state
2043             /// </summary>
2044             /// <since_tizen> 6 </since_tizen>
2045             /// It will be removed in API10
2046             [global::System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Design", "CA1051:Do not declare visible instance fields")]
2047             [Obsolete("Deprecated in API8; Will be removed in API10")]
2048             public ControlStates CurrentState;
2049         }
2050     }
2051 }