[elm_slider] feed limitation
[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 int _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
189            (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
190         wd->icon = NULL;
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
197            (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
198         wd->e_icon = NULL;
199         _sizing_eval(obj);
200      }
201 }
202
203 static int
204 _delay_change(void *data)
205 {
206    Widget_Data *wd = elm_widget_data_get(data);
207    if (!wd) return 0;
208    wd->delay = NULL;
209    evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, NULL);
210    return 0;
211 }
212
213 static void
214 _val_fetch(Evas_Object *obj)
215 {
216    Widget_Data *wd = elm_widget_data_get(obj);
217    double posx = 0.0, posy = 0.0, pos = 0.0, val;
218    if (!wd) return;
219    edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider",
220                                    &posx, &posy);
221    if (wd->horizontal) pos = posx;
222    else pos = posy;
223    if (wd->inverted) pos = 1.0 - pos;
224    val = (pos * (wd->val_max - wd->val_min)) + wd->val_min;
225    if (val != wd->val)
226      {
227         wd->val = val;
228         evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
229         if (wd->delay) ecore_timer_del(wd->delay);
230         wd->delay = ecore_timer_add(0.2, _delay_change, obj);
231      }
232 }
233
234 static void
235 _val_set(Evas_Object *obj)
236 {
237    Widget_Data *wd = elm_widget_data_get(obj);
238    double pos;
239    if (!wd) return;
240    if (wd->val_max > wd->val_min)
241      pos = (wd->val - wd->val_min) / (wd->val_max - wd->val_min);
242    else
243      pos = 0.0;
244    if (pos < 0.0) pos = 0.0;
245    else if (pos > 1.0) pos = 1.0;
246    if (wd->inverted) pos = 1.0 - pos;
247    edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", pos, pos);
248 }
249
250 static void
251 _units_set(Evas_Object *obj)
252 {
253    Widget_Data *wd = elm_widget_data_get(obj);
254    if (!wd) return;
255    if (wd->units)
256      {
257         char buf[1024];
258
259         snprintf(buf, sizeof(buf), wd->units, wd->val);
260         edje_object_part_text_set(wd->slider, "elm.units", buf);
261      }
262    else if (wd->e_label)
263      edje_object_part_text_set(wd->slider, "elm.units", wd->e_label);
264    else
265      edje_object_part_text_set(wd->slider, "elm.units", NULL);
266 }
267
268 static void
269 _indicator_set(Evas_Object *obj)
270 {
271    Widget_Data *wd = elm_widget_data_get(obj);
272    if (!wd) return;
273    if (wd->indicator_format_func)
274      {
275         const char *buf;
276         buf = wd->indicator_format_func(wd->val);
277         edje_object_part_text_set(wd->slider, "elm.indicator", buf);
278      }
279    else if (wd->indicator)
280      {
281         char buf[1024];
282         snprintf(buf, sizeof(buf), wd->indicator, wd->val);
283         edje_object_part_text_set(wd->slider, "elm.indicator", buf);
284      }
285    else
286      edje_object_part_text_set(wd->slider, "elm.indicator", NULL);
287 }
288
289 static void
290 _drag(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
291 {
292     Widget_Data *wd = elm_widget_data_get((Evas_Object*)data);
293     /* delete thumb move timer when drag event occured to the moving thumb */
294     if(wd->mv_timer)
295       {
296          ecore_timer_del(wd->mv_timer);
297          wd->mv_timer = NULL;
298       }
299     edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
300     edje_object_message_signal_process(wd->slider);
301     _val_fetch(data);
302     _units_set(data);
303     _indicator_set(data);
304 }
305
306 static void
307 _drag_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
308 {
309    Widget_Data *wd = elm_widget_data_get((Evas_Object*)data);
310    /*  delete thumb move timer when drag event occured to the moving thumb */
311    if(wd->mv_timer)
312      {
313         ecore_timer_del(wd->mv_timer);
314         wd->mv_timer = NULL;
315      }
316    elm_widget_scroll_hold_push(data);
317    _val_fetch(data);
318    evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
319    edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
320     edje_object_message_signal_process(wd->slider); 
321    _units_set(data);
322    _indicator_set(data);
323 }
324
325 static void
326 _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
327 {
328    elm_widget_scroll_hold_pop(data);
329    _val_fetch(data);
330    evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
331    _units_set(data);
332    _indicator_set(data);
333 }
334
335 static void
336 _drag_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
337 {
338    Widget_Data *wd = elm_widget_data_get(data);
339    edje_object_part_drag_step(wd->slider, "elm.dragable.slider", -0.05, -0.05);
340 }
341
342 static void
343 _drag_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
344 {
345    Widget_Data *wd = elm_widget_data_get(data);
346    edje_object_part_drag_step(wd->slider, "elm.dragable.slider", 0.05, 0.05);
347 }
348
349 static void
350 _spacer_cb(void *data, Evas * e, Evas_Object * obj, void *event_info)
351 {
352    Widget_Data *wd = elm_widget_data_get(data);
353    Evas_Event_Mouse_Down *ev = event_info;
354    Evas_Coord x, y, w, h;
355    double button_x, button_y;
356
357    evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
358    edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider", &button_x, &button_y);
359    if(wd->horizontal){
360      button_x = ((double)ev->output.x - (double)x) / (double)w;
361      if (button_x > 1)
362        button_x = 1;
363      if (button_x < 0)
364        button_x = 0;
365    }
366    else {
367      button_y = ((double)ev->output.y - (double)y) / (double)h;
368      if (button_y > 1)
369        button_y = 1;
370      if (button_y < 0)
371        button_y = 0;
372    }
373    edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
374    evas_event_feed_mouse_cancel(e, 0, NULL);
375    wd->feed_cnt ++;
376    if(wd->feed_cnt < 3)
377      evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);  
378    wd->feed_cnt = 0;
379 }
380
381 static const char*widtype = NULL;
382
383 /**
384  * Add a new slider to the parent
385  *
386  * @param parent The parent object
387  * @return The new object or NULL if it cannot be created
388  *
389  * @ingroup Slider
390  */
391 EAPI Evas_Object *
392 elm_slider_add(Evas_Object *parent)
393 {
394    Evas_Object *obj;
395    Evas *e;
396    Widget_Data *wd;
397
398    wd = ELM_NEW(Widget_Data);
399    e = evas_object_evas_get(parent);
400    obj = elm_widget_add(e);
401    ELM_SET_WIDTYPE(widtype, "slider");
402    elm_widget_type_set(obj, "slider");
403    elm_widget_sub_object_add(parent, obj);
404    elm_widget_data_set(obj, wd);
405    elm_widget_del_hook_set(obj, _del_hook);
406    elm_widget_theme_hook_set(obj, _theme_hook);
407
408    wd->horizontal = EINA_TRUE;
409    wd->feed_cnt = 0;
410    wd->val = 0.0;
411    wd->val_min = 0.0;
412    wd->val_max = 1.0;
413
414     wd->mv_step = (double)((wd->val_max - wd->val_min) / (double)SLIDER_THUMB_MOVE_STEP);
415
416    wd->slider = edje_object_add(e);
417    _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
418    elm_widget_resize_object_set(obj, wd->slider);
419    edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
420    edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
421    edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
422    edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_stop, obj);
423    edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
424 //   edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
425    edje_object_signal_callback_add(wd->slider, "mouse,wheel,0,-1", "*", _drag_up, obj);
426    edje_object_signal_callback_add(wd->slider, "mouse,wheel,0,1", "*", _drag_down, obj);
427    edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
428
429    wd->spacer = evas_object_rectangle_add(e);
430    evas_object_color_set(wd->spacer, 0, 0, 0, 0);
431    evas_object_pass_events_set(wd->spacer, 1);
432    elm_widget_sub_object_add(obj, wd->spacer);
433    edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
434    evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_DOWN, _spacer_cb, obj);
435
436    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
437
438    _sizing_eval(obj);
439
440    // TODO: convert Elementary to subclassing of Evas_Smart_Class
441    // TODO: and save some bytes, making descriptions per-class and not instance!
442    evas_object_smart_callbacks_descriptions_set(obj, _signals);
443    return obj;
444 }
445
446 /**
447  * Set the label of the slider
448  *
449  * @param obj The slider object
450  * @param label The text label string in UTF-8
451  *
452  * @ingroup Slider
453  */
454 EAPI void
455 elm_slider_label_set(Evas_Object *obj, const char *label)
456 {
457    ELM_CHECK_WIDTYPE(obj, widtype);
458    Widget_Data *wd = elm_widget_data_get(obj);
459    if (!wd) return;
460    eina_stringshare_replace(&wd->label, label);
461    if (label)
462      {
463         edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
464         edje_object_message_signal_process(wd->slider);
465      }
466    else
467      {
468         edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
469         edje_object_message_signal_process(wd->slider);
470      }
471    edje_object_part_text_set(wd->slider, "elm.text", label);
472    _sizing_eval(obj);
473 }
474
475 /**
476  * Get the label of the slider
477  *
478  * @param obj The slider object
479  * @return The text label string in UTF-8
480  *
481  * @ingroup Slider
482  */
483 EAPI const char *
484 elm_slider_label_get(const Evas_Object *obj)
485 {
486    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
487    Widget_Data *wd = elm_widget_data_get(obj);
488    if (!wd) return NULL;
489    return wd->label;
490 }
491
492 /**
493  * Set the icon object of the slider object
494  *
495  * Once the icon object is set, it will become a child of the slider object and
496  * be deleted when the slider object is deleted. If another icon object is set
497  * then the previous one becomes orophaned and will no longer be deleted along
498  * with the slider.
499  *
500  * @param obj The slider object
501  * @param icon The icon object
502  *
503  * @ingroup Slider
504  */
505 EAPI void
506 elm_slider_icon_set(Evas_Object *obj, Evas_Object *icon)
507 {
508    ELM_CHECK_WIDTYPE(obj, widtype);
509    Widget_Data *wd = elm_widget_data_get(obj);
510    if (!wd) return;
511    if ((wd->icon != icon) && (wd->icon))
512      elm_widget_sub_object_del(obj, wd->icon);
513    wd->icon = icon;
514    if (icon)
515      {
516         elm_widget_sub_object_add(obj, icon);
517         evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
518                                        _changed_size_hints, obj);
519         edje_object_part_swallow(wd->slider, "elm.swallow.content", icon);
520         edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
521         _sizing_eval(obj);
522      }
523 }
524
525 /**
526  * Get the icon object of the slider object
527  *
528  * @param obj The slider object
529  * @return The icon object
530  *
531  * @ingroup Slider
532  */
533 EAPI Evas_Object *
534 elm_slider_icon_get(const Evas_Object *obj)
535 {
536    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
537    Widget_Data *wd = elm_widget_data_get(obj);
538    if (!wd) return NULL;
539    return wd->icon;
540 }
541
542 /**
543  * Set the length of the dragable region of the slider
544  *
545  * This sets the minimum width or height (depending on orientation) of the
546  * area of the slider that allows the slider to be dragged around. This in
547  * turn affects the objects minimum size (along with icon label and unit
548  * text). Note that this will also get multiplied by the scale factor.
549  *
550  * @param obj The slider object
551  * @param size The length of the slider area
552  *
553  * @ingroup Slider
554  */
555 EAPI void
556 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
557 {
558    ELM_CHECK_WIDTYPE(obj, widtype);
559    Widget_Data *wd = elm_widget_data_get(obj);
560    if (!wd) return;
561    if (wd->size == size) return;
562    wd->size = size;
563    if (wd->horizontal)
564      evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
565    else
566      evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
567    edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
568    _sizing_eval(obj);
569 }
570
571 /**
572  * Get the length of the dragable region of the slider
573  *
574  * This gets the minimum width or height (depending on orientation) of
575  * the area of the slider that allows the slider to be dragged
576  * around. Note that this will also get multiplied by the scale
577  * factor.
578  *
579  * @param obj The slider object
580  * @return The length of the slider area
581  *
582  * @ingroup Slider
583  */
584 EAPI Evas_Coord
585 elm_slider_span_size_get(const Evas_Object *obj)
586 {
587    ELM_CHECK_WIDTYPE(obj, widtype) 0;
588    Widget_Data *wd = elm_widget_data_get(obj);
589    if (!wd) return 0;
590    return wd->size;
591 }
592
593 /**
594  * Set the format string of the unit area
595  *
596  * If NULL, this disabls the unit area display. If not it sets the format
597  * string for the unit text. The unit text is provided a floating point
598  * value, so the unit text can display up to 1 floating point value. Note that
599  * this is optional. Use a format string such as "%1.2f meters" for example.
600  *
601  * @param obj The slider object
602  * @param units The format string for the units display
603  *
604  * @ingroup Slider
605  */
606 EAPI void
607 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
608 {
609    ELM_CHECK_WIDTYPE(obj, widtype);
610    Widget_Data *wd = elm_widget_data_get(obj);
611    if (!wd) return;
612    eina_stringshare_replace(&wd->units, units);
613    if (units)
614      {
615         edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
616         edje_object_message_signal_process(wd->slider);
617      }
618    else
619      {
620         edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
621         edje_object_message_signal_process(wd->slider);
622      }
623    _units_set(obj);
624    _sizing_eval(obj);
625 }
626
627 /**
628  * Get the format string for the unit area
629  *
630  * The slider may also display a value (the value of the slider) somewhere
631  * (for example above the slider knob that is dragged around). This sets the
632  * format string for this. See elm_slider_unit_format_set() for more
633  * information on how this works.
634  *
635  * @param obj The slider object
636  * @return The format string for the unit display.
637  *
638  * @ingroup Slider
639  */
640 EAPI const char *
641 elm_slider_unit_format_get(const Evas_Object *obj)
642 {
643    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
644    Widget_Data *wd = elm_widget_data_get(obj);
645    if (!wd) return NULL;
646    return wd->units;
647 }
648
649 /**
650  * Set the format string for the indicator area
651  *
652  * The slider may also display a value (the value of the slider) somewhere
653  * (for example above the slider knob that is dragged around). This sets the
654  * format string for this. See elm_slider_unit_format_set() for more
655  * information on how this works.
656  *
657  * @param obj The slider object
658  * @param indicator The format string for the indicator display
659  *
660  * @ingroup Slider
661  */
662 EAPI void
663 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
664 {
665    ELM_CHECK_WIDTYPE(obj, widtype);
666    Widget_Data *wd = elm_widget_data_get(obj);
667    if (!wd) return;
668    eina_stringshare_replace(&wd->indicator, indicator);
669    _indicator_set(obj);
670 }
671
672 /**
673  * Get the format string for the indicator area
674  *
675  * The slider may also display a value (the value of the slider) somewhere
676  * (for example above the slider knob that is dragged around). This sets the
677  * format string for this. See elm_slider_indicator_format_set() for more
678  * information on how this works.
679  *
680  * @param obj The slider object
681  * @return The format string for the indicator display.
682  *
683  * @ingroup Slider
684  */
685 EAPI const char *
686 elm_slider_indicator_format_get(const Evas_Object *obj)
687 {
688    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
689    Widget_Data *wd = elm_widget_data_get(obj);
690    if (!wd) return NULL;
691    return wd->indicator;
692 }
693
694 /**
695  * Set orientation of the slider
696  *
697  * @param obj The slider object
698  * @param horizontal If set, the slider will be horizontal
699  *
700  * @ingroup Slider
701  */
702 EAPI void
703 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
704 {
705    ELM_CHECK_WIDTYPE(obj, widtype);
706    Widget_Data *wd = elm_widget_data_get(obj);
707    if (!wd) return;
708    horizontal = !!horizontal;
709    if (wd->horizontal == horizontal) return;
710    wd->horizontal = horizontal;
711    _theme_hook(obj);
712 }
713
714 /**
715  * Get orientation of the slider
716  *
717  * @param obj The slider object
718  * @return If @c EINA_TRUE the slider will be horizontal, else it is
719  *         vertical.
720  * @ingroup Slider
721  */
722 EAPI Eina_Bool
723 elm_slider_horizontal_get(const Evas_Object *obj)
724 {
725    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
726    Widget_Data *wd = elm_widget_data_get(obj);
727    if (!wd) return EINA_FALSE;
728    return wd->horizontal;
729 }
730
731 /**
732  * Set the minimum and maximum values for the slider
733  *
734  * Maximum mut be greater than minimum.
735  *
736  * @param obj The slider object
737  * @param min The minimum value
738  * @param max The maximum value
739  *
740  * @ingroup Slider
741  */
742 EAPI void
743 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
744 {
745    ELM_CHECK_WIDTYPE(obj, widtype);
746    Widget_Data *wd = elm_widget_data_get(obj);
747    if (!wd) return;
748    if ((wd->val_min == min) && (wd->val_max == max)) return;
749    wd->val_min = min;
750    wd->val_max = max;
751
752    wd->mv_step = (double)((wd->val_max - wd->val_min) / (double)SLIDER_THUMB_MOVE_STEP);
753
754    if (wd->val < wd->val_min) wd->val = wd->val_min;
755    if (wd->val > wd->val_max) wd->val = wd->val_max;
756    _val_set(obj);
757    _units_set(obj);
758    _indicator_set(obj);
759 }
760
761 /**
762  * Get the minimum and maximum values for the slider
763  *
764  * @param obj The slider object
765  * @param min The pointer to store minimum value, may be @c NULL.
766  * @param max The pointer to store maximum value, may be @c NULL.
767  *
768  * @ingroup Slider
769  */
770 EAPI void
771 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
772 {
773    if (min) *min = 0.0;
774    if (max) *max = 0.0;
775    ELM_CHECK_WIDTYPE(obj, widtype);
776    Widget_Data *wd = elm_widget_data_get(obj);
777    if (!wd) return;
778    if (min) *min = wd->val_min;
779    if (max) *max = wd->val_max;
780 }
781
782 /**
783  * Set the value the slider indicates
784  *
785  * @param obj The slider object
786  * @param val The value (must be beween min and max for the slider)
787  *
788  * @ingroup Slider
789  */
790 EAPI void
791 elm_slider_value_set(Evas_Object *obj, double val)
792 {
793    ELM_CHECK_WIDTYPE(obj, widtype);
794    Widget_Data *wd = elm_widget_data_get(obj);
795    if (!wd) return;
796    if (wd->val == val) return;
797    wd->val = val;
798    if (wd->val < wd->val_min) wd->val = wd->val_min;
799    if (wd->val > wd->val_max) wd->val = wd->val_max;
800    edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
801    _val_set(obj);
802    _units_set(obj);
803    _indicator_set(obj);
804 }
805
806 /**
807  * Get the value the slider has
808  *
809  * @param obj The slider object
810  * @return The value of the slider
811  *
812  * @ingroup Slider
813  */
814 EAPI double
815 elm_slider_value_get(const Evas_Object *obj)
816 {
817    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
818    Widget_Data *wd = elm_widget_data_get(obj);
819    if (!wd) return 0.0;
820    return wd->val;
821 }
822
823 /**
824  * Invert the slider display
825  *
826  * Normally the slider will display and interpret values from low to high
827  * and when horizontal that is left to right. When vertical that is top
828  * to bottom. This inverts this (so from right to left or bottom to top) if
829  * inverted is set to 1.
830  *
831  * @param obj The slider object
832  * @param inverted The inverted flag. 1 == inverted, 0 == normal
833  *
834  * @ingroup Slider
835  */
836 EAPI void
837 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
838 {
839    ELM_CHECK_WIDTYPE(obj, widtype);
840    Widget_Data *wd = elm_widget_data_get(obj);
841    if (!wd) return;
842    inverted = !!inverted;
843    if (wd->inverted == inverted) return;
844    wd->inverted = inverted;
845    if (wd->inverted)
846      edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
847    else
848      edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
849    edje_object_message_signal_process(wd->slider);
850    _val_set(obj);
851    _units_set(obj);
852    _indicator_set(obj);
853 }
854
855 /**
856  * Get if the slider display is inverted (backwards)
857  *
858  * @param obj The slider object
859  * @return If @c EINA_TRUE the slider will be inverted.
860  * @ingroup Slider
861  */
862 EAPI Eina_Bool
863 elm_slider_inverted_get(const Evas_Object *obj)
864 {
865    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
866    Widget_Data *wd = elm_widget_data_get(obj);
867    if (!wd) return EINA_FALSE;
868    return wd->inverted;
869 }
870
871 /**
872  * Set the format function pointer for the inducator area
873  *
874  * Set the callback function to format the indicator string.
875  * See elm_slider_indicator_format_set() for more info on how this works.
876  *
877  * @param obj The slider object
878  * @param indicator The format string for the indicator display
879  * @param func The indicator format function
880  *
881  * @ingroup Slider
882  */
883 EAPI void
884 elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val))
885 {
886    ELM_CHECK_WIDTYPE(obj, widtype);
887    Widget_Data *wd = elm_widget_data_get(obj);
888    if (!wd) return;
889    wd->indicator_format_func = func;
890    _indicator_set(obj);
891 }
892
893
894 //////////////////////////////////////////////////////////////////////////////////////////////////////
895 ////////////////////////  supporting beat feature  ///////////////////////////////////////////////////
896 //////////////////////////////////////////////////////////////////////////////////////////////////////
897
898
899
900 /**
901  * Set the right icon object of the slider object
902  *
903  * Once the right icon object is set, it will become a child of the slider object and
904  * be deleted when the slider object is deleted. If another icon object is set
905  * then the previous one becomes orophaned and will no longer be deleted along
906  * with the slider.
907  *
908  * @param obj The slider object
909  * @param icon The icon object
910  * 
911  * @return 1 if icon set succeed, 0 if there is no part for right icon 
912  * 
913  * @ingroup Slider
914  */
915 EAPI Eina_Bool 
916 elm_slider_end_icon_set(Evas_Object *obj, Evas_Object *icon)
917 {
918    Widget_Data *wd = elm_widget_data_get(obj);
919
920    if ((wd->e_icon != icon) && (wd->e_icon))
921      elm_widget_sub_object_del(obj, wd->e_icon);
922
923    if (icon)
924      {
925         if ( !(edje_object_part_swallow(wd->slider, "end_icon", icon)) )
926           return EINA_FALSE;            
927         wd->e_icon = icon;
928         elm_widget_sub_object_add(obj, icon);
929         evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
930               _changed_size_hints, obj);
931         edje_object_signal_emit(wd->slider, "elm,state,eicon,visible", "elm");
932         _sizing_eval(obj);
933      }
934
935    return EINA_TRUE;
936 }
937
938
939 /**
940  * Get the right icon object of the slider object
941  *
942  * @param obj The slider object
943  * @return The right icon object
944  *
945  * @ingroup Slider
946  */
947 EAPI Evas_Object *
948 elm_slider_end_icon_get(Evas_Object *obj)
949 {
950    Widget_Data *wd = elm_widget_data_get(obj);
951    if (!wd) return NULL;
952    return wd->e_icon;
953 }
954
955
956 /**
957  * Set whether showing the number(indicator) or not.
958  *
959  * @param obj The slider object
960  * @param show 1 will show the number, 0 will not.
961  *
962  * @ingroup Slider
963  */
964 EAPI void
965 elm_slider_indicator_show_set(Evas_Object *obj, Eina_Bool show)
966 {
967    Widget_Data *wd = elm_widget_data_get(obj);
968    if(show)
969      edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
970    else
971      edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");                  
972 }
973
974 static int _mv_timer_cb(void *data)
975 {
976    Evas_Object* obj = (Evas_Object*)data;
977    Widget_Data *wd = elm_widget_data_get(obj);
978
979    if (!wd) return 1;
980
981    if(wd->src_val < wd->des_val) 
982      {
983         wd->src_val += wd->mv_step;
984         if(wd-> src_val > wd->des_val)  
985           wd->src_val = wd->des_val;
986      }  
987    else if (wd->src_val > wd->des_val) 
988      {
989         wd->src_val -= wd->mv_step;
990         if(wd->src_val < wd->des_val)   
991           wd->src_val = wd->des_val;
992      }  
993
994    elm_slider_value_set(obj, wd->src_val);
995    evas_object_smart_callback_call(obj, SIG_CHANGED , NULL);
996
997    if (wd->val == wd->des_val) 
998      {
999         if(wd->mv_timer)
1000           {
1001              ecore_timer_del(wd->mv_timer);
1002              wd->mv_timer = NULL;
1003           }     
1004         return 0;
1005      }
1006    else
1007      return 1;
1008 }
1009
1010
1011 /**
1012  * Move the thumb to the specified value.
1013  *
1014  * This is different with elm_slider_value_set() in animated moving. 
1015  * 
1016  * @param obj The slider object
1017  * @param val thumb's destination value.
1018  *
1019  * @ingroup Slider
1020  */
1021 EAPI void
1022 elm_slider_value_animated_set(Evas_Object *obj, double val)
1023 {
1024    Widget_Data *wd = elm_widget_data_get(obj);
1025
1026    if (wd->val == val) return;
1027
1028    wd->src_val = wd->val;
1029    wd->des_val = val;
1030    if (wd->des_val < wd->val_min) wd->des_val = wd->val_min;    
1031    if (wd->des_val > wd->val_max) wd->des_val = wd->val_max;
1032
1033    if(wd->mv_timer)
1034      {
1035         ecore_timer_del(wd->mv_timer);
1036         wd->mv_timer = NULL;
1037      }
1038
1039    wd->mv_timer = ecore_timer_add(0.005, _mv_timer_cb, obj);    
1040 }
1041
1042
1043 /**
1044  * Set the label of the slider
1045  *
1046  * @param obj The slider object
1047  * @param label The text label string in UTF-8
1048  *
1049  * @ingroup Slider
1050  */
1051 EAPI void
1052 elm_slider_end_label_set(Evas_Object *obj, const char *label)
1053 {
1054    ELM_CHECK_WIDTYPE(obj, widtype);
1055    Widget_Data *wd = elm_widget_data_get(obj);
1056    if (!wd) return;
1057    eina_stringshare_replace(&wd->e_label, label);
1058    if (label)
1059      {
1060         edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
1061         edje_object_message_signal_process(wd->slider);
1062      }
1063    else
1064      {
1065         edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
1066         edje_object_message_signal_process(wd->slider);
1067      }
1068    edje_object_part_text_set(wd->slider, "elm.units", label);
1069    if(wd->units)
1070      wd->units = NULL;
1071    _sizing_eval(obj);
1072 }
1073
1074 /**
1075  * Get the label of the slider
1076  *
1077  * @param obj The slider object
1078  * @return The text label string in UTF-8
1079  *
1080  * @ingroup Slider
1081  */
1082 EAPI const char *
1083 elm_slider_end_label_get(const Evas_Object *obj)
1084 {
1085    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1086    Widget_Data *wd = elm_widget_data_get(obj);
1087    if (!wd) return NULL;
1088    return wd->e_label;
1089 }