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