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);
85 static const char SIG_CLICKED[] = "clicked";
87 static const Evas_Smart_Cb_Description _signals[] = {
94 _item_icon_set(Evas_Object *icon_obj, const char *type, const char *icon)
98 if ((!type) || (!*type)) goto end;
99 if ((!icon) || (!*icon)) return EINA_FALSE;
100 if ((snprintf(icon_str, sizeof(icon_str), "%s%s", type, icon) > 0)
101 && (elm_icon_standard_set(icon_obj, icon_str)))
104 if (elm_icon_standard_set(icon_obj, icon))
106 WRN("couldn't find icon definition for '%s'", icon);
111 _elm_toolbar_icon_size_get(Widget_Data *wd)
113 const char *icon_size = edje_object_data_get(
114 elm_smart_scroller_edje_object_get(wd->scr), "icon_size");
116 return atoi(icon_size);
117 return _elm_config->icon_size;
121 _item_show(Elm_Toolbar_Item *it)
123 Widget_Data *wd = elm_widget_data_get(it->base.widget);
124 Evas_Coord x, y, w, h, bx, by;
127 evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
128 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
129 elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
133 _item_unselect(Elm_Toolbar_Item *item)
136 if ((!item) || (!item->selected)) return;
137 wd = elm_widget_data_get(item->base.widget);
139 item->selected = EINA_FALSE;
140 wd->selected_item = NULL;
141 edje_object_signal_emit(item->base.view, "elm,state,unselected", "elm");
142 elm_widget_signal_emit(item->icon, "elm,state,unselected", "elm");
146 _item_select(Elm_Toolbar_Item *it)
148 Elm_Toolbar_Item *it2;
149 Widget_Data *wd = elm_widget_data_get(it->base.widget);
153 if ((it->selected) || (it->disabled) || (it->separator)) return;
157 it2 = elm_toolbar_selected_item_get(it->base.widget);
160 it->selected = EINA_TRUE;
161 wd->selected_item = it;
162 edje_object_signal_emit(it->base.view, "elm,state,selected", "elm");
163 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
166 obj2 = it->base.widget;
169 evas_object_show(it->o_menu);
170 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_RESIZE,
171 _menu_move_resize, it);
172 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOVE,
173 _menu_move_resize, it);
175 _menu_move_resize(it, NULL, NULL, NULL);
177 if (it->func) it->func((void *)(it->base.data), it->base.widget, it);
178 evas_object_smart_callback_call(obj2, SIG_CLICKED, it);
182 _menu_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
184 Elm_Toolbar_Item *selected;
185 Elm_Toolbar_Item *it = data;
186 selected = elm_toolbar_selected_item_get(it->base.widget);
187 _item_unselect(selected);
191 _menu_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
193 // avoid hide being emitted during object deletion
194 evas_object_event_callback_del_full
195 (obj, EVAS_CALLBACK_HIDE, _menu_hide, data);
199 _menu_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
201 Elm_Toolbar_Item *it = data;
203 Widget_Data *wd = elm_widget_data_get(it->base.widget);
205 if ((!wd) || (!wd->menu_parent)) return;
206 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
207 elm_menu_move(it->o_menu, x, y+h);
211 _item_disable(Elm_Toolbar_Item *it, Eina_Bool disabled)
213 Widget_Data *wd = elm_widget_data_get(it->base.widget);
216 if (it->disabled == disabled) return;
217 it->disabled = !!disabled;
220 edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
221 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
225 edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
226 elm_widget_signal_emit(it->icon, "elm,state,enabled", "elm");
231 _item_del(Elm_Toolbar_Item *it)
233 Elm_Toolbar_Item_State *it_state;
235 elm_widget_item_pre_notify_del(it);
236 EINA_LIST_FREE(it->states, it_state)
238 if (it->icon == it_state->icon)
240 eina_stringshare_del(it_state->label);
241 eina_stringshare_del(it_state->icon_str);
242 if (it_state->icon) evas_object_del(it_state->icon);
245 eina_stringshare_del(it->label);
246 eina_stringshare_del(it->icon_str);
247 if (it->icon) evas_object_del(it->icon);
248 //TODO: See if checking for wd->menu_parent is necessary before deleting menu
249 if (it->o_menu) evas_object_del(it->o_menu);
250 elm_widget_item_del(it);
254 _del_pre_hook(Evas_Object *obj)
256 Widget_Data *wd = elm_widget_data_get(obj);
257 Elm_Toolbar_Item *it, *next;
260 it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
263 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
268 _item_del(wd->more_item);
272 _del_hook(Evas_Object *obj)
274 Widget_Data *wd = elm_widget_data_get(obj);
282 _mirrored_set_item(Evas_Object *obj __UNUSED__, Elm_Toolbar_Item *it, Eina_Bool mirrored)
284 edje_object_mirrored_set(it->base.view, mirrored);
285 elm_widget_mirrored_set(it->o_menu, mirrored);
289 _theme_hook_item(Evas_Object *obj, Elm_Toolbar_Item *it, double scale, int icon_size)
291 Evas_Object *view = it->base.view;
293 const char *style = elm_widget_style_get(obj);
295 _mirrored_set_item(obj, it, elm_widget_mirrored_get(obj));
296 edje_object_scale_set(view, scale);
299 _elm_theme_object_set(obj, view, "toolbar", "item", style);
302 edje_object_signal_emit(view, "elm,state,selected", "elm");
303 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
307 edje_object_signal_emit(view, "elm,state,disabled", "elm");
308 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
314 ms = ((double)icon_size * scale);
315 evas_object_size_hint_min_set(it->icon, ms, ms);
316 evas_object_size_hint_max_set(it->icon, ms, ms);
317 edje_object_part_swallow(view, "elm.swallow.icon",
320 edje_object_part_text_set(view, "elm.text", it->label);
323 _elm_theme_object_set(obj, view, "toolbar", "separator", style);
327 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
328 edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
330 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
331 evas_object_size_hint_min_set(view, mw, mh);
335 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
337 Widget_Data *wd = elm_widget_data_get(obj);
338 Elm_Toolbar_Item *it;
340 EINA_INLIST_FOREACH(wd->items, it)
341 _mirrored_set_item(obj, it, mirrored);
343 _mirrored_set_item(obj, wd->more_item, mirrored);
347 _theme_hook(Evas_Object *obj)
349 Widget_Data *wd = elm_widget_data_get(obj);
350 Elm_Toolbar_Item *it;
354 _elm_widget_mirrored_reload(obj);
355 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
356 _mirrored_set(obj, elm_widget_mirrored_get(obj));
357 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
358 edje_object_scale_set(wd->scr, scale);
359 wd->icon_size = _elm_toolbar_icon_size_get(wd);
360 EINA_INLIST_FOREACH(wd->items, it)
361 _theme_hook_item(obj, it, scale, wd->icon_size);
363 _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
368 _sizing_eval(Evas_Object *obj)
370 Widget_Data *wd = elm_widget_data_get(obj);
371 Evas_Coord minw = -1, minh = -1, minw_bx;
372 Evas_Coord vw = 0, vh = 0;
376 evas_object_smart_calculate(wd->bx);
377 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
379 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
380 if (w < minw) w = minw;
381 if (h < minh) h = minh;
383 evas_object_resize(wd->scr, w, h);
385 evas_object_size_hint_min_get(wd->bx, &minw, &minh);
387 if (w > minw) minw = w;
388 evas_object_resize(wd->bx, minw, minh);
389 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
390 switch (wd->shrink_mode)
392 case ELM_TOOLBAR_SHRINK_MENU: /* fallthrough */
393 case ELM_TOOLBAR_SHRINK_HIDE: /* fallthrough */
394 case ELM_TOOLBAR_SHRINK_SCROLL: minw = w - vw; break;
395 case ELM_TOOLBAR_SHRINK_NONE: minw = minw_bx + (w - vw); break;
397 minh = minh + (h - vh);
398 evas_object_size_hint_min_set(obj, minw, minh);
399 evas_object_size_hint_max_set(obj, -1, -1);
403 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
405 item->o_menu = elm_menu_add(item->base.view);
407 elm_menu_parent_set(item->o_menu, wd->menu_parent);
408 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
410 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
415 _item_menu_destroy(Elm_Toolbar_Item *item)
419 evas_object_del(item->o_menu);
425 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
427 const Elm_Toolbar_Item *eti1 = i1;
428 const Elm_Toolbar_Item *eti2 = i2;
431 if (!eti1) return -1;
433 return eti2->prio.priority - eti1->prio.priority;
437 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
439 Elm_Toolbar_Item *it;
440 Eina_List *sorted = NULL;
443 EINA_INLIST_FOREACH(wd->items, it)
445 sorted = eina_list_sorted_insert(sorted,
446 _toolbar_item_prio_compare_cb, it);
451 evas_object_geometry_get(wd->more_item->base.view, NULL, NULL, &ciw, NULL);
454 EINA_LIST_FREE(sorted, it)
456 evas_object_geometry_get(it->base.view, NULL, NULL, &ciw, NULL);
458 it->prio.visible = (*iw <= vw);
463 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
465 Elm_Toolbar_Item *it = data;
466 if (it->func) it->func((void *)(it->base.data), it->base.widget, it);
470 _resize_job(void *data)
472 Widget_Data *wd = elm_widget_data_get(data);
473 Evas_Coord mw, mh, vw, vh, w, h;
474 Elm_Toolbar_Item *it;
475 Evas_Object *obj = (Evas_Object *) data;
478 wd->resize_job = NULL;
479 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
480 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
481 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
482 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
484 Evas_Coord iw = 0, more_w;
486 evas_object_resize(wd->bx, vw, h);
487 _fix_items_visibility(wd, &iw, vw);
488 evas_object_geometry_get(wd->more_item->base.view, NULL, NULL, &more_w, NULL);
489 if (iw - more_w <= vw)
492 /* All items are removed from the box object, since removing individual
493 * items won't trigger a resize. Items are be readded below. */
494 evas_object_box_remove_all(wd->bx, EINA_FALSE);
499 _item_menu_destroy(wd->more_item);
500 _item_menu_create(wd, wd->more_item);
501 menu = elm_toolbar_item_menu_get(wd->more_item);
503 EINA_INLIST_FOREACH(wd->items, it)
505 if (!it->prio.visible)
508 elm_menu_item_separator_add(menu, NULL);
512 item = elm_menu_item_add(menu, NULL, it->icon_str, it->label,
513 _elm_toolbar_item_menu_cb, it);
514 elm_menu_item_disabled_set(item, it->disabled);
515 if (it->o_menu) elm_menu_clone(it->o_menu, menu, item);
517 evas_object_hide(it->base.view);
521 evas_object_box_append(wd->bx, it->base.view);
522 evas_object_show(it->base.view);
526 evas_object_box_append(wd->bx, wd->more_item->base.view);
527 evas_object_show(wd->more_item->base.view);
531 /* All items are visible, show them all (except for the "More"
532 * button, of course). */
533 EINA_INLIST_FOREACH(wd->items, it)
535 evas_object_show(it->base.view);
536 evas_object_box_append(wd->bx, it->base.view);
538 evas_object_hide(wd->more_item->base.view);
541 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
545 evas_object_resize(wd->bx, vw, h);
546 _fix_items_visibility(wd, &iw, vw);
547 evas_object_box_remove_all(wd->bx, EINA_FALSE);
550 EINA_INLIST_FOREACH(wd->items, it)
552 if (!it->prio.visible)
553 evas_object_hide(it->base.view);
556 evas_object_box_append(wd->bx, it->base.view);
557 evas_object_show(it->base.view);
563 /* All items are visible, show them all */
564 EINA_INLIST_FOREACH(wd->items, it)
566 evas_object_show(it->base.view);
567 evas_object_box_append(wd->bx, it->base.view);
573 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
574 EINA_INLIST_FOREACH(wd->items, it)
584 _mirrored_set(obj, elm_widget_mirrored_get(obj));
588 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
591 _resize(data, NULL, NULL, NULL);
595 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
597 Widget_Data *wd = elm_widget_data_get(data);
599 wd->resize_job = ecore_job_add(_resize_job, data);
603 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
609 _mouse_in(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,highlighted", "elm");
613 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
617 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
619 Elm_Toolbar_Item *it = data;
620 edje_object_signal_emit(it->base.view, "elm,state,unhighlighted", "elm");
621 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
625 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
627 Evas_Object *obj = (Evas_Object *) data;
628 Widget_Data *wd = elm_widget_data_get(obj);
630 _els_box_layout(o, priv, 1, wd->homogeneous, elm_widget_mirrored_get(obj));
633 static Elm_Toolbar_Item *
634 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
636 Widget_Data *wd = elm_widget_data_get(obj);
637 Evas_Object *icon_obj;
639 Elm_Toolbar_Item *it;
641 icon_obj = elm_icon_add(obj);
642 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
643 if (!icon_obj) return NULL;
644 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
647 evas_object_del(icon_obj);
650 it->label = eina_stringshare_add(label);
651 it->prio.visible = 1;
652 it->prio.priority = 0;
654 it->separator = EINA_FALSE;
655 it->base.data = data;
656 it->base.view = edje_object_add(evas_object_evas_get(obj));
657 if (_item_icon_set(icon_obj, "toolbar/", icon))
660 it->icon_str = eina_stringshare_add(icon);
666 evas_object_del(icon_obj);
669 _elm_theme_object_set(obj, it->base.view, "toolbar", "item",
670 elm_widget_style_get(obj));
671 edje_object_signal_callback_add(it->base.view, "elm,action,click", "elm",
673 edje_object_signal_callback_add(it->base.view, "elm,mouse,in", "elm",
675 edje_object_signal_callback_add(it->base.view, "elm,mouse,out", "elm",
677 elm_widget_sub_object_add(obj, it->base.view);
682 ms = ((double)wd->icon_size * _elm_config->scale);
683 evas_object_size_hint_min_set(it->icon, ms, ms);
684 evas_object_size_hint_max_set(it->icon, ms, ms);
685 edje_object_part_swallow(it->base.view, "elm.swallow.icon", it->icon);
686 evas_object_show(it->icon);
687 elm_widget_sub_object_add(obj, it->icon);
689 edje_object_part_text_set(it->base.view, "elm.text", it->label);
691 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
692 edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw, mh);
693 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
694 evas_object_size_hint_weight_set(it->base.view, -1.0, EVAS_HINT_EXPAND);
695 evas_object_size_hint_align_set(it->base.view, 0.5, EVAS_HINT_FILL);
696 evas_object_size_hint_min_set(it->base.view, mw, mh);
697 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_RESIZE,
703 * Add a toolbar object to @p parent.
705 * @param parent The parent object
707 * @return The created object, or NULL on failure
712 elm_toolbar_add(Evas_Object *parent)
718 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
720 ELM_SET_WIDTYPE(widtype, "toolbar");
721 elm_widget_type_set(obj, "toolbar");
722 elm_widget_sub_object_add(parent, obj);
723 elm_widget_data_set(obj, wd);
724 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
725 elm_widget_del_hook_set(obj, _del_hook);
726 elm_widget_theme_hook_set(obj, _theme_hook);
727 elm_widget_can_focus_set(obj, EINA_FALSE);
729 wd->more_item = NULL;
730 wd->selected_item = NULL;
731 wd->scr = elm_smart_scroller_add(e);
732 elm_smart_scroller_widget_set(wd->scr, obj);
733 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
734 elm_smart_scroller_bounce_allow_set(wd->scr,
735 _elm_config->thumbscroll_bounce_enable,
737 elm_widget_resize_object_set(obj, wd->scr);
738 elm_smart_scroller_policy_set(wd->scr,
739 ELM_SMART_SCROLLER_POLICY_AUTO,
740 ELM_SMART_SCROLLER_POLICY_OFF);
743 wd->icon_size = _elm_toolbar_icon_size_get(wd);
746 wd->homogeneous = EINA_TRUE;
749 wd->bx = evas_object_box_add(e);
750 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
751 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
752 elm_widget_sub_object_add(obj, wd->bx);
753 elm_smart_scroller_child_set(wd->scr, wd->bx);
754 evas_object_show(wd->bx);
756 elm_toolbar_mode_shrink_set(obj, _elm_config->toolbar_shrink_mode);
757 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
758 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
759 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
761 evas_object_smart_callbacks_descriptions_set(obj, _signals);
768 * Set the icon size (in pixels) for the toolbar.
770 * @param obj The toolbar object
771 * @param icon_size The icon size in pixels
776 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
778 ELM_CHECK_WIDTYPE(obj, widtype);
779 Widget_Data *wd = elm_widget_data_get(obj);
781 if (wd->icon_size == icon_size) return;
782 wd->icon_size = icon_size;
787 * Get the icon size (in pixels) for the toolbar.
789 * @param obj The toolbar object
790 * @return The icon size in pixels
795 elm_toolbar_icon_size_get(const Evas_Object *obj)
797 ELM_CHECK_WIDTYPE(obj, widtype) 0;
798 Widget_Data *wd = elm_widget_data_get(obj);
800 return wd->icon_size;
804 * Append item to the toolbar
806 * @param obj The toolbar object
807 * @param icon A string with icon name or the absolute path of an image file.
808 * @param label The label of the item
809 * @param func The function to call when the item is clicked
810 * @param data The data to associate with the item
811 * @return The toolbar item, or NULL upon failure
813 * @see elm_toolbar_item_icon_set
817 EAPI Elm_Toolbar_Item *
818 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
820 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
821 Widget_Data *wd = elm_widget_data_get(obj);
822 if (!wd) return NULL;
824 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
825 if (!it) return NULL;
827 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
828 evas_object_box_append(wd->bx, it->base.view);
829 evas_object_show(it->base.view);
836 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
838 Elm_Toolbar_Item *it = event_info;
839 Elm_Toolbar_Item_State *it_state;
841 it_state = eina_list_data_get(it->current_state);
843 it_state->func((void *)it_state->data, obj, event_info);
847 * Sets the next @p item state as the current state.
849 * @param item The item.
853 EAPI Elm_Toolbar_Item_State *
854 elm_toolbar_item_state_next(Elm_Toolbar_Item *item)
858 Eina_List *next_state;
859 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
861 obj = item->base.widget;
862 wd = elm_widget_data_get(obj);
863 if (!wd) return NULL;
864 if (!item->states) return NULL;
866 next_state = eina_list_next(item->current_state);
868 next_state = eina_list_next(item->states);
869 return eina_list_data_get(next_state);
873 * Sets the previous @p item state as the current state.
875 * @param item The item.
879 EAPI Elm_Toolbar_Item_State *
880 elm_toolbar_item_state_prev(Elm_Toolbar_Item *item)
884 Eina_List *prev_state;
885 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
887 obj = item->base.widget;
888 wd = elm_widget_data_get(obj);
889 if (!wd) return NULL;
890 if (!item->states) return NULL;
892 prev_state = eina_list_prev(item->current_state);
893 if ((!prev_state) || (prev_state == item->states))
894 prev_state = eina_list_last(item->states);
895 return eina_list_data_get(prev_state);
899 * Unset the state of @p it
900 * The default icon and label from this item will be displayed.
902 * @param it The item.
907 elm_toolbar_item_state_unset(Elm_Toolbar_Item *it)
909 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
910 elm_toolbar_item_state_set(it, NULL);
914 * Sets @p state as the current state of @p it.
915 * If @p state is NULL, it won't select any state and the default icon and
916 * label will be used.
918 * @param it The item.
919 * @param state The state to use.
921 * @return True if the state was correctly set.
926 elm_toolbar_item_state_set(Elm_Toolbar_Item *it, Elm_Toolbar_Item_State *state)
929 Eina_List *next_state;
930 Elm_Toolbar_Item_State *it_state;
932 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
934 obj = it->base.widget;
935 wd = elm_widget_data_get(obj);
936 if (!wd) return EINA_FALSE;
937 if (!it->states) return EINA_FALSE;
941 next_state = eina_list_data_find_list(it->states, state);
942 if (!next_state) return EINA_FALSE;
945 next_state = it->states;
947 if (next_state == it->current_state) return EINA_TRUE;
949 it_state = eina_list_data_get(next_state);
950 if (eina_list_data_find(it->current_state, state))
952 _item_label_set(it, it_state->label, "elm,state,label_set,forward");
953 _elm_toolbar_item_icon_obj_set(obj, it, it_state->icon, it_state->icon_str,
954 wd->icon_size, "elm,state,icon_set,forward");
958 _item_label_set(it, it_state->label, "elm,state,label_set,backward");
959 _elm_toolbar_item_icon_obj_set(obj, it, it_state->icon, it_state->icon_str,
960 wd->icon_size, "elm,state,icon_set,backward");
963 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
965 elm_widget_signal_emit(it->icon, "elm,state,enabled", "elm");
967 it->current_state = next_state;
972 * Get the current state of @p item.
973 * If no state is selected, returns NULL.
975 * @param item The item.
981 EAPI Elm_Toolbar_Item_State *
982 elm_toolbar_item_state_get(const Elm_Toolbar_Item *it)
984 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
985 if ((!it->states) || (!it->current_state)) return NULL;
986 if (it->current_state == it->states) return NULL;
988 return eina_list_data_get(it->current_state);
991 static Elm_Toolbar_Item_State *
992 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
994 Elm_Toolbar_Item_State *it_state;
995 it_state = ELM_NEW(Elm_Toolbar_Item_State);
996 it_state->label = eina_stringshare_add(label);
997 it_state->icon_str = eina_stringshare_add(icon_str);
998 it_state->icon = icon;
999 it_state->func = func;
1000 it_state->data = data;
1005 * Add a new state to @p item
1007 * @param item The item.
1008 * @param icon The icon string
1009 * @param label The label of the new state
1010 * @param func The function to call when the item is clicked when this state is
1012 * @param data The data to associate with the state
1013 * @return The toolbar item state, or NULL upon failure
1017 EAPI Elm_Toolbar_Item_State *
1018 elm_toolbar_item_state_add(Elm_Toolbar_Item *item, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1020 Elm_Toolbar_Item_State *it_state;
1021 Evas_Object *icon_obj;
1024 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1025 obj = item->base.widget;
1026 wd = elm_widget_data_get(item->base.widget);
1027 if (!wd) return NULL;
1031 it_state = _item_state_new(item->label, item->icon_str, item->icon,
1032 item->func, item->base.data);
1033 item->states = eina_list_append(item->states, it_state);
1034 item->current_state = item->states;
1037 icon_obj = elm_icon_add(obj);
1038 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1039 if (!icon_obj) goto error_state_add;
1041 if (!_item_icon_set(icon_obj, "toolbar/", icon))
1043 evas_object_del(icon_obj);
1048 it_state = _item_state_new(label, icon, icon_obj, func, data);
1049 item->states = eina_list_append(item->states, it_state);
1050 item->func = _elm_toolbar_item_state_cb;
1051 item->base.data = NULL;
1056 if (item->states && !eina_list_next(item->states))
1058 eina_stringshare_del(item->label);
1059 eina_stringshare_del(item->icon_str);
1060 free(eina_list_data_get(item->states));
1061 eina_list_free(item->states);
1062 item->states = NULL;
1068 elm_toolbar_item_state_del(Elm_Toolbar_Item *item, Elm_Toolbar_Item_State *state)
1070 Eina_List *del_state;
1071 Elm_Toolbar_Item_State *it_state;
1072 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1074 if (!state) return EINA_FALSE;
1075 if (!item->states) return EINA_FALSE;
1077 del_state = eina_list_data_find_list(item->states, state);
1078 if (del_state == item->states) return EINA_FALSE;
1079 if (del_state == item->current_state)
1080 elm_toolbar_item_state_unset(item);
1082 eina_stringshare_del(state->label);
1083 eina_stringshare_del(state->icon_str);
1084 if (state->icon) evas_object_del(state->icon);
1086 item->states = eina_list_remove_list(item->states, del_state);
1087 if (item->states && !eina_list_next(item->states))
1089 it_state = eina_list_data_get(item->states);
1090 item->base.data = it_state->data;
1091 item->func = it_state->func;
1092 eina_stringshare_del(it_state->label);
1093 eina_stringshare_del(it_state->icon_str);
1094 free(eina_list_data_get(item->states));
1095 eina_list_free(item->states);
1096 item->states = NULL;
1103 * Prepend item to the toolbar
1105 * @param obj The toolbar object
1106 * @param icon A string with icon name or the absolute path of an image file.
1107 * @param label The label of the item
1108 * @param func The function to call when the item is clicked
1109 * @param data The data to associate with the item
1110 * @return The toolbar item, or NULL upon failure
1112 * @see elm_toolbar_item_icon_set
1116 EAPI Elm_Toolbar_Item *
1117 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1119 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1120 Widget_Data *wd = elm_widget_data_get(obj);
1121 if (!wd) return NULL;
1123 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1124 if (!it) return NULL;
1126 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1127 evas_object_box_prepend(wd->bx, it->base.view);
1128 evas_object_show(it->base.view);
1135 * Insert item before another in the toolbar
1137 * @param obj The toolbar object
1138 * @param before The item to insert before
1139 * @param icon A string with icon name or the absolute path of an image file.
1140 * @param label The label of the item
1141 * @param func The function to call when the item is clicked
1142 * @param data The data to associate with the item
1143 * @return The toolbar item, or NULL upon failure
1145 * @see elm_toolbar_item_icon_set
1149 EAPI Elm_Toolbar_Item *
1150 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)
1152 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1153 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(before, NULL);
1154 Widget_Data *wd = elm_widget_data_get(obj);
1155 if (!wd) return NULL;
1157 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1158 if (!it) return NULL;
1160 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1161 EINA_INLIST_GET(before));
1162 evas_object_box_insert_before(wd->bx, it->base.view, before->base.view);
1163 evas_object_show(it->base.view);
1170 * Insert item after another in the toolbar
1172 * @param obj The toolbar object
1173 * @param after The item to insert after
1174 * @param icon A string with icon name or the absolute path of an image file.
1175 * @param label The label of the item
1176 * @param func The function to call when the item is clicked
1177 * @param data The data to associate with the item
1178 * @return The toolbar item, or NULL upon failure
1180 * @see elm_toolbar_item_icon_set
1184 EAPI Elm_Toolbar_Item *
1185 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)
1187 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1188 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(after, NULL);
1189 Widget_Data *wd = elm_widget_data_get(obj);
1190 if (!wd) return NULL;
1192 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1193 if (!it) return NULL;
1195 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1196 EINA_INLIST_GET(after));
1197 evas_object_box_insert_after(wd->bx, it->base.view, after->base.view);
1198 evas_object_show(it->base.view);
1205 * Get the first item in the toolbar
1207 * @param obj The toolbar object
1208 * @return The first item, or NULL if none
1212 EAPI Elm_Toolbar_Item *
1213 elm_toolbar_first_item_get(const Evas_Object *obj)
1215 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1216 Widget_Data *wd = elm_widget_data_get(obj);
1217 if (!wd || !wd->items) return NULL;
1218 Elm_Toolbar_Item *it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1223 * Get the last item in the toolbar
1225 * @return The last item, or NULL if none
1229 EAPI Elm_Toolbar_Item *
1230 elm_toolbar_last_item_get(const Evas_Object *obj)
1232 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1233 Widget_Data *wd = elm_widget_data_get(obj);
1234 if (!wd || !wd->items) return NULL;
1235 Elm_Toolbar_Item *it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1240 * Get the next item in the toolbar
1242 * This returns the item after the item @p it.
1244 * @param item The item
1245 * @return The item after @p it, or NULL if none
1249 EAPI Elm_Toolbar_Item *
1250 elm_toolbar_item_next_get(const Elm_Toolbar_Item *item)
1252 Elm_Toolbar_Item *next;
1253 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1254 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
1259 * Get the previous item in the toolbar
1261 * This returns the item before the item @p it.
1263 * @param item The item
1264 * @return The item before @p it, or NULL if none
1268 EAPI Elm_Toolbar_Item *
1269 elm_toolbar_item_prev_get(const Elm_Toolbar_Item *item)
1271 Elm_Toolbar_Item *prev;
1272 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1273 prev = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
1278 * Get the toolbar object from an item
1280 * This returns the toolbar object itself that an item belongs to.
1282 * @param item The item
1283 * @return The toolbar object
1288 elm_toolbar_item_toolbar_get(const Elm_Toolbar_Item *item)
1290 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1291 return item->base.widget;
1295 * Sets the priority of a toolbar item. This is used only when the toolbar
1296 * shrink mode is set to ELM_TOOLBAR_SHRINK_MENU or ELM_TOOLBAR_SHRINK_HIDE:
1297 * when space is at a premium, items with low priority will be removed from
1298 * the toolbar and added to a dynamically-created menu, while items with
1299 * higher priority will remain on the toolbar, with the same order they were
1302 * @param item The toolbar item.
1303 * @param priority The item priority. The default is zero.
1308 elm_toolbar_item_priority_set(Elm_Toolbar_Item *item, int priority)
1310 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1311 if (item->prio.priority == priority) return;
1312 item->prio.priority = priority;
1313 _resize(item->base.widget, NULL, NULL, NULL);
1317 * Gets the priority of a toolbar item.
1319 * @param item The toolbar item.
1320 * @return The item priority, or 0 if an error occurred.
1325 elm_toolbar_item_priority_get(const Elm_Toolbar_Item *item)
1327 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, 0);
1328 return item->prio.priority;
1332 * Get the string used to set the icon of @p item.
1334 * @param item The toolbar item
1335 * @return The string associated with the icon object.
1337 * @see elm_toolbar_item_icon_set()
1342 elm_toolbar_item_icon_get(const Elm_Toolbar_Item *item)
1344 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1345 return item->icon_str;
1349 * Get the label associated with @p item.
1351 * @param item The toolbar item
1357 elm_toolbar_item_label_get(const Elm_Toolbar_Item *item)
1359 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1364 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
1366 Evas_Coord mw = -1, mh = -1;
1367 edje_object_part_text_set(item->base.view, "elm.text", item->label);
1369 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1370 edje_object_size_min_restricted_calc(item->base.view, &mw, &mh, mw, mh);
1371 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1372 evas_object_size_hint_weight_set(item->base.view, -1.0, EVAS_HINT_EXPAND);
1373 evas_object_size_hint_align_set(item->base.view, 0.5, EVAS_HINT_FILL);
1374 evas_object_size_hint_min_set(item->base.view, mw, mh);
1378 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1380 Elm_Toolbar_Item *item = data;
1381 _elm_toolbar_item_label_update(item);
1382 edje_object_signal_callback_del(obj, emission, source,
1383 _elm_toolbar_item_label_set_cb);
1384 edje_object_signal_emit (item->base.view, "elm,state,label,reset", "elm");
1388 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal)
1392 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
1394 eina_stringshare_replace(&item->label, label);
1395 s = edje_object_data_get(item->base.view, "transition_animation_on");
1396 if ((s) && (atoi(s)))
1398 edje_object_part_text_set(item->base.view, "elm.text_new", item->label);
1399 edje_object_signal_emit (item->base.view, signal, "elm");
1400 edje_object_signal_callback_add(item->base.view,
1401 "elm,state,label_set,done", "elm",
1402 _elm_toolbar_item_label_set_cb, item);
1405 _elm_toolbar_item_label_update(item);
1406 _resize(item->base.widget, NULL, NULL, NULL);
1410 * Set the label associated with @p item.
1412 * @param item The toolbar item
1413 * @param label The label of @p item
1418 elm_toolbar_item_label_set(Elm_Toolbar_Item *item, const char *label)
1420 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1421 _item_label_set(item, label, "elm,state,label_set");
1425 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
1427 Elm_Toolbar_Item_State *it_state;
1429 Evas_Coord mw = -1, mh = -1;
1430 Evas_Object *old_icon = edje_object_part_swallow_get(item->base.view,
1431 "elm.swallow.icon");
1432 elm_widget_sub_object_del(item->base.view, old_icon);
1433 evas_object_hide(old_icon);
1434 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
1435 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1436 edje_object_size_min_restricted_calc(item->base.view, &mw, &mh, mw, mh);
1437 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1438 evas_object_size_hint_weight_set(item->base.view, -1.0, EVAS_HINT_EXPAND);
1439 evas_object_size_hint_align_set(item->base.view, 0.5, EVAS_HINT_FILL);
1440 evas_object_size_hint_min_set(item->base.view, mw, mh);
1442 EINA_LIST_FOREACH(item->states, l, it_state)
1443 if (it_state->icon == old_icon)
1445 evas_object_del(old_icon);
1449 * Get the selected state of @p item.
1451 * @param item The toolbar item
1452 * @return If true, the item is selected
1457 elm_toolbar_item_selected_get(const Elm_Toolbar_Item *item)
1459 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1460 return item->selected;
1464 * Set the selected state of an item
1466 * This sets the selected state (1 selected, 0 not selected) of the given
1467 * item @p it. If a new item is selected the previosly selected will be
1470 * @param item The item
1471 * @param selected The selected state
1476 elm_toolbar_item_selected_set(Elm_Toolbar_Item *item, Eina_Bool selected)
1478 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1479 Widget_Data *wd = elm_widget_data_get(item->base.widget);
1482 if (item->selected == selected) return;
1487 _item_unselect(item);
1491 * Get the selectd item in the toolbar
1493 * If no item is selected, NULL is returned.
1495 * @param obj The toolbar object
1496 * @return The selected item, or NULL if none.
1500 EAPI Elm_Toolbar_Item *
1501 elm_toolbar_selected_item_get(const Evas_Object *obj)
1503 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1504 Widget_Data *wd = elm_widget_data_get(obj);
1505 if (!wd) return NULL;
1506 return wd->selected_item;
1510 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1512 Elm_Toolbar_Item *item = data;
1513 edje_object_part_unswallow(item->base.view, item->icon);
1514 _elm_toolbar_item_icon_update(item);
1515 edje_object_signal_callback_del(obj, emission, source,
1516 _elm_toolbar_item_icon_set_cb);
1517 edje_object_signal_emit (item->base.view, "elm,state,icon,reset", "elm");
1521 _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)
1523 Evas_Object *old_icon;
1528 eina_stringshare_replace(&item->icon_str, icon_str);
1531 eina_stringshare_del(item->icon_str);
1532 item->icon_str = NULL;
1534 item->icon = icon_obj;
1537 ms = (icon_size * _elm_config->scale);
1538 evas_object_size_hint_min_set(item->icon, ms, ms);
1539 evas_object_size_hint_max_set(item->icon, ms, ms);
1540 evas_object_show(item->icon);
1541 elm_widget_sub_object_add(obj, item->icon);
1543 s = edje_object_data_get(item->base.view, "transition_animation_on");
1544 if ((s) && (atoi(s)))
1546 old_icon = edje_object_part_swallow_get(item->base.view,
1547 "elm.swallow.icon_new");
1550 elm_widget_sub_object_del(item->base.view, old_icon);
1551 evas_object_hide(old_icon);
1553 edje_object_part_swallow(item->base.view, "elm.swallow.icon_new",
1555 edje_object_signal_emit (item->base.view, signal, "elm");
1556 edje_object_signal_callback_add(item->base.view,
1557 "elm,state,icon_set,done", "elm",
1558 _elm_toolbar_item_icon_set_cb, item);
1561 _elm_toolbar_item_icon_update(item);
1562 _resize(obj, NULL, NULL, NULL);
1566 * Set the icon associated with @p item.
1568 * Toolbar will load icon image from fdo or current theme.
1569 * This behavior can be set by elm_toolbar_icon_order_lookup_set() function.
1570 * If an absolute path is provided it will load it direct from a file.
1572 * @param obj The parent of this item
1573 * @param item The toolbar item
1574 * @param icon A string with icon name or the absolute path of an image file.
1576 * @see elm_toolbar_icon_order_lookup_set(), elm_toolbar_icon_order_lookup_get()
1581 elm_toolbar_item_icon_set(Elm_Toolbar_Item *item, const char *icon)
1583 Evas_Object *icon_obj;
1585 Evas_Object *obj = item->base.widget;
1587 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1588 wd = elm_widget_data_get(obj);
1590 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1592 icon_obj = elm_icon_add(obj);
1593 if (!icon_obj) return;
1594 if (_item_icon_set(icon_obj, "toolbar/", icon))
1595 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1596 "elm,state,icon_set");
1599 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1600 "elm,state,icon_set");
1601 evas_object_del(icon_obj);
1606 * Delete a toolbar item.
1608 * @param item The toolbar item
1613 elm_toolbar_item_del(Elm_Toolbar_Item *item)
1618 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1619 wd = elm_widget_data_get(item->base.widget);
1621 obj2 = item->base.widget;
1622 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
1628 * Set the function called when a toolbar item is freed.
1630 * @param item The item to set the callback on
1631 * @param func The function called
1636 elm_toolbar_item_del_cb_set(Elm_Toolbar_Item *item, Evas_Smart_Cb func)
1638 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1639 elm_widget_item_del_cb_set(item, func);
1643 * Get the disabled state of @p item.
1645 * @param item The toolbar item
1646 * @return If true, the item is disabled
1651 elm_toolbar_item_disabled_get(const Elm_Toolbar_Item *item)
1653 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1654 return item->disabled;
1658 * Set the disabled state of @p item.
1660 * @param item The toolbar item
1661 * @param disabled If true, the item is disabled
1666 elm_toolbar_item_disabled_set(Elm_Toolbar_Item *item, Eina_Bool disabled)
1668 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1669 _item_disable(item, disabled);
1670 _resize(item->base.widget, NULL, NULL, NULL);
1674 * Get the separator state of @p item.
1676 * @param item The toolbar item
1677 * @param separator If true, the item is a separator
1682 elm_toolbar_item_separator_set(Elm_Toolbar_Item *item, Eina_Bool separator)
1684 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1685 if (item->separator == separator) return;
1686 item->separator = separator;
1687 _theme_hook(item->base.view);
1691 * Set the separator state of @p item.
1693 * @param item The toolbar item
1694 * @return If true, the item is a separator
1699 elm_toolbar_item_separator_get(const Elm_Toolbar_Item *item)
1701 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1702 return item->separator;
1706 * Set the shrink state of toolbar @p obj.
1708 * @param obj The toolbar object
1709 * @param shrink_mode The toolbar won't scroll if ELM_TOOLBAR_SHRINK_NONE,
1710 * but will enforce a minimun size so all the items will fit, won't scroll
1711 * and won't show the items that don't fit if ELM_TOOLBAR_SHRINK_HIDE,
1712 * will scroll if ELM_TOOLBAR_SHRINK_SCROLL, and will create a button to
1713 * pop up excess elements with ELM_TOOLBAR_SHRINK_MENU.
1718 elm_toolbar_mode_shrink_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1720 ELM_CHECK_WIDTYPE(obj, widtype);
1721 Widget_Data *wd = elm_widget_data_get(obj);
1725 wd->shrink_mode = shrink_mode;
1726 bounce = (_elm_config->thumbscroll_bounce_enable) &&
1727 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1728 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1732 _item_del(wd->more_item);
1733 wd->more_item = NULL;
1736 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1738 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF, ELM_SMART_SCROLLER_POLICY_OFF);
1740 wd->more_item = _item_new(obj, "more_menu", "More",
1743 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1744 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1745 ELM_SMART_SCROLLER_POLICY_OFF);
1747 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1748 ELM_SMART_SCROLLER_POLICY_OFF);
1753 * Get the shrink mode of toolbar @p obj.
1755 * @param obj The toolbar object
1756 * @return See elm_toolbar_mode_shrink_set.
1760 EAPI Elm_Toolbar_Shrink_Mode
1761 elm_toolbar_mode_shrink_get(const Evas_Object *obj)
1763 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1764 Widget_Data *wd = elm_widget_data_get(obj);
1766 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1767 return wd->shrink_mode;
1771 * Set the homogeneous mode of toolbar @p obj.
1773 * @param obj The toolbar object
1774 * @param homogeneous If true, the toolbar items will be uniform in size
1779 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
1781 ELM_CHECK_WIDTYPE(obj, widtype);
1782 Widget_Data *wd = elm_widget_data_get(obj);
1785 wd->homogeneous = !!homogeneous;
1786 evas_object_smart_calculate(wd->bx);
1789 EINA_DEPRECATED EAPI void
1790 elm_toolbar_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
1792 elm_toolbar_homogeneous_set(obj, homogenous);
1796 * Get the homogeneous mode of toolbar @p obj.
1798 * @param obj The toolbar object
1799 * @return If true, the toolbar items are uniform in size
1804 elm_toolbar_homogeneous_get(const Evas_Object *obj)
1806 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1807 Widget_Data *wd = elm_widget_data_get(obj);
1809 if (!wd) return EINA_FALSE;
1810 return wd->homogeneous;
1813 EINA_DEPRECATED EAPI Eina_Bool
1814 elm_toolbar_homogenous_get(const Evas_Object *obj)
1816 return elm_toolbar_homogeneous_get(obj);
1820 * Set the parent object of the toolbar menu
1822 * @param obj The toolbar object
1823 * @param parent The parent of the menu object
1828 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1830 Elm_Toolbar_Item *it;
1831 ELM_CHECK_WIDTYPE(obj, widtype);
1832 Widget_Data *wd = elm_widget_data_get(obj);
1835 EINA_SAFETY_ON_NULL_RETURN(parent);
1836 wd->menu_parent = parent;
1837 EINA_INLIST_FOREACH(wd->items, it)
1840 elm_menu_parent_set(it->o_menu, wd->menu_parent);
1842 if ((wd->more_item) && (wd->more_item->o_menu))
1843 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1847 * Get the parent object of the toolbar menu
1849 * @param obj The toolbar object
1850 * @return The parent of the menu object
1855 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1857 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1858 Widget_Data *wd = elm_widget_data_get(obj);
1860 if (!wd) return NULL;
1861 return wd->menu_parent;
1865 * Set the alignment of the items.
1867 * @param obj The toolbar object
1868 * @param align The new alignment. (left) 0.0 ... 1.0 (right)
1873 elm_toolbar_align_set(Evas_Object *obj, double align)
1875 ELM_CHECK_WIDTYPE(obj, widtype);
1876 Widget_Data *wd = elm_widget_data_get(obj);
1879 if (wd->align != align)
1880 evas_object_size_hint_align_set(wd->bx, align, 0.5);
1885 * Get the alignment of the items.
1887 * @param obj The toolbar object
1888 * @return The alignment. (left) 0.0 ... 1.0 (right)
1893 elm_toolbar_align_get(const Evas_Object *obj)
1895 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1896 Widget_Data *wd = elm_widget_data_get(obj);
1898 if (!wd) return 0.0;
1903 * Set whether the toolbar item opens a menu.
1905 * @param item The toolbar item
1906 * @param menu If true, @p item will open a menu when selected
1911 elm_toolbar_item_menu_set(Elm_Toolbar_Item *item, Eina_Bool menu)
1913 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1914 Widget_Data *wd = elm_widget_data_get(item->base.widget);
1917 if (item->menu == menu) return;
1919 if (menu) _item_menu_create(wd, item);
1920 else _item_menu_destroy(item);
1924 * Set the text to be shown in the toolbar item.
1926 * @param item Target item
1927 * @param text The text to set in the content
1929 * Setup the text as tooltip to object. The item can have only one tooltip,
1930 * so any previous tooltip data is removed.
1935 elm_toolbar_item_tooltip_text_set(Elm_Toolbar_Item *item, const char *text)
1937 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1938 elm_widget_item_tooltip_text_set(item, text);
1942 * Set the content to be shown in the tooltip item
1944 * Setup the tooltip to item. The item can have only one tooltip,
1945 * so any previous tooltip data is removed. @p func(with @p data) will
1946 * be called every time that need show the tooltip and it should
1947 * return a valid Evas_Object. This object is then managed fully by
1948 * tooltip system and is deleted when the tooltip is gone.
1950 * @param item the toolbar item being attached a tooltip.
1951 * @param func the function used to create the tooltip contents.
1952 * @param data what to provide to @a func as callback data/context.
1953 * @param del_cb called when data is not needed anymore, either when
1954 * another callback replaces @func, the tooltip is unset with
1955 * elm_toolbar_item_tooltip_unset() or the owner @a item
1956 * dies. This callback receives as the first parameter the
1957 * given @a data, and @c event_info is the item.
1962 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)
1964 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1965 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1969 * Unset tooltip from item
1971 * @param item toolbar item to remove previously set tooltip.
1973 * Remove tooltip from item. The callback provided as del_cb to
1974 * elm_toolbar_item_tooltip_content_cb_set() will be called to notify
1975 * it is not used anymore.
1977 * @see elm_toolbar_item_tooltip_content_cb_set()
1982 elm_toolbar_item_tooltip_unset(Elm_Toolbar_Item *item)
1984 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1985 elm_widget_item_tooltip_unset(item);
1989 * Sets a different style for this item tooltip.
1991 * @note before you set a style you should define a tooltip with
1992 * elm_toolbar_item_tooltip_content_cb_set() or
1993 * elm_toolbar_item_tooltip_text_set()
1995 * @param item toolbar item with tooltip already set.
1996 * @param style the theme style to use (default, transparent, ...)
2001 elm_toolbar_item_tooltip_style_set(Elm_Toolbar_Item *item, const char *style)
2003 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2004 elm_widget_item_tooltip_style_set(item, style);
2008 * Get the style for this item tooltip.
2010 * @param item toolbar item with tooltip already set.
2011 * @return style the theme style in use, defaults to "default". If the
2012 * object does not have a tooltip set, then NULL is returned.
2017 elm_toolbar_item_tooltip_style_get(const Elm_Toolbar_Item *item)
2019 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2020 return elm_widget_item_tooltip_style_get(item);
2024 * Set the cursor to be shown when mouse is over the toolbar item
2026 * @param item Target item
2027 * @param cursor the cursor name to be used.
2029 * @see elm_object_cursor_set()
2033 elm_toolbar_item_cursor_set(Elm_Toolbar_Item *item, const char *cursor)
2035 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2036 elm_widget_item_cursor_set(item, cursor);
2040 * Get the cursor to be shown when mouse is over the toolbar item
2042 * @param item toolbar item with cursor already set.
2043 * @return the cursor name.
2048 elm_toolbar_item_cursor_get(const Elm_Toolbar_Item *item)
2050 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2051 return elm_widget_item_cursor_get(item);
2055 * Unset the cursor to be shown when mouse is over the toolbar item
2057 * @param item Target item
2059 * @see elm_object_cursor_unset()
2063 elm_toolbar_item_cursor_unset(Elm_Toolbar_Item *item)
2065 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2066 elm_widget_item_cursor_unset(item);
2070 * Sets a different style for this item cursor.
2072 * @note before you set a style you should define a cursor with
2073 * elm_toolbar_item_cursor_set()
2075 * @param item toolbar item with cursor already set.
2076 * @param style the theme style to use (default, transparent, ...)
2081 elm_toolbar_item_cursor_style_set(Elm_Toolbar_Item *item, const char *style)
2083 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2084 elm_widget_item_cursor_style_set(item, style);
2088 * Get the style for this item cursor.
2090 * @param item toolbar item with cursor already set.
2091 * @return style the theme style in use, defaults to "default". If the
2092 * object does not have a cursor set, then NULL is returned.
2097 elm_toolbar_item_cursor_style_get(const Elm_Toolbar_Item *item)
2099 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2100 return elm_widget_item_cursor_style_get(item);
2104 * Set if the cursor set should be searched on the theme or should use
2105 * the provided by the engine, only.
2107 * @note before you set if should look on theme you should define a cursor
2108 * with elm_object_cursor_set(). By default it will only look for cursors
2109 * provided by the engine.
2111 * @param item widget item with cursor already set.
2112 * @param engine_only boolean to define it cursors should be looked only
2113 * between the provided by the engine or searched on widget's theme as well.
2118 elm_toolbar_item_cursor_engine_only_set(Elm_Toolbar_Item *item, Eina_Bool engine_only)
2120 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2121 elm_widget_item_cursor_engine_only_set(item, engine_only);
2125 * Get the cursor engine only usage for this item cursor.
2127 * @param item widget item with cursor already set.
2128 * @return engine_only boolean to define it cursors should be looked only
2129 * between the provided by the engine or searched on widget's theme as well. If
2130 * the object does not have a cursor set, then EINA_FALSE is returned.
2135 elm_toolbar_item_cursor_engine_only_get(const Elm_Toolbar_Item *item)
2137 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2138 return elm_widget_item_cursor_engine_only_get(item);
2142 * Get whether the toolbar item opens a menu.
2144 * @param item The toolbar item
2145 * @return If true, @p item opens a menu when selected
2150 elm_toolbar_item_menu_get(Elm_Toolbar_Item *item)
2152 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2153 Widget_Data *wd = elm_widget_data_get(item->base.widget);
2154 if (!wd) return NULL;
2155 /* FIXME: It's not ok. This function needs to be reviewed. And should
2156 * receive a const item */
2157 elm_toolbar_item_menu_set(item, 1);
2158 return item->o_menu;
2162 * Returns a pointer to a toolbar item by its label
2164 * @param obj The toolbar object
2165 * @param label The label of the item to find
2167 * @return The pointer to the toolbar item matching @p label
2168 * Returns NULL on failure.
2172 EAPI Elm_Toolbar_Item *
2173 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
2175 Elm_Toolbar_Item *it;
2176 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2177 Widget_Data *wd = elm_widget_data_get(obj);
2179 if (!wd) return NULL;
2180 EINA_INLIST_FOREACH(wd->items, it)
2182 if (!strcmp(it->label, label)) return it;
2189 * Set the data item from the toolbar item
2191 * This set the data value passed on the elm_toolbar_item_append() and
2192 * related item addition calls.
2194 * @param item The item
2195 * @param data The new data pointer to set
2200 elm_toolbar_item_data_set(Elm_Toolbar_Item *item, const void *data)
2202 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2203 elm_widget_item_data_set(item, data);
2207 * Get the data item from the toolbar item
2209 * This returns the data value passed on the elm_toolbar_item_append() and
2210 * related item addition calls.
2212 * @param item The item
2213 * @return The data pointer provided when created
2218 elm_toolbar_item_data_get(const Elm_Toolbar_Item *item)
2220 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2221 return elm_widget_item_data_get(item);
2225 * Set no select mode.
2227 * This will turn off the ability to select items entirely and they will
2228 * neither appear selected nor emit selected signals. The clicked
2229 * callback function will still be called.
2231 * @param obj The Toolbar object
2232 * @param no_select The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2237 elm_toolbar_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select)
2239 ELM_CHECK_WIDTYPE(obj, widtype);
2240 Widget_Data *wd = elm_widget_data_get(obj);
2242 wd->no_select = no_select;
2246 * Gets no select mode.
2248 * @param obj The Toolbar object
2249 * @return The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2254 elm_toolbar_no_select_mode_get(const Evas_Object *obj)
2256 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2257 Widget_Data *wd = elm_widget_data_get(obj);
2258 if (!wd) return EINA_FALSE;
2259 return wd->no_select;
2263 * Sets icon lookup order, for icons used in this toolbar.
2264 * Icons added before calling this function will not be affected.
2265 * The default lookup order is ELM_ICON_LOOKUP_THEME_FDO.
2267 * @param obj The toolbar object
2268 * @param order The icon lookup order
2273 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
2275 ELM_CHECK_WIDTYPE(obj, widtype);
2276 Elm_Toolbar_Item *it;
2277 Widget_Data *wd = elm_widget_data_get(obj);
2280 wd->lookup_order = order;
2281 EINA_INLIST_FOREACH(wd->items, it)
2282 elm_icon_order_lookup_set(it->icon, order);
2284 elm_icon_order_lookup_set(wd->more_item->icon, order);
2288 * Gets the icon lookup order.
2290 * @param obj The Toolbar object
2291 * @return The icon lookup order
2295 EAPI Elm_Icon_Lookup_Order
2296 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
2298 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
2299 Widget_Data *wd = elm_widget_data_get(obj);
2300 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
2301 return wd->lookup_order;