1 #include <Elementary.h>
5 * @defgroup Toolbar Toolbar
7 * A toolbar is a widget that displays a list of buttons inside
8 * a box. It is scrollable, and only one item can be selected at a time.
10 * Signals that you can add callbacks for are:
12 * "clicked" - when the user clicks on a toolbar item and becomes selected
16 typedef struct _Widget_Data Widget_Data;
20 Evas_Object *scr, *bx;
21 Evas_Object *menu_parent;
23 Elm_Toolbar_Item *more_item, *selected_item;
24 Elm_Toolbar_Shrink_Mode shrink_mode;
25 Elm_Icon_Lookup_Order lookup_order;
28 Eina_Bool homogeneous : 1;
29 Eina_Bool no_select : 1;
30 Ecore_Job *resize_job;
33 struct _Elm_Toolbar_Item
44 Eina_Bool visible : 1;
46 Eina_Bool selected : 1;
47 Eina_Bool disabled : 1;
48 Eina_Bool separator : 1;
51 Eina_List *current_state;
54 #define ELM_TOOLBAR_ITEM_FROM_INLIST(item) \
55 ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Toolbar_Item) : NULL)
57 struct _Elm_Toolbar_Item_State
66 static const char *widtype = NULL;
67 static void _item_show(Elm_Toolbar_Item *it);
68 static void _item_select(Elm_Toolbar_Item *it);
69 static void _item_unselect(Elm_Toolbar_Item *it);
70 static void _item_disable(Elm_Toolbar_Item *it, Eina_Bool disabled);
71 static void _del_pre_hook(Evas_Object *obj);
72 static void _del_hook(Evas_Object *obj);
73 static void _mirrored_set(Evas_Object *obj, Eina_Bool mirrored);
74 static void _mirrored_set_item(Evas_Object *obj, Elm_Toolbar_Item *it, Eina_Bool mirrored);
75 static void _theme_hook(Evas_Object *obj);
76 static void _sizing_eval(Evas_Object *obj);
77 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
78 static void _menu_move_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
79 static void _menu_hide(void *data, Evas *e, Evas_Object *obj, void *event_info);
80 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
81 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);
82 static void _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal);
84 static const char SIG_CLICKED[] = "clicked";
86 static const Evas_Smart_Cb_Description _signals[] = {
93 _item_icon_set(Evas_Object *icon_obj, const char *type, const char *icon)
97 if ((!type) || (!*type)) goto end;
98 if ((!icon) || (!*icon)) return EINA_FALSE;
99 if ((snprintf(icon_str, sizeof(icon_str), "%s%s", type, icon) > 0)
100 && (elm_icon_standard_set(icon_obj, icon_str)))
103 if (elm_icon_standard_set(icon_obj, icon))
105 WRN("couldn't find icon definition for '%s'", icon);
110 _elm_toolbar_icon_size_get(Widget_Data *wd)
112 const char *icon_size = edje_object_data_get(
113 elm_smart_scroller_edje_object_get(wd->scr), "icon_size");
115 return atoi(icon_size);
116 return _elm_config->icon_size;
120 _item_show(Elm_Toolbar_Item *it)
122 Widget_Data *wd = elm_widget_data_get(it->base.widget);
123 Evas_Coord x, y, w, h, bx, by;
126 evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
127 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
128 elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
132 _item_unselect(Elm_Toolbar_Item *item)
135 if ((!item) || (!item->selected)) return;
136 wd = elm_widget_data_get(item->base.widget);
138 item->selected = EINA_FALSE;
139 wd->selected_item = NULL;
140 edje_object_signal_emit(item->base.view, "elm,state,unselected", "elm");
141 elm_widget_signal_emit(item->icon, "elm,state,unselected", "elm");
145 _item_select(Elm_Toolbar_Item *it)
147 Elm_Toolbar_Item *it2;
148 Widget_Data *wd = elm_widget_data_get(it->base.widget);
152 if ((it->selected) || (it->disabled) || (it->separator)) return;
156 it2 = elm_toolbar_selected_item_get(it->base.widget);
159 it->selected = EINA_TRUE;
160 wd->selected_item = it;
161 edje_object_signal_emit(it->base.view, "elm,state,selected", "elm");
162 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
165 obj2 = it->base.widget;
168 evas_object_show(it->o_menu);
169 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_RESIZE,
170 _menu_move_resize, it);
171 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOVE,
172 _menu_move_resize, it);
174 _menu_move_resize(it, NULL, NULL, NULL);
176 if (it->func) it->func((void *)(it->base.data), it->base.widget, it);
177 evas_object_smart_callback_call(obj2, SIG_CLICKED, it);
181 _menu_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
183 Elm_Toolbar_Item *selected;
184 Elm_Toolbar_Item *it = data;
185 selected = elm_toolbar_selected_item_get(it->base.widget);
186 _item_unselect(selected);
190 _menu_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
192 // avoid hide being emitted during object deletion
193 evas_object_event_callback_del_full
194 (obj, EVAS_CALLBACK_HIDE, _menu_hide, data);
198 _menu_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
200 Elm_Toolbar_Item *it = data;
202 Widget_Data *wd = elm_widget_data_get(it->base.widget);
204 if ((!wd) || (!wd->menu_parent)) return;
205 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
206 elm_menu_move(it->o_menu, x, y+h);
210 _item_disable(Elm_Toolbar_Item *it, Eina_Bool disabled)
212 Widget_Data *wd = elm_widget_data_get(it->base.widget);
215 if (it->disabled == disabled) return;
216 it->disabled = disabled;
219 edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
220 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
224 edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
225 elm_widget_signal_emit(it->icon, "elm,state,enabled", "elm");
230 _item_del(Elm_Toolbar_Item *it)
232 Elm_Toolbar_Item_State *it_state;
234 elm_widget_item_pre_notify_del(it);
235 EINA_LIST_FREE(it->states, it_state)
237 if (it->icon == it_state->icon)
239 eina_stringshare_del(it_state->label);
240 eina_stringshare_del(it_state->icon_str);
241 if (it_state->icon) evas_object_del(it_state->icon);
244 eina_stringshare_del(it->label);
245 eina_stringshare_del(it->icon_str);
246 if (it->icon) evas_object_del(it->icon);
247 //TODO: See if checking for wd->menu_parent is necessary before deleting menu
248 if (it->o_menu) evas_object_del(it->o_menu);
249 elm_widget_item_del(it);
253 _del_pre_hook(Evas_Object *obj)
255 Widget_Data *wd = elm_widget_data_get(obj);
256 Elm_Toolbar_Item *it, *next;
259 it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
262 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
267 _item_del(wd->more_item);
271 _del_hook(Evas_Object *obj)
273 Widget_Data *wd = elm_widget_data_get(obj);
281 _mirrored_set_item(Evas_Object *obj __UNUSED__, Elm_Toolbar_Item *it, Eina_Bool mirrored)
283 edje_object_mirrored_set(it->base.view, mirrored);
284 elm_widget_mirrored_set(it->o_menu, mirrored);
288 _theme_hook_item(Evas_Object *obj, Elm_Toolbar_Item *it, double scale, int icon_size)
290 Evas_Object *view = it->base.view;
292 const char *style = elm_widget_style_get(obj);
294 _mirrored_set_item(obj, it, elm_widget_mirrored_get(obj));
295 edje_object_scale_set(view, scale);
298 _elm_theme_object_set(obj, view, "toolbar", "item", style);
301 edje_object_signal_emit(view, "elm,state,selected", "elm");
302 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
306 edje_object_signal_emit(view, "elm,state,disabled", "elm");
307 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
313 ms = ((double)icon_size * scale);
314 evas_object_size_hint_min_set(it->icon, ms, ms);
315 evas_object_size_hint_max_set(it->icon, ms, ms);
316 edje_object_part_swallow(view, "elm.swallow.icon",
319 edje_object_part_text_set(view, "elm.text", it->label);
322 _elm_theme_object_set(obj, view, "toolbar", "separator", style);
326 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
327 edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
329 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
330 evas_object_size_hint_min_set(view, mw, mh);
334 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
336 Widget_Data *wd = elm_widget_data_get(obj);
337 Elm_Toolbar_Item *it;
339 EINA_INLIST_FOREACH(wd->items, it)
340 _mirrored_set_item(obj, it, mirrored);
342 _mirrored_set_item(obj, wd->more_item, mirrored);
346 _theme_hook(Evas_Object *obj)
348 Widget_Data *wd = elm_widget_data_get(obj);
349 Elm_Toolbar_Item *it;
353 _elm_widget_mirrored_reload(obj);
354 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
355 _mirrored_set(obj, elm_widget_mirrored_get(obj));
356 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
357 edje_object_scale_set(wd->scr, scale);
358 wd->icon_size = _elm_toolbar_icon_size_get(wd);
359 EINA_INLIST_FOREACH(wd->items, it)
360 _theme_hook_item(obj, it, scale, wd->icon_size);
362 _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
367 _sizing_eval(Evas_Object *obj)
369 Widget_Data *wd = elm_widget_data_get(obj);
370 Evas_Coord minw = -1, minh = -1, minw_bx;
371 Evas_Coord vw = 0, vh = 0;
375 evas_object_smart_calculate(wd->bx);
376 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
378 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
379 if (w < minw) w = minw;
380 if (h < minh) h = minh;
382 evas_object_resize(wd->scr, w, h);
384 evas_object_size_hint_min_get(wd->bx, &minw, &minh);
386 if (w > minw) minw = w;
387 evas_object_resize(wd->bx, minw, minh);
388 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
389 switch (wd->shrink_mode)
391 case ELM_TOOLBAR_SHRINK_MENU: /* fallthrough */
392 case ELM_TOOLBAR_SHRINK_HIDE: /* fallthrough */
393 case ELM_TOOLBAR_SHRINK_SCROLL: minw = w - vw; break;
394 case ELM_TOOLBAR_SHRINK_NONE: minw = minw_bx + (w - vw); break;
396 minh = minh + (h - vh);
397 evas_object_size_hint_min_set(obj, minw, minh);
398 evas_object_size_hint_max_set(obj, -1, -1);
402 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
404 item->o_menu = elm_menu_add(item->base.view);
406 elm_menu_parent_set(item->o_menu, wd->menu_parent);
407 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
409 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
414 _item_menu_destroy(Elm_Toolbar_Item *item)
418 evas_object_del(item->o_menu);
424 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
426 const Elm_Toolbar_Item *eti1 = i1;
427 const Elm_Toolbar_Item *eti2 = i2;
430 if (!eti1) return -1;
432 return eti2->prio.priority - eti1->prio.priority;
436 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
438 Elm_Toolbar_Item *it;
439 Eina_List *sorted = NULL;
442 EINA_INLIST_FOREACH(wd->items, it)
444 sorted = eina_list_sorted_insert(sorted,
445 _toolbar_item_prio_compare_cb, it);
450 evas_object_geometry_get(wd->more_item->base.view, NULL, NULL, &ciw, NULL);
453 EINA_LIST_FREE(sorted, it)
455 evas_object_geometry_get(it->base.view, NULL, NULL, &ciw, NULL);
457 it->prio.visible = (*iw <= vw);
462 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
464 Elm_Toolbar_Item *it = data;
465 if (it->func) it->func((void *)(it->base.data), it->base.widget, it);
469 _resize_job(void *data)
471 Widget_Data *wd = elm_widget_data_get(data);
472 Evas_Coord mw, mh, vw, vh, w, h;
473 Elm_Toolbar_Item *it;
474 Evas_Object *obj = (Evas_Object *) data;
477 wd->resize_job = NULL;
478 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
479 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
480 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
481 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
483 Evas_Coord iw = 0, more_w;
485 evas_object_resize(wd->bx, vw, h);
486 _fix_items_visibility(wd, &iw, vw);
487 evas_object_geometry_get(wd->more_item->base.view, NULL, NULL, &more_w, NULL);
488 if (iw - more_w <= vw)
491 /* All items are removed from the box object, since removing individual
492 * items won't trigger a resize. Items are be readded below. */
493 evas_object_box_remove_all(wd->bx, EINA_FALSE);
498 _item_menu_destroy(wd->more_item);
499 _item_menu_create(wd, wd->more_item);
500 menu = elm_toolbar_item_menu_get(wd->more_item);
502 EINA_INLIST_FOREACH(wd->items, it)
504 if (!it->prio.visible)
507 elm_menu_item_separator_add(menu, NULL);
511 item = elm_menu_item_add(menu, NULL, it->icon_str, it->label,
512 _elm_toolbar_item_menu_cb, it);
513 elm_menu_item_disabled_set(item, it->disabled);
514 if (it->o_menu) elm_menu_clone(it->o_menu, menu, item);
516 evas_object_hide(it->base.view);
520 evas_object_box_append(wd->bx, it->base.view);
521 evas_object_show(it->base.view);
525 evas_object_box_append(wd->bx, wd->more_item->base.view);
526 evas_object_show(wd->more_item->base.view);
530 /* All items are visible, show them all (except for the "More"
531 * button, of course). */
532 EINA_INLIST_FOREACH(wd->items, it)
534 evas_object_show(it->base.view);
535 evas_object_box_append(wd->bx, it->base.view);
537 evas_object_hide(wd->more_item->base.view);
540 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
544 evas_object_resize(wd->bx, vw, h);
545 _fix_items_visibility(wd, &iw, vw);
546 evas_object_box_remove_all(wd->bx, EINA_FALSE);
549 EINA_INLIST_FOREACH(wd->items, it)
551 if (!it->prio.visible)
552 evas_object_hide(it->base.view);
555 evas_object_box_append(wd->bx, it->base.view);
556 evas_object_show(it->base.view);
562 /* All items are visible, show them all */
563 EINA_INLIST_FOREACH(wd->items, it)
565 evas_object_show(it->base.view);
566 evas_object_box_append(wd->bx, it->base.view);
572 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
573 EINA_INLIST_FOREACH(wd->items, it)
583 _mirrored_set(obj, elm_widget_mirrored_get(obj));
587 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
590 _resize(data, NULL, NULL, NULL);
594 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
596 Widget_Data *wd = elm_widget_data_get(data);
598 wd->resize_job = ecore_job_add(_resize_job, data);
602 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
608 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
610 Elm_Toolbar_Item *it = data;
611 edje_object_signal_emit(it->base.view, "elm,state,highlighted", "elm");
612 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
616 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
618 Elm_Toolbar_Item *it = data;
619 edje_object_signal_emit(it->base.view, "elm,state,unhighlighted", "elm");
620 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
624 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
626 Evas_Object *obj = (Evas_Object *) data;
627 Widget_Data *wd = elm_widget_data_get(obj);
629 _els_box_layout(o, priv, 1, wd->homogeneous, elm_widget_mirrored_get(obj));
632 static Elm_Toolbar_Item *
633 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
635 Widget_Data *wd = elm_widget_data_get(obj);
636 Evas_Object *icon_obj;
638 Elm_Toolbar_Item *it;
640 icon_obj = elm_icon_add(obj);
641 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
642 if (!icon_obj) return NULL;
643 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
646 evas_object_del(icon_obj);
649 it->label = eina_stringshare_add(label);
650 it->prio.visible = 1;
651 it->prio.priority = 0;
653 it->separator = EINA_FALSE;
654 it->base.data = data;
655 it->base.view = edje_object_add(evas_object_evas_get(obj));
656 if (_item_icon_set(icon_obj, "toolbar/", icon))
659 it->icon_str = eina_stringshare_add(icon);
665 evas_object_del(icon_obj);
668 _elm_theme_object_set(obj, it->base.view, "toolbar", "item",
669 elm_widget_style_get(obj));
670 edje_object_signal_callback_add(it->base.view, "elm,action,click", "elm",
672 edje_object_signal_callback_add(it->base.view, "elm,mouse,in", "elm",
674 edje_object_signal_callback_add(it->base.view, "elm,mouse,out", "elm",
676 elm_widget_sub_object_add(obj, it->base.view);
681 ms = ((double)wd->icon_size * _elm_config->scale);
682 evas_object_size_hint_min_set(it->icon, ms, ms);
683 evas_object_size_hint_max_set(it->icon, ms, ms);
684 edje_object_part_swallow(it->base.view, "elm.swallow.icon", it->icon);
685 evas_object_show(it->icon);
686 elm_widget_sub_object_add(obj, it->icon);
688 edje_object_part_text_set(it->base.view, "elm.text", it->label);
690 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
691 edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw, mh);
692 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
693 evas_object_size_hint_weight_set(it->base.view, -1.0, EVAS_HINT_EXPAND);
694 evas_object_size_hint_align_set(it->base.view, 0.5, EVAS_HINT_FILL);
695 evas_object_size_hint_min_set(it->base.view, mw, mh);
696 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_RESIZE,
702 * Add a toolbar object to @p parent.
704 * @param parent The parent object
706 * @return The created object, or NULL on failure
711 elm_toolbar_add(Evas_Object *parent)
717 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
719 ELM_SET_WIDTYPE(widtype, "toolbar");
720 elm_widget_type_set(obj, "toolbar");
721 elm_widget_sub_object_add(parent, obj);
722 elm_widget_data_set(obj, wd);
723 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
724 elm_widget_del_hook_set(obj, _del_hook);
725 elm_widget_theme_hook_set(obj, _theme_hook);
726 elm_widget_can_focus_set(obj, EINA_FALSE);
728 wd->more_item = NULL;
729 wd->selected_item = NULL;
730 wd->scr = elm_smart_scroller_add(e);
731 elm_smart_scroller_widget_set(wd->scr, obj);
732 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
733 elm_smart_scroller_bounce_allow_set(wd->scr,
734 _elm_config->thumbscroll_bounce_enable,
736 elm_widget_resize_object_set(obj, wd->scr);
737 elm_smart_scroller_policy_set(wd->scr,
738 ELM_SMART_SCROLLER_POLICY_AUTO,
739 ELM_SMART_SCROLLER_POLICY_OFF);
742 wd->icon_size = _elm_toolbar_icon_size_get(wd);
745 wd->homogeneous = EINA_TRUE;
748 wd->bx = evas_object_box_add(e);
749 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
750 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
751 elm_widget_sub_object_add(obj, wd->bx);
752 elm_smart_scroller_child_set(wd->scr, wd->bx);
753 evas_object_show(wd->bx);
755 elm_toolbar_mode_shrink_set(obj, _elm_config->toolbar_shrink_mode);
756 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
757 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
758 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
760 evas_object_smart_callbacks_descriptions_set(obj, _signals);
767 * Set the icon size (in pixels) for the toolbar.
769 * @param obj The toolbar object
770 * @param icon_size The icon size in pixels
775 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
777 ELM_CHECK_WIDTYPE(obj, widtype);
778 Widget_Data *wd = elm_widget_data_get(obj);
780 if (wd->icon_size == icon_size) return;
781 wd->icon_size = icon_size;
786 * Get the icon size (in pixels) for the toolbar.
788 * @param obj The toolbar object
789 * @return The icon size in pixels
794 elm_toolbar_icon_size_get(const Evas_Object *obj)
796 ELM_CHECK_WIDTYPE(obj, widtype) 0;
797 Widget_Data *wd = elm_widget_data_get(obj);
799 return wd->icon_size;
803 * Append item to the toolbar
805 * @param obj The toolbar object
806 * @param icon A string with icon name or the absolute path of an image file.
807 * @param label The label of the item
808 * @param func The function to call when the item is clicked
809 * @param data The data to associate with the item
810 * @return The toolbar item, or NULL upon failure
812 * @see elm_toolbar_item_icon_set
816 EAPI Elm_Toolbar_Item *
817 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
819 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
820 Widget_Data *wd = elm_widget_data_get(obj);
821 if (!wd) return NULL;
823 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
824 if (!it) return NULL;
826 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
827 evas_object_box_append(wd->bx, it->base.view);
828 evas_object_show(it->base.view);
835 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
837 Elm_Toolbar_Item *it = event_info;
838 Elm_Toolbar_Item_State *it_state;
840 it_state = eina_list_data_get(it->current_state);
842 it_state->func((void *)it_state->data, obj, event_info);
846 * Sets the next @p item state as the current state.
848 * @param item The item.
852 EAPI Elm_Toolbar_Item_State *
853 elm_toolbar_item_state_next(Elm_Toolbar_Item *item)
857 Eina_List *next_state;
858 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
860 obj = item->base.widget;
861 wd = elm_widget_data_get(obj);
862 if (!wd) return NULL;
863 if (!item->states) return NULL;
865 next_state = eina_list_next(item->current_state);
867 next_state = eina_list_next(item->states);
868 return eina_list_data_get(next_state);
872 * Sets the previous @p item state as the current state.
874 * @param item The item.
878 EAPI Elm_Toolbar_Item_State *
879 elm_toolbar_item_state_prev(Elm_Toolbar_Item *item)
883 Eina_List *prev_state;
884 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
886 obj = item->base.widget;
887 wd = elm_widget_data_get(obj);
888 if (!wd) return NULL;
889 if (!item->states) return NULL;
891 prev_state = eina_list_prev(item->current_state);
892 if ((!prev_state) || (prev_state == item->states))
893 prev_state = eina_list_last(item->states);
894 return eina_list_data_get(prev_state);
898 * Unset the state of @p it
899 * The default icon and label from this item will be displayed.
901 * @param it The item.
906 elm_toolbar_item_state_unset(Elm_Toolbar_Item *it)
908 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
909 elm_toolbar_item_state_set(it, NULL);
913 * Sets @p state as the current state of @p it.
914 * If @p state is NULL, it won't select any state and the default icon and
915 * label will be used.
917 * @param it The item.
918 * @param state The state to use.
920 * @return True if the state was correctly set.
925 elm_toolbar_item_state_set(Elm_Toolbar_Item *it, Elm_Toolbar_Item_State *state)
928 Eina_List *next_state;
929 Elm_Toolbar_Item_State *it_state;
931 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
933 obj = it->base.widget;
934 wd = elm_widget_data_get(obj);
935 if (!wd) return EINA_FALSE;
936 if (!it->states) return EINA_FALSE;
940 next_state = eina_list_data_find_list(it->states, state);
941 if (!next_state) return EINA_FALSE;
944 next_state = it->states;
946 if (next_state == it->current_state) return EINA_TRUE;
948 it_state = eina_list_data_get(next_state);
949 if (eina_list_data_find(it->current_state, state))
951 _item_label_set(it, it_state->label, "elm,state,label_set,forward");
952 _elm_toolbar_item_icon_obj_set(obj, it, it_state->icon, it_state->icon_str,
953 wd->icon_size, "elm,state,icon_set,forward");
957 _item_label_set(it, it_state->label, "elm,state,label_set,backward");
958 _elm_toolbar_item_icon_obj_set(obj, it, it_state->icon, it_state->icon_str,
959 wd->icon_size, "elm,state,icon_set,backward");
962 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
964 elm_widget_signal_emit(it->icon, "elm,state,enabled", "elm");
966 it->current_state = next_state;
971 * Get the current state of @p item.
972 * If no state is selected, returns NULL.
974 * @param item The item.
980 EAPI Elm_Toolbar_Item_State *
981 elm_toolbar_item_state_get(const Elm_Toolbar_Item *it)
983 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
984 if ((!it->states) || (!it->current_state)) return NULL;
985 if (it->current_state == it->states) return NULL;
987 return eina_list_data_get(it->current_state);
990 static Elm_Toolbar_Item_State *
991 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
993 Elm_Toolbar_Item_State *it_state;
994 it_state = ELM_NEW(Elm_Toolbar_Item_State);
995 it_state->label = eina_stringshare_add(label);
996 it_state->icon_str = eina_stringshare_add(icon_str);
997 it_state->icon = icon;
998 it_state->func = func;
999 it_state->data = data;
1004 * Add a new state to @p item
1006 * @param item The item.
1007 * @param icon The icon string
1008 * @param label The label of the new state
1009 * @param func The function to call when the item is clicked when this state is
1011 * @param data The data to associate with the state
1012 * @return The toolbar item state, or NULL upon failure
1016 EAPI Elm_Toolbar_Item_State *
1017 elm_toolbar_item_state_add(Elm_Toolbar_Item *item, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1019 Elm_Toolbar_Item_State *it_state;
1020 Evas_Object *icon_obj;
1023 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1024 obj = item->base.widget;
1025 wd = elm_widget_data_get(item->base.widget);
1026 if (!wd) return NULL;
1030 it_state = _item_state_new(item->label, item->icon_str, item->icon,
1031 item->func, item->base.data);
1032 item->states = eina_list_append(item->states, it_state);
1033 item->current_state = item->states;
1036 icon_obj = elm_icon_add(obj);
1037 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1038 if (!icon_obj) goto error_state_add;
1040 if (!_item_icon_set(icon_obj, "toolbar/", icon))
1042 evas_object_del(icon_obj);
1047 it_state = _item_state_new(label, icon, icon_obj, func, data);
1048 item->states = eina_list_append(item->states, it_state);
1049 item->func = _elm_toolbar_item_state_cb;
1050 item->base.data = NULL;
1055 if (item->states && !eina_list_next(item->states))
1057 eina_stringshare_del(item->label);
1058 eina_stringshare_del(item->icon_str);
1059 free(eina_list_data_get(item->states));
1060 eina_list_free(item->states);
1061 item->states = NULL;
1067 elm_toolbar_item_state_del(Elm_Toolbar_Item *item, Elm_Toolbar_Item_State *state)
1069 Eina_List *del_state;
1070 Elm_Toolbar_Item_State *it_state;
1071 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1073 if (!state) return EINA_FALSE;
1074 if (!item->states) return EINA_FALSE;
1076 del_state = eina_list_data_find_list(item->states, state);
1077 if (del_state == item->states) return EINA_FALSE;
1078 if (del_state == item->current_state)
1079 elm_toolbar_item_state_unset(item);
1081 eina_stringshare_del(state->label);
1082 eina_stringshare_del(state->icon_str);
1083 if (state->icon) evas_object_del(state->icon);
1085 item->states = eina_list_remove_list(item->states, del_state);
1086 if (item->states && !eina_list_next(item->states))
1088 it_state = eina_list_data_get(item->states);
1089 item->base.data = it_state->data;
1090 item->func = it_state->func;
1091 eina_stringshare_del(it_state->label);
1092 eina_stringshare_del(it_state->icon_str);
1093 free(eina_list_data_get(item->states));
1094 eina_list_free(item->states);
1095 item->states = NULL;
1102 * Prepend item to the toolbar
1104 * @param obj The toolbar object
1105 * @param icon A string with icon name or the absolute path of an image file.
1106 * @param label The label of the item
1107 * @param func The function to call when the item is clicked
1108 * @param data The data to associate with the item
1109 * @return The toolbar item, or NULL upon failure
1111 * @see elm_toolbar_item_icon_set
1115 EAPI Elm_Toolbar_Item *
1116 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1118 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1119 Widget_Data *wd = elm_widget_data_get(obj);
1120 if (!wd) return NULL;
1122 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1123 if (!it) return NULL;
1125 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1126 evas_object_box_prepend(wd->bx, it->base.view);
1127 evas_object_show(it->base.view);
1134 * Insert item before another in the toolbar
1136 * @param obj The toolbar object
1137 * @param before The item to insert before
1138 * @param icon A string with icon name or the absolute path of an image file.
1139 * @param label The label of the item
1140 * @param func The function to call when the item is clicked
1141 * @param data The data to associate with the item
1142 * @return The toolbar item, or NULL upon failure
1144 * @see elm_toolbar_item_icon_set
1148 EAPI Elm_Toolbar_Item *
1149 elm_toolbar_item_insert_before(Evas_Object *obj, Elm_Toolbar_Item *before, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1151 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1152 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(before, NULL);
1153 Widget_Data *wd = elm_widget_data_get(obj);
1154 if (!wd) return NULL;
1156 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1157 if (!it) return NULL;
1159 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1160 EINA_INLIST_GET(before));
1161 evas_object_box_insert_before(wd->bx, it->base.view, before->base.view);
1162 evas_object_show(it->base.view);
1169 * Insert item after another in the toolbar
1171 * @param obj The toolbar object
1172 * @param after The item to insert after
1173 * @param icon A string with icon name or the absolute path of an image file.
1174 * @param label The label of the item
1175 * @param func The function to call when the item is clicked
1176 * @param data The data to associate with the item
1177 * @return The toolbar item, or NULL upon failure
1179 * @see elm_toolbar_item_icon_set
1183 EAPI Elm_Toolbar_Item *
1184 elm_toolbar_item_insert_after(Evas_Object *obj, Elm_Toolbar_Item *after, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1186 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1187 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(after, NULL);
1188 Widget_Data *wd = elm_widget_data_get(obj);
1189 if (!wd) return NULL;
1191 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1192 if (!it) return NULL;
1194 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1195 EINA_INLIST_GET(after));
1196 evas_object_box_insert_after(wd->bx, it->base.view, after->base.view);
1197 evas_object_show(it->base.view);
1204 * Get the first item in the toolbar
1206 * @param obj The toolbar object
1207 * @return The first item, or NULL if none
1211 EAPI Elm_Toolbar_Item *
1212 elm_toolbar_first_item_get(const Evas_Object *obj)
1214 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1215 Widget_Data *wd = elm_widget_data_get(obj);
1216 if (!wd || !wd->items) return NULL;
1217 Elm_Toolbar_Item *it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1222 * Get the last item in the toolbar
1224 * @return The last item, or NULL if none
1228 EAPI Elm_Toolbar_Item *
1229 elm_toolbar_last_item_get(const Evas_Object *obj)
1231 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1232 Widget_Data *wd = elm_widget_data_get(obj);
1233 if (!wd || !wd->items) return NULL;
1234 Elm_Toolbar_Item *it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1239 * Get the next item in the toolbar
1241 * This returns the item after the item @p it.
1243 * @param item The item
1244 * @return The item after @p it, or NULL if none
1248 EAPI Elm_Toolbar_Item *
1249 elm_toolbar_item_next_get(const Elm_Toolbar_Item *item)
1251 Elm_Toolbar_Item *next;
1252 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1253 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
1258 * Get the previous item in the toolbar
1260 * This returns the item before the item @p it.
1262 * @param item The item
1263 * @return The item before @p it, or NULL if none
1267 EAPI Elm_Toolbar_Item *
1268 elm_toolbar_item_prev_get(const Elm_Toolbar_Item *item)
1270 Elm_Toolbar_Item *prev;
1271 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1272 prev = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
1277 * Get the toolbar object from an item
1279 * This returns the toolbar object itself that an item belongs to.
1281 * @param item The item
1282 * @return The toolbar object
1287 elm_toolbar_item_toolbar_get(const Elm_Toolbar_Item *item)
1289 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1290 return item->base.widget;
1294 * Sets the priority of a toolbar item. This is used only when the toolbar
1295 * shrink mode is set to ELM_TOOLBAR_SHRINK_MENU or ELM_TOOLBAR_SHRINK_HIDE:
1296 * when space is at a premium, items with low priority will be removed from
1297 * the toolbar and added to a dynamically-created menu, while items with
1298 * higher priority will remain on the toolbar, with the same order they were
1301 * @param item The toolbar item.
1302 * @param priority The item priority. The default is zero.
1307 elm_toolbar_item_priority_set(Elm_Toolbar_Item *item, int priority)
1309 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1310 if (item->prio.priority == priority) return;
1311 item->prio.priority = priority;
1312 _resize(item->base.widget, NULL, NULL, NULL);
1316 * Gets the priority of a toolbar item.
1318 * @param item The toolbar item.
1319 * @return The item priority, or 0 if an error occurred.
1324 elm_toolbar_item_priority_get(const Elm_Toolbar_Item *item)
1326 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, 0);
1327 return item->prio.priority;
1331 * Get the string used to set the icon of @p item.
1333 * @param item The toolbar item
1334 * @return The string associated with the icon object.
1336 * @see elm_toolbar_item_icon_set()
1341 elm_toolbar_item_icon_get(const Elm_Toolbar_Item *item)
1343 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1344 return item->icon_str;
1348 * Get the label associated with @p item.
1350 * @param item The toolbar item
1356 elm_toolbar_item_label_get(const Elm_Toolbar_Item *item)
1358 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1363 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
1365 Evas_Coord mw = -1, mh = -1;
1366 edje_object_part_text_set(item->base.view, "elm.text", item->label);
1368 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1369 edje_object_size_min_restricted_calc(item->base.view, &mw, &mh, mw, mh);
1370 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1371 evas_object_size_hint_weight_set(item->base.view, -1.0, EVAS_HINT_EXPAND);
1372 evas_object_size_hint_align_set(item->base.view, 0.5, EVAS_HINT_FILL);
1373 evas_object_size_hint_min_set(item->base.view, mw, mh);
1377 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1379 Elm_Toolbar_Item *item = data;
1380 _elm_toolbar_item_label_update(item);
1381 edje_object_signal_callback_del(obj, emission, source,
1382 _elm_toolbar_item_label_set_cb);
1383 edje_object_signal_emit (item->base.view, "elm,state,label,reset", "elm");
1387 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal)
1391 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
1393 eina_stringshare_replace(&item->label, label);
1394 s = edje_object_data_get(item->base.view, "transition_animation_on");
1395 if ((s) && (atoi(s)))
1397 edje_object_part_text_set(item->base.view, "elm.text_new", item->label);
1398 edje_object_signal_emit (item->base.view, signal, "elm");
1399 edje_object_signal_callback_add(item->base.view,
1400 "elm,state,label_set,done", "elm",
1401 _elm_toolbar_item_label_set_cb, item);
1404 _elm_toolbar_item_label_update(item);
1405 _resize(item->base.widget, NULL, NULL, NULL);
1409 * Set the label associated with @p item.
1411 * @param item The toolbar item
1412 * @param label The label of @p item
1417 elm_toolbar_item_label_set(Elm_Toolbar_Item *item, const char *label)
1419 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1420 _item_label_set(item, label, "elm,state,label_set");
1424 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
1426 Elm_Toolbar_Item_State *it_state;
1428 Evas_Coord mw = -1, mh = -1;
1429 Evas_Object *old_icon = edje_object_part_swallow_get(item->base.view,
1430 "elm.swallow.icon");
1431 elm_widget_sub_object_del(item->base.view, old_icon);
1432 evas_object_hide(old_icon);
1433 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
1434 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1435 edje_object_size_min_restricted_calc(item->base.view, &mw, &mh, mw, mh);
1436 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1437 evas_object_size_hint_weight_set(item->base.view, -1.0, EVAS_HINT_EXPAND);
1438 evas_object_size_hint_align_set(item->base.view, 0.5, EVAS_HINT_FILL);
1439 evas_object_size_hint_min_set(item->base.view, mw, mh);
1441 EINA_LIST_FOREACH(item->states, l, it_state)
1442 if (it_state->icon == old_icon)
1444 evas_object_del(old_icon);
1448 * Get the selected state of @p item.
1450 * @param item The toolbar item
1451 * @return If true, the item is selected
1456 elm_toolbar_item_selected_get(const Elm_Toolbar_Item *item)
1458 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1459 return item->selected;
1463 * Set the selected state of an item
1465 * This sets the selected state (1 selected, 0 not selected) of the given
1466 * item @p it. If a new item is selected the previosly selected will be
1469 * @param item The item
1470 * @param selected The selected state
1475 elm_toolbar_item_selected_set(Elm_Toolbar_Item *item, Eina_Bool selected)
1477 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1478 Widget_Data *wd = elm_widget_data_get(item->base.widget);
1481 if (item->selected == selected) return;
1486 _item_unselect(item);
1490 * Get the selectd item in the toolbar
1492 * If no item is selected, NULL is returned.
1494 * @param obj The toolbar object
1495 * @return The selected item, or NULL if none.
1499 EAPI Elm_Toolbar_Item *
1500 elm_toolbar_selected_item_get(const Evas_Object *obj)
1502 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1503 Widget_Data *wd = elm_widget_data_get(obj);
1504 if (!wd) return NULL;
1505 return wd->selected_item;
1509 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1511 Elm_Toolbar_Item *item = data;
1512 edje_object_part_unswallow(item->base.view, item->icon);
1513 _elm_toolbar_item_icon_update(item);
1514 edje_object_signal_callback_del(obj, emission, source,
1515 _elm_toolbar_item_icon_set_cb);
1516 edje_object_signal_emit (item->base.view, "elm,state,icon,reset", "elm");
1520 _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)
1522 Evas_Object *old_icon;
1527 eina_stringshare_replace(&item->icon_str, icon_str);
1530 eina_stringshare_del(item->icon_str);
1531 item->icon_str = NULL;
1533 item->icon = icon_obj;
1536 ms = (icon_size * _elm_config->scale);
1537 evas_object_size_hint_min_set(item->icon, ms, ms);
1538 evas_object_size_hint_max_set(item->icon, ms, ms);
1539 evas_object_show(item->icon);
1540 elm_widget_sub_object_add(obj, item->icon);
1542 s = edje_object_data_get(item->base.view, "transition_animation_on");
1543 if ((s) && (atoi(s)))
1545 old_icon = edje_object_part_swallow_get(item->base.view,
1546 "elm.swallow.icon_new");
1549 elm_widget_sub_object_del(item->base.view, old_icon);
1550 evas_object_hide(old_icon);
1552 edje_object_part_swallow(item->base.view, "elm.swallow.icon_new",
1554 edje_object_signal_emit (item->base.view, signal, "elm");
1555 edje_object_signal_callback_add(item->base.view,
1556 "elm,state,icon_set,done", "elm",
1557 _elm_toolbar_item_icon_set_cb, item);
1560 _elm_toolbar_item_icon_update(item);
1561 _resize(obj, NULL, NULL, NULL);
1565 * Set the icon associated with @p item.
1567 * Toolbar will load icon image from fdo or current theme.
1568 * This behavior can be set by elm_toolbar_icon_order_lookup_set() function.
1569 * If an absolute path is provided it will load it direct from a file.
1571 * @param obj The parent of this item
1572 * @param item The toolbar item
1573 * @param icon A string with icon name or the absolute path of an image file.
1575 * @see elm_toolbar_icon_order_lookup_set(), elm_toolbar_icon_order_lookup_get()
1580 elm_toolbar_item_icon_set(Elm_Toolbar_Item *item, const char *icon)
1582 Evas_Object *icon_obj;
1584 Evas_Object *obj = item->base.widget;
1586 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1587 wd = elm_widget_data_get(obj);
1589 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1591 icon_obj = elm_icon_add(obj);
1592 if (!icon_obj) return;
1593 if (_item_icon_set(icon_obj, "toolbar/", icon))
1594 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1595 "elm,state,icon_set");
1598 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1599 "elm,state,icon_set");
1600 evas_object_del(icon_obj);
1605 * Delete a toolbar item.
1607 * @param item The toolbar item
1612 elm_toolbar_item_del(Elm_Toolbar_Item *item)
1617 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1618 wd = elm_widget_data_get(item->base.widget);
1620 obj2 = item->base.widget;
1621 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
1627 * Set the function called when a toolbar item is freed.
1629 * @param item The item to set the callback on
1630 * @param func The function called
1635 elm_toolbar_item_del_cb_set(Elm_Toolbar_Item *item, Evas_Smart_Cb func)
1637 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1638 elm_widget_item_del_cb_set(item, func);
1642 * Get the disabled state of @p item.
1644 * @param item The toolbar item
1645 * @return If true, the item is disabled
1650 elm_toolbar_item_disabled_get(const Elm_Toolbar_Item *item)
1652 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1653 return item->disabled;
1657 * Set the disabled state of @p item.
1659 * @param item The toolbar item
1660 * @param disabled If true, the item is disabled
1665 elm_toolbar_item_disabled_set(Elm_Toolbar_Item *item, Eina_Bool disabled)
1667 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1668 _item_disable(item, disabled);
1669 _resize(item->base.widget, NULL, NULL, NULL);
1673 * Get the separator state of @p item.
1675 * @param item The toolbar item
1676 * @param separator If true, the item is a separator
1681 elm_toolbar_item_separator_set(Elm_Toolbar_Item *item, Eina_Bool separator)
1683 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1684 if (item->separator == separator) return;
1685 item->separator = separator;
1686 _theme_hook(item->base.view);
1690 * Set the separator state of @p item.
1692 * @param item The toolbar item
1693 * @return If true, the item is a separator
1698 elm_toolbar_item_separator_get(const Elm_Toolbar_Item *item)
1700 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1701 return item->separator;
1705 * Set the shrink state of toolbar @p obj.
1707 * @param obj The toolbar object
1708 * @param shrink_mode The toolbar won't scroll if ELM_TOOLBAR_SHRINK_NONE,
1709 * but will enforce a minimun size so all the items will fit, won't scroll
1710 * and won't show the items that don't fit if ELM_TOOLBAR_SHRINK_HIDE,
1711 * will scroll if ELM_TOOLBAR_SHRINK_SCROLL, and will create a button to
1712 * pop up excess elements with ELM_TOOLBAR_SHRINK_MENU.
1717 elm_toolbar_mode_shrink_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1719 ELM_CHECK_WIDTYPE(obj, widtype);
1720 Widget_Data *wd = elm_widget_data_get(obj);
1724 wd->shrink_mode = shrink_mode;
1725 bounce = (_elm_config->thumbscroll_bounce_enable) &&
1726 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1727 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1731 _item_del(wd->more_item);
1732 wd->more_item = NULL;
1735 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1737 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF, ELM_SMART_SCROLLER_POLICY_OFF);
1739 wd->more_item = _item_new(obj, "more_menu", "More",
1742 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1743 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1744 ELM_SMART_SCROLLER_POLICY_OFF);
1746 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1747 ELM_SMART_SCROLLER_POLICY_OFF);
1752 * Get the shrink mode of toolbar @p obj.
1754 * @param obj The toolbar object
1755 * @return See elm_toolbar_mode_shrink_set.
1759 EAPI Elm_Toolbar_Shrink_Mode
1760 elm_toolbar_mode_shrink_get(const Evas_Object *obj)
1762 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1763 Widget_Data *wd = elm_widget_data_get(obj);
1765 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1766 return wd->shrink_mode;
1770 * Set the homogenous mode of toolbar @p obj.
1772 * @param obj The toolbar object
1773 * @param homogenous If true, the toolbar items will be uniform in size
1778 elm_toolbar_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
1780 ELM_CHECK_WIDTYPE(obj, widtype);
1781 Widget_Data *wd = elm_widget_data_get(obj);
1784 wd->homogeneous = !!homogenous;
1785 evas_object_smart_calculate(wd->bx);
1789 * Get the homogenous mode of toolbar @p obj.
1791 * @param obj The toolbar object
1792 * @return If true, the toolbar items are uniform in size
1797 elm_toolbar_homogenous_get(const Evas_Object *obj)
1799 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1800 Widget_Data *wd = elm_widget_data_get(obj);
1802 if (!wd) return EINA_FALSE;
1803 return wd->homogeneous;
1807 * Set the parent object of the toolbar menu
1809 * @param obj The toolbar object
1810 * @param parent The parent of the menu object
1815 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1817 Elm_Toolbar_Item *it;
1818 ELM_CHECK_WIDTYPE(obj, widtype);
1819 Widget_Data *wd = elm_widget_data_get(obj);
1822 EINA_SAFETY_ON_NULL_RETURN(parent);
1823 wd->menu_parent = parent;
1824 EINA_INLIST_FOREACH(wd->items, it)
1827 elm_menu_parent_set(it->o_menu, wd->menu_parent);
1829 if ((wd->more_item) && (wd->more_item->o_menu))
1830 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1834 * Get the parent object of the toolbar menu
1836 * @param obj The toolbar object
1837 * @return The parent of the menu object
1842 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1844 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1845 Widget_Data *wd = elm_widget_data_get(obj);
1847 if (!wd) return NULL;
1848 return wd->menu_parent;
1852 * Set the alignment of the items.
1854 * @param obj The toolbar object
1855 * @param align The new alignment. (left) 0.0 ... 1.0 (right)
1860 elm_toolbar_align_set(Evas_Object *obj, double align)
1862 ELM_CHECK_WIDTYPE(obj, widtype);
1863 Widget_Data *wd = elm_widget_data_get(obj);
1866 if (wd->align != align)
1867 evas_object_size_hint_align_set(wd->bx, align, 0.5);
1872 * Get the alignment of the items.
1874 * @param obj The toolbar object
1875 * @return The alignment. (left) 0.0 ... 1.0 (right)
1880 elm_toolbar_align_get(const Evas_Object *obj)
1882 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1883 Widget_Data *wd = elm_widget_data_get(obj);
1885 if (!wd) return 0.0;
1890 * Set whether the toolbar item opens a menu.
1892 * @param item The toolbar item
1893 * @param menu If true, @p item will open a menu when selected
1898 elm_toolbar_item_menu_set(Elm_Toolbar_Item *item, Eina_Bool menu)
1900 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1901 Widget_Data *wd = elm_widget_data_get(item->base.widget);
1904 if (item->menu == menu) return;
1906 if (menu) _item_menu_create(wd, item);
1907 else _item_menu_destroy(item);
1911 * Set the text to be shown in the toolbar item.
1913 * @param item Target item
1914 * @param text The text to set in the content
1916 * Setup the text as tooltip to object. The item can have only one tooltip,
1917 * so any previous tooltip data is removed.
1922 elm_toolbar_item_tooltip_text_set(Elm_Toolbar_Item *item, const char *text)
1924 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1925 elm_widget_item_tooltip_text_set(item, text);
1929 * Set the content to be shown in the tooltip item
1931 * Setup the tooltip to item. The item can have only one tooltip,
1932 * so any previous tooltip data is removed. @p func(with @p data) will
1933 * be called every time that need show the tooltip and it should
1934 * return a valid Evas_Object. This object is then managed fully by
1935 * tooltip system and is deleted when the tooltip is gone.
1937 * @param item the toolbar item being attached a tooltip.
1938 * @param func the function used to create the tooltip contents.
1939 * @param data what to provide to @a func as callback data/context.
1940 * @param del_cb called when data is not needed anymore, either when
1941 * another callback replaces @func, the tooltip is unset with
1942 * elm_toolbar_item_tooltip_unset() or the owner @a item
1943 * dies. This callback receives as the first parameter the
1944 * given @a data, and @c event_info is the item.
1949 elm_toolbar_item_tooltip_content_cb_set(Elm_Toolbar_Item *item, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
1951 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1952 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1956 * Unset tooltip from item
1958 * @param item toolbar item to remove previously set tooltip.
1960 * Remove tooltip from item. The callback provided as del_cb to
1961 * elm_toolbar_item_tooltip_content_cb_set() will be called to notify
1962 * it is not used anymore.
1964 * @see elm_toolbar_item_tooltip_content_cb_set()
1969 elm_toolbar_item_tooltip_unset(Elm_Toolbar_Item *item)
1971 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1972 elm_widget_item_tooltip_unset(item);
1976 * Sets a different style for this item tooltip.
1978 * @note before you set a style you should define a tooltip with
1979 * elm_toolbar_item_tooltip_content_cb_set() or
1980 * elm_toolbar_item_tooltip_text_set()
1982 * @param item toolbar item with tooltip already set.
1983 * @param style the theme style to use (default, transparent, ...)
1988 elm_toolbar_item_tooltip_style_set(Elm_Toolbar_Item *item, const char *style)
1990 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1991 elm_widget_item_tooltip_style_set(item, style);
1995 * Get the style for this item tooltip.
1997 * @param item toolbar item with tooltip already set.
1998 * @return style the theme style in use, defaults to "default". If the
1999 * object does not have a tooltip set, then NULL is returned.
2004 elm_toolbar_item_tooltip_style_get(const Elm_Toolbar_Item *item)
2006 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2007 return elm_widget_item_tooltip_style_get(item);
2011 * Set the cursor to be shown when mouse is over the toolbar item
2013 * @param item Target item
2014 * @param cursor the cursor name to be used.
2016 * @see elm_object_cursor_set()
2020 elm_toolbar_item_cursor_set(Elm_Toolbar_Item *item, const char *cursor)
2022 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2023 elm_widget_item_cursor_set(item, cursor);
2027 * Get the cursor to be shown when mouse is over the toolbar item
2029 * @param item toolbar item with cursor already set.
2030 * @return the cursor name.
2035 elm_toolbar_item_cursor_get(const Elm_Toolbar_Item *item)
2037 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2038 return elm_widget_item_cursor_get(item);
2042 * Unset the cursor to be shown when mouse is over the toolbar item
2044 * @param item Target item
2046 * @see elm_object_cursor_unset()
2050 elm_toolbar_item_cursor_unset(Elm_Toolbar_Item *item)
2052 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2053 elm_widget_item_cursor_unset(item);
2057 * Sets a different style for this item cursor.
2059 * @note before you set a style you should define a cursor with
2060 * elm_toolbar_item_cursor_set()
2062 * @param item toolbar item with cursor already set.
2063 * @param style the theme style to use (default, transparent, ...)
2068 elm_toolbar_item_cursor_style_set(Elm_Toolbar_Item *item, const char *style)
2070 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2071 elm_widget_item_cursor_style_set(item, style);
2075 * Get the style for this item cursor.
2077 * @param item toolbar item with cursor already set.
2078 * @return style the theme style in use, defaults to "default". If the
2079 * object does not have a cursor set, then NULL is returned.
2084 elm_toolbar_item_cursor_style_get(const Elm_Toolbar_Item *item)
2086 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2087 return elm_widget_item_cursor_style_get(item);
2091 * Set if the cursor set should be searched on the theme or should use
2092 * the provided by the engine, only.
2094 * @note before you set if should look on theme you should define a cursor
2095 * with elm_object_cursor_set(). By default it will only look for cursors
2096 * provided by the engine.
2098 * @param item widget item with cursor already set.
2099 * @param engine_only boolean to define it cursors should be looked only
2100 * between the provided by the engine or searched on widget's theme as well.
2105 elm_toolbar_item_cursor_engine_only_set(Elm_Toolbar_Item *item, Eina_Bool engine_only)
2107 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2108 elm_widget_item_cursor_engine_only_set(item, engine_only);
2112 * Get the cursor engine only usage for this item cursor.
2114 * @param item widget item with cursor already set.
2115 * @return engine_only boolean to define it cursors should be looked only
2116 * between the provided by the engine or searched on widget's theme as well. If
2117 * the object does not have a cursor set, then EINA_FALSE is returned.
2122 elm_toolbar_item_cursor_engine_only_get(const Elm_Toolbar_Item *item)
2124 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2125 return elm_widget_item_cursor_engine_only_get(item);
2129 * Get whether the toolbar item opens a menu.
2131 * @param item The toolbar item
2132 * @return If true, @p item opens a menu when selected
2137 elm_toolbar_item_menu_get(Elm_Toolbar_Item *item)
2139 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2140 Widget_Data *wd = elm_widget_data_get(item->base.widget);
2141 if (!wd) return NULL;
2142 /* FIXME: It's not ok. This function needs to be reviewed. And should
2143 * receive a const item */
2144 elm_toolbar_item_menu_set(item, 1);
2145 return item->o_menu;
2149 * Returns a pointer to a toolbar item by its label
2151 * @param obj The toolbar object
2152 * @param label The label of the item to find
2154 * @return The pointer to the toolbar item matching @p label
2155 * Returns NULL on failure.
2159 EAPI Elm_Toolbar_Item *
2160 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
2162 Elm_Toolbar_Item *it;
2163 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2164 Widget_Data *wd = elm_widget_data_get(obj);
2166 if (!wd) return NULL;
2167 EINA_INLIST_FOREACH(wd->items, it)
2169 if (!strcmp(it->label, label)) return it;
2176 * Set the data item from the toolbar item
2178 * This set the data value passed on the elm_toolbar_item_append() and
2179 * related item addition calls.
2181 * @param item The item
2182 * @param data The new data pointer to set
2187 elm_toolbar_item_data_set(Elm_Toolbar_Item *item, const void *data)
2189 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2190 elm_widget_item_data_set(item, data);
2194 * Get the data item from the toolbar item
2196 * This returns the data value passed on the elm_toolbar_item_append() and
2197 * related item addition calls.
2199 * @param item The item
2200 * @return The data pointer provided when created
2205 elm_toolbar_item_data_get(const Elm_Toolbar_Item *item)
2207 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2208 return elm_widget_item_data_get(item);
2212 * Set no select mode.
2214 * This will turn off the ability to select items entirely and they will
2215 * neither appear selected nor emit selected signals. The clicked
2216 * callback function will still be called.
2218 * @param obj The Toolbar object
2219 * @param no_select The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2224 elm_toolbar_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select)
2226 ELM_CHECK_WIDTYPE(obj, widtype);
2227 Widget_Data *wd = elm_widget_data_get(obj);
2229 wd->no_select = no_select;
2233 * Gets no select mode.
2235 * @param obj The Toolbar object
2236 * @return The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2241 elm_toolbar_no_select_mode_get(const Evas_Object *obj)
2243 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2244 Widget_Data *wd = elm_widget_data_get(obj);
2245 if (!wd) return EINA_FALSE;
2246 return wd->no_select;
2250 * Sets icon lookup order, for icons used in this toolbar.
2251 * Icons added before calling this function will not be affected.
2252 * The default lookup order is ELM_ICON_LOOKUP_THEME_FDO.
2254 * @param obj The toolbar object
2255 * @param order The icon lookup order
2260 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
2262 ELM_CHECK_WIDTYPE(obj, widtype);
2263 Elm_Toolbar_Item *it;
2264 Widget_Data *wd = elm_widget_data_get(obj);
2267 wd->lookup_order = order;
2268 EINA_INLIST_FOREACH(wd->items, it)
2269 elm_icon_order_lookup_set(it->icon, order);
2271 elm_icon_order_lookup_set(wd->more_item->icon, order);
2275 * Gets the icon lookup order.
2277 * @param obj The Toolbar object
2278 * @return The icon lookup order
2282 EAPI Elm_Icon_Lookup_Order
2283 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
2285 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
2286 Widget_Data *wd = elm_widget_data_get(obj);
2287 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
2288 return wd->lookup_order;