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")) && (!ev->string)))
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")) && (!ev->string)))
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")) ||
117 ((!strcmp(ev->keyname, "KP_Up")) && (!ev->string)))
119 if (wd->horizontal) return EINA_FALSE;
120 if (wd->inverted) _drag_up(obj, NULL, NULL, NULL);
121 else _drag_down(obj, NULL, NULL, NULL);
122 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
125 else if ((!strcmp(ev->keyname, "Down")) ||
126 ((!strcmp(ev->keyname, "KP_Down")) && (!ev->string)))
128 if (wd->horizontal) return EINA_FALSE;
129 if (wd->inverted) _drag_down(obj, NULL, NULL, NULL);
130 else _drag_up(obj, NULL, NULL, NULL);
131 ev->event_flags |= EVAS_EVENT_FLAG_ON_HOLD;
134 else return EINA_FALSE;
138 _del_hook(Evas_Object *obj)
140 Widget_Data *wd = elm_widget_data_get(obj);
142 if (wd->labels) eina_hash_free(wd->labels);
143 if (wd->indicator) eina_stringshare_del(wd->units);
144 if (wd->delay) ecore_timer_del(wd->delay);
149 _on_focus_hook(void *data __UNUSED__, Evas_Object *obj)
151 Widget_Data *wd = elm_widget_data_get(obj);
153 if (elm_widget_focus_get(obj))
155 edje_object_signal_emit(wd->slider, "elm,action,focus", "elm");
156 evas_object_focus_set(wd->slider, EINA_TRUE);
160 edje_object_signal_emit(wd->slider, "elm,action,unfocus", "elm");
161 evas_object_focus_set(wd->slider, EINA_FALSE);
166 _mirrored_set(Evas_Object *obj, Eina_Bool rtl)
168 Widget_Data *wd = elm_widget_data_get(obj);
170 edje_object_mirrored_set(wd->slider, rtl);
174 _labels_foreach_text_set(const Eina_Hash *hash __UNUSED__, const void *key, void *data, void *fdata)
176 Widget_Data *wd = fdata;
178 edje_object_part_text_set(wd->slider, key, data);
184 _theme_hook(Evas_Object *obj)
186 Widget_Data *wd = elm_widget_data_get(obj);
188 _elm_widget_mirrored_reload(obj);
189 _mirrored_set(obj, elm_widget_mirrored_get(obj));
191 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", elm_widget_style_get(obj));
193 _elm_theme_object_set(obj, wd->slider, "slider", "vertical", elm_widget_style_get(obj));
196 edje_object_part_swallow(wd->slider, "elm.swallow.content", wd->icon);
197 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
200 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
202 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
205 eina_hash_foreach(wd->labels, _labels_foreach_text_set, wd);
206 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
210 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
213 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
215 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
218 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
220 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
223 edje_object_message_signal_process(wd->slider);
224 edje_object_scale_set(wd->slider, elm_widget_scale_get(obj) * _elm_config->scale);
230 _disable_hook(Evas_Object *obj)
232 Widget_Data *wd = elm_widget_data_get(obj);
234 if (elm_widget_disabled_get(obj))
235 edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
237 edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
241 _sizing_eval(Evas_Object *obj)
243 Widget_Data *wd = elm_widget_data_get(obj);
244 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
246 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
247 edje_object_size_min_restricted_calc(wd->slider, &minw, &minh, minw, minh);
248 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
249 evas_object_size_hint_min_set(obj, minw, minh);
250 evas_object_size_hint_max_set(obj, maxw, maxh);
254 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
256 Widget_Data *wd = elm_widget_data_get(data);
258 if ((obj != wd->icon) && (obj != wd->end)) return;
263 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
265 Widget_Data *wd = elm_widget_data_get(obj);
266 Evas_Object *sub = event_info;
270 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
271 evas_object_event_callback_del_full
272 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
274 edje_object_message_signal_process(wd->slider);
279 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
280 evas_object_event_callback_del_full(sub,
281 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
282 _changed_size_hints, obj);
284 edje_object_message_signal_process(wd->slider);
290 _delay_change(void *data)
292 Widget_Data *wd = elm_widget_data_get(data);
293 if (!wd) return ECORE_CALLBACK_CANCEL;
295 evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, NULL);
296 return ECORE_CALLBACK_CANCEL;
300 _val_fetch(Evas_Object *obj)
303 Widget_Data *wd = elm_widget_data_get(obj);
304 double posx = 0.0, posy = 0.0, pos = 0.0, val;
306 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider",
308 if (wd->horizontal) pos = posx;
311 rtl = elm_widget_mirrored_get(obj);
312 if ((!rtl && wd->inverted) || (rtl &&
313 ((!wd->horizontal && wd->inverted) ||
314 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
315 val = (pos * (wd->val_max - wd->val_min)) + wd->val_min;
319 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
320 if (wd->delay) ecore_timer_del(wd->delay);
321 wd->delay = ecore_timer_add(0.2, _delay_change, obj);
326 _val_set(Evas_Object *obj)
329 Widget_Data *wd = elm_widget_data_get(obj);
332 if (wd->val_max > wd->val_min)
333 pos = (wd->val - wd->val_min) / (wd->val_max - wd->val_min);
336 if (pos < 0.0) pos = 0.0;
337 else if (pos > 1.0) pos = 1.0;
339 rtl = elm_widget_mirrored_get(obj);
340 if ((!rtl && wd->inverted) || (rtl &&
341 ((!wd->horizontal && wd->inverted) ||
342 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
343 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", pos, pos);
347 _units_set(Evas_Object *obj)
349 Widget_Data *wd = elm_widget_data_get(obj);
351 if (wd->units_format_func)
354 buf = wd->units_format_func(wd->val);
355 edje_object_part_text_set(wd->slider, "elm.units", buf);
356 if (wd->units_format_free) wd->units_format_free(buf);
362 snprintf(buf, sizeof(buf), wd->units, wd->val);
363 edje_object_part_text_set(wd->slider, "elm.units", buf);
366 edje_object_part_text_set(wd->slider, "elm.units", NULL);
370 _indicator_set(Evas_Object *obj)
372 Widget_Data *wd = elm_widget_data_get(obj);
374 if (wd->indicator_format_func)
377 buf = wd->indicator_format_func(wd->val);
378 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
379 if (wd->indicator_format_free) wd->indicator_format_free(buf);
381 else if (wd->indicator)
384 snprintf(buf, sizeof(buf), wd->indicator, wd->val);
385 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
388 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", NULL);
392 _drag(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
396 _indicator_set(data);
400 _drag_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
403 evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
405 _indicator_set(data);
406 elm_widget_scroll_freeze_push(data);
410 _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
413 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
415 _indicator_set(data);
416 elm_widget_scroll_freeze_pop(data);
420 _drag_step(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
424 _indicator_set(data);
428 _drag_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
433 wd = elm_widget_data_get(data);
436 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
438 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
442 _drag_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
447 wd = elm_widget_data_get(data);
450 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
452 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
456 _spacer_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
458 Widget_Data *wd = elm_widget_data_get(data);
459 Evas_Event_Mouse_Down *ev = event_info;
460 Evas_Coord x, y, w, h;
461 double button_x = 0.0, button_y = 0.0;
463 wd->spacer_down = EINA_TRUE;
465 evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
466 wd->downx = ev->canvas.x - x;
467 wd->downy = ev->canvas.y - y;
470 button_x = ((double)ev->canvas.x - (double)x) / (double)w;
471 if (button_x > 1) button_x = 1;
472 if (button_x < 0) button_x = 0;
476 button_y = ((double)ev->canvas.y - (double)y) / (double)h;
477 if (button_y > 1) button_y = 1;
478 if (button_y < 0) button_y = 0;
480 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
482 evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
484 _indicator_set(data);
485 edje_object_signal_emit(wd->slider, "elm,state,indicator,show", "elm");
489 _spacer_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
491 Widget_Data *wd = elm_widget_data_get(data);
492 Evas_Event_Mouse_Move *ev = event_info;
493 Evas_Coord x, y, w, h;
494 double button_x = 0.0, button_y = 0.0;
500 evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
501 if (wd->horizontal) d = abs(ev->cur.canvas.x - x - wd->downx);
502 else d = abs(ev->cur.canvas.y - y - wd->downy);
503 if (d > (_elm_config->thumbscroll_threshold - 1))
507 elm_widget_scroll_freeze_push(data);
510 ev->event_flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
513 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
515 if (wd->spacer_down) wd->spacer_down = EINA_FALSE;
517 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
519 _indicator_set(data);
522 elm_widget_scroll_freeze_pop(data);
525 edje_object_signal_emit(wd->slider, "elm,state,indicator,hide", "elm");
526 elm_slider_value_set(data, wd->val2);
531 button_x = ((double)ev->cur.canvas.x - (double)x) / (double)w;
532 if (button_x > 1) button_x = 1;
533 if (button_x < 0) button_x = 0;
537 button_y = ((double)ev->cur.canvas.y - (double)y) / (double)h;
538 if (button_y > 1) button_y = 1;
539 if (button_y < 0) button_y = 0;
541 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
544 _indicator_set(data);
549 _spacer_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
551 Widget_Data *wd = elm_widget_data_get(data);
553 if (!wd->spacer_down) return;
554 if (wd->spacer_down) wd->spacer_down = EINA_FALSE;
556 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
558 _indicator_set(data);
561 elm_widget_scroll_freeze_pop(data);
564 edje_object_signal_emit(wd->slider, "elm,state,indicator,hide", "elm");
568 _elm_slider_label_set(Evas_Object *obj, const char *part, const char *label)
570 ELM_CHECK_WIDTYPE(obj, widtype);
571 Widget_Data *wd = elm_widget_data_get(obj);
572 const char* default_part = "elm.text";
573 const char* real_part;
578 real_part = default_part;
584 const char* old_label;
586 old_label = eina_hash_find(wd->labels, real_part);
588 eina_hash_add(wd->labels, real_part, eina_stringshare_add(label));
591 eina_stringshare_ref(old_label);
592 eina_hash_modify(wd->labels, real_part, eina_stringshare_add(label));
593 eina_stringshare_del(old_label);
599 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
600 edje_object_message_signal_process(wd->slider);
604 edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
605 edje_object_message_signal_process(wd->slider);
608 edje_object_part_text_set(wd->slider, real_part, label);
613 _elm_slider_label_get(const Evas_Object *obj, const char *part)
615 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
616 Widget_Data *wd = elm_widget_data_get(obj);
617 if (!wd) return NULL;
618 if (!wd->labels) return NULL;
621 return eina_hash_find(wd->labels, "elm.text");
622 return eina_hash_find(wd->labels, part);
626 _icon_set(Evas_Object *obj, Evas_Object *icon)
628 Widget_Data *wd = elm_widget_data_get(obj);
630 if (wd->icon == icon) return;
631 if (wd->icon) evas_object_del(wd->icon);
635 elm_widget_sub_object_add(obj, icon);
636 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
637 _changed_size_hints, obj);
638 edje_object_part_swallow(wd->slider, "elm.swallow.icon", icon);
639 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
640 edje_object_message_signal_process(wd->slider);
646 _icon_unset(Evas_Object *obj)
648 Widget_Data *wd = elm_widget_data_get(obj);
649 Evas_Object *ret = NULL;
650 if (!wd) return NULL;
653 elm_widget_sub_object_del(obj, wd->icon);
654 evas_object_event_callback_del_full(wd->icon,
655 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
656 _changed_size_hints, obj);
658 edje_object_part_unswallow(wd->slider, wd->icon);
659 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
667 _end_set(Evas_Object *obj, Evas_Object *end)
669 Widget_Data *wd = elm_widget_data_get(obj);
671 if (wd->end == end) return;
672 if (wd->end) evas_object_del(wd->end);
676 elm_widget_sub_object_add(obj, end);
677 evas_object_event_callback_add(end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
678 _changed_size_hints, obj);
679 edje_object_part_swallow(wd->slider, "elm.swallow.end", end);
680 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
681 edje_object_message_signal_process(wd->slider);
687 _end_unset(Evas_Object *obj)
689 Widget_Data *wd = elm_widget_data_get(obj);
690 Evas_Object *ret = NULL;
691 if (!wd) return NULL;
694 elm_widget_sub_object_del(obj, wd->end);
695 evas_object_event_callback_del_full(wd->end,
696 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
697 _changed_size_hints, obj);
699 edje_object_part_unswallow(wd->slider, wd->end);
700 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
708 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
710 ELM_CHECK_WIDTYPE(obj, widtype);
711 if (!part || !strcmp(part, "icon"))
712 _icon_set(obj, content);
713 else if (!strcmp(part, "end"))
714 _end_set(obj, content);
718 _content_get_hook(const Evas_Object *obj, const char *part)
720 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
722 wd = elm_widget_data_get(obj);
723 if (!wd) return NULL;
724 if (!part || !strcmp(part, "icon"))
726 else if (!strcmp(part, "end"))
732 _content_unset_hook(Evas_Object *obj, const char *part)
734 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
735 if (!part || !strcmp(part, "icon"))
736 return _icon_unset(obj);
737 else if (!strcmp(part, "end"))
738 return _end_unset(obj);
743 _hash_labels_free_cb(void* label)
746 eina_stringshare_del(label);
750 _min_max_set(Evas_Object *obj)
752 char *buf_min = NULL;
753 char *buf_max = NULL;
755 Widget_Data *wd = elm_widget_data_get(obj);
757 if (wd->units_format_func)
759 buf_min = wd->units_format_func(wd->val_min);
760 buf_max = wd->units_format_func(wd->val_max);
764 int length = strlen(wd->units);
766 buf_min = alloca(length + 128);
767 buf_max = alloca(length + 128);
769 snprintf((char*) buf_min, length + 128, wd->units, wd->val_min);
770 snprintf((char*) buf_max, length + 128, wd->units, wd->val_max);
773 edje_object_part_text_set(wd->slider, "elm.units.min", buf_min);
774 edje_object_part_text_set(wd->slider, "elm.units.max", buf_max);
776 if (wd->units_format_func && wd->units_format_free)
778 wd->units_format_free(buf_min);
779 wd->units_format_free(buf_max);
785 elm_slider_add(Evas_Object *parent)
791 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
793 ELM_SET_WIDTYPE(widtype, "slider");
794 elm_widget_type_set(obj, "slider");
795 elm_widget_sub_object_add(parent, obj);
796 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
797 elm_widget_data_set(obj, wd);
798 elm_widget_del_hook_set(obj, _del_hook);
799 elm_widget_theme_hook_set(obj, _theme_hook);
800 elm_widget_disable_hook_set(obj, _disable_hook);
801 elm_widget_can_focus_set(obj, EINA_TRUE);
802 elm_widget_event_hook_set(obj, _event_hook);
803 elm_widget_text_set_hook_set(obj, _elm_slider_label_set);
804 elm_widget_text_get_hook_set(obj, _elm_slider_label_get);
805 elm_widget_content_set_hook_set(obj, _content_set_hook);
806 elm_widget_content_get_hook_set(obj, _content_get_hook);
807 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
809 wd->horizontal = EINA_TRUE;
810 wd->indicator_show = EINA_TRUE;
814 wd->labels = eina_hash_string_superfast_new(_hash_labels_free_cb);
816 wd->slider = edje_object_add(e);
817 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
818 elm_widget_resize_object_set(obj, wd->slider);
819 edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
820 edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
821 edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
822 edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_step, obj);
823 edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
824 // edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
825 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
827 wd->spacer = evas_object_rectangle_add(e);
828 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
829 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
830 elm_widget_sub_object_add(obj, wd->spacer);
831 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
832 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_DOWN, _spacer_down_cb, obj);
833 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_MOVE, _spacer_move_cb, obj);
834 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_UP, _spacer_up_cb, obj);
835 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
837 _mirrored_set(obj, elm_widget_mirrored_get(obj));
840 // TODO: convert Elementary to subclassing of Evas_Smart_Class
841 // TODO: and save some bytes, making descriptions per-class and not instance!
842 evas_object_smart_callbacks_descriptions_set(obj, _signals);
847 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
849 ELM_CHECK_WIDTYPE(obj, widtype);
850 Widget_Data *wd = elm_widget_data_get(obj);
852 if (wd->size == size) return;
855 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
857 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
858 if (wd->indicator_show)
859 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
861 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
862 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
867 elm_slider_span_size_get(const Evas_Object *obj)
869 ELM_CHECK_WIDTYPE(obj, widtype) 0;
870 Widget_Data *wd = elm_widget_data_get(obj);
876 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
878 ELM_CHECK_WIDTYPE(obj, widtype);
879 Widget_Data *wd = elm_widget_data_get(obj);
881 eina_stringshare_replace(&wd->units, units);
884 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
885 edje_object_message_signal_process(wd->slider);
889 edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
890 edje_object_message_signal_process(wd->slider);
898 elm_slider_unit_format_get(const Evas_Object *obj)
900 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
901 Widget_Data *wd = elm_widget_data_get(obj);
902 if (!wd) return NULL;
907 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
909 ELM_CHECK_WIDTYPE(obj, widtype);
910 Widget_Data *wd = elm_widget_data_get(obj);
912 eina_stringshare_replace(&wd->indicator, indicator);
917 elm_slider_indicator_format_get(const Evas_Object *obj)
919 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
920 Widget_Data *wd = elm_widget_data_get(obj);
921 if (!wd) return NULL;
922 return wd->indicator;
926 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
928 ELM_CHECK_WIDTYPE(obj, widtype);
929 Widget_Data *wd = elm_widget_data_get(obj);
931 horizontal = !!horizontal;
932 if (wd->horizontal == horizontal) return;
933 wd->horizontal = horizontal;
938 elm_slider_horizontal_get(const Evas_Object *obj)
940 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
941 Widget_Data *wd = elm_widget_data_get(obj);
942 if (!wd) return EINA_FALSE;
943 return wd->horizontal;
947 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
949 ELM_CHECK_WIDTYPE(obj, widtype);
950 Widget_Data *wd = elm_widget_data_get(obj);
952 if ((wd->val_min == min) && (wd->val_max == max)) return;
955 if (wd->val < wd->val_min) wd->val = wd->val_min;
956 if (wd->val > wd->val_max) wd->val = wd->val_max;
964 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
968 ELM_CHECK_WIDTYPE(obj, widtype);
969 Widget_Data *wd = elm_widget_data_get(obj);
971 if (min) *min = wd->val_min;
972 if (max) *max = wd->val_max;
976 elm_slider_value_set(Evas_Object *obj, double val)
978 ELM_CHECK_WIDTYPE(obj, widtype);
979 Widget_Data *wd = elm_widget_data_get(obj);
981 if (wd->val == val) return;
983 if (wd->val < wd->val_min) wd->val = wd->val_min;
984 if (wd->val > wd->val_max) wd->val = wd->val_max;
991 elm_slider_value_get(const Evas_Object *obj)
993 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
994 Widget_Data *wd = elm_widget_data_get(obj);
1000 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
1002 ELM_CHECK_WIDTYPE(obj, widtype);
1003 Widget_Data *wd = elm_widget_data_get(obj);
1005 inverted = !!inverted;
1006 if (wd->inverted == inverted) return;
1007 wd->inverted = inverted;
1009 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
1011 edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
1012 edje_object_message_signal_process(wd->slider);
1015 _indicator_set(obj);
1019 elm_slider_inverted_get(const Evas_Object *obj)
1021 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1022 Widget_Data *wd = elm_widget_data_get(obj);
1023 if (!wd) return EINA_FALSE;
1024 return wd->inverted;
1028 elm_slider_indicator_format_function_set(Evas_Object *obj, char *(*func)(double val), void (*free_func)(char *str))
1030 ELM_CHECK_WIDTYPE(obj, widtype);
1031 Widget_Data *wd = elm_widget_data_get(obj);
1033 wd->indicator_format_func = func;
1034 wd->indicator_format_free = free_func;
1035 _indicator_set(obj);
1039 elm_slider_units_format_function_set(Evas_Object *obj, char *(*func)(double val), void (*free_func)(char *str))
1041 ELM_CHECK_WIDTYPE(obj, widtype);
1042 Widget_Data *wd = elm_widget_data_get(obj);
1044 wd->units_format_func = func;
1045 wd->units_format_free = free_func;
1051 elm_slider_indicator_show_set(Evas_Object *obj, Eina_Bool show)
1053 ELM_CHECK_WIDTYPE(obj, widtype);
1054 Widget_Data *wd = elm_widget_data_get(obj);
1056 wd->indicator_show = EINA_TRUE;
1057 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
1060 wd->indicator_show = EINA_FALSE;
1061 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
1066 elm_slider_indicator_show_get(const Evas_Object *obj)
1068 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1069 Widget_Data *wd = elm_widget_data_get(obj);
1070 if (!wd) return EINA_FALSE;
1071 return wd->indicator_show;