svn update: 51469 (latest:51480)
[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 *spacer;
49    const char *label;
50    const char *units;
51    const char *indicator;
52    const char *(*indicator_format_func)(double val);
53    Eina_Bool horizontal : 1;
54    Eina_Bool inverted : 1;
55    double val, val_min, val_max;
56    Ecore_Timer *delay;
57    Evas_Coord size;
58 };
59
60 static const char *widtype = NULL;
61 static void _del_hook(Evas_Object *obj);
62 static void _theme_hook(Evas_Object *obj);
63 static void _sizing_eval(Evas_Object *obj);
64 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
65 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
66 static void _units_set(Evas_Object *obj);
67 static void _indicator_set(Evas_Object *obj);
68
69 static const char SIG_CHANGED[] = "changed";
70 static const char SIG_DELAY_CHANGED[] = "delay,changed";
71 static const char SIG_DRAG_START[] = "slider,drag,start";
72 static const char SIG_DRAG_STOP[] = "slider,drag,stop";
73 static const Evas_Smart_Cb_Description _signals[] = {
74   {SIG_CHANGED, ""},
75   {SIG_DELAY_CHANGED, ""},
76   {SIG_DRAG_START, ""},
77   {SIG_DRAG_STOP, ""},
78   {NULL, NULL}
79 };
80
81 static void
82 _del_hook(Evas_Object *obj)
83 {
84    Widget_Data *wd = elm_widget_data_get(obj);
85    if (!wd) return;
86    if (wd->label) eina_stringshare_del(wd->label);
87    if (wd->indicator) eina_stringshare_del(wd->units);
88    if (wd->delay) ecore_timer_del(wd->delay);
89    free(wd);
90 }
91
92 static void
93 _theme_hook(Evas_Object *obj)
94 {
95    Widget_Data *wd = elm_widget_data_get(obj);
96    if (!wd) return;
97    if (wd->horizontal)
98      _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", elm_widget_style_get(obj));
99    else
100      _elm_theme_object_set(obj, wd->slider, "slider", "vertical", elm_widget_style_get(obj));
101    if (wd->inverted)
102      edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
103    else
104      edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
105    if (wd->icon)
106      edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
107    else
108      edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
109    if (wd->label)
110      edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
111    else
112      edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
113    edje_object_part_text_set(wd->slider, "elm.text", wd->label);
114    if (wd->units)
115      edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
116    else
117      edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
118    if (wd->horizontal)
119      evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
120    else
121      evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
122    edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
123    _units_set(obj);
124    edje_object_message_signal_process(wd->slider);
125    edje_object_scale_set(wd->slider, elm_widget_scale_get(obj) * _elm_config->scale);
126    _sizing_eval(obj);
127 }
128
129 static void
130 _sizing_eval(Evas_Object *obj)
131 {   
132    Widget_Data *wd = elm_widget_data_get(obj);
133    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
134    if (!wd) return;
135    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
136    edje_object_size_min_restricted_calc(wd->slider, &minw, &minh, minw, minh);
137    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
138    evas_object_size_hint_min_set(obj, minw, minh);
139    evas_object_size_hint_max_set(obj, maxw, maxh);
140 }
141
142 static void
143 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
144 {
145    Widget_Data *wd = elm_widget_data_get(data);
146    if (!wd) return;
147    if (obj != wd->icon) return;
148    _sizing_eval(data);
149 }
150
151 static void
152 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
153 {
154    Widget_Data *wd = elm_widget_data_get(obj);
155    Evas_Object *sub = event_info;
156    if (!wd) return;
157    if (sub == wd->icon)
158      {
159         edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
160         evas_object_event_callback_del_full
161           (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
162         wd->icon = NULL;
163         edje_object_message_signal_process(wd->slider);
164         _sizing_eval(obj);
165      }
166 }
167
168 static Eina_Bool
169 _delay_change(void *data)
170 {
171    Widget_Data *wd = elm_widget_data_get(data);
172    if (!wd) return ECORE_CALLBACK_CANCEL;
173    wd->delay = NULL;
174    evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, NULL);
175    return ECORE_CALLBACK_CANCEL;
176 }
177
178 static void
179 _val_fetch(Evas_Object *obj)
180 {
181    Widget_Data *wd = elm_widget_data_get(obj);
182    double posx = 0.0, posy = 0.0, pos = 0.0, val;
183    if (!wd) return;
184    edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider",
185                                    &posx, &posy);
186    if (wd->horizontal) pos = posx;
187    else pos = posy;
188    if (wd->inverted) pos = 1.0 - pos;
189    val = (pos * (wd->val_max - wd->val_min)) + wd->val_min;
190    if (val != wd->val)
191      {
192         wd->val = val;
193         evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
194         if (wd->delay) ecore_timer_del(wd->delay);
195         wd->delay = ecore_timer_add(0.2, _delay_change, obj);
196      }
197 }
198
199 static void
200 _val_set(Evas_Object *obj)
201 {
202    Widget_Data *wd = elm_widget_data_get(obj);
203    double pos;
204    if (!wd) return;
205    if (wd->val_max > wd->val_min)
206      pos = (wd->val - wd->val_min) / (wd->val_max - wd->val_min);
207    else
208      pos = 0.0;
209    if (pos < 0.0) pos = 0.0;
210    else if (pos > 1.0) pos = 1.0;
211    if (wd->inverted) pos = 1.0 - pos;
212    edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", pos, pos);
213 }
214
215 static void
216 _units_set(Evas_Object *obj)
217 {
218    Widget_Data *wd = elm_widget_data_get(obj);
219    if (!wd) return;
220    if (wd->units)
221      {
222         char buf[1024];
223
224         snprintf(buf, sizeof(buf), wd->units, wd->val);
225         edje_object_part_text_set(wd->slider, "elm.units", buf);
226      }
227    else
228      edje_object_part_text_set(wd->slider, "elm.units", NULL);
229 }
230
231 static void
232 _indicator_set(Evas_Object *obj)
233 {
234    Widget_Data *wd = elm_widget_data_get(obj);
235    if (!wd) return;
236    if (wd->indicator_format_func)
237      {
238         const char *buf;
239         buf = wd->indicator_format_func(wd->val);
240         edje_object_part_text_set(wd->slider, "elm.indicator", buf);
241      }
242    else if (wd->indicator)
243      {
244         char buf[1024];
245         snprintf(buf, sizeof(buf), wd->indicator, wd->val);
246         edje_object_part_text_set(wd->slider, "elm.indicator", buf);
247      }
248    else
249      edje_object_part_text_set(wd->slider, "elm.indicator", NULL);
250 }
251
252 static void
253 _drag(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
254 {
255    _val_fetch(data);
256    _units_set(data);
257    _indicator_set(data);
258 }
259
260 static void
261 _drag_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
262 {
263    _val_fetch(data);
264    evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
265    _units_set(data);
266    _indicator_set(data);
267 }
268
269 static void
270 _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
271 {
272    _val_fetch(data);
273    evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
274    _units_set(data);
275    _indicator_set(data);
276 }
277
278 static void
279 _drag_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
280 {
281    Widget_Data *wd = elm_widget_data_get(data);
282    edje_object_part_drag_step(wd->slider, "elm.dragable.slider", -0.05, -0.05);
283 }
284
285 static void
286 _drag_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
287 {
288    Widget_Data *wd = elm_widget_data_get(data);
289    edje_object_part_drag_step(wd->slider, "elm.dragable.slider", 0.05, 0.05);
290 }
291
292 /**
293  * Add a new slider to the parent
294  *
295  * @param parent The parent object
296  * @return The new object or NULL if it cannot be created
297  *
298  * @ingroup Slider
299  */
300 EAPI Evas_Object *
301 elm_slider_add(Evas_Object *parent)
302 {
303    Evas_Object *obj;
304    Evas *e;
305    Widget_Data *wd;
306
307    wd = ELM_NEW(Widget_Data);
308    e = evas_object_evas_get(parent);
309    obj = elm_widget_add(e);
310    ELM_SET_WIDTYPE(widtype, "slider");
311    elm_widget_type_set(obj, "slider");
312    elm_widget_sub_object_add(parent, obj);
313    elm_widget_data_set(obj, wd);
314    elm_widget_del_hook_set(obj, _del_hook);
315    elm_widget_theme_hook_set(obj, _theme_hook);
316
317    wd->horizontal = EINA_TRUE;
318    wd->val = 0.0;
319    wd->val_min = 0.0;
320    wd->val_max = 1.0;
321
322    wd->slider = edje_object_add(e);
323    _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
324    elm_widget_resize_object_set(obj, wd->slider);
325    edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
326    edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
327    edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
328    edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_stop, obj);
329    edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
330 //   edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
331    edje_object_signal_callback_add(wd->slider, "mouse,wheel,0,-1", "*", _drag_up, obj);
332    edje_object_signal_callback_add(wd->slider, "mouse,wheel,0,1", "*", _drag_down, obj);
333    edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
334
335    wd->spacer = evas_object_rectangle_add(e);
336    evas_object_color_set(wd->spacer, 0, 0, 0, 0);
337    evas_object_pass_events_set(wd->spacer, 1);
338    elm_widget_sub_object_add(obj, wd->spacer);
339    edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
340
341    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
342
343    _sizing_eval(obj);
344
345    // TODO: convert Elementary to subclassing of Evas_Smart_Class
346    // TODO: and save some bytes, making descriptions per-class and not instance!
347    evas_object_smart_callbacks_descriptions_set(obj, _signals);
348    return obj;
349 }
350
351 /**
352  * Set the label of the slider
353  *
354  * @param obj The slider object
355  * @param label The text label string in UTF-8
356  *
357  * @ingroup Slider
358  */
359 EAPI void
360 elm_slider_label_set(Evas_Object *obj, const char *label)
361 {
362    ELM_CHECK_WIDTYPE(obj, widtype);
363    Widget_Data *wd = elm_widget_data_get(obj);
364    if (!wd) return;
365    eina_stringshare_replace(&wd->label, label);
366    if (label)
367      {
368         edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
369         edje_object_message_signal_process(wd->slider);
370      }
371    else
372      {
373         edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
374         edje_object_message_signal_process(wd->slider);
375      }
376    edje_object_part_text_set(wd->slider, "elm.text", label);
377    _sizing_eval(obj);
378 }
379
380 /**
381  * Get the label of the slider
382  *
383  * @param obj The slider object
384  * @return The text label string in UTF-8
385  *
386  * @ingroup Slider
387  */
388 EAPI const char *
389 elm_slider_label_get(const Evas_Object *obj)
390 {
391    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
392    Widget_Data *wd = elm_widget_data_get(obj);
393    if (!wd) return NULL;
394    return wd->label;
395 }
396
397 /**
398  * Set the icon object of the slider object
399  *
400  * Once the icon object is set, a previously set one will be deleted.
401  *
402  * @param obj The slider object
403  * @param icon The icon object
404  *
405  * @ingroup Slider
406  */
407 EAPI void
408 elm_slider_icon_set(Evas_Object *obj, Evas_Object *icon)
409 {
410    ELM_CHECK_WIDTYPE(obj, widtype);
411    Widget_Data *wd = elm_widget_data_get(obj);
412    if (!wd) return;
413    if (wd->icon == icon) return;
414    if (wd->icon) evas_object_del(wd->icon);
415    wd->icon = icon;
416    if (icon)
417      {
418         elm_widget_sub_object_add(obj, icon);
419         evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
420                                        _changed_size_hints, obj);
421         edje_object_part_swallow(wd->slider, "elm.swallow.content", icon);
422         edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
423         edje_object_message_signal_process(wd->slider);
424      }
425    _sizing_eval(obj);
426 }
427
428 /**
429  * Get the icon object of the slider object
430  *
431  * @param obj The slider object
432  * @return The icon object
433  *
434  * @ingroup Slider
435  */
436 EAPI Evas_Object *
437 elm_slider_icon_get(const Evas_Object *obj)
438 {
439    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
440    Widget_Data *wd = elm_widget_data_get(obj);
441    if (!wd) return NULL;
442    return wd->icon;
443 }
444
445 /**
446  * Set the length of the dragable region of the slider
447  *
448  * This sets the minimum width or height (depending on orientation) of the
449  * area of the slider that allows the slider to be dragged around. This in
450  * turn affects the objects minimum size (along with icon label and unit
451  * text). Note that this will also get multiplied by the scale factor.
452  *
453  * @param obj The slider object
454  * @param size The length of the slider area
455  *
456  * @ingroup Slider
457  */
458 EAPI void
459 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
460 {
461    ELM_CHECK_WIDTYPE(obj, widtype);
462    Widget_Data *wd = elm_widget_data_get(obj);
463    if (!wd) return;
464    if (wd->size == size) return;
465    wd->size = size;
466    if (wd->horizontal)
467      evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
468    else
469      evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
470    edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
471    _sizing_eval(obj);
472 }
473
474 /**
475  * Get the length of the dragable region of the slider
476  *
477  * This gets the minimum width or height (depending on orientation) of
478  * the area of the slider that allows the slider to be dragged
479  * around. Note that this will also get multiplied by the scale
480  * factor.
481  *
482  * @param obj The slider object
483  * @return The length of the slider area
484  *
485  * @ingroup Slider
486  */
487 EAPI Evas_Coord
488 elm_slider_span_size_get(const Evas_Object *obj)
489 {
490    ELM_CHECK_WIDTYPE(obj, widtype) 0;
491    Widget_Data *wd = elm_widget_data_get(obj);
492    if (!wd) return 0;
493    return wd->size;
494 }
495
496 /**
497  * Set the format string of the unit area
498  *
499  * If NULL, this disabls the unit area display. If not it sets the format
500  * string for the unit text. The unit text is provided a floating point
501  * value, so the unit text can display up to 1 floating point value. Note that
502  * this is optional. Use a format string such as "%1.2f meters" for example.
503  *
504  * @param obj The slider object
505  * @param units The format string for the units display
506  *
507  * @ingroup Slider
508  */
509 EAPI void
510 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
511 {
512    ELM_CHECK_WIDTYPE(obj, widtype);
513    Widget_Data *wd = elm_widget_data_get(obj);
514    if (!wd) return;
515    eina_stringshare_replace(&wd->units, units);
516    if (units)
517      {
518         edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
519         edje_object_message_signal_process(wd->slider);
520      }
521    else
522      {
523         edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
524         edje_object_message_signal_process(wd->slider);
525      }
526    _units_set(obj);
527    _sizing_eval(obj);
528 }
529
530 /**
531  * Get the format string for the unit area
532  *
533  * The slider may also display a value (the value of the slider) somewhere
534  * (for example above the slider knob that is dragged around). This sets the
535  * format string for this. See elm_slider_unit_format_set() for more
536  * information on how this works.
537  *
538  * @param obj The slider object
539  * @return The format string for the unit display.
540  *
541  * @ingroup Slider
542  */
543 EAPI const char *
544 elm_slider_unit_format_get(const Evas_Object *obj)
545 {
546    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
547    Widget_Data *wd = elm_widget_data_get(obj);
548    if (!wd) return NULL;
549    return wd->units;
550 }
551
552 /**
553  * Set the format string for the indicator area
554  *
555  * The slider may also display a value (the value of the slider) somewhere
556  * (for example above the slider knob that is dragged around). This sets the
557  * format string for this. See elm_slider_unit_format_set() for more
558  * information on how this works.
559  *
560  * @param obj The slider object
561  * @param indicator The format string for the indicator display
562  *
563  * @ingroup Slider
564  */
565 EAPI void
566 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
567 {
568    ELM_CHECK_WIDTYPE(obj, widtype);
569    Widget_Data *wd = elm_widget_data_get(obj);
570    if (!wd) return;
571    eina_stringshare_replace(&wd->indicator, indicator);
572    _indicator_set(obj);
573 }
574
575 /**
576  * Get the format string for the indicator area
577  *
578  * The slider may also display a value (the value of the slider) somewhere
579  * (for example above the slider knob that is dragged around). This sets the
580  * format string for this. See elm_slider_indicator_format_set() for more
581  * information on how this works.
582  *
583  * @param obj The slider object
584  * @return The format string for the indicator display.
585  *
586  * @ingroup Slider
587  */
588 EAPI const char *
589 elm_slider_indicator_format_get(const Evas_Object *obj)
590 {
591    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
592    Widget_Data *wd = elm_widget_data_get(obj);
593    if (!wd) return NULL;
594    return wd->indicator;
595 }
596
597 /**
598  * Set orientation of the slider
599  *
600  * @param obj The slider object
601  * @param horizontal If set, the slider will be horizontal
602  *
603  * @ingroup Slider
604  */
605 EAPI void
606 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
607 {
608    ELM_CHECK_WIDTYPE(obj, widtype);
609    Widget_Data *wd = elm_widget_data_get(obj);
610    if (!wd) return;
611    horizontal = !!horizontal;
612    if (wd->horizontal == horizontal) return;
613    wd->horizontal = horizontal;
614    _theme_hook(obj);
615 }
616
617 /**
618  * Get orientation of the slider
619  *
620  * @param obj The slider object
621  * @return If @c EINA_TRUE the slider will be horizontal, else it is
622  *         vertical.
623  * @ingroup Slider
624  */
625 EAPI Eina_Bool
626 elm_slider_horizontal_get(const Evas_Object *obj)
627 {
628    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
629    Widget_Data *wd = elm_widget_data_get(obj);
630    if (!wd) return EINA_FALSE;
631    return wd->horizontal;
632 }
633
634 /**
635  * Set the minimum and maximum values for the slider
636  *
637  * Maximum mut be greater than minimum.
638  *
639  * @param obj The slider object
640  * @param min The minimum value
641  * @param max The maximum value
642  *
643  * @ingroup Slider
644  */
645 EAPI void
646 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
647 {
648    ELM_CHECK_WIDTYPE(obj, widtype);
649    Widget_Data *wd = elm_widget_data_get(obj);
650    if (!wd) return;
651    if ((wd->val_min == min) && (wd->val_max == max)) return;
652    wd->val_min = min;
653    wd->val_max = max;
654    if (wd->val < wd->val_min) wd->val = wd->val_min;
655    if (wd->val > wd->val_max) wd->val = wd->val_max;
656    _val_set(obj);
657    _units_set(obj);
658    _indicator_set(obj);
659 }
660
661 /**
662  * Get the minimum and maximum values for the slider
663  *
664  * @param obj The slider object
665  * @param min The pointer to store minimum value, may be @c NULL.
666  * @param max The pointer to store maximum value, may be @c NULL.
667  *
668  * @ingroup Slider
669  */
670 EAPI void
671 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
672 {
673    if (min) *min = 0.0;
674    if (max) *max = 0.0;
675    ELM_CHECK_WIDTYPE(obj, widtype);
676    Widget_Data *wd = elm_widget_data_get(obj);
677    if (!wd) return;
678    if (min) *min = wd->val_min;
679    if (max) *max = wd->val_max;
680 }
681
682 /**
683  * Set the value the slider indicates
684  *
685  * @param obj The slider object
686  * @param val The value (must be beween min and max for the slider)
687  *
688  * @ingroup Slider
689  */
690 EAPI void
691 elm_slider_value_set(Evas_Object *obj, double val)
692 {
693    ELM_CHECK_WIDTYPE(obj, widtype);
694    Widget_Data *wd = elm_widget_data_get(obj);
695    if (!wd) return;
696    if (wd->val == val) return;
697    wd->val = val;
698    if (wd->val < wd->val_min) wd->val = wd->val_min;
699    if (wd->val > wd->val_max) wd->val = wd->val_max;
700    _val_set(obj);
701    _units_set(obj);
702    _indicator_set(obj);
703 }
704
705 /**
706  * Get the value the slider has
707  *
708  * @param obj The slider object
709  * @return The value of the slider
710  *
711  * @ingroup Slider
712  */
713 EAPI double
714 elm_slider_value_get(const Evas_Object *obj)
715 {
716    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
717    Widget_Data *wd = elm_widget_data_get(obj);
718    if (!wd) return 0.0;
719    return wd->val;
720 }
721
722 /**
723  * Invert the slider display
724  *
725  * Normally the slider will display and interpret values from low to high
726  * and when horizontal that is left to right. When vertical that is top
727  * to bottom. This inverts this (so from right to left or bottom to top) if
728  * inverted is set to 1.
729  *
730  * @param obj The slider object
731  * @param inverted The inverted flag. 1 == inverted, 0 == normal
732  *
733  * @ingroup Slider
734  */
735 EAPI void
736 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
737 {
738    ELM_CHECK_WIDTYPE(obj, widtype);
739    Widget_Data *wd = elm_widget_data_get(obj);
740    if (!wd) return;
741    inverted = !!inverted;
742    if (wd->inverted == inverted) return;
743    wd->inverted = inverted;
744    if (wd->inverted)
745      edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
746    else
747      edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
748    edje_object_message_signal_process(wd->slider);
749    _val_set(obj);
750    _units_set(obj);
751    _indicator_set(obj);
752 }
753
754 /**
755  * Get if the slider display is inverted (backwards)
756  *
757  * @param obj The slider object
758  * @return If @c EINA_TRUE the slider will be inverted.
759  * @ingroup Slider
760  */
761 EAPI Eina_Bool
762 elm_slider_inverted_get(const Evas_Object *obj)
763 {
764    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
765    Widget_Data *wd = elm_widget_data_get(obj);
766    if (!wd) return EINA_FALSE;
767    return wd->inverted;
768 }
769
770 /**
771  * Set the format function pointer for the inducator area
772  *
773  * Set the callback function to format the indicator string.
774  * See elm_slider_indicator_format_set() for more info on how this works.
775  *
776  * @param obj The slider object
777  * @param indicator The format string for the indicator display
778  * @param func The indicator format function
779  *
780  * @ingroup Slider
781  */
782 EAPI void
783 elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val))
784 {
785    ELM_CHECK_WIDTYPE(obj, widtype);
786    Widget_Data *wd = elm_widget_data_get(obj);
787    if (!wd) return;
788    wd->indicator_format_func = func;
789    _indicator_set(obj);
790 }
791