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 Elm_Object_Select_Mode select_mode;
22 Eina_Bool homogeneous : 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
42 Eina_Bool visible : 1;
44 Eina_Bool selected : 1;
45 Eina_Bool separator : 1;
48 Eina_List *current_state;
51 #define ELM_TOOLBAR_ITEM_FROM_INLIST(item) \
52 ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Toolbar_Item) : NULL)
54 struct _Elm_Toolbar_Item_State
63 static const char *widtype = NULL;
64 static void _item_show(Elm_Toolbar_Item *it);
65 static void _item_select(Elm_Toolbar_Item *it);
66 static void _item_unselect(Elm_Toolbar_Item *it);
67 static void _del_pre_hook(Evas_Object *obj);
68 static void _del_hook(Evas_Object *obj);
69 static void _mirrored_set(Evas_Object *obj, Eina_Bool mirrored);
70 static void _mirrored_set_item(Evas_Object *obj, Elm_Toolbar_Item *it, Eina_Bool mirrored);
71 static void _theme_hook(Evas_Object *obj);
72 static void _sizing_eval(Evas_Object *obj);
73 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
74 static void _menu_move_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
75 static void _menu_hide(void *data, Evas *e, Evas_Object *obj, void *event_info);
76 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
77 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 *sig);
78 static void _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *sig);
80 static const char SIG_CLICKED[] = "clicked";
81 static const char SIG_LONGPRESSED[] = "longpressed";
82 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
84 static const Evas_Smart_Cb_Description _signals[] = {
86 {SIG_LONGPRESSED, ""},
87 {SIG_CLICKED_DOUBLE, ""},
92 _item_disable_hook(Elm_Object_Item *it)
95 Elm_Toolbar_Item *toolbar_it = (Elm_Toolbar_Item *)it;
97 wd = elm_widget_data_get(WIDGET(toolbar_it));
100 if (elm_widget_item_disabled_get(toolbar_it))
102 edje_object_signal_emit(VIEW(toolbar_it), "elm,state,disabled", "elm");
103 elm_widget_signal_emit(toolbar_it->icon, "elm,state,disabled", "elm");
107 edje_object_signal_emit(VIEW(toolbar_it), "elm,state,enabled", "elm");
108 elm_widget_signal_emit(toolbar_it->icon, "elm,state,enabled", "elm");
110 _resize(WIDGET(toolbar_it), NULL, NULL, NULL);
114 _item_icon_set(Evas_Object *icon_obj, const char *type, const char *icon)
118 if ((!type) || (!*type)) goto end;
119 if ((!icon) || (!*icon)) return EINA_FALSE;
120 if ((snprintf(icon_str, sizeof(icon_str), "%s%s", type, icon) > 0)
121 && (elm_icon_standard_set(icon_obj, icon_str)))
124 if (elm_icon_standard_set(icon_obj, icon))
126 WRN("couldn't find icon definition for '%s'", icon);
131 _elm_toolbar_icon_size_get(Widget_Data *wd)
133 const char *icon_size = edje_object_data_get(
134 elm_smart_scroller_edje_object_get(wd->scr), "icon_size");
136 return atoi(icon_size);
137 return _elm_config->icon_size;
141 _item_show(Elm_Toolbar_Item *it)
143 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
144 Evas_Coord x, y, w, h, bx, by;
147 evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
148 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
149 elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
153 _item_unselect(Elm_Toolbar_Item *item)
156 if ((!item) || (!item->selected)) return;
157 wd = elm_widget_data_get(WIDGET(item));
159 item->selected = EINA_FALSE;
160 wd->selected_item = NULL;
161 edje_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
162 elm_widget_signal_emit(item->icon, "elm,state,unselected", "elm");
166 _item_select(Elm_Toolbar_Item *it)
168 Elm_Toolbar_Item *it2;
169 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
174 if (elm_widget_item_disabled_get(it) || (it->separator) || (it->object)) return;
177 if (wd->select_mode != ELM_OBJECT_SELECT_MODE_NONE)
181 if (wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS) return;
186 it2 = (Elm_Toolbar_Item *)
187 elm_toolbar_selected_item_get(WIDGET(it));
190 it->selected = EINA_TRUE;
191 wd->selected_item = it;
192 edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
193 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
198 if (it->menu && (!sel))
200 evas_object_show(it->o_menu);
201 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
202 _menu_move_resize, it);
203 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOVE,
204 _menu_move_resize, it);
206 _menu_move_resize(it, NULL, NULL, NULL);
208 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
209 evas_object_smart_callback_call(obj2, SIG_CLICKED, it);
213 _menu_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
215 Elm_Toolbar_Item *selected;
216 Elm_Toolbar_Item *it = data;
217 selected = (Elm_Toolbar_Item *) elm_toolbar_selected_item_get(WIDGET(it));
218 _item_unselect(selected);
222 _menu_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
224 // avoid hide being emitted during object deletion
225 evas_object_event_callback_del_full
226 (obj, EVAS_CALLBACK_HIDE, _menu_hide, data);
230 _menu_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
232 Elm_Toolbar_Item *it = data;
234 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
236 if ((!wd) || (!wd->menu_parent)) return;
237 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
238 elm_menu_move(it->o_menu, x, y+h);
242 _item_del(Elm_Toolbar_Item *it)
244 Elm_Toolbar_Item_State *it_state;
246 EINA_LIST_FREE(it->states, it_state)
248 if (it->icon == it_state->icon)
250 eina_stringshare_del(it_state->label);
251 eina_stringshare_del(it_state->icon_str);
252 if (it_state->icon) evas_object_del(it_state->icon);
255 eina_stringshare_del(it->label);
256 eina_stringshare_del(it->icon_str);
257 if (it->icon) evas_object_del(it->icon);
258 if (it->object) evas_object_del(it->object);
259 //TODO: See if checking for wd->menu_parent is necessary before deleting menu
260 if (it->o_menu) evas_object_del(it->o_menu);
264 _del_pre_hook(Evas_Object *obj)
266 Widget_Data *wd = elm_widget_data_get(obj);
267 Elm_Toolbar_Item *it, *next;
270 it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
273 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
275 elm_widget_item_free(it);
280 _item_del(wd->more_item);
281 elm_widget_item_free(wd->more_item);
285 ecore_timer_del(wd->long_timer);
286 wd->long_timer = NULL;
291 _del_hook(Evas_Object *obj)
293 Widget_Data *wd = elm_widget_data_get(obj);
301 _mirrored_set_item(Evas_Object *obj __UNUSED__, Elm_Toolbar_Item *it, Eina_Bool mirrored)
303 edje_object_mirrored_set(VIEW(it), mirrored);
304 elm_widget_mirrored_set(it->o_menu, mirrored);
308 _theme_hook_item(Evas_Object *obj, Elm_Toolbar_Item *it, double scale, int icon_size)
310 Widget_Data *wd = elm_widget_data_get(obj);
311 Evas_Object *view = VIEW(it);
313 const char *style = elm_widget_style_get(obj);
315 _mirrored_set_item(obj, it, elm_widget_mirrored_get(obj));
316 edje_object_scale_set(view, scale);
317 if (!it->separator && !it->object)
319 _elm_theme_object_set(obj, view, "toolbar", "item", style);
322 edje_object_signal_emit(view, "elm,state,selected", "elm");
323 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
325 if (elm_widget_item_disabled_get(it))
327 edje_object_signal_emit(view, "elm,state,disabled", "elm");
328 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
334 ms = ((double)icon_size * scale);
335 evas_object_size_hint_min_set(it->icon, ms, ms);
336 evas_object_size_hint_max_set(it->icon, ms, ms);
337 edje_object_part_swallow(view, "elm.swallow.icon", it->icon);
339 edje_object_part_text_set(view, "elm.text", it->label);
345 _elm_theme_object_set(obj, view, "toolbar", "separator", style);
348 evas_object_size_hint_weight_set(view, EVAS_HINT_EXPAND, -1.0);
349 evas_object_size_hint_align_set(view, EVAS_HINT_FILL, 0.5);
353 evas_object_size_hint_weight_set(view, -1.0, EVAS_HINT_EXPAND);
354 evas_object_size_hint_align_set(view, 0.5, EVAS_HINT_FILL);
359 _elm_theme_object_set(obj, view, "toolbar", "object", style);
360 edje_object_part_swallow(view, "elm.swallow.object", it->object);
365 if (!it->separator && !it->object)
366 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
367 edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
368 if (!it->separator && !it->object)
369 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
370 evas_object_size_hint_min_set(view, mw, mh);
374 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
376 Widget_Data *wd = elm_widget_data_get(obj);
377 Elm_Toolbar_Item *it;
379 EINA_INLIST_FOREACH(wd->items, it)
380 _mirrored_set_item(obj, it, mirrored);
382 _mirrored_set_item(obj, wd->more_item, mirrored);
386 _theme_hook(Evas_Object *obj)
388 Widget_Data *wd = elm_widget_data_get(obj);
389 Elm_Toolbar_Item *it;
393 _elm_widget_mirrored_reload(obj);
394 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
395 _mirrored_set(obj, elm_widget_mirrored_get(obj));
396 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
397 edje_object_scale_set(wd->scr, scale);
398 wd->icon_size = _elm_toolbar_icon_size_get(wd);
399 EINA_INLIST_FOREACH(wd->items, it)
400 _theme_hook_item(obj, it, scale, wd->icon_size);
402 _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
407 _item_text_set_hook(Elm_Object_Item *it,
411 if (part && strcmp(part, "default")) return;
412 _item_label_set(((Elm_Toolbar_Item *)it), label, "elm,state,label_set");
416 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
418 if (part && strcmp(part, "default")) return NULL;
419 return ((Elm_Toolbar_Item *)it)->label;
423 _item_content_set_hook(Elm_Object_Item *it,
425 Evas_Object *content)
429 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
430 if (part && strcmp(part, "object")) return;
431 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
432 Evas_Object *obj = WIDGET(item);
433 Widget_Data *wd = elm_widget_data_get(obj);
434 if (!wd || !obj) return;
435 if (item->object == content) return;
437 if (item->object) evas_object_del(item->object);
439 item->object = content;
441 elm_widget_sub_object_add(obj, item->object);
442 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
443 _theme_hook_item(obj, item, scale, wd->icon_size);
447 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
449 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
450 if (part && strcmp(part, "object")) return NULL;
451 return ((Elm_Toolbar_Item *) it)->object;
455 _item_content_unset_hook(Elm_Object_Item *it, const char *part)
460 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
461 if (part && strcmp(part, "object")) return NULL;
462 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
463 Evas_Object *obj = WIDGET(item);
464 Widget_Data *wd = elm_widget_data_get(obj);
466 edje_object_part_unswallow(VIEW(it), item->object);
467 elm_widget_sub_object_del(obj, item->object);
470 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
471 _theme_hook_item(obj, item, scale, wd->icon_size);
476 _translate_hook(Evas_Object *obj)
478 evas_object_smart_callback_call(obj, "language,changed", NULL);
482 _sizing_eval(Evas_Object *obj)
484 Widget_Data *wd = elm_widget_data_get(obj);
485 Evas_Coord minw = -1, minh = -1, minw_bx = -1, minh_bx = -1;
486 Evas_Coord vw = 0, vh = 0;
490 evas_object_smart_need_recalculate_set(wd->bx, EINA_TRUE);
491 evas_object_smart_calculate(wd->bx);
492 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
494 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
495 if (w < minw) w = minw;
496 if (h < minh) h = minh;
497 evas_object_resize(wd->scr, w, h);
499 evas_object_size_hint_min_get(wd->bx, &minw_bx, &minh_bx);
500 // if (wd->vertical && (h > minh)) minh = h;
501 // if ((!wd->vertical) && (w > minw)) minw = w;
502 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
503 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_NONE)
507 minw = minw_bx + (w - vw);
508 minh = minh_bx + (h - vh);
512 minw = minw_bx + (w - vw);
513 minh = minh_bx + (h - vh);
516 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
518 minw = minw_bx + (w - vw);
519 minh = minh_bx + (h - vh);
520 if (minw_bx < vw) minw_bx = vw;
521 if (minh_bx < vh) minh_bx = vh;
527 minw = minw_bx + (w - vw);
533 minh = minh_bx + (h - vh);
535 // if (wd->vertical) minh = h - vh;
536 // else minw = w - vw;
537 // minh = minh + (h - vh);
539 evas_object_resize(wd->bx, minw_bx, minh_bx);
540 evas_object_size_hint_min_set(obj, minw, minh);
541 evas_object_size_hint_max_set(obj, -1, -1);
545 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
547 item->o_menu = elm_menu_add(VIEW(item));
548 item->menu = EINA_TRUE;
550 elm_menu_parent_set(item->o_menu, wd->menu_parent);
551 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
553 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
558 _item_menu_destroy(Elm_Toolbar_Item *item)
562 evas_object_del(item->o_menu);
565 item->menu = EINA_FALSE;
569 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
571 const Elm_Toolbar_Item *eti1 = i1;
572 const Elm_Toolbar_Item *eti2 = i2;
575 if (!eti1) return -1;
577 return eti2->prio.priority - eti1->prio.priority;
581 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
583 Elm_Toolbar_Item *it;
584 Eina_List *sorted = NULL;
585 Evas_Coord ciw = 0, cih = 0;
587 EINA_INLIST_FOREACH(wd->items, it)
589 sorted = eina_list_sorted_insert(sorted,
590 _toolbar_item_prio_compare_cb, it);
595 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL, &ciw, &cih);
596 if (wd->vertical) *iw += cih;
599 EINA_LIST_FREE(sorted, it)
601 evas_object_geometry_get(VIEW(it), NULL, NULL, &ciw, &cih);
602 if (wd->vertical) *iw += cih;
604 it->prio.visible = (*iw <= vw);
609 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
611 Elm_Toolbar_Item *it = data;
612 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
616 _resize_job(void *data)
618 Evas_Object *obj = (Evas_Object *)data;
619 Widget_Data *wd = elm_widget_data_get(obj);
620 Evas_Coord mw, mh, vw = 0, vh = 0, w = 0, h = 0;
621 Elm_Toolbar_Item *it;
624 wd->resize_job = NULL;
625 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
626 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
627 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
628 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
630 Evas_Coord iw = 0, ih = 0, more_w = 0, more_h = 0;
634 evas_object_resize(wd->bx, w, vh);
635 _fix_items_visibility(wd, &ih, vh);
639 evas_object_resize(wd->bx, vw, h);
640 _fix_items_visibility(wd, &iw, vw);
642 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL,
646 if ((ih - more_h) <= vh) ih -= more_h;
650 if ((iw - more_w) <= vw) iw -= more_w;
653 /* All items are removed from the box object, since removing individual
654 * items won't trigger a resize. Items are be readded below. */
655 evas_object_box_remove_all(wd->bx, EINA_FALSE);
656 if (((wd->vertical) && (ih > vh)) ||
657 ((!wd->vertical) && (iw > vw)))
661 _item_menu_destroy(wd->more_item);
662 _item_menu_create(wd, wd->more_item);
663 menu = elm_toolbar_item_menu_get((Elm_Object_Item *)wd->more_item);
664 EINA_INLIST_FOREACH(wd->items, it)
666 if (!it->prio.visible)
669 elm_menu_item_separator_add(menu, NULL);
672 Elm_Object_Item *menu_it;
673 menu_it = elm_menu_item_add
674 (menu, NULL, it->icon_str, it->label,
675 _elm_toolbar_item_menu_cb, it);
676 elm_object_item_disabled_set
677 (menu_it, elm_widget_item_disabled_get(it));
679 elm_menu_clone(it->o_menu, menu, menu_it);
681 evas_object_hide(VIEW(it));
685 evas_object_box_append(wd->bx, VIEW(it));
686 evas_object_show(VIEW(it));
689 evas_object_box_append(wd->bx, wd->VIEW(more_item));
690 evas_object_show(wd->VIEW(more_item));
694 /* All items are visible, show them all (except for the "More"
695 * button, of course). */
696 EINA_INLIST_FOREACH(wd->items, it)
698 evas_object_show(VIEW(it));
699 evas_object_box_append(wd->bx, VIEW(it));
701 evas_object_hide(wd->VIEW(more_item));
704 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
706 Evas_Coord iw = 0, ih = 0;
710 evas_object_resize(wd->bx, w, vh);
711 _fix_items_visibility(wd, &ih, vh);
715 evas_object_resize(wd->bx, vw, h);
716 _fix_items_visibility(wd, &iw, vw);
718 evas_object_box_remove_all(wd->bx, EINA_FALSE);
719 if (((wd->vertical) && (ih > vh)) ||
720 ((!wd->vertical) && (iw > vw)))
722 EINA_INLIST_FOREACH(wd->items, it)
724 if (!it->prio.visible)
725 evas_object_hide(VIEW(it));
728 evas_object_box_append(wd->bx, VIEW(it));
729 evas_object_show(VIEW(it));
735 /* All items are visible, show them all */
736 EINA_INLIST_FOREACH(wd->items, it)
738 evas_object_show(VIEW(it));
739 evas_object_box_append(wd->bx, VIEW(it));
743 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
745 if ((vw >= mw) && (vh >= mh))
746 evas_object_resize(wd->bx, vw, vh);
748 evas_object_resize(wd->bx, mw, vh);
750 evas_object_resize(wd->bx, vw, mh);
756 if ((vh >= mh) && (h != vh)) evas_object_resize(wd->bx, w, vh);
760 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
762 EINA_INLIST_FOREACH(wd->items, it)
772 _mirrored_set(obj, elm_widget_mirrored_get(obj));
776 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
779 _resize(data, NULL, NULL, NULL);
783 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
785 Widget_Data *wd = elm_widget_data_get(data);
787 wd->resize_job = ecore_job_add(_resize_job, data);
791 _select_filter(Elm_Toolbar_Item *it, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
794 char buf[sizeof("elm,action,click,") + 1];
796 button = atoi(emission + sizeof("mouse,clicked,") - 1);
797 if (button == 1) return; /* regular left click event */
798 snprintf(buf, sizeof(buf), "elm,action,click,%d", button);
799 edje_object_signal_emit(VIEW(it), buf, "elm");
803 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
805 Elm_Toolbar_Item *it = data;
807 if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
808 (_elm_access_2nd_click_timeout(VIEW(it))))
810 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
811 _elm_access_say(E_("Selected"));
817 _long_press(Elm_Toolbar_Item *it)
819 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
820 wd->long_timer = NULL;
821 wd->long_press = EINA_TRUE;
822 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
823 return ECORE_CALLBACK_CANCEL;
827 _mouse_down(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Down *ev)
829 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
831 if (ev->button != 1) return;
832 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
833 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
834 wd->long_press = EINA_FALSE;
835 if (wd->long_timer) ecore_timer_interval_set(wd->long_timer, _elm_config->longpress_timeout);
836 else wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, (Ecore_Task_Cb)_long_press, it);
840 _mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
842 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
844 if (ev->button != 1) return;
847 ecore_timer_del(wd->long_timer);
848 wd->long_timer = NULL;
853 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
855 Elm_Toolbar_Item *it = data;
856 edje_object_signal_emit(VIEW(it), "elm,state,highlighted", "elm");
857 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
861 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
863 Elm_Toolbar_Item *it = data;
864 edje_object_signal_emit(VIEW(it), "elm,state,unhighlighted", "elm");
865 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
869 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
871 Evas_Object *obj = (Evas_Object *) data;
872 Widget_Data *wd = elm_widget_data_get(obj);
874 _els_box_layout(o, priv, !wd->vertical, wd->homogeneous,
875 elm_widget_mirrored_get(obj));
879 _access_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item)
881 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
882 const char *txt = item->access_info;
883 if (!txt) txt = it->label;
884 if (txt) return strdup(txt);
889 _access_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
891 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
893 return strdup(E_("Separator"));
894 else if (elm_widget_item_disabled_get(it))
895 return strdup(E_("State: Disabled"));
896 else if (it->selected)
897 return strdup(E_("State: Selected"));
899 return strdup(E_("Has menu"));
904 _item_del_pre_hook(Elm_Object_Item *it)
908 Elm_Toolbar_Item *item, *next;
909 item = (Elm_Toolbar_Item *)it;
911 wd = elm_widget_data_get(WIDGET(item));
912 if (!wd) return EINA_FALSE;
915 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
916 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
918 if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
919 if ((wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
920 item->selected && next) _item_select(next);
927 static Elm_Toolbar_Item *
928 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
930 Widget_Data *wd = elm_widget_data_get(obj);
931 Evas_Object *icon_obj;
933 Elm_Toolbar_Item *it;
935 icon_obj = elm_icon_add(obj);
936 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
937 if (!icon_obj) return NULL;
938 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
941 evas_object_del(icon_obj);
945 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
946 elm_widget_item_disable_hook_set(it, _item_disable_hook);
947 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
948 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
949 elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
950 elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
951 elm_widget_item_content_unset_hook_set(it, _item_content_unset_hook);
953 it->label = eina_stringshare_add(label);
954 it->prio.visible = 1;
955 it->prio.priority = 0;
957 it->separator = EINA_FALSE;
959 it->base.data = data;
960 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
961 _elm_access_item_register(&it->base, VIEW(it));
962 _elm_access_text_set(_elm_access_item_get(&it->base),
963 ELM_ACCESS_TYPE, E_("Tool Item"));
964 _elm_access_callback_set(_elm_access_item_get(&it->base),
965 ELM_ACCESS_INFO, _access_info_cb, it);
966 _elm_access_callback_set(_elm_access_item_get(&it->base),
967 ELM_ACCESS_STATE, _access_state_cb, it);
969 if (_item_icon_set(icon_obj, "toolbar/", icon))
972 it->icon_str = eina_stringshare_add(icon);
978 evas_object_del(icon_obj);
981 _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
982 elm_widget_style_get(obj));
983 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "elm",
985 edje_object_signal_callback_add(VIEW(it), "mouse,clicked,*", "*",
986 (Edje_Signal_Cb)_select_filter, it);
987 edje_object_signal_callback_add(VIEW(it), "elm,mouse,in", "elm",
989 edje_object_signal_callback_add(VIEW(it), "elm,mouse,out", "elm",
991 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
992 (Evas_Object_Event_Cb)_mouse_down, it);
993 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
994 (Evas_Object_Event_Cb)_mouse_up, it);
995 elm_widget_sub_object_add(obj, VIEW(it));
1000 ms = ((double)wd->icon_size * _elm_config->scale);
1001 evas_object_size_hint_min_set(it->icon, ms, ms);
1002 evas_object_size_hint_max_set(it->icon, ms, ms);
1003 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
1004 edje_object_signal_emit(VIEW(it), "elm,state,icon,visible", "elm");
1005 evas_object_show(it->icon);
1006 elm_widget_sub_object_add(obj, it->icon);
1010 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
1011 edje_object_signal_emit(VIEW(it), "elm,state,text,visible", "elm");
1014 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1015 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
1016 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1017 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1021 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, -1.0);
1022 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, 0.5);
1026 evas_object_size_hint_weight_set(VIEW(it), -1.0, EVAS_HINT_EXPAND);
1027 evas_object_size_hint_align_set(VIEW(it), 0.5, EVAS_HINT_FILL);
1032 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1033 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, EVAS_HINT_FILL);
1035 evas_object_size_hint_min_set(VIEW(it), mw, mh);
1036 evas_object_size_hint_max_set(VIEW(it), -1, -1);
1037 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
1039 if ((!wd->items) && (wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS))
1046 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
1048 Evas_Coord mw = -1, mh = -1;
1049 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1050 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
1051 edje_object_signal_emit(VIEW(item), "elm,state,text,visible", "elm");
1053 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1054 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1055 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1056 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1060 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1061 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1065 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1066 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1071 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1072 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1074 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1078 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1080 Elm_Toolbar_Item *item = data;
1081 _elm_toolbar_item_label_update(item);
1082 edje_object_signal_callback_del(obj, emission, source,
1083 _elm_toolbar_item_label_set_cb);
1084 edje_object_signal_emit (VIEW(item), "elm,state,label,reset", "elm");
1088 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *sig)
1092 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
1094 eina_stringshare_replace(&item->label, label);
1095 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1096 if ((s) && (atoi(s)))
1098 edje_object_part_text_set(VIEW(item), "elm.text_new", item->label);
1099 edje_object_signal_emit (VIEW(item), sig, "elm");
1100 edje_object_signal_callback_add(VIEW(item),
1101 "elm,state,label_set,done", "elm",
1102 _elm_toolbar_item_label_set_cb, item);
1105 _elm_toolbar_item_label_update(item);
1106 _resize(WIDGET(item), NULL, NULL, NULL);
1110 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
1112 Elm_Toolbar_Item_State *it_state;
1114 Evas_Coord mw = -1, mh = -1;
1115 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1116 Evas_Object *old_icon = edje_object_part_swallow_get(VIEW(item),
1117 "elm.swallow.icon");
1118 elm_widget_sub_object_del(VIEW(item), old_icon);
1119 evas_object_hide(old_icon);
1120 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1121 edje_object_signal_emit(VIEW(item), "elm,state,icon,visible", "elm");
1122 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1123 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1124 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1125 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1129 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1130 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1134 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1135 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1140 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1141 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1143 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1145 EINA_LIST_FOREACH(item->states, l, it_state)
1147 if (it_state->icon == old_icon) return;
1149 evas_object_del(old_icon);
1153 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1155 Elm_Toolbar_Item *item = data;
1156 edje_object_part_unswallow(VIEW(item), item->icon);
1157 _elm_toolbar_item_icon_update(item);
1158 edje_object_signal_callback_del(obj, emission, source,
1159 _elm_toolbar_item_icon_set_cb);
1160 edje_object_signal_emit (VIEW(item), "elm,state,icon,reset", "elm");
1164 _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 *sig)
1166 Evas_Object *old_icon;
1171 eina_stringshare_replace(&item->icon_str, icon_str);
1174 eina_stringshare_del(item->icon_str);
1175 item->icon_str = NULL;
1177 item->icon = icon_obj;
1180 ms = (icon_size * _elm_config->scale);
1181 evas_object_size_hint_min_set(item->icon, ms, ms);
1182 evas_object_size_hint_max_set(item->icon, ms, ms);
1183 evas_object_show(item->icon);
1184 elm_widget_sub_object_add(obj, item->icon);
1186 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1187 if ((s) && (atoi(s)))
1189 old_icon = edje_object_part_swallow_get(VIEW(item),
1190 "elm.swallow.icon_new");
1193 elm_widget_sub_object_del(VIEW(item), old_icon);
1194 evas_object_hide(old_icon);
1196 edje_object_part_swallow(VIEW(item), "elm.swallow.icon_new",
1198 edje_object_signal_emit (VIEW(item), sig, "elm");
1199 edje_object_signal_callback_add(VIEW(item),
1200 "elm,state,icon_set,done", "elm",
1201 _elm_toolbar_item_icon_set_cb, item);
1204 _elm_toolbar_item_icon_update(item);
1205 _resize(obj, NULL, NULL, NULL);
1209 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1211 Elm_Toolbar_Item *it = event_info;
1212 Elm_Toolbar_Item_State *it_state;
1214 it_state = eina_list_data_get(it->current_state);
1216 it_state->func((void *)it_state->data, obj, event_info);
1219 static Elm_Toolbar_Item_State *
1220 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1222 Elm_Toolbar_Item_State *it_state;
1223 it_state = ELM_NEW(Elm_Toolbar_Item_State);
1224 it_state->label = eina_stringshare_add(label);
1225 it_state->icon_str = eina_stringshare_add(icon_str);
1226 it_state->icon = icon;
1227 it_state->func = func;
1228 it_state->data = data;
1233 elm_toolbar_add(Evas_Object *parent)
1239 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1241 ELM_SET_WIDTYPE(widtype, "toolbar");
1242 elm_widget_type_set(obj, "toolbar");
1243 elm_widget_sub_object_add(parent, obj);
1244 elm_widget_data_set(obj, wd);
1245 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1246 elm_widget_del_hook_set(obj, _del_hook);
1247 elm_widget_theme_hook_set(obj, _theme_hook);
1248 elm_widget_translate_hook_set(obj, _translate_hook);
1249 elm_widget_can_focus_set(obj, EINA_TRUE);
1251 wd->more_item = NULL;
1252 wd->selected_item = NULL;
1253 wd->scr = elm_smart_scroller_add(e);
1254 elm_smart_scroller_widget_set(wd->scr, obj);
1255 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
1256 elm_smart_scroller_bounce_allow_set(wd->scr,
1257 _elm_config->thumbscroll_bounce_enable,
1259 elm_widget_resize_object_set(obj, wd->scr);
1260 elm_smart_scroller_policy_set(wd->scr,
1261 ELM_SMART_SCROLLER_POLICY_AUTO,
1262 ELM_SMART_SCROLLER_POLICY_OFF);
1265 wd->icon_size = _elm_toolbar_icon_size_get(wd);
1268 wd->homogeneous = EINA_TRUE;
1271 wd->bx = evas_object_box_add(e);
1272 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
1273 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
1274 elm_widget_sub_object_add(obj, wd->bx);
1275 elm_smart_scroller_child_set(wd->scr, wd->bx);
1276 evas_object_show(wd->bx);
1278 elm_toolbar_shrink_mode_set(obj, _elm_config->toolbar_shrink_mode);
1279 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
1280 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
1281 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
1283 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1290 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
1292 ELM_CHECK_WIDTYPE(obj, widtype);
1293 Widget_Data *wd = elm_widget_data_get(obj);
1295 if (wd->icon_size == icon_size) return;
1296 wd->icon_size = icon_size;
1301 elm_toolbar_icon_size_get(const Evas_Object *obj)
1303 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1304 Widget_Data *wd = elm_widget_data_get(obj);
1306 return wd->icon_size;
1309 EAPI Elm_Object_Item *
1310 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1312 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1313 Widget_Data *wd = elm_widget_data_get(obj);
1314 if (!wd) return NULL;
1316 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1317 if (!it) return NULL;
1318 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1320 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
1321 evas_object_box_append(wd->bx, VIEW(it));
1322 evas_object_show(VIEW(it));
1324 _theme_hook_item(obj, it, scale, wd->icon_size);
1327 return (Elm_Object_Item *)it;
1330 EAPI Elm_Object_Item *
1331 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1333 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1334 Widget_Data *wd = elm_widget_data_get(obj);
1335 if (!wd) return NULL;
1337 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1338 if (!it) return NULL;
1339 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1341 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1342 evas_object_box_prepend(wd->bx, VIEW(it));
1343 evas_object_show(VIEW(it));
1344 _theme_hook_item(obj, it, scale, wd->icon_size);
1347 return (Elm_Object_Item *)it;
1350 EAPI Elm_Object_Item *
1351 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)
1353 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1354 ELM_OBJ_ITEM_CHECK_OR_RETURN(before, NULL);
1356 Elm_Toolbar_Item *it, *_before;
1358 wd = elm_widget_data_get(obj);
1359 if (!wd) return NULL;
1360 _before = (Elm_Toolbar_Item *) before;
1361 it = _item_new(obj, icon, label, func, data);
1362 if (!it) return NULL;
1363 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1365 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1366 EINA_INLIST_GET(_before));
1367 evas_object_box_insert_before(wd->bx, VIEW(it), VIEW(_before));
1368 evas_object_show(VIEW(it));
1369 _theme_hook_item(obj, it, scale, wd->icon_size);
1372 return (Elm_Object_Item *)it;
1375 EAPI Elm_Object_Item *
1376 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)
1378 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1379 ELM_OBJ_ITEM_CHECK_OR_RETURN(after, NULL);
1381 Elm_Toolbar_Item *it, *_after;
1383 wd = elm_widget_data_get(obj);
1384 if (!wd) return NULL;
1385 _after = (Elm_Toolbar_Item *) after;
1386 it = _item_new(obj, icon, label, func, data);
1387 if (!it) return NULL;
1388 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1390 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1391 EINA_INLIST_GET(_after));
1392 evas_object_box_insert_after(wd->bx, VIEW(it), VIEW(_after));
1393 evas_object_show(VIEW(it));
1394 _theme_hook_item(obj, it, scale, wd->icon_size);
1397 return (Elm_Object_Item *)it;
1400 EAPI Elm_Object_Item *
1401 elm_toolbar_first_item_get(const Evas_Object *obj)
1403 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1404 Widget_Data *wd = elm_widget_data_get(obj);
1405 if (!wd || !wd->items) return NULL;
1406 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1409 EAPI Elm_Object_Item *
1410 elm_toolbar_last_item_get(const Evas_Object *obj)
1412 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1413 Widget_Data *wd = elm_widget_data_get(obj);
1414 if (!wd || !wd->items) return NULL;
1415 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1418 EAPI Elm_Object_Item *
1419 elm_toolbar_item_next_get(const Elm_Object_Item *it)
1421 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1422 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1423 EINA_INLIST_GET(((Elm_Toolbar_Item *)it))->next);
1426 EAPI Elm_Object_Item *
1427 elm_toolbar_item_prev_get(const Elm_Object_Item *it)
1429 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1430 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1431 EINA_INLIST_GET(((Elm_Toolbar_Item *)it))->prev);
1435 elm_toolbar_item_priority_set(Elm_Object_Item *it, int priority)
1437 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1438 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1439 if (item->prio.priority == priority) return;
1440 item->prio.priority = priority;
1441 _resize(WIDGET(item), NULL, NULL, NULL);
1445 elm_toolbar_item_priority_get(const Elm_Object_Item *it)
1447 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
1448 return ((Elm_Toolbar_Item *)it)->prio.priority;
1451 EAPI Elm_Object_Item *
1452 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
1454 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1455 Elm_Toolbar_Item *it;
1456 Widget_Data *wd = elm_widget_data_get(obj);
1457 if (!wd) return NULL;
1459 EINA_INLIST_FOREACH(wd->items, it)
1461 if (!strcmp(it->label, label))
1462 return (Elm_Object_Item *)it;
1468 elm_toolbar_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1470 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1471 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1472 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1475 if (item->selected == selected) return;
1476 if (selected) _item_select(item);
1477 else _item_unselect(item);
1481 elm_toolbar_item_selected_get(const Elm_Object_Item *it)
1483 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1484 return ((Elm_Toolbar_Item *)it)->selected;
1487 EAPI Elm_Object_Item *
1488 elm_toolbar_selected_item_get(const Evas_Object *obj)
1490 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1491 Widget_Data *wd = elm_widget_data_get(obj);
1492 if (!wd) return NULL;
1493 return (Elm_Object_Item *) wd->selected_item;
1497 elm_toolbar_item_icon_set(Elm_Object_Item *it, const char *icon)
1499 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1501 Evas_Object *icon_obj;
1504 Elm_Toolbar_Item * item = (Elm_Toolbar_Item *)it;
1507 wd = elm_widget_data_get(obj);
1509 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1511 icon_obj = elm_icon_add(obj);
1512 if (!icon_obj) return;
1513 if (_item_icon_set(icon_obj, "toolbar/", icon))
1514 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1515 "elm,state,icon_set");
1518 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1519 "elm,state,icon_set");
1520 evas_object_del(icon_obj);
1525 elm_toolbar_item_icon_get(const Elm_Object_Item *it)
1527 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1528 return ((Elm_Toolbar_Item *)it)->icon_str;
1532 elm_toolbar_item_object_get(const Elm_Object_Item *it)
1534 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1538 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1541 wd = elm_widget_data_get(obj);
1542 if (!wd) return NULL;
1548 elm_toolbar_item_icon_object_get(Elm_Object_Item *it)
1550 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1551 return ((Elm_Toolbar_Item *)it)->icon;
1555 elm_toolbar_item_icon_memfile_set(Elm_Object_Item *it, const void *img, size_t size, const char *format, const char *key)
1557 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1559 Evas_Object *icon_obj;
1563 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1566 wd = elm_widget_data_get(obj);
1567 if (!wd) return EINA_FALSE;
1571 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1572 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1573 ret = _els_smart_icon_memfile_set(icon_obj, img, size, format, key);
1576 evas_object_del(icon_obj);
1579 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1580 "elm,state,icon_set");
1583 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1588 elm_toolbar_item_icon_file_set(Elm_Object_Item *it, const char *file, const char *key)
1590 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1592 Evas_Object *icon_obj;
1596 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1599 wd = elm_widget_data_get(obj);
1600 if (!wd) return EINA_FALSE;
1604 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1605 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1606 ret = _els_smart_icon_file_key_set(icon_obj, file, key);
1609 evas_object_del(icon_obj);
1612 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1613 "elm,state,icon_set");
1616 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1621 elm_toolbar_item_separator_set(Elm_Object_Item *it, Eina_Bool separator)
1623 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1624 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1625 Evas_Object *obj = WIDGET(item);
1626 Widget_Data *wd = elm_widget_data_get(obj);
1628 if (item->separator == separator) return;
1629 item->separator = separator;
1630 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1631 _theme_hook_item(obj, item, scale, wd->icon_size);
1635 elm_toolbar_item_separator_get(const Elm_Object_Item *it)
1637 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1638 return ((Elm_Toolbar_Item *)it)->separator;
1642 elm_toolbar_shrink_mode_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1644 ELM_CHECK_WIDTYPE(obj, widtype);
1645 Widget_Data *wd = elm_widget_data_get(obj);
1649 wd->shrink_mode = shrink_mode;
1650 bounce = (_elm_config->thumbscroll_bounce_enable) &&
1651 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1652 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1656 _item_del(wd->more_item);
1657 elm_widget_item_free(wd->more_item);
1658 wd->more_item = NULL;
1661 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1663 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1664 ELM_SMART_SCROLLER_POLICY_OFF);
1665 wd->more_item = _item_new(obj, "more_menu", "More", NULL, NULL);
1667 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1668 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1669 ELM_SMART_SCROLLER_POLICY_OFF);
1671 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1672 ELM_SMART_SCROLLER_POLICY_OFF);
1676 EAPI Elm_Toolbar_Shrink_Mode
1677 elm_toolbar_shrink_mode_get(const Evas_Object *obj)
1679 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1680 Widget_Data *wd = elm_widget_data_get(obj);
1682 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1683 return wd->shrink_mode;
1687 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
1689 ELM_CHECK_WIDTYPE(obj, widtype);
1690 Widget_Data *wd = elm_widget_data_get(obj);
1693 wd->homogeneous = !!homogeneous;
1694 evas_object_smart_calculate(wd->bx);
1698 elm_toolbar_homogeneous_get(const Evas_Object *obj)
1700 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1701 Widget_Data *wd = elm_widget_data_get(obj);
1703 if (!wd) return EINA_FALSE;
1704 return wd->homogeneous;
1708 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1710 Elm_Toolbar_Item *it;
1711 ELM_CHECK_WIDTYPE(obj, widtype);
1712 Widget_Data *wd = elm_widget_data_get(obj);
1715 EINA_SAFETY_ON_NULL_RETURN(parent);
1716 wd->menu_parent = parent;
1717 EINA_INLIST_FOREACH(wd->items, it)
1720 elm_menu_parent_set(it->o_menu, wd->menu_parent);
1722 if ((wd->more_item) && (wd->more_item->o_menu))
1723 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1727 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1729 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1730 Widget_Data *wd = elm_widget_data_get(obj);
1732 if (!wd) return NULL;
1733 return wd->menu_parent;
1737 elm_toolbar_align_set(Evas_Object *obj, double align)
1739 ELM_CHECK_WIDTYPE(obj, widtype);
1740 Widget_Data *wd = elm_widget_data_get(obj);
1745 if (wd->align != align)
1746 evas_object_size_hint_align_set(wd->bx, 0.5, align);
1750 if (wd->align != align)
1751 evas_object_size_hint_align_set(wd->bx, align, 0.5);
1757 elm_toolbar_align_get(const Evas_Object *obj)
1759 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1760 Widget_Data *wd = elm_widget_data_get(obj);
1762 if (!wd) return 0.0;
1767 elm_toolbar_item_menu_set(Elm_Object_Item *it, Eina_Bool menu)
1769 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1770 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1771 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1774 if (item->menu == menu) return;
1775 if (menu) _item_menu_create(wd, item);
1776 else _item_menu_destroy(item);
1780 elm_toolbar_item_menu_get(const Elm_Object_Item *it)
1782 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1783 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1784 if (!item->menu) return NULL;
1785 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1786 if (!wd) return NULL;
1787 return item->o_menu;
1790 EAPI Elm_Toolbar_Item_State *
1791 elm_toolbar_item_state_add(Elm_Object_Item *it, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1793 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1795 Elm_Toolbar_Item_State *it_state;
1796 Evas_Object *icon_obj;
1799 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1801 wd = elm_widget_data_get(WIDGET(item));
1802 if (!wd) return NULL;
1806 it_state = _item_state_new(item->label, item->icon_str, item->icon,
1807 item->func, item->base.data);
1808 item->states = eina_list_append(item->states, it_state);
1809 item->current_state = item->states;
1812 icon_obj = elm_icon_add(obj);
1813 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1814 if (!icon_obj) goto error_state_add;
1816 if (!_item_icon_set(icon_obj, "toolbar/", icon))
1818 evas_object_del(icon_obj);
1823 it_state = _item_state_new(label, icon, icon_obj, func, data);
1824 item->states = eina_list_append(item->states, it_state);
1825 item->func = _elm_toolbar_item_state_cb;
1826 item->base.data = NULL;
1831 if (item->states && !eina_list_next(item->states))
1833 eina_stringshare_del(item->label);
1834 eina_stringshare_del(item->icon_str);
1835 free(eina_list_data_get(item->states));
1836 eina_list_free(item->states);
1837 item->states = NULL;
1843 elm_toolbar_item_state_del(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1845 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1847 Eina_List *del_state;
1848 Elm_Toolbar_Item_State *it_state;
1849 Elm_Toolbar_Item *item;
1851 if (!state) return EINA_FALSE;
1853 item = (Elm_Toolbar_Item *)it;
1854 if (!item->states) return EINA_FALSE;
1856 del_state = eina_list_data_find_list(item->states, state);
1857 if (del_state == item->states) return EINA_FALSE;
1858 if (del_state == item->current_state)
1859 elm_toolbar_item_state_unset(it);
1861 eina_stringshare_del(state->label);
1862 eina_stringshare_del(state->icon_str);
1863 if (state->icon) evas_object_del(state->icon);
1865 item->states = eina_list_remove_list(item->states, del_state);
1866 if (item->states && !eina_list_next(item->states))
1868 it_state = eina_list_data_get(item->states);
1869 item->base.data = it_state->data;
1870 item->func = it_state->func;
1871 eina_stringshare_del(it_state->label);
1872 eina_stringshare_del(it_state->icon_str);
1873 free(eina_list_data_get(item->states));
1874 eina_list_free(item->states);
1875 item->states = NULL;
1881 elm_toolbar_item_state_set(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1883 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1886 Eina_List *next_state;
1887 Elm_Toolbar_Item_State *it_state;
1889 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1892 wd = elm_widget_data_get(obj);
1893 if (!wd) return EINA_FALSE;
1894 if (!item->states) return EINA_FALSE;
1898 next_state = eina_list_data_find_list(item->states, state);
1899 if (!next_state) return EINA_FALSE;
1902 next_state = item->states;
1904 if (next_state == item->current_state) return EINA_TRUE;
1906 it_state = eina_list_data_get(next_state);
1907 if (eina_list_data_find(item->current_state, state))
1909 _item_label_set(item, it_state->label, "elm,state,label_set,forward");
1910 _elm_toolbar_item_icon_obj_set(obj, item, it_state->icon, it_state->icon_str,
1911 wd->icon_size, "elm,state,icon_set,forward");
1915 _item_label_set(item, it_state->label, "elm,state,label_set,backward");
1916 _elm_toolbar_item_icon_obj_set(obj,
1921 "elm,state,icon_set,backward");
1923 if (elm_widget_item_disabled_get(item))
1924 elm_widget_signal_emit(item->icon, "elm,state,disabled", "elm");
1926 elm_widget_signal_emit(item->icon, "elm,state,enabled", "elm");
1928 item->current_state = next_state;
1933 elm_toolbar_item_state_unset(Elm_Object_Item *it)
1935 elm_toolbar_item_state_set(it, NULL);
1938 EAPI Elm_Toolbar_Item_State *
1939 elm_toolbar_item_state_get(const Elm_Object_Item *it)
1941 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1942 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1944 if ((!item->states) || (!item->current_state)) return NULL;
1945 if (item->current_state == item->states) return NULL;
1947 return eina_list_data_get(item->current_state);
1950 EAPI Elm_Toolbar_Item_State *
1951 elm_toolbar_item_state_next(Elm_Object_Item *it)
1953 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1957 Eina_List *next_state;
1958 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1961 wd = elm_widget_data_get(obj);
1962 if (!wd) return NULL;
1963 if (!item->states) return NULL;
1965 next_state = eina_list_next(item->current_state);
1967 next_state = eina_list_next(item->states);
1968 return eina_list_data_get(next_state);
1971 EAPI Elm_Toolbar_Item_State *
1972 elm_toolbar_item_state_prev(Elm_Object_Item *it)
1974 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1978 Eina_List *prev_state;
1979 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1982 wd = elm_widget_data_get(obj);
1983 if (!wd) return NULL;
1984 if (!item->states) return NULL;
1986 prev_state = eina_list_prev(item->current_state);
1987 if ((!prev_state) || (prev_state == item->states))
1988 prev_state = eina_list_last(item->states);
1989 return eina_list_data_get(prev_state);
1993 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
1995 ELM_CHECK_WIDTYPE(obj, widtype);
1996 Elm_Toolbar_Item *it;
1997 Widget_Data *wd = elm_widget_data_get(obj);
2000 wd->lookup_order = order;
2001 EINA_INLIST_FOREACH(wd->items, it)
2002 elm_icon_order_lookup_set(it->icon, order);
2004 elm_icon_order_lookup_set(wd->more_item->icon, order);
2007 EAPI Elm_Icon_Lookup_Order
2008 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
2010 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
2011 Widget_Data *wd = elm_widget_data_get(obj);
2012 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
2013 return wd->lookup_order;
2017 elm_toolbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
2019 ELM_CHECK_WIDTYPE(obj, widtype);
2020 Widget_Data *wd = elm_widget_data_get(obj);
2022 wd->vertical = !horizontal;
2024 evas_object_size_hint_align_set(wd->bx, 0.5, wd->align);
2026 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
2031 elm_toolbar_horizontal_get(const Evas_Object *obj)
2033 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2034 Widget_Data *wd = elm_widget_data_get(obj);
2035 if (!wd) return EINA_FALSE;
2036 return !wd->vertical;
2040 elm_toolbar_items_count(const Evas_Object *obj)
2042 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2043 Widget_Data *wd = elm_widget_data_get(obj);
2045 return wd->item_count;
2049 elm_toolbar_select_mode_set(Evas_Object *obj, Elm_Object_Select_Mode mode)
2051 ELM_CHECK_WIDTYPE(obj, widtype);
2052 Widget_Data *wd = elm_widget_data_get(obj);
2054 if (mode >= ELM_OBJECT_SELECT_MODE_MAX)
2056 if ((mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2057 (wd->select_mode != ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2059 _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
2060 if (wd->select_mode != mode)
2061 wd->select_mode = mode;
2064 EAPI Elm_Object_Select_Mode
2065 elm_toolbar_select_mode_get(const Evas_Object *obj)
2067 ELM_CHECK_WIDTYPE(obj, widtype) ELM_OBJECT_SELECT_MODE_MAX;
2068 Widget_Data *wd = elm_widget_data_get(obj);
2069 if (!wd) return ELM_OBJECT_SELECT_MODE_MAX;
2070 return wd->select_mode;