c65ea0bbd44df27212d4e55479fde0ced5f941d1
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI.Components / Controls / Slider.cs
1 /*
2  * Copyright(c) 2019 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 finished 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         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
70         [EditorBrowsable(EditorBrowsableState.Never)]
71         public static readonly BindableProperty IndicatorTypeProperty = BindableProperty.Create("IndicatorType", typeof(IndicatorType), typeof(Slider), IndicatorType.None, propertyChanged: (bindable, oldValue, newValue) =>
72         {
73             var instance = (Slider)bindable;
74             if (newValue != null)
75             {
76                 instance.privateIndicatorType = (IndicatorType)newValue;
77             }
78         },
79         defaultValueCreator: (bindable) =>
80         {
81             var instance = (Slider)bindable;
82             return instance.privateIndicatorType;
83         });
84         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
85         [EditorBrowsable(EditorBrowsableState.Never)]
86         public static readonly BindableProperty SpaceBetweenTrackAndIndicatorProperty = BindableProperty.Create(nameof(SpaceBetweenTrackAndIndicator), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
87         {
88             var instance = (Slider)bindable;
89             if (newValue != null)
90             {
91                 instance.privateSpaceBetweenTrackAndIndicator = (uint)newValue;
92             }
93         },
94         defaultValueCreator: (bindable) =>
95         {
96             var instance = (Slider)bindable;
97             return instance.privateSpaceBetweenTrackAndIndicator;
98         });
99         /// This will be public opened in tizen_6.0 after ACR done. Before ACR, need to be hidden as inhouse API.
100         [EditorBrowsable(EditorBrowsableState.Never)]
101         public static readonly BindableProperty TrackThicknessProperty = BindableProperty.Create(nameof(TrackThickness), typeof(uint), typeof(Slider), (uint)0, propertyChanged: (bindable, oldValue, newValue) =>
102         {
103             var instance = (Slider)bindable;
104             if (newValue != null)
105             {
106                 instance.privateTrackThickness = (uint)newValue;
107             }
108         },
109         defaultValueCreator: (bindable) =>
110         {
111             var instance = (Slider)bindable;
112             return instance.privateTrackThickness;
113         });
114
115         static Slider() { }
116
117         /// <summary>
118         /// The constructor of the Slider class.
119         /// </summary>
120         /// <since_tizen> 6 </since_tizen>
121         public Slider() 
122         {
123             Initialize();
124         }
125
126         /// <summary>
127         /// The constructor of the Slider class with specific style.
128         /// </summary>
129         /// <param name="style">The string to initialize the Slider</param>
130         /// <since_tizen> 8 </since_tizen>
131         public Slider(string style) : base(style)
132         {
133             Initialize();
134         }
135
136         /// <summary>
137         /// The constructor of the Slider class with specific style.
138         /// </summary>
139         /// <param name="sliderStyle">The style object to initialize the Slider</param>
140         /// <since_tizen> 8 </since_tizen>
141         public Slider(SliderStyle sliderStyle) : base(sliderStyle)
142         {
143             Initialize();
144         }
145
146         /// <summary>
147         /// The value changed event handler.
148         /// </summary>
149         /// <since_tizen> 6 </since_tizen>
150         [Obsolete("Deprecated in API8; Will be removed in API10. Please use ValueChanged event instead.")]
151         public event EventHandler<ValueChangedArgs> ValueChangedEvent
152         {
153             add
154             {
155                 valueChangedHandler += value;
156             }
157             remove
158             {
159                 valueChangedHandler -= value;
160             }
161         }
162
163         /// <summary>
164         /// The sliding finished event handler.
165         /// </summary>
166         /// <since_tizen> 6 </since_tizen>
167         [Obsolete("Deprecated in API8; Will be removed in API10. Please use SlidingFinished event instead.")]
168         public event EventHandler<SlidingFinishedArgs> SlidingFinishedEvent
169         {
170             add
171             {
172                 slidingFinishedHandler += value;
173             }
174             remove
175             {
176                 slidingFinishedHandler -= value;
177             }
178         }
179
180         /// <summary>
181         /// The value changed event handler.
182         /// </summary>
183         /// <since_tizen> 8 </since_tizen>
184         public event EventHandler<SliderValueChangedEventArgs> ValueChanged
185         {
186             add
187             {
188                 sliderValueChangedHandler += value;
189             }
190             remove
191             {
192                 sliderValueChangedHandler -= value;
193             }
194         }
195
196         /// <summary>
197         /// The sliding finished event handler.
198         /// </summary>
199         /// <since_tizen> 8 </since_tizen>
200         public event EventHandler<SliderSlidingStartedEventArgs> SlidingStarted
201         {
202             add
203             {
204                 sliderSlidingStartedHandler += value;
205             }
206             remove
207             {
208                 sliderSlidingStartedHandler -= value;
209             }
210         }
211
212         /// <summary>
213         /// The sliding finished event handler.
214         /// </summary>
215         /// <since_tizen> 8 </since_tizen>
216         public event EventHandler<SliderSlidingFinishedEventArgs> SlidingFinished
217         {
218             add
219             {
220                 sliderSlidingFinishedHandler += value;
221             }
222             remove
223             {
224                 sliderSlidingFinishedHandler -= value;
225             }
226         }
227
228         /// <summary>
229         /// The state changed event handler.
230         /// </summary>
231         /// <since_tizen> 6 </since_tizen>
232         [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEvent")]
233         public event EventHandler<StateChangedArgs> StateChangedEvent
234         {
235             add
236             {
237                 stateChangedHandler += value;
238             }
239             remove
240             {
241                 stateChangedHandler -= value;
242             }
243         }
244
245         /// <summary>
246         /// The direction type of slider.
247         /// </summary>
248         /// <since_tizen> 6 </since_tizen>
249         public enum DirectionType
250         {
251             /// <summary>
252             /// The Horizontal type.
253             /// </summary>
254             /// <since_tizen> 6 </since_tizen>
255             Horizontal,
256
257             /// <summary>
258             /// The Vertical type.
259             /// </summary>
260             /// <since_tizen> 6 </since_tizen>
261             Vertical
262         }
263
264         /// <summary>
265         /// The indicator type of slider.
266         /// </summary>
267         /// <since_tizen> 6 </since_tizen>
268         public enum IndicatorType
269         {
270             /// <summary> Only contains slider bar.</summary>
271             /// <since_tizen> 6 </since_tizen>
272             None,
273
274             /// <summary> Contains slider bar, IndicatorImage.</summary>
275             /// <since_tizen> 6 </since_tizen>
276             Image,
277
278             /// <summary> Contains slider bar, IndicatorText.</summary>
279             /// <since_tizen> 6 </since_tizen>
280             Text
281         }
282
283         /// <summary>
284         /// Return a copied Style instance of Slider
285         /// </summary>
286         /// <remarks>
287         /// It returns copied Style instance and changing it does not effect to the Slider.
288         /// Style setting is possible by using constructor or the function of ApplyStyle(ViewStyle viewStyle)
289         /// </remarks>
290         /// <since_tizen> 8 </since_tizen>
291         public new SliderStyle Style
292         {
293             get
294             {
295                 var result = new SliderStyle(sliderStyle);
296                 result.CopyPropertiesFromView(this);
297                 result.Track.CopyPropertiesFromView(bgTrackImage);
298                 result.Progress.CopyPropertiesFromView(slidedTrackImage);
299                 result.Thumb.CopyPropertiesFromView(thumbImage);
300                 result.LowIndicatorImage.CopyPropertiesFromView(lowIndicatorImage);
301                 result.HighIndicatorImage.CopyPropertiesFromView(highIndicatorImage);
302                 result.LowIndicator.CopyPropertiesFromView(lowIndicatorText);
303                 result.HighIndicator.CopyPropertiesFromView(highIndicatorText);
304                 return result;
305             }
306         }
307
308         /// <summary>
309         /// Return a copied Style instance of Slider
310         /// </summary>
311         private SliderStyle sliderStyle => ViewStyle as SliderStyle;
312
313         /// <summary>
314         /// Gets or sets the direction type of slider.
315         /// </summary>
316         /// <since_tizen> 6 </since_tizen>
317         public DirectionType Direction
318         {
319             get
320             {
321                 return direction;
322             }
323             set
324             {
325                 if (direction == value)
326                 {
327                     return;
328                 }
329                 direction = value;
330                 RelayoutBaseComponent(false);
331                 UpdateBgTrackSize();
332                 UpdateBgTrackPosition();
333                 UpdateValue();
334             }
335         }
336
337         /// <summary>
338         /// Gets or sets the indicator type, arrow or sign.
339         /// </summary>
340         /// <since_tizen> 6 </since_tizen>
341         public IndicatorType Indicator
342         {
343             get
344             {
345                 return (IndicatorType)GetValue(IndicatorTypeProperty);
346             }
347             set
348             {
349                 SetValue(IndicatorTypeProperty, value);
350             }
351         }
352
353         /// <summary>
354         /// Gets or sets the minimum value of slider.
355         /// </summary>
356         /// <since_tizen> 6 </since_tizen>
357         public float MinValue
358         {
359             get
360             {
361                 return minValue;
362             }
363             set
364             {
365                 minValue = value;
366                 UpdateValue();
367             }
368         }
369
370         /// <summary>
371         /// Gets or sets the maximum value of slider.
372         /// </summary>
373         /// <since_tizen> 6 </since_tizen>
374         public float MaxValue
375         {
376             get
377             {
378                 return maxValue;
379             }
380             set
381             {
382                 maxValue = value;
383                 UpdateValue();
384             }
385         }
386
387         /// <summary>
388         /// Gets or sets the current value of slider.
389         /// </summary>
390         /// <since_tizen> 6 </since_tizen>
391         public float CurrentValue
392         {
393             get
394             {
395                 return curValue;
396             }
397             set
398             {
399                 curValue = value;
400                 UpdateValue();
401             }
402         }
403
404         /// <summary>
405         /// Gets or sets the size of the thumb image object.
406         /// </summary>
407         /// <since_tizen> 6 </since_tizen>
408         public Size ThumbSize
409         {
410             get
411             {
412                 return thumbImage?.Size;
413             }
414             set
415             {
416                 if (null != thumbImage)
417                 {
418                     thumbImage.Size = value;
419                     sliderStyle.Thumb.Size = value;
420                 }
421             }
422         }
423
424         /// <summary>
425         /// Gets or sets the resource url of the thumb image object.
426         /// </summary>
427         /// <since_tizen> 6 </since_tizen>
428         public string ThumbImageURL
429         {
430             get
431             {
432                 return thumbImage?.ResourceUrl;
433             }
434             set
435             {
436                 if (null != thumbImage)
437                 {
438                     thumbImage.ResourceUrl = value;
439                     sliderStyle.Thumb.ResourceUrl = value;
440                 }
441             }
442         }
443
444         /// <summary>
445         /// Gets or sets the resource url selector of the thumb image object.
446         /// Getter returns copied selector value if exist, null otherwise.
447         /// </summary>
448         /// <exception cref="NullReferenceException">Thrown when setting null value.</exception>
449         /// <since_tizen> 6 </since_tizen>
450         public StringSelector ThumbImageURLSelector
451         {
452             get => thumbImage == null ? null : new StringSelector((Selector<string>)thumbImage.GetValue(ImageView.ResourceUrlSelectorProperty));
453             set
454             {
455                 if (value == null || thumbImage == null)
456                 {
457                     throw new NullReferenceException("Slider.ThumbImageURLSelector is null");
458                 }
459                 else
460                 {
461                     thumbImage.SetValue(ImageView.ResourceUrlSelectorProperty, value);
462                 }
463             }
464         }
465
466         /// <summary>
467         /// Gets or sets the color of the background track image object.
468         /// </summary>
469         /// <since_tizen> 6 </since_tizen>
470         public Color BgTrackColor
471         {
472             get
473             {
474                 return bgTrackImage?.BackgroundColor;
475             }
476             set
477             {
478                 if (null != bgTrackImage)
479                 {
480                     bgTrackImage.BackgroundColor = value;
481                     sliderStyle.Track.BackgroundColor = value;
482                 }
483             }
484         }
485
486         /// <summary>
487         /// Gets or sets the color of the slided track image object.
488         /// </summary>
489         /// <since_tizen> 6 </since_tizen>
490         public Color SlidedTrackColor
491         {
492             get
493             {
494                 return slidedTrackImage?.BackgroundColor;
495             }
496             set
497             {
498                 if (null != slidedTrackImage)
499                 {
500                     slidedTrackImage.BackgroundColor = value;
501                     sliderStyle.Progress.BackgroundColor = value;
502                 }
503             }
504         }
505
506         /// <summary>
507         /// Gets or sets the thickness value of the track.
508         /// </summary>
509         /// <since_tizen> 6 </since_tizen>
510         public uint TrackThickness
511         {
512             get
513             {
514                 return (uint)GetValue(TrackThicknessProperty);
515             }
516             set
517             {
518                 SetValue(TrackThicknessProperty, value);
519             }
520         }
521
522         /// <summary>
523         /// Gets or sets the resource url of the low indicator image object.
524         /// </summary>
525         /// <since_tizen> 6 </since_tizen>
526         public string LowIndicatorImageURL
527         {
528             get
529             {
530                 return lowIndicatorImage?.ResourceUrl;
531             }
532             set
533             {
534                 if (null == lowIndicatorImage) lowIndicatorImage = new ImageView();
535                 lowIndicatorImage.ResourceUrl = value;
536                 sliderStyle.LowIndicatorImage.ResourceUrl = value;
537             }
538         }
539
540         /// <summary>
541         /// Gets or sets the resource url of the high indicator image object.
542         /// </summary>
543         /// <since_tizen> 6 </since_tizen>
544         public string HighIndicatorImageURL
545         {
546             get
547             {
548                 return highIndicatorImage?.ResourceUrl;
549             }
550             set
551             {
552                 if (null == highIndicatorImage) highIndicatorImage = new ImageView();
553                 highIndicatorImage.ResourceUrl = value;
554                 sliderStyle.HighIndicatorImage.ResourceUrl = value;
555             }
556         }
557
558         /// <summary>
559         /// Gets or sets the text content of the low indicator text object.
560         /// </summary>
561         /// <since_tizen> 6 </since_tizen>
562         public string LowIndicatorTextContent
563         {
564             get
565             {
566                 return lowIndicatorText?.Text;
567             }
568             set
569             {
570                 if (null != lowIndicatorText)
571                 {
572                     lowIndicatorText.Text= value;
573                     sliderStyle.LowIndicator.Text= value;
574                 }
575             }
576         }
577
578         /// <summary>
579         /// Gets or sets the text content of the high indicator text object.
580         /// </summary>
581         /// <since_tizen> 6 </since_tizen>
582         public string HighIndicatorTextContent
583         {
584             get
585             {
586                 return highIndicatorText?.Text;
587             }
588             set
589             {
590                 if (null != highIndicatorText)
591                 {
592                     highIndicatorText.Text = value;
593                     sliderStyle.HighIndicator.Text = value;
594                 }
595             }
596         }
597
598         /// <summary>
599         /// Gets or sets the size of the low indicator object(image or text).
600         /// </summary>
601         /// <since_tizen> 6 </since_tizen>
602         public Size LowIndicatorSize
603         {
604             get
605             {
606                 return lowIndicatorSize;
607             }
608             set
609             {
610                 lowIndicatorSize = value;
611                 UpdateLowIndicatorSize();
612                 UpdateBgTrackSize();
613                 UpdateBgTrackPosition();
614                 UpdateValue();
615             }
616         }
617
618         /// <summary>
619         /// Gets or sets the size of the high indicator object(image or text).
620         /// </summary>
621         /// <since_tizen> 6 </since_tizen>
622         public Size HighIndicatorSize
623         {
624             get
625             {
626                 return highIndicatorText?.Size;
627             }
628             set
629             {
630                 if (null != highIndicatorText)
631                 {
632                     highIndicatorText.Size = value;
633                     sliderStyle.HighIndicator.Size = value;
634                 }
635             }
636         }
637
638         /// <summary>
639         /// Gets or sets the value of the space between track and indicator.
640         /// </summary>
641         /// <since_tizen> 6 </since_tizen>
642         public uint SpaceBetweenTrackAndIndicator
643         {
644             get
645             {
646                 return (uint)GetValue(SpaceBetweenTrackAndIndicatorProperty);
647             }
648             set
649             {
650                 SetValue(SpaceBetweenTrackAndIndicatorProperty, value);
651             }
652         }
653
654         private Extents spaceBetweenTrackAndIndicator
655         {
656             get
657             {
658                 if (null == _spaceBetweenTrackAndIndicator)
659                 {
660                     _spaceBetweenTrackAndIndicator = new Extents((ushort start, ushort end, ushort top, ushort bottom) =>
661                     {
662                         Extents extents = new Extents(start, end, top, bottom);
663                         _spaceBetweenTrackAndIndicator.CopyFrom(extents);
664                     }, 0, 0, 0, 0);
665                 }
666
667                 return _spaceBetweenTrackAndIndicator;
668             }
669         }
670
671         private IndicatorType privateIndicatorType
672         {
673             get
674             {
675                 return indicatorType;
676             }
677             set
678             {
679                 if (indicatorType == value)
680                 {
681                     return;
682                 }
683                 indicatorType = value;
684                 RelayoutBaseComponent(false);
685                 UpdateBgTrackSize();
686                 UpdateBgTrackPosition();
687                 UpdateValue();
688             }
689         }
690
691         private uint privateTrackThickness
692         {
693             get
694             {
695                 return trackThickness ?? 0;
696             }
697             set
698             {
699                 trackThickness = value;
700                 if (bgTrackImage != null)
701                 {
702                     if (direction == DirectionType.Horizontal)
703                     {
704                         bgTrackImage.SizeHeight = (float)trackThickness.Value;
705                     }
706                     else if (direction == DirectionType.Vertical)
707                     {
708                         bgTrackImage.SizeWidth = (float)trackThickness.Value;
709                     }
710                 }
711                 if (slidedTrackImage != null)
712                 {
713                     if (direction == DirectionType.Horizontal)
714                     {
715                         slidedTrackImage.SizeHeight = (float)trackThickness.Value;
716                     }
717                     else if (direction == DirectionType.Vertical)
718                     {
719                         slidedTrackImage.SizeWidth = (float)trackThickness.Value;
720                     }
721                 }
722             }
723         }
724
725         private uint privateSpaceBetweenTrackAndIndicator
726         {
727             get
728             {
729                 return privateTrackPadding.Start;
730             }
731             set
732             {
733                 ushort val = (ushort)value;
734                 privateTrackPadding = new Extents(val, val, val, val);
735             }
736         }
737
738         private Extents privateTrackPadding
739         {
740             get
741             {
742                 return spaceBetweenTrackAndIndicator;
743             }
744             set
745             {
746                 spaceBetweenTrackAndIndicator.CopyFrom(value);
747                 UpdateComponentByIndicatorTypeChanged();
748                 UpdateBgTrackSize();
749                 UpdateBgTrackPosition();
750                 UpdateValue();
751             }
752         }
753
754         /// <summary>
755         /// Focus gained callback.
756         /// </summary>
757         /// <since_tizen> 8 </since_tizen>
758         public override void OnFocusGained()
759         {
760             //State = ControlStates.Focused;
761             UpdateState(true, isPressed);
762             base.OnFocusGained();
763         }
764
765         /// <summary>
766         /// Focus Lost callback.
767         /// </summary>
768         /// <since_tizen> 8 </since_tizen>
769         public override void OnFocusLost()
770         {
771             //State = ControlStates.Normal;
772             UpdateState(false, isPressed);
773             base.OnFocusLost();
774         }
775
776         /// <summary>
777         /// Apply style to scrollbar.
778         /// </summary>
779         /// <param name="viewStyle">The style to apply.</param>
780         /// <since_tizen> 8 </since_tizen>
781         public override void ApplyStyle(ViewStyle viewStyle)
782         {
783             base.ApplyStyle(viewStyle);
784
785             SliderStyle sliderStyle = viewStyle as SliderStyle;
786
787             if (null != sliderStyle?.Progress)
788             {
789                 CreateSlidedTrack().ApplyStyle(sliderStyle.Progress);
790             }
791
792             if (null != sliderStyle?.LowIndicator)
793             {
794                 CreateLowIndicatorText().ApplyStyle(sliderStyle.LowIndicator);
795             }
796
797             if (null != sliderStyle?.HighIndicator)
798             {
799                 CreateHighIndicatorText().ApplyStyle(sliderStyle.HighIndicator);
800             }
801
802             if (null != sliderStyle?.Track)
803             {
804                 CreateBackgroundTrack().ApplyStyle(sliderStyle.Track);
805             }
806
807             if (null != sliderStyle?.Thumb)
808             {
809                 CreateThumb().ApplyStyle(sliderStyle.Thumb);
810             }
811
812             EnableControlStatePropagation = true;
813         }
814
815         /// <summary>
816         /// Get Slider style.
817         /// </summary>
818         /// <returns>The default slider style.</returns>
819         /// <since_tizen> 8 </since_tizen>
820         protected override ViewStyle CreateViewStyle()
821         {
822             return new SliderStyle();
823         }
824
825         /// <summary>
826         /// Dispose Slider.
827         /// </summary>
828         /// <param name="type">Dispose type.</param>
829         /// <since_tizen> 6 </since_tizen>
830         protected override void Dispose(DisposeTypes type)
831         {
832             if (disposed)
833             {
834                 return;
835             }
836
837             if (type == DisposeTypes.Explicit)
838             {
839                 if (null != panGestureDetector)
840                 {
841                     if (null != thumbImage)
842                     {
843                         panGestureDetector.Detach(thumbImage);
844                     }
845                     panGestureDetector.Detected -= OnPanGestureDetected;
846                     panGestureDetector.Dispose();
847                     panGestureDetector = null;
848                 }
849
850                 if (null != thumbImage)
851                 {
852                     thumbImage.TouchEvent -= OnTouchEventForThumb;
853                     Utility.Dispose(thumbImage);
854                 }
855                 Utility.Dispose(slidedTrackImage);
856                 if (null != bgTrackImage)
857                 {
858                     bgTrackImage.TouchEvent -= OnTouchEventForBgTrack;
859                     Utility.Dispose(bgTrackImage);
860                 }
861                 Utility.Dispose(lowIndicatorImage);
862                 Utility.Dispose(highIndicatorImage);
863                 Utility.Dispose(lowIndicatorText);
864                 Utility.Dispose(highIndicatorText);
865             }
866
867             base.Dispose(type);
868         }
869
870         /// <summary>
871         /// Update Slider by style.
872         /// </summary>
873         /// <since_tizen> 6 </since_tizen>
874         /// This will be public opened in tizen_5.5 after ACR done. Before ACR, need to be hidden as inhouse API.
875         [EditorBrowsable(EditorBrowsableState.Never)]
876         protected override void OnUpdate()
877         {
878             RelayoutBaseComponent();
879
880             UpdateComponentByIndicatorTypeChanged();
881             UpdateBgTrackSize();
882             UpdateBgTrackPosition();
883             UpdateLowIndicatorSize();
884             UpdateValue();
885         }
886
887         /// <summary>
888         /// Theme change callback when theme is changed, this callback will be trigger.
889         /// </summary>
890         /// <param name="sender">The sender</param>
891         /// <param name="e">The event data</param>
892         [EditorBrowsable(EditorBrowsableState.Never)]
893         protected override void OnThemeChangedEvent(object sender, StyleManager.ThemeChangeEventArgs e)
894         {
895             SliderStyle sliderStyle = StyleManager.Instance.GetViewStyle(StyleName) as SliderStyle;
896             if (sliderStyle != null)
897             {
898                 ApplyStyle(sliderStyle);
899                 RelayoutRequest();
900             }
901         }
902
903         private void CalculateCurrentValueByGesture(float offset)
904         {
905             currentSlidedOffset += offset;
906
907             if (currentSlidedOffset <= 0)
908             {
909                 curValue = minValue;
910             }
911             else if (currentSlidedOffset >= BgTrackLength())
912             {
913                 curValue = maxValue;
914             }
915             else
916             {
917                 int bgTrackLength = BgTrackLength();
918                 if (bgTrackLength != 0)
919                 {
920                     curValue = ((currentSlidedOffset / (float)bgTrackLength) * (float)(maxValue - minValue)) + minValue;
921                 }
922             }
923             if (valueChangedHandler != null)
924             {
925                 ValueChangedArgs args = new ValueChangedArgs();
926                 args.CurrentValue = curValue;
927                 valueChangedHandler(this, args);
928             }
929
930             if (sliderValueChangedHandler != null)
931             {
932                 SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
933                 args.CurrentValue = curValue;
934                 sliderValueChangedHandler(this, args);
935             }
936         }
937
938         private bool OnTouchEventForBgTrack(object source, TouchEventArgs e)
939         {
940             PointStateType state = e.Touch.GetState(0);
941             if (state == PointStateType.Down)
942             {
943                 Vector2 pos = e.Touch.GetLocalPosition(0);
944                 CalculateCurrentValueByTouch(pos);
945                 UpdateValue();
946                 if (null != slidingFinishedHandler)
947                 {
948                     SlidingFinishedArgs args = new SlidingFinishedArgs();
949                     args.CurrentValue = curValue;
950                     slidingFinishedHandler(this, args);
951                 }
952
953                 if (null !=sliderSlidingFinishedHandler)
954                 {
955                     SliderSlidingFinishedEventArgs args = new SliderSlidingFinishedEventArgs();
956                     args.CurrentValue = curValue;
957                     sliderSlidingFinishedHandler(this, args);
958                 }
959             }
960             return false;
961         }
962
963         private bool OnTouchEventForThumb(object source, TouchEventArgs e)
964         {
965             PointStateType state = e.Touch.GetState(0);
966             if (state == PointStateType.Down)
967             {
968                 UpdateState(isFocused, true);
969             }
970             else if (state == PointStateType.Up)
971             {
972                 UpdateState(isFocused, false);
973             }
974             return true;
975         }
976
977         private void CalculateCurrentValueByTouch(Vector2 pos)
978         {
979             int bgTrackLength = BgTrackLength();
980             if (direction == DirectionType.Horizontal)
981             {
982                 currentSlidedOffset = pos.X;
983             }
984             else if (direction == DirectionType.Vertical)
985             {
986                 currentSlidedOffset = bgTrackLength - pos.Y;
987             }
988             if (bgTrackLength != 0)
989             {
990                 curValue = ((currentSlidedOffset / (float)bgTrackLength) * (maxValue - minValue)) + minValue;
991                 if (null != valueChangedHandler)
992                 {
993                     ValueChangedArgs args = new ValueChangedArgs();
994                     args.CurrentValue = curValue;
995                     valueChangedHandler(this, args);
996                 }
997
998                 if (null != sliderValueChangedHandler)
999                 {
1000                     SliderValueChangedEventArgs args = new SliderValueChangedEventArgs();
1001                     args.CurrentValue = curValue;
1002                     sliderValueChangedHandler(this, args);
1003                 }
1004             }
1005         }
1006
1007         private void UpdateState(bool isFocusedNew, bool isPressedNew)
1008         {
1009             if (isFocused == isFocusedNew && isPressed == isPressedNew)
1010             {
1011                 return;
1012             }
1013             if (thumbImage == null || Style == null)
1014             {
1015                 return;
1016             }
1017             isFocused = isFocusedNew;
1018             isPressed = isPressedNew;
1019
1020             if (!isFocused && !isPressed)
1021             {
1022                 ControlState = ControlState.Normal;
1023                 if (stateChangedHandler != null)
1024                 {
1025                     StateChangedArgs args = new StateChangedArgs();
1026                     args.CurrentState = (ControlStates)ControlStates.Normal;
1027                     stateChangedHandler(this, args);
1028                 }
1029             }
1030             else if (isPressed)
1031             {
1032                 ControlState = ControlState.Pressed;
1033
1034                 if (stateChangedHandler != null)
1035                 {
1036                     StateChangedArgs args = new StateChangedArgs();
1037                     args.CurrentState = (ControlStates)ControlStates.Pressed;
1038                     stateChangedHandler(this, args);
1039                 }
1040             }
1041             else if (!isPressed && isFocused)
1042             {
1043                 ControlState = ControlState.Focused;
1044
1045                 if (stateChangedHandler != null)
1046                 {
1047                     StateChangedArgs args = new StateChangedArgs();
1048                     args.CurrentState = (ControlStates)ControlStates.Focused;
1049                     stateChangedHandler(this, args);
1050                 }
1051             }
1052         }
1053
1054         private void UpdateComponentByIndicatorTypeChanged()
1055         {
1056             IndicatorType type = CurrentIndicatorType();
1057             if (type == IndicatorType.None)
1058             {
1059                 if (lowIndicatorImage != null)
1060                 {
1061                     lowIndicatorImage.Hide();
1062                 }
1063                 if (highIndicatorImage != null)
1064                 {
1065                     highIndicatorImage.Hide();
1066                 }
1067                 if (lowIndicatorText != null)
1068                 {
1069                     lowIndicatorText.Hide();
1070                 }
1071                 if (highIndicatorText != null)
1072                 {
1073                     highIndicatorText.Hide();
1074                 }
1075             }
1076             else if (type == IndicatorType.Image)
1077             {
1078                 if (lowIndicatorImage != null)
1079                 {
1080                     lowIndicatorImage.Show();
1081                 }
1082                 if (highIndicatorImage != null)
1083                 {
1084                     highIndicatorImage.Show();
1085                 }
1086                 if (lowIndicatorText != null)
1087                 {
1088                     lowIndicatorText.Hide();
1089                 }
1090                 if (highIndicatorText != null)
1091                 {
1092                     highIndicatorText.Hide();
1093                 }
1094             }
1095             else if (type == IndicatorType.Text)
1096             {
1097                 if (lowIndicatorText != null)
1098                 {
1099                     lowIndicatorText.Show();
1100                 }
1101                 if (highIndicatorText != null)
1102                 {
1103                     highIndicatorText.Show();
1104                 }
1105                 if (lowIndicatorImage != null)
1106                 {
1107                     lowIndicatorImage.Hide();
1108                 }
1109                 if (highIndicatorImage != null)
1110                 {
1111                     highIndicatorImage.Hide();
1112                 }
1113             }
1114         }
1115
1116         /// <summary>
1117         /// Value Changed event data.
1118         /// </summary>
1119         /// <since_tizen> 6 </since_tizen>
1120         [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs instead.")]
1121         public class ValueChangedArgs : EventArgs
1122         {
1123             /// <summary>
1124             /// Curren value
1125             /// </summary>
1126             /// <since_tizen> 6 </since_tizen>
1127             [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderValueChangedEventArgs.CurrentValue instead.")]
1128             public float CurrentValue;
1129         }
1130
1131         /// <summary>
1132         /// Value Changed event data.
1133         /// </summary>
1134         /// <since_tizen> 6 </since_tizen>
1135         [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs instead.")]
1136         public class SlidingFinishedArgs : EventArgs
1137         {
1138             /// <summary>
1139             /// Curren value
1140             /// </summary>
1141             /// <since_tizen> 6 </since_tizen>
1142             [Obsolete("Deprecated in API8; Will be removed in API10. Please use SliderSlidingFinishedEventArgs.CurrentValue instead.")]
1143             public float CurrentValue;
1144         }
1145
1146         /// <summary>
1147         /// State Changed event data.
1148         /// </summary>
1149         /// <since_tizen> 6 </since_tizen>
1150         [Obsolete("Deprecated in API8; Will be removed in API10. Please use View.ControlStateChangedEventArgs")]
1151         public class StateChangedArgs : EventArgs
1152         {
1153             /// <summary>
1154             /// Curent state
1155             /// </summary>
1156             /// <since_tizen> 6 </since_tizen>
1157             [Obsolete("Deprecated in API8; Will be removed in API10")]
1158             public ControlStates CurrentState;
1159         }
1160     }
1161 }