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;
19 unsigned int item_count;
21 Eina_Bool homogeneous : 1;
22 Eina_Bool no_select : 1;
23 Eina_Bool always_select : 1;
24 Eina_Bool vertical : 1;
25 Eina_Bool long_press : 1;
26 Ecore_Timer *long_timer;
27 Ecore_Job *resize_job;
30 struct _Elm_Toolbar_Item
41 Eina_Bool visible : 1;
43 Eina_Bool selected : 1;
44 Eina_Bool separator : 1;
47 Eina_List *current_state;
50 #define ELM_TOOLBAR_ITEM_FROM_INLIST(item) \
51 ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Toolbar_Item) : NULL)
53 struct _Elm_Toolbar_Item_State
62 static const char *widtype = NULL;
63 static void _item_show(Elm_Toolbar_Item *it);
64 static void _item_select(Elm_Toolbar_Item *it);
65 static void _item_unselect(Elm_Toolbar_Item *it);
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, ""},
91 _item_disable_hook(Elm_Object_Item *it)
94 Elm_Toolbar_Item *toolbar_it = (Elm_Toolbar_Item *) it;
96 wd = elm_widget_data_get(WIDGET(toolbar_it));
99 if (elm_widget_item_disabled_get(toolbar_it))
101 edje_object_signal_emit(VIEW(toolbar_it), "elm,state,disabled", "elm");
102 elm_widget_signal_emit(toolbar_it->icon, "elm,state,disabled", "elm");
106 edje_object_signal_emit(VIEW(toolbar_it), "elm,state,enabled", "elm");
107 elm_widget_signal_emit(toolbar_it->icon, "elm,state,enabled", "elm");
109 _resize(WIDGET(toolbar_it), NULL, NULL, NULL);
113 _item_icon_set(Evas_Object *icon_obj, const char *type, const char *icon)
117 if ((!type) || (!*type)) goto end;
118 if ((!icon) || (!*icon)) return EINA_FALSE;
119 if ((snprintf(icon_str, sizeof(icon_str), "%s%s", type, icon) > 0)
120 && (elm_icon_standard_set(icon_obj, icon_str)))
123 if (elm_icon_standard_set(icon_obj, icon))
125 WRN("couldn't find icon definition for '%s'", icon);
130 _elm_toolbar_icon_size_get(Widget_Data *wd)
132 const char *icon_size = edje_object_data_get(
133 elm_smart_scroller_edje_object_get(wd->scr), "icon_size");
135 return atoi(icon_size);
136 return _elm_config->icon_size;
140 _item_show(Elm_Toolbar_Item *it)
142 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
143 Evas_Coord x, y, w, h, bx, by;
146 evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
147 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
148 elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
152 _item_unselect(Elm_Toolbar_Item *item)
155 if ((!item) || (!item->selected)) return;
156 wd = elm_widget_data_get(WIDGET(item));
158 item->selected = EINA_FALSE;
159 wd->selected_item = NULL;
160 edje_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
161 elm_widget_signal_emit(item->icon, "elm,state,unselected", "elm");
165 _item_select(Elm_Toolbar_Item *it)
167 Elm_Toolbar_Item *it2;
168 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
173 if (elm_widget_item_disabled_get(it) || (it->separator)) return;
180 if (wd->always_select) return;
185 it2 = (Elm_Toolbar_Item *)
186 elm_toolbar_selected_item_get(WIDGET(it));
189 it->selected = EINA_TRUE;
190 wd->selected_item = it;
191 edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
192 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
197 if (it->menu && (!sel))
199 evas_object_show(it->o_menu);
200 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
201 _menu_move_resize, it);
202 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOVE,
203 _menu_move_resize, it);
205 _menu_move_resize(it, NULL, NULL, NULL);
207 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
208 evas_object_smart_callback_call(obj2, SIG_CLICKED, it);
212 _menu_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
214 Elm_Toolbar_Item *selected;
215 Elm_Toolbar_Item *it = data;
216 selected = (Elm_Toolbar_Item *) elm_toolbar_selected_item_get(WIDGET(it));
217 _item_unselect(selected);
221 _menu_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
223 // avoid hide being emitted during object deletion
224 evas_object_event_callback_del_full
225 (obj, EVAS_CALLBACK_HIDE, _menu_hide, data);
229 _menu_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
231 Elm_Toolbar_Item *it = data;
233 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
235 if ((!wd) || (!wd->menu_parent)) return;
236 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
237 elm_menu_move(it->o_menu, x, y+h);
241 _item_del(Elm_Toolbar_Item *it)
243 Elm_Toolbar_Item_State *it_state;
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);
262 _del_pre_hook(Evas_Object *obj)
264 Widget_Data *wd = elm_widget_data_get(obj);
265 Elm_Toolbar_Item *it, *next;
268 it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
271 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
273 elm_widget_item_free(it);
278 _item_del(wd->more_item);
279 elm_widget_item_free(wd->more_item);
283 ecore_timer_del(wd->long_timer);
284 wd->long_timer = NULL;
289 _del_hook(Evas_Object *obj)
291 Widget_Data *wd = elm_widget_data_get(obj);
299 _mirrored_set_item(Evas_Object *obj __UNUSED__, Elm_Toolbar_Item *it, Eina_Bool mirrored)
301 edje_object_mirrored_set(VIEW(it), mirrored);
302 elm_widget_mirrored_set(it->o_menu, mirrored);
306 _theme_hook_item(Evas_Object *obj, Elm_Toolbar_Item *it, double scale, int icon_size)
308 Evas_Object *view = VIEW(it);
310 const char *style = elm_widget_style_get(obj);
312 _mirrored_set_item(obj, it, elm_widget_mirrored_get(obj));
313 edje_object_scale_set(view, scale);
316 _elm_theme_object_set(obj, view, "toolbar", "item", style);
319 edje_object_signal_emit(view, "elm,state,selected", "elm");
320 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
322 if (elm_widget_item_disabled_get(it))
324 edje_object_signal_emit(view, "elm,state,disabled", "elm");
325 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
331 ms = ((double)icon_size * scale);
332 evas_object_size_hint_min_set(it->icon, ms, ms);
333 evas_object_size_hint_max_set(it->icon, ms, ms);
334 edje_object_part_swallow(view, "elm.swallow.icon", it->icon);
336 edje_object_part_text_set(view, "elm.text", it->label);
339 _elm_theme_object_set(obj, view, "toolbar", "separator", style);
343 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
344 edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
346 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
347 evas_object_size_hint_min_set(view, mw, mh);
351 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
353 Widget_Data *wd = elm_widget_data_get(obj);
354 Elm_Toolbar_Item *it;
356 EINA_INLIST_FOREACH(wd->items, it)
357 _mirrored_set_item(obj, it, mirrored);
359 _mirrored_set_item(obj, wd->more_item, mirrored);
363 _theme_hook(Evas_Object *obj)
365 Widget_Data *wd = elm_widget_data_get(obj);
366 Elm_Toolbar_Item *it;
370 _elm_widget_mirrored_reload(obj);
371 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
372 _mirrored_set(obj, elm_widget_mirrored_get(obj));
373 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
374 edje_object_scale_set(wd->scr, scale);
375 wd->icon_size = _elm_toolbar_icon_size_get(wd);
376 EINA_INLIST_FOREACH(wd->items, it)
377 _theme_hook_item(obj, it, scale, wd->icon_size);
379 _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
384 _item_text_set_hook(Elm_Object_Item *it,
388 if (part && strcmp(part, "default")) return;
389 _item_label_set(((Elm_Toolbar_Item *) it), label, "elm,state,label_set");
393 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
395 if (part && strcmp(part, "default")) return NULL;
396 return ((Elm_Toolbar_Item *) it)->label;
400 _translate_hook(Evas_Object *obj)
402 evas_object_smart_callback_call(obj, "language,changed", NULL);
406 _sizing_eval(Evas_Object *obj)
408 Widget_Data *wd = elm_widget_data_get(obj);
409 Evas_Coord minw = -1, minh = -1, minw_bx = -1, minh_bx = -1;
410 Evas_Coord vw = 0, vh = 0;
414 evas_object_smart_need_recalculate_set(wd->bx, EINA_TRUE);
415 evas_object_smart_calculate(wd->bx);
416 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
418 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
419 if (w < minw) w = minw;
420 if (h < minh) h = minh;
421 evas_object_resize(wd->scr, w, h);
423 evas_object_size_hint_min_get(wd->bx, &minw_bx, &minh_bx);
424 // if (wd->vertical && (h > minh)) minh = h;
425 // if ((!wd->vertical) && (w > minw)) minw = w;
426 evas_object_resize(wd->bx, minw_bx, minh_bx);
427 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
428 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_NONE)
432 minw = minw_bx + (w - vw);
433 minh = minh_bx + (h - vh);
437 minw = minw_bx + (w - vw);
438 minh = minh_bx + (h - vh);
445 minw = minw_bx + (w - vw);
451 minh = minh_bx + (h - vh);
453 // if (wd->vertical) minh = h - vh;
454 // else minw = w - vw;
455 // minh = minh + (h - vh);
457 evas_object_size_hint_min_set(obj, minw, minh);
458 evas_object_size_hint_max_set(obj, -1, -1);
462 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
464 item->o_menu = elm_menu_add(VIEW(item));
465 item->menu = EINA_TRUE;
467 elm_menu_parent_set(item->o_menu, wd->menu_parent);
468 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
470 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
475 _item_menu_destroy(Elm_Toolbar_Item *item)
479 evas_object_del(item->o_menu);
482 item->menu = EINA_FALSE;
486 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
488 const Elm_Toolbar_Item *eti1 = i1;
489 const Elm_Toolbar_Item *eti2 = i2;
492 if (!eti1) return -1;
494 return eti2->prio.priority - eti1->prio.priority;
498 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
500 Elm_Toolbar_Item *it;
501 Eina_List *sorted = NULL;
502 Evas_Coord ciw = 0, cih = 0;
504 EINA_INLIST_FOREACH(wd->items, it)
506 sorted = eina_list_sorted_insert(sorted,
507 _toolbar_item_prio_compare_cb, it);
512 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL, &ciw, &cih);
513 if (wd->vertical) *iw += cih;
516 EINA_LIST_FREE(sorted, it)
518 evas_object_geometry_get(VIEW(it), NULL, NULL, &ciw, &cih);
519 if (wd->vertical) *iw += cih;
521 it->prio.visible = (*iw <= vw);
526 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
528 Elm_Toolbar_Item *it = data;
529 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
533 _resize_job(void *data)
535 Evas_Object *obj = (Evas_Object *)data;
536 Widget_Data *wd = elm_widget_data_get(obj);
537 Evas_Coord mw, mh, vw = 0, vh = 0, w = 0, h = 0;
538 Elm_Toolbar_Item *it;
541 wd->resize_job = NULL;
542 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
543 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
544 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
545 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
547 Evas_Coord iw = 0, ih = 0, more_w = 0, more_h = 0;
551 evas_object_resize(wd->bx, w, vh);
552 _fix_items_visibility(wd, &ih, vh);
556 evas_object_resize(wd->bx, vw, h);
557 _fix_items_visibility(wd, &iw, vw);
559 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL,
563 if ((ih - more_h) <= vh) ih -= more_h;
567 if ((iw - more_w) <= vw) iw -= more_w;
570 /* All items are removed from the box object, since removing individual
571 * items won't trigger a resize. Items are be readded below. */
572 evas_object_box_remove_all(wd->bx, EINA_FALSE);
573 if (((wd->vertical) && (ih > vh)) ||
574 ((!wd->vertical) && (iw > vw)))
578 _item_menu_destroy(wd->more_item);
579 _item_menu_create(wd, wd->more_item);
580 menu = elm_toolbar_item_menu_get((Elm_Object_Item *)wd->more_item);
581 EINA_INLIST_FOREACH(wd->items, it)
583 if (!it->prio.visible)
586 elm_menu_item_separator_add(menu, NULL);
589 Elm_Object_Item *menu_it;
590 menu_it = elm_menu_item_add
591 (menu, NULL, it->icon_str, it->label,
592 _elm_toolbar_item_menu_cb, it);
593 elm_object_item_disabled_set
594 (menu_it, elm_widget_item_disabled_get(it));
596 elm_menu_clone(it->o_menu, menu, menu_it);
598 evas_object_hide(VIEW(it));
602 evas_object_box_append(wd->bx, VIEW(it));
603 evas_object_show(VIEW(it));
606 evas_object_box_append(wd->bx, wd->VIEW(more_item));
607 evas_object_show(wd->VIEW(more_item));
611 /* All items are visible, show them all (except for the "More"
612 * button, of course). */
613 EINA_INLIST_FOREACH(wd->items, it)
615 evas_object_show(VIEW(it));
616 evas_object_box_append(wd->bx, VIEW(it));
618 evas_object_hide(wd->VIEW(more_item));
621 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
623 Evas_Coord iw = 0, ih = 0;
627 evas_object_resize(wd->bx, w, vh);
628 _fix_items_visibility(wd, &ih, vh);
632 evas_object_resize(wd->bx, vw, h);
633 _fix_items_visibility(wd, &iw, vw);
635 evas_object_box_remove_all(wd->bx, EINA_FALSE);
636 if (((wd->vertical) && (ih > vh)) ||
637 ((!wd->vertical) && (iw > vw)))
639 EINA_INLIST_FOREACH(wd->items, it)
641 if (!it->prio.visible)
642 evas_object_hide(VIEW(it));
645 evas_object_box_append(wd->bx, VIEW(it));
646 evas_object_show(VIEW(it));
652 /* All items are visible, show them all */
653 EINA_INLIST_FOREACH(wd->items, it)
655 evas_object_show(VIEW(it));
656 evas_object_box_append(wd->bx, VIEW(it));
664 if ((vh >= mh) && (h != vh)) evas_object_resize(wd->bx, w, vh);
668 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
670 EINA_INLIST_FOREACH(wd->items, it)
680 _mirrored_set(obj, elm_widget_mirrored_get(obj));
684 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
687 _resize(data, NULL, NULL, NULL);
691 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
693 Widget_Data *wd = elm_widget_data_get(data);
695 wd->resize_job = ecore_job_add(_resize_job, data);
699 _select_filter(Elm_Toolbar_Item *it, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
702 char buf[sizeof("elm,action,click,") + 1];
704 button = atoi(emission + sizeof("mouse,clicked,") - 1);
705 if (button == 1) return; /* regular left click event */
706 snprintf(buf, sizeof(buf), "elm,action,click,%d", button);
707 edje_object_signal_emit(VIEW(it), buf, "elm");
711 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
713 Elm_Toolbar_Item *it = data;
715 if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
716 (_elm_access_2nd_click_timeout(VIEW(it))))
718 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
719 _elm_access_say(E_("Selected"));
725 _long_press(Elm_Toolbar_Item *it)
727 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
728 wd->long_timer = NULL;
729 wd->long_press = EINA_TRUE;
730 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
731 return ECORE_CALLBACK_CANCEL;
735 _mouse_down(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Down *ev)
737 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
739 if (ev->button != 1) return;
740 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
741 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
742 wd->long_press = EINA_FALSE;
743 if (wd->long_timer) ecore_timer_interval_set(wd->long_timer, _elm_config->longpress_timeout);
744 else wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, (Ecore_Task_Cb)_long_press, it);
748 _mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
750 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
752 if (ev->button != 1) return;
755 ecore_timer_del(wd->long_timer);
756 wd->long_timer = NULL;
761 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
763 Elm_Toolbar_Item *it = data;
764 edje_object_signal_emit(VIEW(it), "elm,state,highlighted", "elm");
765 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
769 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
771 Elm_Toolbar_Item *it = data;
772 edje_object_signal_emit(VIEW(it), "elm,state,unhighlighted", "elm");
773 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
777 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
779 Evas_Object *obj = (Evas_Object *) data;
780 Widget_Data *wd = elm_widget_data_get(obj);
782 _els_box_layout(o, priv, !wd->vertical, wd->homogeneous,
783 elm_widget_mirrored_get(obj));
787 _access_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item)
789 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
790 const char *txt = item->access_info;
791 if (!txt) txt = it->label;
792 if (txt) return strdup(txt);
797 _access_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
799 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
801 return strdup(E_("Separator"));
802 else if (elm_widget_item_disabled_get(it))
803 return strdup(E_("State: Disabled"));
804 else if (it->selected)
805 return strdup(E_("State: Selected"));
807 return strdup(E_("Has menu"));
812 _item_del_pre_hook(Elm_Object_Item *it)
816 Elm_Toolbar_Item *item, *next;
817 item = (Elm_Toolbar_Item *) it;
819 wd = elm_widget_data_get(WIDGET(item));
820 if (!wd) return EINA_FALSE;
823 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
824 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
826 if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
827 if (wd->always_select && item->selected && next) _item_select(next);
834 static Elm_Toolbar_Item *
835 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
837 Widget_Data *wd = elm_widget_data_get(obj);
838 Evas_Object *icon_obj;
840 Elm_Toolbar_Item *it;
842 icon_obj = elm_icon_add(obj);
843 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
844 if (!icon_obj) return NULL;
845 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
848 evas_object_del(icon_obj);
852 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
853 elm_widget_item_disable_hook_set(it, _item_disable_hook);
854 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
855 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
857 it->label = eina_stringshare_add(label);
858 it->prio.visible = 1;
859 it->prio.priority = 0;
861 it->separator = EINA_FALSE;
862 it->base.data = data;
863 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
864 _elm_access_item_register(&it->base, VIEW(it));
865 _elm_access_text_set(_elm_access_item_get(&it->base),
866 ELM_ACCESS_TYPE, E_("Tool Item"));
867 _elm_access_callback_set(_elm_access_item_get(&it->base),
868 ELM_ACCESS_INFO, _access_info_cb, it);
869 _elm_access_callback_set(_elm_access_item_get(&it->base),
870 ELM_ACCESS_STATE, _access_state_cb, it);
872 if (_item_icon_set(icon_obj, "toolbar/", icon))
875 it->icon_str = eina_stringshare_add(icon);
881 evas_object_del(icon_obj);
884 _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
885 elm_widget_style_get(obj));
886 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "elm",
888 edje_object_signal_callback_add(VIEW(it), "mouse,clicked,*", "*",
889 (Edje_Signal_Cb)_select_filter, it);
890 edje_object_signal_callback_add(VIEW(it), "elm,mouse,in", "elm",
892 edje_object_signal_callback_add(VIEW(it), "elm,mouse,out", "elm",
894 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
895 (Evas_Object_Event_Cb)_mouse_down, it);
896 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
897 (Evas_Object_Event_Cb)_mouse_up, it);
898 elm_widget_sub_object_add(obj, VIEW(it));
903 ms = ((double)wd->icon_size * _elm_config->scale);
904 evas_object_size_hint_min_set(it->icon, ms, ms);
905 evas_object_size_hint_max_set(it->icon, ms, ms);
906 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
907 evas_object_show(it->icon);
908 elm_widget_sub_object_add(obj, it->icon);
910 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
912 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
913 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
914 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
917 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, -1.0);
918 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, 0.5);
922 evas_object_size_hint_weight_set(VIEW(it), -1.0, EVAS_HINT_EXPAND);
923 evas_object_size_hint_align_set(VIEW(it), 0.5, EVAS_HINT_FILL);
925 evas_object_size_hint_min_set(VIEW(it), mw, mh);
926 evas_object_size_hint_max_set(VIEW(it), -1, -1);
927 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
929 if ((!wd->items) && wd->always_select) _item_select(it);
935 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
937 Evas_Coord mw = -1, mh = -1;
938 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
939 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
941 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
942 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
943 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
946 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
947 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
951 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
952 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
954 evas_object_size_hint_min_set(VIEW(item), mw, mh);
958 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
960 Elm_Toolbar_Item *item = data;
961 _elm_toolbar_item_label_update(item);
962 edje_object_signal_callback_del(obj, emission, source,
963 _elm_toolbar_item_label_set_cb);
964 edje_object_signal_emit (VIEW(item), "elm,state,label,reset", "elm");
968 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal)
972 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
974 eina_stringshare_replace(&item->label, label);
975 s = edje_object_data_get(VIEW(item), "transition_animation_on");
976 if ((s) && (atoi(s)))
978 edje_object_part_text_set(VIEW(item), "elm.text_new", item->label);
979 edje_object_signal_emit (VIEW(item), signal, "elm");
980 edje_object_signal_callback_add(VIEW(item),
981 "elm,state,label_set,done", "elm",
982 _elm_toolbar_item_label_set_cb, item);
985 _elm_toolbar_item_label_update(item);
986 _resize(WIDGET(item), NULL, NULL, NULL);
990 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
992 Elm_Toolbar_Item_State *it_state;
994 Evas_Coord mw = -1, mh = -1;
995 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
996 Evas_Object *old_icon = edje_object_part_swallow_get(VIEW(item),
998 elm_widget_sub_object_del(VIEW(item), old_icon);
999 evas_object_hide(old_icon);
1000 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1001 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1002 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1003 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1006 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1007 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1011 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1012 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1014 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1016 EINA_LIST_FOREACH(item->states, l, it_state)
1018 if (it_state->icon == old_icon) return;
1020 evas_object_del(old_icon);
1024 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1026 Elm_Toolbar_Item *item = data;
1027 edje_object_part_unswallow(VIEW(item), item->icon);
1028 _elm_toolbar_item_icon_update(item);
1029 edje_object_signal_callback_del(obj, emission, source,
1030 _elm_toolbar_item_icon_set_cb);
1031 edje_object_signal_emit (VIEW(item), "elm,state,icon,reset", "elm");
1035 _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)
1037 Evas_Object *old_icon;
1042 eina_stringshare_replace(&item->icon_str, icon_str);
1045 eina_stringshare_del(item->icon_str);
1046 item->icon_str = NULL;
1048 item->icon = icon_obj;
1051 ms = (icon_size * _elm_config->scale);
1052 evas_object_size_hint_min_set(item->icon, ms, ms);
1053 evas_object_size_hint_max_set(item->icon, ms, ms);
1054 evas_object_show(item->icon);
1055 elm_widget_sub_object_add(obj, item->icon);
1057 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1058 if ((s) && (atoi(s)))
1060 old_icon = edje_object_part_swallow_get(VIEW(item),
1061 "elm.swallow.icon_new");
1064 elm_widget_sub_object_del(VIEW(item), old_icon);
1065 evas_object_hide(old_icon);
1067 edje_object_part_swallow(VIEW(item), "elm.swallow.icon_new",
1069 edje_object_signal_emit (VIEW(item), signal, "elm");
1070 edje_object_signal_callback_add(VIEW(item),
1071 "elm,state,icon_set,done", "elm",
1072 _elm_toolbar_item_icon_set_cb, item);
1075 _elm_toolbar_item_icon_update(item);
1076 _resize(obj, NULL, NULL, NULL);
1080 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1082 Elm_Toolbar_Item *it = event_info;
1083 Elm_Toolbar_Item_State *it_state;
1085 it_state = eina_list_data_get(it->current_state);
1087 it_state->func((void *)it_state->data, obj, event_info);
1090 static Elm_Toolbar_Item_State *
1091 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1093 Elm_Toolbar_Item_State *it_state;
1094 it_state = ELM_NEW(Elm_Toolbar_Item_State);
1095 it_state->label = eina_stringshare_add(label);
1096 it_state->icon_str = eina_stringshare_add(icon_str);
1097 it_state->icon = icon;
1098 it_state->func = func;
1099 it_state->data = data;
1104 elm_toolbar_add(Evas_Object *parent)
1110 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1112 ELM_SET_WIDTYPE(widtype, "toolbar");
1113 elm_widget_type_set(obj, "toolbar");
1114 elm_widget_sub_object_add(parent, obj);
1115 elm_widget_data_set(obj, wd);
1116 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1117 elm_widget_del_hook_set(obj, _del_hook);
1118 elm_widget_theme_hook_set(obj, _theme_hook);
1119 elm_widget_translate_hook_set(obj, _translate_hook);
1120 elm_widget_can_focus_set(obj, EINA_FALSE);
1122 wd->more_item = NULL;
1123 wd->selected_item = NULL;
1124 wd->scr = elm_smart_scroller_add(e);
1125 elm_smart_scroller_widget_set(wd->scr, obj);
1126 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
1127 elm_smart_scroller_bounce_allow_set(wd->scr,
1128 _elm_config->thumbscroll_bounce_enable,
1130 elm_widget_resize_object_set(obj, wd->scr);
1131 elm_smart_scroller_policy_set(wd->scr,
1132 ELM_SMART_SCROLLER_POLICY_AUTO,
1133 ELM_SMART_SCROLLER_POLICY_OFF);
1136 wd->icon_size = _elm_toolbar_icon_size_get(wd);
1139 wd->homogeneous = EINA_TRUE;
1142 wd->bx = evas_object_box_add(e);
1143 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
1144 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
1145 elm_widget_sub_object_add(obj, wd->bx);
1146 elm_smart_scroller_child_set(wd->scr, wd->bx);
1147 evas_object_show(wd->bx);
1149 elm_toolbar_shrink_mode_set(obj, _elm_config->toolbar_shrink_mode);
1150 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
1151 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
1152 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
1154 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1161 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
1163 ELM_CHECK_WIDTYPE(obj, widtype);
1164 Widget_Data *wd = elm_widget_data_get(obj);
1166 if (wd->icon_size == icon_size) return;
1167 wd->icon_size = icon_size;
1172 elm_toolbar_icon_size_get(const Evas_Object *obj)
1174 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1175 Widget_Data *wd = elm_widget_data_get(obj);
1177 return wd->icon_size;
1180 EAPI Elm_Object_Item *
1181 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1183 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1184 Widget_Data *wd = elm_widget_data_get(obj);
1185 if (!wd) return NULL;
1187 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1188 if (!it) return NULL;
1189 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1191 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
1192 evas_object_box_append(wd->bx, VIEW(it));
1193 evas_object_show(VIEW(it));
1195 _theme_hook_item(obj, it, scale, wd->icon_size);
1198 return (Elm_Object_Item *) it;
1201 EAPI Elm_Object_Item *
1202 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1204 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1205 Widget_Data *wd = elm_widget_data_get(obj);
1206 if (!wd) return NULL;
1208 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1209 if (!it) return NULL;
1210 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1212 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1213 evas_object_box_prepend(wd->bx, VIEW(it));
1214 evas_object_show(VIEW(it));
1215 _theme_hook_item(obj, it, scale, wd->icon_size);
1218 return (Elm_Object_Item *) it;
1221 EAPI Elm_Object_Item *
1222 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)
1224 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1225 ELM_OBJ_ITEM_CHECK_OR_RETURN(before, NULL);
1227 Elm_Toolbar_Item *it, *_before;
1229 wd = elm_widget_data_get(obj);
1230 if (!wd) return NULL;
1231 _before = (Elm_Toolbar_Item *) before;
1232 it = _item_new(obj, icon, label, func, data);
1233 if (!it) return NULL;
1234 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1236 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1237 EINA_INLIST_GET(_before));
1238 evas_object_box_insert_before(wd->bx, VIEW(it), VIEW(_before));
1239 evas_object_show(VIEW(it));
1240 _theme_hook_item(obj, it, scale, wd->icon_size);
1243 return (Elm_Object_Item *) it;
1246 EAPI Elm_Object_Item *
1247 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)
1249 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1250 ELM_OBJ_ITEM_CHECK_OR_RETURN(after, NULL);
1252 Elm_Toolbar_Item *it, *_after;
1254 wd = elm_widget_data_get(obj);
1255 if (!wd) return NULL;
1256 _after = (Elm_Toolbar_Item *) after;
1257 it = _item_new(obj, icon, label, func, data);
1258 if (!it) return NULL;
1259 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1261 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1262 EINA_INLIST_GET(_after));
1263 evas_object_box_insert_after(wd->bx, VIEW(it), VIEW(_after));
1264 evas_object_show(VIEW(it));
1265 _theme_hook_item(obj, it, scale, wd->icon_size);
1268 return (Elm_Object_Item *) it;
1271 EAPI Elm_Object_Item *
1272 elm_toolbar_first_item_get(const Evas_Object *obj)
1274 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1275 Widget_Data *wd = elm_widget_data_get(obj);
1276 if (!wd || !wd->items) return NULL;
1277 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1280 EAPI Elm_Object_Item *
1281 elm_toolbar_last_item_get(const Evas_Object *obj)
1283 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1284 Widget_Data *wd = elm_widget_data_get(obj);
1285 if (!wd || !wd->items) return NULL;
1286 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1289 EAPI Elm_Object_Item *
1290 elm_toolbar_item_next_get(const Elm_Object_Item *it)
1292 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1293 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1294 EINA_INLIST_GET(((Elm_Toolbar_Item *) it))->next);
1297 EAPI Elm_Object_Item *
1298 elm_toolbar_item_prev_get(const Elm_Object_Item *it)
1300 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1301 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1302 EINA_INLIST_GET(((Elm_Toolbar_Item *) it))->prev);
1306 elm_toolbar_item_toolbar_get(const Elm_Object_Item *it)
1308 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1309 return elm_object_item_widget_get(it);
1313 elm_toolbar_item_priority_set(Elm_Object_Item *it, int priority)
1315 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1316 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1317 if (item->prio.priority == priority) return;
1318 item->prio.priority = priority;
1319 _resize(WIDGET(item), NULL, NULL, NULL);
1323 elm_toolbar_item_priority_get(const Elm_Object_Item *it)
1325 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
1326 return ((Elm_Toolbar_Item *) it)->prio.priority;
1330 elm_toolbar_item_label_get(const Elm_Object_Item *it)
1332 return _item_text_get_hook(it, NULL);
1336 elm_toolbar_item_label_set(Elm_Object_Item *it, const char *label)
1338 _item_text_set_hook(it, NULL, label);
1342 elm_toolbar_item_data_get(const Elm_Object_Item *it)
1344 return elm_object_item_data_get(it);
1348 elm_toolbar_item_data_set(Elm_Object_Item *it, const void *data)
1350 elm_object_item_data_set(it, (void *) data);
1353 EAPI Elm_Object_Item *
1354 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
1356 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1357 Elm_Toolbar_Item *it;
1358 Widget_Data *wd = elm_widget_data_get(obj);
1359 if (!wd) return NULL;
1361 EINA_INLIST_FOREACH(wd->items, it)
1363 if (!strcmp(it->label, label))
1364 return (Elm_Object_Item *) it;
1370 elm_toolbar_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1372 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1373 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1374 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1377 if (item->selected == selected) return;
1378 if (selected) _item_select(item);
1379 else _item_unselect(item);
1383 elm_toolbar_item_selected_get(const Elm_Object_Item *it)
1385 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1386 return ((Elm_Toolbar_Item *) it)->selected;
1389 EAPI Elm_Object_Item *
1390 elm_toolbar_selected_item_get(const Evas_Object *obj)
1392 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1393 Widget_Data *wd = elm_widget_data_get(obj);
1394 if (!wd) return NULL;
1395 return (Elm_Object_Item *) wd->selected_item;
1399 elm_toolbar_item_icon_set(Elm_Object_Item *it, const char *icon)
1401 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1403 Evas_Object *icon_obj;
1406 Elm_Toolbar_Item * item = (Elm_Toolbar_Item *) it;
1409 wd = elm_widget_data_get(obj);
1411 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1413 icon_obj = elm_icon_add(obj);
1414 if (!icon_obj) return;
1415 if (_item_icon_set(icon_obj, "toolbar/", icon))
1416 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1417 "elm,state,icon_set");
1420 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1421 "elm,state,icon_set");
1422 evas_object_del(icon_obj);
1427 elm_toolbar_item_icon_get(const Elm_Object_Item *it)
1429 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1430 return ((Elm_Toolbar_Item *) it)->icon_str;
1434 elm_toolbar_item_object_get(const Elm_Object_Item *it)
1436 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1440 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1443 wd = elm_widget_data_get(obj);
1444 if (!wd) return NULL;
1450 elm_toolbar_item_icon_object_get(Elm_Object_Item *it)
1452 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1453 return ((Elm_Toolbar_Item *) it)->icon;
1457 elm_toolbar_item_icon_memfile_set(Elm_Object_Item *it, const void *img, size_t size, const char *format, const char *key)
1459 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1461 Evas_Object *icon_obj;
1465 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1468 wd = elm_widget_data_get(obj);
1469 if (!wd) return EINA_FALSE;
1473 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1474 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1475 ret = _els_smart_icon_memfile_set(icon_obj, img, size, format, key);
1478 evas_object_del(icon_obj);
1481 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1482 "elm,state,icon_set");
1485 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1490 elm_toolbar_item_icon_file_set(Elm_Object_Item *it, const char *file, const char *key)
1492 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1494 Evas_Object *icon_obj;
1498 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1501 wd = elm_widget_data_get(obj);
1502 if (!wd) return EINA_FALSE;
1506 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1507 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1508 ret = _els_smart_icon_file_key_set(icon_obj, file, key);
1511 evas_object_del(icon_obj);
1514 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1515 "elm,state,icon_set");
1518 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1523 elm_toolbar_item_del(Elm_Object_Item *it)
1525 elm_object_item_del(it);
1529 elm_toolbar_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1531 elm_object_item_del_cb_set(it, func);
1535 elm_toolbar_item_disabled_get(const Elm_Object_Item *it)
1537 return elm_object_item_disabled_get(it);
1541 elm_toolbar_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1543 elm_object_item_disabled_set(it, disabled);
1547 elm_toolbar_item_separator_set(Elm_Object_Item *it, Eina_Bool separator)
1549 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1550 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1551 Evas_Object *obj = WIDGET(item);
1552 Widget_Data *wd = elm_widget_data_get(obj);
1554 if (item->separator == separator) return;
1555 item->separator = separator;
1556 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1557 _theme_hook_item(obj, item, scale, wd->icon_size);
1561 elm_toolbar_item_separator_get(const Elm_Object_Item *it)
1563 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1564 return ((Elm_Toolbar_Item *) it)->separator;
1568 elm_toolbar_shrink_mode_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1570 ELM_CHECK_WIDTYPE(obj, widtype);
1571 Widget_Data *wd = elm_widget_data_get(obj);
1575 wd->shrink_mode = shrink_mode;
1576 bounce = (_elm_config->thumbscroll_bounce_enable) &&
1577 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1578 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1582 _item_del(wd->more_item);
1583 elm_widget_item_free(wd->more_item);
1584 wd->more_item = NULL;
1587 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1589 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1590 ELM_SMART_SCROLLER_POLICY_OFF);
1591 wd->more_item = _item_new(obj, "more_menu", "More", NULL, NULL);
1593 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1594 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1595 ELM_SMART_SCROLLER_POLICY_OFF);
1597 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1598 ELM_SMART_SCROLLER_POLICY_OFF);
1602 EAPI Elm_Toolbar_Shrink_Mode
1603 elm_toolbar_shrink_mode_get(const Evas_Object *obj)
1605 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1606 Widget_Data *wd = elm_widget_data_get(obj);
1608 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1609 return wd->shrink_mode;
1613 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
1615 ELM_CHECK_WIDTYPE(obj, widtype);
1616 Widget_Data *wd = elm_widget_data_get(obj);
1619 wd->homogeneous = !!homogeneous;
1620 evas_object_smart_calculate(wd->bx);
1624 elm_toolbar_homogeneous_get(const Evas_Object *obj)
1626 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1627 Widget_Data *wd = elm_widget_data_get(obj);
1629 if (!wd) return EINA_FALSE;
1630 return wd->homogeneous;
1634 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1636 Elm_Toolbar_Item *it;
1637 ELM_CHECK_WIDTYPE(obj, widtype);
1638 Widget_Data *wd = elm_widget_data_get(obj);
1641 EINA_SAFETY_ON_NULL_RETURN(parent);
1642 wd->menu_parent = parent;
1643 EINA_INLIST_FOREACH(wd->items, it)
1646 elm_menu_parent_set(it->o_menu, wd->menu_parent);
1648 if ((wd->more_item) && (wd->more_item->o_menu))
1649 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1653 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1655 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1656 Widget_Data *wd = elm_widget_data_get(obj);
1658 if (!wd) return NULL;
1659 return wd->menu_parent;
1663 elm_toolbar_align_set(Evas_Object *obj, double align)
1665 ELM_CHECK_WIDTYPE(obj, widtype);
1666 Widget_Data *wd = elm_widget_data_get(obj);
1671 if (wd->align != align)
1672 evas_object_size_hint_align_set(wd->bx, 0.5, align);
1676 if (wd->align != align)
1677 evas_object_size_hint_align_set(wd->bx, align, 0.5);
1683 elm_toolbar_align_get(const Evas_Object *obj)
1685 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1686 Widget_Data *wd = elm_widget_data_get(obj);
1688 if (!wd) return 0.0;
1693 elm_toolbar_item_menu_set(Elm_Object_Item *it, Eina_Bool menu)
1695 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1696 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1697 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1700 if (item->menu == menu) return;
1701 if (menu) _item_menu_create(wd, item);
1702 else _item_menu_destroy(item);
1706 elm_toolbar_item_menu_get(const Elm_Object_Item *it)
1708 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1709 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1710 if (!item->menu) return NULL;
1711 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1712 if (!wd) return NULL;
1713 return item->o_menu;
1716 EAPI Elm_Toolbar_Item_State *
1717 elm_toolbar_item_state_add(Elm_Object_Item *it, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1719 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1721 Elm_Toolbar_Item_State *it_state;
1722 Evas_Object *icon_obj;
1725 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1727 wd = elm_widget_data_get(WIDGET(item));
1728 if (!wd) return NULL;
1732 it_state = _item_state_new(item->label, item->icon_str, item->icon,
1733 item->func, item->base.data);
1734 item->states = eina_list_append(item->states, it_state);
1735 item->current_state = item->states;
1738 icon_obj = elm_icon_add(obj);
1739 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1740 if (!icon_obj) goto error_state_add;
1742 if (!_item_icon_set(icon_obj, "toolbar/", icon))
1744 evas_object_del(icon_obj);
1749 it_state = _item_state_new(label, icon, icon_obj, func, data);
1750 item->states = eina_list_append(item->states, it_state);
1751 item->func = _elm_toolbar_item_state_cb;
1752 item->base.data = NULL;
1757 if (item->states && !eina_list_next(item->states))
1759 eina_stringshare_del(item->label);
1760 eina_stringshare_del(item->icon_str);
1761 free(eina_list_data_get(item->states));
1762 eina_list_free(item->states);
1763 item->states = NULL;
1769 elm_toolbar_item_state_del(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1771 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1773 Eina_List *del_state;
1774 Elm_Toolbar_Item_State *it_state;
1775 Elm_Toolbar_Item *item;
1777 if (!state) return EINA_FALSE;
1779 item = (Elm_Toolbar_Item *) it;
1780 if (!item->states) return EINA_FALSE;
1782 del_state = eina_list_data_find_list(item->states, state);
1783 if (del_state == item->states) return EINA_FALSE;
1784 if (del_state == item->current_state)
1785 elm_toolbar_item_state_unset(it);
1787 eina_stringshare_del(state->label);
1788 eina_stringshare_del(state->icon_str);
1789 if (state->icon) evas_object_del(state->icon);
1791 item->states = eina_list_remove_list(item->states, del_state);
1792 if (item->states && !eina_list_next(item->states))
1794 it_state = eina_list_data_get(item->states);
1795 item->base.data = it_state->data;
1796 item->func = it_state->func;
1797 eina_stringshare_del(it_state->label);
1798 eina_stringshare_del(it_state->icon_str);
1799 free(eina_list_data_get(item->states));
1800 eina_list_free(item->states);
1801 item->states = NULL;
1807 elm_toolbar_item_state_set(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1809 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1812 Eina_List *next_state;
1813 Elm_Toolbar_Item_State *it_state;
1815 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1818 wd = elm_widget_data_get(obj);
1819 if (!wd) return EINA_FALSE;
1820 if (!item->states) return EINA_FALSE;
1824 next_state = eina_list_data_find_list(item->states, state);
1825 if (!next_state) return EINA_FALSE;
1828 next_state = item->states;
1830 if (next_state == item->current_state) return EINA_TRUE;
1832 it_state = eina_list_data_get(next_state);
1833 if (eina_list_data_find(item->current_state, state))
1835 _item_label_set(item, it_state->label, "elm,state,label_set,forward");
1836 _elm_toolbar_item_icon_obj_set(obj, item, it_state->icon, it_state->icon_str,
1837 wd->icon_size, "elm,state,icon_set,forward");
1841 _item_label_set(item, it_state->label, "elm,state,label_set,backward");
1842 _elm_toolbar_item_icon_obj_set(obj,
1847 "elm,state,icon_set,backward");
1849 if (elm_widget_item_disabled_get(item))
1850 elm_widget_signal_emit(item->icon, "elm,state,disabled", "elm");
1852 elm_widget_signal_emit(item->icon, "elm,state,enabled", "elm");
1854 item->current_state = next_state;
1859 elm_toolbar_item_state_unset(Elm_Object_Item *it)
1861 elm_toolbar_item_state_set(it, NULL);
1864 EAPI Elm_Toolbar_Item_State *
1865 elm_toolbar_item_state_get(const Elm_Object_Item *it)
1867 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1868 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1870 if ((!item->states) || (!item->current_state)) return NULL;
1871 if (item->current_state == item->states) return NULL;
1873 return eina_list_data_get(item->current_state);
1876 EAPI Elm_Toolbar_Item_State *
1877 elm_toolbar_item_state_next(Elm_Object_Item *it)
1879 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1883 Eina_List *next_state;
1884 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1887 wd = elm_widget_data_get(obj);
1888 if (!wd) return NULL;
1889 if (!item->states) return NULL;
1891 next_state = eina_list_next(item->current_state);
1893 next_state = eina_list_next(item->states);
1894 return eina_list_data_get(next_state);
1897 EAPI Elm_Toolbar_Item_State *
1898 elm_toolbar_item_state_prev(Elm_Object_Item *it)
1900 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1904 Eina_List *prev_state;
1905 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1908 wd = elm_widget_data_get(obj);
1909 if (!wd) return NULL;
1910 if (!item->states) return NULL;
1912 prev_state = eina_list_prev(item->current_state);
1913 if ((!prev_state) || (prev_state == item->states))
1914 prev_state = eina_list_last(item->states);
1915 return eina_list_data_get(prev_state);
1919 elm_toolbar_item_tooltip_text_set(Elm_Object_Item *it, const char *text)
1921 elm_object_item_tooltip_text_set(it, text);
1925 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)
1927 elm_object_item_tooltip_content_cb_set(it, func, data, del_cb);
1931 elm_toolbar_item_tooltip_unset(Elm_Object_Item *it)
1933 elm_object_item_tooltip_unset(it);
1937 elm_toolbar_item_tooltip_style_set(Elm_Object_Item *it, const char *style)
1939 elm_object_item_tooltip_style_set(it, style);
1943 elm_toolbar_item_tooltip_style_get(const Elm_Object_Item *it)
1945 return elm_object_item_tooltip_style_get(it);
1949 elm_toolbar_item_cursor_set(Elm_Object_Item *it, const char *cursor)
1951 elm_object_item_cursor_set(it, cursor);
1955 elm_toolbar_item_cursor_get(const Elm_Object_Item *it)
1957 return elm_object_item_cursor_get(it);
1961 elm_toolbar_item_cursor_unset(Elm_Object_Item *it)
1963 elm_object_item_cursor_unset(it);
1967 elm_toolbar_item_cursor_style_set(Elm_Object_Item *it, const char *style)
1969 elm_object_item_cursor_style_set(it, style);
1973 elm_toolbar_item_cursor_style_get(const Elm_Object_Item *it)
1975 return elm_object_item_cursor_style_get(it);
1979 elm_toolbar_item_cursor_engine_only_set(Elm_Object_Item *it, Eina_Bool engine_only)
1981 elm_object_item_cursor_engine_only_set(it, engine_only);
1985 elm_toolbar_item_cursor_engine_only_get(const Elm_Object_Item *it)
1987 return elm_object_item_cursor_engine_only_get(it);
1991 elm_toolbar_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
1993 ELM_CHECK_WIDTYPE(obj, widtype);
1994 Widget_Data *wd = elm_widget_data_get(obj);
1996 if (always_select && (!wd->always_select) && wd->items)
1997 _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
1998 wd->always_select = always_select;
2002 elm_toolbar_always_select_mode_get(const Evas_Object *obj)
2004 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2005 Widget_Data *wd = elm_widget_data_get(obj);
2006 if (!wd) return EINA_FALSE;
2007 return wd->always_select;
2011 elm_toolbar_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select)
2013 ELM_CHECK_WIDTYPE(obj, widtype);
2014 Widget_Data *wd = elm_widget_data_get(obj);
2016 wd->no_select = no_select;
2020 elm_toolbar_no_select_mode_get(const Evas_Object *obj)
2022 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2023 Widget_Data *wd = elm_widget_data_get(obj);
2024 if (!wd) return EINA_FALSE;
2025 return wd->no_select;
2029 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
2031 ELM_CHECK_WIDTYPE(obj, widtype);
2032 Elm_Toolbar_Item *it;
2033 Widget_Data *wd = elm_widget_data_get(obj);
2036 wd->lookup_order = order;
2037 EINA_INLIST_FOREACH(wd->items, it)
2038 elm_icon_order_lookup_set(it->icon, order);
2040 elm_icon_order_lookup_set(wd->more_item->icon, order);
2043 EAPI Elm_Icon_Lookup_Order
2044 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
2046 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
2047 Widget_Data *wd = elm_widget_data_get(obj);
2048 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
2049 return wd->lookup_order;
2052 EINA_DEPRECATED EAPI void
2053 elm_toolbar_orientation_set(Evas_Object *obj, Eina_Bool vertical)
2055 elm_toolbar_horizontal_set(obj, !vertical);
2058 EINA_DEPRECATED EAPI Eina_Bool
2059 elm_toolbar_orientation_get(const Evas_Object *obj)
2061 return !elm_toolbar_horizontal_get(obj);
2065 elm_toolbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
2067 ELM_CHECK_WIDTYPE(obj, widtype);
2068 Widget_Data *wd = elm_widget_data_get(obj);
2070 wd->vertical = !horizontal;
2072 evas_object_size_hint_align_set(wd->bx, 0.5, wd->align);
2074 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
2079 elm_toolbar_horizontal_get(const Evas_Object *obj)
2081 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2082 Widget_Data *wd = elm_widget_data_get(obj);
2083 if (!wd) return EINA_FALSE;
2084 return !wd->vertical;
2088 elm_toolbar_items_count(const Evas_Object *obj)
2090 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2091 Widget_Data *wd = elm_widget_data_get(obj);
2093 return wd->item_count;
2096 EINA_DEPRECATED EAPI void
2097 elm_toolbar_mode_shrink_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
2099 elm_toolbar_shrink_mode_set(obj, shrink_mode);
2102 EINA_DEPRECATED EAPI Elm_Toolbar_Shrink_Mode
2103 elm_toolbar_mode_shrink_get(const Evas_Object *obj)
2105 return elm_toolbar_shrink_mode_get(obj);