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