1 #include <Elementary.h>
3 #include "els_scroller.h"
7 typedef struct _Widget_Data Widget_Data;
8 typedef struct _Elm_Toolbar_Item Elm_Toolbar_Item;
12 Evas_Object *scr, *bx;
13 Evas_Object *menu_parent;
15 Elm_Toolbar_Item *more_item, *selected_item;
16 Elm_Toolbar_Shrink_Mode shrink_mode;
17 Elm_Icon_Lookup_Order lookup_order;
19 unsigned int item_count;
21 Elm_Object_Select_Mode select_mode;
22 Eina_Bool homogeneous : 1;
23 Eina_Bool vertical : 1;
24 Eina_Bool long_press : 1;
25 Ecore_Timer *long_timer;
26 Ecore_Job *resize_job;
29 struct _Elm_Toolbar_Item
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 *sig);
77 static void _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *sig);
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)
94 Elm_Toolbar_Item *toolbar_it = (Elm_Toolbar_Item *)it;
96 wd = elm_widget_data_get(WIDGET(toolbar_it));
99 if (elm_widget_item_disabled_get(toolbar_it))
101 edje_object_signal_emit(VIEW(toolbar_it), "elm,state,disabled", "elm");
102 elm_widget_signal_emit(toolbar_it->icon, "elm,state,disabled", "elm");
106 edje_object_signal_emit(VIEW(toolbar_it), "elm,state,enabled", "elm");
107 elm_widget_signal_emit(toolbar_it->icon, "elm,state,enabled", "elm");
109 _resize(WIDGET(toolbar_it), NULL, NULL, NULL);
113 _item_icon_set(Evas_Object *icon_obj, const char *type, const char *icon)
117 if ((!type) || (!*type)) goto end;
118 if ((!icon) || (!*icon)) return EINA_FALSE;
119 if ((snprintf(icon_str, sizeof(icon_str), "%s%s", type, icon) > 0)
120 && (elm_icon_standard_set(icon_obj, icon_str)))
123 if (elm_icon_standard_set(icon_obj, icon))
125 WRN("couldn't find icon definition for '%s'", icon);
130 _elm_toolbar_icon_size_get(Widget_Data *wd)
132 const char *icon_size = edje_object_data_get(
133 elm_smart_scroller_edje_object_get(wd->scr), "icon_size");
135 return atoi(icon_size);
136 return _elm_config->icon_size;
140 _item_show(Elm_Toolbar_Item *it)
142 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
143 Evas_Coord x, y, w, h, bx, by;
146 evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
147 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
148 elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
152 _item_unselect(Elm_Toolbar_Item *item)
155 if ((!item) || (!item->selected)) return;
156 wd = elm_widget_data_get(WIDGET(item));
158 item->selected = EINA_FALSE;
159 wd->selected_item = NULL;
160 edje_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
161 elm_widget_signal_emit(item->icon, "elm,state,unselected", "elm");
165 _item_select(Elm_Toolbar_Item *it)
167 Elm_Toolbar_Item *it2;
168 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
173 if (elm_widget_item_disabled_get(it) || (it->separator) || (it->object)) return;
176 if (wd->select_mode != ELM_OBJECT_SELECT_MODE_NONE)
180 if (wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS) return;
185 it2 = (Elm_Toolbar_Item *)
186 elm_toolbar_selected_item_get(WIDGET(it));
189 it->selected = EINA_TRUE;
190 wd->selected_item = it;
191 edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
192 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
197 if (it->menu && (!sel))
199 evas_object_show(it->o_menu);
200 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
201 _menu_move_resize, it);
202 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOVE,
203 _menu_move_resize, it);
205 _menu_move_resize(it, NULL, NULL, NULL);
207 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
208 evas_object_smart_callback_call(obj2, SIG_CLICKED, it);
212 _menu_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
214 Elm_Toolbar_Item *selected;
215 Elm_Toolbar_Item *it = data;
216 selected = (Elm_Toolbar_Item *) elm_toolbar_selected_item_get(WIDGET(it));
217 _item_unselect(selected);
221 _menu_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
223 // avoid hide being emitted during object deletion
224 evas_object_event_callback_del_full
225 (obj, EVAS_CALLBACK_HIDE, _menu_hide, data);
229 _menu_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
231 Elm_Toolbar_Item *it = data;
233 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
235 if ((!wd) || (!wd->menu_parent)) return;
236 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
237 elm_menu_move(it->o_menu, x, y+h);
241 _item_del(Elm_Toolbar_Item *it)
243 Elm_Toolbar_Item_State *it_state;
245 EINA_LIST_FREE(it->states, it_state)
247 if (it->icon == it_state->icon)
249 eina_stringshare_del(it_state->label);
250 eina_stringshare_del(it_state->icon_str);
251 if (it_state->icon) evas_object_del(it_state->icon);
254 eina_stringshare_del(it->label);
255 eina_stringshare_del(it->icon_str);
256 if (it->icon) evas_object_del(it->icon);
257 if (it->object) evas_object_del(it->object);
258 //TODO: See if checking for wd->menu_parent is necessary before deleting menu
259 if (it->o_menu) evas_object_del(it->o_menu);
263 _del_pre_hook(Evas_Object *obj)
265 Widget_Data *wd = elm_widget_data_get(obj);
266 Elm_Toolbar_Item *it, *next;
269 it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
272 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
274 elm_widget_item_free(it);
279 _item_del(wd->more_item);
280 elm_widget_item_free(wd->more_item);
284 ecore_timer_del(wd->long_timer);
285 wd->long_timer = NULL;
290 _del_hook(Evas_Object *obj)
292 Widget_Data *wd = elm_widget_data_get(obj);
300 _mirrored_set_item(Evas_Object *obj __UNUSED__, Elm_Toolbar_Item *it, Eina_Bool mirrored)
302 edje_object_mirrored_set(VIEW(it), mirrored);
303 elm_widget_mirrored_set(it->o_menu, mirrored);
307 _theme_hook_item(Evas_Object *obj, Elm_Toolbar_Item *it, double scale, int icon_size)
309 Widget_Data *wd = elm_widget_data_get(obj);
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);
316 if (!it->separator && !it->object)
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", it->icon);
338 edje_object_part_text_set(view, "elm.text", it->label);
344 _elm_theme_object_set(obj, view, "toolbar", "separator", style);
347 evas_object_size_hint_weight_set(view, EVAS_HINT_EXPAND, -1.0);
348 evas_object_size_hint_align_set(view, EVAS_HINT_FILL, 0.5);
352 evas_object_size_hint_weight_set(view, -1.0, EVAS_HINT_EXPAND);
353 evas_object_size_hint_align_set(view, 0.5, EVAS_HINT_FILL);
358 _elm_theme_object_set(obj, view, "toolbar", "object", style);
359 edje_object_part_swallow(view, "elm.swallow.object", it->object);
364 if (!it->separator && !it->object)
365 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
366 edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
367 if (!it->separator && !it->object)
368 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
369 evas_object_size_hint_min_set(view, mw, mh);
373 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
375 Widget_Data *wd = elm_widget_data_get(obj);
376 Elm_Toolbar_Item *it;
378 EINA_INLIST_FOREACH(wd->items, it)
379 _mirrored_set_item(obj, it, mirrored);
381 _mirrored_set_item(obj, wd->more_item, mirrored);
385 _theme_hook(Evas_Object *obj)
387 Widget_Data *wd = elm_widget_data_get(obj);
388 Elm_Toolbar_Item *it;
392 _elm_widget_mirrored_reload(obj);
393 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
394 _mirrored_set(obj, elm_widget_mirrored_get(obj));
395 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
396 edje_object_scale_set(wd->scr, scale);
397 wd->icon_size = _elm_toolbar_icon_size_get(wd);
398 EINA_INLIST_FOREACH(wd->items, it)
399 _theme_hook_item(obj, it, scale, wd->icon_size);
401 _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
406 _item_text_set_hook(Elm_Object_Item *it,
410 if (part && strcmp(part, "default")) return;
411 _item_label_set(((Elm_Toolbar_Item *)it), label, "elm,state,label_set");
415 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
417 if (part && strcmp(part, "default")) return NULL;
418 return ((Elm_Toolbar_Item *)it)->label;
422 _item_content_set_hook(Elm_Object_Item *it,
424 Evas_Object *content)
428 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
429 if (part && strcmp(part, "object")) return;
430 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
431 Evas_Object *obj = WIDGET(item);
432 Widget_Data *wd = elm_widget_data_get(obj);
434 if (item->object == content) return;
435 item->object = content;
436 elm_widget_sub_object_add(obj, item->object);
437 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
438 _theme_hook_item(obj, item, scale, wd->icon_size);
442 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
444 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
445 if (part && strcmp(part, "object")) return NULL;
446 return ((Elm_Toolbar_Item *) it)->object;
450 _item_content_unset_hook(Elm_Object_Item *it, const char *part)
455 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
456 if (part && strcmp(part, "object")) return NULL;
457 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
458 Evas_Object *obj = WIDGET(item);
459 Widget_Data *wd = elm_widget_data_get(obj);
461 edje_object_part_unswallow(VIEW(it), item->object);
462 elm_widget_sub_object_del(obj, item->object);
465 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
466 _theme_hook_item(obj, item, scale, wd->icon_size);
471 _translate_hook(Evas_Object *obj)
473 evas_object_smart_callback_call(obj, "language,changed", NULL);
477 _sizing_eval(Evas_Object *obj)
479 Widget_Data *wd = elm_widget_data_get(obj);
480 Evas_Coord minw = -1, minh = -1, minw_bx = -1, minh_bx = -1;
481 Evas_Coord vw = 0, vh = 0;
485 evas_object_smart_need_recalculate_set(wd->bx, EINA_TRUE);
486 evas_object_smart_calculate(wd->bx);
487 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
489 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
490 if (w < minw) w = minw;
491 if (h < minh) h = minh;
492 evas_object_resize(wd->scr, w, h);
494 evas_object_size_hint_min_get(wd->bx, &minw_bx, &minh_bx);
495 // if (wd->vertical && (h > minh)) minh = h;
496 // if ((!wd->vertical) && (w > minw)) minw = w;
497 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
498 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_NONE)
502 minw = minw_bx + (w - vw);
503 minh = minh_bx + (h - vh);
507 minw = minw_bx + (w - vw);
508 minh = minh_bx + (h - vh);
511 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
513 minw = minw_bx + (w - vw);
514 minh = minh_bx + (h - vh);
515 if (minw_bx < vw) minw_bx = vw;
516 if (minh_bx < vh) minh_bx = vh;
522 minw = minw_bx + (w - vw);
528 minh = minh_bx + (h - vh);
530 // if (wd->vertical) minh = h - vh;
531 // else minw = w - vw;
532 // minh = minh + (h - vh);
534 evas_object_resize(wd->bx, minw_bx, minh_bx);
535 evas_object_size_hint_min_set(obj, minw, minh);
536 evas_object_size_hint_max_set(obj, -1, -1);
540 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
542 item->o_menu = elm_menu_add(VIEW(item));
543 item->menu = EINA_TRUE;
545 elm_menu_parent_set(item->o_menu, wd->menu_parent);
546 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
548 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
553 _item_menu_destroy(Elm_Toolbar_Item *item)
557 evas_object_del(item->o_menu);
560 item->menu = EINA_FALSE;
564 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
566 const Elm_Toolbar_Item *eti1 = i1;
567 const Elm_Toolbar_Item *eti2 = i2;
570 if (!eti1) return -1;
572 return eti2->prio.priority - eti1->prio.priority;
576 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
578 Elm_Toolbar_Item *it;
579 Eina_List *sorted = NULL;
580 Evas_Coord ciw = 0, cih = 0;
582 EINA_INLIST_FOREACH(wd->items, it)
584 sorted = eina_list_sorted_insert(sorted,
585 _toolbar_item_prio_compare_cb, it);
590 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL, &ciw, &cih);
591 if (wd->vertical) *iw += cih;
594 EINA_LIST_FREE(sorted, it)
596 evas_object_geometry_get(VIEW(it), NULL, NULL, &ciw, &cih);
597 if (wd->vertical) *iw += cih;
599 it->prio.visible = (*iw <= vw);
604 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
606 Elm_Toolbar_Item *it = data;
607 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
611 _resize_job(void *data)
613 Evas_Object *obj = (Evas_Object *)data;
614 Widget_Data *wd = elm_widget_data_get(obj);
615 Evas_Coord mw, mh, vw = 0, vh = 0, w = 0, h = 0;
616 Elm_Toolbar_Item *it;
619 wd->resize_job = NULL;
620 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
621 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
622 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
623 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
625 Evas_Coord iw = 0, ih = 0, more_w = 0, more_h = 0;
629 evas_object_resize(wd->bx, w, vh);
630 _fix_items_visibility(wd, &ih, vh);
634 evas_object_resize(wd->bx, vw, h);
635 _fix_items_visibility(wd, &iw, vw);
637 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL,
641 if ((ih - more_h) <= vh) ih -= more_h;
645 if ((iw - more_w) <= vw) iw -= more_w;
648 /* All items are removed from the box object, since removing individual
649 * items won't trigger a resize. Items are be readded below. */
650 evas_object_box_remove_all(wd->bx, EINA_FALSE);
651 if (((wd->vertical) && (ih > vh)) ||
652 ((!wd->vertical) && (iw > vw)))
656 _item_menu_destroy(wd->more_item);
657 _item_menu_create(wd, wd->more_item);
658 menu = elm_toolbar_item_menu_get((Elm_Object_Item *)wd->more_item);
659 EINA_INLIST_FOREACH(wd->items, it)
661 if (!it->prio.visible)
664 elm_menu_item_separator_add(menu, NULL);
667 Elm_Object_Item *menu_it;
668 menu_it = elm_menu_item_add
669 (menu, NULL, it->icon_str, it->label,
670 _elm_toolbar_item_menu_cb, it);
671 elm_object_item_disabled_set
672 (menu_it, elm_widget_item_disabled_get(it));
674 elm_menu_clone(it->o_menu, menu, menu_it);
676 evas_object_hide(VIEW(it));
680 evas_object_box_append(wd->bx, VIEW(it));
681 evas_object_show(VIEW(it));
684 evas_object_box_append(wd->bx, wd->VIEW(more_item));
685 evas_object_show(wd->VIEW(more_item));
689 /* All items are visible, show them all (except for the "More"
690 * button, of course). */
691 EINA_INLIST_FOREACH(wd->items, it)
693 evas_object_show(VIEW(it));
694 evas_object_box_append(wd->bx, VIEW(it));
696 evas_object_hide(wd->VIEW(more_item));
699 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
701 Evas_Coord iw = 0, ih = 0;
705 evas_object_resize(wd->bx, w, vh);
706 _fix_items_visibility(wd, &ih, vh);
710 evas_object_resize(wd->bx, vw, h);
711 _fix_items_visibility(wd, &iw, vw);
713 evas_object_box_remove_all(wd->bx, EINA_FALSE);
714 if (((wd->vertical) && (ih > vh)) ||
715 ((!wd->vertical) && (iw > vw)))
717 EINA_INLIST_FOREACH(wd->items, it)
719 if (!it->prio.visible)
720 evas_object_hide(VIEW(it));
723 evas_object_box_append(wd->bx, VIEW(it));
724 evas_object_show(VIEW(it));
730 /* All items are visible, show them all */
731 EINA_INLIST_FOREACH(wd->items, it)
733 evas_object_show(VIEW(it));
734 evas_object_box_append(wd->bx, VIEW(it));
738 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
740 if ((vw >= mw) && (vh >= mh))
741 evas_object_resize(wd->bx, vw, vh);
743 evas_object_resize(wd->bx, mw, vh);
745 evas_object_resize(wd->bx, vw, mh);
751 if ((vh >= mh) && (h != vh)) evas_object_resize(wd->bx, w, vh);
755 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
757 EINA_INLIST_FOREACH(wd->items, it)
767 _mirrored_set(obj, elm_widget_mirrored_get(obj));
771 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
774 _resize(data, NULL, NULL, NULL);
778 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
780 Widget_Data *wd = elm_widget_data_get(data);
782 wd->resize_job = ecore_job_add(_resize_job, data);
786 _select_filter(Elm_Toolbar_Item *it, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
789 char buf[sizeof("elm,action,click,") + 1];
791 button = atoi(emission + sizeof("mouse,clicked,") - 1);
792 if (button == 1) return; /* regular left click event */
793 snprintf(buf, sizeof(buf), "elm,action,click,%d", button);
794 edje_object_signal_emit(VIEW(it), buf, "elm");
798 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
800 Elm_Toolbar_Item *it = data;
802 if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
803 (_elm_access_2nd_click_timeout(VIEW(it))))
805 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
806 _elm_access_say(E_("Selected"));
812 _long_press(Elm_Toolbar_Item *it)
814 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
815 wd->long_timer = NULL;
816 wd->long_press = EINA_TRUE;
817 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
818 return ECORE_CALLBACK_CANCEL;
822 _mouse_down(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Down *ev)
824 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
826 if (ev->button != 1) return;
827 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
828 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
829 wd->long_press = EINA_FALSE;
830 if (wd->long_timer) ecore_timer_interval_set(wd->long_timer, _elm_config->longpress_timeout);
831 else wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, (Ecore_Task_Cb)_long_press, it);
835 _mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
837 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
839 if (ev->button != 1) return;
842 ecore_timer_del(wd->long_timer);
843 wd->long_timer = NULL;
848 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
850 Elm_Toolbar_Item *it = data;
851 edje_object_signal_emit(VIEW(it), "elm,state,highlighted", "elm");
852 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
856 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
858 Elm_Toolbar_Item *it = data;
859 edje_object_signal_emit(VIEW(it), "elm,state,unhighlighted", "elm");
860 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
864 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
866 Evas_Object *obj = (Evas_Object *) data;
867 Widget_Data *wd = elm_widget_data_get(obj);
869 _els_box_layout(o, priv, !wd->vertical, wd->homogeneous,
870 elm_widget_mirrored_get(obj));
874 _access_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item)
876 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
877 const char *txt = item->access_info;
878 if (!txt) txt = it->label;
879 if (txt) return strdup(txt);
884 _access_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
886 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
888 return strdup(E_("Separator"));
889 else if (elm_widget_item_disabled_get(it))
890 return strdup(E_("State: Disabled"));
891 else if (it->selected)
892 return strdup(E_("State: Selected"));
894 return strdup(E_("Has menu"));
899 _item_del_pre_hook(Elm_Object_Item *it)
903 Elm_Toolbar_Item *item, *next;
904 item = (Elm_Toolbar_Item *)it;
906 wd = elm_widget_data_get(WIDGET(item));
907 if (!wd) return EINA_FALSE;
910 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
911 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
913 if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
914 if ((wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
915 item->selected && next) _item_select(next);
922 static Elm_Toolbar_Item *
923 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
925 Widget_Data *wd = elm_widget_data_get(obj);
926 Evas_Object *icon_obj;
928 Elm_Toolbar_Item *it;
930 icon_obj = elm_icon_add(obj);
931 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
932 if (!icon_obj) return NULL;
933 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
936 evas_object_del(icon_obj);
940 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
941 elm_widget_item_disable_hook_set(it, _item_disable_hook);
942 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
943 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
944 elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
945 elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
946 elm_widget_item_content_unset_hook_set(it, _item_content_unset_hook);
948 it->label = eina_stringshare_add(label);
949 it->prio.visible = 1;
950 it->prio.priority = 0;
952 it->separator = EINA_FALSE;
954 it->base.data = data;
955 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
956 _elm_access_item_register(&it->base, VIEW(it));
957 _elm_access_text_set(_elm_access_item_get(&it->base),
958 ELM_ACCESS_TYPE, E_("Tool Item"));
959 _elm_access_callback_set(_elm_access_item_get(&it->base),
960 ELM_ACCESS_INFO, _access_info_cb, it);
961 _elm_access_callback_set(_elm_access_item_get(&it->base),
962 ELM_ACCESS_STATE, _access_state_cb, it);
964 if (_item_icon_set(icon_obj, "toolbar/", icon))
967 it->icon_str = eina_stringshare_add(icon);
973 evas_object_del(icon_obj);
976 _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
977 elm_widget_style_get(obj));
978 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "elm",
980 edje_object_signal_callback_add(VIEW(it), "mouse,clicked,*", "*",
981 (Edje_Signal_Cb)_select_filter, it);
982 edje_object_signal_callback_add(VIEW(it), "elm,mouse,in", "elm",
984 edje_object_signal_callback_add(VIEW(it), "elm,mouse,out", "elm",
986 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
987 (Evas_Object_Event_Cb)_mouse_down, it);
988 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
989 (Evas_Object_Event_Cb)_mouse_up, it);
990 elm_widget_sub_object_add(obj, VIEW(it));
995 ms = ((double)wd->icon_size * _elm_config->scale);
996 evas_object_size_hint_min_set(it->icon, ms, ms);
997 evas_object_size_hint_max_set(it->icon, ms, ms);
998 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
999 edje_object_signal_emit(VIEW(it), "elm,state,icon,visible", "elm");
1000 evas_object_show(it->icon);
1001 elm_widget_sub_object_add(obj, it->icon);
1005 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
1006 edje_object_signal_emit(VIEW(it), "elm,state,text,visible", "elm");
1009 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1010 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
1011 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1012 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1016 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, -1.0);
1017 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, 0.5);
1021 evas_object_size_hint_weight_set(VIEW(it), -1.0, EVAS_HINT_EXPAND);
1022 evas_object_size_hint_align_set(VIEW(it), 0.5, EVAS_HINT_FILL);
1027 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1028 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, EVAS_HINT_FILL);
1030 evas_object_size_hint_min_set(VIEW(it), mw, mh);
1031 evas_object_size_hint_max_set(VIEW(it), -1, -1);
1032 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
1034 if ((!wd->items) && (wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS))
1041 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
1043 Evas_Coord mw = -1, mh = -1;
1044 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1045 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
1046 edje_object_signal_emit(VIEW(item), "elm,state,text,visible", "elm");
1048 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1049 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1050 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1051 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1055 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1056 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1060 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1061 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1066 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1067 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1069 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1073 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1075 Elm_Toolbar_Item *item = data;
1076 _elm_toolbar_item_label_update(item);
1077 edje_object_signal_callback_del(obj, emission, source,
1078 _elm_toolbar_item_label_set_cb);
1079 edje_object_signal_emit (VIEW(item), "elm,state,label,reset", "elm");
1083 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *sig)
1087 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
1089 eina_stringshare_replace(&item->label, label);
1090 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1091 if ((s) && (atoi(s)))
1093 edje_object_part_text_set(VIEW(item), "elm.text_new", item->label);
1094 edje_object_signal_emit (VIEW(item), sig, "elm");
1095 edje_object_signal_callback_add(VIEW(item),
1096 "elm,state,label_set,done", "elm",
1097 _elm_toolbar_item_label_set_cb, item);
1100 _elm_toolbar_item_label_update(item);
1101 _resize(WIDGET(item), NULL, NULL, NULL);
1105 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
1107 Elm_Toolbar_Item_State *it_state;
1109 Evas_Coord mw = -1, mh = -1;
1110 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1111 Evas_Object *old_icon = edje_object_part_swallow_get(VIEW(item),
1112 "elm.swallow.icon");
1113 elm_widget_sub_object_del(VIEW(item), old_icon);
1114 evas_object_hide(old_icon);
1115 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1116 edje_object_signal_emit(VIEW(item), "elm,state,icon,visible", "elm");
1117 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1118 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1119 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1120 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1124 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1125 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1129 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1130 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1135 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1136 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1138 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1140 EINA_LIST_FOREACH(item->states, l, it_state)
1142 if (it_state->icon == old_icon) return;
1144 evas_object_del(old_icon);
1148 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1150 Elm_Toolbar_Item *item = data;
1151 edje_object_part_unswallow(VIEW(item), item->icon);
1152 _elm_toolbar_item_icon_update(item);
1153 edje_object_signal_callback_del(obj, emission, source,
1154 _elm_toolbar_item_icon_set_cb);
1155 edje_object_signal_emit (VIEW(item), "elm,state,icon,reset", "elm");
1159 _elm_toolbar_item_icon_obj_set(Evas_Object *obj, Elm_Toolbar_Item *item, Evas_Object *icon_obj, const char *icon_str, double icon_size, const char *sig)
1161 Evas_Object *old_icon;
1166 eina_stringshare_replace(&item->icon_str, icon_str);
1169 eina_stringshare_del(item->icon_str);
1170 item->icon_str = NULL;
1172 item->icon = icon_obj;
1175 ms = (icon_size * _elm_config->scale);
1176 evas_object_size_hint_min_set(item->icon, ms, ms);
1177 evas_object_size_hint_max_set(item->icon, ms, ms);
1178 evas_object_show(item->icon);
1179 elm_widget_sub_object_add(obj, item->icon);
1181 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1182 if ((s) && (atoi(s)))
1184 old_icon = edje_object_part_swallow_get(VIEW(item),
1185 "elm.swallow.icon_new");
1188 elm_widget_sub_object_del(VIEW(item), old_icon);
1189 evas_object_hide(old_icon);
1191 edje_object_part_swallow(VIEW(item), "elm.swallow.icon_new",
1193 edje_object_signal_emit (VIEW(item), sig, "elm");
1194 edje_object_signal_callback_add(VIEW(item),
1195 "elm,state,icon_set,done", "elm",
1196 _elm_toolbar_item_icon_set_cb, item);
1199 _elm_toolbar_item_icon_update(item);
1200 _resize(obj, NULL, NULL, NULL);
1204 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1206 Elm_Toolbar_Item *it = event_info;
1207 Elm_Toolbar_Item_State *it_state;
1209 it_state = eina_list_data_get(it->current_state);
1211 it_state->func((void *)it_state->data, obj, event_info);
1214 static Elm_Toolbar_Item_State *
1215 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1217 Elm_Toolbar_Item_State *it_state;
1218 it_state = ELM_NEW(Elm_Toolbar_Item_State);
1219 it_state->label = eina_stringshare_add(label);
1220 it_state->icon_str = eina_stringshare_add(icon_str);
1221 it_state->icon = icon;
1222 it_state->func = func;
1223 it_state->data = data;
1228 elm_toolbar_add(Evas_Object *parent)
1234 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1236 ELM_SET_WIDTYPE(widtype, "toolbar");
1237 elm_widget_type_set(obj, "toolbar");
1238 elm_widget_sub_object_add(parent, obj);
1239 elm_widget_data_set(obj, wd);
1240 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1241 elm_widget_del_hook_set(obj, _del_hook);
1242 elm_widget_theme_hook_set(obj, _theme_hook);
1243 elm_widget_translate_hook_set(obj, _translate_hook);
1244 elm_widget_can_focus_set(obj, EINA_FALSE);
1246 wd->more_item = NULL;
1247 wd->selected_item = NULL;
1248 wd->scr = elm_smart_scroller_add(e);
1249 elm_smart_scroller_widget_set(wd->scr, obj);
1250 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
1251 elm_smart_scroller_bounce_allow_set(wd->scr,
1252 _elm_config->thumbscroll_bounce_enable,
1254 elm_widget_resize_object_set(obj, wd->scr);
1255 elm_smart_scroller_policy_set(wd->scr,
1256 ELM_SMART_SCROLLER_POLICY_AUTO,
1257 ELM_SMART_SCROLLER_POLICY_OFF);
1260 wd->icon_size = _elm_toolbar_icon_size_get(wd);
1263 wd->homogeneous = EINA_TRUE;
1266 wd->bx = evas_object_box_add(e);
1267 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
1268 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
1269 elm_widget_sub_object_add(obj, wd->bx);
1270 elm_smart_scroller_child_set(wd->scr, wd->bx);
1271 evas_object_show(wd->bx);
1273 elm_toolbar_shrink_mode_set(obj, _elm_config->toolbar_shrink_mode);
1274 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
1275 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
1276 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
1278 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1285 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
1287 ELM_CHECK_WIDTYPE(obj, widtype);
1288 Widget_Data *wd = elm_widget_data_get(obj);
1290 if (wd->icon_size == icon_size) return;
1291 wd->icon_size = icon_size;
1296 elm_toolbar_icon_size_get(const Evas_Object *obj)
1298 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1299 Widget_Data *wd = elm_widget_data_get(obj);
1301 return wd->icon_size;
1304 EAPI Elm_Object_Item *
1305 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1307 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1308 Widget_Data *wd = elm_widget_data_get(obj);
1309 if (!wd) return NULL;
1311 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1312 if (!it) return NULL;
1313 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1315 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
1316 evas_object_box_append(wd->bx, VIEW(it));
1317 evas_object_show(VIEW(it));
1319 _theme_hook_item(obj, it, scale, wd->icon_size);
1322 return (Elm_Object_Item *)it;
1325 EAPI Elm_Object_Item *
1326 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1328 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1329 Widget_Data *wd = elm_widget_data_get(obj);
1330 if (!wd) return NULL;
1332 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1333 if (!it) return NULL;
1334 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1336 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1337 evas_object_box_prepend(wd->bx, VIEW(it));
1338 evas_object_show(VIEW(it));
1339 _theme_hook_item(obj, it, scale, wd->icon_size);
1342 return (Elm_Object_Item *)it;
1345 EAPI Elm_Object_Item *
1346 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)
1348 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1349 ELM_OBJ_ITEM_CHECK_OR_RETURN(before, NULL);
1351 Elm_Toolbar_Item *it, *_before;
1353 wd = elm_widget_data_get(obj);
1354 if (!wd) return NULL;
1355 _before = (Elm_Toolbar_Item *) before;
1356 it = _item_new(obj, icon, label, func, data);
1357 if (!it) return NULL;
1358 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1360 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1361 EINA_INLIST_GET(_before));
1362 evas_object_box_insert_before(wd->bx, VIEW(it), VIEW(_before));
1363 evas_object_show(VIEW(it));
1364 _theme_hook_item(obj, it, scale, wd->icon_size);
1367 return (Elm_Object_Item *)it;
1370 EAPI Elm_Object_Item *
1371 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)
1373 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1374 ELM_OBJ_ITEM_CHECK_OR_RETURN(after, NULL);
1376 Elm_Toolbar_Item *it, *_after;
1378 wd = elm_widget_data_get(obj);
1379 if (!wd) return NULL;
1380 _after = (Elm_Toolbar_Item *) after;
1381 it = _item_new(obj, icon, label, func, data);
1382 if (!it) return NULL;
1383 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1385 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1386 EINA_INLIST_GET(_after));
1387 evas_object_box_insert_after(wd->bx, VIEW(it), VIEW(_after));
1388 evas_object_show(VIEW(it));
1389 _theme_hook_item(obj, it, scale, wd->icon_size);
1392 return (Elm_Object_Item *)it;
1395 EAPI Elm_Object_Item *
1396 elm_toolbar_first_item_get(const Evas_Object *obj)
1398 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1399 Widget_Data *wd = elm_widget_data_get(obj);
1400 if (!wd || !wd->items) return NULL;
1401 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1404 EAPI Elm_Object_Item *
1405 elm_toolbar_last_item_get(const Evas_Object *obj)
1407 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1408 Widget_Data *wd = elm_widget_data_get(obj);
1409 if (!wd || !wd->items) return NULL;
1410 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1413 EAPI Elm_Object_Item *
1414 elm_toolbar_item_next_get(const Elm_Object_Item *it)
1416 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1417 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1418 EINA_INLIST_GET(((Elm_Toolbar_Item *)it))->next);
1421 EAPI Elm_Object_Item *
1422 elm_toolbar_item_prev_get(const Elm_Object_Item *it)
1424 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1425 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1426 EINA_INLIST_GET(((Elm_Toolbar_Item *)it))->prev);
1430 elm_toolbar_item_priority_set(Elm_Object_Item *it, int priority)
1432 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1433 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1434 if (item->prio.priority == priority) return;
1435 item->prio.priority = priority;
1436 _resize(WIDGET(item), NULL, NULL, NULL);
1440 elm_toolbar_item_priority_get(const Elm_Object_Item *it)
1442 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
1443 return ((Elm_Toolbar_Item *)it)->prio.priority;
1446 EAPI Elm_Object_Item *
1447 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
1449 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1450 Elm_Toolbar_Item *it;
1451 Widget_Data *wd = elm_widget_data_get(obj);
1452 if (!wd) return NULL;
1454 EINA_INLIST_FOREACH(wd->items, it)
1456 if (!strcmp(it->label, label))
1457 return (Elm_Object_Item *)it;
1463 elm_toolbar_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1465 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1466 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1467 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1470 if (item->selected == selected) return;
1471 if (selected) _item_select(item);
1472 else _item_unselect(item);
1476 elm_toolbar_item_selected_get(const Elm_Object_Item *it)
1478 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1479 return ((Elm_Toolbar_Item *)it)->selected;
1482 EAPI Elm_Object_Item *
1483 elm_toolbar_selected_item_get(const Evas_Object *obj)
1485 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1486 Widget_Data *wd = elm_widget_data_get(obj);
1487 if (!wd) return NULL;
1488 return (Elm_Object_Item *) wd->selected_item;
1492 elm_toolbar_item_icon_set(Elm_Object_Item *it, const char *icon)
1494 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1496 Evas_Object *icon_obj;
1499 Elm_Toolbar_Item * item = (Elm_Toolbar_Item *)it;
1502 wd = elm_widget_data_get(obj);
1504 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1506 icon_obj = elm_icon_add(obj);
1507 if (!icon_obj) return;
1508 if (_item_icon_set(icon_obj, "toolbar/", icon))
1509 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1510 "elm,state,icon_set");
1513 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1514 "elm,state,icon_set");
1515 evas_object_del(icon_obj);
1520 elm_toolbar_item_icon_get(const Elm_Object_Item *it)
1522 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1523 return ((Elm_Toolbar_Item *)it)->icon_str;
1527 elm_toolbar_item_object_get(const Elm_Object_Item *it)
1529 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1533 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1536 wd = elm_widget_data_get(obj);
1537 if (!wd) return NULL;
1543 elm_toolbar_item_icon_object_get(Elm_Object_Item *it)
1545 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1546 return ((Elm_Toolbar_Item *)it)->icon;
1550 elm_toolbar_item_icon_memfile_set(Elm_Object_Item *it, const void *img, size_t size, const char *format, const char *key)
1552 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1554 Evas_Object *icon_obj;
1558 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1561 wd = elm_widget_data_get(obj);
1562 if (!wd) return EINA_FALSE;
1566 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1567 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1568 ret = _els_smart_icon_memfile_set(icon_obj, img, size, format, key);
1571 evas_object_del(icon_obj);
1574 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1575 "elm,state,icon_set");
1578 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1583 elm_toolbar_item_icon_file_set(Elm_Object_Item *it, const char *file, const char *key)
1585 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1587 Evas_Object *icon_obj;
1591 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1594 wd = elm_widget_data_get(obj);
1595 if (!wd) return EINA_FALSE;
1599 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1600 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1601 ret = _els_smart_icon_file_key_set(icon_obj, file, key);
1604 evas_object_del(icon_obj);
1607 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1608 "elm,state,icon_set");
1611 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1616 elm_toolbar_item_separator_set(Elm_Object_Item *it, Eina_Bool separator)
1618 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1619 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1620 Evas_Object *obj = WIDGET(item);
1621 Widget_Data *wd = elm_widget_data_get(obj);
1623 if (item->separator == separator) return;
1624 item->separator = separator;
1625 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1626 _theme_hook_item(obj, item, scale, wd->icon_size);
1630 elm_toolbar_item_separator_get(const Elm_Object_Item *it)
1632 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1633 return ((Elm_Toolbar_Item *)it)->separator;
1637 elm_toolbar_shrink_mode_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1639 ELM_CHECK_WIDTYPE(obj, widtype);
1640 Widget_Data *wd = elm_widget_data_get(obj);
1644 wd->shrink_mode = shrink_mode;
1645 bounce = (_elm_config->thumbscroll_bounce_enable) &&
1646 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1647 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1651 _item_del(wd->more_item);
1652 elm_widget_item_free(wd->more_item);
1653 wd->more_item = NULL;
1656 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1658 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1659 ELM_SMART_SCROLLER_POLICY_OFF);
1660 wd->more_item = _item_new(obj, "more_menu", "More", NULL, NULL);
1662 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1663 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1664 ELM_SMART_SCROLLER_POLICY_OFF);
1666 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1667 ELM_SMART_SCROLLER_POLICY_OFF);
1671 EAPI Elm_Toolbar_Shrink_Mode
1672 elm_toolbar_shrink_mode_get(const Evas_Object *obj)
1674 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1675 Widget_Data *wd = elm_widget_data_get(obj);
1677 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1678 return wd->shrink_mode;
1682 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
1684 ELM_CHECK_WIDTYPE(obj, widtype);
1685 Widget_Data *wd = elm_widget_data_get(obj);
1688 wd->homogeneous = !!homogeneous;
1689 evas_object_smart_calculate(wd->bx);
1693 elm_toolbar_homogeneous_get(const Evas_Object *obj)
1695 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1696 Widget_Data *wd = elm_widget_data_get(obj);
1698 if (!wd) return EINA_FALSE;
1699 return wd->homogeneous;
1703 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1705 Elm_Toolbar_Item *it;
1706 ELM_CHECK_WIDTYPE(obj, widtype);
1707 Widget_Data *wd = elm_widget_data_get(obj);
1710 EINA_SAFETY_ON_NULL_RETURN(parent);
1711 wd->menu_parent = parent;
1712 EINA_INLIST_FOREACH(wd->items, it)
1715 elm_menu_parent_set(it->o_menu, wd->menu_parent);
1717 if ((wd->more_item) && (wd->more_item->o_menu))
1718 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1722 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1724 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1725 Widget_Data *wd = elm_widget_data_get(obj);
1727 if (!wd) return NULL;
1728 return wd->menu_parent;
1732 elm_toolbar_align_set(Evas_Object *obj, double align)
1734 ELM_CHECK_WIDTYPE(obj, widtype);
1735 Widget_Data *wd = elm_widget_data_get(obj);
1740 if (wd->align != align)
1741 evas_object_size_hint_align_set(wd->bx, 0.5, align);
1745 if (wd->align != align)
1746 evas_object_size_hint_align_set(wd->bx, align, 0.5);
1752 elm_toolbar_align_get(const Evas_Object *obj)
1754 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1755 Widget_Data *wd = elm_widget_data_get(obj);
1757 if (!wd) return 0.0;
1762 elm_toolbar_item_menu_set(Elm_Object_Item *it, Eina_Bool menu)
1764 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1765 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1766 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1769 if (item->menu == menu) return;
1770 if (menu) _item_menu_create(wd, item);
1771 else _item_menu_destroy(item);
1775 elm_toolbar_item_menu_get(const Elm_Object_Item *it)
1777 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1778 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1779 if (!item->menu) return NULL;
1780 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1781 if (!wd) return NULL;
1782 return item->o_menu;
1785 EAPI Elm_Toolbar_Item_State *
1786 elm_toolbar_item_state_add(Elm_Object_Item *it, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1788 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1790 Elm_Toolbar_Item_State *it_state;
1791 Evas_Object *icon_obj;
1794 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1796 wd = elm_widget_data_get(WIDGET(item));
1797 if (!wd) return NULL;
1801 it_state = _item_state_new(item->label, item->icon_str, item->icon,
1802 item->func, item->base.data);
1803 item->states = eina_list_append(item->states, it_state);
1804 item->current_state = item->states;
1807 icon_obj = elm_icon_add(obj);
1808 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1809 if (!icon_obj) goto error_state_add;
1811 if (!_item_icon_set(icon_obj, "toolbar/", icon))
1813 evas_object_del(icon_obj);
1818 it_state = _item_state_new(label, icon, icon_obj, func, data);
1819 item->states = eina_list_append(item->states, it_state);
1820 item->func = _elm_toolbar_item_state_cb;
1821 item->base.data = NULL;
1826 if (item->states && !eina_list_next(item->states))
1828 eina_stringshare_del(item->label);
1829 eina_stringshare_del(item->icon_str);
1830 free(eina_list_data_get(item->states));
1831 eina_list_free(item->states);
1832 item->states = NULL;
1838 elm_toolbar_item_state_del(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1840 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1842 Eina_List *del_state;
1843 Elm_Toolbar_Item_State *it_state;
1844 Elm_Toolbar_Item *item;
1846 if (!state) return EINA_FALSE;
1848 item = (Elm_Toolbar_Item *)it;
1849 if (!item->states) return EINA_FALSE;
1851 del_state = eina_list_data_find_list(item->states, state);
1852 if (del_state == item->states) return EINA_FALSE;
1853 if (del_state == item->current_state)
1854 elm_toolbar_item_state_unset(it);
1856 eina_stringshare_del(state->label);
1857 eina_stringshare_del(state->icon_str);
1858 if (state->icon) evas_object_del(state->icon);
1860 item->states = eina_list_remove_list(item->states, del_state);
1861 if (item->states && !eina_list_next(item->states))
1863 it_state = eina_list_data_get(item->states);
1864 item->base.data = it_state->data;
1865 item->func = it_state->func;
1866 eina_stringshare_del(it_state->label);
1867 eina_stringshare_del(it_state->icon_str);
1868 free(eina_list_data_get(item->states));
1869 eina_list_free(item->states);
1870 item->states = NULL;
1876 elm_toolbar_item_state_set(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1878 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1881 Eina_List *next_state;
1882 Elm_Toolbar_Item_State *it_state;
1884 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1887 wd = elm_widget_data_get(obj);
1888 if (!wd) return EINA_FALSE;
1889 if (!item->states) return EINA_FALSE;
1893 next_state = eina_list_data_find_list(item->states, state);
1894 if (!next_state) return EINA_FALSE;
1897 next_state = item->states;
1899 if (next_state == item->current_state) return EINA_TRUE;
1901 it_state = eina_list_data_get(next_state);
1902 if (eina_list_data_find(item->current_state, state))
1904 _item_label_set(item, it_state->label, "elm,state,label_set,forward");
1905 _elm_toolbar_item_icon_obj_set(obj, item, it_state->icon, it_state->icon_str,
1906 wd->icon_size, "elm,state,icon_set,forward");
1910 _item_label_set(item, it_state->label, "elm,state,label_set,backward");
1911 _elm_toolbar_item_icon_obj_set(obj,
1916 "elm,state,icon_set,backward");
1918 if (elm_widget_item_disabled_get(item))
1919 elm_widget_signal_emit(item->icon, "elm,state,disabled", "elm");
1921 elm_widget_signal_emit(item->icon, "elm,state,enabled", "elm");
1923 item->current_state = next_state;
1928 elm_toolbar_item_state_unset(Elm_Object_Item *it)
1930 elm_toolbar_item_state_set(it, NULL);
1933 EAPI Elm_Toolbar_Item_State *
1934 elm_toolbar_item_state_get(const Elm_Object_Item *it)
1936 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1937 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1939 if ((!item->states) || (!item->current_state)) return NULL;
1940 if (item->current_state == item->states) return NULL;
1942 return eina_list_data_get(item->current_state);
1945 EAPI Elm_Toolbar_Item_State *
1946 elm_toolbar_item_state_next(Elm_Object_Item *it)
1948 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1952 Eina_List *next_state;
1953 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1956 wd = elm_widget_data_get(obj);
1957 if (!wd) return NULL;
1958 if (!item->states) return NULL;
1960 next_state = eina_list_next(item->current_state);
1962 next_state = eina_list_next(item->states);
1963 return eina_list_data_get(next_state);
1966 EAPI Elm_Toolbar_Item_State *
1967 elm_toolbar_item_state_prev(Elm_Object_Item *it)
1969 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1973 Eina_List *prev_state;
1974 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1977 wd = elm_widget_data_get(obj);
1978 if (!wd) return NULL;
1979 if (!item->states) return NULL;
1981 prev_state = eina_list_prev(item->current_state);
1982 if ((!prev_state) || (prev_state == item->states))
1983 prev_state = eina_list_last(item->states);
1984 return eina_list_data_get(prev_state);
1988 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
1990 ELM_CHECK_WIDTYPE(obj, widtype);
1991 Elm_Toolbar_Item *it;
1992 Widget_Data *wd = elm_widget_data_get(obj);
1995 wd->lookup_order = order;
1996 EINA_INLIST_FOREACH(wd->items, it)
1997 elm_icon_order_lookup_set(it->icon, order);
1999 elm_icon_order_lookup_set(wd->more_item->icon, order);
2002 EAPI Elm_Icon_Lookup_Order
2003 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
2005 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
2006 Widget_Data *wd = elm_widget_data_get(obj);
2007 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
2008 return wd->lookup_order;
2012 elm_toolbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
2014 ELM_CHECK_WIDTYPE(obj, widtype);
2015 Widget_Data *wd = elm_widget_data_get(obj);
2017 wd->vertical = !horizontal;
2019 evas_object_size_hint_align_set(wd->bx, 0.5, wd->align);
2021 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
2026 elm_toolbar_horizontal_get(const Evas_Object *obj)
2028 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2029 Widget_Data *wd = elm_widget_data_get(obj);
2030 if (!wd) return EINA_FALSE;
2031 return !wd->vertical;
2035 elm_toolbar_items_count(const Evas_Object *obj)
2037 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2038 Widget_Data *wd = elm_widget_data_get(obj);
2040 return wd->item_count;
2044 elm_toolbar_select_mode_set(Evas_Object *obj, Elm_Object_Select_Mode mode)
2046 ELM_CHECK_WIDTYPE(obj, widtype);
2047 Widget_Data *wd = elm_widget_data_get(obj);
2049 if (mode >= ELM_OBJECT_SELECT_MODE_MAX)
2051 if ((mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2052 (wd->select_mode != ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2054 _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
2055 if (wd->select_mode != mode)
2056 wd->select_mode = mode;
2059 EAPI Elm_Object_Select_Mode
2060 elm_toolbar_select_mode_get(const Evas_Object *obj)
2062 ELM_CHECK_WIDTYPE(obj, widtype) ELM_OBJECT_SELECT_MODE_MAX;
2063 Widget_Data *wd = elm_widget_data_get(obj);
2064 if (!wd) return ELM_OBJECT_SELECT_MODE_MAX;
2065 return wd->select_mode;