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, *more, *bx_more, *bx_more2;
13 Evas_Object *menu_parent;
15 Elm_Toolbar_Item *more_item, *selected_item;
16 Elm_Toolbar_Item *reorder_from, *reorder_to;
17 Elm_Toolbar_Shrink_Mode shrink_mode;
18 Elm_Icon_Lookup_Order lookup_order;
20 int standard_priority;
21 unsigned int item_count;
23 Elm_Object_Select_Mode select_mode;
24 Eina_Bool homogeneous : 1;
25 Eina_Bool vertical : 1;
26 Eina_Bool long_press : 1;
27 Ecore_Timer *long_timer;
28 Ecore_Job *resize_job;
31 struct _Elm_Toolbar_Item
45 Eina_Bool visible : 1;
47 Eina_Bool selected : 1;
48 Eina_Bool separator : 1;
51 Eina_List *current_state;
54 #define ELM_TOOLBAR_ITEM_FROM_INLIST(item) \
55 ((item) ? EINA_INLIST_CONTAINER_GET(item, Elm_Toolbar_Item) : NULL)
57 struct _Elm_Toolbar_Item_State
66 static const char *widtype = NULL;
67 static void _item_show(Elm_Toolbar_Item *it);
68 static void _item_select(Elm_Toolbar_Item *it);
69 static void _item_unselect(Elm_Toolbar_Item *it);
70 static void _del_pre_hook(Evas_Object *obj);
71 static void _del_hook(Evas_Object *obj);
72 static void _mirrored_set(Evas_Object *obj, Eina_Bool mirrored);
73 static void _mirrored_set_item(Evas_Object *obj, Elm_Toolbar_Item *it, Eina_Bool mirrored);
74 static void _theme_hook(Evas_Object *obj);
75 static void _sizing_eval(Evas_Object *obj);
76 static void _resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
77 static void _menu_move_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
78 static void _menu_hide(void *data, Evas *e, Evas_Object *obj, void *event_info);
79 static void _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data);
80 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);
81 static void _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *sig);
83 static const char SIG_CLICKED[] = "clicked";
84 static const char SIG_LONGPRESSED[] = "longpressed";
85 static const char SIG_CLICKED_DOUBLE[] = "clicked,double";
87 static const Evas_Smart_Cb_Description _signals[] = {
89 {SIG_LONGPRESSED, ""},
90 {SIG_CLICKED_DOUBLE, ""},
95 _item_disable_hook(Elm_Object_Item *it)
98 Elm_Toolbar_Item *toolbar_it = (Elm_Toolbar_Item *)it;
100 wd = elm_widget_data_get(WIDGET(toolbar_it));
103 if (elm_widget_item_disabled_get(toolbar_it))
105 edje_object_signal_emit(VIEW(toolbar_it), "elm,state,disabled", "elm");
106 elm_widget_signal_emit(toolbar_it->icon, "elm,state,disabled", "elm");
110 edje_object_signal_emit(VIEW(toolbar_it), "elm,state,enabled", "elm");
111 elm_widget_signal_emit(toolbar_it->icon, "elm,state,enabled", "elm");
113 _resize(WIDGET(toolbar_it), NULL, NULL, NULL);
117 _item_icon_set(Evas_Object *icon_obj, const char *type, const char *icon)
121 if ((!type) || (!*type)) goto end;
122 if ((!icon) || (!*icon)) return EINA_FALSE;
123 if ((snprintf(icon_str, sizeof(icon_str), "%s%s", type, icon) > 0)
124 && (elm_icon_standard_set(icon_obj, icon_str)))
127 if (elm_icon_standard_set(icon_obj, icon))
129 WRN("couldn't find icon definition for '%s'", icon);
134 _elm_toolbar_icon_size_get(Widget_Data *wd)
136 const char *icon_size = edje_object_data_get(
137 elm_smart_scroller_edje_object_get(wd->scr), "icon_size");
139 return atoi(icon_size);
140 return _elm_config->icon_size;
144 _item_show(Elm_Toolbar_Item *it)
146 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
147 Evas_Coord x, y, w, h, bx, by;
150 evas_object_geometry_get(wd->bx, &bx, &by, NULL, NULL);
151 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
152 elm_smart_scroller_child_region_show(wd->scr, x - bx, y - by, w, h);
156 _item_unselect(Elm_Toolbar_Item *item)
159 if ((!item) || (!item->selected)) return;
160 wd = elm_widget_data_get(WIDGET(item));
162 item->selected = EINA_FALSE;
163 wd->selected_item = NULL;
164 edje_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
165 elm_widget_signal_emit(item->icon, "elm,state,unselected", "elm");
169 _item_select(Elm_Toolbar_Item *it)
171 Elm_Toolbar_Item *it2;
172 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
175 Evas_Coord w = 0, h = 0;
178 if (elm_widget_item_disabled_get(it) || (it->separator) || (it->object)) return;
181 if (it->object) evas_object_geometry_get(it->object, NULL, NULL, &w, &h);
183 if (wd->select_mode != ELM_OBJECT_SELECT_MODE_NONE)
187 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
188 if (wd->more_item == it)
190 edje_object_signal_emit(elm_layout_edje_get(wd->more), "elm,state,close", "elm");
193 if (wd->select_mode != ELM_OBJECT_SELECT_MODE_ALWAYS)
198 it2 = (Elm_Toolbar_Item *)
199 elm_toolbar_selected_item_get(WIDGET(it));
202 it->selected = EINA_TRUE;
203 wd->selected_item = it;
204 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
206 if (wd->more_item == it)
208 if (!evas_object_box_children_get(wd->bx_more2))
209 edje_object_signal_emit(elm_layout_edje_get(wd->more), "elm,state,open", "elm");
211 edje_object_signal_emit(elm_layout_edje_get(wd->more), "elm,state,open2", "elm");
215 if (it->in_box != wd->bx)
217 edje_object_signal_emit(wd->VIEW(more_item), "elm,state,selected", "elm");
218 elm_widget_signal_emit(wd->more_item->icon, "elm,state,selected", "elm");
222 edje_object_signal_emit(wd->VIEW(more_item), "elm,state,unselected", "elm");
223 elm_widget_signal_emit(wd->more_item->icon, "elm,state,unselected", "elm");
225 edje_object_signal_emit(elm_layout_edje_get(wd->more), "elm,state,close", "elm");
228 edje_object_signal_emit(VIEW(it), "elm,state,selected", "elm");
229 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
234 if (it->menu && (!sel))
236 evas_object_show(it->o_menu);
237 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
238 _menu_move_resize, it);
239 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOVE,
240 _menu_move_resize, it);
242 _menu_move_resize(it, NULL, NULL, NULL);
244 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
245 evas_object_smart_callback_call(obj2, SIG_CLICKED, it);
249 _menu_hide(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
251 Elm_Toolbar_Item *selected;
252 Elm_Toolbar_Item *it = data;
253 selected = (Elm_Toolbar_Item *) elm_toolbar_selected_item_get(WIDGET(it));
254 _item_unselect(selected);
258 _menu_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
260 // avoid hide being emitted during object deletion
261 evas_object_event_callback_del_full
262 (obj, EVAS_CALLBACK_HIDE, _menu_hide, data);
266 _menu_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
268 Elm_Toolbar_Item *it = data;
270 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
272 if ((!wd) || (!wd->menu_parent)) return;
273 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
274 elm_menu_move(it->o_menu, x, y+h);
278 _item_del(Elm_Toolbar_Item *it)
280 Elm_Toolbar_Item_State *it_state;
282 EINA_LIST_FREE(it->states, it_state)
284 if (it->icon == it_state->icon)
286 eina_stringshare_del(it_state->label);
287 eina_stringshare_del(it_state->icon_str);
288 if (it_state->icon) evas_object_del(it_state->icon);
291 eina_stringshare_del(it->label);
292 eina_stringshare_del(it->icon_str);
293 if (it->icon) evas_object_del(it->icon);
294 if (it->object) evas_object_del(it->object);
295 //TODO: See if checking for wd->menu_parent is necessary before deleting menu
296 if (it->o_menu) evas_object_del(it->o_menu);
300 _del_pre_hook(Evas_Object *obj)
302 Widget_Data *wd = elm_widget_data_get(obj);
303 Elm_Toolbar_Item *it, *next;
306 it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
309 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
311 elm_widget_item_free(it);
316 _item_del(wd->more_item);
317 elm_widget_item_free(wd->more_item);
321 ecore_timer_del(wd->long_timer);
322 wd->long_timer = NULL;
327 _del_hook(Evas_Object *obj)
329 Widget_Data *wd = elm_widget_data_get(obj);
337 _mirrored_set_item(Evas_Object *obj __UNUSED__, Elm_Toolbar_Item *it, Eina_Bool mirrored)
339 edje_object_mirrored_set(VIEW(it), mirrored);
340 if (it->o_menu) elm_widget_mirrored_set(it->o_menu, mirrored);
344 _theme_hook_item(Evas_Object *obj, Elm_Toolbar_Item *it, double scale, int icon_size)
346 Widget_Data *wd = elm_widget_data_get(obj);
347 Evas_Object *view = VIEW(it);
348 Evas_Coord mw, mh, minw, minh;
349 const char *style = elm_widget_style_get(obj);
351 _mirrored_set_item(obj, it, elm_widget_mirrored_get(obj));
352 edje_object_scale_set(view, scale);
353 if (!it->separator && !it->object)
355 _elm_theme_object_set(obj, view, "toolbar", "item", style);
358 edje_object_signal_emit(view, "elm,state,selected", "elm");
359 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
361 if (elm_widget_item_disabled_get(it))
363 edje_object_signal_emit(view, "elm,state,disabled", "elm");
364 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
370 ms = ((double)icon_size * scale);
371 evas_object_size_hint_min_set(it->icon, ms, ms);
372 evas_object_size_hint_max_set(it->icon, ms, ms);
373 edje_object_part_swallow(view, "elm.swallow.icon", it->icon);
375 edje_object_part_text_escaped_set(view, "elm.text", it->label);
381 _elm_theme_object_set(obj, view, "toolbar", "separator", style);
384 evas_object_size_hint_weight_set(view, EVAS_HINT_EXPAND, -1.0);
385 evas_object_size_hint_align_set(view, EVAS_HINT_FILL, 0.5);
389 evas_object_size_hint_weight_set(view, -1.0, EVAS_HINT_EXPAND);
390 evas_object_size_hint_align_set(view, 0.5, EVAS_HINT_FILL);
395 _elm_theme_object_set(obj, view, "toolbar", "object", style);
396 edje_object_part_swallow(view, "elm.swallow.object", it->object);
400 mw = mh = minw = minh = -1;
401 if (!it->separator && !it->object)
402 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
403 edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
404 if (!it->separator && !it->object)
405 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
406 evas_object_size_hint_min_get(view, &minw, &minh);
407 if ((minw < mw) && (minh < mh))
408 evas_object_size_hint_min_set(view, mw, mh);
409 else if ((minw < mw) && (minh > mh))
410 evas_object_size_hint_min_set(view, mw, minh);
411 else if ((minw > mw) && (minh < mh))
412 evas_object_size_hint_min_set(view, minw, mh);
416 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
418 Widget_Data *wd = elm_widget_data_get(obj);
419 Elm_Toolbar_Item *it;
421 EINA_INLIST_FOREACH(wd->items, it)
422 _mirrored_set_item(obj, it, mirrored);
424 _mirrored_set_item(obj, wd->more_item, mirrored);
428 _theme_hook(Evas_Object *obj)
430 Widget_Data *wd = elm_widget_data_get(obj);
431 Elm_Toolbar_Item *it;
435 _elm_widget_mirrored_reload(obj);
436 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
437 _mirrored_set(obj, elm_widget_mirrored_get(obj));
438 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
439 edje_object_scale_set(wd->scr, scale);
440 wd->icon_size = _elm_toolbar_icon_size_get(wd);
441 EINA_INLIST_FOREACH(wd->items, it)
442 _theme_hook_item(obj, it, scale, wd->icon_size);
444 _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
449 _item_text_set_hook(Elm_Object_Item *it,
453 if (part && strcmp(part, "default")) return;
454 _item_label_set(((Elm_Toolbar_Item *)it), label, "elm,state,label_set");
458 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
460 if (part && strcmp(part, "default")) return NULL;
461 return ((Elm_Toolbar_Item *)it)->label;
465 _item_content_set_hook(Elm_Object_Item *it,
467 Evas_Object *content)
471 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
472 if (part && strcmp(part, "object")) return;
473 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
474 Evas_Object *obj = WIDGET(item);
475 Widget_Data *wd = elm_widget_data_get(obj);
476 if (!wd || !obj) return;
477 if (item->object == content) return;
479 if (item->object) evas_object_del(item->object);
481 item->object = content;
483 elm_widget_sub_object_add(obj, item->object);
484 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
485 _theme_hook_item(obj, item, scale, wd->icon_size);
489 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
491 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
492 if (part && strcmp(part, "object")) return NULL;
493 return ((Elm_Toolbar_Item *) it)->object;
497 _item_content_unset_hook(Elm_Object_Item *it, const char *part)
502 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
503 if (part && strcmp(part, "object")) return NULL;
504 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
505 Evas_Object *obj = WIDGET(item);
506 Widget_Data *wd = elm_widget_data_get(obj);
508 edje_object_part_unswallow(VIEW(it), item->object);
509 elm_widget_sub_object_del(obj, item->object);
512 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
513 _theme_hook_item(obj, item, scale, wd->icon_size);
518 _translate_hook(Evas_Object *obj)
520 evas_object_smart_callback_call(obj, "language,changed", NULL);
524 _sizing_eval(Evas_Object *obj)
526 Widget_Data *wd = elm_widget_data_get(obj);
527 Evas_Coord minw = -1, minh = -1, minw_bx = -1, minh_bx = -1;
528 Evas_Coord vw = 0, vh = 0;
532 evas_object_smart_need_recalculate_set(wd->bx, EINA_TRUE);
533 evas_object_smart_calculate(wd->bx);
534 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
536 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
537 if (w < minw) w = minw;
538 if (h < minh) h = minh;
539 evas_object_resize(wd->scr, w, h);
541 evas_object_size_hint_min_get(wd->bx, &minw_bx, &minh_bx);
542 // if (wd->vertical && (h > minh)) minh = h;
543 // if ((!wd->vertical) && (w > minw)) minw = w;
544 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
545 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_NONE)
549 minw = minw_bx + (w - vw);
550 minh = minh_bx + (h - vh);
554 minw = minw_bx + (w - vw);
555 minh = minh_bx + (h - vh);
558 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
560 minw = minw_bx + (w - vw);
561 minh = minh_bx + (h - vh);
562 if (minw_bx < vw) minw_bx = vw;
563 if (minh_bx < vh) minh_bx = vh;
569 minw = minw_bx + (w - vw);
575 minh = minh_bx + (h - vh);
577 // if (wd->vertical) minh = h - vh;
578 // else minw = w - vw;
579 // minh = minh + (h - vh);
581 evas_object_resize(wd->bx, minw_bx, minh_bx);
582 evas_object_resize(wd->more, w, h);
583 evas_object_size_hint_min_set(obj, minw, minh);
584 evas_object_size_hint_max_set(obj, -1, -1);
588 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
590 item->o_menu = elm_menu_add(WIDGET(item));
591 item->menu = EINA_TRUE;
593 elm_menu_parent_set(item->o_menu, wd->menu_parent);
594 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
596 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
601 _item_menu_destroy(Elm_Toolbar_Item *item)
605 evas_object_del(item->o_menu);
608 item->menu = EINA_FALSE;
612 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
614 const Elm_Toolbar_Item *eti1 = i1;
615 const Elm_Toolbar_Item *eti2 = i2;
618 if (!eti1) return -1;
620 if (eti2->prio.priority == eti1->prio.priority)
623 return eti2->prio.priority - eti1->prio.priority;
627 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw, Eina_Bool *more)
629 Elm_Toolbar_Item *it, *prev;
630 Eina_List *sorted = NULL;
631 Evas_Coord ciw = 0, cih = 0;
632 int count = 0, i = 0;
635 EINA_INLIST_FOREACH(wd->items, it)
639 prev = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
640 it->prio.priority = prev->prio.priority;
644 EINA_INLIST_FOREACH(wd->items, it)
646 sorted = eina_list_sorted_insert(sorted,
647 _toolbar_item_prio_compare_cb, it);
652 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL, &ciw, &cih);
653 if (wd->vertical) *iw += cih;
657 EINA_LIST_FREE(sorted, it)
659 if (it->prio.priority > wd->standard_priority)
661 evas_object_geometry_get(VIEW(it), NULL, NULL, &ciw, &cih);
662 if (wd->vertical) *iw += cih;
664 it->prio.visible = (*iw <= vw);
666 if (!it->separator) count++;
670 it->prio.visible = EINA_FALSE;
671 if (!it->separator) i++;
672 if (i <= (count + 1))
673 it->in_box = wd->bx_more;
675 it->in_box = wd->bx_more2;
682 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
684 Elm_Toolbar_Item *it = data;
685 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
689 _resize_job(void *data)
691 Evas_Object *obj = (Evas_Object *)data;
692 Widget_Data *wd = elm_widget_data_get(obj);
693 Evas_Coord mw, mh, vw = 0, vh = 0, w = 0, h = 0;
694 Elm_Toolbar_Item *it;
699 wd->resize_job = NULL;
700 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
701 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
702 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
703 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
705 Evas_Coord iw = 0, ih = 0, more_w = 0, more_h = 0;
709 evas_object_resize(wd->bx, w, vh);
710 _fix_items_visibility(wd, &ih, vh, &more);
714 evas_object_resize(wd->bx, vw, h);
715 _fix_items_visibility(wd, &iw, vw, &more);
717 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL,
721 if ((ih - more_h) <= vh) ih -= more_h;
725 if ((iw - more_w) <= vw) iw -= more_w;
728 /* All items are removed from the box object, since removing individual
729 * items won't trigger a resize. Items are be readded below. */
730 evas_object_box_remove_all(wd->bx, EINA_FALSE);
731 if (((wd->vertical) && (ih > vh)) ||
732 ((!wd->vertical) && (iw > vw)) || more)
736 _item_menu_destroy(wd->more_item);
737 _item_menu_create(wd, wd->more_item);
738 menu = elm_toolbar_item_menu_get((Elm_Object_Item *)wd->more_item);
739 EINA_INLIST_FOREACH(wd->items, it)
741 if (!it->prio.visible)
744 elm_menu_item_separator_add(menu, NULL);
747 Elm_Object_Item *menu_it;
748 menu_it = elm_menu_item_add
749 (menu, NULL, it->icon_str, it->label,
750 _elm_toolbar_item_menu_cb, it);
751 elm_object_item_disabled_set
752 (menu_it, elm_widget_item_disabled_get(it));
754 elm_menu_clone(it->o_menu, menu, menu_it);
756 evas_object_hide(VIEW(it));
760 evas_object_box_append(wd->bx, VIEW(it));
761 evas_object_show(VIEW(it));
764 evas_object_box_append(wd->bx, wd->VIEW(more_item));
765 evas_object_show(wd->VIEW(more_item));
769 /* All items are visible, show them all (except for the "More"
770 * button, of course). */
771 EINA_INLIST_FOREACH(wd->items, it)
773 evas_object_show(VIEW(it));
774 evas_object_box_append(wd->bx, VIEW(it));
776 evas_object_hide(wd->VIEW(more_item));
779 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
781 Evas_Coord iw = 0, ih = 0;
785 evas_object_resize(wd->bx, w, vh);
786 _fix_items_visibility(wd, &ih, vh, &more);
790 evas_object_resize(wd->bx, vw, h);
791 _fix_items_visibility(wd, &iw, vw, &more);
793 evas_object_box_remove_all(wd->bx, EINA_FALSE);
794 if (((wd->vertical) && (ih > vh)) ||
795 ((!wd->vertical) && (iw > vw)) || more)
797 EINA_INLIST_FOREACH(wd->items, it)
799 if (!it->prio.visible)
800 evas_object_hide(VIEW(it));
803 evas_object_box_append(wd->bx, VIEW(it));
804 evas_object_show(VIEW(it));
810 /* All items are visible, show them all */
811 EINA_INLIST_FOREACH(wd->items, it)
813 evas_object_show(VIEW(it));
814 evas_object_box_append(wd->bx, VIEW(it));
818 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
820 Evas_Coord iw = 0, ih = 0;
821 if ((vw >= mw) && (vh >= mh))
822 evas_object_resize(wd->bx, vw, vh);
824 evas_object_resize(wd->bx, mw, vh);
826 evas_object_resize(wd->bx, vw, mh);
829 _fix_items_visibility(wd, &ih, vh, &more);
831 _fix_items_visibility(wd, &iw, vw, &more);
833 evas_object_box_remove_all(wd->bx, EINA_FALSE);
834 evas_object_box_remove_all(wd->bx_more, EINA_FALSE);
835 evas_object_box_remove_all(wd->bx_more2, EINA_FALSE);
836 EINA_INLIST_FOREACH(wd->items, it)
840 evas_object_box_append(it->in_box, VIEW(it));
841 evas_object_show(VIEW(it));
846 evas_object_box_append(wd->bx, wd->VIEW(more_item));
847 evas_object_show(wd->VIEW(more_item));
850 evas_object_hide(wd->VIEW(more_item));
856 if ((vh >= mh) && (h != vh)) evas_object_resize(wd->bx, w, vh);
860 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
862 EINA_INLIST_FOREACH(wd->items, it)
872 // Remove the first or last separator since it is not neccessary
873 list = evas_object_box_children_get(wd->bx_more);
874 EINA_INLIST_FOREACH(wd->items, it)
876 if (it->separator && ((VIEW(it) == eina_list_data_get(list)) ||
877 (VIEW(it) == eina_list_nth(list, eina_list_count(list)-1))))
879 evas_object_box_remove(wd->bx_more, VIEW(it));
880 evas_object_move(VIEW(it), -9999, -9999);
881 evas_object_hide(VIEW(it));
884 list = evas_object_box_children_get(wd->bx_more2);
885 EINA_INLIST_FOREACH(wd->items, it)
887 if (it->separator && ((VIEW(it) == eina_list_data_get(list)) ||
888 (VIEW(it) == eina_list_nth(list, eina_list_count(list)-1))))
890 evas_object_box_remove(wd->bx_more2, VIEW(it));
891 evas_object_move(VIEW(it), -9999, -9999);
892 evas_object_hide(VIEW(it));
896 _mirrored_set(obj, elm_widget_mirrored_get(obj));
900 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
903 _resize(data, NULL, NULL, NULL);
907 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
909 Widget_Data *wd = elm_widget_data_get(data);
911 evas_object_geometry_get(data, &x, &y, NULL, &h);
912 evas_object_move(wd->more, x, y + h);
914 wd->resize_job = ecore_job_add(_resize_job, data);
918 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
920 Widget_Data *wd = elm_widget_data_get(data);
922 evas_object_geometry_get(data, &x, &y, NULL, &h);
923 evas_object_move(wd->more, x, y + h);
927 _select_filter(Elm_Toolbar_Item *it, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
930 char buf[sizeof("elm,action,click,") + 1];
932 button = atoi(emission + sizeof("mouse,clicked,") - 1);
933 if (button == 1) return; /* regular left click event */
934 snprintf(buf, sizeof(buf), "elm,action,click,%d", button);
935 edje_object_signal_emit(VIEW(it), buf, "elm");
939 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
941 Elm_Toolbar_Item *it = data;
943 if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
944 (_elm_access_2nd_click_timeout(VIEW(it))))
946 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
947 _elm_access_say(E_("Selected"));
953 _change_items(Evas_Object *obj)
955 Widget_Data *wd = elm_widget_data_get(obj);
957 Elm_Toolbar_Item *prev = NULL, *next = NULL;
960 if ((wd->reorder_from) && (wd->reorder_to) &&
961 (!wd->reorder_from->separator) && (!wd->reorder_to->separator))
963 prev = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(wd->reorder_from)->prev);
965 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(wd->reorder_from)->next);
967 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(wd->reorder_from));
968 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(wd->reorder_from),
969 EINA_INLIST_GET(wd->reorder_to));
971 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(wd->reorder_to));
973 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(wd->reorder_to),
974 EINA_INLIST_GET(prev));
976 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(wd->reorder_to),
977 EINA_INLIST_GET(next));
978 tmp = wd->reorder_from->prio.priority;
979 wd->reorder_from->prio.priority = wd->reorder_to->prio.priority;
980 wd->reorder_to->prio.priority = tmp;
982 _resize(obj, NULL, NULL, NULL);
986 _reorder_mouse_move(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Move *ev)
988 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
991 evas_object_geometry_get(VIEW(it), NULL, NULL, &w, &h);
992 evas_object_move(VIEW(it), ev->cur.canvas.x - (w / 2), ev->cur.canvas.y - (h /2));
993 evas_object_show(VIEW(it));
997 _reorder_mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
999 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1001 Evas_Coord x, y, w, h;
1003 evas_object_event_callback_del_full(wd->scr, EVAS_CALLBACK_MOUSE_MOVE,
1004 (Evas_Object_Event_Cb)_reorder_mouse_move, it);
1005 evas_object_event_callback_del_full(wd->more, EVAS_CALLBACK_MOUSE_MOVE,
1006 (Evas_Object_Event_Cb)_reorder_mouse_move, it);
1007 evas_object_event_callback_del_full(VIEW(it), EVAS_CALLBACK_MOUSE_MOVE,
1008 (Evas_Object_Event_Cb)_reorder_mouse_move, it);
1009 evas_object_event_callback_del_full(wd->scr, EVAS_CALLBACK_MOUSE_UP,
1010 (Evas_Object_Event_Cb)_reorder_mouse_up, it);
1011 evas_object_event_callback_del_full(wd->more, EVAS_CALLBACK_MOUSE_UP,
1012 (Evas_Object_Event_Cb)_reorder_mouse_up, it);
1014 elm_widget_item_free(it);
1016 EINA_INLIST_FOREACH(wd->items, it)
1018 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
1019 if ((x < ev->canvas.x) && (ev->canvas.x < x + w) &&
1020 (y < ev->canvas.y) && (ev->canvas.y < y + h))
1022 wd->reorder_to = it;
1023 _change_items(WIDGET(it));
1029 _item_reorder_start(Elm_Toolbar_Item *item)
1031 Evas_Object *obj = WIDGET(item);
1032 Widget_Data *wd = elm_widget_data_get(obj);
1033 Evas_Object *icon_obj;
1034 Evas_Coord x, y, w, h;
1035 Elm_Toolbar_Item *it;
1037 wd->reorder_from = item;
1039 icon_obj = elm_icon_add(obj);
1040 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1041 if (!icon_obj) return;
1042 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
1045 evas_object_del(icon_obj);
1049 it->label = eina_stringshare_add(item->label);
1050 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
1052 if (_item_icon_set(icon_obj, "toolbar/", item->icon_str))
1054 it->icon = icon_obj;
1055 it->icon_str = eina_stringshare_add(item->icon_str);
1060 it->icon_str = NULL;
1061 evas_object_del(icon_obj);
1064 _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
1065 elm_widget_style_get(obj));
1070 ms = ((double)wd->icon_size * _elm_config->scale);
1071 evas_object_size_hint_min_set(it->icon, ms, ms);
1072 evas_object_size_hint_max_set(it->icon, ms, ms);
1073 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
1074 evas_object_show(it->icon);
1075 elm_widget_sub_object_add(obj, it->icon);
1077 edje_object_part_text_escaped_set(VIEW(it), "elm.text", it->label);
1079 edje_object_signal_emit(VIEW(it), "elm,state,moving", "elm");
1081 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_MOUSE_MOVE,
1082 (Evas_Object_Event_Cb)_reorder_mouse_move, it);
1084 evas_object_event_callback_add(wd->more, EVAS_CALLBACK_MOUSE_MOVE,
1085 (Evas_Object_Event_Cb)_reorder_mouse_move, it);
1087 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_MOVE,
1088 (Evas_Object_Event_Cb)_reorder_mouse_move, it);
1090 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_MOUSE_UP,
1091 (Evas_Object_Event_Cb)_reorder_mouse_up, it);
1093 evas_object_event_callback_add(wd->more, EVAS_CALLBACK_MOUSE_UP,
1094 (Evas_Object_Event_Cb)_reorder_mouse_up, it);
1096 evas_object_geometry_get(VIEW(item), &x, &y, &w, &h);
1097 evas_object_resize(VIEW(it), w, h);
1098 evas_object_move(VIEW(it), x, y);
1099 evas_object_show(VIEW(it));
1103 _long_press(Elm_Toolbar_Item *it)
1105 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1106 wd->long_timer = NULL;
1107 wd->long_press = EINA_TRUE;
1109 if ((wd->more_item != it) &&
1110 (wd->more_item == (Elm_Toolbar_Item *)elm_toolbar_selected_item_get(WIDGET(it))))
1111 _item_reorder_start(it);
1113 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
1114 return ECORE_CALLBACK_CANCEL;
1118 _mouse_move(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Move *ev)
1120 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1122 Evas_Coord x, y, w, h;
1123 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
1125 if ((wd->long_timer) &&
1126 ((x > ev->cur.canvas.x) || (ev->cur.canvas.x > x + w) ||
1127 (y > ev->cur.canvas.y) || (ev->cur.canvas.y > y + h)))
1129 ecore_timer_del(wd->long_timer);
1130 wd->long_timer = NULL;
1135 _mouse_down(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Down *ev)
1137 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1139 if (ev->button != 1) return;
1140 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1141 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
1142 wd->long_press = EINA_FALSE;
1143 if (wd->long_timer) ecore_timer_interval_set(wd->long_timer, _elm_config->longpress_timeout);
1144 else wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, (Ecore_Task_Cb)_long_press, it);
1145 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_MOVE,
1146 (Evas_Object_Event_Cb)_mouse_move, it);
1150 _mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
1152 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1154 if (ev->button != 1) return;
1157 ecore_timer_del(wd->long_timer);
1158 wd->long_timer = NULL;
1160 evas_object_event_callback_del_full(VIEW(it), EVAS_CALLBACK_MOUSE_MOVE,
1161 (Evas_Object_Event_Cb)_mouse_move, it);
1165 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1167 Elm_Toolbar_Item *it = data;
1168 edje_object_signal_emit(VIEW(it), "elm,state,highlighted", "elm");
1169 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
1173 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1175 Elm_Toolbar_Item *it = data;
1176 edje_object_signal_emit(VIEW(it), "elm,state,unhighlighted", "elm");
1177 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
1181 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
1183 Evas_Object *obj = (Evas_Object *) data;
1184 Widget_Data *wd = elm_widget_data_get(obj);
1186 _els_box_layout(o, priv, !wd->vertical, wd->homogeneous,
1187 elm_widget_mirrored_get(obj));
1191 _access_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item)
1193 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
1194 const char *txt = item->access_info;
1195 if (!txt) txt = it->label;
1196 if (txt) return strdup(txt);
1201 _access_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
1203 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
1205 return strdup(E_("Separator"));
1206 else if (elm_widget_item_disabled_get(it))
1207 return strdup(E_("State: Disabled"));
1208 else if (it->selected)
1209 return strdup(E_("State: Selected"));
1211 return strdup(E_("Has menu"));
1216 _item_del_pre_hook(Elm_Object_Item *it)
1220 Elm_Toolbar_Item *item, *next;
1221 item = (Elm_Toolbar_Item *)it;
1223 wd = elm_widget_data_get(WIDGET(item));
1224 if (!wd) return EINA_FALSE;
1226 obj2 = WIDGET(item);
1227 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
1228 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
1230 if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1231 if ((wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
1232 item->selected && next) _item_select(next);
1239 static Elm_Toolbar_Item *
1240 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1242 Widget_Data *wd = elm_widget_data_get(obj);
1243 Evas_Object *icon_obj;
1245 Elm_Toolbar_Item *it;
1247 icon_obj = elm_icon_add(obj);
1248 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1249 if (!icon_obj) return NULL;
1250 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
1253 evas_object_del(icon_obj);
1257 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
1258 elm_widget_item_disable_hook_set(it, _item_disable_hook);
1259 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
1260 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
1261 elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
1262 elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
1263 elm_widget_item_content_unset_hook_set(it, _item_content_unset_hook);
1265 it->label = eina_stringshare_add(label);
1266 it->prio.visible = 1;
1267 it->prio.priority = 0;
1269 it->separator = EINA_FALSE;
1271 it->base.data = data;
1272 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
1273 _elm_access_item_register(&it->base, VIEW(it));
1274 _elm_access_text_set(_elm_access_item_get(&it->base),
1275 ELM_ACCESS_TYPE, E_("Tool Item"));
1276 _elm_access_callback_set(_elm_access_item_get(&it->base),
1277 ELM_ACCESS_INFO, _access_info_cb, it);
1278 _elm_access_callback_set(_elm_access_item_get(&it->base),
1279 ELM_ACCESS_STATE, _access_state_cb, it);
1281 if (_item_icon_set(icon_obj, "toolbar/", icon))
1283 it->icon = icon_obj;
1284 it->icon_str = eina_stringshare_add(icon);
1289 it->icon_str = NULL;
1290 evas_object_del(icon_obj);
1293 _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
1294 elm_widget_style_get(obj));
1295 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "elm",
1297 edje_object_signal_callback_add(VIEW(it), "mouse,clicked,*", "*",
1298 (Edje_Signal_Cb)_select_filter, it);
1299 edje_object_signal_callback_add(VIEW(it), "elm,mouse,in", "elm",
1301 edje_object_signal_callback_add(VIEW(it), "elm,mouse,out", "elm",
1303 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
1304 (Evas_Object_Event_Cb)_mouse_down, it);
1305 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
1306 (Evas_Object_Event_Cb)_mouse_up, it);
1307 elm_widget_sub_object_add(obj, VIEW(it));
1312 ms = ((double)wd->icon_size * _elm_config->scale);
1313 evas_object_size_hint_min_set(it->icon, ms, ms);
1314 evas_object_size_hint_max_set(it->icon, ms, ms);
1315 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
1316 edje_object_signal_emit(VIEW(it), "elm,state,icon,visible", "elm");
1317 evas_object_show(it->icon);
1318 elm_widget_sub_object_add(obj, it->icon);
1322 edje_object_part_text_escaped_set(VIEW(it), "elm.text", it->label);
1323 edje_object_signal_emit(VIEW(it), "elm,state,text,visible", "elm");
1325 mw = mh = minw = minh = -1;
1326 if (!it->separator && !it->object)
1327 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1328 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
1329 if (!it->separator && !it->object)
1330 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1331 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1335 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, -1.0);
1336 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, 0.5);
1340 evas_object_size_hint_weight_set(VIEW(it), -1.0, EVAS_HINT_EXPAND);
1341 evas_object_size_hint_align_set(VIEW(it), 0.5, EVAS_HINT_FILL);
1346 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1347 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, EVAS_HINT_FILL);
1349 evas_object_size_hint_min_set(VIEW(it), mw, mh);
1350 evas_object_size_hint_max_set(VIEW(it), -1, -1);
1351 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
1353 if ((!wd->items) && (wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS))
1359 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
1361 Evas_Coord mw = -1, mh = -1, minw = -1, minh = -1;
1362 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1363 edje_object_part_text_escaped_set(VIEW(item), "elm.text", item->label);
1364 edje_object_signal_emit(VIEW(item), "elm,state,text,visible", "elm");
1366 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1367 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1368 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1369 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1373 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1374 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1378 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1379 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1384 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1385 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1387 evas_object_size_hint_min_get(VIEW(item), &minw, &minh);
1388 if ((minw < mw) && (minh < mh))
1389 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1390 else if ((minw < mw) && (minh > mh))
1391 evas_object_size_hint_min_set(VIEW(item), mw, minh);
1392 else if ((minw > mw) && (minh < mh))
1393 evas_object_size_hint_min_set(VIEW(item), minw, mh);
1397 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1399 Elm_Toolbar_Item *item = data;
1400 _elm_toolbar_item_label_update(item);
1401 edje_object_signal_callback_del(obj, emission, source,
1402 _elm_toolbar_item_label_set_cb);
1403 edje_object_signal_emit (VIEW(item), "elm,state,label,reset", "elm");
1407 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *sig)
1411 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
1413 eina_stringshare_replace(&item->label, label);
1414 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1415 if ((s) && (atoi(s)))
1417 edje_object_part_text_escaped_set(VIEW(item), "elm.text_new", item->label);
1418 edje_object_signal_emit (VIEW(item), sig, "elm");
1419 edje_object_signal_callback_add(VIEW(item),
1420 "elm,state,label_set,done", "elm",
1421 _elm_toolbar_item_label_set_cb, item);
1424 _elm_toolbar_item_label_update(item);
1425 _resize(WIDGET(item), NULL, NULL, NULL);
1429 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
1431 Elm_Toolbar_Item_State *it_state;
1433 Evas_Coord mw = -1, mh = -1, minw = -1, minh = -1;
1434 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1435 Evas_Object *old_icon = edje_object_part_swallow_get(VIEW(item),
1436 "elm.swallow.icon");
1437 elm_widget_sub_object_del(VIEW(item), old_icon);
1438 evas_object_hide(old_icon);
1439 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1440 edje_object_signal_emit(VIEW(item), "elm,state,icon,visible", "elm");
1441 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1442 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1443 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1444 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1448 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1449 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1453 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1454 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1459 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1460 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1462 evas_object_size_hint_min_get(VIEW(item), &minw, &minh);
1463 if ((minw < mw) && (minh < mh))
1464 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1465 else if ((minw < mw) && (minh > mh))
1466 evas_object_size_hint_min_set(VIEW(item), mw, minh);
1467 else if ((minw > mw) && (minh < mh))
1468 evas_object_size_hint_min_set(VIEW(item), minw, mh);
1470 EINA_LIST_FOREACH(item->states, l, it_state)
1472 if (it_state->icon == old_icon) return;
1474 evas_object_del(old_icon);
1478 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1480 Elm_Toolbar_Item *item = data;
1481 edje_object_part_unswallow(VIEW(item), item->icon);
1482 _elm_toolbar_item_icon_update(item);
1483 edje_object_signal_callback_del(obj, emission, source,
1484 _elm_toolbar_item_icon_set_cb);
1485 edje_object_signal_emit (VIEW(item), "elm,state,icon,reset", "elm");
1489 _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)
1491 Evas_Object *old_icon;
1496 eina_stringshare_replace(&item->icon_str, icon_str);
1499 eina_stringshare_del(item->icon_str);
1500 item->icon_str = NULL;
1502 item->icon = icon_obj;
1505 ms = (icon_size * _elm_config->scale);
1506 evas_object_size_hint_min_set(item->icon, ms, ms);
1507 evas_object_size_hint_max_set(item->icon, ms, ms);
1508 evas_object_show(item->icon);
1509 elm_widget_sub_object_add(obj, item->icon);
1511 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1512 if ((s) && (atoi(s)))
1514 old_icon = edje_object_part_swallow_get(VIEW(item),
1515 "elm.swallow.icon_new");
1518 elm_widget_sub_object_del(VIEW(item), old_icon);
1519 evas_object_hide(old_icon);
1521 edje_object_part_swallow(VIEW(item), "elm.swallow.icon_new",
1523 edje_object_signal_emit (VIEW(item), sig, "elm");
1524 edje_object_signal_callback_add(VIEW(item),
1525 "elm,state,icon_set,done", "elm",
1526 _elm_toolbar_item_icon_set_cb, item);
1529 _elm_toolbar_item_icon_update(item);
1530 _resize(obj, NULL, NULL, NULL);
1534 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1536 Elm_Toolbar_Item *it = event_info;
1537 Elm_Toolbar_Item_State *it_state;
1539 it_state = eina_list_data_get(it->current_state);
1541 it_state->func((void *)it_state->data, obj, event_info);
1544 static Elm_Toolbar_Item_State *
1545 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1547 Elm_Toolbar_Item_State *it_state;
1548 it_state = ELM_NEW(Elm_Toolbar_Item_State);
1549 it_state->label = eina_stringshare_add(label);
1550 it_state->icon_str = eina_stringshare_add(icon_str);
1551 it_state->icon = icon;
1552 it_state->func = func;
1553 it_state->data = data;
1558 elm_toolbar_add(Evas_Object *parent)
1564 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1566 ELM_SET_WIDTYPE(widtype, "toolbar");
1567 elm_widget_type_set(obj, "toolbar");
1568 elm_widget_sub_object_add(parent, obj);
1569 elm_widget_data_set(obj, wd);
1570 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1571 elm_widget_del_hook_set(obj, _del_hook);
1572 elm_widget_theme_hook_set(obj, _theme_hook);
1573 elm_widget_translate_hook_set(obj, _translate_hook);
1574 elm_widget_can_focus_set(obj, EINA_TRUE);
1576 wd->more_item = NULL;
1577 wd->selected_item = NULL;
1578 wd->standard_priority = -99999;
1579 wd->scr = elm_smart_scroller_add(e);
1580 elm_smart_scroller_widget_set(wd->scr, obj);
1581 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
1582 elm_smart_scroller_bounce_allow_set(wd->scr,
1583 _elm_config->thumbscroll_bounce_enable,
1585 elm_widget_resize_object_set(obj, wd->scr);
1586 elm_smart_scroller_policy_set(wd->scr,
1587 ELM_SMART_SCROLLER_POLICY_AUTO,
1588 ELM_SMART_SCROLLER_POLICY_OFF);
1590 wd->icon_size = _elm_toolbar_icon_size_get(wd);
1593 wd->homogeneous = EINA_TRUE;
1596 wd->bx = evas_object_box_add(e);
1597 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
1598 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
1599 elm_widget_sub_object_add(obj, wd->bx);
1600 elm_smart_scroller_child_set(wd->scr, wd->bx);
1601 evas_object_show(wd->bx);
1603 wd->more = elm_layout_add(obj);
1604 elm_layout_theme_set(wd->more, "toolbar", "more", "default");
1605 elm_widget_sub_object_add(obj, wd->more);
1606 evas_object_show(wd->more);
1608 wd->bx_more = evas_object_box_add(e);
1609 evas_object_size_hint_align_set(wd->bx_more, wd->align, 0.5);
1610 evas_object_box_layout_set(wd->bx_more, _layout, obj, NULL);
1611 elm_widget_sub_object_add(obj, wd->bx_more);
1612 elm_object_part_content_set(wd->more, "elm.swallow.content", wd->bx_more);
1613 evas_object_show(wd->bx_more);
1615 wd->bx_more2 = evas_object_box_add(e);
1616 evas_object_size_hint_align_set(wd->bx_more2, wd->align, 0.5);
1617 evas_object_box_layout_set(wd->bx_more2, _layout, obj, NULL);
1618 elm_widget_sub_object_add(obj, wd->bx_more2);
1619 elm_object_part_content_set(wd->more, "elm.swallow.content2", wd->bx_more2);
1620 evas_object_show(wd->bx_more2);
1622 elm_toolbar_shrink_mode_set(obj, _elm_config->toolbar_shrink_mode);
1623 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
1624 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_MOVE, _move, obj);
1625 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
1626 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
1628 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1635 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
1637 ELM_CHECK_WIDTYPE(obj, widtype);
1638 Widget_Data *wd = elm_widget_data_get(obj);
1640 if (wd->icon_size == icon_size) return;
1641 wd->icon_size = icon_size;
1646 elm_toolbar_icon_size_get(const Evas_Object *obj)
1648 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1649 Widget_Data *wd = elm_widget_data_get(obj);
1651 return wd->icon_size;
1654 EAPI Elm_Object_Item *
1655 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1657 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1658 Widget_Data *wd = elm_widget_data_get(obj);
1659 if (!wd) return NULL;
1661 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1662 if (!it) return NULL;
1663 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1665 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
1666 evas_object_box_append(wd->bx, VIEW(it));
1667 evas_object_show(VIEW(it));
1669 _theme_hook_item(obj, it, scale, wd->icon_size);
1673 return (Elm_Object_Item *)it;
1676 EAPI Elm_Object_Item *
1677 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1679 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1680 Widget_Data *wd = elm_widget_data_get(obj);
1681 if (!wd) return NULL;
1683 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1684 if (!it) return NULL;
1685 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1687 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1688 evas_object_box_prepend(wd->bx, VIEW(it));
1689 evas_object_show(VIEW(it));
1690 _theme_hook_item(obj, it, scale, wd->icon_size);
1694 return (Elm_Object_Item *)it;
1697 EAPI Elm_Object_Item *
1698 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)
1700 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1701 ELM_OBJ_ITEM_CHECK_OR_RETURN(before, NULL);
1703 Elm_Toolbar_Item *it, *_before;
1705 wd = elm_widget_data_get(obj);
1706 if (!wd) return NULL;
1707 _before = (Elm_Toolbar_Item *) before;
1708 it = _item_new(obj, icon, label, func, data);
1709 if (!it) return NULL;
1710 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1712 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1713 EINA_INLIST_GET(_before));
1714 evas_object_box_insert_before(wd->bx, VIEW(it), VIEW(_before));
1715 evas_object_show(VIEW(it));
1716 _theme_hook_item(obj, it, scale, wd->icon_size);
1720 return (Elm_Object_Item *)it;
1723 EAPI Elm_Object_Item *
1724 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)
1726 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1727 ELM_OBJ_ITEM_CHECK_OR_RETURN(after, NULL);
1729 Elm_Toolbar_Item *it, *_after;
1731 wd = elm_widget_data_get(obj);
1732 if (!wd) return NULL;
1733 _after = (Elm_Toolbar_Item *) after;
1734 it = _item_new(obj, icon, label, func, data);
1735 if (!it) return NULL;
1736 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1738 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1739 EINA_INLIST_GET(_after));
1740 evas_object_box_insert_after(wd->bx, VIEW(it), VIEW(_after));
1741 evas_object_show(VIEW(it));
1742 _theme_hook_item(obj, it, scale, wd->icon_size);
1746 return (Elm_Object_Item *)it;
1749 EAPI Elm_Object_Item *
1750 elm_toolbar_first_item_get(const Evas_Object *obj)
1752 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1753 Widget_Data *wd = elm_widget_data_get(obj);
1754 if (!wd || !wd->items) return NULL;
1755 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1758 EAPI Elm_Object_Item *
1759 elm_toolbar_last_item_get(const Evas_Object *obj)
1761 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1762 Widget_Data *wd = elm_widget_data_get(obj);
1763 if (!wd || !wd->items) return NULL;
1764 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1767 EAPI Elm_Object_Item *
1768 elm_toolbar_item_next_get(const Elm_Object_Item *it)
1770 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1771 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1772 EINA_INLIST_GET(((Elm_Toolbar_Item *)it))->next);
1775 EAPI Elm_Object_Item *
1776 elm_toolbar_item_prev_get(const Elm_Object_Item *it)
1778 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1779 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1780 EINA_INLIST_GET(((Elm_Toolbar_Item *)it))->prev);
1784 elm_toolbar_item_priority_set(Elm_Object_Item *it, int priority)
1786 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1787 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1788 if (item->prio.priority == priority) return;
1789 item->prio.priority = priority;
1790 _resize(WIDGET(item), NULL, NULL, NULL);
1794 elm_toolbar_item_priority_get(const Elm_Object_Item *it)
1796 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
1797 return ((Elm_Toolbar_Item *)it)->prio.priority;
1800 EAPI Elm_Object_Item *
1801 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
1803 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1804 Elm_Toolbar_Item *it;
1805 Widget_Data *wd = elm_widget_data_get(obj);
1806 if (!wd) return NULL;
1808 EINA_INLIST_FOREACH(wd->items, it)
1810 if (!strcmp(it->label, label))
1811 return (Elm_Object_Item *)it;
1817 elm_toolbar_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1819 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1820 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1821 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1824 if (item->selected == selected) return;
1825 if (selected) _item_select(item);
1826 else _item_unselect(item);
1830 elm_toolbar_item_selected_get(const Elm_Object_Item *it)
1832 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1833 return ((Elm_Toolbar_Item *)it)->selected;
1836 EAPI Elm_Object_Item *
1837 elm_toolbar_selected_item_get(const Evas_Object *obj)
1839 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1840 Widget_Data *wd = elm_widget_data_get(obj);
1841 if (!wd) return NULL;
1842 return (Elm_Object_Item *) wd->selected_item;
1845 EAPI Elm_Object_Item *
1846 elm_toolbar_more_item_get(const Evas_Object *obj)
1848 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1849 Widget_Data *wd = elm_widget_data_get(obj);
1850 if (!wd) return NULL;
1851 return (Elm_Object_Item *) wd->more_item;
1855 elm_toolbar_item_icon_set(Elm_Object_Item *it, const char *icon)
1857 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1859 Evas_Object *icon_obj;
1862 Elm_Toolbar_Item * item = (Elm_Toolbar_Item *)it;
1865 wd = elm_widget_data_get(obj);
1867 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1869 icon_obj = elm_icon_add(obj);
1870 if (!icon_obj) return;
1871 if (_item_icon_set(icon_obj, "toolbar/", icon))
1872 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1873 "elm,state,icon_set");
1876 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1877 "elm,state,icon_set");
1878 evas_object_del(icon_obj);
1883 elm_toolbar_item_icon_get(const Elm_Object_Item *it)
1885 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1886 return ((Elm_Toolbar_Item *)it)->icon_str;
1890 elm_toolbar_item_object_get(const Elm_Object_Item *it)
1892 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1896 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1899 wd = elm_widget_data_get(obj);
1900 if (!wd) return NULL;
1906 elm_toolbar_item_icon_object_get(Elm_Object_Item *it)
1908 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1909 return ((Elm_Toolbar_Item *)it)->icon;
1913 elm_toolbar_item_icon_memfile_set(Elm_Object_Item *it, const void *img, size_t size, const char *format, const char *key)
1915 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1917 Evas_Object *icon_obj;
1921 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1924 wd = elm_widget_data_get(obj);
1925 if (!wd) return EINA_FALSE;
1929 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1930 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1931 ret = _els_smart_icon_memfile_set(icon_obj, img, size, format, key);
1934 evas_object_del(icon_obj);
1937 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1938 "elm,state,icon_set");
1941 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1946 elm_toolbar_item_icon_file_set(Elm_Object_Item *it, const char *file, const char *key)
1948 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1950 Evas_Object *icon_obj;
1954 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1957 wd = elm_widget_data_get(obj);
1958 if (!wd) return EINA_FALSE;
1962 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1963 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1964 ret = _els_smart_icon_file_key_set(icon_obj, file, key);
1967 evas_object_del(icon_obj);
1970 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1971 "elm,state,icon_set");
1974 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1979 elm_toolbar_item_separator_set(Elm_Object_Item *it, Eina_Bool separator)
1981 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1982 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1983 Evas_Object *obj = WIDGET(item);
1984 Widget_Data *wd = elm_widget_data_get(obj);
1986 if (item->separator == separator) return;
1987 item->separator = separator;
1988 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1989 _theme_hook_item(obj, item, scale, wd->icon_size);
1990 evas_object_size_hint_min_set(VIEW(item), -1, -1);
1994 elm_toolbar_item_separator_get(const Elm_Object_Item *it)
1996 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1997 return ((Elm_Toolbar_Item *)it)->separator;
2001 elm_toolbar_shrink_mode_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
2003 ELM_CHECK_WIDTYPE(obj, widtype);
2004 Widget_Data *wd = elm_widget_data_get(obj);
2008 wd->shrink_mode = shrink_mode;
2009 bounce = (_elm_config->thumbscroll_bounce_enable) &&
2010 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
2011 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
2015 _item_del(wd->more_item);
2016 elm_widget_item_free(wd->more_item);
2017 wd->more_item = NULL;
2020 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
2022 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
2023 ELM_SMART_SCROLLER_POLICY_OFF);
2024 wd->more_item = _item_new(obj, "more_menu", "More", NULL, NULL);
2026 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
2027 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
2028 ELM_SMART_SCROLLER_POLICY_OFF);
2029 else if (shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
2031 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
2032 ELM_SMART_SCROLLER_POLICY_OFF);
2033 wd->more_item = _item_new(obj, "more_menu", "More", NULL, NULL);
2036 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
2037 ELM_SMART_SCROLLER_POLICY_OFF);
2041 EAPI Elm_Toolbar_Shrink_Mode
2042 elm_toolbar_shrink_mode_get(const Evas_Object *obj)
2044 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
2045 Widget_Data *wd = elm_widget_data_get(obj);
2047 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
2048 return wd->shrink_mode;
2052 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
2054 ELM_CHECK_WIDTYPE(obj, widtype);
2055 Widget_Data *wd = elm_widget_data_get(obj);
2058 wd->homogeneous = !!homogeneous;
2059 evas_object_smart_calculate(wd->bx);
2063 elm_toolbar_homogeneous_get(const Evas_Object *obj)
2065 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2066 Widget_Data *wd = elm_widget_data_get(obj);
2068 if (!wd) return EINA_FALSE;
2069 return wd->homogeneous;
2073 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
2075 Elm_Toolbar_Item *it;
2076 ELM_CHECK_WIDTYPE(obj, widtype);
2077 Widget_Data *wd = elm_widget_data_get(obj);
2080 EINA_SAFETY_ON_NULL_RETURN(parent);
2081 wd->menu_parent = parent;
2082 EINA_INLIST_FOREACH(wd->items, it)
2085 elm_menu_parent_set(it->o_menu, wd->menu_parent);
2087 if ((wd->more_item) && (wd->more_item->o_menu))
2088 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
2092 elm_toolbar_menu_parent_get(const Evas_Object *obj)
2094 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2095 Widget_Data *wd = elm_widget_data_get(obj);
2097 if (!wd) return NULL;
2098 return wd->menu_parent;
2102 elm_toolbar_align_set(Evas_Object *obj, double align)
2104 ELM_CHECK_WIDTYPE(obj, widtype);
2105 Widget_Data *wd = elm_widget_data_get(obj);
2110 if (wd->align != align)
2111 evas_object_size_hint_align_set(wd->bx, 0.5, align);
2115 if (wd->align != align)
2116 evas_object_size_hint_align_set(wd->bx, align, 0.5);
2122 elm_toolbar_align_get(const Evas_Object *obj)
2124 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
2125 Widget_Data *wd = elm_widget_data_get(obj);
2127 if (!wd) return 0.0;
2132 elm_toolbar_item_menu_set(Elm_Object_Item *it, Eina_Bool menu)
2134 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2135 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2136 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
2139 if (item->menu == menu) return;
2140 if (menu) _item_menu_create(wd, item);
2141 else _item_menu_destroy(item);
2145 elm_toolbar_item_menu_get(const Elm_Object_Item *it)
2147 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2148 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2149 if (!item->menu) return NULL;
2150 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
2151 if (!wd) return NULL;
2152 return item->o_menu;
2155 EAPI Elm_Toolbar_Item_State *
2156 elm_toolbar_item_state_add(Elm_Object_Item *it, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
2158 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2160 Elm_Toolbar_Item_State *it_state;
2161 Evas_Object *icon_obj;
2164 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2166 wd = elm_widget_data_get(WIDGET(item));
2167 if (!wd) return NULL;
2171 it_state = _item_state_new(item->label, item->icon_str, item->icon,
2172 item->func, item->base.data);
2173 item->states = eina_list_append(item->states, it_state);
2174 item->current_state = item->states;
2177 icon_obj = elm_icon_add(obj);
2178 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
2179 if (!icon_obj) goto error_state_add;
2181 if (!_item_icon_set(icon_obj, "toolbar/", icon))
2183 evas_object_del(icon_obj);
2188 it_state = _item_state_new(label, icon, icon_obj, func, data);
2189 item->states = eina_list_append(item->states, it_state);
2190 item->func = _elm_toolbar_item_state_cb;
2191 item->base.data = NULL;
2196 if (item->states && !eina_list_next(item->states))
2198 eina_stringshare_del(item->label);
2199 eina_stringshare_del(item->icon_str);
2200 free(eina_list_data_get(item->states));
2201 eina_list_free(item->states);
2202 item->states = NULL;
2208 elm_toolbar_item_state_del(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
2210 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2212 Eina_List *del_state;
2213 Elm_Toolbar_Item_State *it_state;
2214 Elm_Toolbar_Item *item;
2216 if (!state) return EINA_FALSE;
2218 item = (Elm_Toolbar_Item *)it;
2219 if (!item->states) return EINA_FALSE;
2221 del_state = eina_list_data_find_list(item->states, state);
2222 if (del_state == item->states) return EINA_FALSE;
2223 if (del_state == item->current_state)
2224 elm_toolbar_item_state_unset(it);
2226 eina_stringshare_del(state->label);
2227 eina_stringshare_del(state->icon_str);
2228 if (state->icon) evas_object_del(state->icon);
2230 item->states = eina_list_remove_list(item->states, del_state);
2231 if (item->states && !eina_list_next(item->states))
2233 it_state = eina_list_data_get(item->states);
2234 item->base.data = it_state->data;
2235 item->func = it_state->func;
2236 eina_stringshare_del(it_state->label);
2237 eina_stringshare_del(it_state->icon_str);
2238 free(eina_list_data_get(item->states));
2239 eina_list_free(item->states);
2240 item->states = NULL;
2246 elm_toolbar_item_state_set(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
2248 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2251 Eina_List *next_state;
2252 Elm_Toolbar_Item_State *it_state;
2254 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2257 wd = elm_widget_data_get(obj);
2258 if (!wd) return EINA_FALSE;
2259 if (!item->states) return EINA_FALSE;
2263 next_state = eina_list_data_find_list(item->states, state);
2264 if (!next_state) return EINA_FALSE;
2267 next_state = item->states;
2269 if (next_state == item->current_state) return EINA_TRUE;
2271 it_state = eina_list_data_get(next_state);
2272 if (eina_list_data_find(item->current_state, state))
2274 _item_label_set(item, it_state->label, "elm,state,label_set,forward");
2275 _elm_toolbar_item_icon_obj_set(obj, item, it_state->icon, it_state->icon_str,
2276 wd->icon_size, "elm,state,icon_set,forward");
2280 _item_label_set(item, it_state->label, "elm,state,label_set,backward");
2281 _elm_toolbar_item_icon_obj_set(obj,
2286 "elm,state,icon_set,backward");
2288 if (elm_widget_item_disabled_get(item))
2289 elm_widget_signal_emit(item->icon, "elm,state,disabled", "elm");
2291 elm_widget_signal_emit(item->icon, "elm,state,enabled", "elm");
2293 item->current_state = next_state;
2298 elm_toolbar_item_state_unset(Elm_Object_Item *it)
2300 elm_toolbar_item_state_set(it, NULL);
2303 EAPI Elm_Toolbar_Item_State *
2304 elm_toolbar_item_state_get(const Elm_Object_Item *it)
2306 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2307 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2309 if ((!item->states) || (!item->current_state)) return NULL;
2310 if (item->current_state == item->states) return NULL;
2312 return eina_list_data_get(item->current_state);
2315 EAPI Elm_Toolbar_Item_State *
2316 elm_toolbar_item_state_next(Elm_Object_Item *it)
2318 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2322 Eina_List *next_state;
2323 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2326 wd = elm_widget_data_get(obj);
2327 if (!wd) return NULL;
2328 if (!item->states) return NULL;
2330 next_state = eina_list_next(item->current_state);
2332 next_state = eina_list_next(item->states);
2333 return eina_list_data_get(next_state);
2336 EAPI Elm_Toolbar_Item_State *
2337 elm_toolbar_item_state_prev(Elm_Object_Item *it)
2339 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2343 Eina_List *prev_state;
2344 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2347 wd = elm_widget_data_get(obj);
2348 if (!wd) return NULL;
2349 if (!item->states) return NULL;
2351 prev_state = eina_list_prev(item->current_state);
2352 if ((!prev_state) || (prev_state == item->states))
2353 prev_state = eina_list_last(item->states);
2354 return eina_list_data_get(prev_state);
2358 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
2360 ELM_CHECK_WIDTYPE(obj, widtype);
2361 Elm_Toolbar_Item *it;
2362 Widget_Data *wd = elm_widget_data_get(obj);
2365 wd->lookup_order = order;
2366 EINA_INLIST_FOREACH(wd->items, it)
2367 elm_icon_order_lookup_set(it->icon, order);
2369 elm_icon_order_lookup_set(wd->more_item->icon, order);
2372 EAPI Elm_Icon_Lookup_Order
2373 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
2375 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
2376 Widget_Data *wd = elm_widget_data_get(obj);
2377 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
2378 return wd->lookup_order;
2382 elm_toolbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
2384 ELM_CHECK_WIDTYPE(obj, widtype);
2385 Widget_Data *wd = elm_widget_data_get(obj);
2387 wd->vertical = !horizontal;
2389 evas_object_size_hint_align_set(wd->bx, 0.5, wd->align);
2391 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
2396 elm_toolbar_horizontal_get(const Evas_Object *obj)
2398 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2399 Widget_Data *wd = elm_widget_data_get(obj);
2400 if (!wd) return EINA_FALSE;
2401 return !wd->vertical;
2405 elm_toolbar_items_count(const Evas_Object *obj)
2407 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2408 Widget_Data *wd = elm_widget_data_get(obj);
2410 return wd->item_count;
2414 elm_toolbar_standard_priority_set(Evas_Object *obj, int priority)
2416 ELM_CHECK_WIDTYPE(obj, widtype);
2417 Widget_Data *wd = elm_widget_data_get(obj);
2419 wd->standard_priority = priority;
2420 _resize(obj, NULL, NULL, NULL);
2424 elm_toolbar_standard_priority_get(const Evas_Object *obj)
2426 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2427 Widget_Data *wd = elm_widget_data_get(obj);
2429 return wd->standard_priority;
2433 elm_toolbar_select_mode_set(Evas_Object *obj, Elm_Object_Select_Mode mode)
2435 ELM_CHECK_WIDTYPE(obj, widtype);
2436 Widget_Data *wd = elm_widget_data_get(obj);
2438 if (mode >= ELM_OBJECT_SELECT_MODE_MAX)
2440 if ((mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2441 (wd->select_mode != ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2443 _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
2444 if (wd->select_mode != mode)
2445 wd->select_mode = mode;
2448 EAPI Elm_Object_Select_Mode
2449 elm_toolbar_select_mode_get(const Evas_Object *obj)
2451 ELM_CHECK_WIDTYPE(obj, widtype) ELM_OBJECT_SELECT_MODE_MAX;
2452 Widget_Data *wd = elm_widget_data_get(obj);
2453 if (!wd) return ELM_OBJECT_SELECT_MODE_MAX;
2454 return wd->select_mode;