Ensuring that Registry.Unregister is called from the most derived class before the...
[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 (swigCPtr.Handle != global::System.IntPtr.Zero)
64             {
65                 if (swigCMemOwn)
66                 {
67                     swigCMemOwn = false;
68
69                     //Unreference this instance from Registry.
70                     Registry.Unregister(this);
71
72                     NDalicPINVOKE.delete_ProgressBar(swigCPtr);
73                 }
74                 swigCPtr = new global::System.Runtime.InteropServices.HandleRef(null, global::System.IntPtr.Zero);
75             }
76
77             base.Dispose(type);
78         }
79
80
81         /// <summary>
82         /// Event arguments that passed via ValueChangedEventArgs
83         /// </summary>
84         public class ValueChangedEventArgs : EventArgs
85         {
86             private ProgressBar _progressBar;
87             private float _progressValue;
88             private float _secondaryProgressValue;
89
90             public ProgressBar ProgressBar
91             {
92                 get
93                 {
94                     return _progressBar;
95                 }
96                 set
97                 {
98                     _progressBar = value;
99                 }
100             }
101
102             public float ProgressValue
103             {
104                 get
105                 {
106                     return _progressValue;
107                 }
108                 set
109                 {
110                     _progressValue = value;
111                 }
112             }
113
114             public float SecondaryProgressValue
115             {
116                 get
117                 {
118                     return _secondaryProgressValue;
119                 }
120                 set
121                 {
122                     _secondaryProgressValue = value;
123                 }
124             }
125
126         }
127
128         [UnmanagedFunctionPointer(CallingConvention.StdCall)]
129         private delegate void ValueChangedCallbackDelegate(IntPtr progressBar, float progressValue, float secondaryProgressValue);
130         private EventHandler<ValueChangedEventArgs> _progressBarValueChangedEventHandler;
131         private ValueChangedCallbackDelegate _progressBarValueChangedCallbackDelegate;
132
133         /// <summary>
134         /// Event is sent when the ProgressBar value changes.
135         /// </summary>
136         public event EventHandler<ValueChangedEventArgs> ValueChanged
137         {
138             add
139             {
140                 if (_progressBarValueChangedEventHandler == null)
141                 {
142                     _progressBarValueChangedCallbackDelegate = (OnValueChanged);
143                     ValueChangedSignal().Connect(_progressBarValueChangedCallbackDelegate);
144                 }
145                 _progressBarValueChangedEventHandler += value;
146             }
147             remove
148             {
149                 _progressBarValueChangedEventHandler -= value;
150                 if (_progressBarValueChangedEventHandler == null && ValueChangedSignal().Empty() == false)
151                 {
152                     ValueChangedSignal().Disconnect(_progressBarValueChangedCallbackDelegate);
153                 }
154             }
155         }
156
157         // Callback for ProgressBar ValueChanged signal
158         private void OnValueChanged(IntPtr progressBar, float progressValue, float secondaryProgressValue)
159         {
160             ValueChangedEventArgs e = new ValueChangedEventArgs();
161
162             // Populate all members of "e" (ValueChangedEventArgs) with real page
163             e.ProgressBar = Registry.GetManagedBaseHandleFromNativePtr(progressBar) as ProgressBar;
164             e.ProgressValue = progressValue;
165             e.SecondaryProgressValue = secondaryProgressValue;
166
167             if (_progressBarValueChangedEventHandler != null)
168             {
169                 _progressBarValueChangedEventHandler(this, e);
170             }
171         }
172
173         internal class Property
174         {
175             internal static readonly int PROGRESS_VALUE = NDalicPINVOKE.ProgressBar_Property_PROGRESS_VALUE_get();
176             internal static readonly int SECONDARY_PROGRESS_VALUE = NDalicPINVOKE.ProgressBar_Property_SECONDARY_PROGRESS_VALUE_get();
177             internal static readonly int INDETERMINATE = NDalicPINVOKE.ProgressBar_Property_INDETERMINATE_get();
178             internal static readonly int TRACK_VISUAL = NDalicPINVOKE.ProgressBar_Property_TRACK_VISUAL_get();
179             internal static readonly int PROGRESS_VISUAL = NDalicPINVOKE.ProgressBar_Property_PROGRESS_VISUAL_get();
180             internal static readonly int SECONDARY_PROGRESS_VISUAL = NDalicPINVOKE.ProgressBar_Property_SECONDARY_PROGRESS_VISUAL_get();
181             internal static readonly int INDETERMINATE_VISUAL = NDalicPINVOKE.ProgressBar_Property_INDETERMINATE_VISUAL_get();
182             internal static readonly int INDETERMINATE_VISUAL_ANIMATION = NDalicPINVOKE.ProgressBar_Property_INDETERMINATE_VISUAL_ANIMATION_get();
183             internal static readonly int LABEL_VISUAL = NDalicPINVOKE.ProgressBar_Property_LABEL_VISUAL_get();
184         }
185
186         /// <summary>
187         /// Creates the ProgressBar.
188         /// </summary>
189         public ProgressBar() : this(NDalicPINVOKE.ProgressBar_New(), true)
190         {
191             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
192
193         }
194
195         internal ProgressBarValueChangedSignal ValueChangedSignal()
196         {
197             ProgressBarValueChangedSignal ret = new ProgressBarValueChangedSignal(NDalicPINVOKE.ProgressBar_ValueChangedSignal(swigCPtr), false);
198             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
199             return ret;
200         }
201
202         /// <summary>
203         /// The progress value of progress bar, progress runs form 0 to 1.<br>
204         /// If Value is set to 0, progress bar will be set to beginning.<br>
205         /// If Value is set to 1, progress bar will be set to end.<br>
206         /// Any Value outside of the range is ignored.<br>
207         /// </summary>
208         public float ProgressValue
209         {
210             get
211             {
212                 float temp = 0.0f;
213                 GetProperty(ProgressBar.Property.PROGRESS_VALUE).Get(out temp);
214                 return temp;
215             }
216             set
217             {
218                 SetProperty(ProgressBar.Property.PROGRESS_VALUE, new Tizen.NUI.PropertyValue(value));
219             }
220         }
221         /// <summary>
222         /// The secondary progress value of progress bar, secondary progress runs form 0 to 1.<br>
223         /// Optional. If not supplied, the default is 0.<br>
224         /// If Value is set to 0, progress bar will be set secondary progress to beginning.<br>
225         /// If Value is set to 1, progress bar will be set secondary progress to end.<br>
226         /// Any Value outside of the range is ignored.<br>
227         /// </summary>
228         public float SecondaryProgressValue
229         {
230             get
231             {
232                 float temp = 0.0f;
233                 GetProperty(ProgressBar.Property.SECONDARY_PROGRESS_VALUE).Get(out temp);
234                 return temp;
235             }
236             set
237             {
238                 SetProperty(ProgressBar.Property.SECONDARY_PROGRESS_VALUE, new Tizen.NUI.PropertyValue(value));
239             }
240         }
241         /// <summary>
242         /// Sets the progress-bar as \e indeterminate state.
243         /// </summary>
244         public bool Indeterminate
245         {
246             get
247             {
248                 bool temp = false;
249                 GetProperty(ProgressBar.Property.INDETERMINATE).Get(out temp);
250                 return temp;
251             }
252             set
253             {
254                 SetProperty(ProgressBar.Property.INDETERMINATE, new Tizen.NUI.PropertyValue(value));
255             }
256         }
257         /// <summary>
258         /// The track Visual value of progress bar, it's a full progress area and it's shown behind PROGRESS_VISUAL.<br>
259         /// Optional. If not supplied, the default track visual will be shown.<br>
260         /// </summary>
261         public Tizen.NUI.PropertyMap TrackVisual
262         {
263             get
264             {
265                 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
266                 GetProperty(ProgressBar.Property.TRACK_VISUAL).Get(temp);
267                 return temp;
268             }
269             set
270             {
271                 SetProperty(ProgressBar.Property.TRACK_VISUAL, new Tizen.NUI.PropertyValue(value));
272             }
273         }
274         /// <summary>
275         /// The progress Visual value of progress bar, size of the progress visual is changed based on PROGRESS_VALUE.<br>
276         /// Optional. If not supplied, the default progress visual will be shown.<br>
277         /// </summary>
278         public Tizen.NUI.PropertyMap ProgressVisual
279         {
280             get
281             {
282                 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
283                 GetProperty(ProgressBar.Property.PROGRESS_VISUAL).Get(temp);
284                 return temp;
285             }
286             set
287             {
288                 SetProperty(ProgressBar.Property.PROGRESS_VISUAL, new Tizen.NUI.PropertyValue(value));
289             }
290         }
291         /// <summary>
292         /// The secondary progress visual of progress bar, size of the secondary progress visual is changed based on SECONDARY_PROGRESS_VALUE.<br>
293         /// Optional. If not supplied, the secondary progress visual will not be shown.<br>
294         /// </summary>
295         public Tizen.NUI.PropertyMap SecondaryProgressVisual
296         {
297             get
298             {
299                 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
300                 GetProperty(ProgressBar.Property.SECONDARY_PROGRESS_VISUAL).Get(temp);
301                 return temp;
302             }
303             set
304             {
305                 SetProperty(ProgressBar.Property.SECONDARY_PROGRESS_VISUAL, new Tizen.NUI.PropertyValue(value));
306             }
307         }
308         /// <summary>
309         /// The indeterminate visual of progress bar.<br>
310         /// Optional. If not supplied, the default inditerminate visual will be shown.<br>
311         /// </summary>
312         public Tizen.NUI.PropertyMap IndeterminateVisual
313         {
314             get
315             {
316                 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
317                 GetProperty(ProgressBar.Property.INDETERMINATE_VISUAL).Get(temp);
318                 return temp;
319             }
320             set
321             {
322                 SetProperty(ProgressBar.Property.INDETERMINATE_VISUAL, new Tizen.NUI.PropertyValue(value));
323             }
324         }
325         /// <summary>
326         /// The transition data for indeterminate visual animation.<br>
327         /// Optional. If not supplied, default animation will be played.<br>
328         /// </summary>
329         public Tizen.NUI.PropertyArray IndeterminateVisualAnimation
330         {
331             get
332             {
333                 Tizen.NUI.PropertyArray temp = new Tizen.NUI.PropertyArray();
334                 GetProperty(ProgressBar.Property.INDETERMINATE_VISUAL_ANIMATION).Get(temp);
335                 return temp;
336             }
337             set
338             {
339                 SetProperty(ProgressBar.Property.INDETERMINATE_VISUAL_ANIMATION, new Tizen.NUI.PropertyValue(value));
340             }
341         }
342         /// <summary>
343         /// The Label visual of progress bar.
344         /// </summary>
345         public Tizen.NUI.PropertyMap LabelVisual
346         {
347             get
348             {
349                 Tizen.NUI.PropertyMap temp = new Tizen.NUI.PropertyMap();
350                 GetProperty(ProgressBar.Property.LABEL_VISUAL).Get(temp);
351                 return temp;
352             }
353             set
354             {
355                 SetProperty(ProgressBar.Property.LABEL_VISUAL, new Tizen.NUI.PropertyValue(value));
356             }
357         }
358
359     }
360
361 }