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