[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / UIComponents / ProgressBar.cs
1 /*
2  * Copyright(c) 2018 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 System.ComponentModel;
19 using System.Runtime.InteropServices;
20 using Tizen.NUI.BaseComponents;
21 using Tizen.NUI.Binding;
22
23 namespace Tizen.NUI.UIComponents
24 {
25     /// <summary>
26     /// The ProgressBar is a control to give the user an indication of the progress of an operation.
27     /// </summary>
28     /// <since_tizen> 3 </since_tizen>
29     public class ProgressBar : View
30     {
31         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
32         [EditorBrowsable(EditorBrowsableState.Never)]
33         public static readonly BindableProperty ProgressValueProperty = BindableProperty.Create("ProgressValue", typeof(float), typeof(ProgressBar), default(float), propertyChanged: (bindable, oldValue, newValue) =>
34         {
35             var progressBar = (ProgressBar)bindable;
36             if (newValue != null)
37             {
38                 Tizen.NUI.Object.SetProperty(progressBar.swigCPtr, ProgressBar.Property.PROGRESS_VALUE, new Tizen.NUI.PropertyValue((float)newValue));
39             }
40         },
41         defaultValueCreator: (bindable) =>
42         {
43             var progressBar = (ProgressBar)bindable;
44             float temp = 0.0f;
45             Tizen.NUI.Object.GetProperty(progressBar.swigCPtr, ProgressBar.Property.PROGRESS_VALUE).Get(out temp);
46             return temp;
47         });
48         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
49         [EditorBrowsable(EditorBrowsableState.Never)]
50         public static readonly BindableProperty SecondaryProgressValueProperty = BindableProperty.Create("SecondaryProgressValue", typeof(float), typeof(ProgressBar), default(float), propertyChanged: (bindable, oldValue, newValue) =>
51         {
52             var progressBar = (ProgressBar)bindable;
53             if (newValue != null)
54             {
55                 Tizen.NUI.Object.SetProperty(progressBar.swigCPtr, ProgressBar.Property.SECONDARY_PROGRESS_VALUE, new Tizen.NUI.PropertyValue((float)newValue));
56             }
57         },
58         defaultValueCreator: (bindable) =>
59         {
60             var progressBar = (ProgressBar)bindable;
61             float temp = 0.0f;
62             Tizen.NUI.Object.GetProperty(progressBar.swigCPtr, ProgressBar.Property.SECONDARY_PROGRESS_VALUE).Get(out temp);
63             return temp;
64         });
65         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
66         [EditorBrowsable(EditorBrowsableState.Never)]
67         public static readonly BindableProperty IndeterminateProperty = BindableProperty.Create("Indeterminate", typeof(bool), typeof(ProgressBar), false, propertyChanged: (bindable, oldValue, newValue) =>
68         {
69             var progressBar = (ProgressBar)bindable;
70             if (newValue != null)
71             {
72                 Tizen.NUI.Object.SetProperty(progressBar.swigCPtr, ProgressBar.Property.INDETERMINATE, new Tizen.NUI.PropertyValue((bool)newValue));
73             }
74         },
75         defaultValueCreator: (bindable) =>
76         {
77             var progressBar = (ProgressBar)bindable;
78             bool temp = false;
79             Tizen.NUI.Object.GetProperty(progressBar.swigCPtr, ProgressBar.Property.INDETERMINATE).Get(out temp);
80             return temp;
81         });
82         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
83         [EditorBrowsable(EditorBrowsableState.Never)]
84         public static readonly BindableProperty TrackVisualProperty = BindableProperty.Create("TrackVisual", typeof(PropertyMap), typeof(ProgressBar), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
85         {
86             var progressBar = (ProgressBar)bindable;
87             if (newValue != null)
88             {
89                 Tizen.NUI.Object.SetProperty(progressBar.swigCPtr, ProgressBar.Property.TRACK_VISUAL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
90             }
91         },
92         defaultValueCreator: (bindable) =>
93         {
94             var progressBar = (ProgressBar)bindable;
95             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
96             Tizen.NUI.Object.GetProperty(progressBar.swigCPtr, ProgressBar.Property.TRACK_VISUAL).Get(temp);
97             return temp;
98         });
99         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
100         [EditorBrowsable(EditorBrowsableState.Never)]
101         public static readonly BindableProperty ProgressVisualProperty = BindableProperty.Create("ProgressVisual", typeof(PropertyMap), typeof(ProgressBar), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
102         {
103             var progressBar = (ProgressBar)bindable;
104             if (newValue != null)
105             {
106                 Tizen.NUI.Object.SetProperty(progressBar.swigCPtr, ProgressBar.Property.PROGRESS_VISUAL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
107             }
108         },
109         defaultValueCreator: (bindable) =>
110         {
111             var progressBar = (ProgressBar)bindable;
112             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
113             Tizen.NUI.Object.GetProperty(progressBar.swigCPtr, ProgressBar.Property.PROGRESS_VISUAL).Get(temp);
114             return temp;
115         });
116         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
117         [EditorBrowsable(EditorBrowsableState.Never)]
118         public static readonly BindableProperty SecondaryProgressVisualProperty = BindableProperty.Create("SecondaryProgressVisual", typeof(PropertyMap), typeof(ProgressBar), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
119         {
120             var progressBar = (ProgressBar)bindable;
121             if (newValue != null)
122             {
123                 Tizen.NUI.Object.SetProperty(progressBar.swigCPtr, ProgressBar.Property.SECONDARY_PROGRESS_VISUAL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
124             }
125         },
126         defaultValueCreator: (bindable) =>
127         {
128             var progressBar = (ProgressBar)bindable;
129             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
130             Tizen.NUI.Object.GetProperty(progressBar.swigCPtr, ProgressBar.Property.SECONDARY_PROGRESS_VISUAL).Get(temp);
131             return temp;
132         });
133         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
134         [EditorBrowsable(EditorBrowsableState.Never)]
135         public static readonly BindableProperty IndeterminateVisualProperty = BindableProperty.Create("IndeterminateVisual", typeof(PropertyMap), typeof(ProgressBar), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
136         {
137             var progressBar = (ProgressBar)bindable;
138             if (newValue != null)
139             {
140                 Tizen.NUI.Object.SetProperty(progressBar.swigCPtr, ProgressBar.Property.INDETERMINATE_VISUAL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
141             }
142         },
143         defaultValueCreator: (bindable) =>
144         {
145             var progressBar = (ProgressBar)bindable;
146             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
147             Tizen.NUI.Object.GetProperty(progressBar.swigCPtr, ProgressBar.Property.INDETERMINATE_VISUAL).Get(temp);
148             return temp;
149         });
150         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
151         [EditorBrowsable(EditorBrowsableState.Never)]
152         public static readonly BindableProperty IndeterminateVisualAnimationProperty = BindableProperty.Create("IndeterminateVisualAnimation", typeof(PropertyArray), typeof(ProgressBar), new PropertyArray(), propertyChanged: (bindable, oldValue, newValue) =>
153         {
154             var progressBar = (ProgressBar)bindable;
155             if (newValue != null)
156             {
157                 Tizen.NUI.Object.SetProperty(progressBar.swigCPtr, ProgressBar.Property.INDETERMINATE_VISUAL_ANIMATION, new Tizen.NUI.PropertyValue((PropertyArray)newValue));
158             }
159         },
160         defaultValueCreator: (bindable) =>
161         {
162             var progressBar = (ProgressBar)bindable;
163             Tizen.NUI.PropertyArray temp = new Tizen.NUI.PropertyArray();
164             Tizen.NUI.Object.GetProperty(progressBar.swigCPtr, ProgressBar.Property.INDETERMINATE_VISUAL_ANIMATION).Get(temp);
165             return temp;
166         });
167         /// This will be public opened in tizen_5.0 after ACR done. Before ACR, need to be hidden as inhouse API.
168         [EditorBrowsable(EditorBrowsableState.Never)]
169         public static readonly BindableProperty LabelVisualProperty = BindableProperty.Create("LabelVisual", typeof(PropertyMap), typeof(ProgressBar), new PropertyMap(), propertyChanged: (bindable, oldValue, newValue) =>
170         {
171             var progressBar = (ProgressBar)bindable;
172             if (newValue != null)
173             {
174                 Tizen.NUI.Object.SetProperty(progressBar.swigCPtr, ProgressBar.Property.LABEL_VISUAL, new Tizen.NUI.PropertyValue((PropertyMap)newValue));
175             }
176         },
177         defaultValueCreator: (bindable) =>
178         {
179             var progressBar = (ProgressBar)bindable;
180             Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
181             Tizen.NUI.Object.GetProperty(progressBar.swigCPtr, ProgressBar.Property.LABEL_VISUAL).Get(temp);
182             return temp;
183         });
184
185         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
186         private EventHandler<ValueChangedEventArgs> _progressBarValueChangedEventHandler;
187         private ValueChangedCallbackDelegate _progressBarValueChangedCallbackDelegate;
188
189         /// <summary>
190         /// Creates the ProgressBar.
191         /// </summary>
192         /// <since_tizen> 3 </since_tizen>
193         public ProgressBar() : this(Interop.ProgressBar.ProgressBar_New(), true)
194         {
195             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
196
197         }
198
199         internal ProgressBar(global::System.IntPtr cPtr, bool cMemoryOwn) : base(Interop.ProgressBar.ProgressBar_SWIGUpcast(cPtr), cMemoryOwn)
200         {
201             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
202         }
203
204         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
205         private delegate void ValueChangedCallbackDelegate(IntPtr progressBar, float progressValue, float secondaryProgressValue);
206
207         /// <summary>
208         /// The event is sent when the ProgressBar value changes.
209         /// </summary>
210         /// <since_tizen> 3 </since_tizen>
211         public event EventHandler<ValueChangedEventArgs> ValueChanged
212         {
213             add
214             {
215                 if (_progressBarValueChangedEventHandler == null)
216                 {
217                     _progressBarValueChangedCallbackDelegate = (OnValueChanged);
218                     ValueChangedSignal().Connect(_progressBarValueChangedCallbackDelegate);
219                 }
220                 _progressBarValueChangedEventHandler += value;
221             }
222             remove
223             {
224                 _progressBarValueChangedEventHandler -= value;
225                 if (_progressBarValueChangedEventHandler == null && ValueChangedSignal().Empty() == false)
226                 {
227                     ValueChangedSignal().Disconnect(_progressBarValueChangedCallbackDelegate);
228                 }
229             }
230         }
231
232         /// <summary>
233         /// The progress value of the progress bar, the progress runs from 0 to 1.<br />
234         /// If the value is set to 0, then the progress bar will be set to beginning.<br />
235         /// If the value is set to 1, then the progress bar will be set to end.<br />
236         /// Any value outside the range is ignored.<br />
237         /// </summary>
238         /// <since_tizen> 3 </since_tizen>
239         public float ProgressValue
240         {
241             get
242             {
243                 return (float)GetValue(ProgressValueProperty);
244             }
245             set
246             {
247                 SetValue(ProgressValueProperty, value);
248             }
249         }
250
251         /// <summary>
252         /// The secondary progress value of the progress bar, the secondary progress runs from 0 to 1.<br />
253         /// Optional. If not supplied, the default is 0.<br />
254         /// If the value is set to 0, then the progress bar will be set secondary progress to beginning.<br />
255         /// If the value is set to 1, then the progress bar will be set secondary progress to end.<br />
256         /// Any value outside of the range is ignored.<br />
257         /// </summary>
258         /// <since_tizen> 3 </since_tizen>
259         public float SecondaryProgressValue
260         {
261             get
262             {
263                 return (float)GetValue(SecondaryProgressValueProperty);
264             }
265             set
266             {
267                 SetValue(SecondaryProgressValueProperty, value);
268             }
269         }
270
271         /// <summary>
272         /// Sets the progress bar as \e indeterminate state.
273         /// </summary>
274         /// <since_tizen> 3 </since_tizen>
275         public bool Indeterminate
276         {
277             get
278             {
279                 return (bool)GetValue(IndeterminateProperty);
280             }
281             set
282             {
283                 SetValue(IndeterminateProperty, value);
284             }
285         }
286
287         /// <summary>
288         /// The track visual value of progress bar, it's full progress area, and it's shown behind the PROGRESS_VISUAL.<br />
289         /// Optional. If not supplied, the default track visual will be shown.<br />
290         /// </summary>
291         /// <since_tizen> 3 </since_tizen>
292         public Tizen.NUI.PropertyMap TrackVisual
293         {
294             get
295             {
296                 return (PropertyMap)GetValue(TrackVisualProperty);
297             }
298             set
299             {
300                 SetValue(TrackVisualProperty, value);
301             }
302         }
303
304         /// <summary>
305         /// The progress visual value of the progress bar, the size of the progress visual is changed based on the PROGRESS_VALUE.<br />
306         /// Optional. If not supplied, then the default progress visual will be shown.<br />
307         /// </summary>
308         /// <since_tizen> 3 </since_tizen>
309         public Tizen.NUI.PropertyMap ProgressVisual
310         {
311             get
312             {
313                 return (PropertyMap)GetValue(ProgressVisualProperty);
314             }
315             set
316             {
317                 SetValue(ProgressVisualProperty, value);
318             }
319         }
320
321         /// <summary>
322         /// The secondary progress visual of the progress bar, the size of the secondary progress visual is changed based on the SECONDARY_PROGRESS_VALUE.<br />
323         /// Optional. If not supplied, then the secondary progress visual will not be shown.<br />
324         /// </summary>
325         /// <since_tizen> 3 </since_tizen>
326         public Tizen.NUI.PropertyMap SecondaryProgressVisual
327         {
328             get
329             {
330                 return (PropertyMap)GetValue(SecondaryProgressVisualProperty);
331             }
332             set
333             {
334                 SetValue(SecondaryProgressVisualProperty, value);
335             }
336         }
337
338         /// <summary>
339         /// The indeterminate visual of the progress bar.<br />
340         /// Optional. If not supplied, then the default indeterminate visual will be shown.<br />
341         /// </summary>
342         /// <since_tizen> 3 </since_tizen>
343         public Tizen.NUI.PropertyMap IndeterminateVisual
344         {
345             get
346             {
347                 return (PropertyMap)GetValue(IndeterminateVisualProperty);
348             }
349             set
350             {
351                 SetValue(IndeterminateVisualProperty, value);
352             }
353         }
354
355         /// <summary>
356         /// The transition data for the indeterminate visual animation.<br />
357         /// Optional. If not supplied, then the default animation will be played.<br />
358         /// </summary>
359         /// <since_tizen> 3 </since_tizen>
360         public Tizen.NUI.PropertyArray IndeterminateVisualAnimation
361         {
362             get
363             {
364                 return (PropertyArray)GetValue(IndeterminateVisualAnimationProperty);
365             }
366             set
367             {
368                 SetValue(IndeterminateVisualAnimationProperty, value);
369             }
370         }
371
372         /// <summary>
373         /// The label visual of the progress bar.
374         /// </summary>
375         /// <since_tizen> 3 </since_tizen>
376         public Tizen.NUI.PropertyMap LabelVisual
377         {
378             get
379             {
380                 return (PropertyMap)GetValue(LabelVisualProperty);
381             }
382             set
383             {
384                 SetValue(LabelVisualProperty, value);
385             }
386         }
387
388         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ProgressBar obj)
389         {
390             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
391         }
392
393         internal ProgressBarValueChangedSignal ValueChangedSignal()
394         {
395             ProgressBarValueChangedSignal ret = new ProgressBarValueChangedSignal(Interop.ProgressBar.ProgressBar_ValueChangedSignal(swigCPtr), false);
396             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
397             return ret;
398         }
399
400         /// <summary>
401         /// To dispose the ProgressBar instance.
402         /// </summary>
403         /// <since_tizen> 3 </since_tizen>
404         protected override void Dispose(DisposeTypes type)
405         {
406             if (disposed)
407             {
408                 return;
409             }
410
411             //Release your own unmanaged resources here.
412             //You should not access any managed member here except static instance.
413             //because the execution order of Finalizes is non-deterministic.
414
415             if (this != null && _progressBarValueChangedCallbackDelegate != null)
416             {
417                 ValueChangedSignal().Disconnect(_progressBarValueChangedCallbackDelegate);
418             }
419
420             if (swigCPtr.Handle != global::System.IntPtr.Zero)
421             {
422                 if (swigCMemOwn)
423                 {
424                     swigCMemOwn = false;
425                     Interop.ProgressBar.delete_ProgressBar(swigCPtr);
426                 }
427                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
428             }
429
430             base.Dispose(type);
431         }
432
433         // Callback for ProgressBar ValueChanged signal
434         private void OnValueChanged(IntPtr progressBar, float progressValue, float secondaryProgressValue)
435         {
436             ValueChangedEventArgs e = new ValueChangedEventArgs();
437
438             // Populate all members of "e" (ValueChangedEventArgs) with real page
439             e.ProgressBar = Registry.GetManagedBaseHandleFromNativePtr(progressBar) as ProgressBar;
440             e.ProgressValue = progressValue;
441             e.SecondaryProgressValue = secondaryProgressValue;
442
443             if (_progressBarValueChangedEventHandler != null)
444             {
445                 _progressBarValueChangedEventHandler(this, e);
446             }
447         }
448
449         /// <summary>
450         /// Event arguments that passed via the ValueChangedEventArgs.
451         /// </summary>
452         /// <since_tizen> 3 </since_tizen>
453         public class ValueChangedEventArgs : EventArgs
454         {
455             private ProgressBar _progressBar;
456             private float _progressValue;
457             private float _secondaryProgressValue;
458
459             /// <summary>
460             /// ProgressBar
461             /// </summary>
462             /// <since_tizen> 3 </since_tizen>
463             public ProgressBar ProgressBar
464             {
465                 get
466                 {
467                     return _progressBar;
468                 }
469                 set
470                 {
471                     _progressBar = value;
472                 }
473             }
474
475             /// <summary>
476             /// The progress value of the progress bar, the progress runs from 0 to 1.
477             /// </summary>
478             /// <since_tizen> 3 </since_tizen>
479             public float ProgressValue
480             {
481                 get
482                 {
483                     return _progressValue;
484                 }
485                 set
486                 {
487                     _progressValue = value;
488                 }
489             }
490
491             /// <summary>
492             /// The secondary progress value of the progress bar, the secondary progress runs from 0 to 1.
493             /// </summary>
494             /// <since_tizen> 3 </since_tizen>
495             public float SecondaryProgressValue
496             {
497                 get
498                 {
499                     return _secondaryProgressValue;
500                 }
501                 set
502                 {
503                     _secondaryProgressValue = value;
504                 }
505             }
506
507         }
508
509         internal new class Property
510         {
511             internal static readonly int PROGRESS_VALUE = Interop.ProgressBar.ProgressBar_Property_PROGRESS_VALUE_get();
512             internal static readonly int SECONDARY_PROGRESS_VALUE = Interop.ProgressBar.ProgressBar_Property_SECONDARY_PROGRESS_VALUE_get();
513             internal static readonly int INDETERMINATE = Interop.ProgressBar.ProgressBar_Property_INDETERMINATE_get();
514             internal static readonly int TRACK_VISUAL = Interop.ProgressBar.ProgressBar_Property_TRACK_VISUAL_get();
515             internal static readonly int PROGRESS_VISUAL = Interop.ProgressBar.ProgressBar_Property_PROGRESS_VISUAL_get();
516             internal static readonly int SECONDARY_PROGRESS_VISUAL = Interop.ProgressBar.ProgressBar_Property_SECONDARY_PROGRESS_VISUAL_get();
517             internal static readonly int INDETERMINATE_VISUAL = Interop.ProgressBar.ProgressBar_Property_INDETERMINATE_VISUAL_get();
518             internal static readonly int INDETERMINATE_VISUAL_ANIMATION = Interop.ProgressBar.ProgressBar_Property_INDETERMINATE_VISUAL_ANIMATION_get();
519             internal static readonly int LABEL_VISUAL = Interop.ProgressBar.ProgressBar_Property_LABEL_VISUAL_get();
520         }
521     }
522 }