Merge branch 'master' into svn_merge
[framework/uifw/elementary.git] / src / lib / elm_spinner.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3 #include <ctype.h>
4
5 /**
6  * @defgroup Spinner
7  * @ingroup Elementary
8  *
9  * A spinner is a widget which allows the user to increase or decrease
10  * numeric values. By default the spinner will not wrap and has a label
11  * of "%.0f" (just showing the integer value of the double).
12  *
13  * A spinner has a label that is formatted with floating
14  * point values and thus accepts a printf-style format string, like
15  * “%1.2f units”.
16  *
17  * Signals that you can add callbacks for are:
18  *
19  * "changed" - Whenever the spinner value is changed by the user.
20  * "delay,changed" - A short time after the value is changed by the user.
21  *                   This will be called only when the user stops dragging for a very short
22  *                   period or when they release their finger/mouse, so it avoids possibly
23  *                   expensive reactions to the value change.
24  */
25 typedef struct _Widget_Data Widget_Data;
26 typedef struct _Elm_Spinner_Special_Value Elm_Spinner_Special_Value;
27
28 struct _Widget_Data
29 {
30    Evas_Object *spinner, *ent;
31    const char *label;
32    double val, val_min, val_max, orig_val, step;
33    double drag_start_pos, spin_speed, interval, first_interval;
34    Ecore_Timer *delay, *spin;
35    Eina_List *special_values;
36    Eina_Bool wrap : 1;
37    Eina_Bool entry_visible : 1;
38    Eina_Bool dragging : 1;
39    Eina_Bool editable : 1;
40 };
41
42 struct _Elm_Spinner_Special_Value
43 {
44    double value;
45    const char *label;
46 };
47
48 static const char *widtype = NULL;
49 static void _del_hook(Evas_Object *obj);
50 static void _disable_hook(Evas_Object *obj);
51 static void _write_label(Evas_Object *obj);
52 static void _sizing_eval(Evas_Object *obj);
53 //static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
54 static Eina_Bool _value_set(Evas_Object *obj, double delta);
55 static void _on_focus_hook(void *data, Evas_Object *obj);
56 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
57                              Evas_Callback_Type type, void *event_info);
58
59 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
60
61 static const char SIG_CHANGED[] = "changed";
62 static const char SIG_DELAY_CHANGED[] = "delay,changed";
63
64 static const Evas_Smart_Cb_Description _signals[] = {
65    {SIG_CHANGED, ""},
66    {SIG_DELAY_CHANGED, ""},
67    {NULL, NULL}
68 };
69
70 static void
71 _del_hook(Evas_Object *obj)
72 {
73    Elm_Spinner_Special_Value *sv;
74    Widget_Data *wd = elm_widget_data_get(obj);
75    if (!wd) return;
76    if (wd->label) eina_stringshare_del(wd->label);
77    if (wd->delay) ecore_timer_del(wd->delay);
78    if (wd->spin) ecore_timer_del(wd->spin);
79    if (wd->special_values)
80      {
81         EINA_LIST_FREE(wd->special_values, sv)
82           {
83              eina_stringshare_del(sv->label);
84              free(sv);
85           }
86      }
87    free(wd);
88 }
89
90 static void
91 _disable_hook(Evas_Object *obj)
92 {
93    Widget_Data *wd = elm_widget_data_get(obj);
94    if (!wd) return;
95    if (elm_widget_disabled_get(obj))
96       edje_object_signal_emit(wd->spinner, "elm,state,disabled", "elm");
97    else
98       edje_object_signal_emit(wd->spinner, "elm,state,enabled", "elm");
99 }
100
101 static void
102 _signal_emit_hook(Evas_Object *obj, const char *emission, const char *source)
103 {
104    Widget_Data *wd = elm_widget_data_get(obj);
105    if (!wd) return;
106    edje_object_signal_emit(wd->spinner, emission, source);
107 }
108
109 static void
110 _signal_callback_add_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
111 {
112    Widget_Data *wd = elm_widget_data_get(obj);
113    if (!wd) return;
114    edje_object_signal_callback_add(wd->spinner, emission,
115                                    source, func_cb, data);
116 }
117
118 static void
119 _signal_callback_del_hook(Evas_Object *obj, const char *emission, const char *source, Edje_Signal_Cb func_cb, void *data)
120 {
121    Widget_Data *wd = elm_widget_data_get(obj);
122    edje_object_signal_callback_del_full(wd->spinner, emission, source,
123                                         func_cb, data);
124 }
125
126 static void
127 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
128 {
129    Widget_Data *wd = elm_widget_data_get(obj);
130    if (!wd) return;
131    edje_object_mirrored_set(wd->spinner, rtl);
132 }
133
134 static void
135 _theme_hook(Evas_Object *obj)
136 {
137    Widget_Data *wd = elm_widget_data_get(obj);
138    if (!wd) return;
139    _elm_widget_mirrored_reload(obj);
140    _mirrored_set(obj, elm_widget_mirrored_get(obj));
141    _elm_theme_object_set(obj, wd->spinner, "spinner", "base", elm_widget_style_get(obj));
142    edje_object_part_swallow(wd->spinner, "elm.swallow.entry", wd->ent);
143    _write_label(obj);
144    if (elm_widget_focus_get(obj))
145       edje_object_signal_emit(wd->spinner, "elm,action,focus", "elm");
146    else
147       edje_object_signal_emit(wd->spinner, "elm,action,unfocus", "elm");
148    if (elm_widget_disabled_get(obj))
149       edje_object_signal_emit(wd->spinner, "elm,state,disabled", "elm");
150    edje_object_message_signal_process(wd->spinner);
151    edje_object_scale_set(wd->spinner, elm_widget_scale_get(obj) * _elm_config->scale);
152    _sizing_eval(obj);
153 }
154
155 static void
156 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
157 {
158    Widget_Data *wd = elm_widget_data_get(obj);
159    if (!wd) return;
160    if (elm_widget_focus_get(obj))
161      {
162         edje_object_signal_emit(wd->spinner, "elm,action,focus", "elm");
163         evas_object_focus_set(wd->spinner, EINA_TRUE);
164      }
165    else
166      {
167         edje_object_signal_emit(wd->spinner, "elm,action,unfocus", "elm");
168         evas_object_focus_set(wd->spinner, EINA_FALSE);
169      }
170 }
171
172 static Eina_Bool
173 _delay_change(void *data)
174 {
175    Widget_Data *wd = elm_widget_data_get(data);
176    if (!wd) return ECORE_CALLBACK_CANCEL;
177    wd->delay = NULL;
178    evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, NULL);
179    return ECORE_CALLBACK_CANCEL;
180 }
181
182 static void
183 _entry_show(Widget_Data *wd)
184 {
185    char buf[32], fmt[32] = "%0.f";
186
187    /* try to construct just the format from given label
188     * completely ignoring pre/post words
189     */
190    if (wd->label)
191      {
192         const char *start = strchr(wd->label, '%');
193         while (start)
194           {
195              /* handle %% */
196              if (start[1] != '%')
197                break;
198              else
199                start = strchr(start + 2, '%');
200           }
201
202         if (start)
203           {
204              const char *itr, *end = NULL;
205              for (itr = start + 1; *itr != '\0'; itr++)
206                {
207                   /* allowing '%d' is quite dangerous, remove it? */
208                   if ((*itr == 'd') || (*itr == 'f'))
209                     {
210                        end = itr + 1;
211                        break;
212                     }
213                }
214
215              if ((end) && ((size_t)(end - start + 1) < sizeof(fmt)))
216                {
217                   memcpy(fmt, start, end - start);
218                   fmt[end - start] = '\0';
219                }
220           }
221      }
222    snprintf(buf, sizeof(buf), fmt, wd->val);
223    elm_entry_entry_set(wd->ent, buf);
224 }
225
226 static void
227 _write_label(Evas_Object *obj)
228 {
229    Eina_List *l;
230    Elm_Spinner_Special_Value *sv;
231    Widget_Data *wd = elm_widget_data_get(obj);
232    char buf[1024];
233    if (!wd) return;
234    EINA_LIST_FOREACH(wd->special_values, l, sv)
235      {
236         if (sv->value == wd->val)
237           {
238              snprintf(buf, sizeof(buf), "%s", sv->label);
239              goto apply;
240           }
241      }
242    if (wd->label)
243      snprintf(buf, sizeof(buf), wd->label, wd->val);
244    else
245      snprintf(buf, sizeof(buf), "%.0f", wd->val);
246
247 apply:
248    edje_object_part_text_set(wd->spinner, "elm.text", buf);
249    if (wd->entry_visible) _entry_show(wd);
250 }
251
252 static Eina_Bool
253 _value_set(Evas_Object *obj, double delta)
254 {
255    Widget_Data *wd = elm_widget_data_get(obj);
256    double new_val;
257    if (!wd) return EINA_FALSE;
258    new_val = wd->val + delta;
259    if (wd->wrap)
260      {
261         while (new_val < wd->val_min)
262           new_val = wd->val_max + new_val + 1 - wd->val_min;
263         while (new_val > wd->val_max)
264           new_val = wd->val_min + new_val - wd->val_max - 1;
265      }
266    else
267      {
268         if (new_val < wd->val_min)
269           new_val = wd->val_min;
270         else if (new_val > wd->val_max)
271           new_val = wd->val_max;
272      }
273
274    if (new_val == wd->val) return EINA_FALSE;
275    wd->val = new_val;
276
277    evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
278    if (wd->delay) ecore_timer_del(wd->delay);
279    wd->delay = ecore_timer_add(0.2, _delay_change, obj);
280
281    return EINA_TRUE;
282 }
283
284 static void
285 _sizing_eval(Evas_Object *obj)
286 {
287    Widget_Data *wd = elm_widget_data_get(obj);
288    Evas_Coord minw = -1, minh = -1;
289    if (!wd) return;
290    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
291    edje_object_size_min_restricted_calc(wd->spinner, &minw, &minh, minw, minh);
292    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
293    evas_object_size_hint_min_set(obj, minw, minh);
294    evas_object_size_hint_max_set(obj, -1, -1);
295 }
296
297 /*
298    static void
299    _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info)
300    {
301    _sizing_eval(data);
302    }
303  */
304
305 static void
306 _val_set(Evas_Object *obj)
307 {
308    Widget_Data *wd = elm_widget_data_get(obj);
309    double pos = 0.0;
310    if (!wd) return;
311    if (wd->val_max > wd->val_min)
312      pos = ((wd->val - wd->val_min) / (wd->val_max - wd->val_min));
313    if (pos < 0.0) pos = 0.0;
314    else if (pos > 1.0) pos = 1.0;
315    edje_object_part_drag_value_set(wd->spinner, "elm.dragable.slider",
316                                    pos, pos);
317 }
318
319 static void
320 _drag(void *data, Evas_Object *_obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
321 {
322    Evas_Object *obj = data;
323    Widget_Data *wd = elm_widget_data_get(obj);
324    double pos = 0.0, offset, delta;
325    if (!wd) return;
326    if (wd->entry_visible) return;
327    edje_object_part_drag_value_get(wd->spinner, "elm.dragable.slider",
328                                    &pos, NULL);
329    offset = wd->step;
330    delta = (pos - wd->drag_start_pos) * offset;
331    /* If we are on rtl mode, change the delta to be negative on such changes */
332    if (elm_widget_mirrored_get(obj))
333      delta *= -1;
334    if (_value_set(data, delta)) _write_label(data);
335    wd->drag_start_pos = pos;
336    wd->dragging = 1;
337 }
338
339 static void
340 _drag_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
341 {
342    Widget_Data *wd = elm_widget_data_get(data);
343    double pos;
344    if (!wd) return;
345    edje_object_part_drag_value_get(wd->spinner, "elm.dragable.slider",
346                                    &pos, NULL);
347    wd->drag_start_pos = pos;
348 }
349
350 static void
351 _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
352 {
353    Widget_Data *wd = elm_widget_data_get(data);
354    if (!wd) return;
355    wd->drag_start_pos = 0;
356    edje_object_part_drag_value_set(wd->spinner, "elm.dragable.slider", 0.0, 0.0);
357 }
358
359 static void
360 _hide_entry(Evas_Object *obj)
361 {
362    Widget_Data *wd = elm_widget_data_get(obj);
363    if (!wd) return;
364    edje_object_signal_emit(wd->spinner, "elm,state,inactive", "elm");
365    wd->entry_visible = 0;
366 }
367
368 static void
369 _reset_value(Evas_Object *obj)
370 {
371    Widget_Data *wd = elm_widget_data_get(obj);
372    if (!wd) return;
373    _hide_entry(obj);
374    elm_spinner_value_set(obj, wd->orig_val);
375 }
376
377 static void
378 _apply_entry_value(Evas_Object *obj)
379 {
380    Widget_Data *wd = elm_widget_data_get(obj);
381    const char *str;
382    char *end;
383    double val;
384
385    if (!wd) return;
386    _hide_entry(obj);
387    str = elm_entry_entry_get(wd->ent);
388    if (!str) return;
389    val = strtod(str, &end);
390    if ((*end != '\0') && (!isspace(*end))) return;
391    elm_spinner_value_set(obj, val);
392 }
393
394 static void
395 _toggle_entry(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
396 {
397    Widget_Data *wd = elm_widget_data_get(data);
398    if (!wd) return;
399    if (wd->dragging)
400      {
401         wd->dragging = 0;
402         return;
403      }
404    if (elm_widget_disabled_get(data)) return;
405    if (!wd->editable) return;
406    if (wd->entry_visible) _apply_entry_value(data);
407    else
408      {
409         wd->orig_val = wd->val;
410         edje_object_signal_emit(wd->spinner, "elm,state,active", "elm");
411         _entry_show(wd);
412         elm_entry_select_all(wd->ent);
413         elm_widget_focus_set(wd->ent, 1);
414         wd->entry_visible = 1;
415      }
416 }
417
418 static Eina_Bool
419 _spin_value(void *data)
420 {
421    Widget_Data *wd = elm_widget_data_get(data);
422    if (!wd) return ECORE_CALLBACK_CANCEL;
423    if (_value_set(data, wd->spin_speed)) _write_label(data);
424    wd->interval = wd->interval / 1.05;
425    ecore_timer_interval_set(wd->spin, wd->interval);
426    return ECORE_CALLBACK_RENEW;
427 }
428
429 static void
430 _val_inc_start(Evas_Object *obj)
431 {
432    Widget_Data *wd = elm_widget_data_get(obj);
433    if (!wd) return;
434    wd->interval = wd->first_interval;
435    wd->spin_speed = wd->step;
436    if (wd->spin) ecore_timer_del(wd->spin);
437    wd->spin = ecore_timer_add(wd->interval, _spin_value, obj);
438    _spin_value(obj);
439 }
440
441 static void
442 _val_inc_stop(Evas_Object *obj)
443 {
444    Widget_Data *wd = elm_widget_data_get(obj);
445    if (!wd) return;
446    wd->interval = wd->first_interval;
447    wd->spin_speed = 0;
448    if (wd->spin) ecore_timer_del(wd->spin);
449    wd->spin = NULL;
450 }
451
452 static void
453 _val_dec_start(Evas_Object *obj)
454 {
455    Widget_Data *wd = elm_widget_data_get(obj);
456    if (!wd) return;
457    wd->interval = wd->first_interval;
458    wd->spin_speed = -wd->step;
459    if (wd->spin) ecore_timer_del(wd->spin);
460    wd->spin = ecore_timer_add(wd->interval, _spin_value, obj);
461    _spin_value(obj);
462 }
463
464 static void
465 _val_dec_stop(Evas_Object *obj)
466 {
467    Widget_Data *wd = elm_widget_data_get(obj);
468    if (!wd) return;
469    wd->interval = wd->first_interval;
470    wd->spin_speed = 0;
471    if (wd->spin) ecore_timer_del(wd->spin);
472    wd->spin = NULL;
473 }
474
475 static void
476 _button_inc_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
477 {
478    Widget_Data *wd = elm_widget_data_get(data);
479    if (!wd) return;
480    if (wd->entry_visible)
481      {
482         _reset_value(data);
483         return;
484      }
485    _val_inc_start(data);
486 }
487
488 static void
489 _button_inc_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
490 {
491    Widget_Data *wd = elm_widget_data_get(data);
492    if (!wd) return;
493    _val_inc_stop(data);
494 }
495
496 static void
497 _button_dec_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
498 {
499    Widget_Data *wd = elm_widget_data_get(data);
500    if (!wd) return;
501    if (wd->entry_visible)
502      {
503         _reset_value(data);
504         return;
505      }
506    _val_dec_start(data);
507 }
508
509 static void
510 _button_dec_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
511 {
512    Widget_Data *wd = elm_widget_data_get(data);
513    if (!wd) return;
514    _val_dec_stop(data);
515 }
516
517 static void
518 _entry_activated(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
519 {
520    Widget_Data *wd = elm_widget_data_get(data);
521    if (!wd) return;
522    _apply_entry_value(data);
523    evas_object_smart_callback_call(data, SIG_CHANGED, NULL);
524    if (wd->delay) ecore_timer_del(wd->delay);
525    wd->delay = ecore_timer_add(0.2, _delay_change, data);
526 }
527
528 static Eina_Bool
529 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
530 {
531    Widget_Data *wd = elm_widget_data_get(obj);
532    if (!wd) return EINA_FALSE;
533    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
534    if (type == EVAS_CALLBACK_KEY_DOWN)
535      {
536         Evas_Event_Key_Down *ev = event_info;
537         if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
538         else if (!strcmp(ev->keyname, "Left") || !strcmp(ev->keyname, "KP_Left")
539                  || !strcmp(ev->keyname, "Down") || !strcmp(ev->keyname, "KP_Down"))
540           {
541              _val_dec_start(obj);
542              edje_object_signal_emit(wd->spinner, "elm,left,anim,activate", "elm");
543              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
544              return EINA_TRUE;
545           }
546         else if (!strcmp(ev->keyname, "Right") || !strcmp(ev->keyname, "KP_Right")
547                  || !strcmp(ev->keyname, "Up") || !strcmp(ev->keyname, "KP_Up"))
548           {
549              _val_inc_start(obj);
550              edje_object_signal_emit(wd->spinner, "elm,right,anim,activate", "elm");
551              ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
552              return EINA_TRUE;
553           }
554      }
555    else if (type == EVAS_CALLBACK_KEY_UP)
556      {
557         Evas_Event_Key_Down *ev = event_info;
558         if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
559         if (!strcmp(ev->keyname, "Right") || !strcmp(ev->keyname, "KP_Right")
560             || !strcmp(ev->keyname, "Up") || !strcmp(ev->keyname, "KP_Up"))
561           _val_inc_stop(obj);
562         else if (!strcmp(ev->keyname, "Left") || !strcmp(ev->keyname, "KP_Left")
563                  || !strcmp(ev->keyname, "Down") || !strcmp(ev->keyname, "KP_Down"))
564           _val_dec_stop(obj);
565         else  return EINA_FALSE;
566         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
567         return EINA_TRUE;
568      }
569    return EINA_FALSE;
570 }
571
572 /**
573  * Add a new spinner to the parent
574  *
575  * @param parent The parent object
576  * @return The new object or NULL if it cannot be created
577  *
578  * @ingroup Spinner
579  */
580 EAPI Evas_Object *
581 elm_spinner_add(Evas_Object *parent)
582 {
583    Evas_Object *obj;
584    Evas *e;
585    Widget_Data *wd;
586
587    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
588
589    ELM_SET_WIDTYPE(widtype, "spinner");
590    elm_widget_type_set(obj, "spinner");
591    elm_widget_sub_object_add(parent, obj);
592    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
593    elm_widget_data_set(obj, wd);
594    elm_widget_del_hook_set(obj, _del_hook);
595    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
596    elm_widget_theme_hook_set(obj, _theme_hook);
597    elm_widget_disable_hook_set(obj, _disable_hook);
598    elm_widget_signal_emit_hook_set(obj, _signal_emit_hook);
599    elm_widget_signal_callback_add_hook_set(obj, _signal_callback_add_hook);
600    elm_widget_signal_callback_del_hook_set(obj, _signal_callback_del_hook);
601    elm_widget_can_focus_set(obj, EINA_TRUE);
602    elm_widget_event_hook_set(obj, _event_hook);
603
604    wd->val = 0.0;
605    wd->val_min = 0.0;
606    wd->val_max = 100.0;
607    wd->wrap = 0;
608    wd->step = 1.0;
609    wd->first_interval = 0.85;
610    wd->entry_visible = 0;
611    wd->editable = EINA_TRUE;
612
613    wd->spinner = edje_object_add(e);
614    _elm_theme_object_set(obj, wd->spinner, "spinner", "base", "default");
615    elm_widget_resize_object_set(obj, wd->spinner);
616    edje_object_signal_callback_add(wd->spinner, "drag", "*", _drag, obj);
617    edje_object_signal_callback_add(wd->spinner, "drag,start", "*",
618                                    _drag_start, obj);
619    edje_object_signal_callback_add(wd->spinner, "drag,stop", "*",
620                                    _drag_stop, obj);
621    edje_object_signal_callback_add(wd->spinner, "drag,step", "*",
622                                    _drag_stop, obj);
623    edje_object_signal_callback_add(wd->spinner, "drag,page", "*",
624                                    _drag_stop, obj);
625
626    edje_object_signal_callback_add(wd->spinner, "elm,action,increment,start",
627                                    "*", _button_inc_start, obj);
628    edje_object_signal_callback_add(wd->spinner, "elm,action,increment,stop",
629                                    "*", _button_inc_stop, obj);
630    edje_object_signal_callback_add(wd->spinner, "elm,action,decrement,start",
631                                    "*", _button_dec_start, obj);
632    edje_object_signal_callback_add(wd->spinner, "elm,action,decrement,stop",
633                                    "*", _button_dec_stop, obj);
634    edje_object_part_drag_value_set(wd->spinner, "elm.dragable.slider",
635                                    0.0, 0.0);
636
637    wd->ent = elm_entry_add(obj);
638    elm_entry_single_line_set(wd->ent, 1);
639    evas_object_smart_callback_add(wd->ent, "activated", _entry_activated, obj);
640    edje_object_part_swallow(wd->spinner, "elm.swallow.entry", wd->ent);
641    edje_object_signal_callback_add(wd->spinner, "elm,action,entry,toggle",
642                                    "*", _toggle_entry, obj);
643
644    evas_object_smart_callbacks_descriptions_set(obj, _signals);
645
646    _mirrored_set(obj, elm_widget_mirrored_get(obj));
647    _write_label(obj);
648    _sizing_eval(obj);
649    return obj;
650 }
651
652 /**
653  * Set the format string of the label area
654  *
655  * If NULL, this sets the format to "%.0f". If not it sets the format
656  * string for the label text. The label text is provided a floating point
657  * value, so the label text can display up to 1 floating point value. Note that
658  * this is optional. Use a format string such as "%1.2f meters" for example.
659  *
660  * @param obj The spinner object
661  * @param fmt The format string for the label display
662  *
663  * @ingroup Spinner
664  */
665 EAPI void
666 elm_spinner_label_format_set(Evas_Object *obj, const char *fmt)
667 {
668    ELM_CHECK_WIDTYPE(obj, widtype);
669    Widget_Data *wd = elm_widget_data_get(obj);
670    if (!wd) return;
671    eina_stringshare_replace(&wd->label, fmt);
672    _write_label(obj);
673    _sizing_eval(obj);
674 }
675
676 /**
677  * Get the label format of the spinner
678  *
679  * @param obj The spinner object
680  * @return The text label format string in UTF-8
681  *
682  * @ingroup Spinner
683  */
684 EAPI const char *
685 elm_spinner_label_format_get(const Evas_Object *obj)
686 {
687    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
688    Widget_Data *wd = elm_widget_data_get(obj);
689    if (!wd) return NULL;
690    return wd->label;
691 }
692
693 /**
694  * Set the minimum and maximum values for the spinner
695  *
696  * Maximum must be greater than minimum.
697  *
698  * @param obj The spinner object
699  * @param min The minimum value
700  * @param max The maximum value
701  *
702  * @ingroup Spinner
703  */
704 EAPI void
705 elm_spinner_min_max_set(Evas_Object *obj, double min, double max)
706 {
707    ELM_CHECK_WIDTYPE(obj, widtype);
708    Widget_Data *wd = elm_widget_data_get(obj);
709    if (!wd) return;
710    if ((wd->val_min == min) && (wd->val_max == max)) return;
711    wd->val_min = min;
712    wd->val_max = max;
713    if (wd->val < wd->val_min) wd->val = wd->val_min;
714    if (wd->val > wd->val_max) wd->val = wd->val_max;
715    _val_set(obj);
716    _write_label(obj);
717 }
718
719 /**
720  * Get the minimum and maximum values of the spinner
721  *
722  * @param obj The spinner object
723  * @param min The minimum value
724  * @param max The maximum value
725  *
726  * @ingroup Spinner
727  */
728 EAPI void
729 elm_spinner_min_max_get(const Evas_Object *obj, double *min, double *max)
730 {
731    if (min) *min = 0.0;
732    if (max) *max = 0.0;
733    ELM_CHECK_WIDTYPE(obj, widtype);
734    Widget_Data *wd = elm_widget_data_get(obj);
735    if (!wd) return;
736    if (min) *min = wd->val_min;
737    if (max) *max = wd->val_max;
738 }
739
740 /**
741  * Set the step for the spinner
742  *
743  * @param obj The spinner object
744  * @param step The step value
745  *
746  * @ingroup Spinner
747  */
748 EAPI void
749 elm_spinner_step_set(Evas_Object *obj, double step)
750 {
751    ELM_CHECK_WIDTYPE(obj, widtype);
752    Widget_Data *wd = elm_widget_data_get(obj);
753    if (!wd) return;
754    wd->step = step;
755 }
756
757 /**
758  * Get the step of the spinner
759  *
760  * @param obj The spinner object
761  * @return The step value
762  *
763  * @ingroup Spinner
764  */
765 EAPI double
766 elm_spinner_step_get(const Evas_Object *obj)
767 {
768    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
769    Widget_Data *wd = elm_widget_data_get(obj);
770    if (!wd) return 0.0;
771    return wd->step;
772 }
773 /**
774  * Set the value the spinner indicates
775  *
776  * @param obj The spinner object
777  * @param val The value (must be between min and max for the spinner)
778  *
779  * @ingroup Spinner
780  */
781 EAPI void
782 elm_spinner_value_set(Evas_Object *obj, double val)
783 {
784    ELM_CHECK_WIDTYPE(obj, widtype);
785    Widget_Data *wd = elm_widget_data_get(obj);
786    if (!wd) return;
787    if (wd->val == val) return;
788    wd->val = val;
789    if (wd->val < wd->val_min) wd->val = wd->val_min;
790    if (wd->val > wd->val_max) wd->val = wd->val_max;
791    _val_set(obj);
792    _write_label(obj);
793 }
794
795 /**
796  * Get the value the spinner has
797  *
798  * @param obj The spinner object
799  * @return The value of the spinner
800  *
801  * @ingroup Spinner
802  */
803 EAPI double
804 elm_spinner_value_get(const Evas_Object *obj)
805 {
806    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
807    Widget_Data *wd = elm_widget_data_get(obj);
808    if (!wd) return 0.0;
809    return wd->val;
810 }
811
812 /**
813  * Sets whether the spinner should wrap when it reaches its
814  * minimum/maximum value
815  *
816  * @param obj The spinner object
817  * @param wrap True if it should wrap, false otherwise
818  *
819  * @ingroup Spinner
820  */
821 EAPI void
822 elm_spinner_wrap_set(Evas_Object *obj, Eina_Bool wrap)
823 {
824    ELM_CHECK_WIDTYPE(obj, widtype);
825    Widget_Data *wd = elm_widget_data_get(obj);
826    if (!wd) return;
827    wd->wrap = wrap;
828 }
829
830 /**
831  * Gets whether the spinner should wrap when it reaches its
832  * minimum/maximum value
833  *
834  * @param obj The spinner object
835  * @return Bool value of wrap option
836  * (0 = disabled, 1 = enabled)
837  *
838  * @ingroup Spinner
839  */
840 EAPI Eina_Bool
841 elm_spinner_wrap_get(const Evas_Object *obj)
842 {
843    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
844    Widget_Data *wd = elm_widget_data_get(obj);
845    if (!wd) return EINA_FALSE;
846    return wd->wrap;
847 }
848
849 /**
850  * Set a special value to display in the place of the numerical one.
851  *
852  * @param obj The spinner object
853  * @param value The value to be replaced
854  * @param label The label to be used
855  *
856  * @ingroup Spinner
857  */
858 EAPI void
859 elm_spinner_special_value_add(Evas_Object *obj, double value, const char *label)
860 {
861    Elm_Spinner_Special_Value *sv;
862    ELM_CHECK_WIDTYPE(obj, widtype);
863    Widget_Data *wd = elm_widget_data_get(obj);
864    if (!wd) return;
865
866    sv = calloc(1, sizeof(*sv));
867    if (!sv) return;
868    sv->value = value;
869    sv->label = eina_stringshare_add(label);
870
871    wd->special_values = eina_list_append(wd->special_values, sv);
872    _write_label(obj);
873 }
874
875 /**
876  * Set whether the spinner can be directly edited by the user or not.
877  * Default is editable.
878  *
879  * @param obj The spinner object
880  * @param editable Bool value of the edit option
881  * (EINA_FALSE = not editable, EINA_TRUE = editable)
882  */
883 EAPI void
884 elm_spinner_editable_set(Evas_Object *obj, Eina_Bool editable)
885 {
886    ELM_CHECK_WIDTYPE(obj, widtype);
887    Widget_Data *wd = elm_widget_data_get(obj);
888    if (!wd) return;
889    wd->editable = editable;
890 }
891
892 /**
893  * Gets whether the spinner is editable.
894  *
895  * @param obj The spinner object
896  * @return Bool value of edit option
897  * (EINA_FALSE = not editable, EINA_TRUE = editable)
898  */
899 EAPI Eina_Bool
900 elm_spinner_editable_get(const Evas_Object *obj)
901 {
902    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
903    Widget_Data *wd = elm_widget_data_get(obj);
904    if (!wd) return EINA_FALSE;
905    return wd->editable;
906 }
907
908 /**
909  * Set the interval for the spinner
910  *
911  * @param obj The spinner object
912  * @param interval The interval value in seconds
913  *
914  * The interval value is decreased while the user increments or decrements
915  * the spinner value. The next interval value is the previous interval / 1.05,
916  * so it speed up a bit. Default value is 0.85 seconds.
917  *
918  * @ingroup Spinner
919  */
920 EAPI void
921 elm_spinner_interval_set(Evas_Object *obj, double interval)
922 {
923    ELM_CHECK_WIDTYPE(obj, widtype);
924    Widget_Data *wd = elm_widget_data_get(obj);
925    if (!wd) return;
926    wd->first_interval = interval;
927 }
928
929 /**
930  * Get the interval of the spinner
931  *
932  * @param obj The spinner object
933  * @return The value of the first interval in seconds
934  *
935  * The interval value is decreased while the user increments or decrements
936  * the spinner value. The next interval value is the previous interval / 1.05,
937  * so it speed up a bit. Default value is 0.85 seconds.
938  *
939  * @ingroup Spinner
940  */
941 EAPI double
942 elm_spinner_interval_get(const Evas_Object *obj)
943 {
944    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
945    Widget_Data *wd = elm_widget_data_get(obj);
946    if (!wd) return 0.0;
947    return wd->first_interval;
948 }