1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
17 const char *indicator;
19 char *(*indicator_format_func)(double val);
20 void (*indicator_format_free)(char *str);
22 char *(*units_format_func)(double val);
23 void (*units_format_free)(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 _min_max_set(Evas_Object *obj)
750 char *buf_min = NULL;
751 char *buf_max = NULL;
753 Widget_Data *wd = elm_widget_data_get(obj);
755 if (wd->units_format_func)
757 buf_min = wd->units_format_func(wd->val_min);
758 buf_max = wd->units_format_func(wd->val_max);
762 int length = strlen(wd->units);
764 buf_min = alloca(length + 128);
765 buf_max = alloca(length + 128);
767 snprintf((char*) buf_min, length + 128, wd->units, wd->val_min);
768 snprintf((char*) buf_max, length + 128, wd->units, wd->val_max);
771 edje_object_part_text_set(wd->slider, "elm.units.min", buf_min);
772 edje_object_part_text_set(wd->slider, "elm.units.max", buf_max);
774 if (wd->units_format_func && wd->units_format_free)
776 wd->units_format_free(buf_min);
777 wd->units_format_free(buf_max);
783 elm_slider_add(Evas_Object *parent)
789 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
791 ELM_SET_WIDTYPE(widtype, "slider");
792 elm_widget_type_set(obj, "slider");
793 elm_widget_sub_object_add(parent, obj);
794 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
795 elm_widget_data_set(obj, wd);
796 elm_widget_del_hook_set(obj, _del_hook);
797 elm_widget_theme_hook_set(obj, _theme_hook);
798 elm_widget_disable_hook_set(obj, _disable_hook);
799 elm_widget_can_focus_set(obj, EINA_TRUE);
800 elm_widget_event_hook_set(obj, _event_hook);
801 elm_widget_text_set_hook_set(obj, _elm_slider_label_set);
802 elm_widget_text_get_hook_set(obj, _elm_slider_label_get);
803 elm_widget_content_set_hook_set(obj, _content_set_hook);
804 elm_widget_content_get_hook_set(obj, _content_get_hook);
805 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
807 wd->horizontal = EINA_TRUE;
808 wd->indicator_show = EINA_TRUE;
812 wd->labels = eina_hash_string_superfast_new(_hash_labels_free_cb);
814 wd->slider = edje_object_add(e);
815 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
816 elm_widget_resize_object_set(obj, wd->slider);
817 edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
818 edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
819 edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
820 edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_step, obj);
821 edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
822 // edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
823 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
825 wd->spacer = evas_object_rectangle_add(e);
826 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
827 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
828 elm_widget_sub_object_add(obj, wd->spacer);
829 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
830 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_DOWN, _spacer_down_cb, obj);
831 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_MOVE, _spacer_move_cb, obj);
832 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_UP, _spacer_up_cb, obj);
833 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
835 _mirrored_set(obj, elm_widget_mirrored_get(obj));
838 // TODO: convert Elementary to subclassing of Evas_Smart_Class
839 // TODO: and save some bytes, making descriptions per-class and not instance!
840 evas_object_smart_callbacks_descriptions_set(obj, _signals);
845 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
847 ELM_CHECK_WIDTYPE(obj, widtype);
848 Widget_Data *wd = elm_widget_data_get(obj);
850 if (wd->size == size) return;
853 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
855 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
856 if (wd->indicator_show)
857 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
859 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
860 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
865 elm_slider_span_size_get(const Evas_Object *obj)
867 ELM_CHECK_WIDTYPE(obj, widtype) 0;
868 Widget_Data *wd = elm_widget_data_get(obj);
874 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
876 ELM_CHECK_WIDTYPE(obj, widtype);
877 Widget_Data *wd = elm_widget_data_get(obj);
879 eina_stringshare_replace(&wd->units, units);
882 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
883 edje_object_message_signal_process(wd->slider);
887 edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
888 edje_object_message_signal_process(wd->slider);
896 elm_slider_unit_format_get(const Evas_Object *obj)
898 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
899 Widget_Data *wd = elm_widget_data_get(obj);
900 if (!wd) return NULL;
905 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
907 ELM_CHECK_WIDTYPE(obj, widtype);
908 Widget_Data *wd = elm_widget_data_get(obj);
910 eina_stringshare_replace(&wd->indicator, indicator);
915 elm_slider_indicator_format_get(const Evas_Object *obj)
917 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
918 Widget_Data *wd = elm_widget_data_get(obj);
919 if (!wd) return NULL;
920 return wd->indicator;
924 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
926 ELM_CHECK_WIDTYPE(obj, widtype);
927 Widget_Data *wd = elm_widget_data_get(obj);
929 horizontal = !!horizontal;
930 if (wd->horizontal == horizontal) return;
931 wd->horizontal = horizontal;
936 elm_slider_horizontal_get(const Evas_Object *obj)
938 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
939 Widget_Data *wd = elm_widget_data_get(obj);
940 if (!wd) return EINA_FALSE;
941 return wd->horizontal;
945 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
947 ELM_CHECK_WIDTYPE(obj, widtype);
948 Widget_Data *wd = elm_widget_data_get(obj);
950 if ((wd->val_min == min) && (wd->val_max == max)) return;
953 if (wd->val < wd->val_min) wd->val = wd->val_min;
954 if (wd->val > wd->val_max) wd->val = wd->val_max;
962 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
966 ELM_CHECK_WIDTYPE(obj, widtype);
967 Widget_Data *wd = elm_widget_data_get(obj);
969 if (min) *min = wd->val_min;
970 if (max) *max = wd->val_max;
974 elm_slider_value_set(Evas_Object *obj, double val)
976 ELM_CHECK_WIDTYPE(obj, widtype);
977 Widget_Data *wd = elm_widget_data_get(obj);
979 if (wd->val == val) return;
981 if (wd->val < wd->val_min) wd->val = wd->val_min;
982 if (wd->val > wd->val_max) wd->val = wd->val_max;
989 elm_slider_value_get(const Evas_Object *obj)
991 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
992 Widget_Data *wd = elm_widget_data_get(obj);
998 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
1000 ELM_CHECK_WIDTYPE(obj, widtype);
1001 Widget_Data *wd = elm_widget_data_get(obj);
1003 inverted = !!inverted;
1004 if (wd->inverted == inverted) return;
1005 wd->inverted = inverted;
1007 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
1009 edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
1010 edje_object_message_signal_process(wd->slider);
1013 _indicator_set(obj);
1017 elm_slider_inverted_get(const Evas_Object *obj)
1019 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1020 Widget_Data *wd = elm_widget_data_get(obj);
1021 if (!wd) return EINA_FALSE;
1022 return wd->inverted;
1026 elm_slider_indicator_format_function_set(Evas_Object *obj, char *(*func)(double val), void (*free_func)(char *str))
1028 ELM_CHECK_WIDTYPE(obj, widtype);
1029 Widget_Data *wd = elm_widget_data_get(obj);
1031 wd->indicator_format_func = func;
1032 wd->indicator_format_free = free_func;
1033 _indicator_set(obj);
1037 elm_slider_units_format_function_set(Evas_Object *obj, char *(*func)(double val), void (*free_func)(char *str))
1039 ELM_CHECK_WIDTYPE(obj, widtype);
1040 Widget_Data *wd = elm_widget_data_get(obj);
1042 wd->units_format_func = func;
1043 wd->units_format_free = free_func;
1049 elm_slider_indicator_show_set(Evas_Object *obj, Eina_Bool show)
1051 ELM_CHECK_WIDTYPE(obj, widtype);
1052 Widget_Data *wd = elm_widget_data_get(obj);
1054 wd->indicator_show = EINA_TRUE;
1055 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
1058 wd->indicator_show = EINA_FALSE;
1059 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
1064 elm_slider_indicator_show_get(const Evas_Object *obj)
1066 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1067 Widget_Data *wd = elm_widget_data_get(obj);
1068 if (!wd) return EINA_FALSE;
1069 return wd->indicator_show;