1 #include <Elementary.h>
3 #include "els_scroller.h"
7 typedef struct _Widget_Data Widget_Data;
8 typedef struct _Elm_Toolbar_Item Elm_Toolbar_Item;
12 Evas_Object *scr, *bx;
13 Evas_Object *menu_parent;
15 Elm_Toolbar_Item *more_item, *selected_item;
16 Elm_Toolbar_Shrink_Mode shrink_mode;
17 Elm_Icon_Lookup_Order lookup_order;
19 unsigned int item_count;
21 Elm_Object_Select_Mode select_mode;
22 Eina_Bool homogeneous : 1;
23 Eina_Bool vertical : 1;
24 Eina_Bool long_press : 1;
25 Ecore_Timer *long_timer;
26 Ecore_Job *resize_job;
29 struct _Elm_Toolbar_Item
42 Eina_Bool visible : 1;
44 Eina_Bool selected : 1;
45 Eina_Bool separator : 1;
48 Eina_List *current_state;
51 #define ELM_TOOLBAR_ITEM_FROM_INLIST(item) \
52 ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Toolbar_Item) : NULL)
54 struct _Elm_Toolbar_Item_State
63 static const char *widtype = NULL;
64 static void _item_show(Elm_Toolbar_Item *it);
65 static void _item_select(Elm_Toolbar_Item *it);
66 static void _item_unselect(Elm_Toolbar_Item *it);
67 static void _del_pre_hook(Evas_Object *obj);
68 static void _del_hook(Evas_Object *obj);
69 static void _mirrored_set(Evas_Object *obj, Eina_Bool mirrored);
70 static void _mirrored_set_item(Evas_Object *obj, Elm_Toolbar_Item *it, Eina_Bool mirrored);
71 static void _theme_hook(Evas_Object *obj);
72 static void _sizing_eval(Evas_Object *obj);
73 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
74 static void _menu_move_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
75 static void _menu_hide(void *data, Evas *e, Evas_Object *obj, void *event_info);
76 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
77 static void _elm_toolbar_item_icon_obj_set(Evas_Object *obj, Elm_Toolbar_Item *item, Evas_Object *icon_obj, const char *icon_str, double icon_size, const char *sig);
78 static void _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *sig);
80 static const char SIG_CLICKED[] = "clicked";
81 static const char SIG_LONGPRESSED[] = "longpressed";
82 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
84 static const Evas_Smart_Cb_Description _signals[] = {
86 {SIG_LONGPRESSED, ""},
87 {SIG_CLICKED_DOUBLE, ""},
92 _item_disable_hook(Elm_Object_Item *it)
95 Elm_Toolbar_Item *toolbar_it = (Elm_Toolbar_Item *)it;
97 wd = elm_widget_data_get(WIDGET(toolbar_it));
100 if (elm_widget_item_disabled_get(toolbar_it))
102 edje_object_signal_emit(VIEW(toolbar_it), "elm,state,disabled", "elm");
103 elm_widget_signal_emit(toolbar_it->icon, "elm,state,disabled", "elm");
107 edje_object_signal_emit(VIEW(toolbar_it), "elm,state,enabled", "elm");
108 elm_widget_signal_emit(toolbar_it->icon, "elm,state,enabled", "elm");
110 _resize(WIDGET(toolbar_it), NULL, NULL, NULL);
114 _item_icon_set(Evas_Object *icon_obj, const char *type, const char *icon)
118 if ((!type) || (!*type)) goto end;
119 if ((!icon) || (!*icon)) return EINA_FALSE;
120 if ((snprintf(icon_str, sizeof(icon_str), "%s%s", type, icon) > 0)
121 && (elm_icon_standard_set(icon_obj, icon_str)))
124 if (elm_icon_standard_set(icon_obj, icon))
126 WRN("couldn't find icon definition for '%s'", icon);
131 _elm_toolbar_icon_size_get(Widget_Data *wd)
133 const char *icon_size = edje_object_data_get(
134 elm_smart_scroller_edje_object_get(wd->scr), "icon_size");
136 return atoi(icon_size);
137 return _elm_config->icon_size;
141 _item_show(Elm_Toolbar_Item *it)
143 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
144 Evas_Coord x, y, w, h, bx, by;
147 evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
148 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
149 elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
153 _item_unselect(Elm_Toolbar_Item *item)
156 if ((!item) || (!item->selected)) return;
157 wd = elm_widget_data_get(WIDGET(item));
159 item->selected = EINA_FALSE;
160 wd->selected_item = NULL;
161 edje_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
162 elm_widget_signal_emit(item->icon, "elm,state,unselected", "elm");
166 _item_select(Elm_Toolbar_Item *it)
168 Elm_Toolbar_Item *it2;
169 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
174 if (elm_widget_item_disabled_get(it) || (it->separator) || (it->object)) return;
177 if (wd->select_mode != ELM_OBJECT_SELECT_MODE_NONE)
181 if (wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS) return;
186 it2 = (Elm_Toolbar_Item *)
187 elm_toolbar_selected_item_get(WIDGET(it));
190 it->selected = EINA_TRUE;
191 wd->selected_item = it;
192 edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
193 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
198 if (it->menu && (!sel))
200 evas_object_show(it->o_menu);
201 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
202 _menu_move_resize, it);
203 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOVE,
204 _menu_move_resize, it);
206 _menu_move_resize(it, NULL, NULL, NULL);
208 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
209 evas_object_smart_callback_call(obj2, SIG_CLICKED, it);
213 _menu_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
215 Elm_Toolbar_Item *selected;
216 Elm_Toolbar_Item *it = data;
217 selected = (Elm_Toolbar_Item *) elm_toolbar_selected_item_get(WIDGET(it));
218 _item_unselect(selected);
222 _menu_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
224 // avoid hide being emitted during object deletion
225 evas_object_event_callback_del_full
226 (obj, EVAS_CALLBACK_HIDE, _menu_hide, data);
230 _menu_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
232 Elm_Toolbar_Item *it = data;
234 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
236 if ((!wd) || (!wd->menu_parent)) return;
237 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
238 elm_menu_move(it->o_menu, x, y+h);
242 _item_del(Elm_Toolbar_Item *it)
244 Elm_Toolbar_Item_State *it_state;
246 EINA_LIST_FREE(it->states, it_state)
248 if (it->icon == it_state->icon)
250 eina_stringshare_del(it_state->label);
251 eina_stringshare_del(it_state->icon_str);
252 if (it_state->icon) evas_object_del(it_state->icon);
255 eina_stringshare_del(it->label);
256 eina_stringshare_del(it->icon_str);
257 if (it->icon) evas_object_del(it->icon);
258 if (it->object) evas_object_del(it->object);
259 //TODO: See if checking for wd->menu_parent is necessary before deleting menu
260 if (it->o_menu) evas_object_del(it->o_menu);
264 _del_pre_hook(Evas_Object *obj)
266 Widget_Data *wd = elm_widget_data_get(obj);
267 Elm_Toolbar_Item *it, *next;
270 it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
273 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
275 elm_widget_item_free(it);
280 _item_del(wd->more_item);
281 elm_widget_item_free(wd->more_item);
285 ecore_timer_del(wd->long_timer);
286 wd->long_timer = NULL;
291 _del_hook(Evas_Object *obj)
293 Widget_Data *wd = elm_widget_data_get(obj);
301 _mirrored_set_item(Evas_Object *obj __UNUSED__, Elm_Toolbar_Item *it, Eina_Bool mirrored)
303 edje_object_mirrored_set(VIEW(it), mirrored);
304 elm_widget_mirrored_set(it->o_menu, mirrored);
308 _theme_hook_item(Evas_Object *obj, Elm_Toolbar_Item *it, double scale, int icon_size)
310 Widget_Data *wd = elm_widget_data_get(obj);
311 Evas_Object *view = VIEW(it);
313 const char *style = elm_widget_style_get(obj);
315 _mirrored_set_item(obj, it, elm_widget_mirrored_get(obj));
316 edje_object_scale_set(view, scale);
317 if (!it->separator && !it->object)
319 _elm_theme_object_set(obj, view, "toolbar", "item", style);
322 edje_object_signal_emit(view, "elm,state,selected", "elm");
323 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
325 if (elm_widget_item_disabled_get(it))
327 edje_object_signal_emit(view, "elm,state,disabled", "elm");
328 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
334 ms = ((double)icon_size * scale);
335 evas_object_size_hint_min_set(it->icon, ms, ms);
336 evas_object_size_hint_max_set(it->icon, ms, ms);
337 edje_object_part_swallow(view, "elm.swallow.icon", it->icon);
339 edje_object_part_text_set(view, "elm.text", it->label);
345 _elm_theme_object_set(obj, view, "toolbar", "separator", style);
348 evas_object_size_hint_weight_set(view, EVAS_HINT_EXPAND, -1.0);
349 evas_object_size_hint_align_set(view, EVAS_HINT_FILL, 0.5);
353 evas_object_size_hint_weight_set(view, -1.0, EVAS_HINT_EXPAND);
354 evas_object_size_hint_align_set(view, 0.5, EVAS_HINT_FILL);
359 _elm_theme_object_set(obj, view, "toolbar", "object", style);
360 edje_object_part_swallow(view, "elm.swallow.object", it->object);
365 if (!it->separator && !it->object)
366 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
367 edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
368 if (!it->separator && !it->object)
369 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
370 evas_object_size_hint_min_set(view, mw, mh);
374 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
376 Widget_Data *wd = elm_widget_data_get(obj);
377 Elm_Toolbar_Item *it;
379 EINA_INLIST_FOREACH(wd->items, it)
380 _mirrored_set_item(obj, it, mirrored);
382 _mirrored_set_item(obj, wd->more_item, mirrored);
386 _theme_hook(Evas_Object *obj)
388 Widget_Data *wd = elm_widget_data_get(obj);
389 Elm_Toolbar_Item *it;
393 _elm_widget_mirrored_reload(obj);
394 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
395 _mirrored_set(obj, elm_widget_mirrored_get(obj));
396 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
397 edje_object_scale_set(wd->scr, scale);
398 wd->icon_size = _elm_toolbar_icon_size_get(wd);
399 EINA_INLIST_FOREACH(wd->items, it)
400 _theme_hook_item(obj, it, scale, wd->icon_size);
402 _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
407 _item_text_set_hook(Elm_Object_Item *it,
411 if (part && strcmp(part, "default")) return;
412 _item_label_set(((Elm_Toolbar_Item *)it), label, "elm,state,label_set");
416 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
418 if (part && strcmp(part, "default")) return NULL;
419 return ((Elm_Toolbar_Item *)it)->label;
423 _item_content_set_hook(Elm_Object_Item *it,
425 Evas_Object *content)
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 if (part && strcmp(part, "object")) return NULL;
445 return ((Elm_Toolbar_Item *) it)->object;
449 _item_content_unset_hook(Elm_Object_Item *it, const char *part)
454 if (part && strcmp(part, "object")) return NULL;
455 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
456 Evas_Object *obj = WIDGET(item);
457 Widget_Data *wd = elm_widget_data_get(obj);
459 edje_object_part_unswallow(VIEW(it), item->object);
460 elm_widget_sub_object_del(obj, item->object);
463 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
464 _theme_hook_item(obj, item, scale, wd->icon_size);
469 _translate_hook(Evas_Object *obj)
471 evas_object_smart_callback_call(obj, "language,changed", NULL);
475 _sizing_eval(Evas_Object *obj)
477 Widget_Data *wd = elm_widget_data_get(obj);
478 Evas_Coord minw = -1, minh = -1, minw_bx = -1, minh_bx = -1;
479 Evas_Coord vw = 0, vh = 0;
483 evas_object_smart_need_recalculate_set(wd->bx, EINA_TRUE);
484 evas_object_smart_calculate(wd->bx);
485 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
487 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
488 if (w < minw) w = minw;
489 if (h < minh) h = minh;
490 evas_object_resize(wd->scr, w, h);
492 evas_object_size_hint_min_get(wd->bx, &minw_bx, &minh_bx);
493 // if (wd->vertical && (h > minh)) minh = h;
494 // if ((!wd->vertical) && (w > minw)) minw = w;
495 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
496 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_NONE)
500 minw = minw_bx + (w - vw);
501 minh = minh_bx + (h - vh);
505 minw = minw_bx + (w - vw);
506 minh = minh_bx + (h - vh);
509 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
511 minw = minw_bx + (w - vw);
512 minh = minh_bx + (h - vh);
513 if (minw_bx < vw) minw_bx = vw;
514 if (minh_bx < vh) minh_bx = vh;
520 minw = minw_bx + (w - vw);
526 minh = minh_bx + (h - vh);
528 // if (wd->vertical) minh = h - vh;
529 // else minw = w - vw;
530 // minh = minh + (h - vh);
532 evas_object_resize(wd->bx, minw_bx, minh_bx);
533 evas_object_size_hint_min_set(obj, minw, minh);
534 evas_object_size_hint_max_set(obj, -1, -1);
538 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
540 item->o_menu = elm_menu_add(VIEW(item));
541 item->menu = EINA_TRUE;
543 elm_menu_parent_set(item->o_menu, wd->menu_parent);
544 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
546 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
551 _item_menu_destroy(Elm_Toolbar_Item *item)
555 evas_object_del(item->o_menu);
558 item->menu = EINA_FALSE;
562 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
564 const Elm_Toolbar_Item *eti1 = i1;
565 const Elm_Toolbar_Item *eti2 = i2;
568 if (!eti1) return -1;
570 return eti2->prio.priority - eti1->prio.priority;
574 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw)
576 Elm_Toolbar_Item *it;
577 Eina_List *sorted = NULL;
578 Evas_Coord ciw = 0, cih = 0;
580 EINA_INLIST_FOREACH(wd->items, it)
582 sorted = eina_list_sorted_insert(sorted,
583 _toolbar_item_prio_compare_cb, it);
588 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL, &ciw, &cih);
589 if (wd->vertical) *iw += cih;
592 EINA_LIST_FREE(sorted, it)
594 evas_object_geometry_get(VIEW(it), NULL, NULL, &ciw, &cih);
595 if (wd->vertical) *iw += cih;
597 it->prio.visible = (*iw <= vw);
602 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
604 Elm_Toolbar_Item *it = data;
605 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
609 _resize_job(void *data)
611 Evas_Object *obj = (Evas_Object *)data;
612 Widget_Data *wd = elm_widget_data_get(obj);
613 Evas_Coord mw, mh, vw = 0, vh = 0, w = 0, h = 0;
614 Elm_Toolbar_Item *it;
617 wd->resize_job = NULL;
618 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
619 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
620 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
621 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
623 Evas_Coord iw = 0, ih = 0, more_w = 0, more_h = 0;
627 evas_object_resize(wd->bx, w, vh);
628 _fix_items_visibility(wd, &ih, vh);
632 evas_object_resize(wd->bx, vw, h);
633 _fix_items_visibility(wd, &iw, vw);
635 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL,
639 if ((ih - more_h) <= vh) ih -= more_h;
643 if ((iw - more_w) <= vw) iw -= more_w;
646 /* All items are removed from the box object, since removing individual
647 * items won't trigger a resize. Items are be readded below. */
648 evas_object_box_remove_all(wd->bx, EINA_FALSE);
649 if (((wd->vertical) && (ih > vh)) ||
650 ((!wd->vertical) && (iw > vw)))
654 _item_menu_destroy(wd->more_item);
655 _item_menu_create(wd, wd->more_item);
656 menu = elm_toolbar_item_menu_get((Elm_Object_Item *)wd->more_item);
657 EINA_INLIST_FOREACH(wd->items, it)
659 if (!it->prio.visible)
662 elm_menu_item_separator_add(menu, NULL);
665 Elm_Object_Item *menu_it;
666 menu_it = elm_menu_item_add
667 (menu, NULL, it->icon_str, it->label,
668 _elm_toolbar_item_menu_cb, it);
669 elm_object_item_disabled_set
670 (menu_it, elm_widget_item_disabled_get(it));
672 elm_menu_clone(it->o_menu, menu, menu_it);
674 evas_object_hide(VIEW(it));
678 evas_object_box_append(wd->bx, VIEW(it));
679 evas_object_show(VIEW(it));
682 evas_object_box_append(wd->bx, wd->VIEW(more_item));
683 evas_object_show(wd->VIEW(more_item));
687 /* All items are visible, show them all (except for the "More"
688 * button, of course). */
689 EINA_INLIST_FOREACH(wd->items, it)
691 evas_object_show(VIEW(it));
692 evas_object_box_append(wd->bx, VIEW(it));
694 evas_object_hide(wd->VIEW(more_item));
697 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
699 Evas_Coord iw = 0, ih = 0;
703 evas_object_resize(wd->bx, w, vh);
704 _fix_items_visibility(wd, &ih, vh);
708 evas_object_resize(wd->bx, vw, h);
709 _fix_items_visibility(wd, &iw, vw);
711 evas_object_box_remove_all(wd->bx, EINA_FALSE);
712 if (((wd->vertical) && (ih > vh)) ||
713 ((!wd->vertical) && (iw > vw)))
715 EINA_INLIST_FOREACH(wd->items, it)
717 if (!it->prio.visible)
718 evas_object_hide(VIEW(it));
721 evas_object_box_append(wd->bx, VIEW(it));
722 evas_object_show(VIEW(it));
728 /* All items are visible, show them all */
729 EINA_INLIST_FOREACH(wd->items, it)
731 evas_object_show(VIEW(it));
732 evas_object_box_append(wd->bx, VIEW(it));
736 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
738 if ((vw >= mw) && (vh >= mh))
739 evas_object_resize(wd->bx, vw, vh);
741 evas_object_resize(wd->bx, mw, vh);
743 evas_object_resize(wd->bx, vw, mh);
749 if ((vh >= mh) && (h != vh)) evas_object_resize(wd->bx, w, vh);
753 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
755 EINA_INLIST_FOREACH(wd->items, it)
765 _mirrored_set(obj, elm_widget_mirrored_get(obj));
769 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
772 _resize(data, NULL, NULL, NULL);
776 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
778 Widget_Data *wd = elm_widget_data_get(data);
780 wd->resize_job = ecore_job_add(_resize_job, data);
784 _select_filter(Elm_Toolbar_Item *it, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
787 char buf[sizeof("elm,action,click,") + 1];
789 button = atoi(emission + sizeof("mouse,clicked,") - 1);
790 if (button == 1) return; /* regular left click event */
791 snprintf(buf, sizeof(buf), "elm,action,click,%d", button);
792 edje_object_signal_emit(VIEW(it), buf, "elm");
796 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
798 Elm_Toolbar_Item *it = data;
800 if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
801 (_elm_access_2nd_click_timeout(VIEW(it))))
803 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
804 _elm_access_say(E_("Selected"));
810 _long_press(Elm_Toolbar_Item *it)
812 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
813 wd->long_timer = NULL;
814 wd->long_press = EINA_TRUE;
815 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
816 return ECORE_CALLBACK_CANCEL;
820 _mouse_down(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Down *ev)
822 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
824 if (ev->button != 1) return;
825 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
826 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
827 wd->long_press = EINA_FALSE;
828 if (wd->long_timer) ecore_timer_interval_set(wd->long_timer, _elm_config->longpress_timeout);
829 else wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, (Ecore_Task_Cb)_long_press, it);
833 _mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
835 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
837 if (ev->button != 1) return;
840 ecore_timer_del(wd->long_timer);
841 wd->long_timer = NULL;
846 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
848 Elm_Toolbar_Item *it = data;
849 edje_object_signal_emit(VIEW(it), "elm,state,highlighted", "elm");
850 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
854 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
856 Elm_Toolbar_Item *it = data;
857 edje_object_signal_emit(VIEW(it), "elm,state,unhighlighted", "elm");
858 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
862 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
864 Evas_Object *obj = (Evas_Object *) data;
865 Widget_Data *wd = elm_widget_data_get(obj);
867 _els_box_layout(o, priv, !wd->vertical, wd->homogeneous,
868 elm_widget_mirrored_get(obj));
872 _access_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item)
874 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
875 const char *txt = item->access_info;
876 if (!txt) txt = it->label;
877 if (txt) return strdup(txt);
882 _access_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
884 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
886 return strdup(E_("Separator"));
887 else if (elm_widget_item_disabled_get(it))
888 return strdup(E_("State: Disabled"));
889 else if (it->selected)
890 return strdup(E_("State: Selected"));
892 return strdup(E_("Has menu"));
897 _item_del_pre_hook(Elm_Object_Item *it)
901 Elm_Toolbar_Item *item, *next;
902 item = (Elm_Toolbar_Item *)it;
904 wd = elm_widget_data_get(WIDGET(item));
905 if (!wd) return EINA_FALSE;
908 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
909 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
911 if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
912 if ((wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
913 item->selected && next) _item_select(next);
920 static Elm_Toolbar_Item *
921 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
923 Widget_Data *wd = elm_widget_data_get(obj);
924 Evas_Object *icon_obj;
926 Elm_Toolbar_Item *it;
928 icon_obj = elm_icon_add(obj);
929 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
930 if (!icon_obj) return NULL;
931 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
934 evas_object_del(icon_obj);
938 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
939 elm_widget_item_disable_hook_set(it, _item_disable_hook);
940 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
941 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
942 elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
943 elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
944 elm_widget_item_content_unset_hook_set(it, _item_content_unset_hook);
946 it->label = eina_stringshare_add(label);
947 it->prio.visible = 1;
948 it->prio.priority = 0;
950 it->separator = EINA_FALSE;
952 it->base.data = data;
953 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
954 _elm_access_item_register(&it->base, VIEW(it));
955 _elm_access_text_set(_elm_access_item_get(&it->base),
956 ELM_ACCESS_TYPE, E_("Tool Item"));
957 _elm_access_callback_set(_elm_access_item_get(&it->base),
958 ELM_ACCESS_INFO, _access_info_cb, it);
959 _elm_access_callback_set(_elm_access_item_get(&it->base),
960 ELM_ACCESS_STATE, _access_state_cb, it);
962 if (_item_icon_set(icon_obj, "toolbar/", icon))
965 it->icon_str = eina_stringshare_add(icon);
971 evas_object_del(icon_obj);
974 _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
975 elm_widget_style_get(obj));
976 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "elm",
978 edje_object_signal_callback_add(VIEW(it), "mouse,clicked,*", "*",
979 (Edje_Signal_Cb)_select_filter, it);
980 edje_object_signal_callback_add(VIEW(it), "elm,mouse,in", "elm",
982 edje_object_signal_callback_add(VIEW(it), "elm,mouse,out", "elm",
984 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
985 (Evas_Object_Event_Cb)_mouse_down, it);
986 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
987 (Evas_Object_Event_Cb)_mouse_up, it);
988 elm_widget_sub_object_add(obj, VIEW(it));
993 ms = ((double)wd->icon_size * _elm_config->scale);
994 evas_object_size_hint_min_set(it->icon, ms, ms);
995 evas_object_size_hint_max_set(it->icon, ms, ms);
996 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
997 evas_object_show(it->icon);
998 elm_widget_sub_object_add(obj, it->icon);
1000 edje_object_part_text_set(VIEW(it), "elm.text", it->label);
1002 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1003 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
1004 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1005 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1009 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, -1.0);
1010 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, 0.5);
1014 evas_object_size_hint_weight_set(VIEW(it), -1.0, EVAS_HINT_EXPAND);
1015 evas_object_size_hint_align_set(VIEW(it), 0.5, EVAS_HINT_FILL);
1020 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1021 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, EVAS_HINT_FILL);
1023 evas_object_size_hint_min_set(VIEW(it), mw, mh);
1024 evas_object_size_hint_max_set(VIEW(it), -1, -1);
1025 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
1027 if ((!wd->items) && (wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS))
1034 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
1036 Evas_Coord mw = -1, mh = -1;
1037 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1038 edje_object_part_text_set(VIEW(item), "elm.text", item->label);
1040 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1041 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1042 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1043 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1047 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1048 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1052 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1053 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1058 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1059 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1061 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1065 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1067 Elm_Toolbar_Item *item = data;
1068 _elm_toolbar_item_label_update(item);
1069 edje_object_signal_callback_del(obj, emission, source,
1070 _elm_toolbar_item_label_set_cb);
1071 edje_object_signal_emit (VIEW(item), "elm,state,label,reset", "elm");
1075 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *sig)
1079 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
1081 eina_stringshare_replace(&item->label, label);
1082 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1083 if ((s) && (atoi(s)))
1085 edje_object_part_text_set(VIEW(item), "elm.text_new", item->label);
1086 edje_object_signal_emit (VIEW(item), sig, "elm");
1087 edje_object_signal_callback_add(VIEW(item),
1088 "elm,state,label_set,done", "elm",
1089 _elm_toolbar_item_label_set_cb, item);
1092 _elm_toolbar_item_label_update(item);
1093 _resize(WIDGET(item), NULL, NULL, NULL);
1097 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
1099 Elm_Toolbar_Item_State *it_state;
1101 Evas_Coord mw = -1, mh = -1;
1102 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1103 Evas_Object *old_icon = edje_object_part_swallow_get(VIEW(item),
1104 "elm.swallow.icon");
1105 elm_widget_sub_object_del(VIEW(item), old_icon);
1106 evas_object_hide(old_icon);
1107 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1108 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1109 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1110 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1111 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1115 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1116 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1120 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1121 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1126 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1127 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1129 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1131 EINA_LIST_FOREACH(item->states, l, it_state)
1133 if (it_state->icon == old_icon) return;
1135 evas_object_del(old_icon);
1139 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1141 Elm_Toolbar_Item *item = data;
1142 edje_object_part_unswallow(VIEW(item), item->icon);
1143 _elm_toolbar_item_icon_update(item);
1144 edje_object_signal_callback_del(obj, emission, source,
1145 _elm_toolbar_item_icon_set_cb);
1146 edje_object_signal_emit (VIEW(item), "elm,state,icon,reset", "elm");
1150 _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)
1152 Evas_Object *old_icon;
1157 eina_stringshare_replace(&item->icon_str, icon_str);
1160 eina_stringshare_del(item->icon_str);
1161 item->icon_str = NULL;
1163 item->icon = icon_obj;
1166 ms = (icon_size * _elm_config->scale);
1167 evas_object_size_hint_min_set(item->icon, ms, ms);
1168 evas_object_size_hint_max_set(item->icon, ms, ms);
1169 evas_object_show(item->icon);
1170 elm_widget_sub_object_add(obj, item->icon);
1172 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1173 if ((s) && (atoi(s)))
1175 old_icon = edje_object_part_swallow_get(VIEW(item),
1176 "elm.swallow.icon_new");
1179 elm_widget_sub_object_del(VIEW(item), old_icon);
1180 evas_object_hide(old_icon);
1182 edje_object_part_swallow(VIEW(item), "elm.swallow.icon_new",
1184 edje_object_signal_emit (VIEW(item), sig, "elm");
1185 edje_object_signal_callback_add(VIEW(item),
1186 "elm,state,icon_set,done", "elm",
1187 _elm_toolbar_item_icon_set_cb, item);
1190 _elm_toolbar_item_icon_update(item);
1191 _resize(obj, NULL, NULL, NULL);
1195 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1197 Elm_Toolbar_Item *it = event_info;
1198 Elm_Toolbar_Item_State *it_state;
1200 it_state = eina_list_data_get(it->current_state);
1202 it_state->func((void *)it_state->data, obj, event_info);
1205 static Elm_Toolbar_Item_State *
1206 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1208 Elm_Toolbar_Item_State *it_state;
1209 it_state = ELM_NEW(Elm_Toolbar_Item_State);
1210 it_state->label = eina_stringshare_add(label);
1211 it_state->icon_str = eina_stringshare_add(icon_str);
1212 it_state->icon = icon;
1213 it_state->func = func;
1214 it_state->data = data;
1219 elm_toolbar_add(Evas_Object *parent)
1225 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1227 ELM_SET_WIDTYPE(widtype, "toolbar");
1228 elm_widget_type_set(obj, "toolbar");
1229 elm_widget_sub_object_add(parent, obj);
1230 elm_widget_data_set(obj, wd);
1231 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1232 elm_widget_del_hook_set(obj, _del_hook);
1233 elm_widget_theme_hook_set(obj, _theme_hook);
1234 elm_widget_translate_hook_set(obj, _translate_hook);
1235 elm_widget_can_focus_set(obj, EINA_TRUE);
1237 wd->more_item = NULL;
1238 wd->selected_item = NULL;
1239 wd->scr = elm_smart_scroller_add(e);
1240 elm_smart_scroller_widget_set(wd->scr, obj);
1241 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
1242 elm_smart_scroller_bounce_allow_set(wd->scr,
1243 _elm_config->thumbscroll_bounce_enable,
1245 elm_widget_resize_object_set(obj, wd->scr);
1246 elm_smart_scroller_policy_set(wd->scr,
1247 ELM_SMART_SCROLLER_POLICY_AUTO,
1248 ELM_SMART_SCROLLER_POLICY_OFF);
1251 wd->icon_size = _elm_toolbar_icon_size_get(wd);
1254 wd->homogeneous = EINA_TRUE;
1257 wd->bx = evas_object_box_add(e);
1258 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
1259 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
1260 elm_widget_sub_object_add(obj, wd->bx);
1261 elm_smart_scroller_child_set(wd->scr, wd->bx);
1262 evas_object_show(wd->bx);
1264 elm_toolbar_shrink_mode_set(obj, _elm_config->toolbar_shrink_mode);
1265 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
1266 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
1267 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
1269 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1276 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
1278 ELM_CHECK_WIDTYPE(obj, widtype);
1279 Widget_Data *wd = elm_widget_data_get(obj);
1281 if (wd->icon_size == icon_size) return;
1282 wd->icon_size = icon_size;
1287 elm_toolbar_icon_size_get(const Evas_Object *obj)
1289 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1290 Widget_Data *wd = elm_widget_data_get(obj);
1292 return wd->icon_size;
1295 EAPI Elm_Object_Item *
1296 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1298 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1299 Widget_Data *wd = elm_widget_data_get(obj);
1300 if (!wd) return NULL;
1302 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1303 if (!it) return NULL;
1304 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1306 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
1307 evas_object_box_append(wd->bx, VIEW(it));
1308 evas_object_show(VIEW(it));
1310 _theme_hook_item(obj, it, scale, wd->icon_size);
1313 return (Elm_Object_Item *)it;
1316 EAPI Elm_Object_Item *
1317 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1319 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1320 Widget_Data *wd = elm_widget_data_get(obj);
1321 if (!wd) return NULL;
1323 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1324 if (!it) return NULL;
1325 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1327 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1328 evas_object_box_prepend(wd->bx, VIEW(it));
1329 evas_object_show(VIEW(it));
1330 _theme_hook_item(obj, it, scale, wd->icon_size);
1333 return (Elm_Object_Item *)it;
1336 EAPI Elm_Object_Item *
1337 elm_toolbar_item_insert_before(Evas_Object *obj, Elm_Object_Item *before, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1339 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1340 ELM_OBJ_ITEM_CHECK_OR_RETURN(before, NULL);
1342 Elm_Toolbar_Item *it, *_before;
1344 wd = elm_widget_data_get(obj);
1345 if (!wd) return NULL;
1346 _before = (Elm_Toolbar_Item *) before;
1347 it = _item_new(obj, icon, label, func, data);
1348 if (!it) return NULL;
1349 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1351 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1352 EINA_INLIST_GET(_before));
1353 evas_object_box_insert_before(wd->bx, VIEW(it), VIEW(_before));
1354 evas_object_show(VIEW(it));
1355 _theme_hook_item(obj, it, scale, wd->icon_size);
1358 return (Elm_Object_Item *)it;
1361 EAPI Elm_Object_Item *
1362 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)
1364 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1365 ELM_OBJ_ITEM_CHECK_OR_RETURN(after, NULL);
1367 Elm_Toolbar_Item *it, *_after;
1369 wd = elm_widget_data_get(obj);
1370 if (!wd) return NULL;
1371 _after = (Elm_Toolbar_Item *) after;
1372 it = _item_new(obj, icon, label, func, data);
1373 if (!it) return NULL;
1374 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1376 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1377 EINA_INLIST_GET(_after));
1378 evas_object_box_insert_after(wd->bx, VIEW(it), VIEW(_after));
1379 evas_object_show(VIEW(it));
1380 _theme_hook_item(obj, it, scale, wd->icon_size);
1383 return (Elm_Object_Item *)it;
1386 EAPI Elm_Object_Item *
1387 elm_toolbar_first_item_get(const Evas_Object *obj)
1389 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1390 Widget_Data *wd = elm_widget_data_get(obj);
1391 if (!wd || !wd->items) return NULL;
1392 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1395 EAPI Elm_Object_Item *
1396 elm_toolbar_last_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->last);
1404 EAPI Elm_Object_Item *
1405 elm_toolbar_item_next_get(const Elm_Object_Item *it)
1407 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1408 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1409 EINA_INLIST_GET(((Elm_Toolbar_Item *)it))->next);
1412 EAPI Elm_Object_Item *
1413 elm_toolbar_item_prev_get(const Elm_Object_Item *it)
1415 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1416 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1417 EINA_INLIST_GET(((Elm_Toolbar_Item *)it))->prev);
1421 elm_toolbar_item_priority_set(Elm_Object_Item *it, int priority)
1423 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1424 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1425 if (item->prio.priority == priority) return;
1426 item->prio.priority = priority;
1427 _resize(WIDGET(item), NULL, NULL, NULL);
1431 elm_toolbar_item_priority_get(const Elm_Object_Item *it)
1433 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
1434 return ((Elm_Toolbar_Item *)it)->prio.priority;
1437 EAPI Elm_Object_Item *
1438 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
1440 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1441 Elm_Toolbar_Item *it;
1442 Widget_Data *wd = elm_widget_data_get(obj);
1443 if (!wd) return NULL;
1445 EINA_INLIST_FOREACH(wd->items, it)
1447 if (!strcmp(it->label, label))
1448 return (Elm_Object_Item *)it;
1454 elm_toolbar_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1456 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1457 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1458 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1461 if (item->selected == selected) return;
1462 if (selected) _item_select(item);
1463 else _item_unselect(item);
1467 elm_toolbar_item_selected_get(const Elm_Object_Item *it)
1469 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1470 return ((Elm_Toolbar_Item *)it)->selected;
1473 EAPI Elm_Object_Item *
1474 elm_toolbar_selected_item_get(const Evas_Object *obj)
1476 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1477 Widget_Data *wd = elm_widget_data_get(obj);
1478 if (!wd) return NULL;
1479 return (Elm_Object_Item *) wd->selected_item;
1483 elm_toolbar_item_icon_set(Elm_Object_Item *it, const char *icon)
1485 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1487 Evas_Object *icon_obj;
1490 Elm_Toolbar_Item * item = (Elm_Toolbar_Item *)it;
1493 wd = elm_widget_data_get(obj);
1495 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1497 icon_obj = elm_icon_add(obj);
1498 if (!icon_obj) return;
1499 if (_item_icon_set(icon_obj, "toolbar/", icon))
1500 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1501 "elm,state,icon_set");
1504 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1505 "elm,state,icon_set");
1506 evas_object_del(icon_obj);
1511 elm_toolbar_item_icon_get(const Elm_Object_Item *it)
1513 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1514 return ((Elm_Toolbar_Item *)it)->icon_str;
1518 elm_toolbar_item_object_get(const Elm_Object_Item *it)
1520 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1524 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1527 wd = elm_widget_data_get(obj);
1528 if (!wd) return NULL;
1534 elm_toolbar_item_icon_object_get(Elm_Object_Item *it)
1536 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1537 return ((Elm_Toolbar_Item *)it)->icon;
1541 elm_toolbar_item_icon_memfile_set(Elm_Object_Item *it, const void *img, size_t size, const char *format, const char *key)
1543 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1545 Evas_Object *icon_obj;
1549 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1552 wd = elm_widget_data_get(obj);
1553 if (!wd) return EINA_FALSE;
1557 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1558 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1559 ret = _els_smart_icon_memfile_set(icon_obj, img, size, format, key);
1562 evas_object_del(icon_obj);
1565 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1566 "elm,state,icon_set");
1569 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1574 elm_toolbar_item_icon_file_set(Elm_Object_Item *it, const char *file, const char *key)
1576 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1578 Evas_Object *icon_obj;
1582 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1585 wd = elm_widget_data_get(obj);
1586 if (!wd) return EINA_FALSE;
1590 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1591 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1592 ret = _els_smart_icon_file_key_set(icon_obj, file, key);
1595 evas_object_del(icon_obj);
1598 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1599 "elm,state,icon_set");
1602 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1607 elm_toolbar_item_separator_set(Elm_Object_Item *it, Eina_Bool separator)
1609 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1610 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1611 Evas_Object *obj = WIDGET(item);
1612 Widget_Data *wd = elm_widget_data_get(obj);
1614 if (item->separator == separator) return;
1615 item->separator = separator;
1616 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1617 _theme_hook_item(obj, item, scale, wd->icon_size);
1621 elm_toolbar_item_separator_get(const Elm_Object_Item *it)
1623 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1624 return ((Elm_Toolbar_Item *)it)->separator;
1628 elm_toolbar_shrink_mode_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
1630 ELM_CHECK_WIDTYPE(obj, widtype);
1631 Widget_Data *wd = elm_widget_data_get(obj);
1635 wd->shrink_mode = shrink_mode;
1636 bounce = (_elm_config->thumbscroll_bounce_enable) &&
1637 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
1638 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
1642 _item_del(wd->more_item);
1643 elm_widget_item_free(wd->more_item);
1644 wd->more_item = NULL;
1647 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
1649 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1650 ELM_SMART_SCROLLER_POLICY_OFF);
1651 wd->more_item = _item_new(obj, "more_menu", "More", NULL, NULL);
1653 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
1654 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
1655 ELM_SMART_SCROLLER_POLICY_OFF);
1657 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
1658 ELM_SMART_SCROLLER_POLICY_OFF);
1662 EAPI Elm_Toolbar_Shrink_Mode
1663 elm_toolbar_shrink_mode_get(const Evas_Object *obj)
1665 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
1666 Widget_Data *wd = elm_widget_data_get(obj);
1668 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
1669 return wd->shrink_mode;
1673 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
1675 ELM_CHECK_WIDTYPE(obj, widtype);
1676 Widget_Data *wd = elm_widget_data_get(obj);
1679 wd->homogeneous = !!homogeneous;
1680 evas_object_smart_calculate(wd->bx);
1684 elm_toolbar_homogeneous_get(const Evas_Object *obj)
1686 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
1687 Widget_Data *wd = elm_widget_data_get(obj);
1689 if (!wd) return EINA_FALSE;
1690 return wd->homogeneous;
1694 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
1696 Elm_Toolbar_Item *it;
1697 ELM_CHECK_WIDTYPE(obj, widtype);
1698 Widget_Data *wd = elm_widget_data_get(obj);
1701 EINA_SAFETY_ON_NULL_RETURN(parent);
1702 wd->menu_parent = parent;
1703 EINA_INLIST_FOREACH(wd->items, it)
1706 elm_menu_parent_set(it->o_menu, wd->menu_parent);
1708 if ((wd->more_item) && (wd->more_item->o_menu))
1709 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
1713 elm_toolbar_menu_parent_get(const Evas_Object *obj)
1715 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1716 Widget_Data *wd = elm_widget_data_get(obj);
1718 if (!wd) return NULL;
1719 return wd->menu_parent;
1723 elm_toolbar_align_set(Evas_Object *obj, double align)
1725 ELM_CHECK_WIDTYPE(obj, widtype);
1726 Widget_Data *wd = elm_widget_data_get(obj);
1731 if (wd->align != align)
1732 evas_object_size_hint_align_set(wd->bx, 0.5, align);
1736 if (wd->align != align)
1737 evas_object_size_hint_align_set(wd->bx, align, 0.5);
1743 elm_toolbar_align_get(const Evas_Object *obj)
1745 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
1746 Widget_Data *wd = elm_widget_data_get(obj);
1748 if (!wd) return 0.0;
1753 elm_toolbar_item_menu_set(Elm_Object_Item *it, Eina_Bool menu)
1755 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1756 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1757 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1760 if (item->menu == menu) return;
1761 if (menu) _item_menu_create(wd, item);
1762 else _item_menu_destroy(item);
1766 elm_toolbar_item_menu_get(const Elm_Object_Item *it)
1768 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1769 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1770 if (!item->menu) return NULL;
1771 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1772 if (!wd) return NULL;
1773 return item->o_menu;
1776 EAPI Elm_Toolbar_Item_State *
1777 elm_toolbar_item_state_add(Elm_Object_Item *it, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1779 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1781 Elm_Toolbar_Item_State *it_state;
1782 Evas_Object *icon_obj;
1785 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1787 wd = elm_widget_data_get(WIDGET(item));
1788 if (!wd) return NULL;
1792 it_state = _item_state_new(item->label, item->icon_str, item->icon,
1793 item->func, item->base.data);
1794 item->states = eina_list_append(item->states, it_state);
1795 item->current_state = item->states;
1798 icon_obj = elm_icon_add(obj);
1799 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1800 if (!icon_obj) goto error_state_add;
1802 if (!_item_icon_set(icon_obj, "toolbar/", icon))
1804 evas_object_del(icon_obj);
1809 it_state = _item_state_new(label, icon, icon_obj, func, data);
1810 item->states = eina_list_append(item->states, it_state);
1811 item->func = _elm_toolbar_item_state_cb;
1812 item->base.data = NULL;
1817 if (item->states && !eina_list_next(item->states))
1819 eina_stringshare_del(item->label);
1820 eina_stringshare_del(item->icon_str);
1821 free(eina_list_data_get(item->states));
1822 eina_list_free(item->states);
1823 item->states = NULL;
1829 elm_toolbar_item_state_del(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1831 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1833 Eina_List *del_state;
1834 Elm_Toolbar_Item_State *it_state;
1835 Elm_Toolbar_Item *item;
1837 if (!state) return EINA_FALSE;
1839 item = (Elm_Toolbar_Item *)it;
1840 if (!item->states) return EINA_FALSE;
1842 del_state = eina_list_data_find_list(item->states, state);
1843 if (del_state == item->states) return EINA_FALSE;
1844 if (del_state == item->current_state)
1845 elm_toolbar_item_state_unset(it);
1847 eina_stringshare_del(state->label);
1848 eina_stringshare_del(state->icon_str);
1849 if (state->icon) evas_object_del(state->icon);
1851 item->states = eina_list_remove_list(item->states, del_state);
1852 if (item->states && !eina_list_next(item->states))
1854 it_state = eina_list_data_get(item->states);
1855 item->base.data = it_state->data;
1856 item->func = it_state->func;
1857 eina_stringshare_del(it_state->label);
1858 eina_stringshare_del(it_state->icon_str);
1859 free(eina_list_data_get(item->states));
1860 eina_list_free(item->states);
1861 item->states = NULL;
1867 elm_toolbar_item_state_set(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
1869 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1872 Eina_List *next_state;
1873 Elm_Toolbar_Item_State *it_state;
1875 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1878 wd = elm_widget_data_get(obj);
1879 if (!wd) return EINA_FALSE;
1880 if (!item->states) return EINA_FALSE;
1884 next_state = eina_list_data_find_list(item->states, state);
1885 if (!next_state) return EINA_FALSE;
1888 next_state = item->states;
1890 if (next_state == item->current_state) return EINA_TRUE;
1892 it_state = eina_list_data_get(next_state);
1893 if (eina_list_data_find(item->current_state, state))
1895 _item_label_set(item, it_state->label, "elm,state,label_set,forward");
1896 _elm_toolbar_item_icon_obj_set(obj, item, it_state->icon, it_state->icon_str,
1897 wd->icon_size, "elm,state,icon_set,forward");
1901 _item_label_set(item, it_state->label, "elm,state,label_set,backward");
1902 _elm_toolbar_item_icon_obj_set(obj,
1907 "elm,state,icon_set,backward");
1909 if (elm_widget_item_disabled_get(item))
1910 elm_widget_signal_emit(item->icon, "elm,state,disabled", "elm");
1912 elm_widget_signal_emit(item->icon, "elm,state,enabled", "elm");
1914 item->current_state = next_state;
1919 elm_toolbar_item_state_unset(Elm_Object_Item *it)
1921 elm_toolbar_item_state_set(it, NULL);
1924 EAPI Elm_Toolbar_Item_State *
1925 elm_toolbar_item_state_get(const Elm_Object_Item *it)
1927 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1928 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1930 if ((!item->states) || (!item->current_state)) return NULL;
1931 if (item->current_state == item->states) return NULL;
1933 return eina_list_data_get(item->current_state);
1936 EAPI Elm_Toolbar_Item_State *
1937 elm_toolbar_item_state_next(Elm_Object_Item *it)
1939 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1943 Eina_List *next_state;
1944 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1947 wd = elm_widget_data_get(obj);
1948 if (!wd) return NULL;
1949 if (!item->states) return NULL;
1951 next_state = eina_list_next(item->current_state);
1953 next_state = eina_list_next(item->states);
1954 return eina_list_data_get(next_state);
1957 EAPI Elm_Toolbar_Item_State *
1958 elm_toolbar_item_state_prev(Elm_Object_Item *it)
1960 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1964 Eina_List *prev_state;
1965 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1968 wd = elm_widget_data_get(obj);
1969 if (!wd) return NULL;
1970 if (!item->states) return NULL;
1972 prev_state = eina_list_prev(item->current_state);
1973 if ((!prev_state) || (prev_state == item->states))
1974 prev_state = eina_list_last(item->states);
1975 return eina_list_data_get(prev_state);
1979 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
1981 ELM_CHECK_WIDTYPE(obj, widtype);
1982 Elm_Toolbar_Item *it;
1983 Widget_Data *wd = elm_widget_data_get(obj);
1986 wd->lookup_order = order;
1987 EINA_INLIST_FOREACH(wd->items, it)
1988 elm_icon_order_lookup_set(it->icon, order);
1990 elm_icon_order_lookup_set(wd->more_item->icon, order);
1993 EAPI Elm_Icon_Lookup_Order
1994 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
1996 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
1997 Widget_Data *wd = elm_widget_data_get(obj);
1998 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
1999 return wd->lookup_order;
2003 elm_toolbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
2005 ELM_CHECK_WIDTYPE(obj, widtype);
2006 Widget_Data *wd = elm_widget_data_get(obj);
2008 wd->vertical = !horizontal;
2010 evas_object_size_hint_align_set(wd->bx, 0.5, wd->align);
2012 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
2017 elm_toolbar_horizontal_get(const Evas_Object *obj)
2019 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2020 Widget_Data *wd = elm_widget_data_get(obj);
2021 if (!wd) return EINA_FALSE;
2022 return !wd->vertical;
2026 elm_toolbar_items_count(const Evas_Object *obj)
2028 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2029 Widget_Data *wd = elm_widget_data_get(obj);
2031 return wd->item_count;
2035 elm_toolbar_select_mode_set(Evas_Object *obj, Elm_Object_Select_Mode mode)
2037 ELM_CHECK_WIDTYPE(obj, widtype);
2038 Widget_Data *wd = elm_widget_data_get(obj);
2040 if (mode >= ELM_OBJECT_SELECT_MODE_MAX)
2042 if ((mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2043 (wd->select_mode != ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2045 _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
2046 if (wd->select_mode != mode)
2047 wd->select_mode = mode;
2050 EAPI Elm_Object_Select_Mode
2051 elm_toolbar_select_mode_get(const Evas_Object *obj)
2053 ELM_CHECK_WIDTYPE(obj, widtype) ELM_OBJECT_SELECT_MODE_MAX;
2054 Widget_Data *wd = elm_widget_data_get(obj);
2055 if (!wd) return ELM_OBJECT_SELECT_MODE_MAX;
2056 return wd->select_mode;