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 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);
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);
343 _elm_theme_object_set(obj, view, "toolbar", "separator", style);
346 evas_object_size_hint_weight_set(view, EVAS_HINT_EXPAND, -1.0);
347 evas_object_size_hint_align_set(view, EVAS_HINT_FILL, 0.5);
351 evas_object_size_hint_weight_set(view, -1.0, EVAS_HINT_EXPAND);
352 evas_object_size_hint_align_set(view, 0.5, EVAS_HINT_FILL);
358 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
359 edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
361 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
362 evas_object_size_hint_min_set(view, mw, mh);
366 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
368 Widget_Data *wd = elm_widget_data_get(obj);
369 Elm_Toolbar_Item *it;
371 EINA_INLIST_FOREACH(wd->items, it)
372 _mirrored_set_item(obj, it, mirrored);
374 _mirrored_set_item(obj, wd->more_item, mirrored);
378 _theme_hook(Evas_Object *obj)
380 Widget_Data *wd = elm_widget_data_get(obj);
381 Elm_Toolbar_Item *it;
385 _elm_widget_mirrored_reload(obj);
386 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
387 _mirrored_set(obj, elm_widget_mirrored_get(obj));
388 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
389 edje_object_scale_set(wd->scr, scale);
390 wd->icon_size = _elm_toolbar_icon_size_get(wd);
391 EINA_INLIST_FOREACH(wd->items, it)
392 _theme_hook_item(obj, it, scale, wd->icon_size);
394 _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
399 _item_text_set_hook(Elm_Object_Item *it,
403 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
404 if (part && strcmp(part, "default")) return;
405 _item_label_set(((Elm_Toolbar_Item *) it), label, "elm,state,label_set");
409 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
411 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
412 if (part && strcmp(part, "default")) return NULL;
413 return ((Elm_Toolbar_Item *) it)->label;
417 _translate_hook(Evas_Object *obj)
419 evas_object_smart_callback_call(obj, "language,changed", NULL);
423 _sizing_eval(Evas_Object *obj)
425 Widget_Data *wd = elm_widget_data_get(obj);
426 Evas_Coord minw = -1, minh = -1, minw_bx = -1, minh_bx = -1;
427 Evas_Coord vw = 0, vh = 0;
431 evas_object_smart_need_recalculate_set(wd->bx, EINA_TRUE);
432 evas_object_smart_calculate(wd->bx);
433 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
435 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
436 if (w < minw) w = minw;
437 if (h < minh) h = minh;
438 evas_object_resize(wd->scr, w, h);
440 evas_object_size_hint_min_get(wd->bx, &minw_bx, &minh_bx);
441 // if (wd->vertical && (h > minh)) minh = h;
442 // if ((!wd->vertical) && (w > minw)) minw = w;
443 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
444 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_NONE)
448 minw = minw_bx + (w - vw);
449 minh = minh_bx + (h - vh);
453 minw = minw_bx + (w - vw);
454 minh = minh_bx + (h - vh);
457 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
459 minw = minw_bx + (w - vw);
460 minh = minh_bx + (h - vh);
461 if (minw_bx < vw) minw_bx = vw;
462 if (minh_bx < vh) minh_bx = vh;
468 minw = minw_bx + (w - vw);
474 minh = minh_bx + (h - vh);
476 // if (wd->vertical) minh = h - vh;
477 // else minw = w - vw;
478 // minh = minh + (h - vh);
480 evas_object_resize(wd->bx, minw_bx, minh_bx);
481 evas_object_size_hint_min_set(obj, minw, minh);
482 evas_object_size_hint_max_set(obj, -1, -1);
486 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
488 item->o_menu = elm_menu_add(VIEW(item));
489 item->menu = EINA_TRUE;
491 elm_menu_parent_set(item->o_menu, wd->menu_parent);
492 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
494 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
499 _item_menu_destroy(Elm_Toolbar_Item *item)
503 evas_object_del(item->o_menu);
506 item->menu = EINA_FALSE;
510 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
512 const Elm_Toolbar_Item *eti1 = i1;
513 const Elm_Toolbar_Item *eti2 = i2;
516 if (!eti1) return -1;
518 return eti2->prio.priority - eti1->prio.priority;
522 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
524 Elm_Toolbar_Item *it;
525 Eina_List *sorted = NULL;
526 Evas_Coord ciw = 0, cih = 0;
528 EINA_INLIST_FOREACH(wd->items, it)
530 sorted = eina_list_sorted_insert(sorted,
531 _toolbar_item_prio_compare_cb, it);
536 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL, &ciw, &cih);
537 if (wd->vertical) *iw += cih;
540 EINA_LIST_FREE(sorted, it)
542 evas_object_geometry_get(VIEW(it), NULL, NULL, &ciw, &cih);
543 if (wd->vertical) *iw += cih;
545 it->prio.visible = (*iw <= vw);
550 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
552 Elm_Toolbar_Item *it = data;
553 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
557 _resize_job(void *data)
559 Evas_Object *obj = (Evas_Object *)data;
560 Widget_Data *wd = elm_widget_data_get(obj);
561 Evas_Coord mw, mh, vw = 0, vh = 0, w = 0, h = 0;
562 Elm_Toolbar_Item *it;
565 wd->resize_job = NULL;
566 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
567 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
568 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
569 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
571 Evas_Coord iw = 0, ih = 0, more_w = 0, more_h = 0;
575 evas_object_resize(wd->bx, w, vh);
576 _fix_items_visibility(wd, &ih, vh);
580 evas_object_resize(wd->bx, vw, h);
581 _fix_items_visibility(wd, &iw, vw);
583 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL,
587 if ((ih - more_h) <= vh) ih -= more_h;
591 if ((iw - more_w) <= vw) iw -= more_w;
594 /* All items are removed from the box object, since removing individual
595 * items won't trigger a resize. Items are be readded below. */
596 evas_object_box_remove_all(wd->bx, EINA_FALSE);
597 if (((wd->vertical) && (ih > vh)) ||
598 ((!wd->vertical) && (iw > vw)))
602 _item_menu_destroy(wd->more_item);
603 _item_menu_create(wd, wd->more_item);
604 menu = elm_toolbar_item_menu_get((Elm_Object_Item *)wd->more_item);
605 EINA_INLIST_FOREACH(wd->items, it)
607 if (!it->prio.visible)
610 elm_menu_item_separator_add(menu, NULL);
613 Elm_Object_Item *menu_it;
614 menu_it = elm_menu_item_add
615 (menu, NULL, it->icon_str, it->label,
616 _elm_toolbar_item_menu_cb, it);
617 elm_object_item_disabled_set
618 (menu_it, elm_widget_item_disabled_get(it));
620 elm_menu_clone(it->o_menu, menu, menu_it);
622 evas_object_hide(VIEW(it));
626 evas_object_box_append(wd->bx, VIEW(it));
627 evas_object_show(VIEW(it));
630 evas_object_box_append(wd->bx, wd->VIEW(more_item));
631 evas_object_show(wd->VIEW(more_item));
635 /* All items are visible, show them all (except for the "More"
636 * button, of course). */
637 EINA_INLIST_FOREACH(wd->items, it)
639 evas_object_show(VIEW(it));
640 evas_object_box_append(wd->bx, VIEW(it));
642 evas_object_hide(wd->VIEW(more_item));
645 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
647 Evas_Coord iw = 0, ih = 0;
651 evas_object_resize(wd->bx, w, vh);
652 _fix_items_visibility(wd, &ih, vh);
656 evas_object_resize(wd->bx, vw, h);
657 _fix_items_visibility(wd, &iw, vw);
659 evas_object_box_remove_all(wd->bx, EINA_FALSE);
660 if (((wd->vertical) && (ih > vh)) ||
661 ((!wd->vertical) && (iw > vw)))
663 EINA_INLIST_FOREACH(wd->items, it)
665 if (!it->prio.visible)
666 evas_object_hide(VIEW(it));
669 evas_object_box_append(wd->bx, VIEW(it));
670 evas_object_show(VIEW(it));
676 /* All items are visible, show them all */
677 EINA_INLIST_FOREACH(wd->items, it)
679 evas_object_show(VIEW(it));
680 evas_object_box_append(wd->bx, VIEW(it));
684 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
686 if ((vw >= mw) && (vh >= mh))
687 evas_object_resize(wd->bx, vw, vh);
689 evas_object_resize(wd->bx, mw, vh);
691 evas_object_resize(wd->bx, vw, mh);
697 if ((vh >= mh) && (h != vh)) evas_object_resize(wd->bx, w, vh);
701 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
703 EINA_INLIST_FOREACH(wd->items, it)
713 _mirrored_set(obj, elm_widget_mirrored_get(obj));
717 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
720 _resize(data, NULL, NULL, NULL);
724 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
726 Widget_Data *wd = elm_widget_data_get(data);
728 wd->resize_job = ecore_job_add(_resize_job, data);
732 _select_filter(Elm_Toolbar_Item *it, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
735 char buf[sizeof("elm,action,click,") + 1];
737 button = atoi(emission + sizeof("mouse,clicked,") - 1);
738 if (button == 1) return; /* regular left click event */
739 snprintf(buf, sizeof(buf), "elm,action,click,%d", button);
740 edje_object_signal_emit(VIEW(it), buf, "elm");
744 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
746 Elm_Toolbar_Item *it = data;
748 if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
749 (_elm_access_2nd_click_timeout(VIEW(it))))
751 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
752 _elm_access_say(E_("Selected"));
758 _long_press(Elm_Toolbar_Item *it)
760 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
761 wd->long_timer = NULL;
762 wd->long_press = EINA_TRUE;
763 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
764 return ECORE_CALLBACK_CANCEL;
768 _mouse_down(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Down *ev)
770 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
772 if (ev->button != 1) return;
773 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
774 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
775 wd->long_press = EINA_FALSE;
776 if (wd->long_timer) ecore_timer_interval_set(wd->long_timer, _elm_config->longpress_timeout);
777 else wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, (Ecore_Task_Cb)_long_press, it);
781 _mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
783 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
785 if (ev->button != 1) return;
788 ecore_timer_del(wd->long_timer);
789 wd->long_timer = NULL;
794 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
796 Elm_Toolbar_Item *it = data;
797 edje_object_signal_emit(VIEW(it), "elm,state,highlighted", "elm");
798 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
802 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
804 Elm_Toolbar_Item *it = data;
805 edje_object_signal_emit(VIEW(it), "elm,state,unhighlighted", "elm");
806 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
810 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
812 Evas_Object *obj = (Evas_Object *) data;
813 Widget_Data *wd = elm_widget_data_get(obj);
815 _els_box_layout(o, priv, !wd->vertical, wd->homogeneous,
816 elm_widget_mirrored_get(obj));
820 _access_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item)
822 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
823 const char *txt = item->access_info;
824 if (!txt) txt = it->label;
825 if (txt) return strdup(txt);
830 _access_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
832 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
834 return strdup(E_("Separator"));
835 else if (elm_widget_item_disabled_get(it))
836 return strdup(E_("State: Disabled"));
837 else if (it->selected)
838 return strdup(E_("State: Selected"));
840 return strdup(E_("Has menu"));
845 _item_del_pre_hook(Elm_Object_Item *it)
847 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
851 Elm_Toolbar_Item *item, *next;
852 item = (Elm_Toolbar_Item *) it;
854 wd = elm_widget_data_get(WIDGET(item));
855 if (!wd) return EINA_FALSE;
858 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
859 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
861 if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
862 if (wd->always_select && item->selected && next) _item_select(next);
869 static Elm_Toolbar_Item *
870 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
872 Widget_Data *wd = elm_widget_data_get(obj);
873 Evas_Object *icon_obj;
875 Elm_Toolbar_Item *it;
877 icon_obj = elm_icon_add(obj);
878 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
879 if (!icon_obj) return NULL;
880 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
883 evas_object_del(icon_obj);
887 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
888 elm_widget_item_disable_hook_set(it, _item_disable_hook);
889 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
890 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
892 it->label = eina_stringshare_add(label);
893 it->prio.visible = 1;
894 it->prio.priority = 0;
896 it->separator = EINA_FALSE;
897 it->base.data = data;
898 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
899 _elm_access_item_register(&it->base, VIEW(it));
900 _elm_access_text_set(_elm_access_item_get(&it->base),
901 ELM_ACCESS_TYPE, E_("Tool Item"));
902 _elm_access_callback_set(_elm_access_item_get(&it->base),
903 ELM_ACCESS_INFO, _access_info_cb, it);
904 _elm_access_callback_set(_elm_access_item_get(&it->base),
905 ELM_ACCESS_STATE, _access_state_cb, it);
907 if (_item_icon_set(icon_obj, "toolbar/", icon))
910 it->icon_str = eina_stringshare_add(icon);
916 evas_object_del(icon_obj);
919 _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
920 elm_widget_style_get(obj));
921 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "elm",
923 edje_object_signal_callback_add(VIEW(it), "mouse,clicked,*", "*",
924 (Edje_Signal_Cb)_select_filter, it);
925 edje_object_signal_callback_add(VIEW(it), "elm,mouse,in", "elm",
927 edje_object_signal_callback_add(VIEW(it), "elm,mouse,out", "elm",
929 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
930 (Evas_Object_Event_Cb)_mouse_down, it);
931 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
932 (Evas_Object_Event_Cb)_mouse_up, it);
933 elm_widget_sub_object_add(obj, VIEW(it));
938 ms = ((double)wd->icon_size * _elm_config->scale);
939 evas_object_size_hint_min_set(it->icon, ms, ms);
940 evas_object_size_hint_max_set(it->icon, ms, ms);
941 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
942 evas_object_show(it->icon);
943 elm_widget_sub_object_add(obj, it->icon);
945 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
947 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
948 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
949 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
950 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
954 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, -1.0);
955 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, 0.5);
959 evas_object_size_hint_weight_set(VIEW(it), -1.0, EVAS_HINT_EXPAND);
960 evas_object_size_hint_align_set(VIEW(it), 0.5, EVAS_HINT_FILL);
965 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
966 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, EVAS_HINT_FILL);
968 evas_object_size_hint_min_set(VIEW(it), mw, mh);
969 evas_object_size_hint_max_set(VIEW(it), -1, -1);
970 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
972 if ((!wd->items) && wd->always_select) _item_select(it);
978 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
980 Evas_Coord mw = -1, mh = -1;
981 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
982 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
984 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
985 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
986 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
987 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
991 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
992 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
996 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
997 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1002 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1003 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1005 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1009 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1011 Elm_Toolbar_Item *item = data;
1012 _elm_toolbar_item_label_update(item);
1013 edje_object_signal_callback_del(obj, emission, source,
1014 _elm_toolbar_item_label_set_cb);
1015 edje_object_signal_emit (VIEW(item), "elm,state,label,reset", "elm");
1019 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *signal)
1023 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
1025 eina_stringshare_replace(&item->label, label);
1026 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1027 if ((s) && (atoi(s)))
1029 edje_object_part_text_set(VIEW(item), "elm.text_new", item->label);
1030 edje_object_signal_emit (VIEW(item), signal, "elm");
1031 edje_object_signal_callback_add(VIEW(item),
1032 "elm,state,label_set,done", "elm",
1033 _elm_toolbar_item_label_set_cb, item);
1036 _elm_toolbar_item_label_update(item);
1037 _resize(WIDGET(item), NULL, NULL, NULL);
1041 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
1043 Elm_Toolbar_Item_State *it_state;
1045 Evas_Coord mw = -1, mh = -1;
1046 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1047 Evas_Object *old_icon = edje_object_part_swallow_get(VIEW(item),
1048 "elm.swallow.icon");
1049 elm_widget_sub_object_del(VIEW(item), old_icon);
1050 evas_object_hide(old_icon);
1051 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1052 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1053 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1054 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1055 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1059 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1060 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1064 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1065 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1070 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1071 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1073 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1075 EINA_LIST_FOREACH(item->states, l, it_state)
1077 if (it_state->icon == old_icon) return;
1079 evas_object_del(old_icon);
1083 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1085 Elm_Toolbar_Item *item = data;
1086 edje_object_part_unswallow(VIEW(item), item->icon);
1087 _elm_toolbar_item_icon_update(item);
1088 edje_object_signal_callback_del(obj, emission, source,
1089 _elm_toolbar_item_icon_set_cb);
1090 edje_object_signal_emit (VIEW(item), "elm,state,icon,reset", "elm");
1094 _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)
1096 Evas_Object *old_icon;
1101 eina_stringshare_replace(&item->icon_str, icon_str);
1104 eina_stringshare_del(item->icon_str);
1105 item->icon_str = NULL;
1107 item->icon = icon_obj;
1110 ms = (icon_size * _elm_config->scale);
1111 evas_object_size_hint_min_set(item->icon, ms, ms);
1112 evas_object_size_hint_max_set(item->icon, ms, ms);
1113 evas_object_show(item->icon);
1114 elm_widget_sub_object_add(obj, item->icon);
1116 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1117 if ((s) && (atoi(s)))
1119 old_icon = edje_object_part_swallow_get(VIEW(item),
1120 "elm.swallow.icon_new");
1123 elm_widget_sub_object_del(VIEW(item), old_icon);
1124 evas_object_hide(old_icon);
1126 edje_object_part_swallow(VIEW(item), "elm.swallow.icon_new",
1128 edje_object_signal_emit (VIEW(item), signal, "elm");
1129 edje_object_signal_callback_add(VIEW(item),
1130 "elm,state,icon_set,done", "elm",
1131 _elm_toolbar_item_icon_set_cb, item);
1134 _elm_toolbar_item_icon_update(item);
1135 _resize(obj, NULL, NULL, NULL);
1139 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1141 Elm_Toolbar_Item *it = event_info;
1142 Elm_Toolbar_Item_State *it_state;
1144 it_state = eina_list_data_get(it->current_state);
1146 it_state->func((void *)it_state->data, obj, event_info);
1149 static Elm_Toolbar_Item_State *
1150 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1152 Elm_Toolbar_Item_State *it_state;
1153 it_state = ELM_NEW(Elm_Toolbar_Item_State);
1154 it_state->label = eina_stringshare_add(label);
1155 it_state->icon_str = eina_stringshare_add(icon_str);
1156 it_state->icon = icon;
1157 it_state->func = func;
1158 it_state->data = data;
1163 elm_toolbar_add(Evas_Object *parent)
1169 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1171 ELM_SET_WIDTYPE(widtype, "toolbar");
1172 elm_widget_type_set(obj, "toolbar");
1173 elm_widget_sub_object_add(parent, obj);
1174 elm_widget_data_set(obj, wd);
1175 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1176 elm_widget_del_hook_set(obj, _del_hook);
1177 elm_widget_theme_hook_set(obj, _theme_hook);
1178 elm_widget_translate_hook_set(obj, _translate_hook);
1179 elm_widget_can_focus_set(obj, EINA_FALSE);
1181 wd->more_item = NULL;
1182 wd->selected_item = NULL;
1183 wd->scr = elm_smart_scroller_add(e);
1184 elm_smart_scroller_widget_set(wd->scr, obj);
1185 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
1186 elm_smart_scroller_bounce_allow_set(wd->scr,
1187 _elm_config->thumbscroll_bounce_enable,
1189 elm_widget_resize_object_set(obj, wd->scr);
1190 elm_smart_scroller_policy_set(wd->scr,
1191 ELM_SMART_SCROLLER_POLICY_AUTO,
1192 ELM_SMART_SCROLLER_POLICY_OFF);
1195 wd->icon_size = _elm_toolbar_icon_size_get(wd);
1198 wd->homogeneous = EINA_TRUE;
1201 wd->bx = evas_object_box_add(e);
1202 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
1203 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
1204 elm_widget_sub_object_add(obj, wd->bx);
1205 elm_smart_scroller_child_set(wd->scr, wd->bx);
1206 evas_object_show(wd->bx);
1208 elm_toolbar_shrink_mode_set(obj, _elm_config->toolbar_shrink_mode);
1209 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
1210 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
1211 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
1213 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1220 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
1222 ELM_CHECK_WIDTYPE(obj, widtype);
1223 Widget_Data *wd = elm_widget_data_get(obj);
1225 if (wd->icon_size == icon_size) return;
1226 wd->icon_size = icon_size;
1231 elm_toolbar_icon_size_get(const Evas_Object *obj)
1233 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1234 Widget_Data *wd = elm_widget_data_get(obj);
1236 return wd->icon_size;
1239 EAPI Elm_Object_Item *
1240 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1242 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1243 Widget_Data *wd = elm_widget_data_get(obj);
1244 if (!wd) return NULL;
1246 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1247 if (!it) return NULL;
1248 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1250 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
1251 evas_object_box_append(wd->bx, VIEW(it));
1252 evas_object_show(VIEW(it));
1254 _theme_hook_item(obj, it, scale, wd->icon_size);
1257 return (Elm_Object_Item *) it;
1260 EAPI Elm_Object_Item *
1261 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1263 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1264 Widget_Data *wd = elm_widget_data_get(obj);
1265 if (!wd) return NULL;
1267 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1268 if (!it) return NULL;
1269 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1271 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1272 evas_object_box_prepend(wd->bx, VIEW(it));
1273 evas_object_show(VIEW(it));
1274 _theme_hook_item(obj, it, scale, wd->icon_size);
1277 return (Elm_Object_Item *) it;
1280 EAPI Elm_Object_Item *
1281 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)
1283 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1284 ELM_OBJ_ITEM_CHECK_OR_RETURN(before, NULL);
1286 Elm_Toolbar_Item *it, *_before;
1288 wd = elm_widget_data_get(obj);
1289 if (!wd) return NULL;
1290 _before = (Elm_Toolbar_Item *) before;
1291 it = _item_new(obj, icon, label, func, data);
1292 if (!it) return NULL;
1293 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1295 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1296 EINA_INLIST_GET(_before));
1297 evas_object_box_insert_before(wd->bx, VIEW(it), VIEW(_before));
1298 evas_object_show(VIEW(it));
1299 _theme_hook_item(obj, it, scale, wd->icon_size);
1302 return (Elm_Object_Item *) it;
1305 EAPI Elm_Object_Item *
1306 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)
1308 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1309 ELM_OBJ_ITEM_CHECK_OR_RETURN(after, NULL);
1311 Elm_Toolbar_Item *it, *_after;
1313 wd = elm_widget_data_get(obj);
1314 if (!wd) return NULL;
1315 _after = (Elm_Toolbar_Item *) after;
1316 it = _item_new(obj, icon, label, func, data);
1317 if (!it) return NULL;
1318 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1320 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1321 EINA_INLIST_GET(_after));
1322 evas_object_box_insert_after(wd->bx, VIEW(it), VIEW(_after));
1323 evas_object_show(VIEW(it));
1324 _theme_hook_item(obj, it, scale, wd->icon_size);
1327 return (Elm_Object_Item *) it;
1330 EAPI Elm_Object_Item *
1331 elm_toolbar_first_item_get(const Evas_Object *obj)
1333 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1334 Widget_Data *wd = elm_widget_data_get(obj);
1335 if (!wd || !wd->items) return NULL;
1336 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1339 EAPI Elm_Object_Item *
1340 elm_toolbar_last_item_get(const Evas_Object *obj)
1342 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1343 Widget_Data *wd = elm_widget_data_get(obj);
1344 if (!wd || !wd->items) return NULL;
1345 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1348 EAPI Elm_Object_Item *
1349 elm_toolbar_item_next_get(const Elm_Object_Item *it)
1351 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1352 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1353 EINA_INLIST_GET(((Elm_Toolbar_Item *) it))->next);
1356 EAPI Elm_Object_Item *
1357 elm_toolbar_item_prev_get(const Elm_Object_Item *it)
1359 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1360 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1361 EINA_INLIST_GET(((Elm_Toolbar_Item *) it))->prev);
1365 elm_toolbar_item_toolbar_get(const Elm_Object_Item *it)
1367 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1368 return elm_object_item_widget_get(it);
1372 elm_toolbar_item_priority_set(Elm_Object_Item *it, int priority)
1374 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1375 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1376 if (item->prio.priority == priority) return;
1377 item->prio.priority = priority;
1378 _resize(WIDGET(item), NULL, NULL, NULL);
1382 elm_toolbar_item_priority_get(const Elm_Object_Item *it)
1384 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
1385 return ((Elm_Toolbar_Item *) it)->prio.priority;
1389 elm_toolbar_item_label_get(const Elm_Object_Item *it)
1391 return _item_text_get_hook(it, NULL);
1395 elm_toolbar_item_label_set(Elm_Object_Item *it, const char *label)
1397 _item_text_set_hook(it, NULL, label);
1401 elm_toolbar_item_data_get(const Elm_Object_Item *it)
1403 return elm_object_item_data_get(it);
1407 elm_toolbar_item_data_set(Elm_Object_Item *it, const void *data)
1409 elm_object_item_data_set(it, (void *) data);
1412 EAPI Elm_Object_Item *
1413 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
1415 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1416 Elm_Toolbar_Item *it;
1417 Widget_Data *wd = elm_widget_data_get(obj);
1418 if (!wd) return NULL;
1420 EINA_INLIST_FOREACH(wd->items, it)
1422 if (!strcmp(it->label, label))
1423 return (Elm_Object_Item *) it;
1429 elm_toolbar_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1431 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1432 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1433 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1436 if (item->selected == selected) return;
1437 if (selected) _item_select(item);
1438 else _item_unselect(item);
1442 elm_toolbar_item_selected_get(const Elm_Object_Item *it)
1444 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1445 return ((Elm_Toolbar_Item *) it)->selected;
1448 EAPI Elm_Object_Item *
1449 elm_toolbar_selected_item_get(const Evas_Object *obj)
1451 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1452 Widget_Data *wd = elm_widget_data_get(obj);
1453 if (!wd) return NULL;
1454 return (Elm_Object_Item *) wd->selected_item;
1458 elm_toolbar_item_icon_set(Elm_Object_Item *it, const char *icon)
1460 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1462 Evas_Object *icon_obj;
1465 Elm_Toolbar_Item * item = (Elm_Toolbar_Item *) it;
1468 wd = elm_widget_data_get(obj);
1470 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1472 icon_obj = elm_icon_add(obj);
1473 if (!icon_obj) return;
1474 if (_item_icon_set(icon_obj, "toolbar/", icon))
1475 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1476 "elm,state,icon_set");
1479 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1480 "elm,state,icon_set");
1481 evas_object_del(icon_obj);
1486 elm_toolbar_item_icon_get(const Elm_Object_Item *it)
1488 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1489 return ((Elm_Toolbar_Item *) it)->icon_str;
1493 elm_toolbar_item_object_get(const Elm_Object_Item *it)
1495 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1499 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1502 wd = elm_widget_data_get(obj);
1503 if (!wd) return NULL;
1509 elm_toolbar_item_icon_object_get(Elm_Object_Item *it)
1511 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1512 return ((Elm_Toolbar_Item *) it)->icon;
1516 elm_toolbar_item_icon_memfile_set(Elm_Object_Item *it, const void *img, size_t size, const char *format, const char *key)
1518 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1520 Evas_Object *icon_obj;
1524 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1527 wd = elm_widget_data_get(obj);
1528 if (!wd) return EINA_FALSE;
1532 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1533 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1534 ret = _els_smart_icon_memfile_set(icon_obj, img, size, format, key);
1537 evas_object_del(icon_obj);
1540 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1541 "elm,state,icon_set");
1544 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1549 elm_toolbar_item_icon_file_set(Elm_Object_Item *it, const char *file, const char *key)
1551 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1553 Evas_Object *icon_obj;
1557 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1560 wd = elm_widget_data_get(obj);
1561 if (!wd) return EINA_FALSE;
1565 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1566 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1567 ret = _els_smart_icon_file_key_set(icon_obj, file, key);
1570 evas_object_del(icon_obj);
1573 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1574 "elm,state,icon_set");
1577 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1582 elm_toolbar_item_del(Elm_Object_Item *it)
1584 elm_object_item_del(it);
1588 elm_toolbar_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
1590 elm_object_item_del_cb_set(it, func);
1594 elm_toolbar_item_disabled_get(const Elm_Object_Item *it)
1596 return elm_object_item_disabled_get(it);
1600 elm_toolbar_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
1602 elm_object_item_disabled_set(it, disabled);
1606 elm_toolbar_item_separator_set(Elm_Object_Item *it, Eina_Bool separator)
1608 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1609 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1610 Evas_Object *obj = WIDGET(item);
1611 Widget_Data *wd = elm_widget_data_get(obj);
1613 if (item->separator == separator) return;
1614 item->separator = separator;
1615 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1616 _theme_hook_item(obj, item, scale, wd->icon_size);
1620 elm_toolbar_item_separator_get(const Elm_Object_Item *it)
1622 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1623 return ((Elm_Toolbar_Item *) it)->separator;
1627 elm_toolbar_shrink_mode_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1629 ELM_CHECK_WIDTYPE(obj, widtype);
1630 Widget_Data *wd = elm_widget_data_get(obj);
1634 wd->shrink_mode = shrink_mode;
1635 bounce = (_elm_config->thumbscroll_bounce_enable) &&
1636 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1637 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1641 _item_del(wd->more_item);
1642 elm_widget_item_free(wd->more_item);
1643 wd->more_item = NULL;
1646 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1648 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1649 ELM_SMART_SCROLLER_POLICY_OFF);
1650 wd->more_item = _item_new(obj, "more_menu", "More", NULL, NULL);
1652 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1653 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1654 ELM_SMART_SCROLLER_POLICY_OFF);
1656 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1657 ELM_SMART_SCROLLER_POLICY_OFF);
1661 EAPI Elm_Toolbar_Shrink_Mode
1662 elm_toolbar_shrink_mode_get(const Evas_Object *obj)
1664 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1665 Widget_Data *wd = elm_widget_data_get(obj);
1667 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1668 return wd->shrink_mode;
1672 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
1674 ELM_CHECK_WIDTYPE(obj, widtype);
1675 Widget_Data *wd = elm_widget_data_get(obj);
1678 wd->homogeneous = !!homogeneous;
1679 evas_object_smart_calculate(wd->bx);
1683 elm_toolbar_homogeneous_get(const Evas_Object *obj)
1685 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1686 Widget_Data *wd = elm_widget_data_get(obj);
1688 if (!wd) return EINA_FALSE;
1689 return wd->homogeneous;
1693 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1695 Elm_Toolbar_Item *it;
1696 ELM_CHECK_WIDTYPE(obj, widtype);
1697 Widget_Data *wd = elm_widget_data_get(obj);
1700 EINA_SAFETY_ON_NULL_RETURN(parent);
1701 wd->menu_parent = parent;
1702 EINA_INLIST_FOREACH(wd->items, it)
1705 elm_menu_parent_set(it->o_menu, wd->menu_parent);
1707 if ((wd->more_item) && (wd->more_item->o_menu))
1708 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1712 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1714 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1715 Widget_Data *wd = elm_widget_data_get(obj);
1717 if (!wd) return NULL;
1718 return wd->menu_parent;
1722 elm_toolbar_align_set(Evas_Object *obj, double align)
1724 ELM_CHECK_WIDTYPE(obj, widtype);
1725 Widget_Data *wd = elm_widget_data_get(obj);
1730 if (wd->align != align)
1731 evas_object_size_hint_align_set(wd->bx, 0.5, align);
1735 if (wd->align != align)
1736 evas_object_size_hint_align_set(wd->bx, align, 0.5);
1742 elm_toolbar_align_get(const Evas_Object *obj)
1744 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1745 Widget_Data *wd = elm_widget_data_get(obj);
1747 if (!wd) return 0.0;
1752 elm_toolbar_item_menu_set(Elm_Object_Item *it, Eina_Bool menu)
1754 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1755 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1756 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1759 if (item->menu == menu) return;
1760 if (menu) _item_menu_create(wd, item);
1761 else _item_menu_destroy(item);
1765 elm_toolbar_item_menu_get(const Elm_Object_Item *it)
1767 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1768 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1769 if (!item->menu) return NULL;
1770 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1771 if (!wd) return NULL;
1772 return item->o_menu;
1775 EAPI Elm_Toolbar_Item_State *
1776 elm_toolbar_item_state_add(Elm_Object_Item *it, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1778 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1780 Elm_Toolbar_Item_State *it_state;
1781 Evas_Object *icon_obj;
1784 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1786 wd = elm_widget_data_get(WIDGET(item));
1787 if (!wd) return NULL;
1791 it_state = _item_state_new(item->label, item->icon_str, item->icon,
1792 item->func, item->base.data);
1793 item->states = eina_list_append(item->states, it_state);
1794 item->current_state = item->states;
1797 icon_obj = elm_icon_add(obj);
1798 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1799 if (!icon_obj) goto error_state_add;
1801 if (!_item_icon_set(icon_obj, "toolbar/", icon))
1803 evas_object_del(icon_obj);
1808 it_state = _item_state_new(label, icon, icon_obj, func, data);
1809 item->states = eina_list_append(item->states, it_state);
1810 item->func = _elm_toolbar_item_state_cb;
1811 item->base.data = NULL;
1816 if (item->states && !eina_list_next(item->states))
1818 eina_stringshare_del(item->label);
1819 eina_stringshare_del(item->icon_str);
1820 free(eina_list_data_get(item->states));
1821 eina_list_free(item->states);
1822 item->states = NULL;
1828 elm_toolbar_item_state_del(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1830 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1832 Eina_List *del_state;
1833 Elm_Toolbar_Item_State *it_state;
1834 Elm_Toolbar_Item *item;
1836 if (!state) return EINA_FALSE;
1838 item = (Elm_Toolbar_Item *) it;
1839 if (!item->states) return EINA_FALSE;
1841 del_state = eina_list_data_find_list(item->states, state);
1842 if (del_state == item->states) return EINA_FALSE;
1843 if (del_state == item->current_state)
1844 elm_toolbar_item_state_unset(it);
1846 eina_stringshare_del(state->label);
1847 eina_stringshare_del(state->icon_str);
1848 if (state->icon) evas_object_del(state->icon);
1850 item->states = eina_list_remove_list(item->states, del_state);
1851 if (item->states && !eina_list_next(item->states))
1853 it_state = eina_list_data_get(item->states);
1854 item->base.data = it_state->data;
1855 item->func = it_state->func;
1856 eina_stringshare_del(it_state->label);
1857 eina_stringshare_del(it_state->icon_str);
1858 free(eina_list_data_get(item->states));
1859 eina_list_free(item->states);
1860 item->states = NULL;
1866 elm_toolbar_item_state_set(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1868 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1871 Eina_List *next_state;
1872 Elm_Toolbar_Item_State *it_state;
1874 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1877 wd = elm_widget_data_get(obj);
1878 if (!wd) return EINA_FALSE;
1879 if (!item->states) return EINA_FALSE;
1883 next_state = eina_list_data_find_list(item->states, state);
1884 if (!next_state) return EINA_FALSE;
1887 next_state = item->states;
1889 if (next_state == item->current_state) return EINA_TRUE;
1891 it_state = eina_list_data_get(next_state);
1892 if (eina_list_data_find(item->current_state, state))
1894 _item_label_set(item, it_state->label, "elm,state,label_set,forward");
1895 _elm_toolbar_item_icon_obj_set(obj, item, it_state->icon, it_state->icon_str,
1896 wd->icon_size, "elm,state,icon_set,forward");
1900 _item_label_set(item, it_state->label, "elm,state,label_set,backward");
1901 _elm_toolbar_item_icon_obj_set(obj,
1906 "elm,state,icon_set,backward");
1908 if (elm_widget_item_disabled_get(item))
1909 elm_widget_signal_emit(item->icon, "elm,state,disabled", "elm");
1911 elm_widget_signal_emit(item->icon, "elm,state,enabled", "elm");
1913 item->current_state = next_state;
1918 elm_toolbar_item_state_unset(Elm_Object_Item *it)
1920 elm_toolbar_item_state_set(it, NULL);
1923 EAPI Elm_Toolbar_Item_State *
1924 elm_toolbar_item_state_get(const Elm_Object_Item *it)
1926 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1927 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1929 if ((!item->states) || (!item->current_state)) return NULL;
1930 if (item->current_state == item->states) return NULL;
1932 return eina_list_data_get(item->current_state);
1935 EAPI Elm_Toolbar_Item_State *
1936 elm_toolbar_item_state_next(Elm_Object_Item *it)
1938 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1942 Eina_List *next_state;
1943 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1946 wd = elm_widget_data_get(obj);
1947 if (!wd) return NULL;
1948 if (!item->states) return NULL;
1950 next_state = eina_list_next(item->current_state);
1952 next_state = eina_list_next(item->states);
1953 return eina_list_data_get(next_state);
1956 EAPI Elm_Toolbar_Item_State *
1957 elm_toolbar_item_state_prev(Elm_Object_Item *it)
1959 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1963 Eina_List *prev_state;
1964 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
1967 wd = elm_widget_data_get(obj);
1968 if (!wd) return NULL;
1969 if (!item->states) return NULL;
1971 prev_state = eina_list_prev(item->current_state);
1972 if ((!prev_state) || (prev_state == item->states))
1973 prev_state = eina_list_last(item->states);
1974 return eina_list_data_get(prev_state);
1978 elm_toolbar_item_tooltip_text_set(Elm_Object_Item *it, const char *text)
1980 elm_object_item_tooltip_text_set(it, text);
1984 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)
1986 elm_object_item_tooltip_content_cb_set(it, func, data, del_cb);
1990 elm_toolbar_item_tooltip_unset(Elm_Object_Item *it)
1992 elm_object_item_tooltip_unset(it);
1996 elm_toolbar_item_tooltip_style_set(Elm_Object_Item *it, const char *style)
1998 elm_object_item_tooltip_style_set(it, style);
2002 elm_toolbar_item_tooltip_style_get(const Elm_Object_Item *it)
2004 return elm_object_item_tooltip_style_get(it);
2008 elm_toolbar_item_cursor_set(Elm_Object_Item *it, const char *cursor)
2010 elm_object_item_cursor_set(it, cursor);
2014 elm_toolbar_item_cursor_get(const Elm_Object_Item *it)
2016 return elm_object_item_cursor_get(it);
2020 elm_toolbar_item_cursor_unset(Elm_Object_Item *it)
2022 elm_object_item_cursor_unset(it);
2026 elm_toolbar_item_cursor_style_set(Elm_Object_Item *it, const char *style)
2028 elm_object_item_cursor_style_set(it, style);
2032 elm_toolbar_item_cursor_style_get(const Elm_Object_Item *it)
2034 return elm_object_item_cursor_style_get(it);
2038 elm_toolbar_item_cursor_engine_only_set(Elm_Object_Item *it, Eina_Bool engine_only)
2040 elm_object_item_cursor_engine_only_set(it, engine_only);
2044 elm_toolbar_item_cursor_engine_only_get(const Elm_Object_Item *it)
2046 return elm_object_item_cursor_engine_only_get(it);
2050 elm_toolbar_always_select_mode_set(Evas_Object *obj, Eina_Bool always_select)
2052 ELM_CHECK_WIDTYPE(obj, widtype);
2053 Widget_Data *wd = elm_widget_data_get(obj);
2055 if (always_select && (!wd->always_select) && wd->items)
2056 _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
2057 wd->always_select = always_select;
2061 elm_toolbar_always_select_mode_get(const Evas_Object *obj)
2063 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2064 Widget_Data *wd = elm_widget_data_get(obj);
2065 if (!wd) return EINA_FALSE;
2066 return wd->always_select;
2070 elm_toolbar_no_select_mode_set(Evas_Object *obj, Eina_Bool no_select)
2072 ELM_CHECK_WIDTYPE(obj, widtype);
2073 Widget_Data *wd = elm_widget_data_get(obj);
2075 wd->no_select = no_select;
2079 elm_toolbar_no_select_mode_get(const Evas_Object *obj)
2081 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2082 Widget_Data *wd = elm_widget_data_get(obj);
2083 if (!wd) return EINA_FALSE;
2084 return wd->no_select;
2088 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
2090 ELM_CHECK_WIDTYPE(obj, widtype);
2091 Elm_Toolbar_Item *it;
2092 Widget_Data *wd = elm_widget_data_get(obj);
2095 wd->lookup_order = order;
2096 EINA_INLIST_FOREACH(wd->items, it)
2097 elm_icon_order_lookup_set(it->icon, order);
2099 elm_icon_order_lookup_set(wd->more_item->icon, order);
2102 EAPI Elm_Icon_Lookup_Order
2103 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
2105 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
2106 Widget_Data *wd = elm_widget_data_get(obj);
2107 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
2108 return wd->lookup_order;
2111 EINA_DEPRECATED EAPI void
2112 elm_toolbar_orientation_set(Evas_Object *obj, Eina_Bool vertical)
2114 elm_toolbar_horizontal_set(obj, !vertical);
2117 EINA_DEPRECATED EAPI Eina_Bool
2118 elm_toolbar_orientation_get(const Evas_Object *obj)
2120 return !elm_toolbar_horizontal_get(obj);
2124 elm_toolbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
2126 ELM_CHECK_WIDTYPE(obj, widtype);
2127 Widget_Data *wd = elm_widget_data_get(obj);
2129 wd->vertical = !horizontal;
2131 evas_object_size_hint_align_set(wd->bx, 0.5, wd->align);
2133 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
2138 elm_toolbar_horizontal_get(const Evas_Object *obj)
2140 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2141 Widget_Data *wd = elm_widget_data_get(obj);
2142 if (!wd) return EINA_FALSE;
2143 return !wd->vertical;
2147 elm_toolbar_items_count(const Evas_Object *obj)
2149 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2150 Widget_Data *wd = elm_widget_data_get(obj);
2152 return wd->item_count;
2155 EINA_DEPRECATED EAPI void
2156 elm_toolbar_mode_shrink_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
2158 elm_toolbar_shrink_mode_set(obj, shrink_mode);
2161 EINA_DEPRECATED EAPI Elm_Toolbar_Shrink_Mode
2162 elm_toolbar_mode_shrink_get(const Evas_Object *obj)
2164 return elm_toolbar_shrink_mode_get(obj);