0258746e124a48ab3419e1acf5c864e4d67dba38
[framework/uifw/elementary.git] / src / lib / elm_slider.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 /**
5  * @defgroup Slider Slider
6  *
7  * The slider adds a dragable “slider” widget for selecting the value of
8  * something within a range.
9  *
10  * Signals that you can add callbacks for are:
11  *
12  * changed - Whenever the slider value is changed by the user.
13  *
14  * delay,changed - A short time after the value is changed by the user.
15  * This will be called only when the user stops dragging for a very short
16  * period or when they release their finger/mouse, so it avoids possibly
17  * expensive reactions to the value change.
18  *
19  * slider,drag,start - dragging the slider indicator around has started
20  *
21  * slider,drag,stop - dragging the slider indicator around has stopped
22  *
23  * A slider can be horizontal or vertical. It can contain an Icon and has a
24  * primary label as well as a units label (that is formatted with floating
25  * point values and thus accepts a printf-style format string, like
26  * “%1.2f units”. There is also an indicator string that may be somewhere
27  * else (like on the slider itself) that also accepts a format string like
28  * units. Label, Icon Unit and Indicator strings/objects are optional.
29  *
30  * A slider may be inverted which means values invert, with high vales being
31  * on the left or top and low values on the right or bottom (as opposed to
32  * normally being low on the left or top and high on the bottom and right).
33  *
34  * The slider should have its minimum and maximum values set by the
35  * application with  elm_slider_min_max_set() and value should also be set by
36  * the application before use with  elm_slider_value_set(). The span of the
37  * slider is its length (horizontally or vertically). This will be scaled by
38  * the object or applications scaling factor. At any point code can query the
39  * slider for its value with elm_slider_value_get().
40  */
41
42 typedef struct _Widget_Data Widget_Data;
43
44 struct _Widget_Data
45 {
46    Evas_Object *slider;
47    Evas_Object *icon;
48    Evas_Object *end;
49    Evas_Object *spacer;
50    const char *label;
51    const char *units;
52    const char *indicator;
53    const char *(*indicator_format_func)(double val);
54    Eina_Bool horizontal : 1;
55    Eina_Bool inverted : 1;
56    Eina_Bool indicator_show : 1;
57    double val, val_min, val_max;
58    Ecore_Timer *delay;
59    Evas_Coord size;
60 };
61
62 #define ELM_SLIDER_INVERTED_FACTOR (-1.0)
63
64 static const char *widtype = NULL;
65 static void _del_hook(Evas_Object *obj);
66 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
67 static void _theme_hook(Evas_Object *obj);
68 static void _disable_hook(Evas_Object *obj);
69 static void _sizing_eval(Evas_Object *obj);
70 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
71 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
72 static void _units_set(Evas_Object *obj);
73 static void _val_set(Evas_Object *obj);
74 static void _indicator_set(Evas_Object *obj);
75 static void _on_focus_hook(void *data, Evas_Object *obj);
76 static void _drag_up(void *data, Evas_Object *obj,
77                     const char *emission, const char *source);
78 static void _drag_down(void *data, Evas_Object *obj,
79                     const char *emission, const char *source);
80 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
81                              Evas_Callback_Type type, void *event_info);
82 static void _spacer_cb(void *data, Evas * e, Evas_Object * obj, void *event_info);
83
84 static const char SIG_CHANGED[] = "changed";
85 static const char SIG_DELAY_CHANGED[] = "delay,changed";
86 static const char SIG_DRAG_START[] = "slider,drag,start";
87 static const char SIG_DRAG_STOP[] = "slider,drag,stop";
88 static const Evas_Smart_Cb_Description _signals[] = {
89   {SIG_CHANGED, ""},
90   {SIG_DELAY_CHANGED, ""},
91   {SIG_DRAG_START, ""},
92   {SIG_DRAG_STOP, ""},
93   {NULL, NULL}
94 };
95
96 static Eina_Bool
97 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
98 {
99    Evas_Event_Mouse_Wheel *mev;
100    Evas_Event_Key_Down *ev;
101    Widget_Data *wd;
102
103    wd = elm_widget_data_get(obj);
104    if (!wd) return EINA_FALSE;
105
106    if (type == EVAS_CALLBACK_KEY_DOWN) goto key_down;
107    else if (type != EVAS_CALLBACK_MOUSE_WHEEL) return EINA_FALSE;
108
109    mev = event_info;
110    if (mev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
111    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
112
113    if (mev->z < 0) _drag_up(obj, NULL, NULL, NULL);
114    else _drag_down(obj, NULL, NULL, NULL);
115    mev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
116    return EINA_TRUE;
117
118   key_down:
119    ev = event_info;
120    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
121    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
122    if ((!strcmp(ev->keyname, "Left"))
123        || (!strcmp(ev->keyname, "KP_Left")))
124      {
125         if (!wd->horizontal) return EINA_FALSE;
126         if (!wd->inverted) _drag_down(obj, NULL, NULL, NULL);
127         else _drag_up(obj, NULL, NULL, NULL);
128         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
129         return EINA_TRUE;
130      }
131    else if ((!strcmp(ev->keyname, "Right"))
132             || (!strcmp(ev->keyname, "KP_Right")))
133      {
134         if (!wd->horizontal) return EINA_FALSE;
135         if (!wd->inverted) _drag_up(obj, NULL, NULL, NULL);
136         else _drag_down(obj, NULL, NULL, NULL);
137         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
138         return EINA_TRUE;
139      }
140    else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
141      {
142         if (wd->horizontal) return EINA_FALSE;
143         if (wd->inverted) _drag_up(obj, NULL, NULL, NULL);
144         else _drag_down(obj, NULL, NULL, NULL);
145         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
146         return EINA_TRUE;
147      }
148    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
149      {
150         if (wd->horizontal) return EINA_FALSE;
151         if (wd->inverted) _drag_down(obj, NULL, NULL, NULL);
152         else _drag_up(obj, NULL, NULL, NULL);
153         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
154         return EINA_TRUE;
155      }
156    else return EINA_FALSE;
157 }
158
159 static void
160 _del_hook(Evas_Object *obj)
161 {
162    Widget_Data *wd = elm_widget_data_get(obj);
163    if (!wd) return;
164    if (wd->label) eina_stringshare_del(wd->label);
165    if (wd->indicator) eina_stringshare_del(wd->units);
166    if (wd->delay) ecore_timer_del(wd->delay);
167    free(wd);
168 }
169
170 static void
171 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
172 {
173    Widget_Data *wd = elm_widget_data_get(obj);
174    if (!wd) return;
175    if (elm_widget_focus_get(obj))
176      {
177         edje_object_signal_emit(wd->slider, "elm,action,focus", "elm");
178         evas_object_focus_set(wd->slider, EINA_TRUE);
179      }
180    else
181      {
182         edje_object_signal_emit(wd->slider, "elm,action,unfocus", "elm");
183         evas_object_focus_set(wd->slider, EINA_FALSE);
184      }
185 }
186
187 static void
188 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
189 {
190    Widget_Data *wd = elm_widget_data_get(obj);
191    if (!wd) return;
192    edje_object_mirrored_set(wd->slider, rtl);
193 }
194
195 static void
196 _theme_hook(Evas_Object *obj)
197 {
198    Widget_Data *wd = elm_widget_data_get(obj);
199    if (!wd) return;
200    _elm_widget_mirrored_reload(obj);
201    _mirrored_set(obj, elm_widget_mirrored_get(obj));
202    if (wd->horizontal)
203      _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", elm_widget_style_get(obj));
204    else
205      _elm_theme_object_set(obj, wd->slider, "slider", "vertical", elm_widget_style_get(obj));
206    if (wd->icon)
207      {
208         edje_object_part_swallow(wd->slider, "elm.swallow.content", wd->icon);
209         edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
210      }
211    if (wd->end)
212      edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
213    else
214      edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
215    if (wd->label)
216      {
217         edje_object_part_text_set(wd->slider, "elm.text", wd->label);
218         edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
219      }
220
221    if (wd->units)
222      edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
223
224    if (wd->horizontal)
225      evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
226    else
227      evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
228
229    if (wd->inverted)
230      edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
231
232    edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
233    _units_set(obj);
234    _indicator_set(obj);
235    edje_object_message_signal_process(wd->slider);
236    edje_object_scale_set(wd->slider, elm_widget_scale_get(obj) * _elm_config->scale);
237    _val_set(obj);
238    _sizing_eval(obj);
239 }
240
241 static void
242 _disable_hook(Evas_Object *obj)
243 {
244    Widget_Data *wd = elm_widget_data_get(obj);
245    if (!wd) return;
246    if (elm_widget_disabled_get(obj))
247      edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
248    else
249      edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
250 }
251
252 static void
253 _sizing_eval(Evas_Object *obj)
254 {
255    Widget_Data *wd = elm_widget_data_get(obj);
256    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
257    if (!wd) return;
258    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
259    edje_object_size_min_restricted_calc(wd->slider, &minw, &minh, minw, minh);
260    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
261    evas_object_size_hint_min_set(obj, minw, minh);
262    evas_object_size_hint_max_set(obj, maxw, maxh);
263 }
264
265 static void
266 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
267 {
268    Widget_Data *wd = elm_widget_data_get(data);
269    if (!wd) return;
270    if ((obj != wd->icon) && (obj != wd->end)) return;
271    _sizing_eval(data);
272 }
273
274 static void
275 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
276 {
277    Widget_Data *wd = elm_widget_data_get(obj);
278    Evas_Object *sub = event_info;
279    if (!wd) return;
280    if (sub == wd->icon)
281      {
282         edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
283         evas_object_event_callback_del_full
284            (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
285         wd->icon = NULL;
286         edje_object_message_signal_process(wd->slider);
287         _sizing_eval(obj);
288      }
289    if (sub == wd->end)
290      {
291         edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
292         evas_object_event_callback_del_full(sub,
293                                             EVAS_CALLBACK_CHANGED_SIZE_HINTS,
294                                             _changed_size_hints, obj);
295         wd->end = NULL;
296         edje_object_message_signal_process(wd->slider);
297         _sizing_eval(obj);
298      }
299 }
300
301 static Eina_Bool
302 _delay_change(void *data)
303 {
304    Widget_Data *wd = elm_widget_data_get(data);
305    if (!wd) return ECORE_CALLBACK_CANCEL;
306    wd->delay = NULL;
307    evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, NULL);
308    return ECORE_CALLBACK_CANCEL;
309 }
310
311 static void
312 _val_fetch(Evas_Object *obj)
313 {
314    Eina_Bool rtl;
315    Widget_Data *wd = elm_widget_data_get(obj);
316    double posx = 0.0, posy = 0.0, pos = 0.0, val;
317    if (!wd) return;
318    edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider",
319                                    &posx, &posy);
320    if (wd->horizontal) pos = posx;
321    else pos = posy;
322
323    rtl = elm_widget_mirrored_get(obj);
324    if ((!rtl && wd->inverted) || (rtl &&
325                                   ((!wd->horizontal && wd->inverted) ||
326                                    (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
327    val = (pos * (wd->val_max - wd->val_min)) + wd->val_min;
328    if (val != wd->val)
329      {
330         wd->val = val;
331         evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
332         if (wd->delay) ecore_timer_del(wd->delay);
333         wd->delay = ecore_timer_add(0.2, _delay_change, obj);
334      }
335 }
336
337 static void
338 _val_set(Evas_Object *obj)
339 {
340    Eina_Bool rtl;
341    Widget_Data *wd = elm_widget_data_get(obj);
342    double pos;
343    if (!wd) return;
344    if (wd->val_max > wd->val_min)
345      pos = (wd->val - wd->val_min) / (wd->val_max - wd->val_min);
346    else
347      pos = 0.0;
348    if (pos < 0.0) pos = 0.0;
349    else if (pos > 1.0) pos = 1.0;
350
351    rtl = elm_widget_mirrored_get(obj);
352    if ((!rtl && wd->inverted) || (rtl &&
353                                   ((!wd->horizontal && wd->inverted) ||
354                                    (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
355    edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", pos, pos);
356 }
357
358 static void
359 _units_set(Evas_Object *obj)
360 {
361    Widget_Data *wd = elm_widget_data_get(obj);
362    if (!wd) return;
363    if (wd->units)
364      {
365         char buf[1024];
366
367         snprintf(buf, sizeof(buf), wd->units, wd->val);
368         edje_object_part_text_set(wd->slider, "elm.units", buf);
369      }
370    else
371      edje_object_part_text_set(wd->slider, "elm.units", NULL);
372 }
373
374 static void
375 _indicator_set(Evas_Object *obj)
376 {
377    Widget_Data *wd = elm_widget_data_get(obj);
378    if (!wd) return;
379    if (wd->indicator_format_func)
380      {
381         const char *buf;
382         buf = wd->indicator_format_func(wd->val);
383         edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
384      }
385    else if (wd->indicator)
386      {
387         char buf[1024];
388         snprintf(buf, sizeof(buf), wd->indicator, wd->val);
389         edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
390      }
391    else
392      edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", NULL);
393 }
394
395 static void
396 _drag(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
397 {
398    _val_fetch(data);
399    _units_set(data);
400    _indicator_set(data);
401 }
402
403 static void
404 _drag_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
405 {
406    _val_fetch(data);
407    evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
408    _units_set(data);
409    _indicator_set(data);
410    elm_widget_scroll_freeze_push(data);
411 }
412
413 static void
414 _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
415 {
416    _val_fetch(data);
417    evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
418    _units_set(data);
419    _indicator_set(data);
420    elm_widget_scroll_freeze_pop(data);
421 }
422
423 static void
424 _drag_step(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
425 {
426    _val_fetch(data);
427    _units_set(data);
428    _indicator_set(data);
429 }
430
431 static void
432 _drag_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
433 {
434    double step;
435    Widget_Data *wd;
436
437    wd = elm_widget_data_get(data);
438    step = 0.05;
439
440    if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
441
442    edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
443 }
444
445 static void
446 _drag_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
447 {
448    double step;
449    Widget_Data *wd;
450
451    wd = elm_widget_data_get(data);
452    step = -0.05;
453
454    if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
455
456    edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
457 }
458
459 static void
460 _spacer_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
461 {
462    Widget_Data *wd = elm_widget_data_get(data);
463    Evas_Event_Mouse_Down *ev = event_info;
464    Evas_Coord x, y, w, h;
465    double button_x, button_y;
466
467    evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
468    edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider", &button_x, &button_y);
469    if (wd->horizontal)
470      {
471         button_x = ((double)ev->output.x - (double)x) / (double)w;
472         if (button_x > 1) button_x = 1;
473         if (button_x < 0) button_x = 0;
474      }
475    else
476      {
477         button_y = ((double)ev->output.y - (double)y) / (double)h;
478         if (button_y > 1) button_y = 1;
479         if (button_y < 0) button_y = 0;
480      }
481    edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
482    evas_event_feed_mouse_cancel(e, 0, NULL);
483    evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
484 }
485
486 /**
487  * Add a new slider to the parent
488  *
489  * @param parent The parent object
490  * @return The new object or NULL if it cannot be created
491  *
492  * @ingroup Slider
493  */
494 EAPI Evas_Object *
495 elm_slider_add(Evas_Object *parent)
496 {
497    Evas_Object *obj;
498    Evas *e;
499    Widget_Data *wd;
500
501    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
502
503    ELM_SET_WIDTYPE(widtype, "slider");
504    elm_widget_type_set(obj, "slider");
505    elm_widget_sub_object_add(parent, obj);
506    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
507    elm_widget_data_set(obj, wd);
508    elm_widget_del_hook_set(obj, _del_hook);
509    elm_widget_theme_hook_set(obj, _theme_hook);
510    elm_widget_disable_hook_set(obj, _disable_hook);
511    elm_widget_can_focus_set(obj, EINA_TRUE);
512    elm_widget_event_hook_set(obj, _event_hook);
513
514    wd->horizontal = EINA_TRUE;
515    wd->indicator_show = EINA_TRUE;
516    wd->val = 0.0;
517    wd->val_min = 0.0;
518    wd->val_max = 1.0;
519
520    wd->slider = edje_object_add(e);
521    _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
522    elm_widget_resize_object_set(obj, wd->slider);
523    edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
524    edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
525    edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
526    edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_step, obj);
527    edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
528    //   edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
529    edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
530
531    wd->spacer = evas_object_rectangle_add(e);
532    evas_object_color_set(wd->spacer, 0, 0, 0, 0);
533    evas_object_pass_events_set(wd->spacer, EINA_TRUE);
534    elm_widget_sub_object_add(obj, wd->spacer);
535    edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
536    evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_DOWN, _spacer_cb, obj);
537    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
538
539    _mirrored_set(obj, elm_widget_mirrored_get(obj));
540    _sizing_eval(obj);
541
542    // TODO: convert Elementary to subclassing of Evas_Smart_Class
543    // TODO: and save some bytes, making descriptions per-class and not instance!
544    evas_object_smart_callbacks_descriptions_set(obj, _signals);
545    return obj;
546 }
547
548 /**
549  * Set the label of the slider
550  *
551  * @param obj The slider object
552  * @param label The text label string in UTF-8
553  *
554  * @ingroup Slider
555  */
556 EAPI void
557 elm_slider_label_set(Evas_Object *obj, const char *label)
558 {
559    ELM_CHECK_WIDTYPE(obj, widtype);
560    Widget_Data *wd = elm_widget_data_get(obj);
561    if (!wd) return;
562    eina_stringshare_replace(&wd->label, label);
563    if (label)
564      {
565         edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
566         edje_object_message_signal_process(wd->slider);
567      }
568    else
569      {
570         edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
571         edje_object_message_signal_process(wd->slider);
572      }
573    edje_object_part_text_set(wd->slider, "elm.text", label);
574    _sizing_eval(obj);
575 }
576
577 /**
578  * Get the label of the slider
579  *
580  * @param obj The slider object
581  * @return The text label string in UTF-8
582  *
583  * @ingroup Slider
584  */
585 EAPI const char *
586 elm_slider_label_get(const Evas_Object *obj)
587 {
588    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
589    Widget_Data *wd = elm_widget_data_get(obj);
590    if (!wd) return NULL;
591    return wd->label;
592 }
593
594 /**
595  * Set the icon object (leftmost widget) of the slider object.
596  *
597  * Once the icon object is set, a previously set one will be deleted.
598  * If you want to keep that old content object, use the
599  * elm_slider_icon_unset() function.
600  *
601  * @param obj The slider object
602  * @param icon The icon object
603  *
604  * @note If the object being set does not have minimum size hints set,
605  * it won't get properly displayed.
606  *
607  * @ingroup Slider
608  */
609 EAPI void
610 elm_slider_icon_set(Evas_Object *obj, Evas_Object *icon)
611 {
612    ELM_CHECK_WIDTYPE(obj, widtype);
613    Widget_Data *wd = elm_widget_data_get(obj);
614    if (!wd) return;
615    if (wd->icon == icon) return;
616    if (wd->icon) evas_object_del(wd->icon);
617    wd->icon = icon;
618    if (icon)
619      {
620         elm_widget_sub_object_add(obj, icon);
621         evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
622                                        _changed_size_hints, obj);
623         edje_object_part_swallow(wd->slider, "elm.swallow.icon", icon);
624         edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
625         edje_object_message_signal_process(wd->slider);
626      }
627    _sizing_eval(obj);
628 }
629
630 /**
631  * Unset the leftmost widget of the slider, unparenting and
632  * returning it.
633  *
634  * @param obj The slider object
635  * @return the previously set icon sub-object of this slider, on
636  * success.
637  *
638  * @see elm_slider_icon_set()
639  *
640  * @ingroup Slider
641  */
642 EAPI Evas_Object *
643 elm_slider_icon_unset(Evas_Object *obj)
644 {
645    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
646    Widget_Data *wd = elm_widget_data_get(obj);
647    Evas_Object *ret = NULL;
648    if (!wd) return NULL;
649    if (wd->icon)
650      {
651         elm_widget_sub_object_del(obj, wd->icon);
652         ret = wd->icon;
653         edje_object_part_unswallow(wd->slider, wd->icon);
654         edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
655         wd->icon = NULL;
656         _sizing_eval(obj);
657      }
658    return ret;
659 }
660
661 /**
662  * Get the icon object of the slider object. This object is owned by
663  * the scrolled entry and should not be modified.
664  *
665  * @param obj The slider object
666  * @return The icon object
667  *
668  * @ingroup Slider
669  */
670 EAPI Evas_Object *
671 elm_slider_icon_get(const Evas_Object *obj)
672 {
673    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
674    Widget_Data *wd = elm_widget_data_get(obj);
675    if (!wd) return NULL;
676    return wd->icon;
677 }
678
679 /**
680  * Set the length of the dragable region of the slider
681  *
682  * This sets the minimum width or height (depending on orientation) of the
683  * area of the slider that allows the slider to be dragged around. This in
684  * turn affects the objects minimum size (along with icon label and unit
685  * text). Note that this will also get multiplied by the scale factor.
686  *
687  * @param obj The slider object
688  * @param size The length of the slider area
689  *
690  * @ingroup Slider
691  */
692 EAPI void
693 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
694 {
695    ELM_CHECK_WIDTYPE(obj, widtype);
696    Widget_Data *wd = elm_widget_data_get(obj);
697    if (!wd) return;
698    if (wd->size == size) return;
699    wd->size = size;
700    if (wd->horizontal)
701      evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
702    else
703      evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
704    if (wd->indicator_show)
705      edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
706    else
707      edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
708    edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
709    _sizing_eval(obj);
710 }
711
712 /**
713  * Get the length of the dragable region of the slider
714  *
715  * This gets the minimum width or height (depending on orientation) of
716  * the area of the slider that allows the slider to be dragged
717  * around. Note that this will also get multiplied by the scale
718  * factor.
719  *
720  * @param obj The slider object
721  * @return The length of the slider area
722  *
723  * @ingroup Slider
724  */
725 EAPI Evas_Coord
726 elm_slider_span_size_get(const Evas_Object *obj)
727 {
728    ELM_CHECK_WIDTYPE(obj, widtype) 0;
729    Widget_Data *wd = elm_widget_data_get(obj);
730    if (!wd) return 0;
731    return wd->size;
732 }
733
734 /**
735  * Set the format string of the unit area
736  *
737  * If NULL, this disabls the unit area display. If not it sets the format
738  * string for the unit text. The unit text is provided a floating point
739  * value, so the unit text can display up to 1 floating point value. Note that
740  * this is optional. Use a format string such as "%1.2f meters" for example.
741  *
742  * @param obj The slider object
743  * @param units The format string for the units display
744  *
745  * @ingroup Slider
746  */
747 EAPI void
748 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
749 {
750    ELM_CHECK_WIDTYPE(obj, widtype);
751    Widget_Data *wd = elm_widget_data_get(obj);
752    if (!wd) return;
753    eina_stringshare_replace(&wd->units, units);
754    if (units)
755      {
756         edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
757         edje_object_message_signal_process(wd->slider);
758      }
759    else
760      {
761         edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
762         edje_object_message_signal_process(wd->slider);
763      }
764    _units_set(obj);
765    _sizing_eval(obj);
766 }
767
768 /**
769  * Get the format string for the unit area
770  *
771  * The slider may also display a value (the value of the slider) somewhere
772  * (for example above the slider knob that is dragged around). This sets the
773  * format string for this. See elm_slider_unit_format_set() for more
774  * information on how this works.
775  *
776  * @param obj The slider object
777  * @return The format string for the unit display.
778  *
779  * @ingroup Slider
780  */
781 EAPI const char *
782 elm_slider_unit_format_get(const Evas_Object *obj)
783 {
784    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
785    Widget_Data *wd = elm_widget_data_get(obj);
786    if (!wd) return NULL;
787    return wd->units;
788 }
789
790 /**
791  * Set the format string for the indicator area
792  *
793  * The slider may also display a value (the value of the slider) somewhere
794  * (for example above the slider knob that is dragged around). This sets the
795  * format string for this. See elm_slider_unit_format_set() for more
796  * information on how this works.
797  *
798  * @param obj The slider object
799  * @param indicator The format string for the indicator display
800  *
801  * @ingroup Slider
802  */
803 EAPI void
804 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
805 {
806    ELM_CHECK_WIDTYPE(obj, widtype);
807    Widget_Data *wd = elm_widget_data_get(obj);
808    if (!wd) return;
809    eina_stringshare_replace(&wd->indicator, indicator);
810    _indicator_set(obj);
811 }
812
813 /**
814  * Get the format string for the indicator area
815  *
816  * The slider may also display a value (the value of the slider) somewhere
817  * (for example above the slider knob that is dragged around). This sets the
818  * format string for this. See elm_slider_indicator_format_set() for more
819  * information on how this works.
820  *
821  * @param obj The slider object
822  * @return The format string for the indicator display.
823  *
824  * @ingroup Slider
825  */
826 EAPI const char *
827 elm_slider_indicator_format_get(const Evas_Object *obj)
828 {
829    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
830    Widget_Data *wd = elm_widget_data_get(obj);
831    if (!wd) return NULL;
832    return wd->indicator;
833 }
834
835 /**
836  * Set orientation of the slider
837  *
838  * @param obj The slider object
839  * @param horizontal If set, the slider will be horizontal
840  *
841  * @ingroup Slider
842  */
843 EAPI void
844 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
845 {
846    ELM_CHECK_WIDTYPE(obj, widtype);
847    Widget_Data *wd = elm_widget_data_get(obj);
848    if (!wd) return;
849    horizontal = !!horizontal;
850    if (wd->horizontal == horizontal) return;
851    wd->horizontal = horizontal;
852    _theme_hook(obj);
853 }
854
855 /**
856  * Get orientation of the slider
857  *
858  * @param obj The slider object
859  * @return If @c EINA_TRUE the slider will be horizontal, else it is
860  *         vertical.
861  * @ingroup Slider
862  */
863 EAPI Eina_Bool
864 elm_slider_horizontal_get(const Evas_Object *obj)
865 {
866    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
867    Widget_Data *wd = elm_widget_data_get(obj);
868    if (!wd) return EINA_FALSE;
869    return wd->horizontal;
870 }
871
872 /**
873  * Set the minimum and maximum values for the slider
874  *
875  * Maximum mut be greater than minimum.
876  *
877  * @param obj The slider object
878  * @param min The minimum value
879  * @param max The maximum value
880  *
881  * @ingroup Slider
882  */
883 EAPI void
884 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
885 {
886    ELM_CHECK_WIDTYPE(obj, widtype);
887    Widget_Data *wd = elm_widget_data_get(obj);
888    if (!wd) return;
889    if ((wd->val_min == min) && (wd->val_max == max)) return;
890    wd->val_min = min;
891    wd->val_max = max;
892    if (wd->val < wd->val_min) wd->val = wd->val_min;
893    if (wd->val > wd->val_max) wd->val = wd->val_max;
894    _val_set(obj);
895    _units_set(obj);
896    _indicator_set(obj);
897 }
898
899 /**
900  * Get the minimum and maximum values for the slider
901  *
902  * @param obj The slider object
903  * @param min The pointer to store minimum value, may be @c NULL.
904  * @param max The pointer to store maximum value, may be @c NULL.
905  *
906  * @ingroup Slider
907  */
908 EAPI void
909 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
910 {
911    if (min) *min = 0.0;
912    if (max) *max = 0.0;
913    ELM_CHECK_WIDTYPE(obj, widtype);
914    Widget_Data *wd = elm_widget_data_get(obj);
915    if (!wd) return;
916    if (min) *min = wd->val_min;
917    if (max) *max = wd->val_max;
918 }
919
920 /**
921  * Set the value the slider indicates
922  *
923  * @param obj The slider object
924  * @param val The value (must be between min and max for the slider)
925  *
926  * @ingroup Slider
927  */
928 EAPI void
929 elm_slider_value_set(Evas_Object *obj, double val)
930 {
931    ELM_CHECK_WIDTYPE(obj, widtype);
932    Widget_Data *wd = elm_widget_data_get(obj);
933    if (!wd) return;
934    if (wd->val == val) return;
935    wd->val = val;
936    if (wd->val < wd->val_min) wd->val = wd->val_min;
937    if (wd->val > wd->val_max) wd->val = wd->val_max;
938    _val_set(obj);
939    _units_set(obj);
940    _indicator_set(obj);
941 }
942
943 /**
944  * Get the value the slider has
945  *
946  * @param obj The slider object
947  * @return The value of the slider
948  *
949  * @ingroup Slider
950  */
951 EAPI double
952 elm_slider_value_get(const Evas_Object *obj)
953 {
954    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
955    Widget_Data *wd = elm_widget_data_get(obj);
956    if (!wd) return 0.0;
957    return wd->val;
958 }
959
960 /**
961  * Invert the slider display
962  *
963  * Normally the slider will display and interpret values from low to high
964  * and when horizontal that is left to right. When vertical that is top
965  * to bottom. This inverts this (so from right to left or bottom to top) if
966  * inverted is set to 1.
967  *
968  * @param obj The slider object
969  * @param inverted The inverted flag. 1 == inverted, 0 == normal
970  *
971  * @ingroup Slider
972  */
973 EAPI void
974 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
975 {
976    ELM_CHECK_WIDTYPE(obj, widtype);
977    Widget_Data *wd = elm_widget_data_get(obj);
978    if (!wd) return;
979    inverted = !!inverted;
980    if (wd->inverted == inverted) return;
981    wd->inverted = inverted;
982    if (wd->inverted)
983      edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
984    else
985      edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
986    edje_object_message_signal_process(wd->slider);
987    _val_set(obj);
988    _units_set(obj);
989    _indicator_set(obj);
990 }
991
992 /**
993  * Get if the slider display is inverted (backwards)
994  *
995  * @param obj The slider object
996  * @return If @c EINA_TRUE the slider will be inverted.
997  * @ingroup Slider
998  */
999 EAPI Eina_Bool
1000 elm_slider_inverted_get(const Evas_Object *obj)
1001 {
1002    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1003    Widget_Data *wd = elm_widget_data_get(obj);
1004    if (!wd) return EINA_FALSE;
1005    return wd->inverted;
1006 }
1007
1008 /**
1009  * Set the format function pointer for the inducator area
1010  *
1011  * Set the callback function to format the indicator string.
1012  * See elm_slider_indicator_format_set() for more info on how this works.
1013  *
1014  * @param obj The slider object
1015  * @param indicator The format string for the indicator display
1016  * @param func The indicator format function
1017  *
1018  * @ingroup Slider
1019  */
1020 EAPI void
1021 elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val))
1022 {
1023    ELM_CHECK_WIDTYPE(obj, widtype);
1024    Widget_Data *wd = elm_widget_data_get(obj);
1025    if (!wd) return;
1026    wd->indicator_format_func = func;
1027    _indicator_set(obj);
1028 }
1029
1030 /**
1031  * Set the end object (rightmost widget) of the slider object.
1032  *
1033  * Once the end object is set, a previously set one will be deleted.
1034  * If you want to keep that old content object, use the
1035  * elm_button_end_unset() function.
1036  *
1037  * @param obj The slider object
1038  * @param end The end object
1039  *
1040  * @note If the object being set does not have minimum size hints set,
1041  * it won't get properly displayed.
1042  *
1043  * @ingroup Slider
1044  */
1045 EAPI void
1046 elm_slider_end_set(Evas_Object *obj, Evas_Object *end)
1047 {
1048    ELM_CHECK_WIDTYPE(obj, widtype);
1049    Widget_Data *wd = elm_widget_data_get(obj);
1050    if (!wd) return;
1051    if (wd->end == end) return;
1052    if (wd->end) evas_object_del(wd->end);
1053    wd->end = end;
1054    if (end)
1055      {
1056         elm_widget_sub_object_add(obj, end);
1057         evas_object_event_callback_add(end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
1058                                        _changed_size_hints, obj);
1059         edje_object_part_swallow(wd->slider, "elm.swallow.end", end);
1060         edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
1061         edje_object_message_signal_process(wd->slider);
1062      }
1063    _sizing_eval(obj);
1064 }
1065
1066 /**
1067  * Unset the rightmost widget of the slider, unparenting and
1068  * returning it.
1069  *
1070  * @param obj The slider object
1071  * @return the previously set end sub-object of this slider, on
1072  * success.
1073  *
1074  * @see elm_slider_end_set()
1075  *
1076  * @ingroup Slider
1077  */
1078 EAPI Evas_Object *
1079 elm_slider_end_unset(Evas_Object *obj)
1080 {
1081    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1082    Widget_Data *wd = elm_widget_data_get(obj);
1083    Evas_Object *ret = NULL;
1084    if (!wd) return NULL;
1085    if (wd->end)
1086      {
1087         elm_widget_sub_object_del(obj, wd->end);
1088         ret = wd->end;
1089         edje_object_part_unswallow(wd->slider, wd->end);
1090         edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
1091         wd->end = NULL;
1092         _sizing_eval(obj);
1093      }
1094    return ret;
1095 }
1096
1097 /**
1098  * Get the end icon object of the slider object. This object is owned
1099  * by the scrolled entry and should not be modified.
1100  *
1101  * @param obj The slider object
1102  * @return The end icon object
1103  *
1104  * @ingroup Slider
1105  */
1106 EAPI Evas_Object *
1107 elm_slider_end_get(const Evas_Object *obj)
1108 {
1109    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1110    Widget_Data *wd = elm_widget_data_get(obj);
1111    if (!wd) return NULL;
1112    return wd->end;
1113 }
1114
1115 /**
1116  * Set whether to the slider indicator (augmented knob) at all.
1117  *
1118  * @param obj The slider object
1119  * @param show @c EINA_TRUE will make it show it, @c EINA_FALSE will
1120  * let the knob alwayes at default size.
1121  *
1122  * @note It will conflict with elm_slider_indicator_format_set(), if
1123  * you wanted those effects.
1124  *
1125  * @ingroup Slider
1126  */
1127 EAPI void
1128 elm_slider_indicator_show_set(Evas_Object *obj, Eina_Bool show)
1129 {
1130    ELM_CHECK_WIDTYPE(obj, widtype);
1131    Widget_Data *wd = elm_widget_data_get(obj);
1132    if (show) {
1133         wd->indicator_show = EINA_TRUE;
1134         edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
1135    }
1136    else {
1137         wd->indicator_show = EINA_FALSE;
1138         edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
1139    }
1140 }
1141
1142 /**
1143  * Get the state of indicator in the slider (if it's being shown or
1144  * not).
1145  *
1146  * @param obj The slider object
1147  * @return @c EINA_TRUE if the indicator is being shown, @c EINA_FALSE
1148  * otherwise.
1149  *
1150  *  @ingroup Slider
1151  */
1152 EAPI Eina_Bool
1153 elm_slider_indicator_show_get(const Evas_Object *obj)
1154 {
1155    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1156    Widget_Data *wd = elm_widget_data_get(obj);
1157    if (!wd) return EINA_FALSE;
1158    return wd->indicator_show;
1159 }
1160