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