1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
17 const char *indicator;
19 const char *(*indicator_format_func)(double val);
20 void (*indicator_format_free)(const char *str);
22 const char *(*units_format_func)(double val);
23 void (*units_format_free)(const char *str);
25 double val, val_min, val_max, val2;
27 Evas_Coord downx, downy;
29 Eina_Bool horizontal : 1;
30 Eina_Bool inverted : 1;
31 Eina_Bool indicator_show : 1;
32 Eina_Bool spacer_down : 1;
36 #define ELM_SLIDER_INVERTED_FACTOR (-1.0)
38 static const char *widtype = NULL;
39 static void _del_hook(Evas_Object *obj);
40 static void _mirrored_set(Evas_Object *obj, Eina_Bool rtl);
41 static void _theme_hook(Evas_Object *obj);
42 static void _disable_hook(Evas_Object *obj);
43 static void _sizing_eval(Evas_Object *obj);
44 static void _changed_size_hints(void *data, Evas *e, Evas_Object *obj, void *event_info);
45 static void _sub_del(void *data, Evas_Object *obj, void *event_info);
46 static void _units_set(Evas_Object *obj);
47 static void _val_set(Evas_Object *obj);
48 static void _indicator_set(Evas_Object *obj);
49 static void _on_focus_hook(void *data, Evas_Object *obj);
50 static void _drag_up(void *data, Evas_Object *obj,
51 const char *emission, const char *source);
52 static void _drag_down(void *data, Evas_Object *obj,
53 const char *emission, const char *source);
54 static Eina_Bool _event_hook(Evas_Object *obj, Evas_Object *src,
55 Evas_Callback_Type type, void *event_info);
56 static void _spacer_down_cb(void *data, Evas * e, Evas_Object * obj, void *event_info);
57 static void _spacer_move_cb(void *data, Evas * e, Evas_Object * obj, void *event_info);
58 static void _spacer_up_cb(void *data, Evas * e, Evas_Object * obj, void *event_info);
60 static const char SIG_CHANGED[] = "changed";
61 static const char SIG_DELAY_CHANGED[] = "delay,changed";
62 static const char SIG_DRAG_START[] = "slider,drag,start";
63 static const char SIG_DRAG_STOP[] = "slider,drag,stop";
64 static const Evas_Smart_Cb_Description _signals[] = {
66 {SIG_DELAY_CHANGED, ""},
73 _event_hook(Evas_Object *obj, Evas_Object *src __UNUSED__, Evas_Callback_Type type, void *event_info)
75 Evas_Event_Mouse_Wheel *mev;
76 Evas_Event_Key_Down *ev;
79 wd = elm_widget_data_get(obj);
80 if (!wd) return EINA_FALSE;
82 if (type == EVAS_CALLBACK_KEY_DOWN) goto key_down;
83 else if (type != EVAS_CALLBACK_MOUSE_WHEEL) return EINA_FALSE;
86 if (mev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
87 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
89 if (mev->z < 0) _drag_up(obj, NULL, NULL, NULL);
90 else _drag_down(obj, NULL, NULL, NULL);
91 mev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
96 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD) return EINA_FALSE;
97 if (elm_widget_disabled_get(obj)) return EINA_FALSE;
98 if ((!strcmp(ev->keyname, "Left"))
99 || (!strcmp(ev->keyname, "KP_Left")))
101 if (!wd->horizontal) return EINA_FALSE;
102 if (!wd->inverted) _drag_down(obj, NULL, NULL, NULL);
103 else _drag_up(obj, NULL, NULL, NULL);
104 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
107 else if ((!strcmp(ev->keyname, "Right"))
108 || (!strcmp(ev->keyname, "KP_Right")))
110 if (!wd->horizontal) return EINA_FALSE;
111 if (!wd->inverted) _drag_up(obj, NULL, NULL, NULL);
112 else _drag_down(obj, NULL, NULL, NULL);
113 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
116 else if ((!strcmp(ev->keyname, "Up")) || (!strcmp(ev->keyname, "KP_Up")))
118 if (wd->horizontal) return EINA_FALSE;
119 if (wd->inverted) _drag_up(obj, NULL, NULL, NULL);
120 else _drag_down(obj, NULL, NULL, NULL);
121 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
124 else if ((!strcmp(ev->keyname, "Down")) || (!strcmp(ev->keyname, "KP_Down")))
126 if (wd->horizontal) return EINA_FALSE;
127 if (wd->inverted) _drag_down(obj, NULL, NULL, NULL);
128 else _drag_up(obj, NULL, NULL, NULL);
129 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
132 else return EINA_FALSE;
136 _del_hook(Evas_Object *obj)
138 Widget_Data *wd = elm_widget_data_get(obj);
140 if (wd->labels) eina_hash_free(wd->labels);
141 if (wd->indicator) eina_stringshare_del(wd->units);
142 if (wd->delay) ecore_timer_del(wd->delay);
147 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
149 Widget_Data *wd = elm_widget_data_get(obj);
151 if (elm_widget_focus_get(obj))
153 edje_object_signal_emit(wd->slider, "elm,action,focus", "elm");
154 evas_object_focus_set(wd->slider, EINA_TRUE);
158 edje_object_signal_emit(wd->slider, "elm,action,unfocus", "elm");
159 evas_object_focus_set(wd->slider, EINA_FALSE);
164 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
166 Widget_Data *wd = elm_widget_data_get(obj);
168 edje_object_mirrored_set(wd->slider, rtl);
172 _labels_foreach_text_set(const Eina_Hash *hash __UNUSED__, const void *key, void *data, void *fdata)
174 Widget_Data *wd = fdata;
176 edje_object_part_text_set(wd->slider, key, data);
182 _theme_hook(Evas_Object *obj)
184 Widget_Data *wd = elm_widget_data_get(obj);
186 _elm_widget_mirrored_reload(obj);
187 _mirrored_set(obj, elm_widget_mirrored_get(obj));
189 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", elm_widget_style_get(obj));
191 _elm_theme_object_set(obj, wd->slider, "slider", "vertical", elm_widget_style_get(obj));
194 edje_object_part_swallow(wd->slider, "elm.swallow.content", wd->icon);
195 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
198 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
200 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
203 eina_hash_foreach(wd->labels, _labels_foreach_text_set, wd);
204 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
208 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
211 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
213 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
216 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
218 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
221 edje_object_message_signal_process(wd->slider);
222 edje_object_scale_set(wd->slider, elm_widget_scale_get(obj) * _elm_config->scale);
228 _disable_hook(Evas_Object *obj)
230 Widget_Data *wd = elm_widget_data_get(obj);
232 if (elm_widget_disabled_get(obj))
233 edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
235 edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
239 _sizing_eval(Evas_Object *obj)
241 Widget_Data *wd = elm_widget_data_get(obj);
242 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
244 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
245 edje_object_size_min_restricted_calc(wd->slider, &minw, &minh, minw, minh);
246 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
247 evas_object_size_hint_min_set(obj, minw, minh);
248 evas_object_size_hint_max_set(obj, maxw, maxh);
252 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
254 Widget_Data *wd = elm_widget_data_get(data);
256 if ((obj != wd->icon) && (obj != wd->end)) return;
261 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
263 Widget_Data *wd = elm_widget_data_get(obj);
264 Evas_Object *sub = event_info;
268 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
269 evas_object_event_callback_del_full
270 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
272 edje_object_message_signal_process(wd->slider);
277 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
278 evas_object_event_callback_del_full(sub,
279 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
280 _changed_size_hints, obj);
282 edje_object_message_signal_process(wd->slider);
288 _delay_change(void *data)
290 Widget_Data *wd = elm_widget_data_get(data);
291 if (!wd) return ECORE_CALLBACK_CANCEL;
293 evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, NULL);
294 return ECORE_CALLBACK_CANCEL;
298 _val_fetch(Evas_Object *obj)
301 Widget_Data *wd = elm_widget_data_get(obj);
302 double posx = 0.0, posy = 0.0, pos = 0.0, val;
304 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider",
306 if (wd->horizontal) pos = posx;
309 rtl = elm_widget_mirrored_get(obj);
310 if ((!rtl && wd->inverted) || (rtl &&
311 ((!wd->horizontal && wd->inverted) ||
312 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
313 val = (pos * (wd->val_max - wd->val_min)) + wd->val_min;
317 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
318 if (wd->delay) ecore_timer_del(wd->delay);
319 wd->delay = ecore_timer_add(0.2, _delay_change, obj);
324 _val_set(Evas_Object *obj)
327 Widget_Data *wd = elm_widget_data_get(obj);
330 if (wd->val_max > wd->val_min)
331 pos = (wd->val - wd->val_min) / (wd->val_max - wd->val_min);
334 if (pos < 0.0) pos = 0.0;
335 else if (pos > 1.0) pos = 1.0;
337 rtl = elm_widget_mirrored_get(obj);
338 if ((!rtl && wd->inverted) || (rtl &&
339 ((!wd->horizontal && wd->inverted) ||
340 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
341 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", pos, pos);
345 _units_set(Evas_Object *obj)
347 Widget_Data *wd = elm_widget_data_get(obj);
349 if (wd->units_format_func)
352 buf = wd->units_format_func(wd->val);
353 edje_object_part_text_set(wd->slider, "elm.units", buf);
354 if (wd->units_format_free) wd->units_format_free(buf);
360 snprintf(buf, sizeof(buf), wd->units, wd->val);
361 edje_object_part_text_set(wd->slider, "elm.units", buf);
364 edje_object_part_text_set(wd->slider, "elm.units", NULL);
368 _indicator_set(Evas_Object *obj)
370 Widget_Data *wd = elm_widget_data_get(obj);
372 if (wd->indicator_format_func)
375 buf = wd->indicator_format_func(wd->val);
376 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
377 if (wd->indicator_format_free) wd->indicator_format_free(buf);
379 else if (wd->indicator)
382 snprintf(buf, sizeof(buf), wd->indicator, wd->val);
383 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
386 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", NULL);
390 _drag(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
394 _indicator_set(data);
398 _drag_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
401 evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
403 _indicator_set(data);
404 elm_widget_scroll_freeze_push(data);
408 _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
411 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
413 _indicator_set(data);
414 elm_widget_scroll_freeze_pop(data);
418 _drag_step(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
422 _indicator_set(data);
426 _drag_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
431 wd = elm_widget_data_get(data);
434 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
436 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
440 _drag_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
445 wd = elm_widget_data_get(data);
448 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
450 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
454 _spacer_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
456 Widget_Data *wd = elm_widget_data_get(data);
457 Evas_Event_Mouse_Down *ev = event_info;
458 Evas_Coord x, y, w, h;
459 double button_x = 0.0, button_y = 0.0;
461 wd->spacer_down = EINA_TRUE;
463 evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
464 wd->downx = ev->canvas.x - x;
465 wd->downy = ev->canvas.y - y;
468 button_x = ((double)ev->canvas.x - (double)x) / (double)w;
469 if (button_x > 1) button_x = 1;
470 if (button_x < 0) button_x = 0;
474 button_y = ((double)ev->canvas.y - (double)y) / (double)h;
475 if (button_y > 1) button_y = 1;
476 if (button_y < 0) button_y = 0;
478 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
480 evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
482 _indicator_set(data);
483 edje_object_signal_emit(wd->slider, "elm,state,indicator,show", "elm");
487 _spacer_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
489 Widget_Data *wd = elm_widget_data_get(data);
490 Evas_Event_Mouse_Move *ev = event_info;
491 Evas_Coord x, y, w, h;
492 double button_x = 0.0, button_y = 0.0;
498 evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
499 if (wd->horizontal) d = abs(ev->cur.canvas.x - x - wd->downx);
500 else d = abs(ev->cur.canvas.y - y - wd->downy);
501 if (d > (_elm_config->thumbscroll_threshold - 1))
505 elm_widget_scroll_freeze_push(data);
508 ev->event_flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
511 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
513 if (wd->spacer_down) wd->spacer_down = EINA_FALSE;
515 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
517 _indicator_set(data);
520 elm_widget_scroll_freeze_pop(data);
523 edje_object_signal_emit(wd->slider, "elm,state,indicator,hide", "elm");
524 elm_slider_value_set(data, wd->val2);
529 button_x = ((double)ev->cur.canvas.x - (double)x) / (double)w;
530 if (button_x > 1) button_x = 1;
531 if (button_x < 0) button_x = 0;
535 button_y = ((double)ev->cur.canvas.y - (double)y) / (double)h;
536 if (button_y > 1) button_y = 1;
537 if (button_y < 0) button_y = 0;
539 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
542 _indicator_set(data);
547 _spacer_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
549 Widget_Data *wd = elm_widget_data_get(data);
551 if (!wd->spacer_down) return;
552 if (wd->spacer_down) wd->spacer_down = EINA_FALSE;
554 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
556 _indicator_set(data);
559 elm_widget_scroll_freeze_pop(data);
562 edje_object_signal_emit(wd->slider, "elm,state,indicator,hide", "elm");
566 _elm_slider_label_set(Evas_Object *obj, const char *part, const char *label)
568 ELM_CHECK_WIDTYPE(obj, widtype);
569 Widget_Data *wd = elm_widget_data_get(obj);
570 const char* default_part = "elm.text";
571 const char* real_part;
576 real_part = default_part;
582 const char* old_label;
584 old_label = eina_hash_find(wd->labels, real_part);
586 eina_hash_add(wd->labels, real_part, eina_stringshare_add(label));
589 eina_stringshare_ref(old_label);
590 eina_hash_modify(wd->labels, real_part, eina_stringshare_add(label));
591 eina_stringshare_del(old_label);
597 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
598 edje_object_message_signal_process(wd->slider);
602 edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
603 edje_object_message_signal_process(wd->slider);
606 edje_object_part_text_set(wd->slider, real_part, label);
611 _elm_slider_label_get(const Evas_Object *obj, const char *part)
613 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
614 Widget_Data *wd = elm_widget_data_get(obj);
615 if (!wd) return NULL;
616 if (!wd->labels) return NULL;
619 return eina_hash_find(wd->labels, "elm.text");
620 return eina_hash_find(wd->labels, part);
624 _icon_set(Evas_Object *obj, Evas_Object *icon)
626 Widget_Data *wd = elm_widget_data_get(obj);
628 if (wd->icon == icon) return;
629 if (wd->icon) evas_object_del(wd->icon);
633 elm_widget_sub_object_add(obj, icon);
634 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
635 _changed_size_hints, obj);
636 edje_object_part_swallow(wd->slider, "elm.swallow.icon", icon);
637 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
638 edje_object_message_signal_process(wd->slider);
644 _icon_unset(Evas_Object *obj)
646 Widget_Data *wd = elm_widget_data_get(obj);
647 Evas_Object *ret = NULL;
648 if (!wd) return NULL;
651 elm_widget_sub_object_del(obj, wd->icon);
652 evas_object_event_callback_del_full(wd->icon,
653 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
654 _changed_size_hints, obj);
656 edje_object_part_unswallow(wd->slider, wd->icon);
657 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
665 _end_set(Evas_Object *obj, Evas_Object *end)
667 Widget_Data *wd = elm_widget_data_get(obj);
669 if (wd->end == end) return;
670 if (wd->end) evas_object_del(wd->end);
674 elm_widget_sub_object_add(obj, end);
675 evas_object_event_callback_add(end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
676 _changed_size_hints, obj);
677 edje_object_part_swallow(wd->slider, "elm.swallow.end", end);
678 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
679 edje_object_message_signal_process(wd->slider);
685 _end_unset(Evas_Object *obj)
687 Widget_Data *wd = elm_widget_data_get(obj);
688 Evas_Object *ret = NULL;
689 if (!wd) return NULL;
692 elm_widget_sub_object_del(obj, wd->end);
693 evas_object_event_callback_del_full(wd->end,
694 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
695 _changed_size_hints, obj);
697 edje_object_part_unswallow(wd->slider, wd->end);
698 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
706 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
708 ELM_CHECK_WIDTYPE(obj, widtype);
709 if (!part || !strcmp(part, "icon"))
710 _icon_set(obj, content);
711 else if (!strcmp(part, "end"))
712 _end_set(obj, content);
716 _content_get_hook(const Evas_Object *obj, const char *part)
718 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
720 wd = elm_widget_data_get(obj);
721 if (!wd) return NULL;
722 if (!part || !strcmp(part, "icon"))
724 else if (!strcmp(part, "end"))
730 _content_unset_hook(Evas_Object *obj, const char *part)
732 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
733 if (!part || !strcmp(part, "icon"))
734 return _icon_unset(obj);
735 else if (!strcmp(part, "end"))
736 return _end_unset(obj);
741 _hash_labels_free_cb(void* label)
744 eina_stringshare_del(label);
748 elm_slider_add(Evas_Object *parent)
754 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
756 ELM_SET_WIDTYPE(widtype, "slider");
757 elm_widget_type_set(obj, "slider");
758 elm_widget_sub_object_add(parent, obj);
759 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
760 elm_widget_data_set(obj, wd);
761 elm_widget_del_hook_set(obj, _del_hook);
762 elm_widget_theme_hook_set(obj, _theme_hook);
763 elm_widget_disable_hook_set(obj, _disable_hook);
764 elm_widget_can_focus_set(obj, EINA_TRUE);
765 elm_widget_event_hook_set(obj, _event_hook);
766 elm_widget_text_set_hook_set(obj, _elm_slider_label_set);
767 elm_widget_text_get_hook_set(obj, _elm_slider_label_get);
768 elm_widget_content_set_hook_set(obj, _content_set_hook);
769 elm_widget_content_get_hook_set(obj, _content_get_hook);
770 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
772 wd->horizontal = EINA_TRUE;
773 wd->indicator_show = EINA_TRUE;
777 wd->labels = eina_hash_string_superfast_new(_hash_labels_free_cb);
779 wd->slider = edje_object_add(e);
780 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
781 elm_widget_resize_object_set(obj, wd->slider);
782 edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
783 edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
784 edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
785 edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_step, obj);
786 edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
787 // edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
788 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
790 wd->spacer = evas_object_rectangle_add(e);
791 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
792 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
793 elm_widget_sub_object_add(obj, wd->spacer);
794 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
795 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_DOWN, _spacer_down_cb, obj);
796 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_MOVE, _spacer_move_cb, obj);
797 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_UP, _spacer_up_cb, obj);
798 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
800 _mirrored_set(obj, elm_widget_mirrored_get(obj));
803 // TODO: convert Elementary to subclassing of Evas_Smart_Class
804 // TODO: and save some bytes, making descriptions per-class and not instance!
805 evas_object_smart_callbacks_descriptions_set(obj, _signals);
810 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
812 ELM_CHECK_WIDTYPE(obj, widtype);
813 Widget_Data *wd = elm_widget_data_get(obj);
815 if (wd->size == size) return;
818 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
820 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
821 if (wd->indicator_show)
822 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
824 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
825 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
830 elm_slider_span_size_get(const Evas_Object *obj)
832 ELM_CHECK_WIDTYPE(obj, widtype) 0;
833 Widget_Data *wd = elm_widget_data_get(obj);
839 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
841 ELM_CHECK_WIDTYPE(obj, widtype);
842 Widget_Data *wd = elm_widget_data_get(obj);
844 eina_stringshare_replace(&wd->units, units);
847 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
848 edje_object_message_signal_process(wd->slider);
852 edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
853 edje_object_message_signal_process(wd->slider);
860 elm_slider_unit_format_get(const Evas_Object *obj)
862 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
863 Widget_Data *wd = elm_widget_data_get(obj);
864 if (!wd) return NULL;
869 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
871 ELM_CHECK_WIDTYPE(obj, widtype);
872 Widget_Data *wd = elm_widget_data_get(obj);
874 eina_stringshare_replace(&wd->indicator, indicator);
879 elm_slider_indicator_format_get(const Evas_Object *obj)
881 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
882 Widget_Data *wd = elm_widget_data_get(obj);
883 if (!wd) return NULL;
884 return wd->indicator;
888 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
890 ELM_CHECK_WIDTYPE(obj, widtype);
891 Widget_Data *wd = elm_widget_data_get(obj);
893 horizontal = !!horizontal;
894 if (wd->horizontal == horizontal) return;
895 wd->horizontal = horizontal;
900 elm_slider_horizontal_get(const Evas_Object *obj)
902 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
903 Widget_Data *wd = elm_widget_data_get(obj);
904 if (!wd) return EINA_FALSE;
905 return wd->horizontal;
909 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
911 ELM_CHECK_WIDTYPE(obj, widtype);
912 Widget_Data *wd = elm_widget_data_get(obj);
914 if ((wd->val_min == min) && (wd->val_max == max)) return;
917 if (wd->val < wd->val_min) wd->val = wd->val_min;
918 if (wd->val > wd->val_max) wd->val = wd->val_max;
925 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
929 ELM_CHECK_WIDTYPE(obj, widtype);
930 Widget_Data *wd = elm_widget_data_get(obj);
932 if (min) *min = wd->val_min;
933 if (max) *max = wd->val_max;
937 elm_slider_value_set(Evas_Object *obj, double val)
939 ELM_CHECK_WIDTYPE(obj, widtype);
940 Widget_Data *wd = elm_widget_data_get(obj);
942 if (wd->val == val) return;
944 if (wd->val < wd->val_min) wd->val = wd->val_min;
945 if (wd->val > wd->val_max) wd->val = wd->val_max;
952 elm_slider_value_get(const Evas_Object *obj)
954 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
955 Widget_Data *wd = elm_widget_data_get(obj);
961 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
963 ELM_CHECK_WIDTYPE(obj, widtype);
964 Widget_Data *wd = elm_widget_data_get(obj);
966 inverted = !!inverted;
967 if (wd->inverted == inverted) return;
968 wd->inverted = inverted;
970 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
972 edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
973 edje_object_message_signal_process(wd->slider);
980 elm_slider_inverted_get(const Evas_Object *obj)
982 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
983 Widget_Data *wd = elm_widget_data_get(obj);
984 if (!wd) return EINA_FALSE;
989 elm_slider_indicator_format_function_set(Evas_Object *obj, const char *(*func)(double val), void (*free_func)(const char *str))
991 ELM_CHECK_WIDTYPE(obj, widtype);
992 Widget_Data *wd = elm_widget_data_get(obj);
994 wd->indicator_format_func = func;
995 wd->indicator_format_free = free_func;
1000 elm_slider_units_format_function_set(Evas_Object *obj, const char *(*func)(double val), void (*free_func)(const char *str))
1002 ELM_CHECK_WIDTYPE(obj, widtype);
1003 Widget_Data *wd = elm_widget_data_get(obj);
1005 wd->units_format_func = func;
1006 wd->units_format_free = free_func;
1007 _indicator_set(obj);
1011 elm_slider_indicator_show_set(Evas_Object *obj, Eina_Bool show)
1013 ELM_CHECK_WIDTYPE(obj, widtype);
1014 Widget_Data *wd = elm_widget_data_get(obj);
1016 wd->indicator_show = EINA_TRUE;
1017 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
1020 wd->indicator_show = EINA_FALSE;
1021 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
1026 elm_slider_indicator_show_get(const Evas_Object *obj)
1028 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1029 Widget_Data *wd = elm_widget_data_get(obj);
1030 if (!wd) return EINA_FALSE;
1031 return wd->indicator_show;