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));
194 if (elm_widget_disabled_get(obj))
195 edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
197 edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
200 edje_object_part_swallow(wd->slider, "elm.swallow.content", wd->icon);
201 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
204 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
206 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
209 eina_hash_foreach(wd->labels, _labels_foreach_text_set, wd);
210 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
214 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
217 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
219 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
222 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
224 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
227 edje_object_message_signal_process(wd->slider);
228 edje_object_scale_set(wd->slider, elm_widget_scale_get(obj) * _elm_config->scale);
234 _disable_hook(Evas_Object *obj)
236 Widget_Data *wd = elm_widget_data_get(obj);
238 if (elm_widget_disabled_get(obj))
239 edje_object_signal_emit(wd->slider, "elm,state,disabled", "elm");
241 edje_object_signal_emit(wd->slider, "elm,state,enabled", "elm");
245 _sizing_eval(Evas_Object *obj)
247 Widget_Data *wd = elm_widget_data_get(obj);
248 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
250 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
251 edje_object_size_min_restricted_calc(wd->slider, &minw, &minh, minw, minh);
252 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
253 evas_object_size_hint_min_set(obj, minw, minh);
254 evas_object_size_hint_max_set(obj, maxw, maxh);
258 _changed_size_hints(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
260 Widget_Data *wd = elm_widget_data_get(data);
262 if ((obj != wd->icon) && (obj != wd->end)) return;
267 _sub_del(void *data __UNUSED__, Evas_Object *obj, void *event_info)
269 Widget_Data *wd = elm_widget_data_get(obj);
270 Evas_Object *sub = event_info;
274 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
275 evas_object_event_callback_del_full
276 (sub, EVAS_CALLBACK_CHANGED_SIZE_HINTS, _changed_size_hints, obj);
278 edje_object_message_signal_process(wd->slider);
283 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
284 evas_object_event_callback_del_full(sub,
285 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
286 _changed_size_hints, obj);
288 edje_object_message_signal_process(wd->slider);
294 _delay_change(void *data)
296 Widget_Data *wd = elm_widget_data_get(data);
297 if (!wd) return ECORE_CALLBACK_CANCEL;
299 evas_object_smart_callback_call(data, SIG_DELAY_CHANGED, NULL);
300 return ECORE_CALLBACK_CANCEL;
304 _val_fetch(Evas_Object *obj)
307 Widget_Data *wd = elm_widget_data_get(obj);
308 double posx = 0.0, posy = 0.0, pos = 0.0, val;
310 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider",
312 if (wd->horizontal) pos = posx;
315 rtl = elm_widget_mirrored_get(obj);
316 if ((!rtl && wd->inverted) || (rtl &&
317 ((!wd->horizontal && wd->inverted) ||
318 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
319 val = (pos * (wd->val_max - wd->val_min)) + wd->val_min;
323 evas_object_smart_callback_call(obj, SIG_CHANGED, NULL);
324 if (wd->delay) ecore_timer_del(wd->delay);
325 wd->delay = ecore_timer_add(0.2, _delay_change, obj);
330 _val_set(Evas_Object *obj)
333 Widget_Data *wd = elm_widget_data_get(obj);
336 if (wd->val_max > wd->val_min)
337 pos = (wd->val - wd->val_min) / (wd->val_max - wd->val_min);
340 if (pos < 0.0) pos = 0.0;
341 else if (pos > 1.0) pos = 1.0;
343 rtl = elm_widget_mirrored_get(obj);
344 if ((!rtl && wd->inverted) || (rtl &&
345 ((!wd->horizontal && wd->inverted) ||
346 (wd->horizontal && !wd->inverted)))) pos = 1.0 - pos;
347 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", pos, pos);
351 _units_set(Evas_Object *obj)
353 Widget_Data *wd = elm_widget_data_get(obj);
355 if (wd->units_format_func)
358 buf = wd->units_format_func(wd->val);
359 edje_object_part_text_set(wd->slider, "elm.units", buf);
360 if (wd->units_format_free) wd->units_format_free(buf);
366 snprintf(buf, sizeof(buf), wd->units, wd->val);
367 edje_object_part_text_set(wd->slider, "elm.units", buf);
370 edje_object_part_text_set(wd->slider, "elm.units", NULL);
374 _indicator_set(Evas_Object *obj)
376 Widget_Data *wd = elm_widget_data_get(obj);
378 if (wd->indicator_format_func)
381 buf = wd->indicator_format_func(wd->val);
382 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
383 if (wd->indicator_format_free) wd->indicator_format_free(buf);
385 else if (wd->indicator)
388 snprintf(buf, sizeof(buf), wd->indicator, wd->val);
389 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", buf);
392 edje_object_part_text_set(wd->slider, "elm.dragable.slider:elm.indicator", NULL);
396 _drag(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
398 Widget_Data *wd = elm_widget_data_get((Evas_Object*)data);
399 if (elm_widget_disabled_get(data)) return;
402 _indicator_set(data);
403 edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
404 edje_object_message_signal_process(wd->slider);
408 _drag_start(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
410 Widget_Data *wd = elm_widget_data_get((Evas_Object*)data);
411 if (elm_widget_disabled_get(data)) return;
413 evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
415 _indicator_set(data);
416 elm_widget_scroll_freeze_push(data);
417 edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
418 edje_object_message_signal_process(wd->slider);
422 _drag_stop(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
424 if (elm_widget_disabled_get(data)) return;
426 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
428 _indicator_set(data);
429 elm_widget_scroll_freeze_pop(data);
433 _drag_step(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
435 if (elm_widget_disabled_get(data)) return;
438 _indicator_set(data);
442 _drag_up(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
446 if (elm_widget_disabled_get(data)) return;
448 wd = elm_widget_data_get(data);
451 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
453 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
457 _drag_down(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
461 if (elm_widget_disabled_get(data)) return;
463 wd = elm_widget_data_get(data);
466 if (wd->inverted) step *= ELM_SLIDER_INVERTED_FACTOR;
468 edje_object_part_drag_step(wd->slider, "elm.dragable.slider", step, step);
472 _spacer_down_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
474 Widget_Data *wd = elm_widget_data_get(data);
475 Evas_Event_Mouse_Down *ev = event_info;
476 Evas_Coord x, y, w, h;
477 double button_x = 0.0, button_y = 0.0;
478 if (elm_widget_disabled_get(data)) return;
480 wd->spacer_down = EINA_TRUE;
482 evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
483 wd->downx = ev->canvas.x - x;
484 wd->downy = ev->canvas.y - y;
485 edje_object_part_drag_value_get(wd->slider, "elm.dragable.slider", &button_x, &button_y);
488 button_x = ((double)ev->canvas.x - (double)x) / (double)w;
489 if (button_x > 1) button_x = 1;
490 if (button_x < 0) button_x = 0;
494 button_y = ((double)ev->canvas.y - (double)y) / (double)h;
495 if (button_y > 1) button_y = 1;
496 if (button_y < 0) button_y = 0;
498 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
500 evas_object_smart_callback_call(data, SIG_DRAG_START, NULL);
502 _indicator_set(data);
503 edje_object_signal_emit(wd->slider, "elm,state,indicator,show", "elm");
504 edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
505 edje_object_message_signal_process(wd->slider);
509 _spacer_move_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
511 Widget_Data *wd = elm_widget_data_get(data);
512 Evas_Event_Mouse_Move *ev = event_info;
513 Evas_Coord x, y, w, h;
514 double button_x = 0.0, button_y = 0.0;
515 if (elm_widget_disabled_get(data)) return;
521 evas_object_geometry_get(wd->spacer, &x, &y, &w, &h);
522 if (wd->horizontal) d = abs(ev->cur.canvas.x - x - wd->downx);
523 else d = abs(ev->cur.canvas.y - y - wd->downy);
524 if (d > (_elm_config->thumbscroll_threshold - 1))
528 elm_widget_scroll_freeze_push(data);
529 wd->frozen = EINA_TRUE;
531 ev->event_flags &= ~EVAS_EVENT_FLAG_ON_HOLD;
534 if (ev->event_flags & EVAS_EVENT_FLAG_ON_HOLD)
536 if (wd->spacer_down) wd->spacer_down = EINA_FALSE;
538 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
540 _indicator_set(data);
543 elm_widget_scroll_freeze_pop(data);
544 wd->frozen = EINA_FALSE;
546 edje_object_signal_emit(wd->slider, "elm,state,indicator,hide", "elm");
547 elm_slider_value_set(data, wd->val2);
552 button_x = ((double)ev->cur.canvas.x - (double)x) / (double)w;
553 if (button_x > 1) button_x = 1;
554 if (button_x < 0) button_x = 0;
558 button_y = ((double)ev->cur.canvas.y - (double)y) / (double)h;
559 if (button_y > 1) button_y = 1;
560 if (button_y < 0) button_y = 0;
562 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", button_x, button_y);
565 _indicator_set(data);
566 edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
567 edje_object_message_signal_process(wd->slider);
572 _spacer_up_cb(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
574 Widget_Data *wd = elm_widget_data_get(data);
575 if (elm_widget_disabled_get(data)) return;
576 if (!wd->spacer_down) return;
578 wd->spacer_down = EINA_FALSE;
580 evas_object_smart_callback_call(data, SIG_DRAG_STOP, NULL);
582 _indicator_set(data);
585 elm_widget_scroll_freeze_pop(data);
586 wd->frozen = EINA_FALSE;
588 edje_object_signal_emit(wd->slider, "elm,state,indicator,hide", "elm");
592 _elm_slider_label_set(Evas_Object *obj, const char *part, const char *label)
594 ELM_CHECK_WIDTYPE(obj, widtype);
595 Widget_Data *wd = elm_widget_data_get(obj);
596 const char* default_part = "elm.text";
597 const char* real_part;
602 real_part = default_part;
608 const char* old_label;
610 old_label = eina_hash_find(wd->labels, real_part);
612 eina_hash_add(wd->labels, real_part, eina_stringshare_add(label));
615 eina_stringshare_ref(old_label);
616 eina_hash_modify(wd->labels, real_part, eina_stringshare_add(label));
617 eina_stringshare_del(old_label);
623 edje_object_signal_emit(wd->slider, "elm,state,text,visible", "elm");
624 edje_object_message_signal_process(wd->slider);
628 edje_object_signal_emit(wd->slider, "elm,state,text,hidden", "elm");
629 edje_object_message_signal_process(wd->slider);
632 edje_object_part_text_set(wd->slider, real_part, label);
637 _elm_slider_label_get(const Evas_Object *obj, const char *part)
639 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
640 Widget_Data *wd = elm_widget_data_get(obj);
641 if (!wd) return NULL;
642 if (!wd->labels) return NULL;
645 return eina_hash_find(wd->labels, "elm.text");
646 return eina_hash_find(wd->labels, part);
650 _icon_set(Evas_Object *obj, Evas_Object *icon)
652 Widget_Data *wd = elm_widget_data_get(obj);
654 if (wd->icon == icon) return;
655 if (wd->icon) evas_object_del(wd->icon);
659 elm_widget_sub_object_add(obj, icon);
660 evas_object_event_callback_add(icon, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
661 _changed_size_hints, obj);
662 edje_object_part_swallow(wd->slider, "elm.swallow.icon", icon);
663 edje_object_signal_emit(wd->slider, "elm,state,icon,visible", "elm");
664 edje_object_message_signal_process(wd->slider);
670 _icon_unset(Evas_Object *obj)
672 Widget_Data *wd = elm_widget_data_get(obj);
673 Evas_Object *ret = NULL;
674 if (!wd) return NULL;
677 elm_widget_sub_object_del(obj, wd->icon);
678 evas_object_event_callback_del_full(wd->icon,
679 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
680 _changed_size_hints, obj);
682 edje_object_part_unswallow(wd->slider, wd->icon);
683 edje_object_signal_emit(wd->slider, "elm,state,icon,hidden", "elm");
691 _end_set(Evas_Object *obj, Evas_Object *end)
693 Widget_Data *wd = elm_widget_data_get(obj);
695 if (wd->end == end) return;
696 if (wd->end) evas_object_del(wd->end);
700 elm_widget_sub_object_add(obj, end);
701 evas_object_event_callback_add(end, EVAS_CALLBACK_CHANGED_SIZE_HINTS,
702 _changed_size_hints, obj);
703 edje_object_part_swallow(wd->slider, "elm.swallow.end", end);
704 edje_object_signal_emit(wd->slider, "elm,state,end,visible", "elm");
705 edje_object_message_signal_process(wd->slider);
711 _end_unset(Evas_Object *obj)
713 Widget_Data *wd = elm_widget_data_get(obj);
714 Evas_Object *ret = NULL;
715 if (!wd) return NULL;
718 elm_widget_sub_object_del(obj, wd->end);
719 evas_object_event_callback_del_full(wd->end,
720 EVAS_CALLBACK_CHANGED_SIZE_HINTS,
721 _changed_size_hints, obj);
723 edje_object_part_unswallow(wd->slider, wd->end);
724 edje_object_signal_emit(wd->slider, "elm,state,end,hidden", "elm");
732 _content_set_hook(Evas_Object *obj, const char *part, Evas_Object *content)
734 ELM_CHECK_WIDTYPE(obj, widtype);
735 if (!part || !strcmp(part, "icon"))
736 _icon_set(obj, content);
737 else if (!strcmp(part, "end"))
738 _end_set(obj, content);
742 _content_get_hook(const Evas_Object *obj, const char *part)
744 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
746 wd = elm_widget_data_get(obj);
747 if (!wd) return NULL;
748 if (!part || !strcmp(part, "icon"))
750 else if (!strcmp(part, "end"))
756 _content_unset_hook(Evas_Object *obj, const char *part)
758 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
759 if (!part || !strcmp(part, "icon"))
760 return _icon_unset(obj);
761 else if (!strcmp(part, "end"))
762 return _end_unset(obj);
767 _hash_labels_free_cb(void* label)
770 eina_stringshare_del(label);
774 _min_max_set(Evas_Object *obj)
776 char *buf_min = NULL;
777 char *buf_max = NULL;
779 Widget_Data *wd = elm_widget_data_get(obj);
781 if (wd->units_format_func)
783 buf_min = wd->units_format_func(wd->val_min);
784 buf_max = wd->units_format_func(wd->val_max);
788 int length = strlen(wd->units);
790 buf_min = alloca(length + 128);
791 buf_max = alloca(length + 128);
793 snprintf((char*) buf_min, length + 128, wd->units, wd->val_min);
794 snprintf((char*) buf_max, length + 128, wd->units, wd->val_max);
797 edje_object_part_text_set(wd->slider, "elm.units.min", buf_min);
798 edje_object_part_text_set(wd->slider, "elm.units.max", buf_max);
800 if (wd->units_format_func && wd->units_format_free)
802 wd->units_format_free(buf_min);
803 wd->units_format_free(buf_max);
809 elm_slider_add(Evas_Object *parent)
815 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
817 ELM_SET_WIDTYPE(widtype, "slider");
818 elm_widget_type_set(obj, "slider");
819 elm_widget_sub_object_add(parent, obj);
820 elm_widget_on_focus_hook_set(obj, _on_focus_hook, NULL);
821 elm_widget_data_set(obj, wd);
822 elm_widget_del_hook_set(obj, _del_hook);
823 elm_widget_theme_hook_set(obj, _theme_hook);
824 elm_widget_disable_hook_set(obj, _disable_hook);
825 elm_widget_can_focus_set(obj, EINA_TRUE);
826 elm_widget_event_hook_set(obj, _event_hook);
827 elm_widget_text_set_hook_set(obj, _elm_slider_label_set);
828 elm_widget_text_get_hook_set(obj, _elm_slider_label_get);
829 elm_widget_content_set_hook_set(obj, _content_set_hook);
830 elm_widget_content_get_hook_set(obj, _content_get_hook);
831 elm_widget_content_unset_hook_set(obj, _content_unset_hook);
833 wd->horizontal = EINA_TRUE;
834 wd->indicator_show = EINA_TRUE;
838 wd->labels = eina_hash_string_superfast_new(_hash_labels_free_cb);
840 wd->slider = edje_object_add(e);
841 _elm_theme_object_set(obj, wd->slider, "slider", "horizontal", "default");
842 elm_widget_resize_object_set(obj, wd->slider);
843 edje_object_signal_callback_add(wd->slider, "drag", "*", _drag, obj);
844 edje_object_signal_callback_add(wd->slider, "drag,start", "*", _drag_start, obj);
845 edje_object_signal_callback_add(wd->slider, "drag,stop", "*", _drag_stop, obj);
846 edje_object_signal_callback_add(wd->slider, "drag,step", "*", _drag_step, obj);
847 edje_object_signal_callback_add(wd->slider, "drag,page", "*", _drag_stop, obj);
848 // edje_object_signal_callback_add(wd->slider, "drag,set", "*", _drag_stop, obj);
849 edje_object_part_drag_value_set(wd->slider, "elm.dragable.slider", 0.0, 0.0);
851 wd->spacer = evas_object_rectangle_add(e);
852 evas_object_color_set(wd->spacer, 0, 0, 0, 0);
853 evas_object_pass_events_set(wd->spacer, EINA_TRUE);
854 elm_widget_sub_object_add(obj, wd->spacer);
855 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
856 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_DOWN, _spacer_down_cb, obj);
857 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_MOVE, _spacer_move_cb, obj);
858 evas_object_event_callback_add(wd->spacer, EVAS_CALLBACK_MOUSE_UP, _spacer_up_cb, obj);
859 evas_object_smart_callback_add(obj, "sub-object-del", _sub_del, obj);
861 _mirrored_set(obj, elm_widget_mirrored_get(obj));
864 // TODO: convert Elementary to subclassing of Evas_Smart_Class
865 // TODO: and save some bytes, making descriptions per-class and not instance!
866 evas_object_smart_callbacks_descriptions_set(obj, _signals);
871 elm_slider_span_size_set(Evas_Object *obj, Evas_Coord size)
873 ELM_CHECK_WIDTYPE(obj, widtype);
874 Widget_Data *wd = elm_widget_data_get(obj);
876 if (wd->size == size) return;
879 evas_object_size_hint_min_set(wd->spacer, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale, 1);
881 evas_object_size_hint_min_set(wd->spacer, 1, (double)wd->size * elm_widget_scale_get(obj) * _elm_config->scale);
882 if (wd->indicator_show)
883 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
885 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
886 edje_object_part_swallow(wd->slider, "elm.swallow.bar", wd->spacer);
891 elm_slider_span_size_get(const Evas_Object *obj)
893 ELM_CHECK_WIDTYPE(obj, widtype) 0;
894 Widget_Data *wd = elm_widget_data_get(obj);
900 elm_slider_unit_format_set(Evas_Object *obj, const char *units)
902 ELM_CHECK_WIDTYPE(obj, widtype);
903 Widget_Data *wd = elm_widget_data_get(obj);
905 eina_stringshare_replace(&wd->units, units);
908 edje_object_signal_emit(wd->slider, "elm,state,units,visible", "elm");
909 edje_object_message_signal_process(wd->slider);
913 edje_object_signal_emit(wd->slider, "elm,state,units,hidden", "elm");
914 edje_object_message_signal_process(wd->slider);
922 elm_slider_unit_format_get(const Evas_Object *obj)
924 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
925 Widget_Data *wd = elm_widget_data_get(obj);
926 if (!wd) return NULL;
931 elm_slider_indicator_format_set(Evas_Object *obj, const char *indicator)
933 ELM_CHECK_WIDTYPE(obj, widtype);
934 Widget_Data *wd = elm_widget_data_get(obj);
936 eina_stringshare_replace(&wd->indicator, indicator);
941 elm_slider_indicator_format_get(const Evas_Object *obj)
943 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
944 Widget_Data *wd = elm_widget_data_get(obj);
945 if (!wd) return NULL;
946 return wd->indicator;
950 elm_slider_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
952 ELM_CHECK_WIDTYPE(obj, widtype);
953 Widget_Data *wd = elm_widget_data_get(obj);
955 horizontal = !!horizontal;
956 if (wd->horizontal == horizontal) return;
957 wd->horizontal = horizontal;
962 elm_slider_horizontal_get(const Evas_Object *obj)
964 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
965 Widget_Data *wd = elm_widget_data_get(obj);
966 if (!wd) return EINA_FALSE;
967 return wd->horizontal;
971 elm_slider_min_max_set(Evas_Object *obj, double min, double max)
973 ELM_CHECK_WIDTYPE(obj, widtype);
974 Widget_Data *wd = elm_widget_data_get(obj);
976 if ((wd->val_min == min) && (wd->val_max == max)) return;
979 if (wd->val < wd->val_min) wd->val = wd->val_min;
980 if (wd->val > wd->val_max) wd->val = wd->val_max;
988 elm_slider_min_max_get(const Evas_Object *obj, double *min, double *max)
992 ELM_CHECK_WIDTYPE(obj, widtype);
993 Widget_Data *wd = elm_widget_data_get(obj);
995 if (min) *min = wd->val_min;
996 if (max) *max = wd->val_max;
1000 elm_slider_value_set(Evas_Object *obj, double val)
1002 ELM_CHECK_WIDTYPE(obj, widtype);
1003 Widget_Data *wd = elm_widget_data_get(obj);
1005 if (wd->val == val) return;
1007 if (wd->val < wd->val_min) wd->val = wd->val_min;
1008 if (wd->val > wd->val_max) wd->val = wd->val_max;
1009 edje_object_signal_emit(wd->slider, "elm,state,drag", "elm");
1012 _indicator_set(obj);
1016 elm_slider_value_get(const Evas_Object *obj)
1018 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1019 Widget_Data *wd = elm_widget_data_get(obj);
1020 if (!wd) return 0.0;
1025 elm_slider_inverted_set(Evas_Object *obj, Eina_Bool inverted)
1027 ELM_CHECK_WIDTYPE(obj, widtype);
1028 Widget_Data *wd = elm_widget_data_get(obj);
1030 inverted = !!inverted;
1031 if (wd->inverted == inverted) return;
1032 wd->inverted = inverted;
1034 edje_object_signal_emit(wd->slider, "elm,state,inverted,on", "elm");
1036 edje_object_signal_emit(wd->slider, "elm,state,inverted,off", "elm");
1037 edje_object_message_signal_process(wd->slider);
1040 _indicator_set(obj);
1044 elm_slider_inverted_get(const Evas_Object *obj)
1046 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1047 Widget_Data *wd = elm_widget_data_get(obj);
1048 if (!wd) return EINA_FALSE;
1049 return wd->inverted;
1053 elm_slider_indicator_format_function_set(Evas_Object *obj, char *(*func)(double val), void (*free_func)(char *str))
1055 ELM_CHECK_WIDTYPE(obj, widtype);
1056 Widget_Data *wd = elm_widget_data_get(obj);
1058 wd->indicator_format_func = func;
1059 wd->indicator_format_free = free_func;
1060 _indicator_set(obj);
1064 elm_slider_units_format_function_set(Evas_Object *obj, char *(*func)(double val), void (*free_func)(char *str))
1066 ELM_CHECK_WIDTYPE(obj, widtype);
1067 Widget_Data *wd = elm_widget_data_get(obj);
1069 wd->units_format_func = func;
1070 wd->units_format_free = free_func;
1076 elm_slider_indicator_show_set(Evas_Object *obj, Eina_Bool show)
1078 ELM_CHECK_WIDTYPE(obj, widtype);
1079 Widget_Data *wd = elm_widget_data_get(obj);
1081 wd->indicator_show = EINA_TRUE;
1082 edje_object_signal_emit(wd->slider, "elm,state,val,show", "elm");
1085 wd->indicator_show = EINA_FALSE;
1086 edje_object_signal_emit(wd->slider, "elm,state,val,hide", "elm");
1091 elm_slider_indicator_show_get(const Evas_Object *obj)
1093 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1094 Widget_Data *wd = elm_widget_data_get(obj);
1095 if (!wd) return EINA_FALSE;
1096 return wd->indicator_show;