[NUI] TCSACR-226 code change (#1032)
[platform/core/csapi/tizenfx.git] / src / ElmSharp / ElmSharp / Spinner.cs
1 /*
2  * Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
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
19 namespace ElmSharp
20 {
21     /// <summary>
22     /// The Spinner is a widget that increases or decreases the numeric values using arrow buttons, or edit values directly.
23     /// Inherits <see cref="Layout"/>.
24     /// </summary>
25     /// <since_tizen> preview </since_tizen>
26     public class Spinner : Layout
27     {
28         double _minimum = 0.0;
29         double _maximum = 100.0;
30
31         SmartEvent _changed;
32         SmartEvent _delayedChanged;
33
34         /// <summary>
35         /// Creates and initializes a new instance of the Spinner class.
36         /// </summary>
37         /// <param name="parent">The parent of new Spinner instance</param>
38         /// <since_tizen> preview </since_tizen>
39         public Spinner(EvasObject parent) : base(parent)
40         {
41             if (Elementary.GetProfile() == "tv")
42             {
43                 Style = "vertical";
44             }
45         }
46
47         /// <summary>
48         /// Creates and initializes a new instance of the Layout class.
49         /// </summary>
50         /// <since_tizen> preview </since_tizen>
51         protected Spinner() : base()
52         {
53         }
54
55         /// <summary>
56         /// ValueChanged will be triggered whenever the spinner value is changed.
57         /// </summary>
58         /// <since_tizen> preview </since_tizen>
59         public event EventHandler ValueChanged;
60
61         /// <summary>
62         /// DelayedValueChanged will be triggered after a short time when the value is changed.
63         /// </summary>
64         /// <since_tizen> preview </since_tizen>
65         public event EventHandler DelayedValueChanged;
66
67         /// <summary>
68         /// Sets or gets the label format of the spinner.
69         /// </summary>
70         /// <since_tizen> preview </since_tizen>
71         public string LabelFormat
72         {
73             get
74             {
75                 return Interop.Elementary.elm_spinner_label_format_get(RealHandle);
76             }
77             set
78             {
79                 Interop.Elementary.elm_spinner_label_format_set(RealHandle, value);
80             }
81         }
82
83         /// <summary>
84         /// Sets or gets the minimum value for the spinner.
85         /// </summary>
86         /// <since_tizen> preview </since_tizen>
87         public double Minimum
88         {
89             get
90             {
91                 return _minimum;
92             }
93             set
94             {
95                 _minimum = value;
96                 Interop.Elementary.elm_spinner_min_max_set(RealHandle, _minimum, _maximum);
97             }
98         }
99
100         /// <summary>
101         /// Sets or gets the maximum value for the spinner.
102         /// </summary>
103         /// <since_tizen> preview </since_tizen>
104         public double Maximum
105         {
106             get
107             {
108                 return _maximum;
109             }
110             set
111             {
112                 _maximum = value;
113                 Interop.Elementary.elm_spinner_min_max_set(RealHandle, _minimum, _maximum);
114             }
115         }
116
117         /// <summary>
118         /// Sets or gets the step that is used to increment or decrement the spinner value.
119         /// </summary>
120         /// <since_tizen> preview </since_tizen>
121         public double Step
122         {
123             get
124             {
125                 return Interop.Elementary.elm_spinner_step_get(RealHandle);
126             }
127             set
128             {
129                 Interop.Elementary.elm_spinner_step_set(RealHandle, value);
130             }
131         }
132
133         /// <summary>
134         /// Sets or gets the value displayed by the spinner.
135         /// </summary>
136         /// <since_tizen> preview </since_tizen>
137         public double Value
138         {
139             get
140             {
141                 return Interop.Elementary.elm_spinner_value_get(RealHandle);
142             }
143             set
144             {
145                 Interop.Elementary.elm_spinner_value_set(RealHandle, value);
146             }
147         }
148
149         /// <summary>
150         /// Sets or gets the interval on time updates for a user mouse button to hold on the spinner widgets' arrows.
151         /// </summary>
152         /// <since_tizen> preview </since_tizen>
153         public double Interval
154         {
155             get
156             {
157                 return Interop.Elementary.elm_spinner_interval_get(RealHandle);
158             }
159             set
160             {
161                 Interop.Elementary.elm_spinner_interval_set(RealHandle, value);
162             }
163         }
164
165         /// <summary>
166         /// Sets or gets the base for rounding.
167         /// </summary>
168         /// <since_tizen> preview </since_tizen>
169         public double RoundBase
170         {
171             get
172             {
173                 return Interop.Elementary.elm_spinner_base_get(RealHandle);
174             }
175             set
176             {
177                 Interop.Elementary.elm_spinner_base_set(RealHandle, value);
178             }
179         }
180
181         /// <summary>
182         /// Sets or gets the round value for rounding.
183         /// </summary>
184         /// <since_tizen> preview </since_tizen>
185         public int RoundValue
186         {
187             get
188             {
189                 return Interop.Elementary.elm_spinner_round_get(RealHandle);
190             }
191             set
192             {
193                 Interop.Elementary.elm_spinner_round_set(RealHandle, value);
194             }
195         }
196
197         /// <summary>
198         /// Sets or gets the wrap of a given spinner widget.
199         /// </summary>
200         /// <remarks>
201         /// If wrap is disabled when the user tries to increment the value, but the displayed value plus step value is bigger than the maximum value, then the new value will be the maximum value.
202         /// If wrap is enabled when the user tries to increment the value, but the displayed value plus step value is bigger than the maximum value, then the new value will be the minimum value.
203         /// By default, it's disabled.
204         /// </remarks>
205         /// <since_tizen> preview </since_tizen>
206         public bool IsWrapEnabled
207         {
208             get
209             {
210                 return Interop.Elementary.elm_spinner_wrap_get(RealHandle);
211             }
212             set
213             {
214                 Interop.Elementary.elm_spinner_wrap_set(RealHandle, value);
215             }
216         }
217
218         /// <summary>
219         /// Sets or gets whether the spinner can be directly edited by the user or not.
220         /// </summary>
221         /// <remarks>By default, it is enabled.</remarks>
222         /// <since_tizen> preview </since_tizen>
223         public bool IsEditable
224         {
225             get
226             {
227                 return Interop.Elementary.elm_spinner_editable_get(RealHandle);
228             }
229             set
230             {
231                 Interop.Elementary.elm_spinner_editable_set(RealHandle, value);
232             }
233         }
234
235         /// <summary>
236         /// Sets a special string to display in the place of the numerical value.
237         /// </summary>
238         /// <param name="value">The numerical value to be replaced</param>
239         /// <param name="label">The label to be used</param>
240         /// <since_tizen> preview </since_tizen>
241         public void AddSpecialValue(double value, string label)
242         {
243             Interop.Elementary.elm_spinner_special_value_add(RealHandle, value, label);
244         }
245
246         /// <summary>
247         /// Removes a previously added special value. After this, the spinner will display the value itself instead of a label.
248         /// </summary>
249         /// <param name="value">The replaced numerical value.</param>
250         /// <since_tizen> preview </since_tizen>
251         public void RemoveSpecialValue(double value)
252         {
253             Interop.Elementary.elm_spinner_special_value_del(RealHandle, value);
254         }
255
256         /// <summary>
257         /// Gets the special string display in the place of the numerical value.
258         /// </summary>
259         /// <param name="value">The replaced numerical value.</param>
260         /// <returns>The value of the spinner, which replaced the numerical value with a special string.</returns>
261         /// <since_tizen> preview </since_tizen>
262         public string GetSpecialValue(double value)
263         {
264             return Interop.Elementary.elm_spinner_special_value_get(RealHandle, value);
265         }
266
267         /// <summary>
268         /// The callback of the Realized event.
269         /// </summary>
270         /// <since_tizen> preview </since_tizen>
271         protected override void OnRealized()
272         {
273             base.OnRealized();
274             _changed = new SmartEvent(this, this.RealHandle, "changed");
275             _changed.On += (s, e) => ValueChanged?.Invoke(this, EventArgs.Empty);
276
277             _delayedChanged = new SmartEvent(this, this.RealHandle, "delay,changed");
278             _delayedChanged.On += (s, e) => DelayedValueChanged?.Invoke(this, EventArgs.Empty);
279         }
280
281         /// <summary>
282         /// Creates a widget handle.
283         /// </summary>
284         /// <param name="parent">Parent EvasObject.</param>
285         /// <returns>Handle IntPtr.</returns>
286         /// <since_tizen> preview </since_tizen>
287         protected override IntPtr CreateHandle(EvasObject parent)
288         {
289             IntPtr handle = Interop.Elementary.elm_layout_add(parent.Handle);
290             Interop.Elementary.elm_layout_theme_set(handle, "layout", "elm_widget", "default");
291
292             RealHandle = Interop.Elementary.elm_spinner_add(handle);
293             Interop.Elementary.elm_object_part_content_set(handle, "elm.swallow.content", RealHandle);
294
295             return handle;
296         }
297     }
298 }