[slider, editfield, colorpicker, colorpalette] merged
[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 /**
331  * Add a new slider to the parent
332  *
333  * @param parent The parent object
334  * @return The new object or NULL if it cannot be created
335  *
336  * @ingroup Slider
337  */
338 EAPI Evas_Object *
339 elm_slider_add(Evas_Object *parent)
340 {
341    Evas_Object *obj;
342    Evas *e;
343    Widget_Data *wd;
344
345    wd = ELM_NEW(Widget_Data);
346    e = evas_object_evas_get(parent);
347    obj = elm_widget_add(e);
348    ELM_SET_WIDTYPE(widtype, "slider");
349    elm_widget_type_set(obj, "slider");
350    elm_widget_sub_object_add(parent, obj);
351    elm_widget_data_set(obj, wd);
352    elm_widget_del_hook_set(obj, _del_hook);
353    elm_widget_theme_hook_set(obj, _theme_hook);
354
355    wd->horizontal = EINA_TRUE;
356    wd->val = 0.0;
357    wd->val_min = 0.0;
358    wd->val_max = 1.0;
359
360     /* supporting aqua feature */
361     wd->mv_step = (double)((wd->val_max - wd->val_min) / (double)SLIDER_THUMB_MOVE_STEP);
362
363    wd->slider = edje_object_add(e);
364    _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
365    elm_widget_resize_object_set(obj, wd->slider);
366    edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
367    edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
368    edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
369    edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_stop, obj);
370    edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
371 //   edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
372    edje_object_signal_callback_add(wd->slider, "mouse,wheel,0,-1", "*", _drag_up, obj);
373    edje_object_signal_callback_add(wd->slider, "mouse,wheel,0,1", "*", _drag_down, obj);
374    edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
375
376    wd->spacer = evas_object_rectangle_add(e);
377    evas_object_color_set(wd->spacer, 0, 0, 0, 0);
378    evas_object_pass_events_set(wd->spacer, 1);
379    elm_widget_sub_object_add(obj, wd->spacer);
380    edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
381
382    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
383
384    _sizing_eval(obj);
385
386    // TODO: convert Elementary to subclassing of Evas_Smart_Class
387    // TODO: and save some bytes, making descriptions per-class and not instance!
388    evas_object_smart_callbacks_descriptions_set(obj, _signals);
389    return obj;
390 }
391
392 /**
393  * Set the label of the slider
394  *
395  * @param obj The slider object
396  * @param label The text label string in UTF-8
397  *
398  * @ingroup Slider
399  */
400 EAPI void
401 elm_slider_label_set(Evas_Object *obj, const char *label)
402 {
403    ELM_CHECK_WIDTYPE(obj, widtype);
404    Widget_Data *wd = elm_widget_data_get(obj);
405    if (!wd) return;
406    eina_stringshare_replace(&wd->label, label);
407    if (label)
408      {
409         edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
410         edje_object_message_signal_process(wd->slider);
411      }
412    else
413      {
414         edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
415         edje_object_message_signal_process(wd->slider);
416      }
417    edje_object_part_text_set(wd->slider, "elm.text", label);
418    _sizing_eval(obj);
419 }
420
421 /**
422  * Get the label of the slider
423  *
424  * @param obj The slider object
425  * @return The text label string in UTF-8
426  *
427  * @ingroup Slider
428  */
429 EAPI const char *
430 elm_slider_label_get(const Evas_Object *obj)
431 {
432    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
433    Widget_Data *wd = elm_widget_data_get(obj);
434    if (!wd) return NULL;
435    return wd->label;
436 }
437
438 /**
439  * Set the icon object of the slider object
440  *
441  * Once the icon object is set, it will become a child of the slider object and
442  * be deleted when the slider object is deleted. If another icon object is set
443  * then the previous one becomes orophaned and will no longer be deleted along
444  * with the slider.
445  *
446  * @param obj The slider object
447  * @param icon The icon object
448  *
449  * @ingroup Slider
450  */
451 EAPI void
452 elm_slider_icon_set(Evas_Object *obj, Evas_Object *icon)
453 {
454    ELM_CHECK_WIDTYPE(obj, widtype);
455    Widget_Data *wd = elm_widget_data_get(obj);
456    if (!wd) return;
457    if ((wd->icon != icon) && (wd->icon))
458      elm_widget_sub_object_del(obj, wd->icon);
459    wd->icon = icon;
460    if (icon)
461      {
462         elm_widget_sub_object_add(obj, icon);
463         evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
464                                        _changed_size_hints, obj);
465         edje_object_part_swallow(wd->slider, "elm.swallow.content", icon);
466         edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
467         _sizing_eval(obj);
468      }
469 }
470
471 /**
472  * Get the icon object of the slider object
473  *
474  * @param obj The slider object
475  * @return The icon object
476  *
477  * @ingroup Slider
478  */
479 EAPI Evas_Object *
480 elm_slider_icon_get(const Evas_Object *obj)
481 {
482    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
483    Widget_Data *wd = elm_widget_data_get(obj);
484    if (!wd) return NULL;
485    return wd->icon;
486 }
487
488 /**
489  * Set the length of the dragable region of the slider
490  *
491  * This sets the minimum width or height (depending on orientation) of the
492  * area of the slider that allows the slider to be dragged around. This in
493  * turn affects the objects minimum size (along with icon label and unit
494  * text). Note that this will also get multiplied by the scale factor.
495  *
496  * @param obj The slider object
497  * @param size The length of the slider area
498  *
499  * @ingroup Slider
500  */
501 EAPI void
502 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
503 {
504    ELM_CHECK_WIDTYPE(obj, widtype);
505    Widget_Data *wd = elm_widget_data_get(obj);
506    if (!wd) return;
507    if (wd->size == size) return;
508    wd->size = size;
509    if (wd->horizontal)
510      evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
511    else
512      evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
513    edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
514    _sizing_eval(obj);
515 }
516
517 /**
518  * Get the length of the dragable region of the slider
519  *
520  * This gets the minimum width or height (depending on orientation) of
521  * the area of the slider that allows the slider to be dragged
522  * around. Note that this will also get multiplied by the scale
523  * factor.
524  *
525  * @param obj The slider object
526  * @return The length of the slider area
527  *
528  * @ingroup Slider
529  */
530 EAPI Evas_Coord
531 elm_slider_span_size_get(const Evas_Object *obj)
532 {
533    ELM_CHECK_WIDTYPE(obj, widtype) 0;
534    Widget_Data *wd = elm_widget_data_get(obj);
535    if (!wd) return 0;
536    return wd->size;
537 }
538
539 /**
540  * Set the format string of the unit area
541  *
542  * If NULL, this disabls the unit area display. If not it sets the format
543  * string for the unit text. The unit text is provided a floating point
544  * value, so the unit text can display up to 1 floating point value. Note that
545  * this is optional. Use a format string such as "%1.2f meters" for example.
546  *
547  * @param obj The slider object
548  * @param units The format string for the units display
549  *
550  * @ingroup Slider
551  */
552 EAPI void
553 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
554 {
555    ELM_CHECK_WIDTYPE(obj, widtype);
556    Widget_Data *wd = elm_widget_data_get(obj);
557    if (!wd) return;
558    eina_stringshare_replace(&wd->units, units);
559    if (units)
560      {
561         edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
562         edje_object_message_signal_process(wd->slider);
563      }
564    else
565      {
566         edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
567         edje_object_message_signal_process(wd->slider);
568      }
569    _units_set(obj);
570    _sizing_eval(obj);
571 }
572
573 /**
574  * Get the format string for the unit area
575  *
576  * The slider may also display a value (the value of the slider) somewhere
577  * (for example above the slider knob that is dragged around). This sets the
578  * format string for this. See elm_slider_unit_format_set() for more
579  * information on how this works.
580  *
581  * @param obj The slider object
582  * @return The format string for the unit display.
583  *
584  * @ingroup Slider
585  */
586 EAPI const char *
587 elm_slider_unit_format_get(const Evas_Object *obj)
588 {
589    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
590    Widget_Data *wd = elm_widget_data_get(obj);
591    if (!wd) return NULL;
592    return wd->units;
593 }
594
595 /**
596  * Set the format string for the indicator area
597  *
598  * The slider may also display a value (the value of the slider) somewhere
599  * (for example above the slider knob that is dragged around). This sets the
600  * format string for this. See elm_slider_unit_format_set() for more
601  * information on how this works.
602  *
603  * @param obj The slider object
604  * @param indicator The format string for the indicator display
605  *
606  * @ingroup Slider
607  */
608 EAPI void
609 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
610 {
611    ELM_CHECK_WIDTYPE(obj, widtype);
612    Widget_Data *wd = elm_widget_data_get(obj);
613    if (!wd) return;
614    eina_stringshare_replace(&wd->indicator, indicator);
615    _indicator_set(obj);
616 }
617
618 /**
619  * Get the format string for the indicator area
620  *
621  * The slider may also display a value (the value of the slider) somewhere
622  * (for example above the slider knob that is dragged around). This sets the
623  * format string for this. See elm_slider_indicator_format_set() for more
624  * information on how this works.
625  *
626  * @param obj The slider object
627  * @return The format string for the indicator display.
628  *
629  * @ingroup Slider
630  */
631 EAPI const char *
632 elm_slider_indicator_format_get(const Evas_Object *obj)
633 {
634    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
635    Widget_Data *wd = elm_widget_data_get(obj);
636    if (!wd) return NULL;
637    return wd->indicator;
638 }
639
640 /**
641  * Set orientation of the slider
642  *
643  * @param obj The slider object
644  * @param horizontal If set, the slider will be horizontal
645  *
646  * @ingroup Slider
647  */
648 EAPI void
649 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
650 {
651    ELM_CHECK_WIDTYPE(obj, widtype);
652    Widget_Data *wd = elm_widget_data_get(obj);
653    if (!wd) return;
654    horizontal = !!horizontal;
655    if (wd->horizontal == horizontal) return;
656    wd->horizontal = horizontal;
657    _theme_hook(obj);
658 }
659
660 /**
661  * Get orientation of the slider
662  *
663  * @param obj The slider object
664  * @return If @c EINA_TRUE the slider will be horizontal, else it is
665  *         vertical.
666  * @ingroup Slider
667  */
668 EAPI Eina_Bool
669 elm_slider_horizontal_get(const Evas_Object *obj)
670 {
671    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
672    Widget_Data *wd = elm_widget_data_get(obj);
673    if (!wd) return EINA_FALSE;
674    return wd->horizontal;
675 }
676
677 /**
678  * Set the minimum and maximum values for the slider
679  *
680  * Maximum mut be greater than minimum.
681  *
682  * @param obj The slider object
683  * @param min The minimum value
684  * @param max The maximum value
685  *
686  * @ingroup Slider
687  */
688 EAPI void
689 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
690 {
691    ELM_CHECK_WIDTYPE(obj, widtype);
692    Widget_Data *wd = elm_widget_data_get(obj);
693    if (!wd) return;
694    if ((wd->val_min == min) && (wd->val_max == max)) return;
695    wd->val_min = min;
696    wd->val_max = max;
697
698         /* supporting aqua feature */
699         wd->mv_step = (double)((wd->val_max - wd->val_min) / (double)SLIDER_THUMB_MOVE_STEP);
700
701    if (wd->val < wd->val_min) wd->val = wd->val_min;
702    if (wd->val > wd->val_max) wd->val = wd->val_max;
703    _val_set(obj);
704    _units_set(obj);
705    _indicator_set(obj);
706 }
707
708 /**
709  * Get the minimum and maximum values for the slider
710  *
711  * @param obj The slider object
712  * @param min The pointer to store minimum value, may be @c NULL.
713  * @param max The pointer to store maximum value, may be @c NULL.
714  *
715  * @ingroup Slider
716  */
717 EAPI void
718 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
719 {
720    if (min) *min = 0.0;
721    if (max) *max = 0.0;
722    ELM_CHECK_WIDTYPE(obj, widtype);
723    Widget_Data *wd = elm_widget_data_get(obj);
724    if (!wd) return;
725    if (min) *min = wd->val_min;
726    if (max) *max = wd->val_max;
727 }
728
729 /**
730  * Set the value the slider indicates
731  *
732  * @param obj The slider object
733  * @param val The value (must be beween min and max for the slider)
734  *
735  * @ingroup Slider
736  */
737 EAPI void
738 elm_slider_value_set(Evas_Object *obj, double val)
739 {
740    ELM_CHECK_WIDTYPE(obj, widtype);
741    Widget_Data *wd = elm_widget_data_get(obj);
742    if (!wd) return;
743    if (wd->val == val) return;
744    wd->val = val;
745    if (wd->val < wd->val_min) wd->val = wd->val_min;
746    if (wd->val > wd->val_max) wd->val = wd->val_max;
747    _val_set(obj);
748    _units_set(obj);
749    _indicator_set(obj);
750 }
751
752 /**
753  * Get the value the slider has
754  *
755  * @param obj The slider object
756  * @return The value of the slider
757  *
758  * @ingroup Slider
759  */
760 EAPI double
761 elm_slider_value_get(const Evas_Object *obj)
762 {
763    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
764    Widget_Data *wd = elm_widget_data_get(obj);
765    if (!wd) return 0.0;
766    return wd->val;
767 }
768
769 /**
770  * Invert the slider display
771  *
772  * Normally the slider will display and interpret values from low to high
773  * and when horizontal that is left to right. When vertical that is top
774  * to bottom. This inverts this (so from right to left or bottom to top) if
775  * inverted is set to 1.
776  *
777  * @param obj The slider object
778  * @param inverted The inverted flag. 1 == inverted, 0 == normal
779  *
780  * @ingroup Slider
781  */
782 EAPI void
783 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
784 {
785    ELM_CHECK_WIDTYPE(obj, widtype);
786    Widget_Data *wd = elm_widget_data_get(obj);
787    if (!wd) return;
788    inverted = !!inverted;
789    if (wd->inverted == inverted) return;
790    wd->inverted = inverted;
791    if (wd->inverted)
792      edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
793    else
794      edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
795    edje_object_message_signal_process(wd->slider);
796    _val_set(obj);
797    _units_set(obj);
798    _indicator_set(obj);
799 }
800
801 /**
802  * Get if the slider display is inverted (backwards)
803  *
804  * @param obj The slider object
805  * @return If @c EINA_TRUE the slider will be inverted.
806  * @ingroup Slider
807  */
808 EAPI Eina_Bool
809 elm_slider_inverted_get(const Evas_Object *obj)
810 {
811    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
812    Widget_Data *wd = elm_widget_data_get(obj);
813    if (!wd) return EINA_FALSE;
814    return wd->inverted;
815 }
816
817 /**
818  * Set the format function pointer for the inducator area
819  *
820  * Set the callback function to format the indicator string.
821  * See elm_slider_indicator_format_set() for more info on how this works.
822  *
823  * @param obj The slider object
824  * @param indicator The format string for the indicator display
825  * @param func The indicator format function
826  *
827  * @ingroup Slider
828  */
829 EAPI void
830 elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val))
831 {
832    ELM_CHECK_WIDTYPE(obj, widtype);
833    Widget_Data *wd = elm_widget_data_get(obj);
834    if (!wd) return;
835    wd->indicator_format_func = func;
836    _indicator_set(obj);
837 }
838
839
840 //////////////////////////////////////////////////////////////////////////////////////////////////////
841 ////////////////////////  supporting aqua feature  ///////////////////////////////////////////////////
842 //////////////////////////////////////////////////////////////////////////////////////////////////////
843
844
845
846 /**
847  * Set the right icon object of the slider object
848  *
849  * Once the right icon object is set, it will become a child of the slider object and
850  * be deleted when the slider object is deleted. If another icon object is set
851  * then the previous one becomes orophaned and will no longer be deleted along
852  * with the slider.
853  *
854  * @param obj The slider object
855  * @param icon The icon object
856  * 
857  * @return 1 if icon set succeed, 0 if there is no part for right icon 
858  * 
859  * @ingroup Slider
860  */
861 EAPI Eina_Bool 
862 elm_slider_right_icon_set(Evas_Object *obj, Evas_Object *icon)
863 {
864         Widget_Data *wd = elm_widget_data_get(obj);
865         
866         if ((wd->r_icon != icon) && (wd->r_icon))
867                 elm_widget_sub_object_del(obj, wd->r_icon);
868         
869         if (icon)
870         {
871                 if ( !(edje_object_part_swallow(wd->slider, "right_icon", icon)) )
872                         return EINA_FALSE;              
873                 wd->r_icon = icon;
874                 elm_widget_sub_object_add(obj, icon);
875                 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
876                                 _changed_size_hints, obj);
877                 edje_object_signal_emit(wd->slider, "elm,state,ricon,visible", "elm");
878                 _sizing_eval(obj);
879         }
880         
881         return EINA_TRUE;
882 }
883
884
885 /**
886  * Get the right icon object of the slider object
887  *
888  * @param obj The slider object
889  * @return The right icon object
890  *
891  * @ingroup Slider
892  */
893 EAPI Evas_Object *
894 elm_slider_right_icon_get(Evas_Object *obj)
895 {
896         Widget_Data *wd = elm_widget_data_get(obj);
897         if (!wd) return NULL;
898         return wd->r_icon;
899 }
900
901
902 /**
903  * Set whether showing the number(indicator) or not.
904  *
905  * @param obj The slider object
906  * @param show 1 will show the number, 0 will not.
907  *
908  * @ingroup Slider
909  */
910 EAPI void
911 elm_slider_indicator_show_set(Evas_Object *obj, Eina_Bool show)
912 {
913         Widget_Data *wd = elm_widget_data_get(obj);
914         if(show)
915                 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
916         else
917                 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");                       
918 }
919
920
921
922 static _mv_timer_cb(void *data)
923 {
924         Evas_Object* obj = (Evas_Object*)data;
925         Widget_Data *wd = elm_widget_data_get(obj);
926         
927         if (!wd) return EINA_TRUE;
928         
929         if(wd->src_val < wd->des_val) {
930                 wd->src_val += wd->mv_step;
931                 if(wd-> src_val > wd->des_val)  
932                         wd->src_val = wd->des_val;
933         }       
934         
935         else if (wd->src_val > wd->des_val) {
936                 wd->src_val -= wd->mv_step;
937                 if(wd->src_val < wd->des_val)   
938                         wd->src_val = wd->des_val;
939         }       
940                 
941         elm_slider_value_set(obj, wd->src_val);
942         evas_object_smart_callback_call(obj, "changed", NULL);
943
944         if (wd->val == wd->des_val ) {
945                 if(wd->mv_timer){
946                         ecore_timer_del(wd->mv_timer);
947                         wd->mv_timer = NULL;
948                 }       
949                 return EINA_FALSE;
950         }
951         else
952                 return EINA_TRUE;
953 }
954
955
956 /**
957  * Move the thumb to the specified value.
958  *
959  * This is different with elm_slider_value_set() in animated moving. 
960  * 
961  * @param obj The slider object
962  * @param val thumb's destination value.
963  *
964  * @ingroup Slider
965  */
966 EAPI void
967 elm_slider_value_animated_set(Evas_Object *obj, double val)
968 {
969         Widget_Data *wd = elm_widget_data_get(obj);
970         
971         if (wd->val == val) return;
972         
973         wd->src_val = wd->val;
974         wd->des_val = val;
975         if (wd->des_val < wd->val_min) wd->des_val = wd->val_min;       
976         if (wd->des_val > wd->val_max) wd->des_val = wd->val_max;
977
978         if(wd->mv_timer){
979                 ecore_timer_del(wd->mv_timer);
980                 wd->mv_timer = NULL;
981         }
982         
983         wd->mv_timer = ecore_timer_add(0.005, _mv_timer_cb, obj);       
984 }
985
986