1 #include <Elementary.h>
5 * @defgroup Toolbar Toolbar
7 * A toolbar is a widget that displays a list of buttons inside
8 * a box. It is scrollable, and only one item can be selected at a time.
11 typedef struct _Widget_Data Widget_Data;
15 Evas_Object *scr, *bx;
16 Evas_Object *menu_parent;
18 Elm_Toolbar_Item *more_item, *selected_item;
19 Elm_Toolbar_Shrink_Mode shrink_mode;
20 Elm_Icon_Lookup_Order lookup_order;
23 Eina_Bool homogeneous : 1;
24 Eina_Bool no_select : 1;
25 Ecore_Job *resize_job;
28 struct _Elm_Toolbar_Item
39 Eina_Bool visible : 1;
41 Eina_Bool selected : 1;
42 Eina_Bool disabled : 1;
43 Eina_Bool separator : 1;
46 Eina_List *current_state;
49 #define ELM_TOOLBAR_ITEM_FROM_INLIST(item) \
50 ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Toolbar_Item) : NULL)
52 struct _Elm_Toolbar_Item_State
61 static const char *widtype = NULL;
62 static void _item_show(Elm_Toolbar_Item *it);
63 static void _item_select(Elm_Toolbar_Item *it);
64 static void _item_unselect(Elm_Toolbar_Item *it);
65 static void _item_disable(Elm_Toolbar_Item *it, Eina_Bool disabled);
66 static void _del_pre_hook(Evas_Object *obj);
67 static void _del_hook(Evas_Object *obj);
68 static void _mirrored_set(Evas_Object *obj, Eina_Bool mirrored);
69 static void _mirrored_set_item(Evas_Object *obj, Elm_Toolbar_Item *it, Eina_Bool mirrored);
70 static void _theme_hook(Evas_Object *obj);
71 static void _sizing_eval(Evas_Object *obj);
72 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
73 static void _menu_move_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
74 static void _menu_hide(void *data, Evas *e, Evas_Object *obj, void *event_info);
75 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
76 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);
77 static void _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal);
80 _item_icon_set(Evas_Object *icon_obj, const char *type, const char *icon)
84 if ((!type) || (!*type)) goto end;
85 if ((!icon) || (!*icon)) return EINA_FALSE;
86 if ((snprintf(icon_str, sizeof(icon_str), "%s%s", type, icon) > 0)
87 && (elm_icon_standard_set(icon_obj, icon_str)))
90 if (elm_icon_standard_set(icon_obj, icon))
92 WRN("couldn't find icon definition for '%s'", icon);
97 _elm_toolbar_icon_size_get(Widget_Data *wd)
99 const char *icon_size = edje_object_data_get(
100 elm_smart_scroller_edje_object_get(wd->scr), "icon_size");
102 return atoi(icon_size);
103 return _elm_config->icon_size;
107 _item_show(Elm_Toolbar_Item *it)
109 Widget_Data *wd = elm_widget_data_get(it->base.widget);
110 Evas_Coord x, y, w, h, bx, by;
113 evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
114 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
115 elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
119 _item_unselect(Elm_Toolbar_Item *item)
122 if ((!item) || (!item->selected)) return;
123 wd = elm_widget_data_get(item->base.widget);
125 item->selected = EINA_FALSE;
126 wd->selected_item = NULL;
127 edje_object_signal_emit(item->base.view, "elm,state,unselected", "elm");
128 elm_widget_signal_emit(item->icon, "elm,state,unselected", "elm");
132 _item_select(Elm_Toolbar_Item *it)
134 Elm_Toolbar_Item *it2;
135 Widget_Data *wd = elm_widget_data_get(it->base.widget);
139 if ((it->selected) || (it->disabled) || (it->separator)) return;
143 it2 = elm_toolbar_selected_item_get(it->base.widget);
146 it->selected = EINA_TRUE;
147 wd->selected_item = it;
148 edje_object_signal_emit(it->base.view, "elm,state,selected", "elm");
149 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
152 obj2 = it->base.widget;
155 evas_object_show(it->o_menu);
156 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_RESIZE,
157 _menu_move_resize, it);
158 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_MOVE,
159 _menu_move_resize, it);
161 _menu_move_resize(it, NULL, NULL, NULL);
163 if (it->func) it->func((void *)(it->base.data), it->base.widget, it);
164 evas_object_smart_callback_call(obj2, "clicked", it);
168 _menu_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
170 Elm_Toolbar_Item *selected;
171 Elm_Toolbar_Item *it = data;
172 selected = elm_toolbar_selected_item_get(it->base.widget);
173 _item_unselect(selected);
177 _menu_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
179 // avoid hide being emitted during object deletion
180 evas_object_event_callback_del_full
181 (obj, EVAS_CALLBACK_HIDE, _menu_hide, data);
185 _menu_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
187 Elm_Toolbar_Item *it = data;
189 Widget_Data *wd = elm_widget_data_get(it->base.widget);
191 if ((!wd) || (!wd->menu_parent)) return;
192 evas_object_geometry_get(it->base.view, &x, &y, &w, &h);
193 elm_menu_move(it->o_menu, x, y+h);
197 _item_disable(Elm_Toolbar_Item *it, Eina_Bool disabled)
199 Widget_Data *wd = elm_widget_data_get(it->base.widget);
202 if (it->disabled == disabled) return;
203 it->disabled = disabled;
206 edje_object_signal_emit(it->base.view, "elm,state,disabled", "elm");
207 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
211 edje_object_signal_emit(it->base.view, "elm,state,enabled", "elm");
212 elm_widget_signal_emit(it->icon, "elm,state,enabled", "elm");
217 _item_del(Elm_Toolbar_Item *it)
219 Elm_Toolbar_Item_State *it_state;
221 elm_widget_item_pre_notify_del(it);
222 EINA_LIST_FREE(it->states, it_state)
224 if (it->icon == it_state->icon)
226 eina_stringshare_del(it_state->label);
227 eina_stringshare_del(it_state->icon_str);
228 if (it_state->icon) evas_object_del(it_state->icon);
231 eina_stringshare_del(it->label);
232 eina_stringshare_del(it->icon_str);
233 if (it->icon) evas_object_del(it->icon);
234 //TODO: See if checking for wd->menu_parent is necessary before deleting menu
235 if (it->o_menu) evas_object_del(it->o_menu);
236 elm_widget_item_del(it);
240 _del_pre_hook(Evas_Object *obj)
242 Widget_Data *wd = elm_widget_data_get(obj);
243 Elm_Toolbar_Item *it, *next;
246 it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
249 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
254 _item_del(wd->more_item);
258 _del_hook(Evas_Object *obj)
260 Widget_Data *wd = elm_widget_data_get(obj);
268 _mirrored_set_item(Evas_Object *obj __UNUSED__, Elm_Toolbar_Item *it, Eina_Bool mirrored)
270 edje_object_mirrored_set(it->base.view, mirrored);
271 elm_widget_mirrored_set(it->o_menu, mirrored);
275 _theme_hook_item(Evas_Object *obj, Elm_Toolbar_Item *it, double scale, int icon_size)
277 Evas_Object *view = it->base.view;
279 const char *style = elm_widget_style_get(obj);
281 _mirrored_set_item(obj, it, elm_widget_mirrored_get(obj));
282 edje_object_scale_set(view, scale);
285 _elm_theme_object_set(obj, view, "toolbar", "item", style);
288 edje_object_signal_emit(view, "elm,state,selected", "elm");
289 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
293 edje_object_signal_emit(view, "elm,state,disabled", "elm");
294 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
300 ms = ((double)icon_size * scale);
301 evas_object_size_hint_min_set(it->icon, ms, ms);
302 evas_object_size_hint_max_set(it->icon, ms, ms);
303 edje_object_part_swallow(view, "elm.swallow.icon",
306 edje_object_part_text_set(view, "elm.text", it->label);
309 _elm_theme_object_set(obj, view, "toolbar", "separator", style);
313 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
314 edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
316 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
317 evas_object_size_hint_min_set(view, mw, mh);
321 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
323 Widget_Data *wd = elm_widget_data_get(obj);
324 Elm_Toolbar_Item *it;
326 EINA_INLIST_FOREACH(wd->items, it)
327 _mirrored_set_item(obj, it, mirrored);
329 _mirrored_set_item(obj, wd->more_item, mirrored);
333 _theme_hook(Evas_Object *obj)
335 Widget_Data *wd = elm_widget_data_get(obj);
336 Elm_Toolbar_Item *it;
340 _elm_widget_mirrored_reload(obj);
341 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
342 _mirrored_set(obj, elm_widget_mirrored_get(obj));
343 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
344 edje_object_scale_set(wd->scr, scale);
345 wd->icon_size = _elm_toolbar_icon_size_get(wd);
346 EINA_INLIST_FOREACH(wd->items, it)
347 _theme_hook_item(obj, it, scale, wd->icon_size);
349 _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
354 _sizing_eval(Evas_Object *obj)
356 Widget_Data *wd = elm_widget_data_get(obj);
357 Evas_Coord minw = -1, minh = -1, minw_bx;
358 Evas_Coord vw = 0, vh = 0;
362 evas_object_smart_calculate(wd->bx);
363 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
365 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
366 if (w < minw) w = minw;
367 if (h < minh) h = minh;
369 evas_object_resize(wd->scr, w, h);
371 evas_object_size_hint_min_get(wd->bx, &minw, &minh);
373 if (w > minw) minw = w;
374 evas_object_resize(wd->bx, minw, minh);
375 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
376 switch (wd->shrink_mode)
378 case ELM_TOOLBAR_SHRINK_MENU: /* fallthrough */
379 case ELM_TOOLBAR_SHRINK_HIDE: /* fallthrough */
380 case ELM_TOOLBAR_SHRINK_SCROLL: minw = w - vw; break;
381 case ELM_TOOLBAR_SHRINK_NONE: minw = minw_bx + (w - vw); break;
383 minh = minh + (h - vh);
384 evas_object_size_hint_min_set(obj, minw, minh);
385 evas_object_size_hint_max_set(obj, -1, -1);
389 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
391 item->o_menu = elm_menu_add(item->base.view);
393 elm_menu_parent_set(item->o_menu, wd->menu_parent);
394 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
396 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
401 _item_menu_destroy(Elm_Toolbar_Item *item)
405 evas_object_del(item->o_menu);
411 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
413 const Elm_Toolbar_Item *eti1 = i1;
414 const Elm_Toolbar_Item *eti2 = i2;
417 if (!eti1) return -1;
419 return eti2->prio.priority - eti1->prio.priority;
423 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
425 Elm_Toolbar_Item *it;
426 Eina_List *sorted = NULL;
429 EINA_INLIST_FOREACH(wd->items, it)
431 sorted = eina_list_sorted_insert(sorted,
432 _toolbar_item_prio_compare_cb, it);
437 evas_object_geometry_get(wd->more_item->base.view, NULL, NULL, &ciw, NULL);
440 EINA_LIST_FREE(sorted, it)
442 evas_object_geometry_get(it->base.view, NULL, NULL, &ciw, NULL);
444 it->prio.visible = (*iw <= vw);
449 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
451 Elm_Toolbar_Item *it = data;
452 if (it->func) it->func((void *)(it->base.data), it->base.widget, it);
456 _resize_job(void *data)
458 Widget_Data *wd = elm_widget_data_get(data);
459 Evas_Coord mw, mh, vw, vh, w, h;
460 Elm_Toolbar_Item *it;
461 Evas_Object *obj = (Evas_Object *) data;
464 wd->resize_job = NULL;
465 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
466 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
467 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
468 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
470 Evas_Coord iw = 0, more_w;
472 evas_object_resize(wd->bx, vw, h);
473 _fix_items_visibility(wd, &iw, vw);
474 evas_object_geometry_get(wd->more_item->base.view, NULL, NULL, &more_w, NULL);
475 if (iw - more_w <= vw)
478 /* All items are removed from the box object, since removing individual
479 * items won't trigger a resize. Items are be readded below. */
480 evas_object_box_remove_all(wd->bx, EINA_FALSE);
485 _item_menu_destroy(wd->more_item);
486 _item_menu_create(wd, wd->more_item);
487 menu = elm_toolbar_item_menu_get(wd->more_item);
489 EINA_INLIST_FOREACH(wd->items, it)
491 if (!it->prio.visible)
494 elm_menu_item_separator_add(menu, NULL);
498 item = elm_menu_item_add(menu, NULL, it->icon_str, it->label,
499 _elm_toolbar_item_menu_cb, it);
500 elm_menu_item_disabled_set(item, it->disabled);
501 if (it->o_menu) elm_menu_clone(it->o_menu, menu, item);
503 evas_object_hide(it->base.view);
507 evas_object_box_append(wd->bx, it->base.view);
508 evas_object_show(it->base.view);
512 evas_object_box_append(wd->bx, wd->more_item->base.view);
513 evas_object_show(wd->more_item->base.view);
517 /* All items are visible, show them all (except for the "More"
518 * button, of course). */
519 EINA_INLIST_FOREACH(wd->items, it)
521 evas_object_show(it->base.view);
522 evas_object_box_append(wd->bx, it->base.view);
524 evas_object_hide(wd->more_item->base.view);
527 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
531 evas_object_resize(wd->bx, vw, h);
532 _fix_items_visibility(wd, &iw, vw);
533 evas_object_box_remove_all(wd->bx, EINA_FALSE);
536 EINA_INLIST_FOREACH(wd->items, it)
538 if (!it->prio.visible)
539 evas_object_hide(it->base.view);
542 evas_object_box_append(wd->bx, it->base.view);
543 evas_object_show(it->base.view);
549 /* All items are visible, show them all */
550 EINA_INLIST_FOREACH(wd->items, it)
552 evas_object_show(it->base.view);
553 evas_object_box_append(wd->bx, it->base.view);
559 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
560 EINA_INLIST_FOREACH(wd->items, it)
570 _mirrored_set(obj, elm_widget_mirrored_get(obj));
574 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
577 _resize(data, NULL, NULL, NULL);
581 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
583 Widget_Data *wd = elm_widget_data_get(data);
585 wd->resize_job = ecore_job_add(_resize_job, data);
589 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
595 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
597 Elm_Toolbar_Item *it = data;
598 edje_object_signal_emit(it->base.view, "elm,state,highlighted", "elm");
599 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
603 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
605 Elm_Toolbar_Item *it = data;
606 edje_object_signal_emit(it->base.view, "elm,state,unhighlighted", "elm");
607 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
611 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
613 Evas_Object *obj = (Evas_Object *) data;
614 Widget_Data *wd = elm_widget_data_get(obj);
616 _els_box_layout(o, priv, 1, wd->homogeneous, elm_widget_mirrored_get(obj));
619 static Elm_Toolbar_Item *
620 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
622 Widget_Data *wd = elm_widget_data_get(obj);
623 Evas_Object *icon_obj;
625 Elm_Toolbar_Item *it;
627 icon_obj = elm_icon_add(obj);
628 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
629 if (!icon_obj) return NULL;
630 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
633 evas_object_del(icon_obj);
636 it->label = eina_stringshare_add(label);
637 it->prio.visible = 1;
638 it->prio.priority = 0;
640 it->separator = EINA_FALSE;
641 it->base.data = data;
642 it->base.view = edje_object_add(evas_object_evas_get(obj));
643 if (_item_icon_set(icon_obj, "toolbar/", icon))
646 it->icon_str = eina_stringshare_add(icon);
652 evas_object_del(icon_obj);
655 _elm_theme_object_set(obj, it->base.view, "toolbar", "item",
656 elm_widget_style_get(obj));
657 edje_object_signal_callback_add(it->base.view, "elm,action,click", "elm",
659 edje_object_signal_callback_add(it->base.view, "elm,mouse,in", "elm",
661 edje_object_signal_callback_add(it->base.view, "elm,mouse,out", "elm",
663 elm_widget_sub_object_add(obj, it->base.view);
668 ms = ((double)wd->icon_size * _elm_config->scale);
669 evas_object_size_hint_min_set(it->icon, ms, ms);
670 evas_object_size_hint_max_set(it->icon, ms, ms);
671 edje_object_part_swallow(it->base.view, "elm.swallow.icon", it->icon);
672 evas_object_show(it->icon);
673 elm_widget_sub_object_add(obj, it->icon);
675 edje_object_part_text_set(it->base.view, "elm.text", it->label);
677 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
678 edje_object_size_min_restricted_calc(it->base.view, &mw, &mh, mw, mh);
679 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
680 evas_object_size_hint_weight_set(it->base.view, -1.0, EVAS_HINT_EXPAND);
681 evas_object_size_hint_align_set(it->base.view, 0.5, EVAS_HINT_FILL);
682 evas_object_size_hint_min_set(it->base.view, mw, mh);
683 evas_object_event_callback_add(it->base.view, EVAS_CALLBACK_RESIZE,
689 * Add a toolbar object to @p parent.
691 * @param parent The parent object
693 * @return The created object, or NULL on failure
698 elm_toolbar_add(Evas_Object *parent)
704 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
706 ELM_SET_WIDTYPE(widtype, "toolbar");
707 elm_widget_type_set(obj, "toolbar");
708 elm_widget_sub_object_add(parent, obj);
709 elm_widget_data_set(obj, wd);
710 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
711 elm_widget_del_hook_set(obj, _del_hook);
712 elm_widget_theme_hook_set(obj, _theme_hook);
713 elm_widget_can_focus_set(obj, EINA_FALSE);
715 wd->more_item = NULL;
716 wd->selected_item = NULL;
717 wd->scr = elm_smart_scroller_add(e);
718 elm_smart_scroller_widget_set(wd->scr, obj);
719 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
720 elm_smart_scroller_bounce_allow_set(wd->scr,
721 _elm_config->thumbscroll_bounce_enable,
723 elm_widget_resize_object_set(obj, wd->scr);
724 elm_smart_scroller_policy_set(wd->scr,
725 ELM_SMART_SCROLLER_POLICY_AUTO,
726 ELM_SMART_SCROLLER_POLICY_OFF);
729 wd->icon_size = _elm_toolbar_icon_size_get(wd);
732 wd->homogeneous = EINA_TRUE;
735 wd->bx = evas_object_box_add(e);
736 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
737 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
738 elm_widget_sub_object_add(obj, wd->bx);
739 elm_smart_scroller_child_set(wd->scr, wd->bx);
740 evas_object_show(wd->bx);
742 elm_toolbar_mode_shrink_set(obj, _elm_config->toolbar_shrink_mode);
743 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
744 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
745 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
752 * Set the icon size (in pixels) for the toolbar.
754 * @param obj The toolbar object
755 * @param icon_size The icon size in pixels
760 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
762 ELM_CHECK_WIDTYPE(obj, widtype);
763 Widget_Data *wd = elm_widget_data_get(obj);
765 if (wd->icon_size == icon_size) return;
766 wd->icon_size = icon_size;
771 * Get the icon size (in pixels) for the toolbar.
773 * @param obj The toolbar object
774 * @return The icon size in pixels
779 elm_toolbar_icon_size_get(const Evas_Object *obj)
781 ELM_CHECK_WIDTYPE(obj, widtype) 0;
782 Widget_Data *wd = elm_widget_data_get(obj);
784 return wd->icon_size;
788 * Append item to the toolbar
790 * @param obj The toolbar object
791 * @param icon A string with icon name or the absolute path of an image file.
792 * @param label The label of the item
793 * @param func The function to call when the item is clicked
794 * @param data The data to associate with the item
795 * @return The toolbar item, or NULL upon failure
797 * @see elm_toolbar_item_icon_set
801 EAPI Elm_Toolbar_Item *
802 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
804 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
805 Widget_Data *wd = elm_widget_data_get(obj);
806 if (!wd) return NULL;
808 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
809 if (!it) return NULL;
811 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
812 evas_object_box_append(wd->bx, it->base.view);
813 evas_object_show(it->base.view);
820 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
822 Elm_Toolbar_Item *it = event_info;
823 Elm_Toolbar_Item_State *it_state;
825 it_state = eina_list_data_get(it->current_state);
827 it_state->func((void *)it_state->data, obj, event_info);
831 * Sets the next @p item state as the current state.
833 * @param item The item.
837 EAPI Elm_Toolbar_Item_State *
838 elm_toolbar_item_state_next(Elm_Toolbar_Item *item)
842 Eina_List *next_state;
843 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
845 obj = item->base.widget;
846 wd = elm_widget_data_get(obj);
847 if (!wd) return NULL;
848 if (!item->states) return NULL;
850 next_state = eina_list_next(item->current_state);
852 next_state = eina_list_next(item->states);
853 return eina_list_data_get(next_state);
857 * Sets the previous @p item state as the current state.
859 * @param item The item.
863 EAPI Elm_Toolbar_Item_State *
864 elm_toolbar_item_state_prev(Elm_Toolbar_Item *item)
868 Eina_List *prev_state;
869 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
871 obj = item->base.widget;
872 wd = elm_widget_data_get(obj);
873 if (!wd) return NULL;
874 if (!item->states) return NULL;
876 prev_state = eina_list_prev(item->current_state);
877 if ((!prev_state) || (prev_state == item->states))
878 prev_state = eina_list_last(item->states);
879 return eina_list_data_get(prev_state);
883 * Unset the state of @p it
884 * The default icon and label from this item will be displayed.
886 * @param it The item.
891 elm_toolbar_item_state_unset(Elm_Toolbar_Item *it)
893 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it);
894 elm_toolbar_item_state_set(it, NULL);
898 * Sets @p state as the current state of @p it.
899 * If @p state is NULL, it won't select any state and the default icon and
900 * label will be used.
902 * @param it The item.
903 * @param state The state to use.
905 * @return True if the state was correctly set.
910 elm_toolbar_item_state_set(Elm_Toolbar_Item *it, Elm_Toolbar_Item_State *state)
913 Eina_List *next_state;
914 Elm_Toolbar_Item_State *it_state;
916 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, EINA_FALSE);
918 obj = it->base.widget;
919 wd = elm_widget_data_get(obj);
920 if (!wd) return EINA_FALSE;
921 if (!it->states) return EINA_FALSE;
925 next_state = eina_list_data_find_list(it->states, state);
926 if (!next_state) return EINA_FALSE;
929 next_state = it->states;
931 if (next_state == it->current_state) return EINA_TRUE;
933 it_state = eina_list_data_get(next_state);
934 if (eina_list_data_find(it->current_state, state))
936 _item_label_set(it, it_state->label, "elm,state,label_set,forward");
937 _elm_toolbar_item_icon_obj_set(obj, it, it_state->icon, it_state->icon_str,
938 wd->icon_size, "elm,state,icon_set,forward");
942 _item_label_set(it, it_state->label, "elm,state,label_set,backward");
943 _elm_toolbar_item_icon_obj_set(obj, it, it_state->icon, it_state->icon_str,
944 wd->icon_size, "elm,state,icon_set,backward");
947 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
949 elm_widget_signal_emit(it->icon, "elm,state,enabled", "elm");
951 it->current_state = next_state;
956 * Get the current state of @p item.
957 * If no state is selected, returns NULL.
959 * @param item The item.
965 EAPI Elm_Toolbar_Item_State *
966 elm_toolbar_item_state_get(const Elm_Toolbar_Item *it)
968 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
969 if ((!it->states) || (!it->current_state)) return NULL;
970 if (it->current_state == it->states) return NULL;
972 return eina_list_data_get(it->current_state);
975 static Elm_Toolbar_Item_State *
976 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
978 Elm_Toolbar_Item_State *it_state;
979 it_state = ELM_NEW(Elm_Toolbar_Item_State);
980 it_state->label = eina_stringshare_add(label);
981 it_state->icon_str = eina_stringshare_add(icon_str);
982 it_state->icon = icon;
983 it_state->func = func;
984 it_state->data = data;
989 * Add a new state to @p item
991 * @param item The item.
992 * @param icon The icon string
993 * @param label The label of the new state
994 * @param func The function to call when the item is clicked when this state is
996 * @param data The data to associate with the state
997 * @return The toolbar item state, or NULL upon failure
1001 EAPI Elm_Toolbar_Item_State *
1002 elm_toolbar_item_state_add(Elm_Toolbar_Item *item, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1004 Elm_Toolbar_Item_State *it_state;
1005 Evas_Object *icon_obj;
1008 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1009 obj = item->base.widget;
1010 wd = elm_widget_data_get(item->base.widget);
1011 if (!wd) return NULL;
1015 it_state = _item_state_new(item->label, item->icon_str, item->icon,
1016 item->func, item->base.data);
1017 item->states = eina_list_append(item->states, it_state);
1018 item->current_state = item->states;
1021 icon_obj = elm_icon_add(obj);
1022 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1023 if (!icon_obj) goto error_state_add;
1025 if (!_item_icon_set(icon_obj, "toolbar/", icon))
1027 evas_object_del(icon_obj);
1032 it_state = _item_state_new(label, icon, icon_obj, func, data);
1033 item->states = eina_list_append(item->states, it_state);
1034 item->func = _elm_toolbar_item_state_cb;
1035 item->base.data = NULL;
1040 if (item->states && !eina_list_next(item->states))
1042 eina_stringshare_del(item->label);
1043 eina_stringshare_del(item->icon_str);
1044 free(eina_list_data_get(item->states));
1045 eina_list_free(item->states);
1046 item->states = NULL;
1052 elm_toolbar_item_state_del(Elm_Toolbar_Item *item, Elm_Toolbar_Item_State *state)
1054 Eina_List *del_state;
1055 Elm_Toolbar_Item_State *it_state;
1056 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1058 if (!state) return EINA_FALSE;
1059 if (!item->states) return EINA_FALSE;
1061 del_state = eina_list_data_find_list(item->states, state);
1062 if (del_state == item->states) return EINA_FALSE;
1063 if (del_state == item->current_state)
1064 elm_toolbar_item_state_unset(item);
1066 eina_stringshare_del(state->label);
1067 eina_stringshare_del(state->icon_str);
1068 if (state->icon) evas_object_del(state->icon);
1070 item->states = eina_list_remove_list(item->states, del_state);
1071 if (item->states && !eina_list_next(item->states))
1073 it_state = eina_list_data_get(item->states);
1074 item->base.data = it_state->data;
1075 item->func = it_state->func;
1076 eina_stringshare_del(it_state->label);
1077 eina_stringshare_del(it_state->icon_str);
1078 free(eina_list_data_get(item->states));
1079 eina_list_free(item->states);
1080 item->states = NULL;
1087 * Prepend item to the toolbar
1089 * @param obj The toolbar object
1090 * @param icon A string with icon name or the absolute path of an image file.
1091 * @param label The label of the item
1092 * @param func The function to call when the item is clicked
1093 * @param data The data to associate with the item
1094 * @return The toolbar item, or NULL upon failure
1096 * @see elm_toolbar_item_icon_set
1100 EAPI Elm_Toolbar_Item *
1101 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1103 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1104 Widget_Data *wd = elm_widget_data_get(obj);
1105 if (!wd) return NULL;
1107 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1108 if (!it) return NULL;
1110 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1111 evas_object_box_prepend(wd->bx, it->base.view);
1112 evas_object_show(it->base.view);
1119 * Insert item before another in the toolbar
1121 * @param obj The toolbar object
1122 * @param before The item to insert before
1123 * @param icon A string with icon name or the absolute path of an image file.
1124 * @param label The label of the item
1125 * @param func The function to call when the item is clicked
1126 * @param data The data to associate with the item
1127 * @return The toolbar item, or NULL upon failure
1129 * @see elm_toolbar_item_icon_set
1133 EAPI Elm_Toolbar_Item *
1134 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)
1136 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1137 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(before, NULL);
1138 Widget_Data *wd = elm_widget_data_get(obj);
1139 if (!wd) return NULL;
1141 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1142 if (!it) return NULL;
1144 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1145 EINA_INLIST_GET(before));
1146 evas_object_box_insert_before(wd->bx, it->base.view, before->base.view);
1147 evas_object_show(it->base.view);
1154 * Insert item after another in the toolbar
1156 * @param obj The toolbar object
1157 * @param after The item to insert after
1158 * @param icon A string with icon name or the absolute path of an image file.
1159 * @param label The label of the item
1160 * @param func The function to call when the item is clicked
1161 * @param data The data to associate with the item
1162 * @return The toolbar item, or NULL upon failure
1164 * @see elm_toolbar_item_icon_set
1168 EAPI Elm_Toolbar_Item *
1169 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)
1171 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1172 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(after, NULL);
1173 Widget_Data *wd = elm_widget_data_get(obj);
1174 if (!wd) return NULL;
1176 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1177 if (!it) return NULL;
1179 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1180 EINA_INLIST_GET(after));
1181 evas_object_box_insert_after(wd->bx, it->base.view, after->base.view);
1182 evas_object_show(it->base.view);
1189 * Get the first item in the toolbar
1191 * @param obj The toolbar object
1192 * @return The first item, or NULL if none
1196 EAPI Elm_Toolbar_Item *
1197 elm_toolbar_first_item_get(const Evas_Object *obj)
1199 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1200 Widget_Data *wd = elm_widget_data_get(obj);
1201 if (!wd || !wd->items) return NULL;
1202 Elm_Toolbar_Item *it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1207 * Get the last item in the toolbar
1209 * @return The last item, or NULL if none
1213 EAPI Elm_Toolbar_Item *
1214 elm_toolbar_last_item_get(const Evas_Object *obj)
1216 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1217 Widget_Data *wd = elm_widget_data_get(obj);
1218 if (!wd || !wd->items) return NULL;
1219 Elm_Toolbar_Item *it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1224 * Get the next item in the toolbar
1226 * This returns the item after the item @p it.
1228 * @param item The item
1229 * @return The item after @p it, or NULL if none
1233 EAPI Elm_Toolbar_Item *
1234 elm_toolbar_item_next_get(const Elm_Toolbar_Item *item)
1236 Elm_Toolbar_Item *next;
1237 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1238 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
1243 * Get the previous item in the toolbar
1245 * This returns the item before the item @p it.
1247 * @param item The item
1248 * @return The item before @p it, or NULL if none
1252 EAPI Elm_Toolbar_Item *
1253 elm_toolbar_item_prev_get(const Elm_Toolbar_Item *item)
1255 Elm_Toolbar_Item *prev;
1256 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1257 prev = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->prev);
1262 * Get the toolbar object from an item
1264 * This returns the toolbar object itself that an item belongs to.
1266 * @param item The item
1267 * @return The toolbar object
1272 elm_toolbar_item_toolbar_get(const Elm_Toolbar_Item *item)
1274 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1275 return item->base.widget;
1279 * Sets the priority of a toolbar item. This is used only when the toolbar
1280 * shrink mode is set to ELM_TOOLBAR_SHRINK_MENU or ELM_TOOLBAR_SHRINK_HIDE:
1281 * when space is at a premium, items with low priority will be removed from
1282 * the toolbar and added to a dynamically-created menu, while items with
1283 * higher priority will remain on the toolbar, with the same order they were
1286 * @param item The toolbar item.
1287 * @param priority The item priority. The default is zero.
1292 elm_toolbar_item_priority_set(Elm_Toolbar_Item *item, int priority)
1294 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1295 if (item->prio.priority == priority) return;
1296 item->prio.priority = priority;
1297 _resize(item->base.widget, NULL, NULL, NULL);
1301 * Gets the priority of a toolbar item.
1303 * @param item The toolbar item.
1304 * @return The item priority, or 0 if an error occurred.
1309 elm_toolbar_item_priority_get(const Elm_Toolbar_Item *item)
1311 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, 0);
1312 return item->prio.priority;
1316 * Get the string used to set the icon of @p item.
1318 * @param item The toolbar item
1319 * @return The string associated with the icon object.
1321 * @see elm_toolbar_item_icon_set()
1326 elm_toolbar_item_icon_get(const Elm_Toolbar_Item *item)
1328 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1329 return item->icon_str;
1333 * Get the label associated with @p item.
1335 * @param item The toolbar item
1341 elm_toolbar_item_label_get(const Elm_Toolbar_Item *item)
1343 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1348 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
1350 Evas_Coord mw = -1, mh = -1;
1351 edje_object_part_text_set(item->base.view, "elm.text", item->label);
1353 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1354 edje_object_size_min_restricted_calc(item->base.view, &mw, &mh, mw, mh);
1355 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1356 evas_object_size_hint_weight_set(item->base.view, -1.0, EVAS_HINT_EXPAND);
1357 evas_object_size_hint_align_set(item->base.view, 0.5, EVAS_HINT_FILL);
1358 evas_object_size_hint_min_set(item->base.view, mw, mh);
1362 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1364 Elm_Toolbar_Item *item = data;
1365 _elm_toolbar_item_label_update(item);
1366 edje_object_signal_callback_del(obj, emission, source,
1367 _elm_toolbar_item_label_set_cb);
1368 edje_object_signal_emit (item->base.view, "elm,state,label,reset", "elm");
1372 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal)
1376 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
1378 eina_stringshare_replace(&item->label, label);
1379 s = edje_object_data_get(item->base.view, "transition_animation_on");
1380 if ((s) && (atoi(s)))
1382 edje_object_part_text_set(item->base.view, "elm.text_new", item->label);
1383 edje_object_signal_emit (item->base.view, signal, "elm");
1384 edje_object_signal_callback_add(item->base.view,
1385 "elm,state,label_set,done", "elm",
1386 _elm_toolbar_item_label_set_cb, item);
1389 _elm_toolbar_item_label_update(item);
1390 _resize(item->base.widget, NULL, NULL, NULL);
1394 * Set the label associated with @p item.
1396 * @param item The toolbar item
1397 * @param label The label of @p item
1402 elm_toolbar_item_label_set(Elm_Toolbar_Item *item, const char *label)
1404 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1405 _item_label_set(item, label, "elm,state,label_set");
1409 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
1411 Elm_Toolbar_Item_State *it_state;
1413 Evas_Coord mw = -1, mh = -1;
1414 Evas_Object *old_icon = edje_object_part_swallow_get(item->base.view,
1415 "elm.swallow.icon");
1416 elm_widget_sub_object_del(item->base.view, old_icon);
1417 evas_object_hide(old_icon);
1418 edje_object_part_swallow(item->base.view, "elm.swallow.icon", item->icon);
1419 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1420 edje_object_size_min_restricted_calc(item->base.view, &mw, &mh, mw, mh);
1421 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1422 evas_object_size_hint_weight_set(item->base.view, -1.0, EVAS_HINT_EXPAND);
1423 evas_object_size_hint_align_set(item->base.view, 0.5, EVAS_HINT_FILL);
1424 evas_object_size_hint_min_set(item->base.view, mw, mh);
1426 EINA_LIST_FOREACH(item->states, l, it_state)
1427 if (it_state->icon == old_icon)
1429 evas_object_del(old_icon);
1433 * Get the selected state of @p item.
1435 * @param item The toolbar item
1436 * @return If true, the item is selected
1441 elm_toolbar_item_selected_get(const Elm_Toolbar_Item *item)
1443 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1444 return item->selected;
1448 * Set the selected state of an item
1450 * This sets the selected state (1 selected, 0 not selected) of the given
1451 * item @p it. If a new item is selected the previosly selected will be
1454 * @param item The item
1455 * @param selected The selected state
1460 elm_toolbar_item_selected_set(Elm_Toolbar_Item *item, Eina_Bool selected)
1462 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1463 Widget_Data *wd = elm_widget_data_get(item->base.widget);
1466 if (item->selected == selected) return;
1471 _item_unselect(item);
1475 * Get the selectd item in the toolbar
1477 * If no item is selected, NULL is returned.
1479 * @param obj The toolbar object
1480 * @return The selected item, or NULL if none.
1484 EAPI Elm_Toolbar_Item *
1485 elm_toolbar_selected_item_get(const Evas_Object *obj)
1487 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1488 Widget_Data *wd = elm_widget_data_get(obj);
1489 if (!wd) return NULL;
1490 return wd->selected_item;
1494 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1496 Elm_Toolbar_Item *item = data;
1497 edje_object_part_unswallow(item->base.view, item->icon);
1498 _elm_toolbar_item_icon_update(item);
1499 edje_object_signal_callback_del(obj, emission, source,
1500 _elm_toolbar_item_icon_set_cb);
1501 edje_object_signal_emit (item->base.view, "elm,state,icon,reset", "elm");
1505 _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)
1507 Evas_Object *old_icon;
1512 eina_stringshare_replace(&item->icon_str, icon_str);
1515 eina_stringshare_del(item->icon_str);
1516 item->icon_str = NULL;
1518 item->icon = icon_obj;
1521 ms = (icon_size * _elm_config->scale);
1522 evas_object_size_hint_min_set(item->icon, ms, ms);
1523 evas_object_size_hint_max_set(item->icon, ms, ms);
1524 evas_object_show(item->icon);
1525 elm_widget_sub_object_add(obj, item->icon);
1527 s = edje_object_data_get(item->base.view, "transition_animation_on");
1528 if ((s) && (atoi(s)))
1530 old_icon = edje_object_part_swallow_get(item->base.view,
1531 "elm.swallow.icon_new");
1534 elm_widget_sub_object_del(item->base.view, old_icon);
1535 evas_object_hide(old_icon);
1537 edje_object_part_swallow(item->base.view, "elm.swallow.icon_new",
1539 edje_object_signal_emit (item->base.view, signal, "elm");
1540 edje_object_signal_callback_add(item->base.view,
1541 "elm,state,icon_set,done", "elm",
1542 _elm_toolbar_item_icon_set_cb, item);
1545 _elm_toolbar_item_icon_update(item);
1546 _resize(obj, NULL, NULL, NULL);
1550 * Set the icon associated with @p item.
1552 * Toolbar will load icon image from fdo or current theme.
1553 * This behavior can be set by elm_toolbar_icon_order_lookup_set() function.
1554 * If an absolute path is provided it will load it direct from a file.
1556 * @param obj The parent of this item
1557 * @param item The toolbar item
1558 * @param icon A string with icon name or the absolute path of an image file.
1560 * @see elm_toolbar_icon_order_lookup_set(), elm_toolbar_icon_order_lookup_get()
1565 elm_toolbar_item_icon_set(Elm_Toolbar_Item *item, const char *icon)
1567 Evas_Object *icon_obj;
1569 Evas_Object *obj = item->base.widget;
1571 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1572 wd = elm_widget_data_get(obj);
1574 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1576 icon_obj = elm_icon_add(obj);
1577 if (!icon_obj) return;
1578 if (_item_icon_set(icon_obj, "toolbar/", icon))
1579 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1580 "elm,state,icon_set");
1583 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1584 "elm,state,icon_set");
1585 evas_object_del(icon_obj);
1590 * Delete a toolbar item.
1592 * @param item The toolbar item
1597 elm_toolbar_item_del(Elm_Toolbar_Item *item)
1602 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1603 wd = elm_widget_data_get(item->base.widget);
1605 obj2 = item->base.widget;
1606 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
1612 * Set the function called when a toolbar item is freed.
1614 * @param item The item to set the callback on
1615 * @param func The function called
1620 elm_toolbar_item_del_cb_set(Elm_Toolbar_Item *item, Evas_Smart_Cb func)
1622 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1623 elm_widget_item_del_cb_set(item, func);
1627 * Get the disabled state of @p item.
1629 * @param item The toolbar item
1630 * @return If true, the item is disabled
1635 elm_toolbar_item_disabled_get(const Elm_Toolbar_Item *item)
1637 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1638 return item->disabled;
1642 * Set the disabled state of @p item.
1644 * @param item The toolbar item
1645 * @param disabled If true, the item is disabled
1650 elm_toolbar_item_disabled_set(Elm_Toolbar_Item *item, Eina_Bool disabled)
1652 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1653 _item_disable(item, disabled);
1654 _resize(item->base.widget, NULL, NULL, NULL);
1658 * Get the separator state of @p item.
1660 * @param item The toolbar item
1661 * @param separator If true, the item is a separator
1666 elm_toolbar_item_separator_set(Elm_Toolbar_Item *item, Eina_Bool separator)
1668 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1669 if (item->separator == separator) return;
1670 item->separator = separator;
1671 _theme_hook(item->base.view);
1675 * Set the separator state of @p item.
1677 * @param item The toolbar item
1678 * @return If true, the item is a separator
1683 elm_toolbar_item_separator_get(const Elm_Toolbar_Item *item)
1685 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1686 return item->separator;
1690 * Set the shrink state of toolbar @p obj.
1692 * @param obj The toolbar object
1693 * @param shrink_mode The toolbar won't scroll if ELM_TOOLBAR_SHRINK_NONE,
1694 * but will enforce a minimun size so all the items will fit, won't scroll
1695 * and won't show the items that don't fit if ELM_TOOLBAR_SHRINK_HIDE,
1696 * will scroll if ELM_TOOLBAR_SHRINK_SCROLL, and will create a button to
1697 * pop up excess elements with ELM_TOOLBAR_SHRINK_MENU.
1702 elm_toolbar_mode_shrink_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1704 ELM_CHECK_WIDTYPE(obj, widtype);
1705 Widget_Data *wd = elm_widget_data_get(obj);
1709 wd->shrink_mode = shrink_mode;
1710 bounce = (_elm_config->thumbscroll_bounce_enable) &&
1711 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1712 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1716 _item_del(wd->more_item);
1717 wd->more_item = NULL;
1720 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1722 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF, ELM_SMART_SCROLLER_POLICY_OFF);
1724 wd->more_item = _item_new(obj, "more_menu", "More",
1727 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1728 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1729 ELM_SMART_SCROLLER_POLICY_OFF);
1731 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1732 ELM_SMART_SCROLLER_POLICY_OFF);
1737 * Get the shrink mode of toolbar @p obj.
1739 * @param obj The toolbar object
1740 * @return See elm_toolbar_mode_shrink_set.
1744 EAPI Elm_Toolbar_Shrink_Mode
1745 elm_toolbar_mode_shrink_get(const Evas_Object *obj)
1747 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1748 Widget_Data *wd = elm_widget_data_get(obj);
1750 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1751 return wd->shrink_mode;
1755 * Set the homogenous mode of toolbar @p obj.
1757 * @param obj The toolbar object
1758 * @param homogenous If true, the toolbar items will be uniform in size
1763 elm_toolbar_homogenous_set(Evas_Object *obj, Eina_Bool homogenous)
1765 ELM_CHECK_WIDTYPE(obj, widtype);
1766 Widget_Data *wd = elm_widget_data_get(obj);
1769 wd->homogeneous = !!homogenous;
1770 evas_object_smart_calculate(wd->bx);
1774 * Get the homogenous mode of toolbar @p obj.
1776 * @param obj The toolbar object
1777 * @return If true, the toolbar items are uniform in size
1782 elm_toolbar_homogenous_get(const Evas_Object *obj)
1784 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1785 Widget_Data *wd = elm_widget_data_get(obj);
1787 if (!wd) return EINA_FALSE;
1788 return wd->homogeneous;
1792 * Set the parent object of the toolbar menu
1794 * @param obj The toolbar object
1795 * @param parent The parent of the menu object
1800 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1802 Elm_Toolbar_Item *it;
1803 ELM_CHECK_WIDTYPE(obj, widtype);
1804 Widget_Data *wd = elm_widget_data_get(obj);
1807 EINA_SAFETY_ON_NULL_RETURN(parent);
1808 wd->menu_parent = parent;
1809 EINA_INLIST_FOREACH(wd->items, it)
1812 elm_menu_parent_set(it->o_menu, wd->menu_parent);
1814 if ((wd->more_item) && (wd->more_item->o_menu))
1815 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1819 * Get the parent object of the toolbar menu
1821 * @param obj The toolbar object
1822 * @return The parent of the menu object
1827 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1829 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1830 Widget_Data *wd = elm_widget_data_get(obj);
1832 if (!wd) return NULL;
1833 return wd->menu_parent;
1837 * Set the alignment of the items.
1839 * @param obj The toolbar object
1840 * @param align The new alignment. (left) 0.0 ... 1.0 (right)
1845 elm_toolbar_align_set(Evas_Object *obj, double align)
1847 ELM_CHECK_WIDTYPE(obj, widtype);
1848 Widget_Data *wd = elm_widget_data_get(obj);
1851 if (wd->align != align)
1852 evas_object_size_hint_align_set(wd->bx, align, 0.5);
1857 * Get the alignment of the items.
1859 * @param obj The toolbar object
1860 * @return The alignment. (left) 0.0 ... 1.0 (right)
1865 elm_toolbar_align_get(const Evas_Object *obj)
1867 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1868 Widget_Data *wd = elm_widget_data_get(obj);
1870 if (!wd) return 0.0;
1875 * Set whether the toolbar item opens a menu.
1877 * @param item The toolbar item
1878 * @param menu If true, @p item will open a menu when selected
1883 elm_toolbar_item_menu_set(Elm_Toolbar_Item *item, Eina_Bool menu)
1885 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1886 Widget_Data *wd = elm_widget_data_get(item->base.widget);
1889 if (item->menu == menu) return;
1891 if (menu) _item_menu_create(wd, item);
1892 else _item_menu_destroy(item);
1896 * Set the text to be shown in the toolbar item.
1898 * @param item Target item
1899 * @param text The text to set in the content
1901 * Setup the text as tooltip to object. The item can have only one tooltip,
1902 * so any previous tooltip data is removed.
1907 elm_toolbar_item_tooltip_text_set(Elm_Toolbar_Item *item, const char *text)
1909 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1910 elm_widget_item_tooltip_text_set(item, text);
1914 * Set the content to be shown in the tooltip item
1916 * Setup the tooltip to item. The item can have only one tooltip,
1917 * so any previous tooltip data is removed. @p func(with @p data) will
1918 * be called every time that need show the tooltip and it should
1919 * return a valid Evas_Object. This object is then managed fully by
1920 * tooltip system and is deleted when the tooltip is gone.
1922 * @param item the toolbar item being attached a tooltip.
1923 * @param func the function used to create the tooltip contents.
1924 * @param data what to provide to @a func as callback data/context.
1925 * @param del_cb called when data is not needed anymore, either when
1926 * another callback replaces @func, the tooltip is unset with
1927 * elm_toolbar_item_tooltip_unset() or the owner @a item
1928 * dies. This callback receives as the first parameter the
1929 * given @a data, and @c event_info is the item.
1934 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)
1936 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1937 elm_widget_item_tooltip_content_cb_set(item, func, data, del_cb);
1941 * Unset tooltip from item
1943 * @param item toolbar item to remove previously set tooltip.
1945 * Remove tooltip from item. The callback provided as del_cb to
1946 * elm_toolbar_item_tooltip_content_cb_set() will be called to notify
1947 * it is not used anymore.
1949 * @see elm_toolbar_item_tooltip_content_cb_set()
1954 elm_toolbar_item_tooltip_unset(Elm_Toolbar_Item *item)
1956 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1957 elm_widget_item_tooltip_unset(item);
1961 * Sets a different style for this item tooltip.
1963 * @note before you set a style you should define a tooltip with
1964 * elm_toolbar_item_tooltip_content_cb_set() or
1965 * elm_toolbar_item_tooltip_text_set()
1967 * @param item toolbar item with tooltip already set.
1968 * @param style the theme style to use (default, transparent, ...)
1973 elm_toolbar_item_tooltip_style_set(Elm_Toolbar_Item *item, const char *style)
1975 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1976 elm_widget_item_tooltip_style_set(item, style);
1980 * Get the style for this item tooltip.
1982 * @param item toolbar item with tooltip already set.
1983 * @return style the theme style in use, defaults to "default". If the
1984 * object does not have a tooltip set, then NULL is returned.
1989 elm_toolbar_item_tooltip_style_get(const Elm_Toolbar_Item *item)
1991 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1992 return elm_widget_item_tooltip_style_get(item);
1996 * Set the cursor to be shown when mouse is over the toolbar item
1998 * @param item Target item
1999 * @param cursor the cursor name to be used.
2001 * @see elm_object_cursor_set()
2005 elm_toolbar_item_cursor_set(Elm_Toolbar_Item *item, const char *cursor)
2007 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2008 elm_widget_item_cursor_set(item, cursor);
2012 * Get the cursor to be shown when mouse is over the toolbar item
2014 * @param item toolbar item with cursor already set.
2015 * @return the cursor name.
2020 elm_toolbar_item_cursor_get(const Elm_Toolbar_Item *item)
2022 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2023 return elm_widget_item_cursor_get(item);
2027 * Unset the cursor to be shown when mouse is over the toolbar item
2029 * @param item Target item
2031 * @see elm_object_cursor_unset()
2035 elm_toolbar_item_cursor_unset(Elm_Toolbar_Item *item)
2037 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2038 elm_widget_item_cursor_unset(item);
2042 * Sets a different style for this item cursor.
2044 * @note before you set a style you should define a cursor with
2045 * elm_toolbar_item_cursor_set()
2047 * @param item toolbar item with cursor already set.
2048 * @param style the theme style to use (default, transparent, ...)
2053 elm_toolbar_item_cursor_style_set(Elm_Toolbar_Item *item, const char *style)
2055 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2056 elm_widget_item_cursor_style_set(item, style);
2060 * Get the style for this item cursor.
2062 * @param item toolbar item with cursor already set.
2063 * @return style the theme style in use, defaults to "default". If the
2064 * object does not have a cursor set, then NULL is returned.
2069 elm_toolbar_item_cursor_style_get(const Elm_Toolbar_Item *item)
2071 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2072 return elm_widget_item_cursor_style_get(item);
2076 * Set if the cursor set should be searched on the theme or should use
2077 * the provided by the engine, only.
2079 * @note before you set if should look on theme you should define a cursor
2080 * with elm_object_cursor_set(). By default it will only look for cursors
2081 * provided by the engine.
2083 * @param item widget item with cursor already set.
2084 * @param engine_only boolean to define it cursors should be looked only
2085 * between the provided by the engine or searched on widget's theme as well.
2090 elm_toolbar_item_cursor_engine_only_set(Elm_Toolbar_Item *item, Eina_Bool engine_only)
2092 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2093 elm_widget_item_cursor_engine_only_set(item, engine_only);
2097 * Get the cursor engine only usage for this item cursor.
2099 * @param item widget item with cursor already set.
2100 * @return engine_only boolean to define it cursors should be looked only
2101 * between the provided by the engine or searched on widget's theme as well. If
2102 * the object does not have a cursor set, then EINA_FALSE is returned.
2107 elm_toolbar_item_cursor_engine_only_get(const Elm_Toolbar_Item *item)
2109 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
2110 return elm_widget_item_cursor_engine_only_get(item);
2114 * Get whether the toolbar item opens a menu.
2116 * @param item The toolbar item
2117 * @return If true, @p item opens a menu when selected
2122 elm_toolbar_item_menu_get(Elm_Toolbar_Item *item)
2124 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2125 Widget_Data *wd = elm_widget_data_get(item->base.widget);
2126 if (!wd) return NULL;
2127 /* FIXME: It's not ok. This function needs to be reviewed. And should
2128 * receive a const item */
2129 elm_toolbar_item_menu_set(item, 1);
2130 return item->o_menu;
2134 * Returns a pointer to a toolbar item by its label
2136 * @param obj The toolbar object
2137 * @param label The label of the item to find
2139 * @return The pointer to the toolbar item matching @p label
2140 * Returns NULL on failure.
2144 EAPI Elm_Toolbar_Item *
2145 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
2147 Elm_Toolbar_Item *it;
2148 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2149 Widget_Data *wd = elm_widget_data_get(obj);
2151 if (!wd) return NULL;
2152 EINA_INLIST_FOREACH(wd->items, it)
2154 if (!strcmp(it->label, label)) return it;
2161 * Set the data item from the toolbar item
2163 * This set the data value passed on the elm_toolbar_item_append() and
2164 * related item addition calls.
2166 * @param item The item
2167 * @param data The new data pointer to set
2172 elm_toolbar_item_data_set(Elm_Toolbar_Item *item, const void *data)
2174 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
2175 elm_widget_item_data_set(item, data);
2179 * Get the data item from the toolbar item
2181 * This returns the data value passed on the elm_toolbar_item_append() and
2182 * related item addition calls.
2184 * @param item The item
2185 * @return The data pointer provided when created
2190 elm_toolbar_item_data_get(const Elm_Toolbar_Item *item)
2192 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
2193 return elm_widget_item_data_get(item);
2197 * Set no select mode.
2199 * This will turn off the ability to select items entirely and they will
2200 * neither appear selected nor emit selected signals. The clicked
2201 * callback function will still be called.
2203 * @param obj The Toolbar object
2204 * @param no_select The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2209 elm_toolbar_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select)
2211 ELM_CHECK_WIDTYPE(obj, widtype);
2212 Widget_Data *wd = elm_widget_data_get(obj);
2214 wd->no_select = no_select;
2218 * Gets no select mode.
2220 * @param obj The Toolbar object
2221 * @return The no select mode (EINA_TRUE = on, EINA_FALSE = off)
2226 elm_toolbar_no_select_mode_get(const Evas_Object *obj)
2228 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2229 Widget_Data *wd = elm_widget_data_get(obj);
2230 if (!wd) return EINA_FALSE;
2231 return wd->no_select;
2235 * Sets icon lookup order, for icons used in this toolbar.
2236 * Icons added before calling this function will not be affected.
2237 * The default lookup order is ELM_ICON_LOOKUP_THEME_FDO.
2239 * @param obj The toolbar object
2240 * @param order The icon lookup order
2245 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
2247 ELM_CHECK_WIDTYPE(obj, widtype);
2248 Elm_Toolbar_Item *it;
2249 Widget_Data *wd = elm_widget_data_get(obj);
2252 wd->lookup_order = order;
2253 EINA_INLIST_FOREACH(wd->items, it)
2254 elm_icon_order_lookup_set(it->icon, order);
2256 elm_icon_order_lookup_set(wd->more_item->icon, order);
2260 * Gets the icon lookup order.
2262 * @param obj The Toolbar object
2263 * @return The icon lookup order
2267 EAPI Elm_Icon_Lookup_Order
2268 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
2270 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
2271 Widget_Data *wd = elm_widget_data_get(obj);
2272 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
2273 return wd->lookup_order;