[separator slider] Remove docs
[framework/uifw/elementary.git] / src / lib / elm_slider.c
1 #include <Elementary.h>
2 #include "elm_priv.h"
3
4 typedef struct _Widget_Data Widget_Data;
5
6 struct _Widget_Data
7 {
8    Evas_Object *slider;
9    Evas_Object *icon;
10    Evas_Object *end;
11    Evas_Object *spacer;
12
13    Ecore_Timer *delay;
14
15    const char *label;
16    const char *units;
17    const char *indicator;
18
19    const char *(*indicator_format_func)(double val);
20    void (*indicator_format_free)(const char *str);
21
22    const char *(*units_format_func)(double val);
23    void (*units_format_free)(const char *str);
24
25    double val, val_min, val_max;
26    Evas_Coord size;
27
28    Eina_Bool horizontal : 1;
29    Eina_Bool inverted : 1;
30    Eina_Bool indicator_show : 1;
31    int feed_cnt;
32 };
33
34 #define ELM_SLIDER_INVERTED_FACTOR (-1.0)
35
36 static const char *widtype = NULL;
37 static void _del_hook(Evas_Object *obj);
38 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
39 static void _theme_hook(Evas_Object *obj);
40 static void _disable_hook(Evas_Object *obj);
41 static void _sizing_eval(Evas_Object *obj);
42 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
43 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
44 static void _units_set(Evas_Object *obj);
45 static void _val_set(Evas_Object *obj);
46 static void _indicator_set(Evas_Object *obj);
47 static void _on_focus_hook(void *data, Evas_Object *obj);
48 static void _drag_up(void *data, Evas_Object *obj,
49                     const char *emission, const char *source);
50 static void _drag_down(void *data, Evas_Object *obj,
51                     const char *emission, const char *source);
52 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
53                              Evas_Callback_Type type, void *event_info);
54 static void _spacer_cb(void *data, Evas * e, Evas_Object * obj, void *event_info);
55
56 static const char SIG_CHANGED[] = "changed";
57 static const char SIG_DELAY_CHANGED[] = "delay,changed";
58 static const char SIG_DRAG_START[] = "slider,drag,start";
59 static const char SIG_DRAG_STOP[] = "slider,drag,stop";
60 static const Evas_Smart_Cb_Description _signals[] = {
61   {SIG_CHANGED, ""},
62   {SIG_DELAY_CHANGED, ""},
63   {SIG_DRAG_START, ""},
64   {SIG_DRAG_STOP, ""},
65   {NULL, NULL}
66 };
67
68 static Eina_Bool
69 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
70 {
71    Evas_Event_Mouse_Wheel *mev;
72    Evas_Event_Key_Down *ev;
73    Widget_Data *wd;
74
75    wd = elm_widget_data_get(obj);
76    if (!wd) return EINA_FALSE;
77    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
78
79    if (type == EVAS_CALLBACK_KEY_DOWN) goto key_down;
80    else if (type != EVAS_CALLBACK_MOUSE_WHEEL) return EINA_FALSE;
81
82    mev = event_info;
83    if (mev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
84    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
85
86    if (mev->z < 0) _drag_up(obj, NULL, NULL, NULL);
87    else _drag_down(obj, NULL, NULL, NULL);
88    mev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
89    return EINA_TRUE;
90
91   key_down:
92    ev = event_info;
93    if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
94    if (elm_widget_disabled_get(obj)) return EINA_FALSE;
95    if ((!strcmp(ev->keyname, "Left"))
96        || (!strcmp(ev->keyname, "KP_Left")))
97      {
98         if (!wd->horizontal) return EINA_FALSE;
99         if (!wd->inverted) _drag_down(obj, NULL, NULL, NULL);
100         else _drag_up(obj, NULL, NULL, NULL);
101         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
102         return EINA_TRUE;
103      }
104    else if ((!strcmp(ev->keyname, "Right"))
105             || (!strcmp(ev->keyname, "KP_Right")))
106      {
107         if (!wd->horizontal) return EINA_FALSE;
108         if (!wd->inverted) _drag_up(obj, NULL, NULL, NULL);
109         else _drag_down(obj, NULL, NULL, NULL);
110         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
111         return EINA_TRUE;
112      }
113    else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
114      {
115         if (wd->horizontal) return EINA_FALSE;
116         if (wd->inverted) _drag_up(obj, NULL, NULL, NULL);
117         else _drag_down(obj, NULL, NULL, NULL);
118         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
119         return EINA_TRUE;
120      }
121    else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
122      {
123         if (wd->horizontal) return EINA_FALSE;
124         if (wd->inverted) _drag_down(obj, NULL, NULL, NULL);
125         else _drag_up(obj, NULL, NULL, NULL);
126         ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
127         return EINA_TRUE;
128      }
129    else return EINA_FALSE;
130 }
131
132 static void
133 _del_hook(Evas_Object *obj)
134 {
135    Widget_Data *wd = elm_widget_data_get(obj);
136    if (!wd) return;
137    if (wd->label) eina_stringshare_del(wd->label);
138    if (wd->indicator) eina_stringshare_del(wd->units);
139    if (wd->delay) ecore_timer_del(wd->delay);
140    free(wd);
141 }
142
143 static void
144 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
145 {
146    Widget_Data *wd = elm_widget_data_get(obj);
147    if (!wd) return;
148    if (elm_widget_focus_get(obj))
149      {
150         edje_object_signal_emit(wd->slider, "elm,action,focus", "elm");
151         evas_object_focus_set(wd->slider, EINA_TRUE);
152      }
153    else
154      {
155         edje_object_signal_emit(wd->slider, "elm,action,unfocus", "elm");
156         evas_object_focus_set(wd->slider, EINA_FALSE);
157      }
158 }
159
160 static void
161 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
162 {
163    Widget_Data *wd = elm_widget_data_get(obj);
164    if (!wd) return;
165    edje_object_mirrored_set(wd->slider, rtl);
166 }
167
168 static void
169 _theme_hook(Evas_Object *obj)
170 {
171    Widget_Data *wd = elm_widget_data_get(obj);
172    if (!wd) return;
173    _elm_widget_mirrored_reload(obj);
174    _mirrored_set(obj, elm_widget_mirrored_get(obj));
175    if (wd->horizontal)
176      _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", elm_widget_style_get(obj));
177    else
178      _elm_theme_object_set(obj, wd->slider, "slider", "vertical", elm_widget_style_get(obj));
179    if (elm_widget_disabled_get(obj))
180      edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
181    else
182      edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
183    if (wd->icon)
184      {
185         edje_object_part_swallow(wd->slider, "elm.swallow.content", wd->icon);
186         edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
187      }
188    if (wd->end)
189      edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
190    else
191      edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
192    if (wd->label)
193      {
194         edje_object_part_text_set(wd->slider, "elm.text", wd->label);
195         edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
196      }
197
198    if (wd->units)
199      edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
200
201    if (wd->horizontal)
202      evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
203    else
204      evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
205
206    if (wd->inverted)
207      edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
208
209    edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
210    _units_set(obj);
211    _indicator_set(obj);
212    edje_object_message_signal_process(wd->slider);
213    edje_object_scale_set(wd->slider, elm_widget_scale_get(obj) * _elm_config->scale);
214    _val_set(obj);
215    _sizing_eval(obj);
216 }
217
218 static void
219 _disable_hook(Evas_Object *obj)
220 {
221    Widget_Data *wd = elm_widget_data_get(obj);
222    if (!wd) return;
223    if (elm_widget_disabled_get(obj))
224      edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
225    else
226      edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
227 }
228
229 static void
230 _sizing_eval(Evas_Object *obj)
231 {
232    Widget_Data *wd = elm_widget_data_get(obj);
233    Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
234    if (!wd) return;
235    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
236    edje_object_size_min_restricted_calc(wd->slider, &minw, &minh, minw, minh);
237    elm_coords_finger_size_adjust(1, &minw, 1, &minh);
238    evas_object_size_hint_min_set(obj, minw, minh);
239    evas_object_size_hint_max_set(obj, maxw, maxh);
240 }
241
242 static void
243 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
244 {
245    Widget_Data *wd = elm_widget_data_get(data);
246    if (!wd) return;
247    if ((obj != wd->icon) && (obj != wd->end)) return;
248    _sizing_eval(data);
249 }
250
251 static void
252 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
253 {
254    Widget_Data *wd = elm_widget_data_get(obj);
255    Evas_Object *sub = event_info;
256    if (!wd) return;
257    if (sub == wd->icon)
258      {
259         edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
260         evas_object_event_callback_del_full
261            (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
262         wd->icon = NULL;
263         edje_object_message_signal_process(wd->slider);
264         _sizing_eval(obj);
265      }
266    if (sub == wd->end)
267      {
268         edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
269         evas_object_event_callback_del_full(sub,
270                                             EVAS_CALLBACK_CHANGED_SIZE_HINTS,
271                                             _changed_size_hints, obj);
272         wd->end = NULL;
273         edje_object_message_signal_process(wd->slider);
274         _sizing_eval(obj);
275      }
276 }
277
278 static Eina_Bool
279 _delay_change(void *data)
280 {
281    Widget_Data *wd = elm_widget_data_get(data);
282    if (!wd) return ECORE_CALLBACK_CANCEL;
283    wd->delay = NULL;
284    evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, NULL);
285    return ECORE_CALLBACK_CANCEL;
286 }
287
288 static void
289 _val_fetch(Evas_Object *obj)
290 {
291    Eina_Bool rtl;
292    Widget_Data *wd = elm_widget_data_get(obj);
293    double posx = 0.0, posy = 0.0, pos = 0.0, val;
294    if (!wd) return;
295    edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider",
296                                    &posx, &posy);
297    if (wd->horizontal) pos = posx;
298    else pos = posy;
299
300    rtl = elm_widget_mirrored_get(obj);
301    if ((!rtl && wd->inverted) || (rtl &&
302                                   ((!wd->horizontal && wd->inverted) ||
303                                    (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
304    val = (pos * (wd->val_max - wd->val_min)) + wd->val_min;
305    if (val != wd->val)
306      {
307         wd->val = val;
308         evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
309         if (wd->delay) ecore_timer_del(wd->delay);
310         wd->delay = ecore_timer_add(0.2, _delay_change, obj);
311      }
312 }
313
314 static void
315 _val_set(Evas_Object *obj)
316 {
317    Eina_Bool rtl;
318    Widget_Data *wd = elm_widget_data_get(obj);
319    double pos;
320    if (!wd) return;
321    if (wd->val_max > wd->val_min)
322      pos = (wd->val - wd->val_min) / (wd->val_max - wd->val_min);
323    else
324      pos = 0.0;
325    if (pos < 0.0) pos = 0.0;
326    else if (pos > 1.0) pos = 1.0;
327
328    rtl = elm_widget_mirrored_get(obj);
329    if ((!rtl && wd->inverted) || (rtl &&
330                                   ((!wd->horizontal && wd->inverted) ||
331                                    (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
332    edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", pos, pos);
333 }
334
335 static void
336 _units_set(Evas_Object *obj)
337 {
338    Widget_Data *wd = elm_widget_data_get(obj);
339    if (!wd) return;
340    if (wd->units_format_func)
341      {
342         const char *buf;
343         buf = wd->units_format_func(wd->val);
344         edje_object_part_text_set(wd->slider, "elm.units", buf);
345         if (wd->units_format_free) wd->units_format_free(buf);
346      }
347    else if (wd->units)
348      {
349         char buf[1024];
350
351         snprintf(buf, sizeof(buf), wd->units, wd->val);
352         edje_object_part_text_set(wd->slider, "elm.units", buf);
353      }
354    else
355      edje_object_part_text_set(wd->slider, "elm.units", NULL);
356 }
357
358 static void
359 _indicator_set(Evas_Object *obj)
360 {
361    Widget_Data *wd = elm_widget_data_get(obj);
362    if (!wd) return;
363    if (wd->indicator_format_func)
364      {
365         const char *buf;
366         buf = wd->indicator_format_func(wd->val);
367         edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
368         if (wd->indicator_format_free) wd->indicator_format_free(buf);
369      }
370    else if (wd->indicator)
371      {
372         char buf[1024];
373         snprintf(buf, sizeof(buf), wd->indicator, wd->val);
374         edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
375      }
376    else
377      edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", NULL);
378 }
379
380 static void
381 _drag(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
382 {
383    Widget_Data *wd = elm_widget_data_get((Evas_Object*)data);
384    if (elm_widget_disabled_get(data)) return;
385    _val_fetch(data);
386    _units_set(data);
387    _indicator_set(data);
388    edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
389    edje_object_message_signal_process(wd->slider);
390 }
391
392 static void
393 _drag_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
394 {
395    Widget_Data *wd = elm_widget_data_get((Evas_Object*)data);
396    if (elm_widget_disabled_get(data)) return;
397    _val_fetch(data);
398    evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
399    _units_set(data);
400    _indicator_set(data);
401    elm_widget_scroll_freeze_push(data);
402    edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
403    edje_object_message_signal_process(wd->slider);
404 }
405
406 static void
407 _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
408 {
409    if (elm_widget_disabled_get(data)) return;
410    _val_fetch(data);
411    evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
412    _units_set(data);
413    _indicator_set(data);
414    elm_widget_scroll_freeze_pop(data);
415 }
416
417 static void
418 _drag_step(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
419 {
420    if (elm_widget_disabled_get(data)) return;
421    _val_fetch(data);
422    _units_set(data);
423    _indicator_set(data);
424 }
425
426 static void
427 _drag_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
428 {
429    double step;
430    Widget_Data *wd;
431    if (elm_widget_disabled_get(data)) return;
432
433    wd = elm_widget_data_get(data);
434    step = 0.05;
435
436    if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
437
438    edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
439 }
440
441 static void
442 _drag_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
443 {
444    double step;
445    Widget_Data *wd;
446    if (elm_widget_disabled_get(data)) return;
447
448    wd = elm_widget_data_get(data);
449    step = -0.05;
450
451    if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
452
453    edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
454 }
455
456 static void
457 _spacer_cb(void *data, Evas *e, Evas_Object *obj __UNUSED__, void *event_info)
458 {
459    Widget_Data *wd = elm_widget_data_get(data);
460    Evas_Event_Mouse_Down *ev = event_info;
461    Evas_Coord x, y, w, h;
462    double button_x, button_y;
463    if (elm_widget_disabled_get(data)) return;
464
465    evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
466    edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider", &button_x, &button_y);
467    if (wd->horizontal)
468      {
469         button_x = ((double)ev->canvas.x - (double)x) / (double)w;
470         if (button_x > 1) button_x = 1;
471         if (button_x < 0) button_x = 0;
472      }
473    else
474      {
475         button_y = ((double)ev->canvas.y - (double)y) / (double)h;
476         if (button_y > 1) button_y = 1;
477         if (button_y < 0) button_y = 0;
478      }
479    edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
480    evas_event_feed_mouse_cancel(e, 0, NULL);
481    wd->feed_cnt ++;
482    if(wd->feed_cnt < 3)
483    evas_event_feed_mouse_down(e, 1, EVAS_BUTTON_NONE, 0, NULL);
484    wd->feed_cnt = 0;
485 }
486
487 static void
488 _elm_slider_label_set(Evas_Object *obj, const char *item, const char *label)
489 {
490    ELM_CHECK_WIDTYPE(obj, widtype);
491    Widget_Data *wd = elm_widget_data_get(obj);
492    if (item && strcmp(item, "default")) return;
493    if (!wd) return;
494    eina_stringshare_replace(&wd->label, label);
495    if (label)
496      {
497         edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
498         edje_object_message_signal_process(wd->slider);
499      }
500    else
501      {
502         edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
503         edje_object_message_signal_process(wd->slider);
504      }
505    edje_object_part_text_set(wd->slider, "elm.text", label);
506    _sizing_eval(obj);
507 }
508
509 static const char *
510 _elm_slider_label_get(const Evas_Object *obj, const char *item)
511 {
512    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
513    Widget_Data *wd = elm_widget_data_get(obj);
514    if (item && strcmp(item, "default")) return NULL;
515    if (!wd) return NULL;
516    return wd->label;
517 }
518
519 EAPI Evas_Object *
520 elm_slider_add(Evas_Object *parent)
521 {
522    Evas_Object *obj;
523    Evas *e;
524    Widget_Data *wd;
525
526    ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
527
528    ELM_SET_WIDTYPE(widtype, "slider");
529    elm_widget_type_set(obj, "slider");
530    elm_widget_sub_object_add(parent, obj);
531    elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
532    elm_widget_data_set(obj, wd);
533    elm_widget_del_hook_set(obj, _del_hook);
534    elm_widget_theme_hook_set(obj, _theme_hook);
535    elm_widget_disable_hook_set(obj, _disable_hook);
536    elm_widget_can_focus_set(obj, EINA_TRUE);
537    elm_widget_event_hook_set(obj, _event_hook);
538    elm_widget_text_set_hook_set(obj, _elm_slider_label_set);
539    elm_widget_text_get_hook_set(obj, _elm_slider_label_get);
540
541    wd->horizontal = EINA_TRUE;
542    wd->indicator_show = EINA_TRUE;
543    wd->feed_cnt = 0;
544    wd->val = 0.0;
545    wd->val_min = 0.0;
546    wd->val_max = 1.0;
547
548    wd->slider = edje_object_add(e);
549    _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
550    elm_widget_resize_object_set(obj, wd->slider);
551    edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
552    edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
553    edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
554    edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_step, obj);
555    edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
556    //   edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
557    edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
558
559    wd->spacer = evas_object_rectangle_add(e);
560    evas_object_color_set(wd->spacer, 0, 0, 0, 0);
561    evas_object_pass_events_set(wd->spacer, EINA_TRUE);
562    elm_widget_sub_object_add(obj, wd->spacer);
563    edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
564    evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_DOWN, _spacer_cb, obj);
565    evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
566
567    _mirrored_set(obj, elm_widget_mirrored_get(obj));
568    _sizing_eval(obj);
569
570    // TODO: convert Elementary to subclassing of Evas_Smart_Class
571    // TODO: and save some bytes, making descriptions per-class and not instance!
572    evas_object_smart_callbacks_descriptions_set(obj, _signals);
573    return obj;
574 }
575
576 EAPI void
577 elm_slider_label_set(Evas_Object *obj, const char *label)
578 {
579    _elm_slider_label_set(obj, NULL, label);
580 }
581
582 EAPI const char *
583 elm_slider_label_get(const Evas_Object *obj)
584 {
585    return _elm_slider_label_get(obj, NULL);
586 }
587
588 EAPI void
589 elm_slider_icon_set(Evas_Object *obj, Evas_Object *icon)
590 {
591    ELM_CHECK_WIDTYPE(obj, widtype);
592    Widget_Data *wd = elm_widget_data_get(obj);
593    if (!wd) return;
594    if (wd->icon == icon) return;
595    if (wd->icon) evas_object_del(wd->icon);
596    wd->icon = icon;
597    if (icon)
598      {
599         elm_widget_sub_object_add(obj, icon);
600         evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
601                                        _changed_size_hints, obj);
602         edje_object_part_swallow(wd->slider, "elm.swallow.icon", icon);
603         edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
604         edje_object_message_signal_process(wd->slider);
605      }
606    _sizing_eval(obj);
607 }
608
609 EAPI Evas_Object *
610 elm_slider_icon_unset(Evas_Object *obj)
611 {
612    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
613    Widget_Data *wd = elm_widget_data_get(obj);
614    Evas_Object *ret = NULL;
615    if (!wd) return NULL;
616    if (wd->icon)
617      {
618         elm_widget_sub_object_del(obj, wd->icon);
619         ret = wd->icon;
620         edje_object_part_unswallow(wd->slider, wd->icon);
621         edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
622         wd->icon = NULL;
623         _sizing_eval(obj);
624      }
625    return ret;
626 }
627
628 EAPI Evas_Object *
629 elm_slider_icon_get(const Evas_Object *obj)
630 {
631    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
632    Widget_Data *wd = elm_widget_data_get(obj);
633    if (!wd) return NULL;
634    return wd->icon;
635 }
636
637 EAPI void
638 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
639 {
640    ELM_CHECK_WIDTYPE(obj, widtype);
641    Widget_Data *wd = elm_widget_data_get(obj);
642    if (!wd) return;
643    if (wd->size == size) return;
644    wd->size = size;
645    if (wd->horizontal)
646      evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
647    else
648      evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
649    if (wd->indicator_show)
650      edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
651    else
652      edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
653    edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
654    _sizing_eval(obj);
655 }
656
657 EAPI Evas_Coord
658 elm_slider_span_size_get(const Evas_Object *obj)
659 {
660    ELM_CHECK_WIDTYPE(obj, widtype) 0;
661    Widget_Data *wd = elm_widget_data_get(obj);
662    if (!wd) return 0;
663    return wd->size;
664 }
665
666 EAPI void
667 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
668 {
669    ELM_CHECK_WIDTYPE(obj, widtype);
670    Widget_Data *wd = elm_widget_data_get(obj);
671    if (!wd) return;
672    eina_stringshare_replace(&wd->units, units);
673    if (units)
674      {
675         edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
676         edje_object_message_signal_process(wd->slider);
677      }
678    else
679      {
680         edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
681         edje_object_message_signal_process(wd->slider);
682      }
683    _units_set(obj);
684    _sizing_eval(obj);
685 }
686
687 EAPI const char *
688 elm_slider_unit_format_get(const Evas_Object *obj)
689 {
690    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
691    Widget_Data *wd = elm_widget_data_get(obj);
692    if (!wd) return NULL;
693    return wd->units;
694 }
695
696 EAPI void
697 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
698 {
699    ELM_CHECK_WIDTYPE(obj, widtype);
700    Widget_Data *wd = elm_widget_data_get(obj);
701    if (!wd) return;
702    eina_stringshare_replace(&wd->indicator, indicator);
703    _indicator_set(obj);
704 }
705
706 EAPI const char *
707 elm_slider_indicator_format_get(const Evas_Object *obj)
708 {
709    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
710    Widget_Data *wd = elm_widget_data_get(obj);
711    if (!wd) return NULL;
712    return wd->indicator;
713 }
714
715 EAPI void
716 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
717 {
718    ELM_CHECK_WIDTYPE(obj, widtype);
719    Widget_Data *wd = elm_widget_data_get(obj);
720    if (!wd) return;
721    horizontal = !!horizontal;
722    if (wd->horizontal == horizontal) return;
723    wd->horizontal = horizontal;
724    _theme_hook(obj);
725 }
726
727 EAPI Eina_Bool
728 elm_slider_horizontal_get(const Evas_Object *obj)
729 {
730    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
731    Widget_Data *wd = elm_widget_data_get(obj);
732    if (!wd) return EINA_FALSE;
733    return wd->horizontal;
734 }
735
736 EAPI void
737 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
738 {
739    ELM_CHECK_WIDTYPE(obj, widtype);
740    Widget_Data *wd = elm_widget_data_get(obj);
741    if (!wd) return;
742    if ((wd->val_min == min) && (wd->val_max == max)) return;
743    wd->val_min = min;
744    wd->val_max = max;
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 EAPI void
753 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
754 {
755    if (min) *min = 0.0;
756    if (max) *max = 0.0;
757    ELM_CHECK_WIDTYPE(obj, widtype);
758    Widget_Data *wd = elm_widget_data_get(obj);
759    if (!wd) return;
760    if (min) *min = wd->val_min;
761    if (max) *max = wd->val_max;
762 }
763
764 EAPI void
765 elm_slider_value_set(Evas_Object *obj, double val)
766 {
767    ELM_CHECK_WIDTYPE(obj, widtype);
768    Widget_Data *wd = elm_widget_data_get(obj);
769    if (!wd) return;
770    if (wd->val == val) return;
771    wd->val = val;
772    if (wd->val < wd->val_min) wd->val = wd->val_min;
773    if (wd->val > wd->val_max) wd->val = wd->val_max;
774    edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
775    _val_set(obj);
776    _units_set(obj);
777    _indicator_set(obj);
778 }
779
780 EAPI double
781 elm_slider_value_get(const Evas_Object *obj)
782 {
783    ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
784    Widget_Data *wd = elm_widget_data_get(obj);
785    if (!wd) return 0.0;
786    return wd->val;
787 }
788
789 EAPI void
790 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
791 {
792    ELM_CHECK_WIDTYPE(obj, widtype);
793    Widget_Data *wd = elm_widget_data_get(obj);
794    if (!wd) return;
795    inverted = !!inverted;
796    if (wd->inverted == inverted) return;
797    wd->inverted = inverted;
798    if (wd->inverted)
799      edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
800    else
801      edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
802    edje_object_message_signal_process(wd->slider);
803    _val_set(obj);
804    _units_set(obj);
805    _indicator_set(obj);
806 }
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 EAPI void
818 elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val), void (*free_func)(const char *str))
819 {
820    ELM_CHECK_WIDTYPE(obj, widtype);
821    Widget_Data *wd = elm_widget_data_get(obj);
822    if (!wd) return;
823    wd->indicator_format_func = func;
824    wd->indicator_format_free = free_func;
825    _indicator_set(obj);
826 }
827
828 EAPI void
829 elm_slider_units_format_function_set(Evas_Object *obj, const char *(*func)(double val), void (*free_func)(const char *str))
830 {
831    ELM_CHECK_WIDTYPE(obj, widtype);
832    Widget_Data *wd = elm_widget_data_get(obj);
833    if (!wd) return;
834    wd->units_format_func = func;
835    wd->units_format_free = free_func;
836    _indicator_set(obj);
837 }
838
839 EAPI void
840 elm_slider_end_set(Evas_Object *obj, Evas_Object *end)
841 {
842    ELM_CHECK_WIDTYPE(obj, widtype);
843    Widget_Data *wd = elm_widget_data_get(obj);
844    if (!wd) return;
845    if (wd->end == end) return;
846    if (wd->end) evas_object_del(wd->end);
847    wd->end = end;
848    if (end)
849      {
850         elm_widget_sub_object_add(obj, end);
851         evas_object_event_callback_add(end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
852                                        _changed_size_hints, obj);
853         edje_object_part_swallow(wd->slider, "elm.swallow.end", end);
854         edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
855         edje_object_message_signal_process(wd->slider);
856      }
857    _sizing_eval(obj);
858 }
859
860 EAPI Evas_Object *
861 elm_slider_end_unset(Evas_Object *obj)
862 {
863    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
864    Widget_Data *wd = elm_widget_data_get(obj);
865    Evas_Object *ret = NULL;
866    if (!wd) return NULL;
867    if (wd->end)
868      {
869         elm_widget_sub_object_del(obj, wd->end);
870         ret = wd->end;
871         edje_object_part_unswallow(wd->slider, wd->end);
872         edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
873         wd->end = NULL;
874         _sizing_eval(obj);
875      }
876    return ret;
877 }
878
879 EAPI Evas_Object *
880 elm_slider_end_get(const Evas_Object *obj)
881 {
882    ELM_CHECK_WIDTYPE(obj, widtype) NULL;
883    Widget_Data *wd = elm_widget_data_get(obj);
884    if (!wd) return NULL;
885    return wd->end;
886 }
887
888 EAPI void
889 elm_slider_indicator_show_set(Evas_Object *obj, Eina_Bool show)
890 {
891    ELM_CHECK_WIDTYPE(obj, widtype);
892    Widget_Data *wd = elm_widget_data_get(obj);
893    if (show) {
894         wd->indicator_show = EINA_TRUE;
895         edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
896    }
897    else {
898         wd->indicator_show = EINA_FALSE;
899         edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
900    }
901 }
902
903 EAPI Eina_Bool
904 elm_slider_indicator_show_get(const Evas_Object *obj)
905 {
906    ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
907    Widget_Data *wd = elm_widget_data_get(obj);
908    if (!wd) return EINA_FALSE;
909    return wd->indicator_show;
910 }
911