1 #include <Elementary.h>
3 #include "els_scroller.h"
7 typedef struct _Widget_Data Widget_Data;
8 typedef struct _Elm_Toolbar_Item Elm_Toolbar_Item;
12 Evas_Object *scr, *bx;
13 Evas_Object *menu_parent;
15 Elm_Toolbar_Item *more_item, *selected_item;
16 Elm_Toolbar_Shrink_Mode shrink_mode;
17 Elm_Icon_Lookup_Order lookup_order;
20 Eina_Bool homogeneous : 1;
21 Eina_Bool no_select : 1;
22 Eina_Bool always_select : 1;
23 Eina_Bool vertical : 1;
24 Eina_Bool long_press : 1;
25 Ecore_Timer *long_timer;
26 Ecore_Job *resize_job;
29 struct _Elm_Toolbar_Item
40 Eina_Bool visible : 1;
42 Eina_Bool selected : 1;
43 Eina_Bool separator : 1;
46 Eina_List *current_state;
49 #define ELM_TOOLBAR_ITEM_FROM_INLIST(item) \
50 ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Toolbar_Item) : NULL)
52 struct _Elm_Toolbar_Item_State
61 static const char *widtype = NULL;
62 static void _item_show(Elm_Toolbar_Item *it);
63 static void _item_select(Elm_Toolbar_Item *it);
64 static void _item_unselect(Elm_Toolbar_Item *it);
65 static void _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);
79 static const char SIG_CLICKED[] = "clicked";
80 static const char SIG_LONGPRESSED[] = "longpressed";
81 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
83 static const Evas_Smart_Cb_Description _signals[] = {
85 {SIG_LONGPRESSED, ""},
86 {SIG_CLICKED_DOUBLE, ""},
92 _item_icon_set(Evas_Object *icon_obj, const char *type, const char *icon)
96 if ((!type) || (!*type)) goto end;
97 if ((!icon) || (!*icon)) return EINA_FALSE;
98 if ((snprintf(icon_str, sizeof(icon_str), "%s%s", type, icon) > 0)
99 && (elm_icon_standard_set(icon_obj, icon_str)))
102 if (elm_icon_standard_set(icon_obj, icon))
104 WRN("couldn't find icon definition for '%s'", icon);
109 _elm_toolbar_icon_size_get(Widget_Data *wd)
111 const char *icon_size = edje_object_data_get(
112 elm_smart_scroller_edje_object_get(wd->scr), "icon_size");
114 return atoi(icon_size);
115 return _elm_config->icon_size;
119 _item_show(Elm_Toolbar_Item *it)
121 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
122 Evas_Coord x, y, w, h, bx, by;
125 evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
126 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
127 elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
131 _item_unselect(Elm_Toolbar_Item *item)
134 if ((!item) || (!item->selected)) return;
135 wd = elm_widget_data_get(WIDGET(item));
137 item->selected = EINA_FALSE;
138 wd->selected_item = NULL;
139 edje_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
140 elm_widget_signal_emit(item->icon, "elm,state,unselected", "elm");
144 _item_select(Elm_Toolbar_Item *it)
146 Elm_Toolbar_Item *it2;
147 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
152 if (elm_widget_item_disabled_get(it) || (it->separator)) return;
159 if (wd->always_select) return;
164 it2 = (Elm_Toolbar_Item *)
165 elm_toolbar_selected_item_get(WIDGET(it));
168 it->selected = EINA_TRUE;
169 wd->selected_item = it;
170 edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
171 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
176 if (it->menu && (!sel))
178 evas_object_show(it->o_menu);
179 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
180 _menu_move_resize, it);
181 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOVE,
182 _menu_move_resize, it);
184 _menu_move_resize(it, NULL, NULL, NULL);
186 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
187 evas_object_smart_callback_call(obj2, SIG_CLICKED, it);
191 _menu_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
193 Elm_Toolbar_Item *selected;
194 Elm_Toolbar_Item *it = data;
195 selected = (Elm_Toolbar_Item *) elm_toolbar_selected_item_get(WIDGET(it));
196 _item_unselect(selected);
200 _menu_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
202 // avoid hide being emitted during object deletion
203 evas_object_event_callback_del_full
204 (obj, EVAS_CALLBACK_HIDE, _menu_hide, data);
208 _menu_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
210 Elm_Toolbar_Item *it = data;
212 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
214 if ((!wd) || (!wd->menu_parent)) return;
215 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
216 elm_menu_move(it->o_menu, x, y+h);
220 _item_disable(Elm_Toolbar_Item *it, Eina_Bool disabled)
222 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
225 if (elm_widget_item_disabled_get(it) == disabled) return;
226 elm_object_item_disabled_set((Elm_Object_Item *) it, disabled);
229 edje_object_signal_emit(VIEW(it), "elm,state,disabled", "elm");
230 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
234 edje_object_signal_emit(VIEW(it), "elm,state,enabled", "elm");
235 elm_widget_signal_emit(it->icon, "elm,state,enabled", "elm");
240 _item_del(Elm_Toolbar_Item *it)
242 Elm_Toolbar_Item_State *it_state;
244 elm_widget_item_pre_notify_del(it);
245 EINA_LIST_FREE(it->states, it_state)
247 if (it->icon == it_state->icon)
249 eina_stringshare_del(it_state->label);
250 eina_stringshare_del(it_state->icon_str);
251 if (it_state->icon) evas_object_del(it_state->icon);
254 eina_stringshare_del(it->label);
255 eina_stringshare_del(it->icon_str);
256 if (it->icon) evas_object_del(it->icon);
257 //TODO: See if checking for wd->menu_parent is necessary before deleting menu
258 if (it->o_menu) evas_object_del(it->o_menu);
259 elm_widget_item_del(it);
263 _del_pre_hook(Evas_Object *obj)
265 Widget_Data *wd = elm_widget_data_get(obj);
266 Elm_Toolbar_Item *it, *next;
269 it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
272 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
277 _item_del(wd->more_item);
280 ecore_timer_del(wd->long_timer);
281 wd->long_timer = NULL;
286 _del_hook(Evas_Object *obj)
288 Widget_Data *wd = elm_widget_data_get(obj);
296 _mirrored_set_item(Evas_Object *obj __UNUSED__, Elm_Toolbar_Item *it, Eina_Bool mirrored)
298 edje_object_mirrored_set(VIEW(it), mirrored);
299 elm_widget_mirrored_set(it->o_menu, mirrored);
303 _theme_hook_item(Evas_Object *obj, Elm_Toolbar_Item *it, double scale, int icon_size)
305 Evas_Object *view = VIEW(it);
307 const char *style = elm_widget_style_get(obj);
309 _mirrored_set_item(obj, it, elm_widget_mirrored_get(obj));
310 edje_object_scale_set(view, scale);
313 _elm_theme_object_set(obj, view, "toolbar", "item", style);
316 edje_object_signal_emit(view, "elm,state,selected", "elm");
317 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
319 if (elm_widget_item_disabled_get(it))
321 edje_object_signal_emit(view, "elm,state,disabled", "elm");
322 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
328 ms = ((double)icon_size * scale);
329 evas_object_size_hint_min_set(it->icon, ms, ms);
330 evas_object_size_hint_max_set(it->icon, ms, ms);
331 edje_object_part_swallow(view, "elm.swallow.icon",
334 edje_object_part_text_set(view, "elm.text", it->label);
337 _elm_theme_object_set(obj, view, "toolbar", "separator", style);
341 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
342 edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
344 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
345 evas_object_size_hint_min_set(view, mw, mh);
349 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
351 Widget_Data *wd = elm_widget_data_get(obj);
352 Elm_Toolbar_Item *it;
354 EINA_INLIST_FOREACH(wd->items, it)
355 _mirrored_set_item(obj, it, mirrored);
357 _mirrored_set_item(obj, wd->more_item, mirrored);
361 _theme_hook(Evas_Object *obj)
363 Widget_Data *wd = elm_widget_data_get(obj);
364 Elm_Toolbar_Item *it;
368 _elm_widget_mirrored_reload(obj);
369 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
370 _mirrored_set(obj, elm_widget_mirrored_get(obj));
371 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
372 edje_object_scale_set(wd->scr, scale);
373 wd->icon_size = _elm_toolbar_icon_size_get(wd);
374 EINA_INLIST_FOREACH(wd->items, it)
375 _theme_hook_item(obj, it, scale, wd->icon_size);
377 _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
382 _translate_hook(Evas_Object *obj)
384 evas_object_smart_callback_call(obj, "language,changed", NULL);
388 _sizing_eval(Evas_Object *obj)
390 Widget_Data *wd = elm_widget_data_get(obj);
391 Evas_Coord minw = -1, minh = -1, minw_bx, minh_bx;
392 Evas_Coord vw = 0, vh = 0;
396 evas_object_smart_calculate(wd->bx);
397 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
399 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
400 if (w < minw) w = minw;
401 if (h < minh) h = minh;
402 evas_object_resize(wd->scr, w, h);
404 evas_object_size_hint_min_get(wd->bx, &minw, &minh);
407 if (wd->vertical && (h > minh)) minh = h;
408 if ((!wd->vertical) && (w > minw)) minw = w;
409 evas_object_resize(wd->bx, minw, minh);
410 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
411 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_NONE)
413 if (wd->vertical) minh = minh_bx + (h - vh);
414 else minw = minw_bx + (w - vw);
418 if (wd->vertical) minh = h - vh;
421 minh = minh + (h - vh);
422 evas_object_size_hint_min_set(obj, minw, minh);
423 evas_object_size_hint_max_set(obj, -1, -1);
427 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
429 item->o_menu = elm_menu_add(VIEW(item));
430 item->menu = EINA_TRUE;
432 elm_menu_parent_set(item->o_menu, wd->menu_parent);
433 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
435 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
440 _item_menu_destroy(Elm_Toolbar_Item *item)
444 evas_object_del(item->o_menu);
447 item->menu = EINA_FALSE;
451 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
453 const Elm_Toolbar_Item *eti1 = i1;
454 const Elm_Toolbar_Item *eti2 = i2;
457 if (!eti1) return -1;
459 return eti2->prio.priority - eti1->prio.priority;
463 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
465 Elm_Toolbar_Item *it;
466 Eina_List *sorted = NULL;
469 EINA_INLIST_FOREACH(wd->items, it)
471 sorted = eina_list_sorted_insert(sorted,
472 _toolbar_item_prio_compare_cb, it);
477 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL, &ciw, NULL);
480 EINA_LIST_FREE(sorted, it)
482 evas_object_geometry_get(VIEW(it), NULL, NULL, &ciw, NULL);
484 it->prio.visible = (*iw <= vw);
489 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
491 Elm_Toolbar_Item *it = data;
492 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
496 _resize_job(void *data)
498 Widget_Data *wd = elm_widget_data_get(data);
499 Evas_Coord mw, mh, vw, vh, w, h;
500 Elm_Toolbar_Item *it;
501 Evas_Object *obj = (Evas_Object *) data;
504 wd->resize_job = NULL;
505 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
506 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
507 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
508 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
510 Evas_Coord iw = 0, more_w;
512 evas_object_resize(wd->bx, vw, h);
513 _fix_items_visibility(wd, &iw, vw);
514 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL, &more_w, NULL);
515 if (iw - more_w <= vw)
518 /* All items are removed from the box object, since removing individual
519 * items won't trigger a resize. Items are be readded below. */
520 evas_object_box_remove_all(wd->bx, EINA_FALSE);
525 _item_menu_destroy(wd->more_item);
526 _item_menu_create(wd, wd->more_item);
528 elm_toolbar_item_menu_get((Elm_Object_Item *) wd->more_item);
530 EINA_INLIST_FOREACH(wd->items, it)
532 if (!it->prio.visible)
535 elm_menu_item_separator_add(menu, NULL);
538 Elm_Object_Item *menu_it;
539 menu_it = elm_menu_item_add(menu, NULL,
540 it->icon_str, it->label,
541 _elm_toolbar_item_menu_cb, it);
542 elm_object_item_disabled_set(menu_it,
543 elm_widget_item_disabled_get(it));
545 elm_menu_clone(it->o_menu, menu, menu_it);
547 evas_object_hide(VIEW(it));
551 evas_object_box_append(wd->bx, VIEW(it));
552 evas_object_show(VIEW(it));
556 evas_object_box_append(wd->bx, wd->VIEW(more_item));
557 evas_object_show(wd->VIEW(more_item));
561 /* All items are visible, show them all (except for the "More"
562 * button, of course). */
563 EINA_INLIST_FOREACH(wd->items, it)
565 evas_object_show(VIEW(it));
566 evas_object_box_append(wd->bx, VIEW(it));
568 evas_object_hide(wd->VIEW(more_item));
571 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
575 evas_object_resize(wd->bx, vw, h);
576 _fix_items_visibility(wd, &iw, vw);
577 evas_object_box_remove_all(wd->bx, EINA_FALSE);
580 EINA_INLIST_FOREACH(wd->items, it)
582 if (!it->prio.visible)
583 evas_object_hide(VIEW(it));
586 evas_object_box_append(wd->bx, VIEW(it));
587 evas_object_show(VIEW(it));
593 /* All items are visible, show them all */
594 EINA_INLIST_FOREACH(wd->items, it)
596 evas_object_show(VIEW(it));
597 evas_object_box_append(wd->bx, VIEW(it));
603 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
604 EINA_INLIST_FOREACH(wd->items, it)
614 _mirrored_set(obj, elm_widget_mirrored_get(obj));
618 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
621 _resize(data, NULL, NULL, NULL);
625 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
627 Widget_Data *wd = elm_widget_data_get(data);
629 wd->resize_job = ecore_job_add(_resize_job, data);
633 _select_filter(Elm_Toolbar_Item *it, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
636 char buf[sizeof("elm,action,click,") + 1];
638 button = atoi(emission + sizeof("mouse,clicked,") - 1);
639 if (button == 1) return; /* regular left click event */
640 snprintf(buf, sizeof(buf), "elm,action,click,%d", button);
641 edje_object_signal_emit(VIEW(it), buf, "elm");
645 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
647 Elm_Toolbar_Item *it = data;
649 if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
650 (_elm_access_2nd_click_timeout(VIEW(it))))
652 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
653 _elm_access_say(E_("Selected"));
659 _long_press(Elm_Toolbar_Item *it)
661 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
662 wd->long_timer = NULL;
663 wd->long_press = EINA_TRUE;
664 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
665 return ECORE_CALLBACK_CANCEL;
669 _mouse_down(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Down *ev)
671 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
673 if (ev->button != 1) return;
674 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
675 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
676 wd->long_press = EINA_FALSE;
677 if (wd->long_timer) ecore_timer_interval_set(wd->long_timer, _elm_config->longpress_timeout);
678 else wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, (Ecore_Task_Cb)_long_press, it);
682 _mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
684 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
686 if (ev->button != 1) return;
689 ecore_timer_del(wd->long_timer);
690 wd->long_timer = NULL;
695 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
697 Elm_Toolbar_Item *it = data;
698 edje_object_signal_emit(VIEW(it), "elm,state,highlighted", "elm");
699 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
703 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
705 Elm_Toolbar_Item *it = data;
706 edje_object_signal_emit(VIEW(it), "elm,state,unhighlighted", "elm");
707 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
711 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
713 Evas_Object *obj = (Evas_Object *) data;
714 Widget_Data *wd = elm_widget_data_get(obj);
716 _els_box_layout(o, priv, !wd->vertical, wd->homogeneous, elm_widget_mirrored_get(obj));
720 _access_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item)
722 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
723 const char *txt = item->access_info;
724 if (!txt) txt = it->label;
725 if (txt) return strdup(txt);
730 _access_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
732 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
734 return strdup(E_("Separator"));
735 else if (elm_widget_item_disabled_get(it))
736 return strdup(E_("State: Disabled"));
737 else if (it->selected)
738 return strdup(E_("State: Selected"));
740 return strdup(E_("Has menu"));
744 static Elm_Toolbar_Item *
745 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
747 Widget_Data *wd = elm_widget_data_get(obj);
748 Evas_Object *icon_obj;
750 Elm_Toolbar_Item *it;
752 icon_obj = elm_icon_add(obj);
753 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
754 if (!icon_obj) return NULL;
755 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
758 evas_object_del(icon_obj);
761 it->label = eina_stringshare_add(label);
762 it->prio.visible = 1;
763 it->prio.priority = 0;
765 it->separator = EINA_FALSE;
766 it->base.data = data;
767 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
768 _elm_access_item_register(&it->base, VIEW(it));
769 _elm_access_text_set(_elm_access_item_get(&it->base),
770 ELM_ACCESS_TYPE, E_("Tool Item"));
771 _elm_access_callback_set(_elm_access_item_get(&it->base),
772 ELM_ACCESS_INFO, _access_info_cb, it);
773 _elm_access_callback_set(_elm_access_item_get(&it->base),
774 ELM_ACCESS_STATE, _access_state_cb, it);
776 if (_item_icon_set(icon_obj, "toolbar/", icon))
779 it->icon_str = eina_stringshare_add(icon);
785 evas_object_del(icon_obj);
788 _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
789 elm_widget_style_get(obj));
790 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "elm",
792 edje_object_signal_callback_add(VIEW(it), "mouse,clicked,*", "*",
793 (Edje_Signal_Cb)_select_filter, it);
794 edje_object_signal_callback_add(VIEW(it), "elm,mouse,in", "elm",
796 edje_object_signal_callback_add(VIEW(it), "elm,mouse,out", "elm",
798 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
799 (Evas_Object_Event_Cb)_mouse_down, it);
800 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
801 (Evas_Object_Event_Cb)_mouse_up, it);
802 elm_widget_sub_object_add(obj, VIEW(it));
807 ms = ((double)wd->icon_size * _elm_config->scale);
808 evas_object_size_hint_min_set(it->icon, ms, ms);
809 evas_object_size_hint_max_set(it->icon, ms, ms);
810 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
811 evas_object_show(it->icon);
812 elm_widget_sub_object_add(obj, it->icon);
814 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
816 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
817 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
818 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
821 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, -1.0);
822 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, 0.5);
826 evas_object_size_hint_weight_set(VIEW(it), -1.0, EVAS_HINT_EXPAND);
827 evas_object_size_hint_align_set(VIEW(it), 0.5, EVAS_HINT_FILL);
829 evas_object_size_hint_min_set(VIEW(it), mw, mh);
830 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
832 if ((!wd->items) && wd->always_select) _item_select(it);
837 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
839 Evas_Coord mw = -1, mh = -1;
840 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
841 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
843 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
844 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
845 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
848 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
849 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
853 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
854 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
856 evas_object_size_hint_min_set(VIEW(item), mw, mh);
860 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
862 Elm_Toolbar_Item *item = data;
863 _elm_toolbar_item_label_update(item);
864 edje_object_signal_callback_del(obj, emission, source,
865 _elm_toolbar_item_label_set_cb);
866 edje_object_signal_emit (VIEW(item), "elm,state,label,reset", "elm");
870 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal)
874 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
876 eina_stringshare_replace(&item->label, label);
877 s = edje_object_data_get(VIEW(item), "transition_animation_on");
878 if ((s) && (atoi(s)))
880 edje_object_part_text_set(VIEW(item), "elm.text_new", item->label);
881 edje_object_signal_emit (VIEW(item), signal, "elm");
882 edje_object_signal_callback_add(VIEW(item),
883 "elm,state,label_set,done", "elm",
884 _elm_toolbar_item_label_set_cb, item);
887 _elm_toolbar_item_label_update(item);
888 _resize(WIDGET(item), NULL, NULL, NULL);
892 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
894 Elm_Toolbar_Item_State *it_state;
896 Evas_Coord mw = -1, mh = -1;
897 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
898 Evas_Object *old_icon = edje_object_part_swallow_get(VIEW(item),
900 elm_widget_sub_object_del(VIEW(item), old_icon);
901 evas_object_hide(old_icon);
902 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
903 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
904 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
905 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
908 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
909 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
913 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
914 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
916 evas_object_size_hint_min_set(VIEW(item), mw, mh);
918 EINA_LIST_FOREACH(item->states, l, it_state)
919 if (it_state->icon == old_icon)
921 evas_object_del(old_icon);
925 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
927 Elm_Toolbar_Item *item = data;
928 edje_object_part_unswallow(VIEW(item), item->icon);
929 _elm_toolbar_item_icon_update(item);
930 edje_object_signal_callback_del(obj, emission, source,
931 _elm_toolbar_item_icon_set_cb);
932 edje_object_signal_emit (VIEW(item), "elm,state,icon,reset", "elm");
936 _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)
938 Evas_Object *old_icon;
943 eina_stringshare_replace(&item->icon_str, icon_str);
946 eina_stringshare_del(item->icon_str);
947 item->icon_str = NULL;
949 item->icon = icon_obj;
952 ms = (icon_size * _elm_config->scale);
953 evas_object_size_hint_min_set(item->icon, ms, ms);
954 evas_object_size_hint_max_set(item->icon, ms, ms);
955 evas_object_show(item->icon);
956 elm_widget_sub_object_add(obj, item->icon);
958 s = edje_object_data_get(VIEW(item), "transition_animation_on");
959 if ((s) && (atoi(s)))
961 old_icon = edje_object_part_swallow_get(VIEW(item),
962 "elm.swallow.icon_new");
965 elm_widget_sub_object_del(VIEW(item), old_icon);
966 evas_object_hide(old_icon);
968 edje_object_part_swallow(VIEW(item), "elm.swallow.icon_new",
970 edje_object_signal_emit (VIEW(item), signal, "elm");
971 edje_object_signal_callback_add(VIEW(item),
972 "elm,state,icon_set,done", "elm",
973 _elm_toolbar_item_icon_set_cb, item);
976 _elm_toolbar_item_icon_update(item);
977 _resize(obj, NULL, NULL, NULL);
981 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
983 Elm_Toolbar_Item *it = event_info;
984 Elm_Toolbar_Item_State *it_state;
986 it_state = eina_list_data_get(it->current_state);
988 it_state->func((void *)it_state->data, obj, event_info);
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 elm_toolbar_add(Evas_Object *parent)
1011 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1013 ELM_SET_WIDTYPE(widtype, "toolbar");
1014 elm_widget_type_set(obj, "toolbar");
1015 elm_widget_sub_object_add(parent, obj);
1016 elm_widget_data_set(obj, wd);
1017 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1018 elm_widget_del_hook_set(obj, _del_hook);
1019 elm_widget_theme_hook_set(obj, _theme_hook);
1020 elm_widget_translate_hook_set(obj, _translate_hook);
1021 elm_widget_can_focus_set(obj, EINA_FALSE);
1023 wd->more_item = NULL;
1024 wd->selected_item = NULL;
1025 wd->scr = elm_smart_scroller_add(e);
1026 elm_smart_scroller_widget_set(wd->scr, obj);
1027 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
1028 elm_smart_scroller_bounce_allow_set(wd->scr,
1029 _elm_config->thumbscroll_bounce_enable,
1031 elm_widget_resize_object_set(obj, wd->scr);
1032 elm_smart_scroller_policy_set(wd->scr,
1033 ELM_SMART_SCROLLER_POLICY_AUTO,
1034 ELM_SMART_SCROLLER_POLICY_OFF);
1037 wd->icon_size = _elm_toolbar_icon_size_get(wd);
1040 wd->homogeneous = EINA_TRUE;
1043 wd->bx = evas_object_box_add(e);
1044 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
1045 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
1046 elm_widget_sub_object_add(obj, wd->bx);
1047 elm_smart_scroller_child_set(wd->scr, wd->bx);
1048 evas_object_show(wd->bx);
1050 elm_toolbar_mode_shrink_set(obj, _elm_config->toolbar_shrink_mode);
1051 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
1052 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
1053 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
1055 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1062 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
1064 ELM_CHECK_WIDTYPE(obj, widtype);
1065 Widget_Data *wd = elm_widget_data_get(obj);
1067 if (wd->icon_size == icon_size) return;
1068 wd->icon_size = icon_size;
1073 elm_toolbar_icon_size_get(const Evas_Object *obj)
1075 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1076 Widget_Data *wd = elm_widget_data_get(obj);
1078 return wd->icon_size;
1081 EAPI Elm_Object_Item *
1082 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1084 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1085 Widget_Data *wd = elm_widget_data_get(obj);
1086 if (!wd) return NULL;
1088 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1089 if (!it) return NULL;
1090 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1092 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
1093 evas_object_box_append(wd->bx, VIEW(it));
1094 evas_object_show(VIEW(it));
1096 _theme_hook_item(obj, it, scale, wd->icon_size);
1099 return (Elm_Object_Item *) it;
1102 EAPI Elm_Object_Item *
1103 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1105 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1106 Widget_Data *wd = elm_widget_data_get(obj);
1107 if (!wd) return NULL;
1109 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1110 if (!it) return NULL;
1111 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1113 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1114 evas_object_box_prepend(wd->bx, VIEW(it));
1115 evas_object_show(VIEW(it));
1116 _theme_hook_item(obj, it, scale, wd->icon_size);
1119 return (Elm_Object_Item *) it;
1122 EAPI Elm_Object_Item *
1123 elm_toolbar_item_insert_before(Evas_Object *obj, Elm_Object_Item *before, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1125 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1126 ELM_OBJ_ITEM_CHECK_OR_RETURN(before, NULL);
1128 Elm_Toolbar_Item *it, *_before;
1130 wd = elm_widget_data_get(obj);
1131 if (!wd) return NULL;
1132 _before = (Elm_Toolbar_Item *) before;
1133 it = _item_new(obj, icon, label, func, data);
1134 if (!it) return NULL;
1135 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1137 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1138 EINA_INLIST_GET(_before));
1139 evas_object_box_insert_before(wd->bx, VIEW(it), VIEW(_before));
1140 evas_object_show(VIEW(it));
1141 _theme_hook_item(obj, it, scale, wd->icon_size);
1144 return (Elm_Object_Item *) it;
1147 EAPI Elm_Object_Item *
1148 elm_toolbar_item_insert_after(Evas_Object *obj, Elm_Object_Item *after, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1150 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1151 ELM_OBJ_ITEM_CHECK_OR_RETURN(after, NULL);
1153 Elm_Toolbar_Item *it, *_after;
1155 wd = elm_widget_data_get(obj);
1156 if (!wd) return NULL;
1157 _after = (Elm_Toolbar_Item *) after;
1158 it = _item_new(obj, icon, label, func, data);
1159 if (!it) return NULL;
1160 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1162 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1163 EINA_INLIST_GET(_after));
1164 evas_object_box_insert_after(wd->bx, VIEW(it), VIEW(_after));
1165 evas_object_show(VIEW(it));
1166 _theme_hook_item(obj, it, scale, wd->icon_size);
1169 return (Elm_Object_Item *) it;
1172 EAPI Elm_Object_Item *
1173 elm_toolbar_first_item_get(const Evas_Object *obj)
1175 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1176 Widget_Data *wd = elm_widget_data_get(obj);
1177 if (!wd || !wd->items) return NULL;
1178 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1181 EAPI Elm_Object_Item *
1182 elm_toolbar_last_item_get(const Evas_Object *obj)
1184 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1185 Widget_Data *wd = elm_widget_data_get(obj);
1186 if (!wd || !wd->items) return NULL;
1187 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1190 EAPI Elm_Object_Item *
1191 elm_toolbar_item_next_get(const Elm_Object_Item *it)
1193 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1194 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1195 EINA_INLIST_GET(((Elm_Toolbar_Item *) it))->next);
1198 EAPI Elm_Object_Item *
1199 elm_toolbar_item_prev_get(const Elm_Object_Item *it)
1201 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1202 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1203 EINA_INLIST_GET(((Elm_Toolbar_Item *) it))->prev);
1207 elm_toolbar_item_toolbar_get(const Elm_Object_Item *it)
1209 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1210 return elm_object_item_object_get(it);
1214 elm_toolbar_item_priority_set(Elm_Object_Item *it, int priority)
1216 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1217 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1218 if (item->prio.priority == priority) return;
1219 item->prio.priority = priority;
1220 _resize(WIDGET(item), NULL, NULL, NULL);
1224 elm_toolbar_item_priority_get(const Elm_Object_Item *it)
1226 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
1227 return ((Elm_Toolbar_Item *) it)->prio.priority;
1231 elm_toolbar_item_label_get(const Elm_Object_Item *it)
1233 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1234 return ((Elm_Toolbar_Item *) it)->label;
1238 elm_toolbar_item_label_set(Elm_Object_Item *it, const char *label)
1240 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1241 _item_label_set(((Elm_Toolbar_Item *) it), label, "elm,state,label_set");
1245 elm_toolbar_item_data_get(const Elm_Object_Item *it)
1247 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1248 return elm_object_item_data_get(it);
1252 elm_toolbar_item_data_set(Elm_Object_Item *it, const void *data)
1254 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1255 elm_object_item_data_set(it, (void *) data);
1258 EAPI Elm_Object_Item *
1259 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
1261 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1262 Elm_Toolbar_Item *it;
1263 Widget_Data *wd = elm_widget_data_get(obj);
1264 if (!wd) return NULL;
1266 EINA_INLIST_FOREACH(wd->items, it)
1268 if (!strcmp(it->label, label))
1269 return (Elm_Object_Item *) it;
1275 elm_toolbar_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1277 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1278 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1279 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1282 if (item->selected == selected) return;
1283 if (selected) _item_select(item);
1284 else _item_unselect(item);
1288 elm_toolbar_item_selected_get(const Elm_Object_Item *it)
1290 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1291 return ((Elm_Toolbar_Item *) it)->selected;
1294 EAPI Elm_Object_Item *
1295 elm_toolbar_selected_item_get(const Evas_Object *obj)
1297 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1298 Widget_Data *wd = elm_widget_data_get(obj);
1299 if (!wd) return NULL;
1300 return (Elm_Object_Item *) wd->selected_item;
1304 elm_toolbar_item_icon_set(Elm_Object_Item *it, const char *icon)
1306 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1308 Evas_Object *icon_obj;
1311 Elm_Toolbar_Item * item = (Elm_Toolbar_Item *) it;
1314 wd = elm_widget_data_get(obj);
1316 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1318 icon_obj = elm_icon_add(obj);
1319 if (!icon_obj) return;
1320 if (_item_icon_set(icon_obj, "toolbar/", icon))
1321 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1322 "elm,state,icon_set");
1325 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1326 "elm,state,icon_set");
1327 evas_object_del(icon_obj);
1332 elm_toolbar_item_icon_get(const Elm_Object_Item *it)
1334 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1335 return ((Elm_Toolbar_Item *) it)->icon_str;
1339 elm_toolbar_item_object_get(const Elm_Object_Item *it)
1341 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1345 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1348 wd = elm_widget_data_get(obj);
1349 if (!wd) return NULL;
1355 elm_toolbar_item_icon_object_get(Elm_Object_Item *it)
1357 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1358 return ((Elm_Toolbar_Item *) it)->icon;
1362 elm_toolbar_item_icon_memfile_set(Elm_Object_Item *it, const void *img, size_t size, const char *format, const char *key)
1364 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1366 Evas_Object *icon_obj;
1370 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1373 wd = elm_widget_data_get(obj);
1374 if (!wd) return EINA_FALSE;
1378 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1379 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1380 ret = _els_smart_icon_memfile_set(icon_obj, img, size, format, key);
1383 evas_object_del(icon_obj);
1386 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1387 "elm,state,icon_set");
1390 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1395 elm_toolbar_item_icon_file_set(Elm_Object_Item *it, const char *file, const char *key)
1397 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1399 Evas_Object *icon_obj;
1403 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1406 wd = elm_widget_data_get(obj);
1407 if (!wd) return EINA_FALSE;
1411 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1412 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1413 ret = _els_smart_icon_file_key_set(icon_obj, file, key);
1416 evas_object_del(icon_obj);
1419 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1420 "elm,state,icon_set");
1423 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1428 elm_toolbar_item_del(Elm_Object_Item *it)
1430 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1434 Elm_Toolbar_Item *item, *next;
1435 item = (Elm_Toolbar_Item *) it;
1437 wd = elm_widget_data_get(WIDGET(item));
1439 obj2 = WIDGET(item);
1440 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
1441 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
1442 if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1443 if (wd->always_select && item->selected && next) _item_select(next);
1449 elm_toolbar_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1451 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1452 elm_toolbar_item_del_cb_set(it, func);
1456 elm_toolbar_item_disabled_get(const Elm_Object_Item *it)
1458 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1459 return ((Elm_Widget_Item *) it)->disabled;
1463 elm_toolbar_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1465 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1466 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1467 _item_disable(item, disabled);
1468 _resize(WIDGET(item), NULL, NULL, NULL);
1472 elm_toolbar_item_separator_set(Elm_Object_Item *it, Eina_Bool separator)
1474 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1475 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1476 Evas_Object *obj = WIDGET(item);
1477 Widget_Data *wd = elm_widget_data_get(obj);
1479 if (item->separator == separator) return;
1480 item->separator = separator;
1481 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1482 _theme_hook_item(obj, item, scale, wd->icon_size);
1486 elm_toolbar_item_separator_get(const Elm_Object_Item *it)
1488 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1489 return ((Elm_Toolbar_Item *) it)->separator;
1493 elm_toolbar_mode_shrink_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1495 ELM_CHECK_WIDTYPE(obj, widtype);
1496 Widget_Data *wd = elm_widget_data_get(obj);
1500 wd->shrink_mode = shrink_mode;
1501 bounce = (_elm_config->thumbscroll_bounce_enable) &&
1502 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1503 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1507 _item_del(wd->more_item);
1508 wd->more_item = NULL;
1511 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1513 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF, ELM_SMART_SCROLLER_POLICY_OFF);
1515 wd->more_item = _item_new(obj, "more_menu", "More",
1518 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1519 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1520 ELM_SMART_SCROLLER_POLICY_OFF);
1522 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1523 ELM_SMART_SCROLLER_POLICY_OFF);
1527 EAPI Elm_Toolbar_Shrink_Mode
1528 elm_toolbar_mode_shrink_get(const Evas_Object *obj)
1530 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1531 Widget_Data *wd = elm_widget_data_get(obj);
1533 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1534 return wd->shrink_mode;
1538 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
1540 ELM_CHECK_WIDTYPE(obj, widtype);
1541 Widget_Data *wd = elm_widget_data_get(obj);
1544 wd->homogeneous = !!homogeneous;
1545 evas_object_smart_calculate(wd->bx);
1549 elm_toolbar_homogeneous_get(const Evas_Object *obj)
1551 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1552 Widget_Data *wd = elm_widget_data_get(obj);
1554 if (!wd) return EINA_FALSE;
1555 return wd->homogeneous;
1559 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1561 Elm_Toolbar_Item *it;
1562 ELM_CHECK_WIDTYPE(obj, widtype);
1563 Widget_Data *wd = elm_widget_data_get(obj);
1566 EINA_SAFETY_ON_NULL_RETURN(parent);
1567 wd->menu_parent = parent;
1568 EINA_INLIST_FOREACH(wd->items, it)
1571 elm_menu_parent_set(it->o_menu, wd->menu_parent);
1573 if ((wd->more_item) && (wd->more_item->o_menu))
1574 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1578 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1580 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1581 Widget_Data *wd = elm_widget_data_get(obj);
1583 if (!wd) return NULL;
1584 return wd->menu_parent;
1588 elm_toolbar_align_set(Evas_Object *obj, double align)
1590 ELM_CHECK_WIDTYPE(obj, widtype);
1591 Widget_Data *wd = elm_widget_data_get(obj);
1594 if (wd->align != align)
1595 evas_object_size_hint_align_set(wd->bx, align, 0.5);
1600 elm_toolbar_align_get(const Evas_Object *obj)
1602 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1603 Widget_Data *wd = elm_widget_data_get(obj);
1605 if (!wd) return 0.0;
1610 elm_toolbar_item_menu_set(Elm_Object_Item *it, Eina_Bool menu)
1612 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1613 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1614 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1617 if (item->menu == menu) return;
1618 if (menu) _item_menu_create(wd, item);
1619 else _item_menu_destroy(item);
1623 elm_toolbar_item_menu_get(const Elm_Object_Item *it)
1625 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1626 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1627 if (!item->menu) return NULL;
1628 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1629 if (!wd) return NULL;
1630 return item->o_menu;
1633 EAPI Elm_Toolbar_Item_State *
1634 elm_toolbar_item_state_add(Elm_Object_Item *it, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1636 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1638 Elm_Toolbar_Item_State *it_state;
1639 Evas_Object *icon_obj;
1642 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1644 wd = elm_widget_data_get(WIDGET(item));
1645 if (!wd) return NULL;
1649 it_state = _item_state_new(item->label, item->icon_str, item->icon,
1650 item->func, item->base.data);
1651 item->states = eina_list_append(item->states, it_state);
1652 item->current_state = item->states;
1655 icon_obj = elm_icon_add(obj);
1656 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1657 if (!icon_obj) goto error_state_add;
1659 if (!_item_icon_set(icon_obj, "toolbar/", icon))
1661 evas_object_del(icon_obj);
1666 it_state = _item_state_new(label, icon, icon_obj, func, data);
1667 item->states = eina_list_append(item->states, it_state);
1668 item->func = _elm_toolbar_item_state_cb;
1669 item->base.data = NULL;
1674 if (item->states && !eina_list_next(item->states))
1676 eina_stringshare_del(item->label);
1677 eina_stringshare_del(item->icon_str);
1678 free(eina_list_data_get(item->states));
1679 eina_list_free(item->states);
1680 item->states = NULL;
1686 elm_toolbar_item_state_del(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1688 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1690 Eina_List *del_state;
1691 Elm_Toolbar_Item_State *it_state;
1692 Elm_Toolbar_Item *item;
1694 if (!state) return EINA_FALSE;
1696 item = (Elm_Toolbar_Item *) it;
1697 if (!item->states) return EINA_FALSE;
1699 del_state = eina_list_data_find_list(item->states, state);
1700 if (del_state == item->states) return EINA_FALSE;
1701 if (del_state == item->current_state)
1702 elm_toolbar_item_state_unset(it);
1704 eina_stringshare_del(state->label);
1705 eina_stringshare_del(state->icon_str);
1706 if (state->icon) evas_object_del(state->icon);
1708 item->states = eina_list_remove_list(item->states, del_state);
1709 if (item->states && !eina_list_next(item->states))
1711 it_state = eina_list_data_get(item->states);
1712 item->base.data = it_state->data;
1713 item->func = it_state->func;
1714 eina_stringshare_del(it_state->label);
1715 eina_stringshare_del(it_state->icon_str);
1716 free(eina_list_data_get(item->states));
1717 eina_list_free(item->states);
1718 item->states = NULL;
1724 elm_toolbar_item_state_set(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1726 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1729 Eina_List *next_state;
1730 Elm_Toolbar_Item_State *it_state;
1732 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1735 wd = elm_widget_data_get(obj);
1736 if (!wd) return EINA_FALSE;
1737 if (!item->states) return EINA_FALSE;
1741 next_state = eina_list_data_find_list(item->states, state);
1742 if (!next_state) return EINA_FALSE;
1745 next_state = item->states;
1747 if (next_state == item->current_state) return EINA_TRUE;
1749 it_state = eina_list_data_get(next_state);
1750 if (eina_list_data_find(item->current_state, state))
1752 _item_label_set(item, it_state->label, "elm,state,label_set,forward");
1753 _elm_toolbar_item_icon_obj_set(obj, item, it_state->icon, it_state->icon_str,
1754 wd->icon_size, "elm,state,icon_set,forward");
1758 _item_label_set(item, it_state->label, "elm,state,label_set,backward");
1759 _elm_toolbar_item_icon_obj_set(obj,
1764 "elm,state,icon_set,backward");
1766 if (elm_widget_item_disabled_get(item))
1767 elm_widget_signal_emit(item->icon, "elm,state,disabled", "elm");
1769 elm_widget_signal_emit(item->icon, "elm,state,enabled", "elm");
1771 item->current_state = next_state;
1776 elm_toolbar_item_state_unset(Elm_Object_Item *it)
1778 elm_toolbar_item_state_set(it, NULL);
1781 EAPI Elm_Toolbar_Item_State *
1782 elm_toolbar_item_state_get(const Elm_Object_Item *it)
1784 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1785 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1787 if ((!item->states) || (!item->current_state)) return NULL;
1788 if (item->current_state == item->states) return NULL;
1790 return eina_list_data_get(item->current_state);
1793 EAPI Elm_Toolbar_Item_State *
1794 elm_toolbar_item_state_next(Elm_Object_Item *it)
1796 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1800 Eina_List *next_state;
1801 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1804 wd = elm_widget_data_get(obj);
1805 if (!wd) return NULL;
1806 if (!item->states) return NULL;
1808 next_state = eina_list_next(item->current_state);
1810 next_state = eina_list_next(item->states);
1811 return eina_list_data_get(next_state);
1814 EAPI Elm_Toolbar_Item_State *
1815 elm_toolbar_item_state_prev(Elm_Object_Item *it)
1817 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1821 Eina_List *prev_state;
1822 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1825 wd = elm_widget_data_get(obj);
1826 if (!wd) return NULL;
1827 if (!item->states) return NULL;
1829 prev_state = eina_list_prev(item->current_state);
1830 if ((!prev_state) || (prev_state == item->states))
1831 prev_state = eina_list_last(item->states);
1832 return eina_list_data_get(prev_state);
1836 elm_toolbar_item_tooltip_text_set(Elm_Object_Item *it, const char *text)
1838 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1839 elm_widget_item_tooltip_text_set(it, text);
1843 elm_toolbar_item_tooltip_content_cb_set(Elm_Object_Item *it, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
1845 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1846 elm_widget_item_tooltip_content_cb_set(it, func, data, del_cb);
1850 elm_toolbar_item_tooltip_unset(Elm_Object_Item *it)
1852 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1853 elm_widget_item_tooltip_unset(it);
1857 elm_toolbar_item_tooltip_style_set(Elm_Object_Item *it, const char *style)
1859 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1860 elm_widget_item_tooltip_style_set(it, style);
1864 elm_toolbar_item_tooltip_style_get(const Elm_Object_Item *it)
1866 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1867 return elm_widget_item_tooltip_style_get(it);
1871 elm_toolbar_item_cursor_set(Elm_Object_Item *it, const char *cursor)
1873 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1874 elm_widget_item_cursor_set(it, cursor);
1878 elm_toolbar_item_cursor_get(const Elm_Object_Item *it)
1880 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1881 return elm_widget_item_cursor_get(it);
1885 elm_toolbar_item_cursor_unset(Elm_Object_Item *it)
1887 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1888 elm_widget_item_cursor_unset(it);
1892 elm_toolbar_item_cursor_style_set(Elm_Object_Item *it, const char *style)
1894 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1895 elm_widget_item_cursor_style_set(it, style);
1899 elm_toolbar_item_cursor_style_get(const Elm_Object_Item *it)
1901 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1902 return elm_widget_item_cursor_style_get(it);
1906 elm_toolbar_item_cursor_engine_only_set(Elm_Object_Item *it, Eina_Bool engine_only)
1908 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1909 elm_widget_item_cursor_engine_only_set(it, engine_only);
1913 elm_toolbar_item_cursor_engine_only_get(const Elm_Object_Item *it)
1915 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1916 return elm_widget_item_cursor_engine_only_get(it);
1920 elm_toolbar_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
1922 ELM_CHECK_WIDTYPE(obj, widtype);
1923 Widget_Data *wd = elm_widget_data_get(obj);
1925 if (always_select && (!wd->always_select) && wd->items)
1926 _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
1927 wd->always_select = always_select;
1931 elm_toolbar_always_select_mode_get(const Evas_Object *obj)
1933 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1934 Widget_Data *wd = elm_widget_data_get(obj);
1935 if (!wd) return EINA_FALSE;
1936 return wd->always_select;
1940 elm_toolbar_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select)
1942 ELM_CHECK_WIDTYPE(obj, widtype);
1943 Widget_Data *wd = elm_widget_data_get(obj);
1945 wd->no_select = no_select;
1949 elm_toolbar_no_select_mode_get(const Evas_Object *obj)
1951 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1952 Widget_Data *wd = elm_widget_data_get(obj);
1953 if (!wd) return EINA_FALSE;
1954 return wd->no_select;
1958 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
1960 ELM_CHECK_WIDTYPE(obj, widtype);
1961 Elm_Toolbar_Item *it;
1962 Widget_Data *wd = elm_widget_data_get(obj);
1965 wd->lookup_order = order;
1966 EINA_INLIST_FOREACH(wd->items, it)
1967 elm_icon_order_lookup_set(it->icon, order);
1969 elm_icon_order_lookup_set(wd->more_item->icon, order);
1972 EAPI Elm_Icon_Lookup_Order
1973 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
1975 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
1976 Widget_Data *wd = elm_widget_data_get(obj);
1977 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
1978 return wd->lookup_order;
1981 EINA_DEPRECATED EAPI void
1982 elm_toolbar_orientation_set(Evas_Object *obj, Eina_Bool vertical)
1984 elm_toolbar_horizontal_set(obj, !vertical);
1987 EINA_DEPRECATED EAPI Eina_Bool
1988 elm_toolbar_orientation_get(const Evas_Object *obj)
1990 return !elm_toolbar_horizontal_get(obj);
1994 elm_toolbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
1996 ELM_CHECK_WIDTYPE(obj, widtype);
1997 Widget_Data *wd = elm_widget_data_get(obj);
1999 wd->vertical = !horizontal;
2004 elm_toolbar_horizontal_get(const Evas_Object *obj)
2006 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2007 Widget_Data *wd = elm_widget_data_get(obj);
2008 if (!wd) return EINA_FALSE;
2009 return !wd->vertical;