1 #include <Elementary.h>
3 #include "els_scroller.h"
7 typedef struct _Widget_Data Widget_Data;
8 typedef struct _Elm_Toolbar_Item Elm_Toolbar_Item;
12 Evas_Object *scr, *bx;
13 Evas_Object *menu_parent;
15 Elm_Toolbar_Item *more_item, *selected_item;
16 Elm_Toolbar_Shrink_Mode shrink_mode;
17 Elm_Icon_Lookup_Order lookup_order;
20 Eina_Bool homogeneous : 1;
21 Eina_Bool no_select : 1;
22 Eina_Bool always_select : 1;
23 Eina_Bool vertical : 1;
24 Eina_Bool long_press : 1;
25 Ecore_Timer *long_timer;
26 Ecore_Job *resize_job;
29 struct _Elm_Toolbar_Item
40 Eina_Bool visible : 1;
42 Eina_Bool selected : 1;
43 Eina_Bool separator : 1;
46 Eina_List *current_state;
49 #define ELM_TOOLBAR_ITEM_FROM_INLIST(item) \
50 ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Toolbar_Item) : NULL)
52 struct _Elm_Toolbar_Item_State
61 static const char *widtype = NULL;
62 static void _item_show(Elm_Toolbar_Item *it);
63 static void _item_select(Elm_Toolbar_Item *it);
64 static void _item_unselect(Elm_Toolbar_Item *it);
65 static void _del_pre_hook(Evas_Object *obj);
66 static void _del_hook(Evas_Object *obj);
67 static void _mirrored_set(Evas_Object *obj, Eina_Bool mirrored);
68 static void _mirrored_set_item(Evas_Object *obj, Elm_Toolbar_Item *it, Eina_Bool mirrored);
69 static void _theme_hook(Evas_Object *obj);
70 static void _sizing_eval(Evas_Object *obj);
71 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
72 static void _menu_move_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
73 static void _menu_hide(void *data, Evas *e, Evas_Object *obj, void *event_info);
74 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
75 static void _elm_toolbar_item_icon_obj_set(Evas_Object *obj, Elm_Toolbar_Item *item, Evas_Object *icon_obj, const char *icon_str, double icon_size, const char *signal);
76 static void _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal);
78 static const char SIG_CLICKED[] = "clicked";
79 static const char SIG_LONGPRESSED[] = "longpressed";
80 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
82 static const Evas_Smart_Cb_Description _signals[] = {
84 {SIG_LONGPRESSED, ""},
85 {SIG_CLICKED_DOUBLE, ""},
90 _item_disable_set_hook(Elm_Object_Item *it)
92 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
95 Elm_Toolbar_Item *toolbar_it = (Elm_Toolbar_Item *) it;
97 wd = elm_widget_data_get(WIDGET(toolbar_it));
100 if (elm_widget_item_disabled_get(toolbar_it))
102 edje_object_signal_emit(VIEW(toolbar_it), "elm,state,disabled", "elm");
103 elm_widget_signal_emit(toolbar_it->icon, "elm,state,disabled", "elm");
107 edje_object_signal_emit(VIEW(toolbar_it), "elm,state,enabled", "elm");
108 elm_widget_signal_emit(toolbar_it->icon, "elm,state,enabled", "elm");
110 _resize(WIDGET(toolbar_it), NULL, NULL, NULL);
114 _item_icon_set(Evas_Object *icon_obj, const char *type, const char *icon)
118 if ((!type) || (!*type)) goto end;
119 if ((!icon) || (!*icon)) return EINA_FALSE;
120 if ((snprintf(icon_str, sizeof(icon_str), "%s%s", type, icon) > 0)
121 && (elm_icon_standard_set(icon_obj, icon_str)))
124 if (elm_icon_standard_set(icon_obj, icon))
126 WRN("couldn't find icon definition for '%s'", icon);
131 _elm_toolbar_icon_size_get(Widget_Data *wd)
133 const char *icon_size = edje_object_data_get(
134 elm_smart_scroller_edje_object_get(wd->scr), "icon_size");
136 return atoi(icon_size);
137 return _elm_config->icon_size;
141 _item_show(Elm_Toolbar_Item *it)
143 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
144 Evas_Coord x, y, w, h, bx, by;
147 evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
148 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
149 elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
153 _item_unselect(Elm_Toolbar_Item *item)
156 if ((!item) || (!item->selected)) return;
157 wd = elm_widget_data_get(WIDGET(item));
159 item->selected = EINA_FALSE;
160 wd->selected_item = NULL;
161 edje_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
162 elm_widget_signal_emit(item->icon, "elm,state,unselected", "elm");
166 _item_select(Elm_Toolbar_Item *it)
168 Elm_Toolbar_Item *it2;
169 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
174 if (elm_widget_item_disabled_get(it) || (it->separator)) return;
181 if (wd->always_select) return;
186 it2 = (Elm_Toolbar_Item *)
187 elm_toolbar_selected_item_get(WIDGET(it));
190 it->selected = EINA_TRUE;
191 wd->selected_item = it;
192 edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
193 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
198 if (it->menu && (!sel))
200 evas_object_show(it->o_menu);
201 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
202 _menu_move_resize, it);
203 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOVE,
204 _menu_move_resize, it);
206 _menu_move_resize(it, NULL, NULL, NULL);
208 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
209 evas_object_smart_callback_call(obj2, SIG_CLICKED, it);
213 _menu_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
215 Elm_Toolbar_Item *selected;
216 Elm_Toolbar_Item *it = data;
217 selected = (Elm_Toolbar_Item *) elm_toolbar_selected_item_get(WIDGET(it));
218 _item_unselect(selected);
222 _menu_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
224 // avoid hide being emitted during object deletion
225 evas_object_event_callback_del_full
226 (obj, EVAS_CALLBACK_HIDE, _menu_hide, data);
230 _menu_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
232 Elm_Toolbar_Item *it = data;
234 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
236 if ((!wd) || (!wd->menu_parent)) return;
237 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
238 elm_menu_move(it->o_menu, x, y+h);
242 _item_del(Elm_Toolbar_Item *it)
244 Elm_Toolbar_Item_State *it_state;
246 elm_widget_item_pre_notify_del(it);
247 EINA_LIST_FREE(it->states, it_state)
249 if (it->icon == it_state->icon)
251 eina_stringshare_del(it_state->label);
252 eina_stringshare_del(it_state->icon_str);
253 if (it_state->icon) evas_object_del(it_state->icon);
256 eina_stringshare_del(it->label);
257 eina_stringshare_del(it->icon_str);
258 if (it->icon) evas_object_del(it->icon);
259 //TODO: See if checking for wd->menu_parent is necessary before deleting menu
260 if (it->o_menu) evas_object_del(it->o_menu);
261 elm_widget_item_del(it);
265 _del_pre_hook(Evas_Object *obj)
267 Widget_Data *wd = elm_widget_data_get(obj);
268 Elm_Toolbar_Item *it, *next;
271 it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
274 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
279 _item_del(wd->more_item);
282 ecore_timer_del(wd->long_timer);
283 wd->long_timer = NULL;
288 _del_hook(Evas_Object *obj)
290 Widget_Data *wd = elm_widget_data_get(obj);
298 _mirrored_set_item(Evas_Object *obj __UNUSED__, Elm_Toolbar_Item *it, Eina_Bool mirrored)
300 edje_object_mirrored_set(VIEW(it), mirrored);
301 elm_widget_mirrored_set(it->o_menu, mirrored);
305 _theme_hook_item(Evas_Object *obj, Elm_Toolbar_Item *it, double scale, int icon_size)
307 Evas_Object *view = VIEW(it);
309 const char *style = elm_widget_style_get(obj);
311 _mirrored_set_item(obj, it, elm_widget_mirrored_get(obj));
312 edje_object_scale_set(view, scale);
315 _elm_theme_object_set(obj, view, "toolbar", "item", style);
318 edje_object_signal_emit(view, "elm,state,selected", "elm");
319 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
321 if (elm_widget_item_disabled_get(it))
323 edje_object_signal_emit(view, "elm,state,disabled", "elm");
324 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
330 ms = ((double)icon_size * scale);
331 evas_object_size_hint_min_set(it->icon, ms, ms);
332 evas_object_size_hint_max_set(it->icon, ms, ms);
333 edje_object_part_swallow(view, "elm.swallow.icon",
336 edje_object_part_text_set(view, "elm.text", it->label);
339 _elm_theme_object_set(obj, view, "toolbar", "separator", style);
343 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
344 edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
346 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
347 evas_object_size_hint_min_set(view, mw, mh);
351 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
353 Widget_Data *wd = elm_widget_data_get(obj);
354 Elm_Toolbar_Item *it;
356 EINA_INLIST_FOREACH(wd->items, it)
357 _mirrored_set_item(obj, it, mirrored);
359 _mirrored_set_item(obj, wd->more_item, mirrored);
363 _theme_hook(Evas_Object *obj)
365 Widget_Data *wd = elm_widget_data_get(obj);
366 Elm_Toolbar_Item *it;
370 _elm_widget_mirrored_reload(obj);
371 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
372 _mirrored_set(obj, elm_widget_mirrored_get(obj));
373 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
374 edje_object_scale_set(wd->scr, scale);
375 wd->icon_size = _elm_toolbar_icon_size_get(wd);
376 EINA_INLIST_FOREACH(wd->items, it)
377 _theme_hook_item(obj, it, scale, wd->icon_size);
379 _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
384 _item_text_set_hook(Elm_Object_Item *it,
388 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
389 if (part && strcmp(part, "default")) return;
390 _item_label_set(((Elm_Toolbar_Item *) it), label, "elm,state,label_set");
394 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
396 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
397 if (part && strcmp(part, "default")) return NULL;
398 return ((Elm_Toolbar_Item *) it)->label;
402 _translate_hook(Evas_Object *obj)
404 evas_object_smart_callback_call(obj, "language,changed", NULL);
408 _sizing_eval(Evas_Object *obj)
410 Widget_Data *wd = elm_widget_data_get(obj);
411 Evas_Coord minw = -1, minh = -1, minw_bx, minh_bx;
412 Evas_Coord vw = 0, vh = 0;
416 evas_object_smart_calculate(wd->bx);
417 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
419 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
420 if (w < minw) w = minw;
421 if (h < minh) h = minh;
422 evas_object_resize(wd->scr, w, h);
424 evas_object_size_hint_min_get(wd->bx, &minw, &minh);
427 if (wd->vertical && (h > minh)) minh = h;
428 if ((!wd->vertical) && (w > minw)) minw = w;
429 evas_object_resize(wd->bx, minw, minh);
430 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
431 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_NONE)
433 if (wd->vertical) minh = minh_bx + (h - vh);
434 else minw = minw_bx + (w - vw);
438 if (wd->vertical) minh = h - vh;
441 minh = minh + (h - vh);
442 evas_object_size_hint_min_set(obj, minw, minh);
443 evas_object_size_hint_max_set(obj, -1, -1);
447 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
449 item->o_menu = elm_menu_add(VIEW(item));
450 item->menu = EINA_TRUE;
452 elm_menu_parent_set(item->o_menu, wd->menu_parent);
453 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
455 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
460 _item_menu_destroy(Elm_Toolbar_Item *item)
464 evas_object_del(item->o_menu);
467 item->menu = EINA_FALSE;
471 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
473 const Elm_Toolbar_Item *eti1 = i1;
474 const Elm_Toolbar_Item *eti2 = i2;
477 if (!eti1) return -1;
479 return eti2->prio.priority - eti1->prio.priority;
483 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
485 Elm_Toolbar_Item *it;
486 Eina_List *sorted = NULL;
489 EINA_INLIST_FOREACH(wd->items, it)
491 sorted = eina_list_sorted_insert(sorted,
492 _toolbar_item_prio_compare_cb, it);
497 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL, &ciw, NULL);
500 EINA_LIST_FREE(sorted, it)
502 evas_object_geometry_get(VIEW(it), NULL, NULL, &ciw, NULL);
504 it->prio.visible = (*iw <= vw);
509 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
511 Elm_Toolbar_Item *it = data;
512 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
516 _resize_job(void *data)
518 Widget_Data *wd = elm_widget_data_get(data);
519 Evas_Coord mw, mh, vw, vh, w, h;
520 Elm_Toolbar_Item *it;
521 Evas_Object *obj = (Evas_Object *) data;
524 wd->resize_job = NULL;
525 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
526 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
527 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
528 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
530 Evas_Coord iw = 0, more_w;
532 evas_object_resize(wd->bx, vw, h);
533 _fix_items_visibility(wd, &iw, vw);
534 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL, &more_w, NULL);
535 if (iw - more_w <= vw)
538 /* All items are removed from the box object, since removing individual
539 * items won't trigger a resize. Items are be readded below. */
540 evas_object_box_remove_all(wd->bx, EINA_FALSE);
545 _item_menu_destroy(wd->more_item);
546 _item_menu_create(wd, wd->more_item);
548 elm_toolbar_item_menu_get((Elm_Object_Item *) wd->more_item);
550 EINA_INLIST_FOREACH(wd->items, it)
552 if (!it->prio.visible)
555 elm_menu_item_separator_add(menu, NULL);
558 Elm_Object_Item *menu_it;
559 menu_it = elm_menu_item_add(menu, NULL,
560 it->icon_str, it->label,
561 _elm_toolbar_item_menu_cb, it);
562 elm_object_item_disabled_set(menu_it,
563 elm_widget_item_disabled_get(it));
565 elm_menu_clone(it->o_menu, menu, menu_it);
567 evas_object_hide(VIEW(it));
571 evas_object_box_append(wd->bx, VIEW(it));
572 evas_object_show(VIEW(it));
576 evas_object_box_append(wd->bx, wd->VIEW(more_item));
577 evas_object_show(wd->VIEW(more_item));
581 /* All items are visible, show them all (except for the "More"
582 * button, of course). */
583 EINA_INLIST_FOREACH(wd->items, it)
585 evas_object_show(VIEW(it));
586 evas_object_box_append(wd->bx, VIEW(it));
588 evas_object_hide(wd->VIEW(more_item));
591 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
595 evas_object_resize(wd->bx, vw, h);
596 _fix_items_visibility(wd, &iw, vw);
597 evas_object_box_remove_all(wd->bx, EINA_FALSE);
600 EINA_INLIST_FOREACH(wd->items, it)
602 if (!it->prio.visible)
603 evas_object_hide(VIEW(it));
606 evas_object_box_append(wd->bx, VIEW(it));
607 evas_object_show(VIEW(it));
613 /* All items are visible, show them all */
614 EINA_INLIST_FOREACH(wd->items, it)
616 evas_object_show(VIEW(it));
617 evas_object_box_append(wd->bx, VIEW(it));
623 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
624 EINA_INLIST_FOREACH(wd->items, it)
634 _mirrored_set(obj, elm_widget_mirrored_get(obj));
638 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
641 _resize(data, NULL, NULL, NULL);
645 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
647 Widget_Data *wd = elm_widget_data_get(data);
649 wd->resize_job = ecore_job_add(_resize_job, data);
653 _select_filter(Elm_Toolbar_Item *it, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
656 char buf[sizeof("elm,action,click,") + 1];
658 button = atoi(emission + sizeof("mouse,clicked,") - 1);
659 if (button == 1) return; /* regular left click event */
660 snprintf(buf, sizeof(buf), "elm,action,click,%d", button);
661 edje_object_signal_emit(VIEW(it), buf, "elm");
665 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
667 Elm_Toolbar_Item *it = data;
669 if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
670 (_elm_access_2nd_click_timeout(VIEW(it))))
672 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
673 _elm_access_say(E_("Selected"));
679 _long_press(Elm_Toolbar_Item *it)
681 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
682 wd->long_timer = NULL;
683 wd->long_press = EINA_TRUE;
684 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
685 return ECORE_CALLBACK_CANCEL;
689 _mouse_down(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Down *ev)
691 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
693 if (ev->button != 1) return;
694 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
695 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
696 wd->long_press = EINA_FALSE;
697 if (wd->long_timer) ecore_timer_interval_set(wd->long_timer, _elm_config->longpress_timeout);
698 else wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, (Ecore_Task_Cb)_long_press, it);
702 _mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
704 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
706 if (ev->button != 1) return;
709 ecore_timer_del(wd->long_timer);
710 wd->long_timer = NULL;
715 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
717 Elm_Toolbar_Item *it = data;
718 edje_object_signal_emit(VIEW(it), "elm,state,highlighted", "elm");
719 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
723 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
725 Elm_Toolbar_Item *it = data;
726 edje_object_signal_emit(VIEW(it), "elm,state,unhighlighted", "elm");
727 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
731 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
733 Evas_Object *obj = (Evas_Object *) data;
734 Widget_Data *wd = elm_widget_data_get(obj);
736 _els_box_layout(o, priv, !wd->vertical, wd->homogeneous, elm_widget_mirrored_get(obj));
740 _access_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item)
742 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
743 const char *txt = item->access_info;
744 if (!txt) txt = it->label;
745 if (txt) return strdup(txt);
750 _access_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
752 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
754 return strdup(E_("Separator"));
755 else if (elm_widget_item_disabled_get(it))
756 return strdup(E_("State: Disabled"));
757 else if (it->selected)
758 return strdup(E_("State: Selected"));
760 return strdup(E_("Has menu"));
764 static Elm_Toolbar_Item *
765 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
767 Widget_Data *wd = elm_widget_data_get(obj);
768 Evas_Object *icon_obj;
770 Elm_Toolbar_Item *it;
772 icon_obj = elm_icon_add(obj);
773 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
774 if (!icon_obj) return NULL;
775 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
778 evas_object_del(icon_obj);
782 elm_widget_item_disable_set_hook_set(it, _item_disable_set_hook);
783 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
784 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
786 it->label = eina_stringshare_add(label);
787 it->prio.visible = 1;
788 it->prio.priority = 0;
790 it->separator = EINA_FALSE;
791 it->base.data = data;
792 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
793 _elm_access_item_register(&it->base, VIEW(it));
794 _elm_access_text_set(_elm_access_item_get(&it->base),
795 ELM_ACCESS_TYPE, E_("Tool Item"));
796 _elm_access_callback_set(_elm_access_item_get(&it->base),
797 ELM_ACCESS_INFO, _access_info_cb, it);
798 _elm_access_callback_set(_elm_access_item_get(&it->base),
799 ELM_ACCESS_STATE, _access_state_cb, it);
801 if (_item_icon_set(icon_obj, "toolbar/", icon))
804 it->icon_str = eina_stringshare_add(icon);
810 evas_object_del(icon_obj);
813 _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
814 elm_widget_style_get(obj));
815 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "elm",
817 edje_object_signal_callback_add(VIEW(it), "mouse,clicked,*", "*",
818 (Edje_Signal_Cb)_select_filter, it);
819 edje_object_signal_callback_add(VIEW(it), "elm,mouse,in", "elm",
821 edje_object_signal_callback_add(VIEW(it), "elm,mouse,out", "elm",
823 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
824 (Evas_Object_Event_Cb)_mouse_down, it);
825 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
826 (Evas_Object_Event_Cb)_mouse_up, it);
827 elm_widget_sub_object_add(obj, VIEW(it));
832 ms = ((double)wd->icon_size * _elm_config->scale);
833 evas_object_size_hint_min_set(it->icon, ms, ms);
834 evas_object_size_hint_max_set(it->icon, ms, ms);
835 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
836 evas_object_show(it->icon);
837 elm_widget_sub_object_add(obj, it->icon);
839 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
841 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
842 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
843 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
846 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, -1.0);
847 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, 0.5);
851 evas_object_size_hint_weight_set(VIEW(it), -1.0, EVAS_HINT_EXPAND);
852 evas_object_size_hint_align_set(VIEW(it), 0.5, EVAS_HINT_FILL);
854 evas_object_size_hint_min_set(VIEW(it), mw, mh);
855 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
857 if ((!wd->items) && wd->always_select) _item_select(it);
862 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
864 Evas_Coord mw = -1, mh = -1;
865 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
866 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
868 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
869 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
870 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
873 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
874 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
878 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
879 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
881 evas_object_size_hint_min_set(VIEW(item), mw, mh);
885 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
887 Elm_Toolbar_Item *item = data;
888 _elm_toolbar_item_label_update(item);
889 edje_object_signal_callback_del(obj, emission, source,
890 _elm_toolbar_item_label_set_cb);
891 edje_object_signal_emit (VIEW(item), "elm,state,label,reset", "elm");
895 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal)
899 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
901 eina_stringshare_replace(&item->label, label);
902 s = edje_object_data_get(VIEW(item), "transition_animation_on");
903 if ((s) && (atoi(s)))
905 edje_object_part_text_set(VIEW(item), "elm.text_new", item->label);
906 edje_object_signal_emit (VIEW(item), signal, "elm");
907 edje_object_signal_callback_add(VIEW(item),
908 "elm,state,label_set,done", "elm",
909 _elm_toolbar_item_label_set_cb, item);
912 _elm_toolbar_item_label_update(item);
913 _resize(WIDGET(item), NULL, NULL, NULL);
917 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
919 Elm_Toolbar_Item_State *it_state;
921 Evas_Coord mw = -1, mh = -1;
922 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
923 Evas_Object *old_icon = edje_object_part_swallow_get(VIEW(item),
925 elm_widget_sub_object_del(VIEW(item), old_icon);
926 evas_object_hide(old_icon);
927 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
928 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
929 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
930 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
933 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
934 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
938 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
939 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
941 evas_object_size_hint_min_set(VIEW(item), mw, mh);
943 EINA_LIST_FOREACH(item->states, l, it_state)
944 if (it_state->icon == old_icon)
946 evas_object_del(old_icon);
950 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
952 Elm_Toolbar_Item *item = data;
953 edje_object_part_unswallow(VIEW(item), item->icon);
954 _elm_toolbar_item_icon_update(item);
955 edje_object_signal_callback_del(obj, emission, source,
956 _elm_toolbar_item_icon_set_cb);
957 edje_object_signal_emit (VIEW(item), "elm,state,icon,reset", "elm");
961 _elm_toolbar_item_icon_obj_set(Evas_Object *obj, Elm_Toolbar_Item *item, Evas_Object *icon_obj, const char *icon_str, double icon_size, const char *signal)
963 Evas_Object *old_icon;
968 eina_stringshare_replace(&item->icon_str, icon_str);
971 eina_stringshare_del(item->icon_str);
972 item->icon_str = NULL;
974 item->icon = icon_obj;
977 ms = (icon_size * _elm_config->scale);
978 evas_object_size_hint_min_set(item->icon, ms, ms);
979 evas_object_size_hint_max_set(item->icon, ms, ms);
980 evas_object_show(item->icon);
981 elm_widget_sub_object_add(obj, item->icon);
983 s = edje_object_data_get(VIEW(item), "transition_animation_on");
984 if ((s) && (atoi(s)))
986 old_icon = edje_object_part_swallow_get(VIEW(item),
987 "elm.swallow.icon_new");
990 elm_widget_sub_object_del(VIEW(item), old_icon);
991 evas_object_hide(old_icon);
993 edje_object_part_swallow(VIEW(item), "elm.swallow.icon_new",
995 edje_object_signal_emit (VIEW(item), signal, "elm");
996 edje_object_signal_callback_add(VIEW(item),
997 "elm,state,icon_set,done", "elm",
998 _elm_toolbar_item_icon_set_cb, item);
1001 _elm_toolbar_item_icon_update(item);
1002 _resize(obj, NULL, NULL, NULL);
1006 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1008 Elm_Toolbar_Item *it = event_info;
1009 Elm_Toolbar_Item_State *it_state;
1011 it_state = eina_list_data_get(it->current_state);
1013 it_state->func((void *)it_state->data, obj, event_info);
1016 static Elm_Toolbar_Item_State *
1017 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1019 Elm_Toolbar_Item_State *it_state;
1020 it_state = ELM_NEW(Elm_Toolbar_Item_State);
1021 it_state->label = eina_stringshare_add(label);
1022 it_state->icon_str = eina_stringshare_add(icon_str);
1023 it_state->icon = icon;
1024 it_state->func = func;
1025 it_state->data = data;
1030 elm_toolbar_add(Evas_Object *parent)
1036 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1038 ELM_SET_WIDTYPE(widtype, "toolbar");
1039 elm_widget_type_set(obj, "toolbar");
1040 elm_widget_sub_object_add(parent, obj);
1041 elm_widget_data_set(obj, wd);
1042 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1043 elm_widget_del_hook_set(obj, _del_hook);
1044 elm_widget_theme_hook_set(obj, _theme_hook);
1045 elm_widget_translate_hook_set(obj, _translate_hook);
1046 elm_widget_can_focus_set(obj, EINA_FALSE);
1048 wd->more_item = NULL;
1049 wd->selected_item = NULL;
1050 wd->scr = elm_smart_scroller_add(e);
1051 elm_smart_scroller_widget_set(wd->scr, obj);
1052 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
1053 elm_smart_scroller_bounce_allow_set(wd->scr,
1054 _elm_config->thumbscroll_bounce_enable,
1056 elm_widget_resize_object_set(obj, wd->scr);
1057 elm_smart_scroller_policy_set(wd->scr,
1058 ELM_SMART_SCROLLER_POLICY_AUTO,
1059 ELM_SMART_SCROLLER_POLICY_OFF);
1062 wd->icon_size = _elm_toolbar_icon_size_get(wd);
1065 wd->homogeneous = EINA_TRUE;
1068 wd->bx = evas_object_box_add(e);
1069 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
1070 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
1071 elm_widget_sub_object_add(obj, wd->bx);
1072 elm_smart_scroller_child_set(wd->scr, wd->bx);
1073 evas_object_show(wd->bx);
1075 elm_toolbar_mode_shrink_set(obj, _elm_config->toolbar_shrink_mode);
1076 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
1077 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
1078 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
1080 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1087 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
1089 ELM_CHECK_WIDTYPE(obj, widtype);
1090 Widget_Data *wd = elm_widget_data_get(obj);
1092 if (wd->icon_size == icon_size) return;
1093 wd->icon_size = icon_size;
1098 elm_toolbar_icon_size_get(const Evas_Object *obj)
1100 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1101 Widget_Data *wd = elm_widget_data_get(obj);
1103 return wd->icon_size;
1106 EAPI Elm_Object_Item *
1107 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1109 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1110 Widget_Data *wd = elm_widget_data_get(obj);
1111 if (!wd) return NULL;
1113 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1114 if (!it) return NULL;
1115 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1117 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
1118 evas_object_box_append(wd->bx, VIEW(it));
1119 evas_object_show(VIEW(it));
1121 _theme_hook_item(obj, it, scale, wd->icon_size);
1124 return (Elm_Object_Item *) it;
1127 EAPI Elm_Object_Item *
1128 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1130 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1131 Widget_Data *wd = elm_widget_data_get(obj);
1132 if (!wd) return NULL;
1134 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1135 if (!it) return NULL;
1136 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1138 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1139 evas_object_box_prepend(wd->bx, VIEW(it));
1140 evas_object_show(VIEW(it));
1141 _theme_hook_item(obj, it, scale, wd->icon_size);
1144 return (Elm_Object_Item *) it;
1147 EAPI Elm_Object_Item *
1148 elm_toolbar_item_insert_before(Evas_Object *obj, Elm_Object_Item *before, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1150 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1151 ELM_OBJ_ITEM_CHECK_OR_RETURN(before, NULL);
1153 Elm_Toolbar_Item *it, *_before;
1155 wd = elm_widget_data_get(obj);
1156 if (!wd) return NULL;
1157 _before = (Elm_Toolbar_Item *) before;
1158 it = _item_new(obj, icon, label, func, data);
1159 if (!it) return NULL;
1160 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1162 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1163 EINA_INLIST_GET(_before));
1164 evas_object_box_insert_before(wd->bx, VIEW(it), VIEW(_before));
1165 evas_object_show(VIEW(it));
1166 _theme_hook_item(obj, it, scale, wd->icon_size);
1169 return (Elm_Object_Item *) it;
1172 EAPI Elm_Object_Item *
1173 elm_toolbar_item_insert_after(Evas_Object *obj, Elm_Object_Item *after, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1175 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1176 ELM_OBJ_ITEM_CHECK_OR_RETURN(after, NULL);
1178 Elm_Toolbar_Item *it, *_after;
1180 wd = elm_widget_data_get(obj);
1181 if (!wd) return NULL;
1182 _after = (Elm_Toolbar_Item *) after;
1183 it = _item_new(obj, icon, label, func, data);
1184 if (!it) return NULL;
1185 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1187 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1188 EINA_INLIST_GET(_after));
1189 evas_object_box_insert_after(wd->bx, VIEW(it), VIEW(_after));
1190 evas_object_show(VIEW(it));
1191 _theme_hook_item(obj, it, scale, wd->icon_size);
1194 return (Elm_Object_Item *) it;
1197 EAPI Elm_Object_Item *
1198 elm_toolbar_first_item_get(const Evas_Object *obj)
1200 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1201 Widget_Data *wd = elm_widget_data_get(obj);
1202 if (!wd || !wd->items) return NULL;
1203 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1206 EAPI Elm_Object_Item *
1207 elm_toolbar_last_item_get(const Evas_Object *obj)
1209 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1210 Widget_Data *wd = elm_widget_data_get(obj);
1211 if (!wd || !wd->items) return NULL;
1212 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1215 EAPI Elm_Object_Item *
1216 elm_toolbar_item_next_get(const Elm_Object_Item *it)
1218 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1219 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1220 EINA_INLIST_GET(((Elm_Toolbar_Item *) it))->next);
1223 EAPI Elm_Object_Item *
1224 elm_toolbar_item_prev_get(const Elm_Object_Item *it)
1226 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1227 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1228 EINA_INLIST_GET(((Elm_Toolbar_Item *) it))->prev);
1232 elm_toolbar_item_toolbar_get(const Elm_Object_Item *it)
1234 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1235 return elm_object_item_object_get(it);
1239 elm_toolbar_item_priority_set(Elm_Object_Item *it, int priority)
1241 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1242 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1243 if (item->prio.priority == priority) return;
1244 item->prio.priority = priority;
1245 _resize(WIDGET(item), NULL, NULL, NULL);
1249 elm_toolbar_item_priority_get(const Elm_Object_Item *it)
1251 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
1252 return ((Elm_Toolbar_Item *) it)->prio.priority;
1256 elm_toolbar_item_label_get(const Elm_Object_Item *it)
1258 return _item_text_get_hook(it, NULL);
1262 elm_toolbar_item_label_set(Elm_Object_Item *it, const char *label)
1264 _item_text_set_hook(it, NULL, label);
1268 elm_toolbar_item_data_get(const Elm_Object_Item *it)
1270 return elm_object_item_data_get(it);
1274 elm_toolbar_item_data_set(Elm_Object_Item *it, const void *data)
1276 elm_object_item_data_set(it, (void *) data);
1279 EAPI Elm_Object_Item *
1280 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
1282 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1283 Elm_Toolbar_Item *it;
1284 Widget_Data *wd = elm_widget_data_get(obj);
1285 if (!wd) return NULL;
1287 EINA_INLIST_FOREACH(wd->items, it)
1289 if (!strcmp(it->label, label))
1290 return (Elm_Object_Item *) it;
1296 elm_toolbar_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1298 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1299 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1300 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1303 if (item->selected == selected) return;
1304 if (selected) _item_select(item);
1305 else _item_unselect(item);
1309 elm_toolbar_item_selected_get(const Elm_Object_Item *it)
1311 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1312 return ((Elm_Toolbar_Item *) it)->selected;
1315 EAPI Elm_Object_Item *
1316 elm_toolbar_selected_item_get(const Evas_Object *obj)
1318 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1319 Widget_Data *wd = elm_widget_data_get(obj);
1320 if (!wd) return NULL;
1321 return (Elm_Object_Item *) wd->selected_item;
1325 elm_toolbar_item_icon_set(Elm_Object_Item *it, const char *icon)
1327 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1329 Evas_Object *icon_obj;
1332 Elm_Toolbar_Item * item = (Elm_Toolbar_Item *) it;
1335 wd = elm_widget_data_get(obj);
1337 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1339 icon_obj = elm_icon_add(obj);
1340 if (!icon_obj) return;
1341 if (_item_icon_set(icon_obj, "toolbar/", icon))
1342 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1343 "elm,state,icon_set");
1346 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1347 "elm,state,icon_set");
1348 evas_object_del(icon_obj);
1353 elm_toolbar_item_icon_get(const Elm_Object_Item *it)
1355 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1356 return ((Elm_Toolbar_Item *) it)->icon_str;
1360 elm_toolbar_item_object_get(const Elm_Object_Item *it)
1362 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1366 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1369 wd = elm_widget_data_get(obj);
1370 if (!wd) return NULL;
1376 elm_toolbar_item_icon_object_get(Elm_Object_Item *it)
1378 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1379 return ((Elm_Toolbar_Item *) it)->icon;
1383 elm_toolbar_item_icon_memfile_set(Elm_Object_Item *it, const void *img, size_t size, const char *format, const char *key)
1385 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1387 Evas_Object *icon_obj;
1391 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1394 wd = elm_widget_data_get(obj);
1395 if (!wd) return EINA_FALSE;
1399 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1400 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1401 ret = _els_smart_icon_memfile_set(icon_obj, img, size, format, key);
1404 evas_object_del(icon_obj);
1407 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1408 "elm,state,icon_set");
1411 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1416 elm_toolbar_item_icon_file_set(Elm_Object_Item *it, const char *file, const char *key)
1418 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1420 Evas_Object *icon_obj;
1424 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1427 wd = elm_widget_data_get(obj);
1428 if (!wd) return EINA_FALSE;
1432 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1433 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1434 ret = _els_smart_icon_file_key_set(icon_obj, file, key);
1437 evas_object_del(icon_obj);
1440 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1441 "elm,state,icon_set");
1444 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1449 elm_toolbar_item_del(Elm_Object_Item *it)
1451 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1455 Elm_Toolbar_Item *item, *next;
1456 item = (Elm_Toolbar_Item *) it;
1458 wd = elm_widget_data_get(WIDGET(item));
1460 obj2 = WIDGET(item);
1461 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
1462 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
1463 if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1464 if (wd->always_select && item->selected && next) _item_select(next);
1470 elm_toolbar_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1472 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1473 elm_widget_item_del_cb_set(it, func);
1477 elm_toolbar_item_disabled_get(const Elm_Object_Item *it)
1479 return elm_object_item_disabled_get(it);
1483 elm_toolbar_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1485 elm_object_item_disabled_set(it, disabled);
1489 elm_toolbar_item_separator_set(Elm_Object_Item *it, Eina_Bool separator)
1491 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1492 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1493 Evas_Object *obj = WIDGET(item);
1494 Widget_Data *wd = elm_widget_data_get(obj);
1496 if (item->separator == separator) return;
1497 item->separator = separator;
1498 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1499 _theme_hook_item(obj, item, scale, wd->icon_size);
1503 elm_toolbar_item_separator_get(const Elm_Object_Item *it)
1505 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1506 return ((Elm_Toolbar_Item *) it)->separator;
1510 elm_toolbar_mode_shrink_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1512 ELM_CHECK_WIDTYPE(obj, widtype);
1513 Widget_Data *wd = elm_widget_data_get(obj);
1517 wd->shrink_mode = shrink_mode;
1518 bounce = (_elm_config->thumbscroll_bounce_enable) &&
1519 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1520 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1524 _item_del(wd->more_item);
1525 wd->more_item = NULL;
1528 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1530 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF, ELM_SMART_SCROLLER_POLICY_OFF);
1532 wd->more_item = _item_new(obj, "more_menu", "More",
1535 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1536 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1537 ELM_SMART_SCROLLER_POLICY_OFF);
1539 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1540 ELM_SMART_SCROLLER_POLICY_OFF);
1544 EAPI Elm_Toolbar_Shrink_Mode
1545 elm_toolbar_mode_shrink_get(const Evas_Object *obj)
1547 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1548 Widget_Data *wd = elm_widget_data_get(obj);
1550 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1551 return wd->shrink_mode;
1555 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
1557 ELM_CHECK_WIDTYPE(obj, widtype);
1558 Widget_Data *wd = elm_widget_data_get(obj);
1561 wd->homogeneous = !!homogeneous;
1562 evas_object_smart_calculate(wd->bx);
1566 elm_toolbar_homogeneous_get(const Evas_Object *obj)
1568 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1569 Widget_Data *wd = elm_widget_data_get(obj);
1571 if (!wd) return EINA_FALSE;
1572 return wd->homogeneous;
1576 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1578 Elm_Toolbar_Item *it;
1579 ELM_CHECK_WIDTYPE(obj, widtype);
1580 Widget_Data *wd = elm_widget_data_get(obj);
1583 EINA_SAFETY_ON_NULL_RETURN(parent);
1584 wd->menu_parent = parent;
1585 EINA_INLIST_FOREACH(wd->items, it)
1588 elm_menu_parent_set(it->o_menu, wd->menu_parent);
1590 if ((wd->more_item) && (wd->more_item->o_menu))
1591 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1595 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1597 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1598 Widget_Data *wd = elm_widget_data_get(obj);
1600 if (!wd) return NULL;
1601 return wd->menu_parent;
1605 elm_toolbar_align_set(Evas_Object *obj, double align)
1607 ELM_CHECK_WIDTYPE(obj, widtype);
1608 Widget_Data *wd = elm_widget_data_get(obj);
1611 if (wd->align != align)
1612 evas_object_size_hint_align_set(wd->bx, align, 0.5);
1617 elm_toolbar_align_get(const Evas_Object *obj)
1619 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1620 Widget_Data *wd = elm_widget_data_get(obj);
1622 if (!wd) return 0.0;
1627 elm_toolbar_item_menu_set(Elm_Object_Item *it, Eina_Bool menu)
1629 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1630 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1631 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1634 if (item->menu == menu) return;
1635 if (menu) _item_menu_create(wd, item);
1636 else _item_menu_destroy(item);
1640 elm_toolbar_item_menu_get(const Elm_Object_Item *it)
1642 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1643 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1644 if (!item->menu) return NULL;
1645 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1646 if (!wd) return NULL;
1647 return item->o_menu;
1650 EAPI Elm_Toolbar_Item_State *
1651 elm_toolbar_item_state_add(Elm_Object_Item *it, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1653 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1655 Elm_Toolbar_Item_State *it_state;
1656 Evas_Object *icon_obj;
1659 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1661 wd = elm_widget_data_get(WIDGET(item));
1662 if (!wd) return NULL;
1666 it_state = _item_state_new(item->label, item->icon_str, item->icon,
1667 item->func, item->base.data);
1668 item->states = eina_list_append(item->states, it_state);
1669 item->current_state = item->states;
1672 icon_obj = elm_icon_add(obj);
1673 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1674 if (!icon_obj) goto error_state_add;
1676 if (!_item_icon_set(icon_obj, "toolbar/", icon))
1678 evas_object_del(icon_obj);
1683 it_state = _item_state_new(label, icon, icon_obj, func, data);
1684 item->states = eina_list_append(item->states, it_state);
1685 item->func = _elm_toolbar_item_state_cb;
1686 item->base.data = NULL;
1691 if (item->states && !eina_list_next(item->states))
1693 eina_stringshare_del(item->label);
1694 eina_stringshare_del(item->icon_str);
1695 free(eina_list_data_get(item->states));
1696 eina_list_free(item->states);
1697 item->states = NULL;
1703 elm_toolbar_item_state_del(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1705 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1707 Eina_List *del_state;
1708 Elm_Toolbar_Item_State *it_state;
1709 Elm_Toolbar_Item *item;
1711 if (!state) return EINA_FALSE;
1713 item = (Elm_Toolbar_Item *) it;
1714 if (!item->states) return EINA_FALSE;
1716 del_state = eina_list_data_find_list(item->states, state);
1717 if (del_state == item->states) return EINA_FALSE;
1718 if (del_state == item->current_state)
1719 elm_toolbar_item_state_unset(it);
1721 eina_stringshare_del(state->label);
1722 eina_stringshare_del(state->icon_str);
1723 if (state->icon) evas_object_del(state->icon);
1725 item->states = eina_list_remove_list(item->states, del_state);
1726 if (item->states && !eina_list_next(item->states))
1728 it_state = eina_list_data_get(item->states);
1729 item->base.data = it_state->data;
1730 item->func = it_state->func;
1731 eina_stringshare_del(it_state->label);
1732 eina_stringshare_del(it_state->icon_str);
1733 free(eina_list_data_get(item->states));
1734 eina_list_free(item->states);
1735 item->states = NULL;
1741 elm_toolbar_item_state_set(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1743 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1746 Eina_List *next_state;
1747 Elm_Toolbar_Item_State *it_state;
1749 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1752 wd = elm_widget_data_get(obj);
1753 if (!wd) return EINA_FALSE;
1754 if (!item->states) return EINA_FALSE;
1758 next_state = eina_list_data_find_list(item->states, state);
1759 if (!next_state) return EINA_FALSE;
1762 next_state = item->states;
1764 if (next_state == item->current_state) return EINA_TRUE;
1766 it_state = eina_list_data_get(next_state);
1767 if (eina_list_data_find(item->current_state, state))
1769 _item_label_set(item, it_state->label, "elm,state,label_set,forward");
1770 _elm_toolbar_item_icon_obj_set(obj, item, it_state->icon, it_state->icon_str,
1771 wd->icon_size, "elm,state,icon_set,forward");
1775 _item_label_set(item, it_state->label, "elm,state,label_set,backward");
1776 _elm_toolbar_item_icon_obj_set(obj,
1781 "elm,state,icon_set,backward");
1783 if (elm_widget_item_disabled_get(item))
1784 elm_widget_signal_emit(item->icon, "elm,state,disabled", "elm");
1786 elm_widget_signal_emit(item->icon, "elm,state,enabled", "elm");
1788 item->current_state = next_state;
1793 elm_toolbar_item_state_unset(Elm_Object_Item *it)
1795 elm_toolbar_item_state_set(it, NULL);
1798 EAPI Elm_Toolbar_Item_State *
1799 elm_toolbar_item_state_get(const Elm_Object_Item *it)
1801 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1802 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1804 if ((!item->states) || (!item->current_state)) return NULL;
1805 if (item->current_state == item->states) return NULL;
1807 return eina_list_data_get(item->current_state);
1810 EAPI Elm_Toolbar_Item_State *
1811 elm_toolbar_item_state_next(Elm_Object_Item *it)
1813 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1817 Eina_List *next_state;
1818 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1821 wd = elm_widget_data_get(obj);
1822 if (!wd) return NULL;
1823 if (!item->states) return NULL;
1825 next_state = eina_list_next(item->current_state);
1827 next_state = eina_list_next(item->states);
1828 return eina_list_data_get(next_state);
1831 EAPI Elm_Toolbar_Item_State *
1832 elm_toolbar_item_state_prev(Elm_Object_Item *it)
1834 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1838 Eina_List *prev_state;
1839 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1842 wd = elm_widget_data_get(obj);
1843 if (!wd) return NULL;
1844 if (!item->states) return NULL;
1846 prev_state = eina_list_prev(item->current_state);
1847 if ((!prev_state) || (prev_state == item->states))
1848 prev_state = eina_list_last(item->states);
1849 return eina_list_data_get(prev_state);
1853 elm_toolbar_item_tooltip_text_set(Elm_Object_Item *it, const char *text)
1855 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1856 elm_widget_item_tooltip_text_set(it, text);
1860 elm_toolbar_item_tooltip_content_cb_set(Elm_Object_Item *it, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
1862 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1863 elm_widget_item_tooltip_content_cb_set(it, func, data, del_cb);
1867 elm_toolbar_item_tooltip_unset(Elm_Object_Item *it)
1869 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1870 elm_widget_item_tooltip_unset(it);
1874 elm_toolbar_item_tooltip_style_set(Elm_Object_Item *it, const char *style)
1876 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1877 elm_widget_item_tooltip_style_set(it, style);
1881 elm_toolbar_item_tooltip_style_get(const Elm_Object_Item *it)
1883 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1884 return elm_widget_item_tooltip_style_get(it);
1888 elm_toolbar_item_cursor_set(Elm_Object_Item *it, const char *cursor)
1890 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1891 elm_widget_item_cursor_set(it, cursor);
1895 elm_toolbar_item_cursor_get(const Elm_Object_Item *it)
1897 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1898 return elm_widget_item_cursor_get(it);
1902 elm_toolbar_item_cursor_unset(Elm_Object_Item *it)
1904 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1905 elm_widget_item_cursor_unset(it);
1909 elm_toolbar_item_cursor_style_set(Elm_Object_Item *it, const char *style)
1911 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1912 elm_widget_item_cursor_style_set(it, style);
1916 elm_toolbar_item_cursor_style_get(const Elm_Object_Item *it)
1918 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1919 return elm_widget_item_cursor_style_get(it);
1923 elm_toolbar_item_cursor_engine_only_set(Elm_Object_Item *it, Eina_Bool engine_only)
1925 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1926 elm_widget_item_cursor_engine_only_set(it, engine_only);
1930 elm_toolbar_item_cursor_engine_only_get(const Elm_Object_Item *it)
1932 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1933 return elm_widget_item_cursor_engine_only_get(it);
1937 elm_toolbar_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
1939 ELM_CHECK_WIDTYPE(obj, widtype);
1940 Widget_Data *wd = elm_widget_data_get(obj);
1942 if (always_select && (!wd->always_select) && wd->items)
1943 _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
1944 wd->always_select = always_select;
1948 elm_toolbar_always_select_mode_get(const Evas_Object *obj)
1950 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1951 Widget_Data *wd = elm_widget_data_get(obj);
1952 if (!wd) return EINA_FALSE;
1953 return wd->always_select;
1957 elm_toolbar_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select)
1959 ELM_CHECK_WIDTYPE(obj, widtype);
1960 Widget_Data *wd = elm_widget_data_get(obj);
1962 wd->no_select = no_select;
1966 elm_toolbar_no_select_mode_get(const Evas_Object *obj)
1968 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1969 Widget_Data *wd = elm_widget_data_get(obj);
1970 if (!wd) return EINA_FALSE;
1971 return wd->no_select;
1975 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
1977 ELM_CHECK_WIDTYPE(obj, widtype);
1978 Elm_Toolbar_Item *it;
1979 Widget_Data *wd = elm_widget_data_get(obj);
1982 wd->lookup_order = order;
1983 EINA_INLIST_FOREACH(wd->items, it)
1984 elm_icon_order_lookup_set(it->icon, order);
1986 elm_icon_order_lookup_set(wd->more_item->icon, order);
1989 EAPI Elm_Icon_Lookup_Order
1990 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
1992 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
1993 Widget_Data *wd = elm_widget_data_get(obj);
1994 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
1995 return wd->lookup_order;
1998 EINA_DEPRECATED EAPI void
1999 elm_toolbar_orientation_set(Evas_Object *obj, Eina_Bool vertical)
2001 elm_toolbar_horizontal_set(obj, !vertical);
2004 EINA_DEPRECATED EAPI Eina_Bool
2005 elm_toolbar_orientation_get(const Evas_Object *obj)
2007 return !elm_toolbar_horizontal_get(obj);
2011 elm_toolbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
2013 ELM_CHECK_WIDTYPE(obj, widtype);
2014 Widget_Data *wd = elm_widget_data_get(obj);
2016 wd->vertical = !horizontal;
2021 elm_toolbar_horizontal_get(const Evas_Object *obj)
2023 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2024 Widget_Data *wd = elm_widget_data_get(obj);
2025 if (!wd) return EINA_FALSE;
2026 return !wd->vertical;