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_escaped_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, *prev;
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;
605 it->prio.visible = (*iw <= vw);
608 prev = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
609 it->prio.visible = prev->prio.visible;
615 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
617 Elm_Toolbar_Item *it = data;
618 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
622 _resize_job(void *data)
624 Evas_Object *obj = (Evas_Object *)data;
625 Widget_Data *wd = elm_widget_data_get(obj);
626 Evas_Coord mw, mh, vw = 0, vh = 0, w = 0, h = 0;
627 Elm_Toolbar_Item *it;
630 wd->resize_job = NULL;
631 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
632 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
633 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
634 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
636 Evas_Coord iw = 0, ih = 0, more_w = 0, more_h = 0;
640 evas_object_resize(wd->bx, w, vh);
641 _fix_items_visibility(wd, &ih, vh);
645 evas_object_resize(wd->bx, vw, h);
646 _fix_items_visibility(wd, &iw, vw);
648 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL,
652 if ((ih - more_h) <= vh) ih -= more_h;
656 if ((iw - more_w) <= vw) iw -= more_w;
659 /* All items are removed from the box object, since removing individual
660 * items won't trigger a resize. Items are be readded below. */
661 evas_object_box_remove_all(wd->bx, EINA_FALSE);
662 if (((wd->vertical) && (ih > vh)) ||
663 ((!wd->vertical) && (iw > vw)))
667 _item_menu_destroy(wd->more_item);
668 _item_menu_create(wd, wd->more_item);
669 menu = elm_toolbar_item_menu_get((Elm_Object_Item *)wd->more_item);
670 EINA_INLIST_FOREACH(wd->items, it)
672 if (!it->prio.visible)
675 elm_menu_item_separator_add(menu, NULL);
678 Elm_Object_Item *menu_it;
679 menu_it = elm_menu_item_add
680 (menu, NULL, it->icon_str, it->label,
681 _elm_toolbar_item_menu_cb, it);
682 elm_object_item_disabled_set
683 (menu_it, elm_widget_item_disabled_get(it));
685 elm_menu_clone(it->o_menu, menu, menu_it);
687 evas_object_hide(VIEW(it));
691 evas_object_box_append(wd->bx, VIEW(it));
692 evas_object_show(VIEW(it));
695 evas_object_box_append(wd->bx, wd->VIEW(more_item));
696 evas_object_show(wd->VIEW(more_item));
700 /* All items are visible, show them all (except for the "More"
701 * button, of course). */
702 EINA_INLIST_FOREACH(wd->items, it)
704 evas_object_show(VIEW(it));
705 evas_object_box_append(wd->bx, VIEW(it));
707 evas_object_hide(wd->VIEW(more_item));
710 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
712 Evas_Coord iw = 0, ih = 0;
716 evas_object_resize(wd->bx, w, vh);
717 _fix_items_visibility(wd, &ih, vh);
721 evas_object_resize(wd->bx, vw, h);
722 _fix_items_visibility(wd, &iw, vw);
724 evas_object_box_remove_all(wd->bx, EINA_FALSE);
725 if (((wd->vertical) && (ih > vh)) ||
726 ((!wd->vertical) && (iw > vw)))
728 EINA_INLIST_FOREACH(wd->items, it)
730 if (!it->prio.visible)
731 evas_object_hide(VIEW(it));
734 evas_object_box_append(wd->bx, VIEW(it));
735 evas_object_show(VIEW(it));
741 /* All items are visible, show them all */
742 EINA_INLIST_FOREACH(wd->items, it)
744 evas_object_show(VIEW(it));
745 evas_object_box_append(wd->bx, VIEW(it));
749 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
751 if ((vw >= mw) && (vh >= mh))
752 evas_object_resize(wd->bx, vw, vh);
754 evas_object_resize(wd->bx, mw, vh);
756 evas_object_resize(wd->bx, vw, mh);
762 if ((vh >= mh) && (h != vh)) evas_object_resize(wd->bx, w, vh);
766 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
768 EINA_INLIST_FOREACH(wd->items, it)
778 _mirrored_set(obj, elm_widget_mirrored_get(obj));
782 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
785 _resize(data, NULL, NULL, NULL);
789 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
791 Widget_Data *wd = elm_widget_data_get(data);
793 wd->resize_job = ecore_job_add(_resize_job, data);
797 _select_filter(Elm_Toolbar_Item *it, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
800 char buf[sizeof("elm,action,click,") + 1];
802 button = atoi(emission + sizeof("mouse,clicked,") - 1);
803 if (button == 1) return; /* regular left click event */
804 snprintf(buf, sizeof(buf), "elm,action,click,%d", button);
805 edje_object_signal_emit(VIEW(it), buf, "elm");
809 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
811 Elm_Toolbar_Item *it = data;
813 if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
814 (_elm_access_2nd_click_timeout(VIEW(it))))
816 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
817 _elm_access_say(E_("Selected"));
823 _long_press(Elm_Toolbar_Item *it)
825 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
826 wd->long_timer = NULL;
827 wd->long_press = EINA_TRUE;
828 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
829 return ECORE_CALLBACK_CANCEL;
833 _mouse_down(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Down *ev)
835 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
837 if (ev->button != 1) return;
838 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
839 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
840 wd->long_press = EINA_FALSE;
841 if (wd->long_timer) ecore_timer_interval_set(wd->long_timer, _elm_config->longpress_timeout);
842 else wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, (Ecore_Task_Cb)_long_press, it);
846 _mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
848 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
850 if (ev->button != 1) return;
853 ecore_timer_del(wd->long_timer);
854 wd->long_timer = NULL;
859 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
861 Elm_Toolbar_Item *it = data;
862 edje_object_signal_emit(VIEW(it), "elm,state,highlighted", "elm");
863 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
867 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
869 Elm_Toolbar_Item *it = data;
870 edje_object_signal_emit(VIEW(it), "elm,state,unhighlighted", "elm");
871 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
875 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
877 Evas_Object *obj = (Evas_Object *) data;
878 Widget_Data *wd = elm_widget_data_get(obj);
880 _els_box_layout(o, priv, !wd->vertical, wd->homogeneous,
881 elm_widget_mirrored_get(obj));
885 _access_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item)
887 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
888 const char *txt = item->access_info;
889 if (!txt) txt = it->label;
890 if (txt) return strdup(txt);
895 _access_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
897 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
899 return strdup(E_("Separator"));
900 else if (elm_widget_item_disabled_get(it))
901 return strdup(E_("State: Disabled"));
902 else if (it->selected)
903 return strdup(E_("State: Selected"));
905 return strdup(E_("Has menu"));
910 _item_del_pre_hook(Elm_Object_Item *it)
914 Elm_Toolbar_Item *item, *next;
915 item = (Elm_Toolbar_Item *)it;
917 wd = elm_widget_data_get(WIDGET(item));
918 if (!wd) return EINA_FALSE;
921 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
922 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
924 if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
925 if ((wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
926 item->selected && next) _item_select(next);
933 static Elm_Toolbar_Item *
934 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
936 Widget_Data *wd = elm_widget_data_get(obj);
937 Evas_Object *icon_obj;
939 Elm_Toolbar_Item *it;
941 icon_obj = elm_icon_add(obj);
942 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
943 if (!icon_obj) return NULL;
944 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
947 evas_object_del(icon_obj);
951 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
952 elm_widget_item_disable_hook_set(it, _item_disable_hook);
953 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
954 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
955 elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
956 elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
957 elm_widget_item_content_unset_hook_set(it, _item_content_unset_hook);
959 it->label = eina_stringshare_add(label);
960 it->prio.visible = 1;
961 it->prio.priority = 0;
963 it->separator = EINA_FALSE;
965 it->base.data = data;
966 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
967 _elm_access_item_register(&it->base, VIEW(it));
968 _elm_access_text_set(_elm_access_item_get(&it->base),
969 ELM_ACCESS_TYPE, E_("Tool Item"));
970 _elm_access_callback_set(_elm_access_item_get(&it->base),
971 ELM_ACCESS_INFO, _access_info_cb, it);
972 _elm_access_callback_set(_elm_access_item_get(&it->base),
973 ELM_ACCESS_STATE, _access_state_cb, it);
975 if (_item_icon_set(icon_obj, "toolbar/", icon))
978 it->icon_str = eina_stringshare_add(icon);
984 evas_object_del(icon_obj);
987 _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
988 elm_widget_style_get(obj));
989 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "elm",
991 edje_object_signal_callback_add(VIEW(it), "mouse,clicked,*", "*",
992 (Edje_Signal_Cb)_select_filter, it);
993 edje_object_signal_callback_add(VIEW(it), "elm,mouse,in", "elm",
995 edje_object_signal_callback_add(VIEW(it), "elm,mouse,out", "elm",
997 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
998 (Evas_Object_Event_Cb)_mouse_down, it);
999 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
1000 (Evas_Object_Event_Cb)_mouse_up, it);
1001 elm_widget_sub_object_add(obj, VIEW(it));
1006 ms = ((double)wd->icon_size * _elm_config->scale);
1007 evas_object_size_hint_min_set(it->icon, ms, ms);
1008 evas_object_size_hint_max_set(it->icon, ms, ms);
1009 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
1010 edje_object_signal_emit(VIEW(it), "elm,state,icon,visible", "elm");
1011 evas_object_show(it->icon);
1012 elm_widget_sub_object_add(obj, it->icon);
1016 edje_object_part_text_escaped_set(VIEW(it), "elm.text", it->label);
1017 edje_object_signal_emit(VIEW(it), "elm,state,text,visible", "elm");
1020 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1021 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
1022 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1023 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1027 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, -1.0);
1028 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, 0.5);
1032 evas_object_size_hint_weight_set(VIEW(it), -1.0, EVAS_HINT_EXPAND);
1033 evas_object_size_hint_align_set(VIEW(it), 0.5, EVAS_HINT_FILL);
1038 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1039 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, EVAS_HINT_FILL);
1041 evas_object_size_hint_min_set(VIEW(it), mw, mh);
1042 evas_object_size_hint_max_set(VIEW(it), -1, -1);
1043 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
1045 if ((!wd->items) && (wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS))
1052 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
1054 Evas_Coord mw = -1, mh = -1;
1055 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1056 edje_object_part_text_escaped_set(VIEW(item), "elm.text", item->label);
1057 edje_object_signal_emit(VIEW(item), "elm,state,text,visible", "elm");
1059 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1060 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1061 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1062 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1066 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1067 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1071 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1072 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1077 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1078 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1080 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1084 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1086 Elm_Toolbar_Item *item = data;
1087 _elm_toolbar_item_label_update(item);
1088 edje_object_signal_callback_del(obj, emission, source,
1089 _elm_toolbar_item_label_set_cb);
1090 edje_object_signal_emit (VIEW(item), "elm,state,label,reset", "elm");
1094 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *sig)
1098 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
1100 eina_stringshare_replace(&item->label, label);
1101 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1102 if ((s) && (atoi(s)))
1104 edje_object_part_text_escaped_set(VIEW(item), "elm.text_new", item->label);
1105 edje_object_signal_emit (VIEW(item), sig, "elm");
1106 edje_object_signal_callback_add(VIEW(item),
1107 "elm,state,label_set,done", "elm",
1108 _elm_toolbar_item_label_set_cb, item);
1111 _elm_toolbar_item_label_update(item);
1112 _resize(WIDGET(item), NULL, NULL, NULL);
1116 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
1118 Elm_Toolbar_Item_State *it_state;
1120 Evas_Coord mw = -1, mh = -1;
1121 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1122 Evas_Object *old_icon = edje_object_part_swallow_get(VIEW(item),
1123 "elm.swallow.icon");
1124 elm_widget_sub_object_del(VIEW(item), old_icon);
1125 evas_object_hide(old_icon);
1126 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1127 edje_object_signal_emit(VIEW(item), "elm,state,icon,visible", "elm");
1128 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1129 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1130 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1131 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1135 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1136 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1140 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1141 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1146 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1147 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1149 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1151 EINA_LIST_FOREACH(item->states, l, it_state)
1153 if (it_state->icon == old_icon) return;
1155 evas_object_del(old_icon);
1159 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1161 Elm_Toolbar_Item *item = data;
1162 edje_object_part_unswallow(VIEW(item), item->icon);
1163 _elm_toolbar_item_icon_update(item);
1164 edje_object_signal_callback_del(obj, emission, source,
1165 _elm_toolbar_item_icon_set_cb);
1166 edje_object_signal_emit (VIEW(item), "elm,state,icon,reset", "elm");
1170 _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)
1172 Evas_Object *old_icon;
1177 eina_stringshare_replace(&item->icon_str, icon_str);
1180 eina_stringshare_del(item->icon_str);
1181 item->icon_str = NULL;
1183 item->icon = icon_obj;
1186 ms = (icon_size * _elm_config->scale);
1187 evas_object_size_hint_min_set(item->icon, ms, ms);
1188 evas_object_size_hint_max_set(item->icon, ms, ms);
1189 evas_object_show(item->icon);
1190 elm_widget_sub_object_add(obj, item->icon);
1192 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1193 if ((s) && (atoi(s)))
1195 old_icon = edje_object_part_swallow_get(VIEW(item),
1196 "elm.swallow.icon_new");
1199 elm_widget_sub_object_del(VIEW(item), old_icon);
1200 evas_object_hide(old_icon);
1202 edje_object_part_swallow(VIEW(item), "elm.swallow.icon_new",
1204 edje_object_signal_emit (VIEW(item), sig, "elm");
1205 edje_object_signal_callback_add(VIEW(item),
1206 "elm,state,icon_set,done", "elm",
1207 _elm_toolbar_item_icon_set_cb, item);
1210 _elm_toolbar_item_icon_update(item);
1211 _resize(obj, NULL, NULL, NULL);
1215 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1217 Elm_Toolbar_Item *it = event_info;
1218 Elm_Toolbar_Item_State *it_state;
1220 it_state = eina_list_data_get(it->current_state);
1222 it_state->func((void *)it_state->data, obj, event_info);
1225 static Elm_Toolbar_Item_State *
1226 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1228 Elm_Toolbar_Item_State *it_state;
1229 it_state = ELM_NEW(Elm_Toolbar_Item_State);
1230 it_state->label = eina_stringshare_add(label);
1231 it_state->icon_str = eina_stringshare_add(icon_str);
1232 it_state->icon = icon;
1233 it_state->func = func;
1234 it_state->data = data;
1239 elm_toolbar_add(Evas_Object *parent)
1245 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1247 ELM_SET_WIDTYPE(widtype, "toolbar");
1248 elm_widget_type_set(obj, "toolbar");
1249 elm_widget_sub_object_add(parent, obj);
1250 elm_widget_data_set(obj, wd);
1251 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1252 elm_widget_del_hook_set(obj, _del_hook);
1253 elm_widget_theme_hook_set(obj, _theme_hook);
1254 elm_widget_translate_hook_set(obj, _translate_hook);
1255 elm_widget_can_focus_set(obj, EINA_TRUE);
1257 wd->more_item = NULL;
1258 wd->selected_item = NULL;
1259 wd->scr = elm_smart_scroller_add(e);
1260 elm_smart_scroller_widget_set(wd->scr, obj);
1261 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
1262 elm_smart_scroller_bounce_allow_set(wd->scr,
1263 _elm_config->thumbscroll_bounce_enable,
1265 elm_widget_resize_object_set(obj, wd->scr);
1266 elm_smart_scroller_policy_set(wd->scr,
1267 ELM_SMART_SCROLLER_POLICY_AUTO,
1268 ELM_SMART_SCROLLER_POLICY_OFF);
1271 wd->icon_size = _elm_toolbar_icon_size_get(wd);
1274 wd->homogeneous = EINA_TRUE;
1277 wd->bx = evas_object_box_add(e);
1278 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
1279 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
1280 elm_widget_sub_object_add(obj, wd->bx);
1281 elm_smart_scroller_child_set(wd->scr, wd->bx);
1282 evas_object_show(wd->bx);
1284 elm_toolbar_shrink_mode_set(obj, _elm_config->toolbar_shrink_mode);
1285 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
1286 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
1287 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
1289 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1296 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
1298 ELM_CHECK_WIDTYPE(obj, widtype);
1299 Widget_Data *wd = elm_widget_data_get(obj);
1301 if (wd->icon_size == icon_size) return;
1302 wd->icon_size = icon_size;
1307 elm_toolbar_icon_size_get(const Evas_Object *obj)
1309 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1310 Widget_Data *wd = elm_widget_data_get(obj);
1312 return wd->icon_size;
1315 EAPI Elm_Object_Item *
1316 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1318 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1319 Widget_Data *wd = elm_widget_data_get(obj);
1320 if (!wd) return NULL;
1322 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1323 if (!it) return NULL;
1324 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1326 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
1327 evas_object_box_append(wd->bx, VIEW(it));
1328 evas_object_show(VIEW(it));
1330 _theme_hook_item(obj, it, scale, wd->icon_size);
1333 return (Elm_Object_Item *)it;
1336 EAPI Elm_Object_Item *
1337 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1339 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1340 Widget_Data *wd = elm_widget_data_get(obj);
1341 if (!wd) return NULL;
1343 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1344 if (!it) return NULL;
1345 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1347 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1348 evas_object_box_prepend(wd->bx, VIEW(it));
1349 evas_object_show(VIEW(it));
1350 _theme_hook_item(obj, it, scale, wd->icon_size);
1353 return (Elm_Object_Item *)it;
1356 EAPI Elm_Object_Item *
1357 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)
1359 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1360 ELM_OBJ_ITEM_CHECK_OR_RETURN(before, NULL);
1362 Elm_Toolbar_Item *it, *_before;
1364 wd = elm_widget_data_get(obj);
1365 if (!wd) return NULL;
1366 _before = (Elm_Toolbar_Item *) before;
1367 it = _item_new(obj, icon, label, func, data);
1368 if (!it) return NULL;
1369 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1371 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1372 EINA_INLIST_GET(_before));
1373 evas_object_box_insert_before(wd->bx, VIEW(it), VIEW(_before));
1374 evas_object_show(VIEW(it));
1375 _theme_hook_item(obj, it, scale, wd->icon_size);
1378 return (Elm_Object_Item *)it;
1381 EAPI Elm_Object_Item *
1382 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)
1384 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1385 ELM_OBJ_ITEM_CHECK_OR_RETURN(after, NULL);
1387 Elm_Toolbar_Item *it, *_after;
1389 wd = elm_widget_data_get(obj);
1390 if (!wd) return NULL;
1391 _after = (Elm_Toolbar_Item *) after;
1392 it = _item_new(obj, icon, label, func, data);
1393 if (!it) return NULL;
1394 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1396 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1397 EINA_INLIST_GET(_after));
1398 evas_object_box_insert_after(wd->bx, VIEW(it), VIEW(_after));
1399 evas_object_show(VIEW(it));
1400 _theme_hook_item(obj, it, scale, wd->icon_size);
1403 return (Elm_Object_Item *)it;
1406 EAPI Elm_Object_Item *
1407 elm_toolbar_first_item_get(const Evas_Object *obj)
1409 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1410 Widget_Data *wd = elm_widget_data_get(obj);
1411 if (!wd || !wd->items) return NULL;
1412 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1415 EAPI Elm_Object_Item *
1416 elm_toolbar_last_item_get(const Evas_Object *obj)
1418 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1419 Widget_Data *wd = elm_widget_data_get(obj);
1420 if (!wd || !wd->items) return NULL;
1421 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1424 EAPI Elm_Object_Item *
1425 elm_toolbar_item_next_get(const Elm_Object_Item *it)
1427 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1428 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1429 EINA_INLIST_GET(((Elm_Toolbar_Item *)it))->next);
1432 EAPI Elm_Object_Item *
1433 elm_toolbar_item_prev_get(const Elm_Object_Item *it)
1435 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1436 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1437 EINA_INLIST_GET(((Elm_Toolbar_Item *)it))->prev);
1441 elm_toolbar_item_priority_set(Elm_Object_Item *it, int priority)
1443 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1444 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1445 if (item->prio.priority == priority) return;
1446 item->prio.priority = priority;
1447 _resize(WIDGET(item), NULL, NULL, NULL);
1451 elm_toolbar_item_priority_get(const Elm_Object_Item *it)
1453 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
1454 return ((Elm_Toolbar_Item *)it)->prio.priority;
1457 EAPI Elm_Object_Item *
1458 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
1460 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1461 Elm_Toolbar_Item *it;
1462 Widget_Data *wd = elm_widget_data_get(obj);
1463 if (!wd) return NULL;
1465 EINA_INLIST_FOREACH(wd->items, it)
1467 if (!strcmp(it->label, label))
1468 return (Elm_Object_Item *)it;
1474 elm_toolbar_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1476 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1477 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1478 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1481 if (item->selected == selected) return;
1482 if (selected) _item_select(item);
1483 else _item_unselect(item);
1487 elm_toolbar_item_selected_get(const Elm_Object_Item *it)
1489 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1490 return ((Elm_Toolbar_Item *)it)->selected;
1493 EAPI Elm_Object_Item *
1494 elm_toolbar_selected_item_get(const Evas_Object *obj)
1496 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1497 Widget_Data *wd = elm_widget_data_get(obj);
1498 if (!wd) return NULL;
1499 return (Elm_Object_Item *) wd->selected_item;
1503 elm_toolbar_item_icon_set(Elm_Object_Item *it, const char *icon)
1505 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1507 Evas_Object *icon_obj;
1510 Elm_Toolbar_Item * item = (Elm_Toolbar_Item *)it;
1513 wd = elm_widget_data_get(obj);
1515 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1517 icon_obj = elm_icon_add(obj);
1518 if (!icon_obj) return;
1519 if (_item_icon_set(icon_obj, "toolbar/", icon))
1520 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1521 "elm,state,icon_set");
1524 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1525 "elm,state,icon_set");
1526 evas_object_del(icon_obj);
1531 elm_toolbar_item_icon_get(const Elm_Object_Item *it)
1533 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1534 return ((Elm_Toolbar_Item *)it)->icon_str;
1538 elm_toolbar_item_object_get(const Elm_Object_Item *it)
1540 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1544 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1547 wd = elm_widget_data_get(obj);
1548 if (!wd) return NULL;
1554 elm_toolbar_item_icon_object_get(Elm_Object_Item *it)
1556 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1557 return ((Elm_Toolbar_Item *)it)->icon;
1561 elm_toolbar_item_icon_memfile_set(Elm_Object_Item *it, const void *img, size_t size, const char *format, const char *key)
1563 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1565 Evas_Object *icon_obj;
1569 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1572 wd = elm_widget_data_get(obj);
1573 if (!wd) return EINA_FALSE;
1577 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1578 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1579 ret = _els_smart_icon_memfile_set(icon_obj, img, size, format, key);
1582 evas_object_del(icon_obj);
1585 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1586 "elm,state,icon_set");
1589 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1594 elm_toolbar_item_icon_file_set(Elm_Object_Item *it, const char *file, const char *key)
1596 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1598 Evas_Object *icon_obj;
1602 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1605 wd = elm_widget_data_get(obj);
1606 if (!wd) return EINA_FALSE;
1610 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1611 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1612 ret = _els_smart_icon_file_key_set(icon_obj, file, key);
1615 evas_object_del(icon_obj);
1618 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1619 "elm,state,icon_set");
1622 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1627 elm_toolbar_item_separator_set(Elm_Object_Item *it, Eina_Bool separator)
1629 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1630 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1631 Evas_Object *obj = WIDGET(item);
1632 Widget_Data *wd = elm_widget_data_get(obj);
1634 if (item->separator == separator) return;
1635 item->separator = separator;
1636 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1637 _theme_hook_item(obj, item, scale, wd->icon_size);
1641 elm_toolbar_item_separator_get(const Elm_Object_Item *it)
1643 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1644 return ((Elm_Toolbar_Item *)it)->separator;
1648 elm_toolbar_shrink_mode_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1650 ELM_CHECK_WIDTYPE(obj, widtype);
1651 Widget_Data *wd = elm_widget_data_get(obj);
1655 wd->shrink_mode = shrink_mode;
1656 bounce = (_elm_config->thumbscroll_bounce_enable) &&
1657 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1658 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1662 _item_del(wd->more_item);
1663 elm_widget_item_free(wd->more_item);
1664 wd->more_item = NULL;
1667 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1669 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1670 ELM_SMART_SCROLLER_POLICY_OFF);
1671 wd->more_item = _item_new(obj, "more_menu", "More", NULL, NULL);
1673 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1674 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1675 ELM_SMART_SCROLLER_POLICY_OFF);
1677 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1678 ELM_SMART_SCROLLER_POLICY_OFF);
1682 EAPI Elm_Toolbar_Shrink_Mode
1683 elm_toolbar_shrink_mode_get(const Evas_Object *obj)
1685 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1686 Widget_Data *wd = elm_widget_data_get(obj);
1688 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1689 return wd->shrink_mode;
1693 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
1695 ELM_CHECK_WIDTYPE(obj, widtype);
1696 Widget_Data *wd = elm_widget_data_get(obj);
1699 wd->homogeneous = !!homogeneous;
1700 evas_object_smart_calculate(wd->bx);
1704 elm_toolbar_homogeneous_get(const Evas_Object *obj)
1706 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1707 Widget_Data *wd = elm_widget_data_get(obj);
1709 if (!wd) return EINA_FALSE;
1710 return wd->homogeneous;
1714 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1716 Elm_Toolbar_Item *it;
1717 ELM_CHECK_WIDTYPE(obj, widtype);
1718 Widget_Data *wd = elm_widget_data_get(obj);
1721 EINA_SAFETY_ON_NULL_RETURN(parent);
1722 wd->menu_parent = parent;
1723 EINA_INLIST_FOREACH(wd->items, it)
1726 elm_menu_parent_set(it->o_menu, wd->menu_parent);
1728 if ((wd->more_item) && (wd->more_item->o_menu))
1729 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1733 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1735 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1736 Widget_Data *wd = elm_widget_data_get(obj);
1738 if (!wd) return NULL;
1739 return wd->menu_parent;
1743 elm_toolbar_align_set(Evas_Object *obj, double align)
1745 ELM_CHECK_WIDTYPE(obj, widtype);
1746 Widget_Data *wd = elm_widget_data_get(obj);
1751 if (wd->align != align)
1752 evas_object_size_hint_align_set(wd->bx, 0.5, align);
1756 if (wd->align != align)
1757 evas_object_size_hint_align_set(wd->bx, align, 0.5);
1763 elm_toolbar_align_get(const Evas_Object *obj)
1765 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1766 Widget_Data *wd = elm_widget_data_get(obj);
1768 if (!wd) return 0.0;
1773 elm_toolbar_item_menu_set(Elm_Object_Item *it, Eina_Bool menu)
1775 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1776 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1777 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1780 if (item->menu == menu) return;
1781 if (menu) _item_menu_create(wd, item);
1782 else _item_menu_destroy(item);
1786 elm_toolbar_item_menu_get(const Elm_Object_Item *it)
1788 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1789 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1790 if (!item->menu) return NULL;
1791 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1792 if (!wd) return NULL;
1793 return item->o_menu;
1796 EAPI Elm_Toolbar_Item_State *
1797 elm_toolbar_item_state_add(Elm_Object_Item *it, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1799 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1801 Elm_Toolbar_Item_State *it_state;
1802 Evas_Object *icon_obj;
1805 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1807 wd = elm_widget_data_get(WIDGET(item));
1808 if (!wd) return NULL;
1812 it_state = _item_state_new(item->label, item->icon_str, item->icon,
1813 item->func, item->base.data);
1814 item->states = eina_list_append(item->states, it_state);
1815 item->current_state = item->states;
1818 icon_obj = elm_icon_add(obj);
1819 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1820 if (!icon_obj) goto error_state_add;
1822 if (!_item_icon_set(icon_obj, "toolbar/", icon))
1824 evas_object_del(icon_obj);
1829 it_state = _item_state_new(label, icon, icon_obj, func, data);
1830 item->states = eina_list_append(item->states, it_state);
1831 item->func = _elm_toolbar_item_state_cb;
1832 item->base.data = NULL;
1837 if (item->states && !eina_list_next(item->states))
1839 eina_stringshare_del(item->label);
1840 eina_stringshare_del(item->icon_str);
1841 free(eina_list_data_get(item->states));
1842 eina_list_free(item->states);
1843 item->states = NULL;
1849 elm_toolbar_item_state_del(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1851 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1853 Eina_List *del_state;
1854 Elm_Toolbar_Item_State *it_state;
1855 Elm_Toolbar_Item *item;
1857 if (!state) return EINA_FALSE;
1859 item = (Elm_Toolbar_Item *)it;
1860 if (!item->states) return EINA_FALSE;
1862 del_state = eina_list_data_find_list(item->states, state);
1863 if (del_state == item->states) return EINA_FALSE;
1864 if (del_state == item->current_state)
1865 elm_toolbar_item_state_unset(it);
1867 eina_stringshare_del(state->label);
1868 eina_stringshare_del(state->icon_str);
1869 if (state->icon) evas_object_del(state->icon);
1871 item->states = eina_list_remove_list(item->states, del_state);
1872 if (item->states && !eina_list_next(item->states))
1874 it_state = eina_list_data_get(item->states);
1875 item->base.data = it_state->data;
1876 item->func = it_state->func;
1877 eina_stringshare_del(it_state->label);
1878 eina_stringshare_del(it_state->icon_str);
1879 free(eina_list_data_get(item->states));
1880 eina_list_free(item->states);
1881 item->states = NULL;
1887 elm_toolbar_item_state_set(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1889 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1892 Eina_List *next_state;
1893 Elm_Toolbar_Item_State *it_state;
1895 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1898 wd = elm_widget_data_get(obj);
1899 if (!wd) return EINA_FALSE;
1900 if (!item->states) return EINA_FALSE;
1904 next_state = eina_list_data_find_list(item->states, state);
1905 if (!next_state) return EINA_FALSE;
1908 next_state = item->states;
1910 if (next_state == item->current_state) return EINA_TRUE;
1912 it_state = eina_list_data_get(next_state);
1913 if (eina_list_data_find(item->current_state, state))
1915 _item_label_set(item, it_state->label, "elm,state,label_set,forward");
1916 _elm_toolbar_item_icon_obj_set(obj, item, it_state->icon, it_state->icon_str,
1917 wd->icon_size, "elm,state,icon_set,forward");
1921 _item_label_set(item, it_state->label, "elm,state,label_set,backward");
1922 _elm_toolbar_item_icon_obj_set(obj,
1927 "elm,state,icon_set,backward");
1929 if (elm_widget_item_disabled_get(item))
1930 elm_widget_signal_emit(item->icon, "elm,state,disabled", "elm");
1932 elm_widget_signal_emit(item->icon, "elm,state,enabled", "elm");
1934 item->current_state = next_state;
1939 elm_toolbar_item_state_unset(Elm_Object_Item *it)
1941 elm_toolbar_item_state_set(it, NULL);
1944 EAPI Elm_Toolbar_Item_State *
1945 elm_toolbar_item_state_get(const Elm_Object_Item *it)
1947 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1948 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1950 if ((!item->states) || (!item->current_state)) return NULL;
1951 if (item->current_state == item->states) return NULL;
1953 return eina_list_data_get(item->current_state);
1956 EAPI Elm_Toolbar_Item_State *
1957 elm_toolbar_item_state_next(Elm_Object_Item *it)
1959 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1963 Eina_List *next_state;
1964 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1967 wd = elm_widget_data_get(obj);
1968 if (!wd) return NULL;
1969 if (!item->states) return NULL;
1971 next_state = eina_list_next(item->current_state);
1973 next_state = eina_list_next(item->states);
1974 return eina_list_data_get(next_state);
1977 EAPI Elm_Toolbar_Item_State *
1978 elm_toolbar_item_state_prev(Elm_Object_Item *it)
1980 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1984 Eina_List *prev_state;
1985 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1988 wd = elm_widget_data_get(obj);
1989 if (!wd) return NULL;
1990 if (!item->states) return NULL;
1992 prev_state = eina_list_prev(item->current_state);
1993 if ((!prev_state) || (prev_state == item->states))
1994 prev_state = eina_list_last(item->states);
1995 return eina_list_data_get(prev_state);
1999 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
2001 ELM_CHECK_WIDTYPE(obj, widtype);
2002 Elm_Toolbar_Item *it;
2003 Widget_Data *wd = elm_widget_data_get(obj);
2006 wd->lookup_order = order;
2007 EINA_INLIST_FOREACH(wd->items, it)
2008 elm_icon_order_lookup_set(it->icon, order);
2010 elm_icon_order_lookup_set(wd->more_item->icon, order);
2013 EAPI Elm_Icon_Lookup_Order
2014 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
2016 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
2017 Widget_Data *wd = elm_widget_data_get(obj);
2018 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
2019 return wd->lookup_order;
2023 elm_toolbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
2025 ELM_CHECK_WIDTYPE(obj, widtype);
2026 Widget_Data *wd = elm_widget_data_get(obj);
2028 wd->vertical = !horizontal;
2030 evas_object_size_hint_align_set(wd->bx, 0.5, wd->align);
2032 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
2037 elm_toolbar_horizontal_get(const Evas_Object *obj)
2039 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2040 Widget_Data *wd = elm_widget_data_get(obj);
2041 if (!wd) return EINA_FALSE;
2042 return !wd->vertical;
2046 elm_toolbar_items_count(const Evas_Object *obj)
2048 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2049 Widget_Data *wd = elm_widget_data_get(obj);
2051 return wd->item_count;
2055 elm_toolbar_select_mode_set(Evas_Object *obj, Elm_Object_Select_Mode mode)
2057 ELM_CHECK_WIDTYPE(obj, widtype);
2058 Widget_Data *wd = elm_widget_data_get(obj);
2060 if (mode >= ELM_OBJECT_SELECT_MODE_MAX)
2062 if ((mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2063 (wd->select_mode != ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2065 _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
2066 if (wd->select_mode != mode)
2067 wd->select_mode = mode;
2070 EAPI Elm_Object_Select_Mode
2071 elm_toolbar_select_mode_get(const Evas_Object *obj)
2073 ELM_CHECK_WIDTYPE(obj, widtype) ELM_OBJECT_SELECT_MODE_MAX;
2074 Widget_Data *wd = elm_widget_data_get(obj);
2075 if (!wd) return ELM_OBJECT_SELECT_MODE_MAX;
2076 return wd->select_mode;