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