a6bde472301c33ab98a90b196a4b70cb373b5ce7
[platform/core/csapi/nui.git] / Tizen.NUI / src / public / UIComponents / ProgressBar.cs
1 /** Copyright (c) 2017 Samsung Electronics Co., Ltd.
2 *
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 *
15 */
16
17 namespace Tizen.NUI.UIComponents
18 {
19
20     using System;
21     using System.Runtime.InteropServices;
22     using Tizen.NUI.BaseComponents;
23
24     /// <summary>
25     /// ProgressBar is a control to give the user an indication of the progress of an operation.
26     /// </summary>
27     public class ProgressBar : View
28     {
29         private global::System.Runtime.InteropServices.HandleRef swigCPtr;
30
31         internal ProgressBar(global::System.IntPtr cPtr, bool cMemoryOwn) : base(NDalicPINVOKE.ProgressBar_SWIGUpcast(cPtr), cMemoryOwn)
32         {
33             swigCPtr = new global::System.Runtime.InteropServices.HandleRef(this, cPtr);
34         }
35
36         internal static global::System.Runtime.InteropServices.HandleRef getCPtr(ProgressBar obj)
37         {
38             return (obj == null) ? new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero) : obj.swigCPtr;
39         }
40
41         /// <summary>
42         /// To make ProgressBar instance be disposed.
43         /// </summary>
44         protected override void Dispose(DisposeTypes type)
45         {
46             if (disposed)
47             {
48                 return;
49             }
50
51             if (type == DisposeTypes.Explicit)
52             {
53                 //Called by User
54                 //Release your own managed resources here.
55                 //You should release all of your own disposable objects here.
56
57             }
58
59             //Release your own unmanaged resources here.
60             //You should not access any managed member here except static instance.
61             //because the execution order of Finalizes is non-deterministic.
62
63             if (_progressBarValueChangedCallbackDelegate != null)
64             {
65                 ValueChangedSignal().Disconnect(_progressBarValueChangedCallbackDelegate);
66             }
67
68             if (swigCPtr.Handle != global::System.IntPtr.Zero)
69             {
70                 if (swigCMemOwn)
71                 {
72                     swigCMemOwn = false;
73                     NDalicPINVOKE.delete_ProgressBar(swigCPtr);
74                 }
75                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
76             }
77
78             base.Dispose(type);
79         }
80
81
82         /// <summary>
83         /// Event arguments that passed via ValueChangedEventArgs
84         /// </summary>
85         public class ValueChangedEventArgs : EventArgs
86         {
87             private ProgressBar _progressBar;
88             private float _progressValue;
89             private float _secondaryProgressValue;
90
91             public ProgressBar ProgressBar
92             {
93                 get
94                 {
95                     return _progressBar;
96                 }
97                 set
98                 {
99                     _progressBar = value;
100                 }
101             }
102
103             public float ProgressValue
104             {
105                 get
106                 {
107                     return _progressValue;
108                 }
109                 set
110                 {
111                     _progressValue = value;
112                 }
113             }
114
115             public float SecondaryProgressValue
116             {
117                 get
118                 {
119                     return _secondaryProgressValue;
120                 }
121                 set
122                 {
123                     _secondaryProgressValue = value;
124                 }
125             }
126
127         }
128
129         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
130         private delegate void ValueChangedCallbackDelegate(IntPtr progressBar, float progressValue, float secondaryProgressValue);
131         private EventHandler<ValueChangedEventArgs> _progressBarValueChangedEventHandler;
132         private ValueChangedCallbackDelegate _progressBarValueChangedCallbackDelegate;
133
134         /// <summary>
135         /// Event is sent when the ProgressBar value changes.
136         /// </summary>
137         public event EventHandler<ValueChangedEventArgs> ValueChanged
138         {
139             add
140             {
141                 if (_progressBarValueChangedEventHandler == null)
142                 {
143                     _progressBarValueChangedCallbackDelegate = (OnValueChanged);
144                     ValueChangedSignal().Connect(_progressBarValueChangedCallbackDelegate);
145                 }
146                 _progressBarValueChangedEventHandler += value;
147             }
148             remove
149             {
150                 _progressBarValueChangedEventHandler -= value;
151                 if (_progressBarValueChangedEventHandler == null && ValueChangedSignal().Empty() == false)
152                 {
153                     ValueChangedSignal().Disconnect(_progressBarValueChangedCallbackDelegate);
154                 }
155             }
156         }
157
158         // Callback for ProgressBar ValueChanged signal
159         private void OnValueChanged(IntPtr progressBar, float progressValue, float secondaryProgressValue)
160         {
161             ValueChangedEventArgs e = new ValueChangedEventArgs();
162
163             // Populate all members of "e" (ValueChangedEventArgs) with real page
164             e.ProgressBar = Registry.GetManagedBaseHandleFromNativePtr(progressBar) as ProgressBar;
165             e.ProgressValue = progressValue;
166             e.SecondaryProgressValue = secondaryProgressValue;
167
168             if (_progressBarValueChangedEventHandler != null)
169             {
170                 _progressBarValueChangedEventHandler(this, e);
171             }
172         }
173
174         internal class Property
175         {
176             internal static readonly int PROGRESS_VALUE = NDalicPINVOKE.ProgressBar_Property_PROGRESS_VALUE_get();
177             internal static readonly int SECONDARY_PROGRESS_VALUE = NDalicPINVOKE.ProgressBar_Property_SECONDARY_PROGRESS_VALUE_get();
178             internal static readonly int INDETERMINATE = NDalicPINVOKE.ProgressBar_Property_INDETERMINATE_get();
179             internal static readonly int TRACK_VISUAL = NDalicPINVOKE.ProgressBar_Property_TRACK_VISUAL_get();
180             internal static readonly int PROGRESS_VISUAL = NDalicPINVOKE.ProgressBar_Property_PROGRESS_VISUAL_get();
181             internal static readonly int SECONDARY_PROGRESS_VISUAL = NDalicPINVOKE.ProgressBar_Property_SECONDARY_PROGRESS_VISUAL_get();
182             internal static readonly int INDETERMINATE_VISUAL = NDalicPINVOKE.ProgressBar_Property_INDETERMINATE_VISUAL_get();
183             internal static readonly int INDETERMINATE_VISUAL_ANIMATION = NDalicPINVOKE.ProgressBar_Property_INDETERMINATE_VISUAL_ANIMATION_get();
184             internal static readonly int LABEL_VISUAL = NDalicPINVOKE.ProgressBar_Property_LABEL_VISUAL_get();
185         }
186
187         /// <summary>
188         /// Creates the ProgressBar.
189         /// </summary>
190         public ProgressBar() : this(NDalicPINVOKE.ProgressBar_New(), true)
191         {
192             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
193
194         }
195
196         internal ProgressBarValueChangedSignal ValueChangedSignal()
197         {
198             ProgressBarValueChangedSignal ret = new ProgressBarValueChangedSignal(NDalicPINVOKE.ProgressBar_ValueChangedSignal(swigCPtr), false);
199             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
200             return ret;
201         }
202
203         /// <summary>
204         /// The progress value of progress bar, progress runs form 0 to 1.<br>
205         /// If Value is set to 0, progress bar will be set to beginning.<br>
206         /// If Value is set to 1, progress bar will be set to end.<br>
207         /// Any Value outside of the range is ignored.<br>
208         /// </summary>
209         public float ProgressValue
210         {
211             get
212             {
213                 float temp = 0.0f;
214                 GetProperty(ProgressBar.Property.PROGRESS_VALUE).Get(out temp);
215                 return temp;
216             }
217             set
218             {
219                 SetProperty(ProgressBar.Property.PROGRESS_VALUE, new Tizen.NUI.PropertyValue(value));
220             }
221         }
222         /// <summary>
223         /// The secondary progress value of progress bar, secondary progress runs form 0 to 1.<br>
224         /// Optional. If not supplied, the default is 0.<br>
225         /// If Value is set to 0, progress bar will be set secondary progress to beginning.<br>
226         /// If Value is set to 1, progress bar will be set secondary progress to end.<br>
227         /// Any Value outside of the range is ignored.<br>
228         /// </summary>
229         public float SecondaryProgressValue
230         {
231             get
232             {
233                 float temp = 0.0f;
234                 GetProperty(ProgressBar.Property.SECONDARY_PROGRESS_VALUE).Get(out temp);
235                 return temp;
236             }
237             set
238             {
239                 SetProperty(ProgressBar.Property.SECONDARY_PROGRESS_VALUE, new Tizen.NUI.PropertyValue(value));
240             }
241         }
242         /// <summary>
243         /// Sets the progress-bar as \e indeterminate state.
244         /// </summary>
245         public bool Indeterminate
246         {
247             get
248             {
249                 bool temp = false;
250                 GetProperty(ProgressBar.Property.INDETERMINATE).Get(out temp);
251                 return temp;
252             }
253             set
254             {
255                 SetProperty(ProgressBar.Property.INDETERMINATE, new Tizen.NUI.PropertyValue(value));
256             }
257         }
258         /// <summary>
259         /// The track Visual value of progress bar, it's a full progress area and it's shown behind PROGRESS_VISUAL.<br>
260         /// Optional. If not supplied, the default track visual will be shown.<br>
261         /// </summary>
262         public Tizen.NUI.PropertyMap TrackVisual
263         {
264             get
265             {
266                 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
267                 GetProperty(ProgressBar.Property.TRACK_VISUAL).Get(temp);
268                 return temp;
269             }
270             set
271             {
272                 SetProperty(ProgressBar.Property.TRACK_VISUAL, new Tizen.NUI.PropertyValue(value));
273             }
274         }
275         /// <summary>
276         /// The progress Visual value of progress bar, size of the progress visual is changed based on PROGRESS_VALUE.<br>
277         /// Optional. If not supplied, the default progress visual will be shown.<br>
278         /// </summary>
279         public Tizen.NUI.PropertyMap ProgressVisual
280         {
281             get
282             {
283                 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
284                 GetProperty(ProgressBar.Property.PROGRESS_VISUAL).Get(temp);
285                 return temp;
286             }
287             set
288             {
289                 SetProperty(ProgressBar.Property.PROGRESS_VISUAL, new Tizen.NUI.PropertyValue(value));
290             }
291         }
292         /// <summary>
293         /// The secondary progress visual of progress bar, size of the secondary progress visual is changed based on SECONDARY_PROGRESS_VALUE.<br>
294         /// Optional. If not supplied, the secondary progress visual will not be shown.<br>
295         /// </summary>
296         public Tizen.NUI.PropertyMap SecondaryProgressVisual
297         {
298             get
299             {
300                 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
301                 GetProperty(ProgressBar.Property.SECONDARY_PROGRESS_VISUAL).Get(temp);
302                 return temp;
303             }
304             set
305             {
306                 SetProperty(ProgressBar.Property.SECONDARY_PROGRESS_VISUAL, new Tizen.NUI.PropertyValue(value));
307             }
308         }
309         /// <summary>
310         /// The indeterminate visual of progress bar.<br>
311         /// Optional. If not supplied, the default inditerminate visual will be shown.<br>
312         /// </summary>
313         public Tizen.NUI.PropertyMap IndeterminateVisual
314         {
315             get
316             {
317                 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
318                 GetProperty(ProgressBar.Property.INDETERMINATE_VISUAL).Get(temp);
319                 return temp;
320             }
321             set
322             {
323                 SetProperty(ProgressBar.Property.INDETERMINATE_VISUAL, new Tizen.NUI.PropertyValue(value));
324             }
325         }
326         /// <summary>
327         /// The transition data for indeterminate visual animation.<br>
328         /// Optional. If not supplied, default animation will be played.<br>
329         /// </summary>
330         public Tizen.NUI.PropertyArray IndeterminateVisualAnimation
331         {
332             get
333             {
334                 Tizen.NUI.PropertyArray temp = new Tizen.NUI.PropertyArray();
335                 GetProperty(ProgressBar.Property.INDETERMINATE_VISUAL_ANIMATION).Get(temp);
336                 return temp;
337             }
338             set
339             {
340                 SetProperty(ProgressBar.Property.INDETERMINATE_VISUAL_ANIMATION, new Tizen.NUI.PropertyValue(value));
341             }
342         }
343         /// <summary>
344         /// The Label visual of progress bar.
345         /// </summary>
346         public Tizen.NUI.PropertyMap LabelVisual
347         {
348             get
349             {
350                 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
351                 GetProperty(ProgressBar.Property.LABEL_VISUAL).Get(temp);
352                 return temp;
353             }
354             set
355             {
356                 SetProperty(ProgressBar.Property.LABEL_VISUAL, new Tizen.NUI.PropertyValue(value));
357             }
358         }
359
360     }
361
362 }