1 #include <Elementary.h>
3 #include "els_scroller.h"
7 typedef struct _Widget_Data Widget_Data;
8 typedef struct _Elm_Toolbar_Item Elm_Toolbar_Item;
12 Evas_Object *scr, *bx;
13 Evas_Object *menu_parent;
15 Elm_Toolbar_Item *more_item, *selected_item;
16 Elm_Toolbar_Shrink_Mode shrink_mode;
17 Elm_Icon_Lookup_Order lookup_order;
19 unsigned int item_count;
21 Eina_Bool homogeneous : 1;
22 Eina_Bool no_select : 1;
23 Eina_Bool always_select : 1;
24 Eina_Bool vertical : 1;
25 Eina_Bool long_press : 1;
26 Ecore_Timer *long_timer;
27 Ecore_Job *resize_job;
30 struct _Elm_Toolbar_Item
41 Eina_Bool visible : 1;
43 Eina_Bool selected : 1;
44 Eina_Bool separator : 1;
47 Eina_List *current_state;
50 #define ELM_TOOLBAR_ITEM_FROM_INLIST(item) \
51 ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Toolbar_Item) : NULL)
53 struct _Elm_Toolbar_Item_State
62 static const char *widtype = NULL;
63 static void _item_show(Elm_Toolbar_Item *it);
64 static void _item_select(Elm_Toolbar_Item *it);
65 static void _item_unselect(Elm_Toolbar_Item *it);
66 static void _del_pre_hook(Evas_Object *obj);
67 static void _del_hook(Evas_Object *obj);
68 static void _mirrored_set(Evas_Object *obj, Eina_Bool mirrored);
69 static void _mirrored_set_item(Evas_Object *obj, Elm_Toolbar_Item *it, Eina_Bool mirrored);
70 static void _theme_hook(Evas_Object *obj);
71 static void _sizing_eval(Evas_Object *obj);
72 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
73 static void _menu_move_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
74 static void _menu_hide(void *data, Evas *e, Evas_Object *obj, void *event_info);
75 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
76 static void _elm_toolbar_item_icon_obj_set(Evas_Object *obj, Elm_Toolbar_Item *item, Evas_Object *icon_obj, const char *icon_str, double icon_size, const char *signal);
77 static void _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal);
79 static const char SIG_CLICKED[] = "clicked";
80 static const char SIG_LONGPRESSED[] = "longpressed";
81 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
83 static const Evas_Smart_Cb_Description _signals[] = {
85 {SIG_LONGPRESSED, ""},
86 {SIG_CLICKED_DOUBLE, ""},
91 _item_disable_hook(Elm_Object_Item *it)
93 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
96 Elm_Toolbar_Item *toolbar_it = (Elm_Toolbar_Item *) it;
98 wd = elm_widget_data_get(WIDGET(toolbar_it));
101 if (elm_widget_item_disabled_get(toolbar_it))
103 edje_object_signal_emit(VIEW(toolbar_it), "elm,state,disabled", "elm");
104 elm_widget_signal_emit(toolbar_it->icon, "elm,state,disabled", "elm");
108 edje_object_signal_emit(VIEW(toolbar_it), "elm,state,enabled", "elm");
109 elm_widget_signal_emit(toolbar_it->icon, "elm,state,enabled", "elm");
111 _resize(WIDGET(toolbar_it), NULL, NULL, NULL);
115 _item_icon_set(Evas_Object *icon_obj, const char *type, const char *icon)
119 if ((!type) || (!*type)) goto end;
120 if ((!icon) || (!*icon)) return EINA_FALSE;
121 if ((snprintf(icon_str, sizeof(icon_str), "%s%s", type, icon) > 0)
122 && (elm_icon_standard_set(icon_obj, icon_str)))
125 if (elm_icon_standard_set(icon_obj, icon))
127 WRN("couldn't find icon definition for '%s'", icon);
132 _elm_toolbar_icon_size_get(Widget_Data *wd)
134 const char *icon_size = edje_object_data_get(
135 elm_smart_scroller_edje_object_get(wd->scr), "icon_size");
137 return atoi(icon_size);
138 return _elm_config->icon_size;
142 _item_show(Elm_Toolbar_Item *it)
144 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
145 Evas_Coord x, y, w, h, bx, by;
148 evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
149 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
150 elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
154 _item_unselect(Elm_Toolbar_Item *item)
157 if ((!item) || (!item->selected)) return;
158 wd = elm_widget_data_get(WIDGET(item));
160 item->selected = EINA_FALSE;
161 wd->selected_item = NULL;
162 edje_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
163 elm_widget_signal_emit(item->icon, "elm,state,unselected", "elm");
167 _item_select(Elm_Toolbar_Item *it)
169 Elm_Toolbar_Item *it2;
170 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
175 if (elm_widget_item_disabled_get(it) || (it->separator)) return;
182 if (wd->always_select) return;
187 it2 = (Elm_Toolbar_Item *)
188 elm_toolbar_selected_item_get(WIDGET(it));
191 it->selected = EINA_TRUE;
192 wd->selected_item = it;
193 edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
194 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
199 if (it->menu && (!sel))
201 evas_object_show(it->o_menu);
202 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
203 _menu_move_resize, it);
204 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOVE,
205 _menu_move_resize, it);
207 _menu_move_resize(it, NULL, NULL, NULL);
209 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
210 evas_object_smart_callback_call(obj2, SIG_CLICKED, it);
214 _menu_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
216 Elm_Toolbar_Item *selected;
217 Elm_Toolbar_Item *it = data;
218 selected = (Elm_Toolbar_Item *) elm_toolbar_selected_item_get(WIDGET(it));
219 _item_unselect(selected);
223 _menu_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
225 // avoid hide being emitted during object deletion
226 evas_object_event_callback_del_full
227 (obj, EVAS_CALLBACK_HIDE, _menu_hide, data);
231 _menu_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
233 Elm_Toolbar_Item *it = data;
235 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
237 if ((!wd) || (!wd->menu_parent)) return;
238 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
239 elm_menu_move(it->o_menu, x, y+h);
243 _item_del(Elm_Toolbar_Item *it)
245 Elm_Toolbar_Item_State *it_state;
247 EINA_LIST_FREE(it->states, it_state)
249 if (it->icon == it_state->icon)
251 eina_stringshare_del(it_state->label);
252 eina_stringshare_del(it_state->icon_str);
253 if (it_state->icon) evas_object_del(it_state->icon);
256 eina_stringshare_del(it->label);
257 eina_stringshare_del(it->icon_str);
258 if (it->icon) evas_object_del(it->icon);
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 Evas_Object *view = VIEW(it);
312 const char *style = elm_widget_style_get(obj);
314 _mirrored_set_item(obj, it, elm_widget_mirrored_get(obj));
315 edje_object_scale_set(view, scale);
318 _elm_theme_object_set(obj, view, "toolbar", "item", style);
321 edje_object_signal_emit(view, "elm,state,selected", "elm");
322 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
324 if (elm_widget_item_disabled_get(it))
326 edje_object_signal_emit(view, "elm,state,disabled", "elm");
327 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
333 ms = ((double)icon_size * scale);
334 evas_object_size_hint_min_set(it->icon, ms, ms);
335 evas_object_size_hint_max_set(it->icon, ms, ms);
336 edje_object_part_swallow(view, "elm.swallow.icon",
339 edje_object_part_text_set(view, "elm.text", it->label);
342 _elm_theme_object_set(obj, view, "toolbar", "separator", style);
346 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
347 edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
349 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
350 evas_object_size_hint_min_set(view, mw, mh);
354 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
356 Widget_Data *wd = elm_widget_data_get(obj);
357 Elm_Toolbar_Item *it;
359 EINA_INLIST_FOREACH(wd->items, it)
360 _mirrored_set_item(obj, it, mirrored);
362 _mirrored_set_item(obj, wd->more_item, mirrored);
366 _theme_hook(Evas_Object *obj)
368 Widget_Data *wd = elm_widget_data_get(obj);
369 Elm_Toolbar_Item *it;
373 _elm_widget_mirrored_reload(obj);
374 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
375 _mirrored_set(obj, elm_widget_mirrored_get(obj));
376 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
377 edje_object_scale_set(wd->scr, scale);
378 wd->icon_size = _elm_toolbar_icon_size_get(wd);
379 EINA_INLIST_FOREACH(wd->items, it)
380 _theme_hook_item(obj, it, scale, wd->icon_size);
382 _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
387 _item_text_set_hook(Elm_Object_Item *it,
391 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
392 if (part && strcmp(part, "default")) return;
393 _item_label_set(((Elm_Toolbar_Item *) it), label, "elm,state,label_set");
397 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
399 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
400 if (part && strcmp(part, "default")) return NULL;
401 return ((Elm_Toolbar_Item *) it)->label;
405 _translate_hook(Evas_Object *obj)
407 evas_object_smart_callback_call(obj, "language,changed", NULL);
411 _sizing_eval(Evas_Object *obj)
413 Widget_Data *wd = elm_widget_data_get(obj);
414 Evas_Coord minw = -1, minh = -1, minw_bx, minh_bx;
415 Evas_Coord vw = 0, vh = 0;
419 evas_object_smart_calculate(wd->bx);
420 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
422 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
423 if (w < minw) w = minw;
424 if (h < minh) h = minh;
425 evas_object_resize(wd->scr, w, h);
427 evas_object_size_hint_min_get(wd->bx, &minw, &minh);
430 if (wd->vertical && (h > minh)) minh = h;
431 if ((!wd->vertical) && (w > minw)) minw = w;
432 evas_object_resize(wd->bx, minw, minh);
433 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
434 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_NONE)
436 if (wd->vertical) minh = minh_bx + (h - vh);
437 else minw = minw_bx + (w - vw);
441 if (wd->vertical) minh = h - vh;
444 minh = minh + (h - vh);
445 evas_object_size_hint_min_set(obj, minw, minh);
446 evas_object_size_hint_max_set(obj, -1, -1);
450 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
452 item->o_menu = elm_menu_add(VIEW(item));
453 item->menu = EINA_TRUE;
455 elm_menu_parent_set(item->o_menu, wd->menu_parent);
456 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
458 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
463 _item_menu_destroy(Elm_Toolbar_Item *item)
467 evas_object_del(item->o_menu);
470 item->menu = EINA_FALSE;
474 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
476 const Elm_Toolbar_Item *eti1 = i1;
477 const Elm_Toolbar_Item *eti2 = i2;
480 if (!eti1) return -1;
482 return eti2->prio.priority - eti1->prio.priority;
486 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
488 Elm_Toolbar_Item *it;
489 Eina_List *sorted = NULL;
492 EINA_INLIST_FOREACH(wd->items, it)
494 sorted = eina_list_sorted_insert(sorted,
495 _toolbar_item_prio_compare_cb, it);
500 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL, &ciw, NULL);
503 EINA_LIST_FREE(sorted, it)
505 evas_object_geometry_get(VIEW(it), NULL, NULL, &ciw, NULL);
507 it->prio.visible = (*iw <= vw);
512 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
514 Elm_Toolbar_Item *it = data;
515 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
519 _resize_job(void *data)
521 Widget_Data *wd = elm_widget_data_get(data);
522 Evas_Coord mw, mh, vw, vh, w, h;
523 Elm_Toolbar_Item *it;
524 Evas_Object *obj = (Evas_Object *) data;
527 wd->resize_job = NULL;
528 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
529 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
530 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
531 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
533 Evas_Coord iw = 0, more_w;
535 evas_object_resize(wd->bx, vw, h);
536 _fix_items_visibility(wd, &iw, vw);
537 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL, &more_w, NULL);
538 if (iw - more_w <= vw)
541 /* All items are removed from the box object, since removing individual
542 * items won't trigger a resize. Items are be readded below. */
543 evas_object_box_remove_all(wd->bx, EINA_FALSE);
548 _item_menu_destroy(wd->more_item);
549 _item_menu_create(wd, wd->more_item);
551 elm_toolbar_item_menu_get((Elm_Object_Item *) wd->more_item);
553 EINA_INLIST_FOREACH(wd->items, it)
555 if (!it->prio.visible)
558 elm_menu_item_separator_add(menu, NULL);
561 Elm_Object_Item *menu_it;
562 menu_it = elm_menu_item_add(menu, NULL,
563 it->icon_str, it->label,
564 _elm_toolbar_item_menu_cb, it);
565 elm_object_item_disabled_set(menu_it,
566 elm_widget_item_disabled_get(it));
568 elm_menu_clone(it->o_menu, menu, menu_it);
570 evas_object_hide(VIEW(it));
574 evas_object_box_append(wd->bx, VIEW(it));
575 evas_object_show(VIEW(it));
579 evas_object_box_append(wd->bx, wd->VIEW(more_item));
580 evas_object_show(wd->VIEW(more_item));
584 /* All items are visible, show them all (except for the "More"
585 * button, of course). */
586 EINA_INLIST_FOREACH(wd->items, it)
588 evas_object_show(VIEW(it));
589 evas_object_box_append(wd->bx, VIEW(it));
591 evas_object_hide(wd->VIEW(more_item));
594 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
598 evas_object_resize(wd->bx, vw, h);
599 _fix_items_visibility(wd, &iw, vw);
600 evas_object_box_remove_all(wd->bx, EINA_FALSE);
603 EINA_INLIST_FOREACH(wd->items, it)
605 if (!it->prio.visible)
606 evas_object_hide(VIEW(it));
609 evas_object_box_append(wd->bx, VIEW(it));
610 evas_object_show(VIEW(it));
616 /* All items are visible, show them all */
617 EINA_INLIST_FOREACH(wd->items, it)
619 evas_object_show(VIEW(it));
620 evas_object_box_append(wd->bx, VIEW(it));
626 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
627 EINA_INLIST_FOREACH(wd->items, it)
637 _mirrored_set(obj, elm_widget_mirrored_get(obj));
641 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
644 _resize(data, NULL, NULL, NULL);
648 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
650 Widget_Data *wd = elm_widget_data_get(data);
652 wd->resize_job = ecore_job_add(_resize_job, data);
656 _select_filter(Elm_Toolbar_Item *it, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
659 char buf[sizeof("elm,action,click,") + 1];
661 button = atoi(emission + sizeof("mouse,clicked,") - 1);
662 if (button == 1) return; /* regular left click event */
663 snprintf(buf, sizeof(buf), "elm,action,click,%d", button);
664 edje_object_signal_emit(VIEW(it), buf, "elm");
668 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
670 Elm_Toolbar_Item *it = data;
672 if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
673 (_elm_access_2nd_click_timeout(VIEW(it))))
675 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
676 _elm_access_say(E_("Selected"));
682 _long_press(Elm_Toolbar_Item *it)
684 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
685 wd->long_timer = NULL;
686 wd->long_press = EINA_TRUE;
687 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
688 return ECORE_CALLBACK_CANCEL;
692 _mouse_down(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Down *ev)
694 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
696 if (ev->button != 1) return;
697 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
698 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
699 wd->long_press = EINA_FALSE;
700 if (wd->long_timer) ecore_timer_interval_set(wd->long_timer, _elm_config->longpress_timeout);
701 else wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, (Ecore_Task_Cb)_long_press, it);
705 _mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
707 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
709 if (ev->button != 1) return;
712 ecore_timer_del(wd->long_timer);
713 wd->long_timer = NULL;
718 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
720 Elm_Toolbar_Item *it = data;
721 edje_object_signal_emit(VIEW(it), "elm,state,highlighted", "elm");
722 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
726 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
728 Elm_Toolbar_Item *it = data;
729 edje_object_signal_emit(VIEW(it), "elm,state,unhighlighted", "elm");
730 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
734 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
736 Evas_Object *obj = (Evas_Object *) data;
737 Widget_Data *wd = elm_widget_data_get(obj);
739 _els_box_layout(o, priv, !wd->vertical, wd->homogeneous, elm_widget_mirrored_get(obj));
743 _access_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item)
745 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
746 const char *txt = item->access_info;
747 if (!txt) txt = it->label;
748 if (txt) return strdup(txt);
753 _access_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
755 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
757 return strdup(E_("Separator"));
758 else if (elm_widget_item_disabled_get(it))
759 return strdup(E_("State: Disabled"));
760 else if (it->selected)
761 return strdup(E_("State: Selected"));
763 return strdup(E_("Has menu"));
768 _item_del_pre_hook(Elm_Object_Item *it)
770 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
774 Elm_Toolbar_Item *item, *next;
775 item = (Elm_Toolbar_Item *) it;
777 wd = elm_widget_data_get(WIDGET(item));
778 if (!wd) return EINA_FALSE;
781 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
782 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
784 if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
785 if (wd->always_select && item->selected && next) _item_select(next);
792 static Elm_Toolbar_Item *
793 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
795 Widget_Data *wd = elm_widget_data_get(obj);
796 Evas_Object *icon_obj;
798 Elm_Toolbar_Item *it;
800 icon_obj = elm_icon_add(obj);
801 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
802 if (!icon_obj) return NULL;
803 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
806 evas_object_del(icon_obj);
810 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
811 elm_widget_item_disable_hook_set(it, _item_disable_hook);
812 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
813 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
815 it->label = eina_stringshare_add(label);
816 it->prio.visible = 1;
817 it->prio.priority = 0;
819 it->separator = EINA_FALSE;
820 it->base.data = data;
821 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
822 _elm_access_item_register(&it->base, VIEW(it));
823 _elm_access_text_set(_elm_access_item_get(&it->base),
824 ELM_ACCESS_TYPE, E_("Tool Item"));
825 _elm_access_callback_set(_elm_access_item_get(&it->base),
826 ELM_ACCESS_INFO, _access_info_cb, it);
827 _elm_access_callback_set(_elm_access_item_get(&it->base),
828 ELM_ACCESS_STATE, _access_state_cb, it);
830 if (_item_icon_set(icon_obj, "toolbar/", icon))
833 it->icon_str = eina_stringshare_add(icon);
839 evas_object_del(icon_obj);
842 _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
843 elm_widget_style_get(obj));
844 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "elm",
846 edje_object_signal_callback_add(VIEW(it), "mouse,clicked,*", "*",
847 (Edje_Signal_Cb)_select_filter, it);
848 edje_object_signal_callback_add(VIEW(it), "elm,mouse,in", "elm",
850 edje_object_signal_callback_add(VIEW(it), "elm,mouse,out", "elm",
852 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
853 (Evas_Object_Event_Cb)_mouse_down, it);
854 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
855 (Evas_Object_Event_Cb)_mouse_up, it);
856 elm_widget_sub_object_add(obj, VIEW(it));
861 ms = ((double)wd->icon_size * _elm_config->scale);
862 evas_object_size_hint_min_set(it->icon, ms, ms);
863 evas_object_size_hint_max_set(it->icon, ms, ms);
864 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
865 evas_object_show(it->icon);
866 elm_widget_sub_object_add(obj, it->icon);
868 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
870 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
871 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
872 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
875 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, -1.0);
876 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, 0.5);
880 evas_object_size_hint_weight_set(VIEW(it), -1.0, EVAS_HINT_EXPAND);
881 evas_object_size_hint_align_set(VIEW(it), 0.5, EVAS_HINT_FILL);
883 evas_object_size_hint_min_set(VIEW(it), mw, mh);
884 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
886 if ((!wd->items) && wd->always_select) _item_select(it);
892 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
894 Evas_Coord mw = -1, mh = -1;
895 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
896 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
898 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
899 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
900 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
903 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
904 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
908 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
909 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
911 evas_object_size_hint_min_set(VIEW(item), mw, mh);
915 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
917 Elm_Toolbar_Item *item = data;
918 _elm_toolbar_item_label_update(item);
919 edje_object_signal_callback_del(obj, emission, source,
920 _elm_toolbar_item_label_set_cb);
921 edje_object_signal_emit (VIEW(item), "elm,state,label,reset", "elm");
925 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal)
929 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
931 eina_stringshare_replace(&item->label, label);
932 s = edje_object_data_get(VIEW(item), "transition_animation_on");
933 if ((s) && (atoi(s)))
935 edje_object_part_text_set(VIEW(item), "elm.text_new", item->label);
936 edje_object_signal_emit (VIEW(item), signal, "elm");
937 edje_object_signal_callback_add(VIEW(item),
938 "elm,state,label_set,done", "elm",
939 _elm_toolbar_item_label_set_cb, item);
942 _elm_toolbar_item_label_update(item);
943 _resize(WIDGET(item), NULL, NULL, NULL);
947 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
949 Elm_Toolbar_Item_State *it_state;
951 Evas_Coord mw = -1, mh = -1;
952 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
953 Evas_Object *old_icon = edje_object_part_swallow_get(VIEW(item),
955 elm_widget_sub_object_del(VIEW(item), old_icon);
956 evas_object_hide(old_icon);
957 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
958 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
959 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
960 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
963 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
964 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
968 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
969 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
971 evas_object_size_hint_min_set(VIEW(item), mw, mh);
973 EINA_LIST_FOREACH(item->states, l, it_state)
974 if (it_state->icon == old_icon)
976 evas_object_del(old_icon);
980 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
982 Elm_Toolbar_Item *item = data;
983 edje_object_part_unswallow(VIEW(item), item->icon);
984 _elm_toolbar_item_icon_update(item);
985 edje_object_signal_callback_del(obj, emission, source,
986 _elm_toolbar_item_icon_set_cb);
987 edje_object_signal_emit (VIEW(item), "elm,state,icon,reset", "elm");
991 _elm_toolbar_item_icon_obj_set(Evas_Object *obj, Elm_Toolbar_Item *item, Evas_Object *icon_obj, const char *icon_str, double icon_size, const char *signal)
993 Evas_Object *old_icon;
998 eina_stringshare_replace(&item->icon_str, icon_str);
1001 eina_stringshare_del(item->icon_str);
1002 item->icon_str = NULL;
1004 item->icon = icon_obj;
1007 ms = (icon_size * _elm_config->scale);
1008 evas_object_size_hint_min_set(item->icon, ms, ms);
1009 evas_object_size_hint_max_set(item->icon, ms, ms);
1010 evas_object_show(item->icon);
1011 elm_widget_sub_object_add(obj, item->icon);
1013 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1014 if ((s) && (atoi(s)))
1016 old_icon = edje_object_part_swallow_get(VIEW(item),
1017 "elm.swallow.icon_new");
1020 elm_widget_sub_object_del(VIEW(item), old_icon);
1021 evas_object_hide(old_icon);
1023 edje_object_part_swallow(VIEW(item), "elm.swallow.icon_new",
1025 edje_object_signal_emit (VIEW(item), signal, "elm");
1026 edje_object_signal_callback_add(VIEW(item),
1027 "elm,state,icon_set,done", "elm",
1028 _elm_toolbar_item_icon_set_cb, item);
1031 _elm_toolbar_item_icon_update(item);
1032 _resize(obj, NULL, NULL, NULL);
1036 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1038 Elm_Toolbar_Item *it = event_info;
1039 Elm_Toolbar_Item_State *it_state;
1041 it_state = eina_list_data_get(it->current_state);
1043 it_state->func((void *)it_state->data, obj, event_info);
1046 static Elm_Toolbar_Item_State *
1047 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1049 Elm_Toolbar_Item_State *it_state;
1050 it_state = ELM_NEW(Elm_Toolbar_Item_State);
1051 it_state->label = eina_stringshare_add(label);
1052 it_state->icon_str = eina_stringshare_add(icon_str);
1053 it_state->icon = icon;
1054 it_state->func = func;
1055 it_state->data = data;
1060 elm_toolbar_add(Evas_Object *parent)
1066 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1068 ELM_SET_WIDTYPE(widtype, "toolbar");
1069 elm_widget_type_set(obj, "toolbar");
1070 elm_widget_sub_object_add(parent, obj);
1071 elm_widget_data_set(obj, wd);
1072 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1073 elm_widget_del_hook_set(obj, _del_hook);
1074 elm_widget_theme_hook_set(obj, _theme_hook);
1075 elm_widget_translate_hook_set(obj, _translate_hook);
1076 elm_widget_can_focus_set(obj, EINA_FALSE);
1078 wd->more_item = NULL;
1079 wd->selected_item = NULL;
1080 wd->scr = elm_smart_scroller_add(e);
1081 elm_smart_scroller_widget_set(wd->scr, obj);
1082 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
1083 elm_smart_scroller_bounce_allow_set(wd->scr,
1084 _elm_config->thumbscroll_bounce_enable,
1086 elm_widget_resize_object_set(obj, wd->scr);
1087 elm_smart_scroller_policy_set(wd->scr,
1088 ELM_SMART_SCROLLER_POLICY_AUTO,
1089 ELM_SMART_SCROLLER_POLICY_OFF);
1092 wd->icon_size = _elm_toolbar_icon_size_get(wd);
1095 wd->homogeneous = EINA_TRUE;
1098 wd->bx = evas_object_box_add(e);
1099 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
1100 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
1101 elm_widget_sub_object_add(obj, wd->bx);
1102 elm_smart_scroller_child_set(wd->scr, wd->bx);
1103 evas_object_show(wd->bx);
1105 elm_toolbar_shrink_mode_set(obj, _elm_config->toolbar_shrink_mode);
1106 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
1107 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
1108 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
1110 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1117 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
1119 ELM_CHECK_WIDTYPE(obj, widtype);
1120 Widget_Data *wd = elm_widget_data_get(obj);
1122 if (wd->icon_size == icon_size) return;
1123 wd->icon_size = icon_size;
1128 elm_toolbar_icon_size_get(const Evas_Object *obj)
1130 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1131 Widget_Data *wd = elm_widget_data_get(obj);
1133 return wd->icon_size;
1136 EAPI Elm_Object_Item *
1137 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1139 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1140 Widget_Data *wd = elm_widget_data_get(obj);
1141 if (!wd) return NULL;
1143 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1144 if (!it) return NULL;
1145 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1147 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
1148 evas_object_box_append(wd->bx, VIEW(it));
1149 evas_object_show(VIEW(it));
1151 _theme_hook_item(obj, it, scale, wd->icon_size);
1154 return (Elm_Object_Item *) it;
1157 EAPI Elm_Object_Item *
1158 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1160 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1161 Widget_Data *wd = elm_widget_data_get(obj);
1162 if (!wd) return NULL;
1164 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1165 if (!it) return NULL;
1166 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1168 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1169 evas_object_box_prepend(wd->bx, VIEW(it));
1170 evas_object_show(VIEW(it));
1171 _theme_hook_item(obj, it, scale, wd->icon_size);
1174 return (Elm_Object_Item *) it;
1177 EAPI Elm_Object_Item *
1178 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)
1180 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1181 ELM_OBJ_ITEM_CHECK_OR_RETURN(before, NULL);
1183 Elm_Toolbar_Item *it, *_before;
1185 wd = elm_widget_data_get(obj);
1186 if (!wd) return NULL;
1187 _before = (Elm_Toolbar_Item *) before;
1188 it = _item_new(obj, icon, label, func, data);
1189 if (!it) return NULL;
1190 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1192 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1193 EINA_INLIST_GET(_before));
1194 evas_object_box_insert_before(wd->bx, VIEW(it), VIEW(_before));
1195 evas_object_show(VIEW(it));
1196 _theme_hook_item(obj, it, scale, wd->icon_size);
1199 return (Elm_Object_Item *) it;
1202 EAPI Elm_Object_Item *
1203 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)
1205 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1206 ELM_OBJ_ITEM_CHECK_OR_RETURN(after, NULL);
1208 Elm_Toolbar_Item *it, *_after;
1210 wd = elm_widget_data_get(obj);
1211 if (!wd) return NULL;
1212 _after = (Elm_Toolbar_Item *) after;
1213 it = _item_new(obj, icon, label, func, data);
1214 if (!it) return NULL;
1215 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1217 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1218 EINA_INLIST_GET(_after));
1219 evas_object_box_insert_after(wd->bx, VIEW(it), VIEW(_after));
1220 evas_object_show(VIEW(it));
1221 _theme_hook_item(obj, it, scale, wd->icon_size);
1224 return (Elm_Object_Item *) it;
1227 EAPI Elm_Object_Item *
1228 elm_toolbar_first_item_get(const Evas_Object *obj)
1230 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1231 Widget_Data *wd = elm_widget_data_get(obj);
1232 if (!wd || !wd->items) return NULL;
1233 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1236 EAPI Elm_Object_Item *
1237 elm_toolbar_last_item_get(const Evas_Object *obj)
1239 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1240 Widget_Data *wd = elm_widget_data_get(obj);
1241 if (!wd || !wd->items) return NULL;
1242 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1245 EAPI Elm_Object_Item *
1246 elm_toolbar_item_next_get(const Elm_Object_Item *it)
1248 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1249 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1250 EINA_INLIST_GET(((Elm_Toolbar_Item *) it))->next);
1253 EAPI Elm_Object_Item *
1254 elm_toolbar_item_prev_get(const Elm_Object_Item *it)
1256 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1257 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1258 EINA_INLIST_GET(((Elm_Toolbar_Item *) it))->prev);
1262 elm_toolbar_item_toolbar_get(const Elm_Object_Item *it)
1264 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1265 return elm_object_item_widget_get(it);
1269 elm_toolbar_item_priority_set(Elm_Object_Item *it, int priority)
1271 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1272 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1273 if (item->prio.priority == priority) return;
1274 item->prio.priority = priority;
1275 _resize(WIDGET(item), NULL, NULL, NULL);
1279 elm_toolbar_item_priority_get(const Elm_Object_Item *it)
1281 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
1282 return ((Elm_Toolbar_Item *) it)->prio.priority;
1286 elm_toolbar_item_label_get(const Elm_Object_Item *it)
1288 return _item_text_get_hook(it, NULL);
1292 elm_toolbar_item_label_set(Elm_Object_Item *it, const char *label)
1294 _item_text_set_hook(it, NULL, label);
1298 elm_toolbar_item_data_get(const Elm_Object_Item *it)
1300 return elm_object_item_data_get(it);
1304 elm_toolbar_item_data_set(Elm_Object_Item *it, const void *data)
1306 elm_object_item_data_set(it, (void *) data);
1309 EAPI Elm_Object_Item *
1310 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
1312 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1313 Elm_Toolbar_Item *it;
1314 Widget_Data *wd = elm_widget_data_get(obj);
1315 if (!wd) return NULL;
1317 EINA_INLIST_FOREACH(wd->items, it)
1319 if (!strcmp(it->label, label))
1320 return (Elm_Object_Item *) it;
1326 elm_toolbar_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1328 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1329 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1330 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1333 if (item->selected == selected) return;
1334 if (selected) _item_select(item);
1335 else _item_unselect(item);
1339 elm_toolbar_item_selected_get(const Elm_Object_Item *it)
1341 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1342 return ((Elm_Toolbar_Item *) it)->selected;
1345 EAPI Elm_Object_Item *
1346 elm_toolbar_selected_item_get(const Evas_Object *obj)
1348 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1349 Widget_Data *wd = elm_widget_data_get(obj);
1350 if (!wd) return NULL;
1351 return (Elm_Object_Item *) wd->selected_item;
1355 elm_toolbar_item_icon_set(Elm_Object_Item *it, const char *icon)
1357 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1359 Evas_Object *icon_obj;
1362 Elm_Toolbar_Item * item = (Elm_Toolbar_Item *) it;
1365 wd = elm_widget_data_get(obj);
1367 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1369 icon_obj = elm_icon_add(obj);
1370 if (!icon_obj) return;
1371 if (_item_icon_set(icon_obj, "toolbar/", icon))
1372 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1373 "elm,state,icon_set");
1376 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1377 "elm,state,icon_set");
1378 evas_object_del(icon_obj);
1383 elm_toolbar_item_icon_get(const Elm_Object_Item *it)
1385 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1386 return ((Elm_Toolbar_Item *) it)->icon_str;
1390 elm_toolbar_item_object_get(const Elm_Object_Item *it)
1392 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1396 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1399 wd = elm_widget_data_get(obj);
1400 if (!wd) return NULL;
1406 elm_toolbar_item_icon_object_get(Elm_Object_Item *it)
1408 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1409 return ((Elm_Toolbar_Item *) it)->icon;
1413 elm_toolbar_item_icon_memfile_set(Elm_Object_Item *it, const void *img, size_t size, const char *format, const char *key)
1415 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1417 Evas_Object *icon_obj;
1421 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1424 wd = elm_widget_data_get(obj);
1425 if (!wd) return EINA_FALSE;
1429 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1430 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1431 ret = _els_smart_icon_memfile_set(icon_obj, img, size, format, key);
1434 evas_object_del(icon_obj);
1437 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1438 "elm,state,icon_set");
1441 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1446 elm_toolbar_item_icon_file_set(Elm_Object_Item *it, const char *file, const char *key)
1448 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1450 Evas_Object *icon_obj;
1454 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1457 wd = elm_widget_data_get(obj);
1458 if (!wd) return EINA_FALSE;
1462 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1463 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1464 ret = _els_smart_icon_file_key_set(icon_obj, file, key);
1467 evas_object_del(icon_obj);
1470 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1471 "elm,state,icon_set");
1474 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1479 elm_toolbar_item_del(Elm_Object_Item *it)
1481 elm_object_item_del(it);
1485 elm_toolbar_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1487 elm_object_item_del_cb_set(it, func);
1491 elm_toolbar_item_disabled_get(const Elm_Object_Item *it)
1493 return elm_object_item_disabled_get(it);
1497 elm_toolbar_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1499 elm_object_item_disabled_set(it, disabled);
1503 elm_toolbar_item_separator_set(Elm_Object_Item *it, Eina_Bool separator)
1505 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1506 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1507 Evas_Object *obj = WIDGET(item);
1508 Widget_Data *wd = elm_widget_data_get(obj);
1510 if (item->separator == separator) return;
1511 item->separator = separator;
1512 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1513 _theme_hook_item(obj, item, scale, wd->icon_size);
1517 elm_toolbar_item_separator_get(const Elm_Object_Item *it)
1519 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1520 return ((Elm_Toolbar_Item *) it)->separator;
1524 elm_toolbar_shrink_mode_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1526 ELM_CHECK_WIDTYPE(obj, widtype);
1527 Widget_Data *wd = elm_widget_data_get(obj);
1531 wd->shrink_mode = shrink_mode;
1532 bounce = (_elm_config->thumbscroll_bounce_enable) &&
1533 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1534 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1538 _item_del(wd->more_item);
1539 elm_widget_item_free(wd->more_item);
1540 wd->more_item = NULL;
1543 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1545 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF, ELM_SMART_SCROLLER_POLICY_OFF);
1547 wd->more_item = _item_new(obj, "more_menu", "More",
1550 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1551 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1552 ELM_SMART_SCROLLER_POLICY_OFF);
1554 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1555 ELM_SMART_SCROLLER_POLICY_OFF);
1559 EAPI Elm_Toolbar_Shrink_Mode
1560 elm_toolbar_shrink_mode_get(const Evas_Object *obj)
1562 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1563 Widget_Data *wd = elm_widget_data_get(obj);
1565 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1566 return wd->shrink_mode;
1570 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
1572 ELM_CHECK_WIDTYPE(obj, widtype);
1573 Widget_Data *wd = elm_widget_data_get(obj);
1576 wd->homogeneous = !!homogeneous;
1577 evas_object_smart_calculate(wd->bx);
1581 elm_toolbar_homogeneous_get(const Evas_Object *obj)
1583 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1584 Widget_Data *wd = elm_widget_data_get(obj);
1586 if (!wd) return EINA_FALSE;
1587 return wd->homogeneous;
1591 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1593 Elm_Toolbar_Item *it;
1594 ELM_CHECK_WIDTYPE(obj, widtype);
1595 Widget_Data *wd = elm_widget_data_get(obj);
1598 EINA_SAFETY_ON_NULL_RETURN(parent);
1599 wd->menu_parent = parent;
1600 EINA_INLIST_FOREACH(wd->items, it)
1603 elm_menu_parent_set(it->o_menu, wd->menu_parent);
1605 if ((wd->more_item) && (wd->more_item->o_menu))
1606 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1610 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1612 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1613 Widget_Data *wd = elm_widget_data_get(obj);
1615 if (!wd) return NULL;
1616 return wd->menu_parent;
1620 elm_toolbar_align_set(Evas_Object *obj, double align)
1622 ELM_CHECK_WIDTYPE(obj, widtype);
1623 Widget_Data *wd = elm_widget_data_get(obj);
1626 if (wd->align != align)
1627 evas_object_size_hint_align_set(wd->bx, align, 0.5);
1632 elm_toolbar_align_get(const Evas_Object *obj)
1634 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1635 Widget_Data *wd = elm_widget_data_get(obj);
1637 if (!wd) return 0.0;
1642 elm_toolbar_item_menu_set(Elm_Object_Item *it, Eina_Bool menu)
1644 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1645 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1646 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1649 if (item->menu == menu) return;
1650 if (menu) _item_menu_create(wd, item);
1651 else _item_menu_destroy(item);
1655 elm_toolbar_item_menu_get(const Elm_Object_Item *it)
1657 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1658 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1659 if (!item->menu) return NULL;
1660 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1661 if (!wd) return NULL;
1662 return item->o_menu;
1665 EAPI Elm_Toolbar_Item_State *
1666 elm_toolbar_item_state_add(Elm_Object_Item *it, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1668 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1670 Elm_Toolbar_Item_State *it_state;
1671 Evas_Object *icon_obj;
1674 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1676 wd = elm_widget_data_get(WIDGET(item));
1677 if (!wd) return NULL;
1681 it_state = _item_state_new(item->label, item->icon_str, item->icon,
1682 item->func, item->base.data);
1683 item->states = eina_list_append(item->states, it_state);
1684 item->current_state = item->states;
1687 icon_obj = elm_icon_add(obj);
1688 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1689 if (!icon_obj) goto error_state_add;
1691 if (!_item_icon_set(icon_obj, "toolbar/", icon))
1693 evas_object_del(icon_obj);
1698 it_state = _item_state_new(label, icon, icon_obj, func, data);
1699 item->states = eina_list_append(item->states, it_state);
1700 item->func = _elm_toolbar_item_state_cb;
1701 item->base.data = NULL;
1706 if (item->states && !eina_list_next(item->states))
1708 eina_stringshare_del(item->label);
1709 eina_stringshare_del(item->icon_str);
1710 free(eina_list_data_get(item->states));
1711 eina_list_free(item->states);
1712 item->states = NULL;
1718 elm_toolbar_item_state_del(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1720 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1722 Eina_List *del_state;
1723 Elm_Toolbar_Item_State *it_state;
1724 Elm_Toolbar_Item *item;
1726 if (!state) return EINA_FALSE;
1728 item = (Elm_Toolbar_Item *) it;
1729 if (!item->states) return EINA_FALSE;
1731 del_state = eina_list_data_find_list(item->states, state);
1732 if (del_state == item->states) return EINA_FALSE;
1733 if (del_state == item->current_state)
1734 elm_toolbar_item_state_unset(it);
1736 eina_stringshare_del(state->label);
1737 eina_stringshare_del(state->icon_str);
1738 if (state->icon) evas_object_del(state->icon);
1740 item->states = eina_list_remove_list(item->states, del_state);
1741 if (item->states && !eina_list_next(item->states))
1743 it_state = eina_list_data_get(item->states);
1744 item->base.data = it_state->data;
1745 item->func = it_state->func;
1746 eina_stringshare_del(it_state->label);
1747 eina_stringshare_del(it_state->icon_str);
1748 free(eina_list_data_get(item->states));
1749 eina_list_free(item->states);
1750 item->states = NULL;
1756 elm_toolbar_item_state_set(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1758 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1761 Eina_List *next_state;
1762 Elm_Toolbar_Item_State *it_state;
1764 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1767 wd = elm_widget_data_get(obj);
1768 if (!wd) return EINA_FALSE;
1769 if (!item->states) return EINA_FALSE;
1773 next_state = eina_list_data_find_list(item->states, state);
1774 if (!next_state) return EINA_FALSE;
1777 next_state = item->states;
1779 if (next_state == item->current_state) return EINA_TRUE;
1781 it_state = eina_list_data_get(next_state);
1782 if (eina_list_data_find(item->current_state, state))
1784 _item_label_set(item, it_state->label, "elm,state,label_set,forward");
1785 _elm_toolbar_item_icon_obj_set(obj, item, it_state->icon, it_state->icon_str,
1786 wd->icon_size, "elm,state,icon_set,forward");
1790 _item_label_set(item, it_state->label, "elm,state,label_set,backward");
1791 _elm_toolbar_item_icon_obj_set(obj,
1796 "elm,state,icon_set,backward");
1798 if (elm_widget_item_disabled_get(item))
1799 elm_widget_signal_emit(item->icon, "elm,state,disabled", "elm");
1801 elm_widget_signal_emit(item->icon, "elm,state,enabled", "elm");
1803 item->current_state = next_state;
1808 elm_toolbar_item_state_unset(Elm_Object_Item *it)
1810 elm_toolbar_item_state_set(it, NULL);
1813 EAPI Elm_Toolbar_Item_State *
1814 elm_toolbar_item_state_get(const Elm_Object_Item *it)
1816 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1817 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1819 if ((!item->states) || (!item->current_state)) return NULL;
1820 if (item->current_state == item->states) return NULL;
1822 return eina_list_data_get(item->current_state);
1825 EAPI Elm_Toolbar_Item_State *
1826 elm_toolbar_item_state_next(Elm_Object_Item *it)
1828 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1832 Eina_List *next_state;
1833 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1836 wd = elm_widget_data_get(obj);
1837 if (!wd) return NULL;
1838 if (!item->states) return NULL;
1840 next_state = eina_list_next(item->current_state);
1842 next_state = eina_list_next(item->states);
1843 return eina_list_data_get(next_state);
1846 EAPI Elm_Toolbar_Item_State *
1847 elm_toolbar_item_state_prev(Elm_Object_Item *it)
1849 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1853 Eina_List *prev_state;
1854 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1857 wd = elm_widget_data_get(obj);
1858 if (!wd) return NULL;
1859 if (!item->states) return NULL;
1861 prev_state = eina_list_prev(item->current_state);
1862 if ((!prev_state) || (prev_state == item->states))
1863 prev_state = eina_list_last(item->states);
1864 return eina_list_data_get(prev_state);
1868 elm_toolbar_item_tooltip_text_set(Elm_Object_Item *it, const char *text)
1870 elm_object_item_tooltip_text_set(it, text);
1874 elm_toolbar_item_tooltip_content_cb_set(Elm_Object_Item *it, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb)
1876 elm_object_item_tooltip_content_cb_set(it, func, data, del_cb);
1880 elm_toolbar_item_tooltip_unset(Elm_Object_Item *it)
1882 elm_object_item_tooltip_unset(it);
1886 elm_toolbar_item_tooltip_style_set(Elm_Object_Item *it, const char *style)
1888 elm_object_item_tooltip_style_set(it, style);
1892 elm_toolbar_item_tooltip_style_get(const Elm_Object_Item *it)
1894 return elm_object_item_tooltip_style_get(it);
1898 elm_toolbar_item_cursor_set(Elm_Object_Item *it, const char *cursor)
1900 elm_object_item_cursor_set(it, cursor);
1904 elm_toolbar_item_cursor_get(const Elm_Object_Item *it)
1906 return elm_object_item_cursor_get(it);
1910 elm_toolbar_item_cursor_unset(Elm_Object_Item *it)
1912 elm_object_item_cursor_unset(it);
1916 elm_toolbar_item_cursor_style_set(Elm_Object_Item *it, const char *style)
1918 elm_object_item_cursor_style_set(it, style);
1922 elm_toolbar_item_cursor_style_get(const Elm_Object_Item *it)
1924 return elm_object_item_cursor_style_get(it);
1928 elm_toolbar_item_cursor_engine_only_set(Elm_Object_Item *it, Eina_Bool engine_only)
1930 elm_object_item_cursor_engine_only_set(it, engine_only);
1934 elm_toolbar_item_cursor_engine_only_get(const Elm_Object_Item *it)
1936 return elm_object_item_cursor_engine_only_get(it);
1940 elm_toolbar_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
1942 ELM_CHECK_WIDTYPE(obj, widtype);
1943 Widget_Data *wd = elm_widget_data_get(obj);
1945 if (always_select && (!wd->always_select) && wd->items)
1946 _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
1947 wd->always_select = always_select;
1951 elm_toolbar_always_select_mode_get(const Evas_Object *obj)
1953 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1954 Widget_Data *wd = elm_widget_data_get(obj);
1955 if (!wd) return EINA_FALSE;
1956 return wd->always_select;
1960 elm_toolbar_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select)
1962 ELM_CHECK_WIDTYPE(obj, widtype);
1963 Widget_Data *wd = elm_widget_data_get(obj);
1965 wd->no_select = no_select;
1969 elm_toolbar_no_select_mode_get(const Evas_Object *obj)
1971 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1972 Widget_Data *wd = elm_widget_data_get(obj);
1973 if (!wd) return EINA_FALSE;
1974 return wd->no_select;
1978 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
1980 ELM_CHECK_WIDTYPE(obj, widtype);
1981 Elm_Toolbar_Item *it;
1982 Widget_Data *wd = elm_widget_data_get(obj);
1985 wd->lookup_order = order;
1986 EINA_INLIST_FOREACH(wd->items, it)
1987 elm_icon_order_lookup_set(it->icon, order);
1989 elm_icon_order_lookup_set(wd->more_item->icon, order);
1992 EAPI Elm_Icon_Lookup_Order
1993 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
1995 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
1996 Widget_Data *wd = elm_widget_data_get(obj);
1997 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
1998 return wd->lookup_order;
2001 EINA_DEPRECATED EAPI void
2002 elm_toolbar_orientation_set(Evas_Object *obj, Eina_Bool vertical)
2004 elm_toolbar_horizontal_set(obj, !vertical);
2007 EINA_DEPRECATED EAPI Eina_Bool
2008 elm_toolbar_orientation_get(const Evas_Object *obj)
2010 return !elm_toolbar_horizontal_get(obj);
2014 elm_toolbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
2016 ELM_CHECK_WIDTYPE(obj, widtype);
2017 Widget_Data *wd = elm_widget_data_get(obj);
2019 wd->vertical = !horizontal;
2024 elm_toolbar_horizontal_get(const Evas_Object *obj)
2026 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2027 Widget_Data *wd = elm_widget_data_get(obj);
2028 if (!wd) return EINA_FALSE;
2029 return !wd->vertical;
2033 elm_toolbar_items_count(const Evas_Object *obj)
2035 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2036 Widget_Data *wd = elm_widget_data_get(obj);
2038 return wd->item_count;
2041 EINA_DEPRECATED EAPI void
2042 elm_toolbar_mode_shrink_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
2044 elm_toolbar_shrink_mode_set(obj, shrink_mode);
2047 EINA_DEPRECATED EAPI Elm_Toolbar_Shrink_Mode
2048 elm_toolbar_mode_shrink_get(const Evas_Object *obj)
2050 return elm_toolbar_shrink_mode_get(obj);