1 #include <Elementary.h>
5 * @defgroup Toolbar Toolbar
8 * A toolbar is a widget that displays a list of buttons inside
9 * a box. It is scrollable, and only one item can be selected at a time.
11 * Signals that you can add callbacks for are:
13 * "clicked" - when the user clicks on a toolbar item and becomes selected
17 typedef struct _Widget_Data Widget_Data;
21 Evas_Object *scr, *bx;
22 Evas_Object *menu_parent;
24 Elm_Toolbar_Item *more_item, *selected_item;
25 Elm_Toolbar_Shrink_Mode shrink_mode;
26 Elm_Icon_Lookup_Order lookup_order;
29 Eina_Bool homogeneous : 1;
30 Eina_Bool no_select : 1;
31 Ecore_Job *resize_job;
34 struct _Elm_Toolbar_Item
45 Eina_Bool visible : 1;
47 Eina_Bool selected : 1;
48 Eina_Bool disabled : 1;
49 Eina_Bool separator : 1;
52 Eina_List *current_state;
55 #define ELM_TOOLBAR_ITEM_FROM_INLIST(item) \
56 ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Toolbar_Item) : NULL)
58 struct _Elm_Toolbar_Item_State
67 static const char *widtype = NULL;
68 static void _item_show(Elm_Toolbar_Item *it);
69 static void _item_select(Elm_Toolbar_Item *it);
70 static void _item_unselect(Elm_Toolbar_Item *it);
71 static void _item_disable(Elm_Toolbar_Item *it, Eina_Bool disabled);
72 static void _del_pre_hook(Evas_Object *obj);
73 static void _del_hook(Evas_Object *obj);
74 static void _mirrored_set(Evas_Object *obj, Eina_Bool mirrored);
75 static void _mirrored_set_item(Evas_Object *obj, Elm_Toolbar_Item *it, Eina_Bool mirrored);
76 static void _theme_hook(Evas_Object *obj);
77 static void _sizing_eval(Evas_Object *obj);
78 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
79 static void _menu_move_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
80 static void _menu_hide(void *data, Evas *e, Evas_Object *obj, void *event_info);
81 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
82 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);
83 static void _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal);
86 _item_icon_set(Evas_Object *icon_obj, const char *type, const char *icon)
90 if ((!type) || (!*type)) goto end;
91 if ((!icon) || (!*icon)) return EINA_FALSE;
92 if ((snprintf(icon_str, sizeof(icon_str), "%s%s", type, icon) > 0)
93 && (elm_icon_standard_set(icon_obj, icon_str)))
96 if (elm_icon_standard_set(icon_obj, icon))
98 WRN("couldn't find icon definition for '%s'", icon);
103 _elm_toolbar_icon_size_get(Widget_Data *wd)
105 const char *icon_size = edje_object_data_get(
106 elm_smart_scroller_edje_object_get(wd->scr), "icon_size");
108 return atoi(icon_size);
109 return _elm_config->icon_size;
113 _item_show(Elm_Toolbar_Item *it)
115 Widget_Data *wd = elm_widget_data_get(it->base.widget);
116 Evas_Coord x, y, w, h, bx, by;
119 evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
120 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
121 elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
125 _item_unselect(Elm_Toolbar_Item *item)
128 if ((!item) || (!item->selected)) return;
129 wd = elm_widget_data_get(item->base.widget);
131 item->selected = EINA_FALSE;
132 wd->selected_item = NULL;
133 edje_object_signal_emit(item->base.view, "elm,state,unselected", "elm");
134 elm_widget_signal_emit(item->icon, "elm,state,unselected", "elm");
138 _item_select(Elm_Toolbar_Item *it)
140 Elm_Toolbar_Item *it2;
141 Widget_Data *wd = elm_widget_data_get(it->base.widget);
145 if ((it->selected) || (it->disabled) || (it->separator)) return;
149 it2 = elm_toolbar_selected_item_get(it->base.widget);
152 it->selected = EINA_TRUE;
153 wd->selected_item = it;
154 edje_object_signal_emit(it->base.view, "elm,state,selected", "elm");
155 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
158 obj2 = it->base.widget;
161 evas_object_show(it->o_menu);
162 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_RESIZE,
163 _menu_move_resize, it);
164 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOVE,
165 _menu_move_resize, it);
167 _menu_move_resize(it, NULL, NULL, NULL);
169 if (it->func) it->func((void *)(it->base.data), it->base.widget, it);
170 evas_object_smart_callback_call(obj2, "clicked", it);
174 _menu_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
176 Elm_Toolbar_Item *selected;
177 Elm_Toolbar_Item *it = data;
178 selected = elm_toolbar_selected_item_get(it->base.widget);
179 _item_unselect(selected);
183 _menu_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
185 // avoid hide being emitted during object deletion
186 evas_object_event_callback_del_full
187 (obj, EVAS_CALLBACK_HIDE, _menu_hide, data);
191 _menu_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
193 Elm_Toolbar_Item *it = data;
195 Widget_Data *wd = elm_widget_data_get(it->base.widget);
197 if ((!wd) || (!wd->menu_parent)) return;
198 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
199 elm_menu_move(it->o_menu, x, y+h);
203 _item_disable(Elm_Toolbar_Item *it, Eina_Bool disabled)
205 Widget_Data *wd = elm_widget_data_get(it->base.widget);
208 if (it->disabled == disabled) return;
209 it->disabled = disabled;
212 edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
213 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
217 edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
218 elm_widget_signal_emit(it->icon, "elm,state,enabled", "elm");
223 _item_del(Elm_Toolbar_Item *it)
225 Elm_Toolbar_Item_State *it_state;
227 elm_widget_item_pre_notify_del(it);
228 EINA_LIST_FREE(it->states, it_state)
230 if (it->icon == it_state->icon)
232 eina_stringshare_del(it_state->label);
233 eina_stringshare_del(it_state->icon_str);
234 if (it_state->icon) evas_object_del(it_state->icon);
237 eina_stringshare_del(it->label);
238 eina_stringshare_del(it->icon_str);
239 if (it->icon) evas_object_del(it->icon);
240 //TODO: See if checking for wd->menu_parent is necessary before deleting menu
241 if (it->o_menu) evas_object_del(it->o_menu);
242 elm_widget_item_del(it);
246 _del_pre_hook(Evas_Object *obj)
248 Widget_Data *wd = elm_widget_data_get(obj);
249 Elm_Toolbar_Item *it, *next;
252 it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
255 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
260 _item_del(wd->more_item);
264 _del_hook(Evas_Object *obj)
266 Widget_Data *wd = elm_widget_data_get(obj);
274 _mirrored_set_item(Evas_Object *obj __UNUSED__, Elm_Toolbar_Item *it, Eina_Bool mirrored)
276 edje_object_mirrored_set(it->base.view, mirrored);
277 elm_widget_mirrored_set(it->o_menu, mirrored);
281 _theme_hook_item(Evas_Object *obj, Elm_Toolbar_Item *it, double scale, int icon_size)
283 Evas_Object *view = it->base.view;
285 const char *style = elm_widget_style_get(obj);
287 _mirrored_set_item(obj, it, elm_widget_mirrored_get(obj));
288 edje_object_scale_set(view, scale);
291 _elm_theme_object_set(obj, view, "toolbar", "item", style);
294 edje_object_signal_emit(view, "elm,state,selected", "elm");
295 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
299 edje_object_signal_emit(view, "elm,state,disabled", "elm");
300 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
306 ms = ((double)icon_size * scale);
307 evas_object_size_hint_min_set(it->icon, ms, ms);
308 evas_object_size_hint_max_set(it->icon, ms, ms);
309 edje_object_part_swallow(view, "elm.swallow.icon",
312 edje_object_part_text_set(view, "elm.text", it->label);
315 _elm_theme_object_set(obj, view, "toolbar", "separator", style);
319 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
320 edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
322 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
323 evas_object_size_hint_min_set(view, mw, mh);
327 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
329 Widget_Data *wd = elm_widget_data_get(obj);
330 Elm_Toolbar_Item *it;
332 EINA_INLIST_FOREACH(wd->items, it)
333 _mirrored_set_item(obj, it, mirrored);
335 _mirrored_set_item(obj, wd->more_item, mirrored);
339 _theme_hook(Evas_Object *obj)
341 Widget_Data *wd = elm_widget_data_get(obj);
342 Elm_Toolbar_Item *it;
346 _elm_widget_mirrored_reload(obj);
347 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
348 _mirrored_set(obj, elm_widget_mirrored_get(obj));
349 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
350 edje_object_scale_set(wd->scr, scale);
351 wd->icon_size = _elm_toolbar_icon_size_get(wd);
352 EINA_INLIST_FOREACH(wd->items, it)
353 _theme_hook_item(obj, it, scale, wd->icon_size);
355 _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
360 _sizing_eval(Evas_Object *obj)
362 Widget_Data *wd = elm_widget_data_get(obj);
363 Evas_Coord minw = -1, minh = -1, minw_bx;
364 Evas_Coord vw = 0, vh = 0;
368 evas_object_smart_calculate(wd->bx);
369 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
371 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
372 if (w < minw) w = minw;
373 if (h < minh) h = minh;
375 evas_object_resize(wd->scr, w, h);
377 evas_object_size_hint_min_get(wd->bx, &minw, &minh);
379 if (w > minw) minw = w;
380 evas_object_resize(wd->bx, minw, minh);
381 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
382 switch (wd->shrink_mode)
384 case ELM_TOOLBAR_SHRINK_MENU: /* fallthrough */
385 case ELM_TOOLBAR_SHRINK_HIDE: /* fallthrough */
386 case ELM_TOOLBAR_SHRINK_SCROLL: minw = w - vw; break;
387 case ELM_TOOLBAR_SHRINK_NONE: minw = minw_bx + (w - vw); break;
389 minh = minh + (h - vh);
390 evas_object_size_hint_min_set(obj, minw, minh);
391 evas_object_size_hint_max_set(obj, -1, -1);
395 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
397 item->o_menu = elm_menu_add(item->base.view);
399 elm_menu_parent_set(item->o_menu, wd->menu_parent);
400 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
402 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
407 _item_menu_destroy(Elm_Toolbar_Item *item)
411 evas_object_del(item->o_menu);
417 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
419 const Elm_Toolbar_Item *eti1 = i1;
420 const Elm_Toolbar_Item *eti2 = i2;
423 if (!eti1) return -1;
425 return eti2->prio.priority - eti1->prio.priority;
429 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
431 Elm_Toolbar_Item *it;
432 Eina_List *sorted = NULL;
435 EINA_INLIST_FOREACH(wd->items, it)
437 sorted = eina_list_sorted_insert(sorted,
438 _toolbar_item_prio_compare_cb, it);
443 evas_object_geometry_get(wd->more_item->base.view, NULL, NULL, &ciw, NULL);
446 EINA_LIST_FREE(sorted, it)
448 evas_object_geometry_get(it->base.view, NULL, NULL, &ciw, NULL);
450 it->prio.visible = (*iw <= vw);
455 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
457 Elm_Toolbar_Item *it = data;
458 if (it->func) it->func((void *)(it->base.data), it->base.widget, it);
462 _resize_job(void *data)
464 Widget_Data *wd = elm_widget_data_get(data);
465 Evas_Coord mw, mh, vw, vh, w, h;
466 Elm_Toolbar_Item *it;
467 Evas_Object *obj = (Evas_Object *) data;
470 wd->resize_job = NULL;
471 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
472 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
473 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
474 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
476 Evas_Coord iw = 0, more_w;
478 evas_object_resize(wd->bx, vw, h);
479 _fix_items_visibility(wd, &iw, vw);
480 evas_object_geometry_get(wd->more_item->base.view, NULL, NULL, &more_w, NULL);
481 if (iw - more_w <= vw)
484 /* All items are removed from the box object, since removing individual
485 * items won't trigger a resize. Items are be readded below. */
486 evas_object_box_remove_all(wd->bx, EINA_FALSE);
491 _item_menu_destroy(wd->more_item);
492 _item_menu_create(wd, wd->more_item);
493 menu = elm_toolbar_item_menu_get(wd->more_item);
495 EINA_INLIST_FOREACH(wd->items, it)
497 if (!it->prio.visible)
500 elm_menu_item_separator_add(menu, NULL);
504 item = elm_menu_item_add(menu, NULL, it->icon_str, it->label,
505 _elm_toolbar_item_menu_cb, it);
506 elm_menu_item_disabled_set(item, it->disabled);
507 if (it->o_menu) elm_menu_clone(it->o_menu, menu, item);
509 evas_object_hide(it->base.view);
513 evas_object_box_append(wd->bx, it->base.view);
514 evas_object_show(it->base.view);
518 evas_object_box_append(wd->bx, wd->more_item->base.view);
519 evas_object_show(wd->more_item->base.view);
523 /* All items are visible, show them all (except for the "More"
524 * button, of course). */
525 EINA_INLIST_FOREACH(wd->items, it)
527 evas_object_show(it->base.view);
528 evas_object_box_append(wd->bx, it->base.view);
530 evas_object_hide(wd->more_item->base.view);
533 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
537 evas_object_resize(wd->bx, vw, h);
538 _fix_items_visibility(wd, &iw, vw);
539 evas_object_box_remove_all(wd->bx, EINA_FALSE);
542 EINA_INLIST_FOREACH(wd->items, it)
544 if (!it->prio.visible)
545 evas_object_hide(it->base.view);
548 evas_object_box_append(wd->bx, it->base.view);
549 evas_object_show(it->base.view);
555 /* All items are visible, show them all */
556 EINA_INLIST_FOREACH(wd->items, it)
558 evas_object_show(it->base.view);
559 evas_object_box_append(wd->bx, it->base.view);
565 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
566 EINA_INLIST_FOREACH(wd->items, it)
576 _mirrored_set(obj, elm_widget_mirrored_get(obj));
580 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
583 _resize(data, NULL, NULL, NULL);
587 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
589 Widget_Data *wd = elm_widget_data_get(data);
591 wd->resize_job = ecore_job_add(_resize_job, data);
595 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
601 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
603 Elm_Toolbar_Item *it = data;
604 edje_object_signal_emit(it->base.view, "elm,state,highlighted", "elm");
605 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
609 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
611 Elm_Toolbar_Item *it = data;
612 edje_object_signal_emit(it->base.view, "elm,state,unhighlighted", "elm");
613 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
617 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
619 Evas_Object *obj = (Evas_Object *) data;
620 Widget_Data *wd = elm_widget_data_get(obj);
622 //_els_box_layout(o, priv, 1, wd->homogeneous, elm_widget_mirrored_get(obj));
625 static Elm_Toolbar_Item *
626 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
628 Widget_Data *wd = elm_widget_data_get(obj);
629 Evas_Object *icon_obj;
631 Elm_Toolbar_Item *it;
633 icon_obj = elm_icon_add(obj);
634 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
635 if (!icon_obj) return NULL;
636 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
639 evas_object_del(icon_obj);
642 it->label = eina_stringshare_add(label);
643 it->prio.visible = 1;
644 it->prio.priority = 0;
646 it->separator = EINA_FALSE;
647 it->base.data = data;
648 it->base.view = edje_object_add(evas_object_evas_get(obj));
649 if (_item_icon_set(icon_obj, "toolbar/", icon))
652 it->icon_str = eina_stringshare_add(icon);
658 evas_object_del(icon_obj);
661 _elm_theme_object_set(obj, it->base.view, "toolbar", "item",
662 elm_widget_style_get(obj));
663 edje_object_signal_callback_add(it->base.view, "elm,action,click", "elm",
665 edje_object_signal_callback_add(it->base.view, "elm,mouse,in", "elm",
667 edje_object_signal_callback_add(it->base.view, "elm,mouse,out", "elm",
669 elm_widget_sub_object_add(obj, it->base.view);
674 ms = ((double)wd->icon_size * _elm_config->scale);
675 evas_object_size_hint_min_set(it->icon, ms, ms);
676 evas_object_size_hint_max_set(it->icon, ms, ms);
677 edje_object_part_swallow(it->base.view, "elm.swallow.icon", it->icon);
678 evas_object_show(it->icon);
679 elm_widget_sub_object_add(obj, it->icon);
681 edje_object_part_text_set(it->base.view, "elm.text", it->label);
683 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
684 edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw, mh);
685 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
686 evas_object_size_hint_weight_set(it->base.view, -1.0, EVAS_HINT_EXPAND);
687 evas_object_size_hint_align_set(it->base.view, 0.5, EVAS_HINT_FILL);
688 evas_object_size_hint_min_set(it->base.view, mw, mh);
689 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_RESIZE,
695 * Add a toolbar object to @p parent.
697 * @param parent The parent object
699 * @return The created object, or NULL on failure
704 elm_toolbar_add(Evas_Object *parent)
710 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
712 ELM_SET_WIDTYPE(widtype, "toolbar");
713 elm_widget_type_set(obj, "toolbar");
714 elm_widget_sub_object_add(parent, obj);
715 elm_widget_data_set(obj, wd);
716 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
717 elm_widget_del_hook_set(obj, _del_hook);
718 elm_widget_theme_hook_set(obj, _theme_hook);
719 elm_widget_can_focus_set(obj, EINA_FALSE);
721 wd->more_item = NULL;
722 wd->selected_item = NULL;
723 wd->scr = elm_smart_scroller_add(e);
724 elm_smart_scroller_widget_set(wd->scr, obj);
725 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
726 elm_smart_scroller_bounce_allow_set(wd->scr,
727 _elm_config->thumbscroll_bounce_enable,
729 elm_widget_resize_object_set(obj, wd->scr);
730 elm_smart_scroller_policy_set(wd->scr,
731 ELM_SMART_SCROLLER_POLICY_AUTO,
732 ELM_SMART_SCROLLER_POLICY_OFF);
735 wd->icon_size = _elm_toolbar_icon_size_get(wd);
738 wd->homogeneous = EINA_TRUE;
741 wd->bx = evas_object_box_add(e);
742 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
743 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
744 elm_widget_sub_object_add(obj, wd->bx);
745 elm_smart_scroller_child_set(wd->scr, wd->bx);
746 evas_object_show(wd->bx);
748 elm_toolbar_mode_shrink_set(obj, _elm_config->toolbar_shrink_mode);
749 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
750 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
751 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
758 * Set the icon size (in pixels) for the toolbar.
760 * @param obj The toolbar object
761 * @param icon_size The icon size in pixels
766 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
768 ELM_CHECK_WIDTYPE(obj, widtype);
769 Widget_Data *wd = elm_widget_data_get(obj);
771 if (wd->icon_size == icon_size) return;
772 wd->icon_size = icon_size;
777 * Get the icon size (in pixels) for the toolbar.
779 * @param obj The toolbar object
780 * @return The icon size in pixels
785 elm_toolbar_icon_size_get(const Evas_Object *obj)
787 ELM_CHECK_WIDTYPE(obj, widtype) 0;
788 Widget_Data *wd = elm_widget_data_get(obj);
790 return wd->icon_size;
794 * Append item to the toolbar
796 * @param obj The toolbar object
797 * @param icon A string with icon name or the absolute path of an image file.
798 * @param label The label of the item
799 * @param func The function to call when the item is clicked
800 * @param data The data to associate with the item
801 * @return The toolbar item, or NULL upon failure
803 * @see elm_toolbar_item_icon_set
807 EAPI Elm_Toolbar_Item *
808 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
810 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
811 Widget_Data *wd = elm_widget_data_get(obj);
812 if (!wd) return NULL;
814 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
815 if (!it) return NULL;
817 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
818 evas_object_box_append(wd->bx, it->base.view);
819 evas_object_show(it->base.view);
826 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
828 Elm_Toolbar_Item *it = event_info;
829 Elm_Toolbar_Item_State *it_state;
831 it_state = eina_list_data_get(it->current_state);
833 it_state->func((void *)it_state->data, obj, event_info);
837 * Sets the next @p item state as the current state.
839 * @param item The item.
843 EAPI Elm_Toolbar_Item_State *
844 elm_toolbar_item_state_next(Elm_Toolbar_Item *item)
848 Eina_List *next_state;
849 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
851 obj = item->base.widget;
852 wd = elm_widget_data_get(obj);
853 if (!wd) return NULL;
854 if (!item->states) return NULL;
856 next_state = eina_list_next(item->current_state);
858 next_state = eina_list_next(item->states);
859 return eina_list_data_get(next_state);
863 * Sets the previous @p item state as the current state.
865 * @param item The item.
869 EAPI Elm_Toolbar_Item_State *
870 elm_toolbar_item_state_prev(Elm_Toolbar_Item *item)
874 Eina_List *prev_state;
875 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
877 obj = item->base.widget;
878 wd = elm_widget_data_get(obj);
879 if (!wd) return NULL;
880 if (!item->states) return NULL;
882 prev_state = eina_list_prev(item->current_state);
883 if ((!prev_state) || (prev_state == item->states))
884 prev_state = eina_list_last(item->states);
885 return eina_list_data_get(prev_state);
889 * Unset the state of @p it
890 * The default icon and label from this item will be displayed.
892 * @param it The item.
897 elm_toolbar_item_state_unset(Elm_Toolbar_Item *it)
899 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
900 elm_toolbar_item_state_set(it, NULL);
904 * Sets @p state as the current state of @p it.
905 * If @p state is NULL, it won't select any state and the default icon and
906 * label will be used.
908 * @param it The item.
909 * @param state The state to use.
911 * @return True if the state was correctly set.
916 elm_toolbar_item_state_set(Elm_Toolbar_Item *it, Elm_Toolbar_Item_State *state)
919 Eina_List *next_state;
920 Elm_Toolbar_Item_State *it_state;
922 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
924 obj = it->base.widget;
925 wd = elm_widget_data_get(obj);
926 if (!wd) return EINA_FALSE;
927 if (!it->states) return EINA_FALSE;
931 next_state = eina_list_data_find_list(it->states, state);
932 if (!next_state) return EINA_FALSE;
935 next_state = it->states;
937 if (next_state == it->current_state) return EINA_TRUE;
939 it_state = eina_list_data_get(next_state);
940 if (eina_list_data_find(it->current_state, state))
942 _item_label_set(it, it_state->label, "elm,state,label_set,forward");
943 _elm_toolbar_item_icon_obj_set(obj, it, it_state->icon, it_state->icon_str,
944 wd->icon_size, "elm,state,icon_set,forward");
948 _item_label_set(it, it_state->label, "elm,state,label_set,backward");
949 _elm_toolbar_item_icon_obj_set(obj, it, it_state->icon, it_state->icon_str,
950 wd->icon_size, "elm,state,icon_set,backward");
953 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
955 elm_widget_signal_emit(it->icon, "elm,state,enabled", "elm");
957 it->current_state = next_state;
962 * Get the current state of @p item.
963 * If no state is selected, returns NULL.
965 * @param item The item.
971 EAPI Elm_Toolbar_Item_State *
972 elm_toolbar_item_state_get(const Elm_Toolbar_Item *it)
974 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
975 if ((!it->states) || (!it->current_state)) return NULL;
976 if (it->current_state == it->states) return NULL;
978 return eina_list_data_get(it->current_state);
981 static Elm_Toolbar_Item_State *
982 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
984 Elm_Toolbar_Item_State *it_state;
985 it_state = ELM_NEW(Elm_Toolbar_Item_State);
986 it_state->label = eina_stringshare_add(label);
987 it_state->icon_str = eina_stringshare_add(icon_str);
988 it_state->icon = icon;
989 it_state->func = func;
990 it_state->data = data;
995 * Add a new state to @p item
997 * @param item The item.
998 * @param icon The icon string
999 * @param label The label of the new state
1000 * @param func The function to call when the item is clicked when this state is
1002 * @param data The data to associate with the state
1003 * @return The toolbar item state, or NULL upon failure
1007 EAPI Elm_Toolbar_Item_State *
1008 elm_toolbar_item_state_add(Elm_Toolbar_Item *item, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1010 Elm_Toolbar_Item_State *it_state;
1011 Evas_Object *icon_obj;
1014 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1015 obj = item->base.widget;
1016 wd = elm_widget_data_get(item->base.widget);
1017 if (!wd) return NULL;
1021 it_state = _item_state_new(item->label, item->icon_str, item->icon,
1022 item->func, item->base.data);
1023 item->states = eina_list_append(item->states, it_state);
1024 item->current_state = item->states;
1027 icon_obj = elm_icon_add(obj);
1028 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1029 if (!icon_obj) goto error_state_add;
1031 if (!_item_icon_set(icon_obj, "toolbar/", icon))
1033 evas_object_del(icon_obj);
1038 it_state = _item_state_new(label, icon, icon_obj, func, data);
1039 item->states = eina_list_append(item->states, it_state);
1040 item->func = _elm_toolbar_item_state_cb;
1041 item->base.data = NULL;
1046 if (item->states && !eina_list_next(item->states))
1048 eina_stringshare_del(item->label);
1049 eina_stringshare_del(item->icon_str);
1050 free(eina_list_data_get(item->states));
1051 eina_list_free(item->states);
1052 item->states = NULL;
1058 elm_toolbar_item_state_del(Elm_Toolbar_Item *item, Elm_Toolbar_Item_State *state)
1060 Eina_List *del_state;
1061 Elm_Toolbar_Item_State *it_state;
1062 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1064 if (!state) return EINA_FALSE;
1065 if (!item->states) return EINA_FALSE;
1067 del_state = eina_list_data_find_list(item->states, state);
1068 if (del_state == item->states) return EINA_FALSE;
1069 if (del_state == item->current_state)
1070 elm_toolbar_item_state_unset(item);
1072 eina_stringshare_del(state->label);
1073 eina_stringshare_del(state->icon_str);
1074 if (state->icon) evas_object_del(state->icon);
1076 item->states = eina_list_remove_list(item->states, del_state);
1077 if (item->states && !eina_list_next(item->states))
1079 it_state = eina_list_data_get(item->states);
1080 item->base.data = it_state->data;
1081 item->func = it_state->func;
1082 eina_stringshare_del(it_state->label);
1083 eina_stringshare_del(it_state->icon_str);
1084 free(eina_list_data_get(item->states));
1085 eina_list_free(item->states);
1086 item->states = NULL;
1093 * Prepend item to the toolbar
1095 * @param obj The toolbar object
1096 * @param icon A string with icon name or the absolute path of an image file.
1097 * @param label The label of the item
1098 * @param func The function to call when the item is clicked
1099 * @param data The data to associate with the item
1100 * @return The toolbar item, or NULL upon failure
1102 * @see elm_toolbar_item_icon_set
1106 EAPI Elm_Toolbar_Item *
1107 elm_toolbar_item_prepend(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;
1116 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1117 evas_object_box_prepend(wd->bx, it->base.view);
1118 evas_object_show(it->base.view);
1125 * Insert item before another in the toolbar
1127 * @param obj The toolbar object
1128 * @param before The item to insert before
1129 * @param icon A string with icon name or the absolute path of an image file.
1130 * @param label The label of the item
1131 * @param func The function to call when the item is clicked
1132 * @param data The data to associate with the item
1133 * @return The toolbar item, or NULL upon failure
1135 * @see elm_toolbar_item_icon_set
1139 EAPI Elm_Toolbar_Item *
1140 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)
1142 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1143 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(before, NULL);
1144 Widget_Data *wd = elm_widget_data_get(obj);
1145 if (!wd) return NULL;
1147 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1148 if (!it) return NULL;
1150 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1151 EINA_INLIST_GET(before));
1152 evas_object_box_insert_before(wd->bx, it->base.view, before->base.view);
1153 evas_object_show(it->base.view);
1160 * Insert item after another in the toolbar
1162 * @param obj The toolbar object
1163 * @param after The item to insert after
1164 * @param icon A string with icon name or the absolute path of an image file.
1165 * @param label The label of the item
1166 * @param func The function to call when the item is clicked
1167 * @param data The data to associate with the item
1168 * @return The toolbar item, or NULL upon failure
1170 * @see elm_toolbar_item_icon_set
1174 EAPI Elm_Toolbar_Item *
1175 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)
1177 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1178 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(after, NULL);
1179 Widget_Data *wd = elm_widget_data_get(obj);
1180 if (!wd) return NULL;
1182 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1183 if (!it) return NULL;
1185 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1186 EINA_INLIST_GET(after));
1187 evas_object_box_insert_after(wd->bx, it->base.view, after->base.view);
1188 evas_object_show(it->base.view);
1195 * Get the first item in the toolbar
1197 * @param obj The toolbar object
1198 * @return The first item, or NULL if none
1202 EAPI Elm_Toolbar_Item *
1203 elm_toolbar_first_item_get(const Evas_Object *obj)
1205 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1206 Widget_Data *wd = elm_widget_data_get(obj);
1207 if (!wd || !wd->items) return NULL;
1208 Elm_Toolbar_Item *it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1213 * Get the last item in the toolbar
1215 * @return The last item, or NULL if none
1219 EAPI Elm_Toolbar_Item *
1220 elm_toolbar_last_item_get(const Evas_Object *obj)
1222 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1223 Widget_Data *wd = elm_widget_data_get(obj);
1224 if (!wd || !wd->items) return NULL;
1225 Elm_Toolbar_Item *it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1230 * Get the next item in the toolbar
1232 * This returns the item after the item @p it.
1234 * @param item The item
1235 * @return The item after @p it, or NULL if none
1239 EAPI Elm_Toolbar_Item *
1240 elm_toolbar_item_next_get(const Elm_Toolbar_Item *item)
1242 Elm_Toolbar_Item *next;
1243 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1244 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
1249 * Get the previous item in the toolbar
1251 * This returns the item before the item @p it.
1253 * @param item The item
1254 * @return The item before @p it, or NULL if none
1258 EAPI Elm_Toolbar_Item *
1259 elm_toolbar_item_prev_get(const Elm_Toolbar_Item *item)
1261 Elm_Toolbar_Item *prev;
1262 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1263 prev = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
1268 * Get the toolbar object from an item
1270 * This returns the toolbar object itself that an item belongs to.
1272 * @param item The item
1273 * @return The toolbar object
1278 elm_toolbar_item_toolbar_get(const Elm_Toolbar_Item *item)
1280 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1281 return item->base.widget;
1285 * Sets the priority of a toolbar item. This is used only when the toolbar
1286 * shrink mode is set to ELM_TOOLBAR_SHRINK_MENU or ELM_TOOLBAR_SHRINK_HIDE:
1287 * when space is at a premium, items with low priority will be removed from
1288 * the toolbar and added to a dynamically-created menu, while items with
1289 * higher priority will remain on the toolbar, with the same order they were
1292 * @param item The toolbar item.
1293 * @param priority The item priority. The default is zero.
1298 elm_toolbar_item_priority_set(Elm_Toolbar_Item *item, int priority)
1300 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1301 if (item->prio.priority == priority) return;
1302 item->prio.priority = priority;
1303 _resize(item->base.widget, NULL, NULL, NULL);
1307 * Gets the priority of a toolbar item.
1309 * @param item The toolbar item.
1310 * @return The item priority, or 0 if an error occurred.
1315 elm_toolbar_item_priority_get(const Elm_Toolbar_Item *item)
1317 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, 0);
1318 return item->prio.priority;
1322 * Get the string used to set the icon of @p item.
1324 * @param item The toolbar item
1325 * @return The string associated with the icon object.
1327 * @see elm_toolbar_item_icon_set()
1332 elm_toolbar_item_icon_get(const Elm_Toolbar_Item *item)
1334 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1335 return item->icon_str;
1339 * Get the label associated with @p item.
1341 * @param item The toolbar item
1347 elm_toolbar_item_label_get(const Elm_Toolbar_Item *item)
1349 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1354 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
1356 Evas_Coord mw = -1, mh = -1;
1357 edje_object_part_text_set(item->base.view, "elm.text", item->label);
1359 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1360 edje_object_size_min_restricted_calc(item->base.view, &mw, &mh, mw, mh);
1361 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1362 evas_object_size_hint_weight_set(item->base.view, -1.0, EVAS_HINT_EXPAND);
1363 evas_object_size_hint_align_set(item->base.view, 0.5, EVAS_HINT_FILL);
1364 evas_object_size_hint_min_set(item->base.view, mw, mh);
1368 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1370 Elm_Toolbar_Item *item = data;
1371 _elm_toolbar_item_label_update(item);
1372 edje_object_signal_callback_del(obj, emission, source,
1373 _elm_toolbar_item_label_set_cb);
1374 edje_object_signal_emit (item->base.view, "elm,state,label,reset", "elm");
1378 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal)
1382 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
1384 eina_stringshare_replace(&item->label, label);
1385 s = edje_object_data_get(item->base.view, "transition_animation_on");
1386 if ((s) && (atoi(s)))
1388 edje_object_part_text_set(item->base.view, "elm.text_new", item->label);
1389 edje_object_signal_emit (item->base.view, signal, "elm");
1390 edje_object_signal_callback_add(item->base.view,
1391 "elm,state,label_set,done", "elm",
1392 _elm_toolbar_item_label_set_cb, item);
1395 _elm_toolbar_item_label_update(item);
1396 _resize(item->base.widget, NULL, NULL, NULL);
1400 * Set the label associated with @p item.
1402 * @param item The toolbar item
1403 * @param label The label of @p item
1408 elm_toolbar_item_label_set(Elm_Toolbar_Item *item, const char *label)
1410 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1411 _item_label_set(item, label, "elm,state,label_set");
1415 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
1417 Elm_Toolbar_Item_State *it_state;
1419 Evas_Coord mw = -1, mh = -1;
1420 Evas_Object *old_icon = edje_object_part_swallow_get(item->base.view,
1421 "elm.swallow.icon");
1422 elm_widget_sub_object_del(item->base.view, old_icon);
1423 evas_object_hide(old_icon);
1424 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
1425 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1426 edje_object_size_min_restricted_calc(item->base.view, &mw, &mh, mw, mh);
1427 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1428 evas_object_size_hint_weight_set(item->base.view, -1.0, EVAS_HINT_EXPAND);
1429 evas_object_size_hint_align_set(item->base.view, 0.5, EVAS_HINT_FILL);
1430 evas_object_size_hint_min_set(item->base.view, mw, mh);
1432 EINA_LIST_FOREACH(item->states, l, it_state)
1433 if (it_state->icon == old_icon)
1435 evas_object_del(old_icon);
1439 * Get the selected state of @p item.
1441 * @param item The toolbar item
1442 * @return If true, the item is selected
1447 elm_toolbar_item_selected_get(const Elm_Toolbar_Item *item)
1449 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1450 return item->selected;
1454 * Set the selected state of an item
1456 * This sets the selected state (1 selected, 0 not selected) of the given
1457 * item @p it. If a new item is selected the previosly selected will be
1460 * @param item The item
1461 * @param selected The selected state
1466 elm_toolbar_item_selected_set(Elm_Toolbar_Item *item, Eina_Bool selected)
1468 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1469 Widget_Data *wd = elm_widget_data_get(item->base.widget);
1472 if (item->selected == selected) return;
1477 _item_unselect(item);
1481 * Get the selectd item in the toolbar
1483 * If no item is selected, NULL is returned.
1485 * @param obj The toolbar object
1486 * @return The selected item, or NULL if none.
1490 EAPI Elm_Toolbar_Item *
1491 elm_toolbar_selected_item_get(const Evas_Object *obj)
1493 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1494 Widget_Data *wd = elm_widget_data_get(obj);
1495 if (!wd) return NULL;
1496 return wd->selected_item;
1500 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1502 Elm_Toolbar_Item *item = data;
1503 edje_object_part_unswallow(item->base.view, item->icon);
1504 _elm_toolbar_item_icon_update(item);
1505 edje_object_signal_callback_del(obj, emission, source,
1506 _elm_toolbar_item_icon_set_cb);
1507 edje_object_signal_emit (item->base.view, "elm,state,icon,reset", "elm");
1511 _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)
1513 Evas_Object *old_icon;
1518 eina_stringshare_replace(&item->icon_str, icon_str);
1521 eina_stringshare_del(item->icon_str);
1522 item->icon_str = NULL;
1524 item->icon = icon_obj;
1527 ms = (icon_size * _elm_config->scale);
1528 evas_object_size_hint_min_set(item->icon, ms, ms);
1529 evas_object_size_hint_max_set(item->icon, ms, ms);
1530 evas_object_show(item->icon);
1531 elm_widget_sub_object_add(obj, item->icon);
1533 s = edje_object_data_get(item->base.view, "transition_animation_on");
1534 if ((s) && (atoi(s)))
1536 old_icon = edje_object_part_swallow_get(item->base.view,
1537 "elm.swallow.icon_new");
1540 elm_widget_sub_object_del(item->base.view, old_icon);
1541 evas_object_hide(old_icon);
1543 edje_object_part_swallow(item->base.view, "elm.swallow.icon_new",
1545 edje_object_signal_emit (item->base.view, signal, "elm");
1546 edje_object_signal_callback_add(item->base.view,
1547 "elm,state,icon_set,done", "elm",
1548 _elm_toolbar_item_icon_set_cb, item);
1551 _elm_toolbar_item_icon_update(item);
1552 _resize(obj, NULL, NULL, NULL);
1556 * Set the icon associated with @p item.
1558 * Toolbar will load icon image from fdo or current theme.
1559 * This behavior can be set by elm_toolbar_icon_order_lookup_set() function.
1560 * If an absolute path is provided it will load it direct from a file.
1562 * @param obj The parent of this item
1563 * @param item The toolbar item
1564 * @param icon A string with icon name or the absolute path of an image file.
1566 * @see elm_toolbar_icon_order_lookup_set(), elm_toolbar_icon_order_lookup_get()
1571 elm_toolbar_item_icon_set(Elm_Toolbar_Item *item, const char *icon)
1573 Evas_Object *icon_obj;
1575 Evas_Object *obj = item->base.widget;
1577 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1578 wd = elm_widget_data_get(obj);
1580 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1582 icon_obj = elm_icon_add(obj);
1583 if (!icon_obj) return;
1584 if (_item_icon_set(icon_obj, "toolbar/", icon))
1585 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1586 "elm,state,icon_set");
1589 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1590 "elm,state,icon_set");
1591 evas_object_del(icon_obj);
1596 * Delete a toolbar item.
1598 * @param item The toolbar item
1603 elm_toolbar_item_del(Elm_Toolbar_Item *item)
1608 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1609 wd = elm_widget_data_get(item->base.widget);
1611 obj2 = item->base.widget;
1612 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
1618 * Set the function called when a toolbar item is freed.
1620 * @param item The item to set the callback on
1621 * @param func The function called
1626 elm_toolbar_item_del_cb_set(Elm_Toolbar_Item *item, Evas_Smart_Cb func)
1628 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1629 elm_widget_item_del_cb_set(item, func);
1633 * Get the disabled state of @p item.
1635 * @param item The toolbar item
1636 * @return If true, the item is disabled
1641 elm_toolbar_item_disabled_get(const Elm_Toolbar_Item *item)
1643 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1644 return item->disabled;
1648 * Set the disabled state of @p item.
1650 * @param item The toolbar item
1651 * @param disabled If true, the item is disabled
1656 elm_toolbar_item_disabled_set(Elm_Toolbar_Item *item, Eina_Bool disabled)
1658 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1659 _item_disable(item, disabled);
1660 _resize(item->base.widget, NULL, NULL, NULL);
1664 * Get the separator state of @p item.
1666 * @param item The toolbar item
1667 * @param separator If true, the item is a separator
1672 elm_toolbar_item_separator_set(Elm_Toolbar_Item *item, Eina_Bool separator)
1674 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1675 if (item->separator == separator) return;
1676 item->separator = separator;
1677 _theme_hook(item->base.view);
1681 * Set the separator state of @p item.
1683 * @param item The toolbar item
1684 * @return If true, the item is a separator
1689 elm_toolbar_item_separator_get(const Elm_Toolbar_Item *item)
1691 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1692 return item->separator;
1696 * Set the shrink state of toolbar @p obj.
1698 * @param obj The toolbar object
1699 * @param shrink_mode The toolbar won't scroll if ELM_TOOLBAR_SHRINK_NONE,
1700 * but will enforce a minimun size so all the items will fit, won't scroll
1701 * and won't show the items that don't fit if ELM_TOOLBAR_SHRINK_HIDE,
1702 * will scroll if ELM_TOOLBAR_SHRINK_SCROLL, and will create a button to
1703 * pop up excess elements with ELM_TOOLBAR_SHRINK_MENU.
1708 elm_toolbar_mode_shrink_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1710 ELM_CHECK_WIDTYPE(obj, widtype);
1711 Widget_Data *wd = elm_widget_data_get(obj);
1715 wd->shrink_mode = shrink_mode;
1716 bounce = (_elm_config->thumbscroll_bounce_enable) &&
1717 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1718 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1722 _item_del(wd->more_item);
1723 wd->more_item = NULL;
1726 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1728 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF, ELM_SMART_SCROLLER_POLICY_OFF);
1730 wd->more_item = _item_new(obj, "more_menu", "More",
1733 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1734 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1735 ELM_SMART_SCROLLER_POLICY_OFF);
1737 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1738 ELM_SMART_SCROLLER_POLICY_OFF);
1743 * Get the shrink mode of toolbar @p obj.
1745 * @param obj The toolbar object
1746 * @return See elm_toolbar_mode_shrink_set.
1750 EAPI Elm_Toolbar_Shrink_Mode
1751 elm_toolbar_mode_shrink_get(const Evas_Object *obj)
1753 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1754 Widget_Data *wd = elm_widget_data_get(obj);
1756 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1757 return wd->shrink_mode;
1761 * Set the homogenous mode of toolbar @p obj.
1763 * @param obj The toolbar object
1764 * @param homogenous If true, the toolbar items will be uniform in size
1769 elm_toolbar_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
1771 ELM_CHECK_WIDTYPE(obj, widtype);
1772 Widget_Data *wd = elm_widget_data_get(obj);
1775 wd->homogeneous = !!homogenous;
1776 evas_object_smart_calculate(wd->bx);
1780 * Get the homogenous mode of toolbar @p obj.
1782 * @param obj The toolbar object
1783 * @return If true, the toolbar items are uniform in size
1788 elm_toolbar_homogenous_get(const Evas_Object *obj)
1790 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1791 Widget_Data *wd = elm_widget_data_get(obj);
1793 if (!wd) return EINA_FALSE;
1794 return wd->homogeneous;
1798 * Set the parent object of the toolbar menu
1800 * @param obj The toolbar object
1801 * @param parent The parent of the menu object
1806 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1808 Elm_Toolbar_Item *it;
1809 ELM_CHECK_WIDTYPE(obj, widtype);
1810 Widget_Data *wd = elm_widget_data_get(obj);
1813 EINA_SAFETY_ON_NULL_RETURN(parent);
1814 wd->menu_parent = parent;
1815 EINA_INLIST_FOREACH(wd->items, it)
1818 elm_menu_parent_set(it->o_menu, wd->menu_parent);
1820 if ((wd->more_item) && (wd->more_item->o_menu))
1821 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1825 * Get the parent object of the toolbar menu
1827 * @param obj The toolbar object
1828 * @return The parent of the menu object
1833 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1835 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1836 Widget_Data *wd = elm_widget_data_get(obj);
1838 if (!wd) return NULL;
1839 return wd->menu_parent;
1843 * Set the alignment of the items.
1845 * @param obj The toolbar object
1846 * @param align The new alignment. (left) 0.0 ... 1.0 (right)
1851 elm_toolbar_align_set(Evas_Object *obj, double align)
1853 ELM_CHECK_WIDTYPE(obj, widtype);
1854 Widget_Data *wd = elm_widget_data_get(obj);
1857 if (wd->align != align)
1858 evas_object_size_hint_align_set(wd->bx, align, 0.5);
1863 * Get the alignment of the items.
1865 * @param obj The toolbar object
1866 * @return The alignment. (left) 0.0 ... 1.0 (right)
1871 elm_toolbar_align_get(const Evas_Object *obj)
1873 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1874 Widget_Data *wd = elm_widget_data_get(obj);
1876 if (!wd) return 0.0;
1881 * Set whether the toolbar item opens a menu.
1883 * @param item The toolbar item
1884 * @param menu If true, @p item will open a menu when selected
1889 elm_toolbar_item_menu_set(Elm_Toolbar_Item *item, Eina_Bool menu)
1891 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1892 Widget_Data *wd = elm_widget_data_get(item->base.widget);
1895 if (item->menu == menu) return;
1897 if (menu) _item_menu_create(wd, item);
1898 else _item_menu_destroy(item);
1902 * Set the text to be shown in the toolbar item.
1904 * @param item Target item
1905 * @param text The text to set in the content
1907 * Setup the text as tooltip to object. The item can have only one tooltip,
1908 * so any previous tooltip data is removed.
1913 elm_toolbar_item_tooltip_text_set(Elm_Toolbar_Item *item, const char *text)
1915 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1916 elm_widget_item_tooltip_text_set(item, text);
1920 * Set the content to be shown in the tooltip item
1922 * Setup the tooltip to item. The item can have only one tooltip,
1923 * so any previous tooltip data is removed. @p func(with @p data) will
1924 * be called every time that need show the tooltip and it should
1925 * return a valid Evas_Object. This object is then managed fully by
1926 * tooltip system and is deleted when the tooltip is gone.
1928 * @param item the toolbar item being attached a tooltip.
1929 * @param func the function used to create the tooltip contents.
1930 * @param data what to provide to @a func as callback data/context.
1931 * @param del_cb called when data is not needed anymore, either when
1932 * another callback replaces @func, the tooltip is unset with
1933 * elm_toolbar_item_tooltip_unset() or the owner @a item
1934 * dies. This callback receives as the first parameter the
1935 * given @a data, and @c event_info is the item.
1940 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)
1942 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1943 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1947 * Unset tooltip from item
1949 * @param item toolbar item to remove previously set tooltip.
1951 * Remove tooltip from item. The callback provided as del_cb to
1952 * elm_toolbar_item_tooltip_content_cb_set() will be called to notify
1953 * it is not used anymore.
1955 * @see elm_toolbar_item_tooltip_content_cb_set()
1960 elm_toolbar_item_tooltip_unset(Elm_Toolbar_Item *item)
1962 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1963 elm_widget_item_tooltip_unset(item);
1967 * Sets a different style for this item tooltip.
1969 * @note before you set a style you should define a tooltip with
1970 * elm_toolbar_item_tooltip_content_cb_set() or
1971 * elm_toolbar_item_tooltip_text_set()
1973 * @param item toolbar item with tooltip already set.
1974 * @param style the theme style to use (default, transparent, ...)
1979 elm_toolbar_item_tooltip_style_set(Elm_Toolbar_Item *item, const char *style)
1981 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1982 elm_widget_item_tooltip_style_set(item, style);
1986 * Get the style for this item tooltip.
1988 * @param item toolbar item with tooltip already set.
1989 * @return style the theme style in use, defaults to "default". If the
1990 * object does not have a tooltip set, then NULL is returned.
1995 elm_toolbar_item_tooltip_style_get(const Elm_Toolbar_Item *item)
1997 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1998 return elm_widget_item_tooltip_style_get(item);
2002 * Set the cursor to be shown when mouse is over the toolbar item
2004 * @param item Target item
2005 * @param cursor the cursor name to be used.
2007 * @see elm_object_cursor_set()
2011 elm_toolbar_item_cursor_set(Elm_Toolbar_Item *item, const char *cursor)
2013 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2014 elm_widget_item_cursor_set(item, cursor);
2018 * Get the cursor to be shown when mouse is over the toolbar item
2020 * @param item toolbar item with cursor already set.
2021 * @return the cursor name.
2026 elm_toolbar_item_cursor_get(const Elm_Toolbar_Item *item)
2028 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2029 return elm_widget_item_cursor_get(item);
2033 * Unset the cursor to be shown when mouse is over the toolbar item
2035 * @param item Target item
2037 * @see elm_object_cursor_unset()
2041 elm_toolbar_item_cursor_unset(Elm_Toolbar_Item *item)
2043 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2044 elm_widget_item_cursor_unset(item);
2048 * Sets a different style for this item cursor.
2050 * @note before you set a style you should define a cursor with
2051 * elm_toolbar_item_cursor_set()
2053 * @param item toolbar item with cursor already set.
2054 * @param style the theme style to use (default, transparent, ...)
2059 elm_toolbar_item_cursor_style_set(Elm_Toolbar_Item *item, const char *style)
2061 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2062 elm_widget_item_cursor_style_set(item, style);
2066 * Get the style for this item cursor.
2068 * @param item toolbar item with cursor already set.
2069 * @return style the theme style in use, defaults to "default". If the
2070 * object does not have a cursor set, then NULL is returned.
2075 elm_toolbar_item_cursor_style_get(const Elm_Toolbar_Item *item)
2077 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2078 return elm_widget_item_cursor_style_get(item);
2082 * Set if the cursor set should be searched on the theme or should use
2083 * the provided by the engine, only.
2085 * @note before you set if should look on theme you should define a cursor
2086 * with elm_object_cursor_set(). By default it will only look for cursors
2087 * provided by the engine.
2089 * @param item widget item with cursor already set.
2090 * @param engine_only boolean to define it cursors should be looked only
2091 * between the provided by the engine or searched on widget's theme as well.
2096 elm_toolbar_item_cursor_engine_only_set(Elm_Toolbar_Item *item, Eina_Bool engine_only)
2098 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2099 elm_widget_item_cursor_engine_only_set(item, engine_only);
2103 * Get the cursor engine only usage for this item cursor.
2105 * @param item widget item with cursor already set.
2106 * @return engine_only boolean to define it cursors should be looked only
2107 * between the provided by the engine or searched on widget's theme as well. If
2108 * the object does not have a cursor set, then EINA_FALSE is returned.
2113 elm_toolbar_item_cursor_engine_only_get(const Elm_Toolbar_Item *item)
2115 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2116 return elm_widget_item_cursor_engine_only_get(item);
2120 * Get whether the toolbar item opens a menu.
2122 * @param item The toolbar item
2123 * @return If true, @p item opens a menu when selected
2128 elm_toolbar_item_menu_get(Elm_Toolbar_Item *item)
2130 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2131 Widget_Data *wd = elm_widget_data_get(item->base.widget);
2132 if (!wd) return NULL;
2133 /* FIXME: It's not ok. This function needs to be reviewed. And should
2134 * receive a const item */
2135 elm_toolbar_item_menu_set(item, 1);
2136 return item->o_menu;
2140 * Returns a pointer to a toolbar item by its label
2142 * @param obj The toolbar object
2143 * @param label The label of the item to find
2145 * @return The pointer to the toolbar item matching @p label
2146 * Returns NULL on failure.
2150 EAPI Elm_Toolbar_Item *
2151 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
2153 Elm_Toolbar_Item *it;
2154 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2155 Widget_Data *wd = elm_widget_data_get(obj);
2157 if (!wd) return NULL;
2158 EINA_INLIST_FOREACH(wd->items, it)
2160 if (!strcmp(it->label, label)) return it;
2167 * Set the data item from the toolbar item
2169 * This set the data value passed on the elm_toolbar_item_append() and
2170 * related item addition calls.
2172 * @param item The item
2173 * @param data The new data pointer to set
2178 elm_toolbar_item_data_set(Elm_Toolbar_Item *item, const void *data)
2180 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2181 elm_widget_item_data_set(item, data);
2185 * Get the data item from the toolbar item
2187 * This returns the data value passed on the elm_toolbar_item_append() and
2188 * related item addition calls.
2190 * @param item The item
2191 * @return The data pointer provided when created
2196 elm_toolbar_item_data_get(const Elm_Toolbar_Item *item)
2198 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2199 return elm_widget_item_data_get(item);
2203 * Set no select mode.
2205 * This will turn off the ability to select items entirely and they will
2206 * neither appear selected nor emit selected signals. The clicked
2207 * callback function will still be called.
2209 * @param obj The Toolbar object
2210 * @param no_select The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2215 elm_toolbar_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select)
2217 ELM_CHECK_WIDTYPE(obj, widtype);
2218 Widget_Data *wd = elm_widget_data_get(obj);
2220 wd->no_select = no_select;
2224 * Gets no select mode.
2226 * @param obj The Toolbar object
2227 * @return The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2232 elm_toolbar_no_select_mode_get(const Evas_Object *obj)
2234 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2235 Widget_Data *wd = elm_widget_data_get(obj);
2236 if (!wd) return EINA_FALSE;
2237 return wd->no_select;
2241 * Sets icon lookup order, for icons used in this toolbar.
2242 * Icons added before calling this function will not be affected.
2243 * The default lookup order is ELM_ICON_LOOKUP_THEME_FDO.
2245 * @param obj The toolbar object
2246 * @param order The icon lookup order
2251 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
2253 ELM_CHECK_WIDTYPE(obj, widtype);
2254 Elm_Toolbar_Item *it;
2255 Widget_Data *wd = elm_widget_data_get(obj);
2258 wd->lookup_order = order;
2259 EINA_INLIST_FOREACH(wd->items, it)
2260 elm_icon_order_lookup_set(it->icon, order);
2262 elm_icon_order_lookup_set(wd->more_item->icon, order);
2266 * Gets the icon lookup order.
2268 * @param obj The Toolbar object
2269 * @return The icon lookup order
2273 EAPI Elm_Icon_Lookup_Order
2274 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
2276 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
2277 Widget_Data *wd = elm_widget_data_get(obj);
2278 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
2279 return wd->lookup_order;