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)
428 if (part && strcmp(part, "object")) return;
429 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
430 Evas_Object *obj = WIDGET(item);
431 Widget_Data *wd = elm_widget_data_get(obj);
432 if (!wd || !obj) return;
433 if (item->object == content) return;
435 if (item->object) evas_object_del(item->object);
437 item->object = content;
439 elm_widget_sub_object_add(obj, item->object);
440 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
441 _theme_hook_item(obj, item, scale, wd->icon_size);
445 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
447 if (part && strcmp(part, "object")) return NULL;
448 return ((Elm_Toolbar_Item *) it)->object;
452 _item_content_unset_hook(Elm_Object_Item *it, const char *part)
457 if (part && strcmp(part, "object")) return NULL;
458 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
459 Evas_Object *obj = WIDGET(item);
460 Widget_Data *wd = elm_widget_data_get(obj);
462 edje_object_part_unswallow(VIEW(it), item->object);
463 elm_widget_sub_object_del(obj, item->object);
466 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
467 _theme_hook_item(obj, item, scale, wd->icon_size);
472 _translate_hook(Evas_Object *obj)
474 evas_object_smart_callback_call(obj, "language,changed", NULL);
478 _sizing_eval(Evas_Object *obj)
480 Widget_Data *wd = elm_widget_data_get(obj);
481 Evas_Coord minw = -1, minh = -1, minw_bx = -1, minh_bx = -1;
482 Evas_Coord vw = 0, vh = 0;
486 evas_object_smart_need_recalculate_set(wd->bx, EINA_TRUE);
487 evas_object_smart_calculate(wd->bx);
488 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
490 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
491 if (w < minw) w = minw;
492 if (h < minh) h = minh;
493 evas_object_resize(wd->scr, w, h);
495 evas_object_size_hint_min_get(wd->bx, &minw_bx, &minh_bx);
496 // if (wd->vertical && (h > minh)) minh = h;
497 // if ((!wd->vertical) && (w > minw)) minw = w;
498 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
499 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_NONE)
503 minw = minw_bx + (w - vw);
504 minh = minh_bx + (h - vh);
508 minw = minw_bx + (w - vw);
509 minh = minh_bx + (h - vh);
512 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
514 minw = minw_bx + (w - vw);
515 minh = minh_bx + (h - vh);
516 if (minw_bx < vw) minw_bx = vw;
517 if (minh_bx < vh) minh_bx = vh;
523 minw = minw_bx + (w - vw);
529 minh = minh_bx + (h - vh);
531 // if (wd->vertical) minh = h - vh;
532 // else minw = w - vw;
533 // minh = minh + (h - vh);
535 evas_object_resize(wd->bx, minw_bx, minh_bx);
536 evas_object_size_hint_min_set(obj, minw, minh);
537 evas_object_size_hint_max_set(obj, -1, -1);
541 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
543 item->o_menu = elm_menu_add(VIEW(item));
544 item->menu = EINA_TRUE;
546 elm_menu_parent_set(item->o_menu, wd->menu_parent);
547 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
549 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
554 _item_menu_destroy(Elm_Toolbar_Item *item)
558 evas_object_del(item->o_menu);
561 item->menu = EINA_FALSE;
565 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
567 const Elm_Toolbar_Item *eti1 = i1;
568 const Elm_Toolbar_Item *eti2 = i2;
571 if (!eti1) return -1;
573 return eti2->prio.priority - eti1->prio.priority;
577 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
579 Elm_Toolbar_Item *it;
580 Eina_List *sorted = NULL;
581 Evas_Coord ciw = 0, cih = 0;
583 EINA_INLIST_FOREACH(wd->items, it)
585 sorted = eina_list_sorted_insert(sorted,
586 _toolbar_item_prio_compare_cb, it);
591 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL, &ciw, &cih);
592 if (wd->vertical) *iw += cih;
595 EINA_LIST_FREE(sorted, it)
597 evas_object_geometry_get(VIEW(it), NULL, NULL, &ciw, &cih);
598 if (wd->vertical) *iw += cih;
600 it->prio.visible = (*iw <= vw);
605 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
607 Elm_Toolbar_Item *it = data;
608 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
612 _resize_job(void *data)
614 Evas_Object *obj = (Evas_Object *)data;
615 Widget_Data *wd = elm_widget_data_get(obj);
616 Evas_Coord mw, mh, vw = 0, vh = 0, w = 0, h = 0;
617 Elm_Toolbar_Item *it;
620 wd->resize_job = NULL;
621 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
622 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
623 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
624 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
626 Evas_Coord iw = 0, ih = 0, more_w = 0, more_h = 0;
630 evas_object_resize(wd->bx, w, vh);
631 _fix_items_visibility(wd, &ih, vh);
635 evas_object_resize(wd->bx, vw, h);
636 _fix_items_visibility(wd, &iw, vw);
638 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL,
642 if ((ih - more_h) <= vh) ih -= more_h;
646 if ((iw - more_w) <= vw) iw -= more_w;
649 /* All items are removed from the box object, since removing individual
650 * items won't trigger a resize. Items are be readded below. */
651 evas_object_box_remove_all(wd->bx, EINA_FALSE);
652 if (((wd->vertical) && (ih > vh)) ||
653 ((!wd->vertical) && (iw > vw)))
657 _item_menu_destroy(wd->more_item);
658 _item_menu_create(wd, wd->more_item);
659 menu = elm_toolbar_item_menu_get((Elm_Object_Item *)wd->more_item);
660 EINA_INLIST_FOREACH(wd->items, it)
662 if (!it->prio.visible)
665 elm_menu_item_separator_add(menu, NULL);
668 Elm_Object_Item *menu_it;
669 menu_it = elm_menu_item_add
670 (menu, NULL, it->icon_str, it->label,
671 _elm_toolbar_item_menu_cb, it);
672 elm_object_item_disabled_set
673 (menu_it, elm_widget_item_disabled_get(it));
675 elm_menu_clone(it->o_menu, menu, menu_it);
677 evas_object_hide(VIEW(it));
681 evas_object_box_append(wd->bx, VIEW(it));
682 evas_object_show(VIEW(it));
685 evas_object_box_append(wd->bx, wd->VIEW(more_item));
686 evas_object_show(wd->VIEW(more_item));
690 /* All items are visible, show them all (except for the "More"
691 * button, of course). */
692 EINA_INLIST_FOREACH(wd->items, it)
694 evas_object_show(VIEW(it));
695 evas_object_box_append(wd->bx, VIEW(it));
697 evas_object_hide(wd->VIEW(more_item));
700 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
702 Evas_Coord iw = 0, ih = 0;
706 evas_object_resize(wd->bx, w, vh);
707 _fix_items_visibility(wd, &ih, vh);
711 evas_object_resize(wd->bx, vw, h);
712 _fix_items_visibility(wd, &iw, vw);
714 evas_object_box_remove_all(wd->bx, EINA_FALSE);
715 if (((wd->vertical) && (ih > vh)) ||
716 ((!wd->vertical) && (iw > vw)))
718 EINA_INLIST_FOREACH(wd->items, it)
720 if (!it->prio.visible)
721 evas_object_hide(VIEW(it));
724 evas_object_box_append(wd->bx, VIEW(it));
725 evas_object_show(VIEW(it));
731 /* All items are visible, show them all */
732 EINA_INLIST_FOREACH(wd->items, it)
734 evas_object_show(VIEW(it));
735 evas_object_box_append(wd->bx, VIEW(it));
739 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
741 if ((vw >= mw) && (vh >= mh))
742 evas_object_resize(wd->bx, vw, vh);
744 evas_object_resize(wd->bx, mw, vh);
746 evas_object_resize(wd->bx, vw, mh);
752 if ((vh >= mh) && (h != vh)) evas_object_resize(wd->bx, w, vh);
756 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
758 EINA_INLIST_FOREACH(wd->items, it)
768 _mirrored_set(obj, elm_widget_mirrored_get(obj));
772 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
775 _resize(data, NULL, NULL, NULL);
779 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
781 Widget_Data *wd = elm_widget_data_get(data);
783 wd->resize_job = ecore_job_add(_resize_job, data);
787 _select_filter(Elm_Toolbar_Item *it, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
790 char buf[sizeof("elm,action,click,") + 1];
792 button = atoi(emission + sizeof("mouse,clicked,") - 1);
793 if (button == 1) return; /* regular left click event */
794 snprintf(buf, sizeof(buf), "elm,action,click,%d", button);
795 edje_object_signal_emit(VIEW(it), buf, "elm");
799 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
801 Elm_Toolbar_Item *it = data;
803 if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
804 (_elm_access_2nd_click_timeout(VIEW(it))))
806 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
807 _elm_access_say(E_("Selected"));
813 _long_press(Elm_Toolbar_Item *it)
815 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
816 wd->long_timer = NULL;
817 wd->long_press = EINA_TRUE;
818 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
819 return ECORE_CALLBACK_CANCEL;
823 _mouse_down(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Down *ev)
825 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
827 if (ev->button != 1) return;
828 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
829 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
830 wd->long_press = EINA_FALSE;
831 if (wd->long_timer) ecore_timer_interval_set(wd->long_timer, _elm_config->longpress_timeout);
832 else wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, (Ecore_Task_Cb)_long_press, it);
836 _mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
838 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
840 if (ev->button != 1) return;
843 ecore_timer_del(wd->long_timer);
844 wd->long_timer = NULL;
849 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
851 Elm_Toolbar_Item *it = data;
852 edje_object_signal_emit(VIEW(it), "elm,state,highlighted", "elm");
853 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
857 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
859 Elm_Toolbar_Item *it = data;
860 edje_object_signal_emit(VIEW(it), "elm,state,unhighlighted", "elm");
861 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
865 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
867 Evas_Object *obj = (Evas_Object *) data;
868 Widget_Data *wd = elm_widget_data_get(obj);
870 _els_box_layout(o, priv, !wd->vertical, wd->homogeneous,
871 elm_widget_mirrored_get(obj));
875 _access_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item)
877 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
878 const char *txt = item->access_info;
879 if (!txt) txt = it->label;
880 if (txt) return strdup(txt);
885 _access_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
887 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
889 return strdup(E_("Separator"));
890 else if (elm_widget_item_disabled_get(it))
891 return strdup(E_("State: Disabled"));
892 else if (it->selected)
893 return strdup(E_("State: Selected"));
895 return strdup(E_("Has menu"));
900 _item_del_pre_hook(Elm_Object_Item *it)
904 Elm_Toolbar_Item *item, *next;
905 item = (Elm_Toolbar_Item *)it;
907 wd = elm_widget_data_get(WIDGET(item));
908 if (!wd) return EINA_FALSE;
911 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
912 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
914 if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
915 if ((wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
916 item->selected && next) _item_select(next);
923 static Elm_Toolbar_Item *
924 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
926 Widget_Data *wd = elm_widget_data_get(obj);
927 Evas_Object *icon_obj;
929 Elm_Toolbar_Item *it;
931 icon_obj = elm_icon_add(obj);
932 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
933 if (!icon_obj) return NULL;
934 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
937 evas_object_del(icon_obj);
941 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
942 elm_widget_item_disable_hook_set(it, _item_disable_hook);
943 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
944 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
945 elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
946 elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
947 elm_widget_item_content_unset_hook_set(it, _item_content_unset_hook);
949 it->label = eina_stringshare_add(label);
950 it->prio.visible = 1;
951 it->prio.priority = 0;
953 it->separator = EINA_FALSE;
955 it->base.data = data;
956 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
957 _elm_access_item_register(&it->base, VIEW(it));
958 _elm_access_text_set(_elm_access_item_get(&it->base),
959 ELM_ACCESS_TYPE, E_("Tool Item"));
960 _elm_access_callback_set(_elm_access_item_get(&it->base),
961 ELM_ACCESS_INFO, _access_info_cb, it);
962 _elm_access_callback_set(_elm_access_item_get(&it->base),
963 ELM_ACCESS_STATE, _access_state_cb, it);
965 if (_item_icon_set(icon_obj, "toolbar/", icon))
968 it->icon_str = eina_stringshare_add(icon);
974 evas_object_del(icon_obj);
977 _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
978 elm_widget_style_get(obj));
979 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "elm",
981 edje_object_signal_callback_add(VIEW(it), "mouse,clicked,*", "*",
982 (Edje_Signal_Cb)_select_filter, it);
983 edje_object_signal_callback_add(VIEW(it), "elm,mouse,in", "elm",
985 edje_object_signal_callback_add(VIEW(it), "elm,mouse,out", "elm",
987 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
988 (Evas_Object_Event_Cb)_mouse_down, it);
989 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
990 (Evas_Object_Event_Cb)_mouse_up, it);
991 elm_widget_sub_object_add(obj, VIEW(it));
996 ms = ((double)wd->icon_size * _elm_config->scale);
997 evas_object_size_hint_min_set(it->icon, ms, ms);
998 evas_object_size_hint_max_set(it->icon, ms, ms);
999 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
1000 evas_object_show(it->icon);
1001 elm_widget_sub_object_add(obj, it->icon);
1003 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
1005 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1006 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
1007 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1008 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1012 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, -1.0);
1013 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, 0.5);
1017 evas_object_size_hint_weight_set(VIEW(it), -1.0, EVAS_HINT_EXPAND);
1018 evas_object_size_hint_align_set(VIEW(it), 0.5, EVAS_HINT_FILL);
1023 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1024 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, EVAS_HINT_FILL);
1026 evas_object_size_hint_min_set(VIEW(it), mw, mh);
1027 evas_object_size_hint_max_set(VIEW(it), -1, -1);
1028 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
1030 if ((!wd->items) && (wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS))
1037 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
1039 Evas_Coord mw = -1, mh = -1;
1040 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1041 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
1043 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1044 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1045 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1046 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1050 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1051 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1055 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1056 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1061 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1062 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1064 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1068 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1070 Elm_Toolbar_Item *item = data;
1071 _elm_toolbar_item_label_update(item);
1072 edje_object_signal_callback_del(obj, emission, source,
1073 _elm_toolbar_item_label_set_cb);
1074 edje_object_signal_emit (VIEW(item), "elm,state,label,reset", "elm");
1078 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *sig)
1082 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
1084 eina_stringshare_replace(&item->label, label);
1085 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1086 if ((s) && (atoi(s)))
1088 edje_object_part_text_set(VIEW(item), "elm.text_new", item->label);
1089 edje_object_signal_emit (VIEW(item), sig, "elm");
1090 edje_object_signal_callback_add(VIEW(item),
1091 "elm,state,label_set,done", "elm",
1092 _elm_toolbar_item_label_set_cb, item);
1095 _elm_toolbar_item_label_update(item);
1096 _resize(WIDGET(item), NULL, NULL, NULL);
1100 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
1102 Elm_Toolbar_Item_State *it_state;
1104 Evas_Coord mw = -1, mh = -1;
1105 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1106 Evas_Object *old_icon = edje_object_part_swallow_get(VIEW(item),
1107 "elm.swallow.icon");
1108 elm_widget_sub_object_del(VIEW(item), old_icon);
1109 evas_object_hide(old_icon);
1110 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1111 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1112 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1113 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1114 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1118 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1119 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1123 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1124 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1129 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1130 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1132 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1134 EINA_LIST_FOREACH(item->states, l, it_state)
1136 if (it_state->icon == old_icon) return;
1138 evas_object_del(old_icon);
1142 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1144 Elm_Toolbar_Item *item = data;
1145 edje_object_part_unswallow(VIEW(item), item->icon);
1146 _elm_toolbar_item_icon_update(item);
1147 edje_object_signal_callback_del(obj, emission, source,
1148 _elm_toolbar_item_icon_set_cb);
1149 edje_object_signal_emit (VIEW(item), "elm,state,icon,reset", "elm");
1153 _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)
1155 Evas_Object *old_icon;
1160 eina_stringshare_replace(&item->icon_str, icon_str);
1163 eina_stringshare_del(item->icon_str);
1164 item->icon_str = NULL;
1166 item->icon = icon_obj;
1169 ms = (icon_size * _elm_config->scale);
1170 evas_object_size_hint_min_set(item->icon, ms, ms);
1171 evas_object_size_hint_max_set(item->icon, ms, ms);
1172 evas_object_show(item->icon);
1173 elm_widget_sub_object_add(obj, item->icon);
1175 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1176 if ((s) && (atoi(s)))
1178 old_icon = edje_object_part_swallow_get(VIEW(item),
1179 "elm.swallow.icon_new");
1182 elm_widget_sub_object_del(VIEW(item), old_icon);
1183 evas_object_hide(old_icon);
1185 edje_object_part_swallow(VIEW(item), "elm.swallow.icon_new",
1187 edje_object_signal_emit (VIEW(item), sig, "elm");
1188 edje_object_signal_callback_add(VIEW(item),
1189 "elm,state,icon_set,done", "elm",
1190 _elm_toolbar_item_icon_set_cb, item);
1193 _elm_toolbar_item_icon_update(item);
1194 _resize(obj, NULL, NULL, NULL);
1198 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1200 Elm_Toolbar_Item *it = event_info;
1201 Elm_Toolbar_Item_State *it_state;
1203 it_state = eina_list_data_get(it->current_state);
1205 it_state->func((void *)it_state->data, obj, event_info);
1208 static Elm_Toolbar_Item_State *
1209 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1211 Elm_Toolbar_Item_State *it_state;
1212 it_state = ELM_NEW(Elm_Toolbar_Item_State);
1213 it_state->label = eina_stringshare_add(label);
1214 it_state->icon_str = eina_stringshare_add(icon_str);
1215 it_state->icon = icon;
1216 it_state->func = func;
1217 it_state->data = data;
1222 elm_toolbar_add(Evas_Object *parent)
1228 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1230 ELM_SET_WIDTYPE(widtype, "toolbar");
1231 elm_widget_type_set(obj, "toolbar");
1232 elm_widget_sub_object_add(parent, obj);
1233 elm_widget_data_set(obj, wd);
1234 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1235 elm_widget_del_hook_set(obj, _del_hook);
1236 elm_widget_theme_hook_set(obj, _theme_hook);
1237 elm_widget_translate_hook_set(obj, _translate_hook);
1238 elm_widget_can_focus_set(obj, EINA_TRUE);
1240 wd->more_item = NULL;
1241 wd->selected_item = NULL;
1242 wd->scr = elm_smart_scroller_add(e);
1243 elm_smart_scroller_widget_set(wd->scr, obj);
1244 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
1245 elm_smart_scroller_bounce_allow_set(wd->scr,
1246 _elm_config->thumbscroll_bounce_enable,
1248 elm_widget_resize_object_set(obj, wd->scr);
1249 elm_smart_scroller_policy_set(wd->scr,
1250 ELM_SMART_SCROLLER_POLICY_AUTO,
1251 ELM_SMART_SCROLLER_POLICY_OFF);
1254 wd->icon_size = _elm_toolbar_icon_size_get(wd);
1257 wd->homogeneous = EINA_TRUE;
1260 wd->bx = evas_object_box_add(e);
1261 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
1262 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
1263 elm_widget_sub_object_add(obj, wd->bx);
1264 elm_smart_scroller_child_set(wd->scr, wd->bx);
1265 evas_object_show(wd->bx);
1267 elm_toolbar_shrink_mode_set(obj, _elm_config->toolbar_shrink_mode);
1268 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
1269 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
1270 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
1272 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1279 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
1281 ELM_CHECK_WIDTYPE(obj, widtype);
1282 Widget_Data *wd = elm_widget_data_get(obj);
1284 if (wd->icon_size == icon_size) return;
1285 wd->icon_size = icon_size;
1290 elm_toolbar_icon_size_get(const Evas_Object *obj)
1292 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1293 Widget_Data *wd = elm_widget_data_get(obj);
1295 return wd->icon_size;
1298 EAPI Elm_Object_Item *
1299 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1301 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1302 Widget_Data *wd = elm_widget_data_get(obj);
1303 if (!wd) return NULL;
1305 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1306 if (!it) return NULL;
1307 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1309 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
1310 evas_object_box_append(wd->bx, VIEW(it));
1311 evas_object_show(VIEW(it));
1313 _theme_hook_item(obj, it, scale, wd->icon_size);
1316 return (Elm_Object_Item *)it;
1319 EAPI Elm_Object_Item *
1320 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1322 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1323 Widget_Data *wd = elm_widget_data_get(obj);
1324 if (!wd) return NULL;
1326 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1327 if (!it) return NULL;
1328 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1330 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1331 evas_object_box_prepend(wd->bx, VIEW(it));
1332 evas_object_show(VIEW(it));
1333 _theme_hook_item(obj, it, scale, wd->icon_size);
1336 return (Elm_Object_Item *)it;
1339 EAPI Elm_Object_Item *
1340 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)
1342 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1343 ELM_OBJ_ITEM_CHECK_OR_RETURN(before, NULL);
1345 Elm_Toolbar_Item *it, *_before;
1347 wd = elm_widget_data_get(obj);
1348 if (!wd) return NULL;
1349 _before = (Elm_Toolbar_Item *) before;
1350 it = _item_new(obj, icon, label, func, data);
1351 if (!it) return NULL;
1352 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1354 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1355 EINA_INLIST_GET(_before));
1356 evas_object_box_insert_before(wd->bx, VIEW(it), VIEW(_before));
1357 evas_object_show(VIEW(it));
1358 _theme_hook_item(obj, it, scale, wd->icon_size);
1361 return (Elm_Object_Item *)it;
1364 EAPI Elm_Object_Item *
1365 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)
1367 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1368 ELM_OBJ_ITEM_CHECK_OR_RETURN(after, NULL);
1370 Elm_Toolbar_Item *it, *_after;
1372 wd = elm_widget_data_get(obj);
1373 if (!wd) return NULL;
1374 _after = (Elm_Toolbar_Item *) after;
1375 it = _item_new(obj, icon, label, func, data);
1376 if (!it) return NULL;
1377 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1379 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1380 EINA_INLIST_GET(_after));
1381 evas_object_box_insert_after(wd->bx, VIEW(it), VIEW(_after));
1382 evas_object_show(VIEW(it));
1383 _theme_hook_item(obj, it, scale, wd->icon_size);
1386 return (Elm_Object_Item *)it;
1389 EAPI Elm_Object_Item *
1390 elm_toolbar_first_item_get(const Evas_Object *obj)
1392 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1393 Widget_Data *wd = elm_widget_data_get(obj);
1394 if (!wd || !wd->items) return NULL;
1395 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1398 EAPI Elm_Object_Item *
1399 elm_toolbar_last_item_get(const Evas_Object *obj)
1401 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1402 Widget_Data *wd = elm_widget_data_get(obj);
1403 if (!wd || !wd->items) return NULL;
1404 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1407 EAPI Elm_Object_Item *
1408 elm_toolbar_item_next_get(const Elm_Object_Item *it)
1410 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1411 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1412 EINA_INLIST_GET(((Elm_Toolbar_Item *)it))->next);
1415 EAPI Elm_Object_Item *
1416 elm_toolbar_item_prev_get(const Elm_Object_Item *it)
1418 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1419 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1420 EINA_INLIST_GET(((Elm_Toolbar_Item *)it))->prev);
1424 elm_toolbar_item_priority_set(Elm_Object_Item *it, int priority)
1426 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1427 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1428 if (item->prio.priority == priority) return;
1429 item->prio.priority = priority;
1430 _resize(WIDGET(item), NULL, NULL, NULL);
1434 elm_toolbar_item_priority_get(const Elm_Object_Item *it)
1436 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
1437 return ((Elm_Toolbar_Item *)it)->prio.priority;
1440 EAPI Elm_Object_Item *
1441 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
1443 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1444 Elm_Toolbar_Item *it;
1445 Widget_Data *wd = elm_widget_data_get(obj);
1446 if (!wd) return NULL;
1448 EINA_INLIST_FOREACH(wd->items, it)
1450 if (!strcmp(it->label, label))
1451 return (Elm_Object_Item *)it;
1457 elm_toolbar_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1459 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1460 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1461 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1464 if (item->selected == selected) return;
1465 if (selected) _item_select(item);
1466 else _item_unselect(item);
1470 elm_toolbar_item_selected_get(const Elm_Object_Item *it)
1472 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1473 return ((Elm_Toolbar_Item *)it)->selected;
1476 EAPI Elm_Object_Item *
1477 elm_toolbar_selected_item_get(const Evas_Object *obj)
1479 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1480 Widget_Data *wd = elm_widget_data_get(obj);
1481 if (!wd) return NULL;
1482 return (Elm_Object_Item *) wd->selected_item;
1486 elm_toolbar_item_icon_set(Elm_Object_Item *it, const char *icon)
1488 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1490 Evas_Object *icon_obj;
1493 Elm_Toolbar_Item * item = (Elm_Toolbar_Item *)it;
1496 wd = elm_widget_data_get(obj);
1498 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1500 icon_obj = elm_icon_add(obj);
1501 if (!icon_obj) return;
1502 if (_item_icon_set(icon_obj, "toolbar/", icon))
1503 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1504 "elm,state,icon_set");
1507 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1508 "elm,state,icon_set");
1509 evas_object_del(icon_obj);
1514 elm_toolbar_item_icon_get(const Elm_Object_Item *it)
1516 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1517 return ((Elm_Toolbar_Item *)it)->icon_str;
1521 elm_toolbar_item_object_get(const Elm_Object_Item *it)
1523 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1527 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1530 wd = elm_widget_data_get(obj);
1531 if (!wd) return NULL;
1537 elm_toolbar_item_icon_object_get(Elm_Object_Item *it)
1539 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1540 return ((Elm_Toolbar_Item *)it)->icon;
1544 elm_toolbar_item_icon_memfile_set(Elm_Object_Item *it, const void *img, size_t size, const char *format, const char *key)
1546 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1548 Evas_Object *icon_obj;
1552 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1555 wd = elm_widget_data_get(obj);
1556 if (!wd) return EINA_FALSE;
1560 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1561 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1562 ret = _els_smart_icon_memfile_set(icon_obj, img, size, format, key);
1565 evas_object_del(icon_obj);
1568 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1569 "elm,state,icon_set");
1572 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1577 elm_toolbar_item_icon_file_set(Elm_Object_Item *it, const char *file, const char *key)
1579 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1581 Evas_Object *icon_obj;
1585 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1588 wd = elm_widget_data_get(obj);
1589 if (!wd) return EINA_FALSE;
1593 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1594 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1595 ret = _els_smart_icon_file_key_set(icon_obj, file, key);
1598 evas_object_del(icon_obj);
1601 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1602 "elm,state,icon_set");
1605 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1610 elm_toolbar_item_separator_set(Elm_Object_Item *it, Eina_Bool separator)
1612 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1613 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1614 Evas_Object *obj = WIDGET(item);
1615 Widget_Data *wd = elm_widget_data_get(obj);
1617 if (item->separator == separator) return;
1618 item->separator = separator;
1619 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1620 _theme_hook_item(obj, item, scale, wd->icon_size);
1624 elm_toolbar_item_separator_get(const Elm_Object_Item *it)
1626 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1627 return ((Elm_Toolbar_Item *)it)->separator;
1631 elm_toolbar_shrink_mode_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1633 ELM_CHECK_WIDTYPE(obj, widtype);
1634 Widget_Data *wd = elm_widget_data_get(obj);
1638 wd->shrink_mode = shrink_mode;
1639 bounce = (_elm_config->thumbscroll_bounce_enable) &&
1640 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1641 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1645 _item_del(wd->more_item);
1646 elm_widget_item_free(wd->more_item);
1647 wd->more_item = NULL;
1650 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1652 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1653 ELM_SMART_SCROLLER_POLICY_OFF);
1654 wd->more_item = _item_new(obj, "more_menu", "More", NULL, NULL);
1656 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1657 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1658 ELM_SMART_SCROLLER_POLICY_OFF);
1660 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1661 ELM_SMART_SCROLLER_POLICY_OFF);
1665 EAPI Elm_Toolbar_Shrink_Mode
1666 elm_toolbar_shrink_mode_get(const Evas_Object *obj)
1668 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1669 Widget_Data *wd = elm_widget_data_get(obj);
1671 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1672 return wd->shrink_mode;
1676 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
1678 ELM_CHECK_WIDTYPE(obj, widtype);
1679 Widget_Data *wd = elm_widget_data_get(obj);
1682 wd->homogeneous = !!homogeneous;
1683 evas_object_smart_calculate(wd->bx);
1687 elm_toolbar_homogeneous_get(const Evas_Object *obj)
1689 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1690 Widget_Data *wd = elm_widget_data_get(obj);
1692 if (!wd) return EINA_FALSE;
1693 return wd->homogeneous;
1697 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1699 Elm_Toolbar_Item *it;
1700 ELM_CHECK_WIDTYPE(obj, widtype);
1701 Widget_Data *wd = elm_widget_data_get(obj);
1704 EINA_SAFETY_ON_NULL_RETURN(parent);
1705 wd->menu_parent = parent;
1706 EINA_INLIST_FOREACH(wd->items, it)
1709 elm_menu_parent_set(it->o_menu, wd->menu_parent);
1711 if ((wd->more_item) && (wd->more_item->o_menu))
1712 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1716 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1718 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1719 Widget_Data *wd = elm_widget_data_get(obj);
1721 if (!wd) return NULL;
1722 return wd->menu_parent;
1726 elm_toolbar_align_set(Evas_Object *obj, double align)
1728 ELM_CHECK_WIDTYPE(obj, widtype);
1729 Widget_Data *wd = elm_widget_data_get(obj);
1734 if (wd->align != align)
1735 evas_object_size_hint_align_set(wd->bx, 0.5, align);
1739 if (wd->align != align)
1740 evas_object_size_hint_align_set(wd->bx, align, 0.5);
1746 elm_toolbar_align_get(const Evas_Object *obj)
1748 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1749 Widget_Data *wd = elm_widget_data_get(obj);
1751 if (!wd) return 0.0;
1756 elm_toolbar_item_menu_set(Elm_Object_Item *it, Eina_Bool menu)
1758 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1759 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1760 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1763 if (item->menu == menu) return;
1764 if (menu) _item_menu_create(wd, item);
1765 else _item_menu_destroy(item);
1769 elm_toolbar_item_menu_get(const Elm_Object_Item *it)
1771 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1772 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1773 if (!item->menu) return NULL;
1774 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1775 if (!wd) return NULL;
1776 return item->o_menu;
1779 EAPI Elm_Toolbar_Item_State *
1780 elm_toolbar_item_state_add(Elm_Object_Item *it, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1782 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1784 Elm_Toolbar_Item_State *it_state;
1785 Evas_Object *icon_obj;
1788 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1790 wd = elm_widget_data_get(WIDGET(item));
1791 if (!wd) return NULL;
1795 it_state = _item_state_new(item->label, item->icon_str, item->icon,
1796 item->func, item->base.data);
1797 item->states = eina_list_append(item->states, it_state);
1798 item->current_state = item->states;
1801 icon_obj = elm_icon_add(obj);
1802 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1803 if (!icon_obj) goto error_state_add;
1805 if (!_item_icon_set(icon_obj, "toolbar/", icon))
1807 evas_object_del(icon_obj);
1812 it_state = _item_state_new(label, icon, icon_obj, func, data);
1813 item->states = eina_list_append(item->states, it_state);
1814 item->func = _elm_toolbar_item_state_cb;
1815 item->base.data = NULL;
1820 if (item->states && !eina_list_next(item->states))
1822 eina_stringshare_del(item->label);
1823 eina_stringshare_del(item->icon_str);
1824 free(eina_list_data_get(item->states));
1825 eina_list_free(item->states);
1826 item->states = NULL;
1832 elm_toolbar_item_state_del(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1834 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1836 Eina_List *del_state;
1837 Elm_Toolbar_Item_State *it_state;
1838 Elm_Toolbar_Item *item;
1840 if (!state) return EINA_FALSE;
1842 item = (Elm_Toolbar_Item *)it;
1843 if (!item->states) return EINA_FALSE;
1845 del_state = eina_list_data_find_list(item->states, state);
1846 if (del_state == item->states) return EINA_FALSE;
1847 if (del_state == item->current_state)
1848 elm_toolbar_item_state_unset(it);
1850 eina_stringshare_del(state->label);
1851 eina_stringshare_del(state->icon_str);
1852 if (state->icon) evas_object_del(state->icon);
1854 item->states = eina_list_remove_list(item->states, del_state);
1855 if (item->states && !eina_list_next(item->states))
1857 it_state = eina_list_data_get(item->states);
1858 item->base.data = it_state->data;
1859 item->func = it_state->func;
1860 eina_stringshare_del(it_state->label);
1861 eina_stringshare_del(it_state->icon_str);
1862 free(eina_list_data_get(item->states));
1863 eina_list_free(item->states);
1864 item->states = NULL;
1870 elm_toolbar_item_state_set(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1872 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1875 Eina_List *next_state;
1876 Elm_Toolbar_Item_State *it_state;
1878 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1881 wd = elm_widget_data_get(obj);
1882 if (!wd) return EINA_FALSE;
1883 if (!item->states) return EINA_FALSE;
1887 next_state = eina_list_data_find_list(item->states, state);
1888 if (!next_state) return EINA_FALSE;
1891 next_state = item->states;
1893 if (next_state == item->current_state) return EINA_TRUE;
1895 it_state = eina_list_data_get(next_state);
1896 if (eina_list_data_find(item->current_state, state))
1898 _item_label_set(item, it_state->label, "elm,state,label_set,forward");
1899 _elm_toolbar_item_icon_obj_set(obj, item, it_state->icon, it_state->icon_str,
1900 wd->icon_size, "elm,state,icon_set,forward");
1904 _item_label_set(item, it_state->label, "elm,state,label_set,backward");
1905 _elm_toolbar_item_icon_obj_set(obj,
1910 "elm,state,icon_set,backward");
1912 if (elm_widget_item_disabled_get(item))
1913 elm_widget_signal_emit(item->icon, "elm,state,disabled", "elm");
1915 elm_widget_signal_emit(item->icon, "elm,state,enabled", "elm");
1917 item->current_state = next_state;
1922 elm_toolbar_item_state_unset(Elm_Object_Item *it)
1924 elm_toolbar_item_state_set(it, NULL);
1927 EAPI Elm_Toolbar_Item_State *
1928 elm_toolbar_item_state_get(const Elm_Object_Item *it)
1930 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1931 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1933 if ((!item->states) || (!item->current_state)) return NULL;
1934 if (item->current_state == item->states) return NULL;
1936 return eina_list_data_get(item->current_state);
1939 EAPI Elm_Toolbar_Item_State *
1940 elm_toolbar_item_state_next(Elm_Object_Item *it)
1942 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1946 Eina_List *next_state;
1947 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1950 wd = elm_widget_data_get(obj);
1951 if (!wd) return NULL;
1952 if (!item->states) return NULL;
1954 next_state = eina_list_next(item->current_state);
1956 next_state = eina_list_next(item->states);
1957 return eina_list_data_get(next_state);
1960 EAPI Elm_Toolbar_Item_State *
1961 elm_toolbar_item_state_prev(Elm_Object_Item *it)
1963 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1967 Eina_List *prev_state;
1968 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1971 wd = elm_widget_data_get(obj);
1972 if (!wd) return NULL;
1973 if (!item->states) return NULL;
1975 prev_state = eina_list_prev(item->current_state);
1976 if ((!prev_state) || (prev_state == item->states))
1977 prev_state = eina_list_last(item->states);
1978 return eina_list_data_get(prev_state);
1982 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
1984 ELM_CHECK_WIDTYPE(obj, widtype);
1985 Elm_Toolbar_Item *it;
1986 Widget_Data *wd = elm_widget_data_get(obj);
1989 wd->lookup_order = order;
1990 EINA_INLIST_FOREACH(wd->items, it)
1991 elm_icon_order_lookup_set(it->icon, order);
1993 elm_icon_order_lookup_set(wd->more_item->icon, order);
1996 EAPI Elm_Icon_Lookup_Order
1997 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
1999 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
2000 Widget_Data *wd = elm_widget_data_get(obj);
2001 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
2002 return wd->lookup_order;
2006 elm_toolbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
2008 ELM_CHECK_WIDTYPE(obj, widtype);
2009 Widget_Data *wd = elm_widget_data_get(obj);
2011 wd->vertical = !horizontal;
2013 evas_object_size_hint_align_set(wd->bx, 0.5, wd->align);
2015 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
2020 elm_toolbar_horizontal_get(const Evas_Object *obj)
2022 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2023 Widget_Data *wd = elm_widget_data_get(obj);
2024 if (!wd) return EINA_FALSE;
2025 return !wd->vertical;
2029 elm_toolbar_items_count(const Evas_Object *obj)
2031 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2032 Widget_Data *wd = elm_widget_data_get(obj);
2034 return wd->item_count;
2038 elm_toolbar_select_mode_set(Evas_Object *obj, Elm_Object_Select_Mode mode)
2040 ELM_CHECK_WIDTYPE(obj, widtype);
2041 Widget_Data *wd = elm_widget_data_get(obj);
2043 if (mode >= ELM_OBJECT_SELECT_MODE_MAX)
2045 if ((mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2046 (wd->select_mode != ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2048 _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
2049 if (wd->select_mode != mode)
2050 wd->select_mode = mode;
2053 EAPI Elm_Object_Select_Mode
2054 elm_toolbar_select_mode_get(const Evas_Object *obj)
2056 ELM_CHECK_WIDTYPE(obj, widtype) ELM_OBJECT_SELECT_MODE_MAX;
2057 Widget_Data *wd = elm_widget_data_get(obj);
2058 if (!wd) return ELM_OBJECT_SELECT_MODE_MAX;
2059 return wd->select_mode;