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 if (it->label) edje_object_signal_emit(VIEW(it), "elm,state,text,hidden", "elm");
293 eina_stringshare_del(it->icon_str);
296 edje_object_signal_emit(VIEW(it), "elm,state,icon,hidden", "elm");
297 evas_object_del(it->icon);
299 if (it->object) evas_object_del(it->object);
300 //TODO: See if checking for wd->menu_parent is necessary before deleting menu
301 if (it->o_menu) evas_object_del(it->o_menu);
305 _del_pre_hook(Evas_Object *obj)
307 Widget_Data *wd = elm_widget_data_get(obj);
308 Elm_Toolbar_Item *it, *next;
311 it = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
314 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next);
316 elm_widget_item_free(it);
321 _item_del(wd->more_item);
322 elm_widget_item_free(wd->more_item);
326 ecore_timer_del(wd->long_timer);
327 wd->long_timer = NULL;
332 _del_hook(Evas_Object *obj)
334 Widget_Data *wd = elm_widget_data_get(obj);
342 _mirrored_set_item(Evas_Object *obj __UNUSED__, Elm_Toolbar_Item *it, Eina_Bool mirrored)
344 edje_object_mirrored_set(VIEW(it), mirrored);
345 if (it->o_menu) elm_widget_mirrored_set(it->o_menu, mirrored);
349 _theme_hook_item(Evas_Object *obj, Elm_Toolbar_Item *it, double scale, int icon_size)
351 Widget_Data *wd = elm_widget_data_get(obj);
352 Evas_Object *view = VIEW(it);
353 Evas_Coord mw, mh, minw, minh;
354 const char *style = elm_widget_style_get(obj);
356 _mirrored_set_item(obj, it, elm_widget_mirrored_get(obj));
357 edje_object_scale_set(view, scale);
358 if (!it->separator && !it->object)
360 _elm_theme_object_set(obj, view, "toolbar", "item", style);
363 edje_object_signal_emit(view, "elm,state,selected", "elm");
364 elm_widget_signal_emit(it->icon, "elm,state,selected", "elm");
366 if (elm_widget_item_disabled_get(it))
368 edje_object_signal_emit(view, "elm,state,disabled", "elm");
369 elm_widget_signal_emit(it->icon, "elm,state,disabled", "elm");
375 ms = ((double)icon_size * scale);
376 evas_object_size_hint_min_set(it->icon, ms, ms);
377 evas_object_size_hint_max_set(it->icon, ms, ms);
378 edje_object_part_swallow(view, "elm.swallow.icon", it->icon);
380 edje_object_part_text_escaped_set(view, "elm.text", it->label);
386 _elm_theme_object_set(obj, view, "toolbar", "separator", style);
389 evas_object_size_hint_weight_set(view, EVAS_HINT_EXPAND, -1.0);
390 evas_object_size_hint_align_set(view, EVAS_HINT_FILL, 0.5);
394 evas_object_size_hint_weight_set(view, -1.0, EVAS_HINT_EXPAND);
395 evas_object_size_hint_align_set(view, 0.5, EVAS_HINT_FILL);
400 _elm_theme_object_set(obj, view, "toolbar", "object", style);
401 edje_object_part_swallow(view, "elm.swallow.object", it->object);
405 mw = mh = minw = minh = -1;
406 if (!it->separator && !it->object)
407 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
408 edje_object_size_min_restricted_calc(view, &mw, &mh, mw, mh);
409 if (!it->separator && !it->object)
410 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
411 evas_object_size_hint_min_get(view, &minw, &minh);
412 if ((minw < mw) && (minh < mh))
413 evas_object_size_hint_min_set(view, mw, mh);
414 else if ((minw < mw) && (minh > mh))
415 evas_object_size_hint_min_set(view, mw, minh);
416 else if ((minw > mw) && (minh < mh))
417 evas_object_size_hint_min_set(view, minw, mh);
421 _mirrored_set(Evas_Object *obj, Eina_Bool mirrored)
423 Widget_Data *wd = elm_widget_data_get(obj);
424 Elm_Toolbar_Item *it;
426 EINA_INLIST_FOREACH(wd->items, it)
427 _mirrored_set_item(obj, it, mirrored);
429 _mirrored_set_item(obj, wd->more_item, mirrored);
433 _theme_hook(Evas_Object *obj)
435 Widget_Data *wd = elm_widget_data_get(obj);
436 Elm_Toolbar_Item *it;
440 _elm_widget_mirrored_reload(obj);
441 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", elm_widget_style_get(obj));
442 _mirrored_set(obj, elm_widget_mirrored_get(obj));
443 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
444 edje_object_scale_set(wd->scr, scale);
445 wd->icon_size = _elm_toolbar_icon_size_get(wd);
446 EINA_INLIST_FOREACH(wd->items, it)
447 _theme_hook_item(obj, it, scale, wd->icon_size);
449 _theme_hook_item(obj, wd->more_item, scale, wd->icon_size);
454 _item_text_set_hook(Elm_Object_Item *it,
458 if (part && strcmp(part, "default")) return;
459 _item_label_set(((Elm_Toolbar_Item *)it), label, "elm,state,label_set");
463 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
465 if (part && strcmp(part, "default")) return NULL;
466 return ((Elm_Toolbar_Item *)it)->label;
470 _item_content_set_hook(Elm_Object_Item *it,
472 Evas_Object *content)
476 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
477 if (part && strcmp(part, "object")) return;
478 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
479 Evas_Object *obj = WIDGET(item);
480 Widget_Data *wd = elm_widget_data_get(obj);
481 if (!wd || !obj) return;
482 if (item->object == content) return;
484 if (item->object) evas_object_del(item->object);
486 item->object = content;
488 elm_widget_sub_object_add(obj, item->object);
489 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
490 _theme_hook_item(obj, item, scale, wd->icon_size);
494 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
496 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
497 if (part && strcmp(part, "object")) return NULL;
498 return ((Elm_Toolbar_Item *) it)->object;
502 _item_content_unset_hook(Elm_Object_Item *it, const char *part)
507 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
508 if (part && strcmp(part, "object")) return NULL;
509 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *) it;
510 Evas_Object *obj = WIDGET(item);
511 Widget_Data *wd = elm_widget_data_get(obj);
513 edje_object_part_unswallow(VIEW(it), item->object);
514 elm_widget_sub_object_del(obj, item->object);
517 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
518 _theme_hook_item(obj, item, scale, wd->icon_size);
523 _translate_hook(Evas_Object *obj)
525 evas_object_smart_callback_call(obj, "language,changed", NULL);
529 _sizing_eval(Evas_Object *obj)
531 Widget_Data *wd = elm_widget_data_get(obj);
532 Evas_Coord minw = -1, minh = -1, minw_bx = -1, minh_bx = -1;
533 Evas_Coord vw = 0, vh = 0;
537 evas_object_smart_need_recalculate_set(wd->bx, EINA_TRUE);
538 evas_object_smart_calculate(wd->bx);
539 edje_object_size_min_calc(elm_smart_scroller_edje_object_get(wd->scr),
541 evas_object_geometry_get(obj, NULL, NULL, &w, &h);
542 if (w < minw) w = minw;
543 if (h < minh) h = minh;
544 evas_object_resize(wd->scr, w, h);
546 evas_object_size_hint_min_get(wd->bx, &minw_bx, &minh_bx);
547 // if (wd->vertical && (h > minh)) minh = h;
548 // if ((!wd->vertical) && (w > minw)) minw = w;
549 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
550 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_NONE)
554 minw = minw_bx + (w - vw);
555 minh = minh_bx + (h - vh);
559 minw = minw_bx + (w - vw);
560 minh = minh_bx + (h - vh);
563 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
565 minw = minw_bx + (w - vw);
566 minh = minh_bx + (h - vh);
567 if (minw_bx < vw) minw_bx = vw;
568 if (minh_bx < vh) minh_bx = vh;
574 minw = minw_bx + (w - vw);
580 minh = minh_bx + (h - vh);
582 // if (wd->vertical) minh = h - vh;
583 // else minw = w - vw;
584 // minh = minh + (h - vh);
586 evas_object_resize(wd->bx, minw_bx, minh_bx);
587 evas_object_resize(wd->more, w, h);
588 evas_object_size_hint_min_set(obj, minw, minh);
589 evas_object_size_hint_max_set(obj, -1, -1);
593 _item_menu_create(Widget_Data *wd, Elm_Toolbar_Item *item)
595 item->o_menu = elm_menu_add(WIDGET(item));
596 item->menu = EINA_TRUE;
598 elm_menu_parent_set(item->o_menu, wd->menu_parent);
599 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_HIDE,
601 evas_object_event_callback_add(item->o_menu, EVAS_CALLBACK_DEL,
606 _item_menu_destroy(Elm_Toolbar_Item *item)
610 evas_object_del(item->o_menu);
613 item->menu = EINA_FALSE;
617 _toolbar_item_prio_compare_cb(const void *i1, const void *i2)
619 const Elm_Toolbar_Item *eti1 = i1;
620 const Elm_Toolbar_Item *eti2 = i2;
623 if (!eti1) return -1;
625 if (eti2->prio.priority == eti1->prio.priority)
628 return eti2->prio.priority - eti1->prio.priority;
632 _fix_items_visibility(Widget_Data *wd, Evas_Coord *iw, Evas_Coord vw, Eina_Bool *more)
634 Elm_Toolbar_Item *it, *prev;
635 Eina_List *sorted = NULL;
636 Evas_Coord ciw = 0, cih = 0;
637 int count = 0, i = 0;
640 EINA_INLIST_FOREACH(wd->items, it)
644 prev = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev);
645 it->prio.priority = prev->prio.priority;
649 EINA_INLIST_FOREACH(wd->items, it)
651 sorted = eina_list_sorted_insert(sorted,
652 _toolbar_item_prio_compare_cb, it);
657 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL, &ciw, &cih);
658 if (wd->vertical) *iw += cih;
662 EINA_LIST_FREE(sorted, it)
664 if (it->prio.priority > wd->standard_priority)
666 evas_object_geometry_get(VIEW(it), NULL, NULL, &ciw, &cih);
667 if (wd->vertical) *iw += cih;
669 it->prio.visible = (*iw <= vw);
671 if (!it->separator) count++;
675 it->prio.visible = EINA_FALSE;
676 if (!it->separator) i++;
677 if (i <= (count + 1))
678 it->in_box = wd->bx_more;
680 it->in_box = wd->bx_more2;
687 _elm_toolbar_item_menu_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
689 Elm_Toolbar_Item *it = data;
690 if (it->func) it->func((void *)(it->base.data), WIDGET(it), it);
694 _resize_job(void *data)
696 Evas_Object *obj = (Evas_Object *)data;
697 Widget_Data *wd = elm_widget_data_get(obj);
698 Evas_Coord mw, mh, vw = 0, vh = 0, w = 0, h = 0;
699 Elm_Toolbar_Item *it;
704 wd->resize_job = NULL;
705 elm_smart_scroller_child_viewport_size_get(wd->scr, &vw, &vh);
706 evas_object_size_hint_min_get(wd->bx, &mw, &mh);
707 evas_object_geometry_get(wd->bx, NULL, NULL, &w, &h);
708 if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
710 Evas_Coord iw = 0, ih = 0, more_w = 0, more_h = 0;
714 evas_object_resize(wd->bx, w, vh);
715 _fix_items_visibility(wd, &ih, vh, &more);
719 evas_object_resize(wd->bx, vw, h);
720 _fix_items_visibility(wd, &iw, vw, &more);
722 evas_object_geometry_get(wd->VIEW(more_item), NULL, NULL,
726 if ((ih - more_h) <= vh) ih -= more_h;
730 if ((iw - more_w) <= vw) iw -= more_w;
733 /* All items are removed from the box object, since removing individual
734 * items won't trigger a resize. Items are be readded below. */
735 evas_object_box_remove_all(wd->bx, EINA_FALSE);
736 if (((wd->vertical) && (ih > vh)) ||
737 ((!wd->vertical) && (iw > vw)) || more)
741 _item_menu_destroy(wd->more_item);
742 _item_menu_create(wd, wd->more_item);
743 menu = elm_toolbar_item_menu_get((Elm_Object_Item *)wd->more_item);
744 EINA_INLIST_FOREACH(wd->items, it)
746 if (!it->prio.visible)
749 elm_menu_item_separator_add(menu, NULL);
752 Elm_Object_Item *menu_it;
753 menu_it = elm_menu_item_add
754 (menu, NULL, it->icon_str, it->label,
755 _elm_toolbar_item_menu_cb, it);
756 elm_object_item_disabled_set
757 (menu_it, elm_widget_item_disabled_get(it));
759 elm_menu_clone(it->o_menu, menu, menu_it);
761 evas_object_hide(VIEW(it));
765 evas_object_box_append(wd->bx, VIEW(it));
766 evas_object_show(VIEW(it));
769 evas_object_box_append(wd->bx, wd->VIEW(more_item));
770 evas_object_show(wd->VIEW(more_item));
774 /* All items are visible, show them all (except for the "More"
775 * button, of course). */
776 EINA_INLIST_FOREACH(wd->items, it)
778 evas_object_show(VIEW(it));
779 evas_object_box_append(wd->bx, VIEW(it));
781 evas_object_hide(wd->VIEW(more_item));
784 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
786 Evas_Coord iw = 0, ih = 0;
790 evas_object_resize(wd->bx, w, vh);
791 _fix_items_visibility(wd, &ih, vh, &more);
795 evas_object_resize(wd->bx, vw, h);
796 _fix_items_visibility(wd, &iw, vw, &more);
798 evas_object_box_remove_all(wd->bx, EINA_FALSE);
799 if (((wd->vertical) && (ih > vh)) ||
800 ((!wd->vertical) && (iw > vw)) || more)
802 EINA_INLIST_FOREACH(wd->items, it)
804 if (!it->prio.visible)
805 evas_object_hide(VIEW(it));
808 evas_object_box_append(wd->bx, VIEW(it));
809 evas_object_show(VIEW(it));
815 /* All items are visible, show them all */
816 EINA_INLIST_FOREACH(wd->items, it)
818 evas_object_show(VIEW(it));
819 evas_object_box_append(wd->bx, VIEW(it));
823 else if (wd->shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
825 Evas_Coord iw = 0, ih = 0;
826 if ((vw >= mw) && (vh >= mh))
827 evas_object_resize(wd->bx, vw, vh);
829 evas_object_resize(wd->bx, mw, vh);
831 evas_object_resize(wd->bx, vw, mh);
834 _fix_items_visibility(wd, &ih, vh, &more);
836 _fix_items_visibility(wd, &iw, vw, &more);
838 evas_object_box_remove_all(wd->bx, EINA_FALSE);
839 evas_object_box_remove_all(wd->bx_more, EINA_FALSE);
840 evas_object_box_remove_all(wd->bx_more2, EINA_FALSE);
841 EINA_INLIST_FOREACH(wd->items, it)
845 evas_object_box_append(it->in_box, VIEW(it));
846 evas_object_show(VIEW(it));
851 evas_object_box_append(wd->bx, wd->VIEW(more_item));
852 evas_object_show(wd->VIEW(more_item));
855 evas_object_hide(wd->VIEW(more_item));
861 if ((vh >= mh) && (h != vh)) evas_object_resize(wd->bx, w, vh);
865 if ((vw >= mw) && (w != vw)) evas_object_resize(wd->bx, vw, h);
867 EINA_INLIST_FOREACH(wd->items, it)
877 // Remove the first or last separator since it is not neccessary
878 list = evas_object_box_children_get(wd->bx_more);
879 EINA_INLIST_FOREACH(wd->items, it)
881 if (it->separator && ((VIEW(it) == eina_list_data_get(list)) ||
882 (VIEW(it) == eina_list_nth(list, eina_list_count(list)-1))))
884 evas_object_box_remove(wd->bx_more, VIEW(it));
885 evas_object_move(VIEW(it), -9999, -9999);
886 evas_object_hide(VIEW(it));
889 list = evas_object_box_children_get(wd->bx_more2);
890 EINA_INLIST_FOREACH(wd->items, it)
892 if (it->separator && ((VIEW(it) == eina_list_data_get(list)) ||
893 (VIEW(it) == eina_list_nth(list, eina_list_count(list)-1))))
895 evas_object_box_remove(wd->bx_more2, VIEW(it));
896 evas_object_move(VIEW(it), -9999, -9999);
897 evas_object_hide(VIEW(it));
901 _mirrored_set(obj, elm_widget_mirrored_get(obj));
905 _resize_item(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
908 _resize(data, NULL, NULL, NULL);
912 _resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
914 Widget_Data *wd = elm_widget_data_get(data);
916 evas_object_geometry_get(data, &x, &y, NULL, &h);
917 evas_object_move(wd->more, x, y + h);
919 wd->resize_job = ecore_job_add(_resize_job, data);
923 _move(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
925 Widget_Data *wd = elm_widget_data_get(data);
927 evas_object_geometry_get(data, &x, &y, NULL, &h);
928 evas_object_move(wd->more, x, y + h);
932 _select_filter(Elm_Toolbar_Item *it, Evas_Object *obj __UNUSED__, const char *emission, const char *source __UNUSED__)
935 char buf[sizeof("elm,action,click,") + 1];
937 button = atoi(emission + sizeof("mouse,clicked,") - 1);
938 if (button == 1) return; /* regular left click event */
939 snprintf(buf, sizeof(buf), "elm,action,click,%d", button);
940 edje_object_signal_emit(VIEW(it), buf, "elm");
944 _select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
946 Elm_Toolbar_Item *it = data;
948 if ((_elm_config->access_mode == ELM_ACCESS_MODE_OFF) ||
949 (_elm_access_2nd_click_timeout(VIEW(it))))
951 if (_elm_config->access_mode != ELM_ACCESS_MODE_OFF)
952 _elm_access_say(E_("Selected"));
958 _change_items(Evas_Object *obj)
960 Widget_Data *wd = elm_widget_data_get(obj);
962 Elm_Toolbar_Item *prev = NULL, *next = NULL;
965 if ((wd->reorder_from) && (wd->reorder_to) &&
966 (!wd->reorder_from->separator) && (!wd->reorder_to->separator))
968 prev = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(wd->reorder_from)->prev);
970 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(wd->reorder_from)->next);
972 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(wd->reorder_from));
973 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(wd->reorder_from),
974 EINA_INLIST_GET(wd->reorder_to));
976 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(wd->reorder_to));
978 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(wd->reorder_to),
979 EINA_INLIST_GET(prev));
981 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(wd->reorder_to),
982 EINA_INLIST_GET(next));
983 tmp = wd->reorder_from->prio.priority;
984 wd->reorder_from->prio.priority = wd->reorder_to->prio.priority;
985 wd->reorder_to->prio.priority = tmp;
987 _resize(obj, NULL, NULL, NULL);
991 _reorder_mouse_move(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Move *ev)
993 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
996 evas_object_geometry_get(VIEW(it), NULL, NULL, &w, &h);
997 evas_object_move(VIEW(it), ev->cur.canvas.x - (w / 2), ev->cur.canvas.y - (h /2));
998 evas_object_show(VIEW(it));
1002 _reorder_mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
1004 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1006 Evas_Coord x, y, w, h;
1008 evas_object_event_callback_del_full(wd->scr, EVAS_CALLBACK_MOUSE_MOVE,
1009 (Evas_Object_Event_Cb)_reorder_mouse_move, it);
1010 evas_object_event_callback_del_full(wd->more, EVAS_CALLBACK_MOUSE_MOVE,
1011 (Evas_Object_Event_Cb)_reorder_mouse_move, it);
1012 evas_object_event_callback_del_full(VIEW(it), EVAS_CALLBACK_MOUSE_MOVE,
1013 (Evas_Object_Event_Cb)_reorder_mouse_move, it);
1014 evas_object_event_callback_del_full(wd->scr, EVAS_CALLBACK_MOUSE_UP,
1015 (Evas_Object_Event_Cb)_reorder_mouse_up, it);
1016 evas_object_event_callback_del_full(wd->more, EVAS_CALLBACK_MOUSE_UP,
1017 (Evas_Object_Event_Cb)_reorder_mouse_up, it);
1019 elm_widget_item_free(it);
1021 EINA_INLIST_FOREACH(wd->items, it)
1023 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
1024 if ((x < ev->canvas.x) && (ev->canvas.x < x + w) &&
1025 (y < ev->canvas.y) && (ev->canvas.y < y + h))
1027 wd->reorder_to = it;
1028 _change_items(WIDGET(it));
1034 _item_reorder_start(Elm_Toolbar_Item *item)
1036 Evas_Object *obj = WIDGET(item);
1037 Widget_Data *wd = elm_widget_data_get(obj);
1038 Evas_Object *icon_obj;
1039 Evas_Coord x, y, w, h;
1040 Elm_Toolbar_Item *it;
1042 wd->reorder_from = item;
1044 icon_obj = elm_icon_add(obj);
1045 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1046 if (!icon_obj) return;
1047 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
1050 evas_object_del(icon_obj);
1054 it->label = eina_stringshare_add(item->label);
1055 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
1057 if (_item_icon_set(icon_obj, "toolbar/", item->icon_str))
1059 it->icon = icon_obj;
1060 it->icon_str = eina_stringshare_add(item->icon_str);
1065 it->icon_str = NULL;
1066 evas_object_del(icon_obj);
1069 _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
1070 elm_widget_style_get(obj));
1075 ms = ((double)wd->icon_size * _elm_config->scale);
1076 evas_object_size_hint_min_set(it->icon, ms, ms);
1077 evas_object_size_hint_max_set(it->icon, ms, ms);
1078 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
1079 edje_object_signal_emit(VIEW(it), "elm,state,icon,visible", "elm"); //!!
1080 evas_object_show(it->icon);
1081 elm_widget_sub_object_add(obj, it->icon);
1083 edje_object_part_text_escaped_set(VIEW(it), "elm.text", it->label);
1085 edje_object_signal_emit(VIEW(it), "elm,state,moving", "elm");
1087 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_MOUSE_MOVE,
1088 (Evas_Object_Event_Cb)_reorder_mouse_move, it);
1090 evas_object_event_callback_add(wd->more, EVAS_CALLBACK_MOUSE_MOVE,
1091 (Evas_Object_Event_Cb)_reorder_mouse_move, it);
1093 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_MOVE,
1094 (Evas_Object_Event_Cb)_reorder_mouse_move, it);
1096 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_MOUSE_UP,
1097 (Evas_Object_Event_Cb)_reorder_mouse_up, it);
1099 evas_object_event_callback_add(wd->more, EVAS_CALLBACK_MOUSE_UP,
1100 (Evas_Object_Event_Cb)_reorder_mouse_up, it);
1102 evas_object_geometry_get(VIEW(item), &x, &y, &w, &h);
1103 evas_object_resize(VIEW(it), w, h);
1104 evas_object_move(VIEW(it), x, y);
1105 evas_object_show(VIEW(it));
1109 _long_press(Elm_Toolbar_Item *it)
1111 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1112 wd->long_timer = NULL;
1113 wd->long_press = EINA_TRUE;
1115 if ((wd->more_item != it) &&
1116 (wd->more_item == (Elm_Toolbar_Item *)elm_toolbar_selected_item_get(WIDGET(it))))
1117 _item_reorder_start(it);
1119 evas_object_smart_callback_call(WIDGET(it), SIG_LONGPRESSED, it);
1120 return ECORE_CALLBACK_CANCEL;
1124 _mouse_move(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Move *ev)
1126 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1128 Evas_Coord x, y, w, h;
1129 evas_object_geometry_get(VIEW(it), &x, &y, &w, &h);
1131 if ((wd->long_timer) &&
1132 ((x > ev->cur.canvas.x) || (ev->cur.canvas.x > x + w) ||
1133 (y > ev->cur.canvas.y) || (ev->cur.canvas.y > y + h)))
1135 ecore_timer_del(wd->long_timer);
1136 wd->long_timer = NULL;
1141 _mouse_down(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Down *ev)
1143 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1145 if (ev->button != 1) return;
1146 if (ev->flags & EVAS_BUTTON_DOUBLE_CLICK)
1147 evas_object_smart_callback_call(WIDGET(it), SIG_CLICKED_DOUBLE, it);
1148 wd->long_press = EINA_FALSE;
1149 if (wd->long_timer) ecore_timer_interval_set(wd->long_timer, _elm_config->longpress_timeout);
1150 else wd->long_timer = ecore_timer_add(_elm_config->longpress_timeout, (Ecore_Task_Cb)_long_press, it);
1151 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_MOVE,
1152 (Evas_Object_Event_Cb)_mouse_move, it);
1156 _mouse_up(Elm_Toolbar_Item *it, Evas *evas __UNUSED__, Evas_Object *obj __UNUSED__, Evas_Event_Mouse_Up *ev)
1158 Widget_Data *wd = elm_widget_data_get(WIDGET(it));
1160 if (ev->button != 1) return;
1163 ecore_timer_del(wd->long_timer);
1164 wd->long_timer = NULL;
1166 evas_object_event_callback_del_full(VIEW(it), EVAS_CALLBACK_MOUSE_MOVE,
1167 (Evas_Object_Event_Cb)_mouse_move, it);
1171 _mouse_in(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1173 Elm_Toolbar_Item *it = data;
1174 edje_object_signal_emit(VIEW(it), "elm,state,highlighted", "elm");
1175 elm_widget_signal_emit(it->icon, "elm,state,highlighted", "elm");
1179 _mouse_out(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
1181 Elm_Toolbar_Item *it = data;
1182 edje_object_signal_emit(VIEW(it), "elm,state,unhighlighted", "elm");
1183 elm_widget_signal_emit(it->icon, "elm,state,unhighlighted", "elm");
1187 _layout(Evas_Object *o, Evas_Object_Box_Data *priv, void *data)
1189 Evas_Object *obj = (Evas_Object *) data;
1190 Widget_Data *wd = elm_widget_data_get(obj);
1192 _els_box_layout(o, priv, !wd->vertical, wd->homogeneous,
1193 elm_widget_mirrored_get(obj));
1197 _access_info_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item)
1199 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
1200 const char *txt = item->access_info;
1201 if (!txt) txt = it->label;
1202 if (txt) return strdup(txt);
1207 _access_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, Elm_Widget_Item *item __UNUSED__)
1209 Elm_Toolbar_Item *it = (Elm_Toolbar_Item *)item;
1211 return strdup(E_("Separator"));
1212 else if (elm_widget_item_disabled_get(it))
1213 return strdup(E_("State: Disabled"));
1214 else if (it->selected)
1215 return strdup(E_("State: Selected"));
1217 return strdup(E_("Has menu"));
1222 _item_del_pre_hook(Elm_Object_Item *it)
1226 Elm_Toolbar_Item *item, *next;
1227 item = (Elm_Toolbar_Item *)it;
1229 wd = elm_widget_data_get(WIDGET(item));
1230 if (!wd) return EINA_FALSE;
1232 obj2 = WIDGET(item);
1233 next = ELM_TOOLBAR_ITEM_FROM_INLIST(EINA_INLIST_GET(item)->next);
1234 wd->items = eina_inlist_remove(wd->items, EINA_INLIST_GET(item));
1236 if (!next) next = ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1237 if ((wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
1238 item->selected && next) _item_select(next);
1245 static Elm_Toolbar_Item *
1246 _item_new(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1248 Widget_Data *wd = elm_widget_data_get(obj);
1249 Evas_Object *icon_obj;
1251 Elm_Toolbar_Item *it;
1253 icon_obj = elm_icon_add(obj);
1254 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
1255 if (!icon_obj) return NULL;
1256 it = elm_widget_item_new(obj, Elm_Toolbar_Item);
1259 evas_object_del(icon_obj);
1263 elm_widget_item_del_pre_hook_set(it, _item_del_pre_hook);
1264 elm_widget_item_disable_hook_set(it, _item_disable_hook);
1265 elm_widget_item_text_set_hook_set(it, _item_text_set_hook);
1266 elm_widget_item_text_get_hook_set(it, _item_text_get_hook);
1267 elm_widget_item_content_set_hook_set(it, _item_content_set_hook);
1268 elm_widget_item_content_get_hook_set(it, _item_content_get_hook);
1269 elm_widget_item_content_unset_hook_set(it, _item_content_unset_hook);
1271 it->label = eina_stringshare_add(label);
1272 it->prio.visible = 1;
1273 it->prio.priority = 0;
1275 it->separator = EINA_FALSE;
1277 it->base.data = data;
1278 VIEW(it) = edje_object_add(evas_object_evas_get(obj));
1279 _elm_access_item_register(&it->base, VIEW(it));
1280 _elm_access_text_set(_elm_access_item_get(&it->base),
1281 ELM_ACCESS_TYPE, E_("Tool Item"));
1282 _elm_access_callback_set(_elm_access_item_get(&it->base),
1283 ELM_ACCESS_INFO, _access_info_cb, it);
1284 _elm_access_callback_set(_elm_access_item_get(&it->base),
1285 ELM_ACCESS_STATE, _access_state_cb, it);
1287 if (_item_icon_set(icon_obj, "toolbar/", icon))
1289 it->icon = icon_obj;
1290 it->icon_str = eina_stringshare_add(icon);
1295 it->icon_str = NULL;
1296 evas_object_del(icon_obj);
1299 _elm_theme_object_set(obj, VIEW(it), "toolbar", "item",
1300 elm_widget_style_get(obj));
1301 edje_object_signal_callback_add(VIEW(it), "elm,action,click", "elm",
1303 edje_object_signal_callback_add(VIEW(it), "mouse,clicked,*", "*",
1304 (Edje_Signal_Cb)_select_filter, it);
1305 edje_object_signal_callback_add(VIEW(it), "elm,mouse,in", "elm",
1307 edje_object_signal_callback_add(VIEW(it), "elm,mouse,out", "elm",
1309 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_DOWN,
1310 (Evas_Object_Event_Cb)_mouse_down, it);
1311 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_MOUSE_UP,
1312 (Evas_Object_Event_Cb)_mouse_up, it);
1313 elm_widget_sub_object_add(obj, VIEW(it));
1318 ms = ((double)wd->icon_size * _elm_config->scale);
1319 evas_object_size_hint_min_set(it->icon, ms, ms);
1320 evas_object_size_hint_max_set(it->icon, ms, ms);
1321 edje_object_part_swallow(VIEW(it), "elm.swallow.icon", it->icon);
1322 edje_object_signal_emit(VIEW(it), "elm,state,icon,visible", "elm");
1323 evas_object_show(it->icon);
1324 elm_widget_sub_object_add(obj, it->icon);
1328 edje_object_part_text_escaped_set(VIEW(it), "elm.text", it->label);
1329 edje_object_signal_emit(VIEW(it), "elm,state,text,visible", "elm");
1332 if (!it->separator && !it->object)
1333 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1334 edje_object_size_min_restricted_calc(VIEW(it), &mw, &mh, mw, mh);
1335 if (!it->separator && !it->object)
1336 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1337 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1341 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, -1.0);
1342 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, 0.5);
1346 evas_object_size_hint_weight_set(VIEW(it), -1.0, EVAS_HINT_EXPAND);
1347 evas_object_size_hint_align_set(VIEW(it), 0.5, EVAS_HINT_FILL);
1352 evas_object_size_hint_weight_set(VIEW(it), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1353 evas_object_size_hint_align_set(VIEW(it), EVAS_HINT_FILL, EVAS_HINT_FILL);
1355 evas_object_size_hint_min_set(VIEW(it), mw, mh);
1356 evas_object_size_hint_max_set(VIEW(it), -1, -1);
1357 evas_object_event_callback_add(VIEW(it), EVAS_CALLBACK_RESIZE,
1359 if ((!wd->items) && (wd->select_mode == ELM_OBJECT_SELECT_MODE_ALWAYS))
1365 _elm_toolbar_item_label_update(Elm_Toolbar_Item *item)
1367 Evas_Coord mw = -1, mh = -1, minw = -1, minh = -1;
1368 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1369 edje_object_part_text_escaped_set(VIEW(item), "elm.text", item->label);
1370 edje_object_signal_emit(VIEW(item), "elm,state,text,visible", "elm");
1372 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1373 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1374 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1375 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1379 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1380 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1384 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1385 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1390 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1391 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1393 evas_object_size_hint_min_get(VIEW(item), &minw, &minh);
1394 if ((minw < mw) && (minh < mh))
1395 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1396 else if ((minw < mw) && (minh > mh))
1397 evas_object_size_hint_min_set(VIEW(item), mw, minh);
1398 else if ((minw > mw) && (minh < mh))
1399 evas_object_size_hint_min_set(VIEW(item), minw, mh);
1403 _elm_toolbar_item_label_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1405 Elm_Toolbar_Item *item = data;
1406 _elm_toolbar_item_label_update(item);
1407 edje_object_signal_callback_del(obj, emission, source,
1408 _elm_toolbar_item_label_set_cb);
1409 edje_object_signal_emit (VIEW(item), "elm,state,label,reset", "elm");
1413 _item_label_set(Elm_Toolbar_Item *item, const char *label, const char *sig)
1417 if ((label) && (item->label) && (!strcmp(label, item->label))) return;
1419 eina_stringshare_replace(&item->label, label);
1420 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1421 if ((s) && (atoi(s)))
1423 edje_object_part_text_escaped_set(VIEW(item), "elm.text_new", item->label);
1424 edje_object_signal_emit (VIEW(item), sig, "elm");
1425 edje_object_signal_callback_add(VIEW(item),
1426 "elm,state,label_set,done", "elm",
1427 _elm_toolbar_item_label_set_cb, item);
1430 _elm_toolbar_item_label_update(item);
1431 _resize(WIDGET(item), NULL, NULL, NULL);
1435 _elm_toolbar_item_icon_update(Elm_Toolbar_Item *item)
1437 Elm_Toolbar_Item_State *it_state;
1439 Evas_Coord mw = -1, mh = -1, minw = -1, minh = -1;
1440 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1441 Evas_Object *old_icon = edje_object_part_swallow_get(VIEW(item),
1442 "elm.swallow.icon");
1443 elm_widget_sub_object_del(VIEW(item), old_icon);
1444 /* edje_object_part_unswallow(VIEW(item), old_icon); */
1445 edje_object_part_swallow(VIEW(item), "elm.swallow.icon", item->icon);
1446 edje_object_signal_emit(VIEW(item), "elm,state,icon,visible", "elm");
1447 evas_object_hide(old_icon);
1448 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1449 edje_object_size_min_restricted_calc(VIEW(item), &mw, &mh, mw, mh);
1450 elm_coords_finger_size_adjust(1, &mw, 1, &mh);
1451 if (wd->shrink_mode != ELM_TOOLBAR_SHRINK_EXPAND)
1455 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, -1.0);
1456 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, 0.5);
1460 evas_object_size_hint_weight_set(VIEW(item), -1.0, EVAS_HINT_EXPAND);
1461 evas_object_size_hint_align_set(VIEW(item), 0.5, EVAS_HINT_FILL);
1466 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
1467 evas_object_size_hint_align_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
1469 evas_object_size_hint_min_get(VIEW(item), &minw, &minh);
1470 if ((minw < mw) && (minh < mh))
1471 evas_object_size_hint_min_set(VIEW(item), mw, mh);
1472 else if ((minw < mw) && (minh > mh))
1473 evas_object_size_hint_min_set(VIEW(item), mw, minh);
1474 else if ((minw > mw) && (minh < mh))
1475 evas_object_size_hint_min_set(VIEW(item), minw, mh);
1477 EINA_LIST_FOREACH(item->states, l, it_state)
1479 if (it_state->icon == old_icon) return;
1481 evas_object_del(old_icon);
1485 _elm_toolbar_item_icon_set_cb (void *data, Evas_Object *obj, const char *emission, const char *source)
1487 Elm_Toolbar_Item *item = data;
1488 edje_object_part_unswallow(VIEW(item), item->icon);
1489 _elm_toolbar_item_icon_update(item);
1490 edje_object_signal_callback_del(obj, emission, source,
1491 _elm_toolbar_item_icon_set_cb);
1492 edje_object_signal_emit (VIEW(item), "elm,state,icon,reset", "elm");
1496 _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)
1498 Evas_Object *old_icon;
1503 eina_stringshare_replace(&item->icon_str, icon_str);
1506 eina_stringshare_del(item->icon_str);
1507 item->icon_str = NULL;
1509 item->icon = icon_obj;
1512 ms = (icon_size * _elm_config->scale);
1513 evas_object_size_hint_min_set(item->icon, ms, ms);
1514 evas_object_size_hint_max_set(item->icon, ms, ms);
1515 evas_object_show(item->icon);
1516 elm_widget_sub_object_add(obj, item->icon);
1518 s = edje_object_data_get(VIEW(item), "transition_animation_on");
1519 if ((s) && (atoi(s)))
1521 old_icon = edje_object_part_swallow_get(VIEW(item),
1522 "elm.swallow.icon_new");
1525 elm_widget_sub_object_del(VIEW(item), old_icon);
1526 evas_object_hide(old_icon);
1528 edje_object_part_swallow(VIEW(item), "elm.swallow.icon_new",
1530 edje_object_signal_emit (VIEW(item), sig, "elm");
1531 edje_object_signal_callback_add(VIEW(item),
1532 "elm,state,icon_set,done", "elm",
1533 _elm_toolbar_item_icon_set_cb, item);
1536 _elm_toolbar_item_icon_update(item);
1537 _resize(obj, NULL, NULL, NULL);
1541 _elm_toolbar_item_state_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info)
1543 Elm_Toolbar_Item *it = event_info;
1544 Elm_Toolbar_Item_State *it_state;
1546 it_state = eina_list_data_get(it->current_state);
1548 it_state->func((void *)it_state->data, obj, event_info);
1551 static Elm_Toolbar_Item_State *
1552 _item_state_new(const char *label, const char *icon_str, Evas_Object *icon, Evas_Smart_Cb func, const void *data)
1554 Elm_Toolbar_Item_State *it_state;
1555 it_state = ELM_NEW(Elm_Toolbar_Item_State);
1556 it_state->label = eina_stringshare_add(label);
1557 it_state->icon_str = eina_stringshare_add(icon_str);
1558 it_state->icon = icon;
1559 it_state->func = func;
1560 it_state->data = data;
1565 elm_toolbar_add(Evas_Object *parent)
1571 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
1573 ELM_SET_WIDTYPE(widtype, "toolbar");
1574 elm_widget_type_set(obj, "toolbar");
1575 elm_widget_sub_object_add(parent, obj);
1576 elm_widget_data_set(obj, wd);
1577 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
1578 elm_widget_del_hook_set(obj, _del_hook);
1579 elm_widget_theme_hook_set(obj, _theme_hook);
1580 elm_widget_translate_hook_set(obj, _translate_hook);
1581 elm_widget_can_focus_set(obj, EINA_TRUE);
1583 wd->more_item = NULL;
1584 wd->selected_item = NULL;
1585 wd->standard_priority = -99999;
1586 wd->scr = elm_smart_scroller_add(e);
1587 elm_smart_scroller_widget_set(wd->scr, obj);
1588 elm_smart_scroller_object_theme_set(obj, wd->scr, "toolbar", "base", "default");
1589 elm_smart_scroller_bounce_allow_set(wd->scr,
1590 _elm_config->thumbscroll_bounce_enable,
1592 elm_widget_resize_object_set(obj, wd->scr);
1593 elm_smart_scroller_policy_set(wd->scr,
1594 ELM_SMART_SCROLLER_POLICY_AUTO,
1595 ELM_SMART_SCROLLER_POLICY_OFF);
1597 wd->icon_size = _elm_toolbar_icon_size_get(wd);
1600 wd->homogeneous = EINA_TRUE;
1603 wd->bx = evas_object_box_add(e);
1604 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
1605 evas_object_box_layout_set(wd->bx, _layout, obj, NULL);
1606 elm_widget_sub_object_add(obj, wd->bx);
1607 elm_smart_scroller_child_set(wd->scr, wd->bx);
1608 evas_object_show(wd->bx);
1610 wd->more = elm_layout_add(obj);
1611 elm_layout_theme_set(wd->more, "toolbar", "more", "default");
1612 elm_widget_sub_object_add(obj, wd->more);
1613 evas_object_show(wd->more);
1615 wd->bx_more = evas_object_box_add(e);
1616 evas_object_size_hint_align_set(wd->bx_more, wd->align, 0.5);
1617 evas_object_box_layout_set(wd->bx_more, _layout, obj, NULL);
1618 elm_widget_sub_object_add(obj, wd->bx_more);
1619 elm_object_part_content_set(wd->more, "elm.swallow.content", wd->bx_more);
1620 evas_object_show(wd->bx_more);
1622 wd->bx_more2 = evas_object_box_add(e);
1623 evas_object_size_hint_align_set(wd->bx_more2, wd->align, 0.5);
1624 evas_object_box_layout_set(wd->bx_more2, _layout, obj, NULL);
1625 elm_widget_sub_object_add(obj, wd->bx_more2);
1626 elm_object_part_content_set(wd->more, "elm.swallow.content2", wd->bx_more2);
1627 evas_object_show(wd->bx_more2);
1629 elm_toolbar_shrink_mode_set(obj, _elm_config->toolbar_shrink_mode);
1630 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_RESIZE, _resize, obj);
1631 evas_object_event_callback_add(wd->scr, EVAS_CALLBACK_MOVE, _move, obj);
1632 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _resize, obj);
1633 elm_toolbar_icon_order_lookup_set(obj, ELM_ICON_LOOKUP_THEME_FDO);
1635 evas_object_smart_callbacks_descriptions_set(obj, _signals);
1642 elm_toolbar_icon_size_set(Evas_Object *obj, int icon_size)
1644 ELM_CHECK_WIDTYPE(obj, widtype);
1645 Widget_Data *wd = elm_widget_data_get(obj);
1647 if (wd->icon_size == icon_size) return;
1648 wd->icon_size = icon_size;
1653 elm_toolbar_icon_size_get(const Evas_Object *obj)
1655 ELM_CHECK_WIDTYPE(obj, widtype) 0;
1656 Widget_Data *wd = elm_widget_data_get(obj);
1658 return wd->icon_size;
1661 EAPI Elm_Object_Item *
1662 elm_toolbar_item_append(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1664 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1665 Widget_Data *wd = elm_widget_data_get(obj);
1666 if (!wd) return NULL;
1668 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1669 if (!it) return NULL;
1670 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1672 wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it));
1673 evas_object_box_append(wd->bx, VIEW(it));
1674 evas_object_show(VIEW(it));
1676 _theme_hook_item(obj, it, scale, wd->icon_size);
1680 return (Elm_Object_Item *)it;
1683 EAPI Elm_Object_Item *
1684 elm_toolbar_item_prepend(Evas_Object *obj, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
1686 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1687 Widget_Data *wd = elm_widget_data_get(obj);
1688 if (!wd) return NULL;
1690 Elm_Toolbar_Item *it = _item_new(obj, icon, label, func, data);
1691 if (!it) return NULL;
1692 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1694 wd->items = eina_inlist_prepend(wd->items, EINA_INLIST_GET(it));
1695 evas_object_box_prepend(wd->bx, VIEW(it));
1696 evas_object_show(VIEW(it));
1697 _theme_hook_item(obj, it, scale, wd->icon_size);
1701 return (Elm_Object_Item *)it;
1704 EAPI Elm_Object_Item *
1705 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)
1707 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1708 ELM_OBJ_ITEM_CHECK_OR_RETURN(before, NULL);
1710 Elm_Toolbar_Item *it, *_before;
1712 wd = elm_widget_data_get(obj);
1713 if (!wd) return NULL;
1714 _before = (Elm_Toolbar_Item *) before;
1715 it = _item_new(obj, icon, label, func, data);
1716 if (!it) return NULL;
1717 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1719 wd->items = eina_inlist_prepend_relative(wd->items, EINA_INLIST_GET(it),
1720 EINA_INLIST_GET(_before));
1721 evas_object_box_insert_before(wd->bx, VIEW(it), VIEW(_before));
1722 evas_object_show(VIEW(it));
1723 _theme_hook_item(obj, it, scale, wd->icon_size);
1727 return (Elm_Object_Item *)it;
1730 EAPI Elm_Object_Item *
1731 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)
1733 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1734 ELM_OBJ_ITEM_CHECK_OR_RETURN(after, NULL);
1736 Elm_Toolbar_Item *it, *_after;
1738 wd = elm_widget_data_get(obj);
1739 if (!wd) return NULL;
1740 _after = (Elm_Toolbar_Item *) after;
1741 it = _item_new(obj, icon, label, func, data);
1742 if (!it) return NULL;
1743 double scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1745 wd->items = eina_inlist_append_relative(wd->items, EINA_INLIST_GET(it),
1746 EINA_INLIST_GET(_after));
1747 evas_object_box_insert_after(wd->bx, VIEW(it), VIEW(_after));
1748 evas_object_show(VIEW(it));
1749 _theme_hook_item(obj, it, scale, wd->icon_size);
1753 return (Elm_Object_Item *)it;
1756 EAPI Elm_Object_Item *
1757 elm_toolbar_first_item_get(const Evas_Object *obj)
1759 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1760 Widget_Data *wd = elm_widget_data_get(obj);
1761 if (!wd || !wd->items) return NULL;
1762 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items);
1765 EAPI Elm_Object_Item *
1766 elm_toolbar_last_item_get(const Evas_Object *obj)
1768 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1769 Widget_Data *wd = elm_widget_data_get(obj);
1770 if (!wd || !wd->items) return NULL;
1771 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items->last);
1774 EAPI Elm_Object_Item *
1775 elm_toolbar_item_next_get(const Elm_Object_Item *it)
1777 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1778 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1779 EINA_INLIST_GET(((Elm_Toolbar_Item *)it))->next);
1782 EAPI Elm_Object_Item *
1783 elm_toolbar_item_prev_get(const Elm_Object_Item *it)
1785 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1786 return (Elm_Object_Item *) ELM_TOOLBAR_ITEM_FROM_INLIST(
1787 EINA_INLIST_GET(((Elm_Toolbar_Item *)it))->prev);
1791 elm_toolbar_item_priority_set(Elm_Object_Item *it, int priority)
1793 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1794 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1795 if (item->prio.priority == priority) return;
1796 item->prio.priority = priority;
1797 _resize(WIDGET(item), NULL, NULL, NULL);
1801 elm_toolbar_item_priority_get(const Elm_Object_Item *it)
1803 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
1804 return ((Elm_Toolbar_Item *)it)->prio.priority;
1807 EAPI Elm_Object_Item *
1808 elm_toolbar_item_find_by_label(const Evas_Object *obj, const char *label)
1810 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1811 Elm_Toolbar_Item *it;
1812 Widget_Data *wd = elm_widget_data_get(obj);
1813 if (!wd) return NULL;
1815 EINA_INLIST_FOREACH(wd->items, it)
1817 if (!strcmp(it->label, label))
1818 return (Elm_Object_Item *)it;
1824 elm_toolbar_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
1826 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1827 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1828 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1831 if (item->selected == selected) return;
1832 if (selected) _item_select(item);
1833 else _item_unselect(item);
1837 elm_toolbar_item_selected_get(const Elm_Object_Item *it)
1839 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1840 return ((Elm_Toolbar_Item *)it)->selected;
1843 EAPI Elm_Object_Item *
1844 elm_toolbar_selected_item_get(const Evas_Object *obj)
1846 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1847 Widget_Data *wd = elm_widget_data_get(obj);
1848 if (!wd) return NULL;
1849 return (Elm_Object_Item *) wd->selected_item;
1852 EAPI Elm_Object_Item *
1853 elm_toolbar_more_item_get(const Evas_Object *obj)
1855 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1856 Widget_Data *wd = elm_widget_data_get(obj);
1857 if (!wd) return NULL;
1858 return (Elm_Object_Item *) wd->more_item;
1862 elm_toolbar_item_icon_set(Elm_Object_Item *it, const char *icon)
1864 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1866 Evas_Object *icon_obj;
1869 Elm_Toolbar_Item * item = (Elm_Toolbar_Item *)it;
1872 wd = elm_widget_data_get(obj);
1874 if ((icon) && (item->icon_str) && (!strcmp(icon, item->icon_str))) return;
1876 icon_obj = elm_icon_add(obj);
1877 if (!icon_obj) return;
1878 if (_item_icon_set(icon_obj, "toolbar/", icon))
1879 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, icon, wd->icon_size,
1880 "elm,state,icon_set");
1883 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0,
1884 "elm,state,icon_set");
1885 evas_object_del(icon_obj);
1890 elm_toolbar_item_icon_get(const Elm_Object_Item *it)
1892 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1893 return ((Elm_Toolbar_Item *)it)->icon_str;
1897 elm_toolbar_item_object_get(const Elm_Object_Item *it)
1899 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1903 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1906 wd = elm_widget_data_get(obj);
1907 if (!wd) return NULL;
1913 elm_toolbar_item_icon_object_get(Elm_Object_Item *it)
1915 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1916 return ((Elm_Toolbar_Item *)it)->icon;
1920 elm_toolbar_item_icon_memfile_set(Elm_Object_Item *it, const void *img, size_t size, const char *format, const char *key)
1922 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1924 Evas_Object *icon_obj;
1928 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1931 wd = elm_widget_data_get(obj);
1932 if (!wd) return EINA_FALSE;
1936 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1937 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1938 ret = _els_smart_icon_memfile_set(icon_obj, img, size, format, key);
1941 evas_object_del(icon_obj);
1944 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1945 "elm,state,icon_set");
1948 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1953 elm_toolbar_item_icon_file_set(Elm_Object_Item *it, const char *file, const char *key)
1955 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
1957 Evas_Object *icon_obj;
1961 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1964 wd = elm_widget_data_get(obj);
1965 if (!wd) return EINA_FALSE;
1969 icon_obj = _els_smart_icon_add(evas_object_evas_get(obj));
1970 evas_object_repeat_events_set(icon_obj, EINA_TRUE);
1971 ret = _els_smart_icon_file_key_set(icon_obj, file, key);
1974 evas_object_del(icon_obj);
1977 _elm_toolbar_item_icon_obj_set(obj, item, icon_obj, NULL, wd->icon_size,
1978 "elm,state,icon_set");
1981 _elm_toolbar_item_icon_obj_set(obj, item, NULL, NULL, 0, "elm,state,icon_set");
1986 elm_toolbar_item_separator_set(Elm_Object_Item *it, Eina_Bool separator)
1988 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
1989 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
1990 Evas_Object *obj = WIDGET(item);
1991 Widget_Data *wd = elm_widget_data_get(obj);
1993 if (item->separator == separator) return;
1994 item->separator = separator;
1995 scale = (elm_widget_scale_get(obj) * _elm_config->scale);
1996 _theme_hook_item(obj, item, scale, wd->icon_size);
1997 evas_object_size_hint_min_set(VIEW(item), -1, -1);
2001 elm_toolbar_item_separator_get(const Elm_Object_Item *it)
2003 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2004 return ((Elm_Toolbar_Item *)it)->separator;
2008 elm_toolbar_shrink_mode_set(Evas_Object *obj, Elm_Toolbar_Shrink_Mode shrink_mode)
2010 ELM_CHECK_WIDTYPE(obj, widtype);
2011 Widget_Data *wd = elm_widget_data_get(obj);
2015 wd->shrink_mode = shrink_mode;
2016 bounce = (_elm_config->thumbscroll_bounce_enable) &&
2017 (shrink_mode == ELM_TOOLBAR_SHRINK_SCROLL);
2018 elm_smart_scroller_bounce_allow_set(wd->scr, bounce, EINA_FALSE);
2022 _item_del(wd->more_item);
2023 elm_widget_item_free(wd->more_item);
2024 wd->more_item = NULL;
2027 if (shrink_mode == ELM_TOOLBAR_SHRINK_MENU)
2029 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
2030 ELM_SMART_SCROLLER_POLICY_OFF);
2031 wd->more_item = _item_new(obj, "more_menu", "More", NULL, NULL);
2033 else if (shrink_mode == ELM_TOOLBAR_SHRINK_HIDE)
2034 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_OFF,
2035 ELM_SMART_SCROLLER_POLICY_OFF);
2036 else if (shrink_mode == ELM_TOOLBAR_SHRINK_EXPAND)
2038 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
2039 ELM_SMART_SCROLLER_POLICY_OFF);
2040 wd->more_item = _item_new(obj, "more_menu", "More", NULL, NULL);
2043 elm_smart_scroller_policy_set(wd->scr, ELM_SMART_SCROLLER_POLICY_AUTO,
2044 ELM_SMART_SCROLLER_POLICY_OFF);
2048 EAPI Elm_Toolbar_Shrink_Mode
2049 elm_toolbar_shrink_mode_get(const Evas_Object *obj)
2051 ELM_CHECK_WIDTYPE(obj, widtype) ELM_TOOLBAR_SHRINK_NONE;
2052 Widget_Data *wd = elm_widget_data_get(obj);
2054 if (!wd) return ELM_TOOLBAR_SHRINK_NONE;
2055 return wd->shrink_mode;
2059 elm_toolbar_homogeneous_set(Evas_Object *obj, Eina_Bool homogeneous)
2061 ELM_CHECK_WIDTYPE(obj, widtype);
2062 Widget_Data *wd = elm_widget_data_get(obj);
2065 wd->homogeneous = !!homogeneous;
2066 evas_object_smart_calculate(wd->bx);
2070 elm_toolbar_homogeneous_get(const Evas_Object *obj)
2072 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2073 Widget_Data *wd = elm_widget_data_get(obj);
2075 if (!wd) return EINA_FALSE;
2076 return wd->homogeneous;
2080 elm_toolbar_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
2082 Elm_Toolbar_Item *it;
2083 ELM_CHECK_WIDTYPE(obj, widtype);
2084 Widget_Data *wd = elm_widget_data_get(obj);
2087 EINA_SAFETY_ON_NULL_RETURN(parent);
2088 wd->menu_parent = parent;
2089 EINA_INLIST_FOREACH(wd->items, it)
2092 elm_menu_parent_set(it->o_menu, wd->menu_parent);
2094 if ((wd->more_item) && (wd->more_item->o_menu))
2095 elm_menu_parent_set(wd->more_item->o_menu, wd->menu_parent);
2099 elm_toolbar_menu_parent_get(const Evas_Object *obj)
2101 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
2102 Widget_Data *wd = elm_widget_data_get(obj);
2104 if (!wd) return NULL;
2105 return wd->menu_parent;
2109 elm_toolbar_align_set(Evas_Object *obj, double align)
2111 ELM_CHECK_WIDTYPE(obj, widtype);
2112 Widget_Data *wd = elm_widget_data_get(obj);
2117 if (wd->align != align)
2118 evas_object_size_hint_align_set(wd->bx, 0.5, align);
2122 if (wd->align != align)
2123 evas_object_size_hint_align_set(wd->bx, align, 0.5);
2129 elm_toolbar_align_get(const Evas_Object *obj)
2131 ELM_CHECK_WIDTYPE(obj, widtype) 0.0;
2132 Widget_Data *wd = elm_widget_data_get(obj);
2134 if (!wd) return 0.0;
2139 elm_toolbar_item_menu_set(Elm_Object_Item *it, Eina_Bool menu)
2141 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
2142 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2143 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
2146 if (item->menu == menu) return;
2147 if (menu) _item_menu_create(wd, item);
2148 else _item_menu_destroy(item);
2152 elm_toolbar_item_menu_get(const Elm_Object_Item *it)
2154 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2155 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2156 if (!item->menu) return NULL;
2157 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
2158 if (!wd) return NULL;
2159 return item->o_menu;
2162 EAPI Elm_Toolbar_Item_State *
2163 elm_toolbar_item_state_add(Elm_Object_Item *it, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
2165 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2167 Elm_Toolbar_Item_State *it_state;
2168 Evas_Object *icon_obj;
2171 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2173 wd = elm_widget_data_get(WIDGET(item));
2174 if (!wd) return NULL;
2178 it_state = _item_state_new(item->label, item->icon_str, item->icon,
2179 item->func, item->base.data);
2180 item->states = eina_list_append(item->states, it_state);
2181 item->current_state = item->states;
2184 icon_obj = elm_icon_add(obj);
2185 elm_icon_order_lookup_set(icon_obj, wd->lookup_order);
2186 if (!icon_obj) goto error_state_add;
2188 if (!_item_icon_set(icon_obj, "toolbar/", icon))
2190 evas_object_del(icon_obj);
2195 it_state = _item_state_new(label, icon, icon_obj, func, data);
2196 item->states = eina_list_append(item->states, it_state);
2197 item->func = _elm_toolbar_item_state_cb;
2198 item->base.data = NULL;
2203 if (item->states && !eina_list_next(item->states))
2205 eina_stringshare_del(item->label);
2206 eina_stringshare_del(item->icon_str);
2207 free(eina_list_data_get(item->states));
2208 eina_list_free(item->states);
2209 item->states = NULL;
2215 elm_toolbar_item_state_del(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
2217 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2219 Eina_List *del_state;
2220 Elm_Toolbar_Item_State *it_state;
2221 Elm_Toolbar_Item *item;
2223 if (!state) return EINA_FALSE;
2225 item = (Elm_Toolbar_Item *)it;
2226 if (!item->states) return EINA_FALSE;
2228 del_state = eina_list_data_find_list(item->states, state);
2229 if (del_state == item->states) return EINA_FALSE;
2230 if (del_state == item->current_state)
2231 elm_toolbar_item_state_unset(it);
2233 eina_stringshare_del(state->label);
2234 eina_stringshare_del(state->icon_str);
2235 if (state->icon) evas_object_del(state->icon);
2237 item->states = eina_list_remove_list(item->states, del_state);
2238 if (item->states && !eina_list_next(item->states))
2240 it_state = eina_list_data_get(item->states);
2241 item->base.data = it_state->data;
2242 item->func = it_state->func;
2243 eina_stringshare_del(it_state->label);
2244 eina_stringshare_del(it_state->icon_str);
2245 free(eina_list_data_get(item->states));
2246 eina_list_free(item->states);
2247 item->states = NULL;
2253 elm_toolbar_item_state_set(Elm_Object_Item *it, Elm_Toolbar_Item_State *state)
2255 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
2258 Eina_List *next_state;
2259 Elm_Toolbar_Item_State *it_state;
2261 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2264 wd = elm_widget_data_get(obj);
2265 if (!wd) return EINA_FALSE;
2266 if (!item->states) return EINA_FALSE;
2270 next_state = eina_list_data_find_list(item->states, state);
2271 if (!next_state) return EINA_FALSE;
2274 next_state = item->states;
2276 if (next_state == item->current_state) return EINA_TRUE;
2278 it_state = eina_list_data_get(next_state);
2279 if (eina_list_data_find(item->current_state, state))
2281 _item_label_set(item, it_state->label, "elm,state,label_set,forward");
2282 _elm_toolbar_item_icon_obj_set(obj, item, it_state->icon, it_state->icon_str,
2283 wd->icon_size, "elm,state,icon_set,forward");
2287 _item_label_set(item, it_state->label, "elm,state,label_set,backward");
2288 _elm_toolbar_item_icon_obj_set(obj,
2293 "elm,state,icon_set,backward");
2295 if (elm_widget_item_disabled_get(item))
2296 elm_widget_signal_emit(item->icon, "elm,state,disabled", "elm");
2298 elm_widget_signal_emit(item->icon, "elm,state,enabled", "elm");
2300 item->current_state = next_state;
2305 elm_toolbar_item_state_unset(Elm_Object_Item *it)
2307 elm_toolbar_item_state_set(it, NULL);
2310 EAPI Elm_Toolbar_Item_State *
2311 elm_toolbar_item_state_get(const Elm_Object_Item *it)
2313 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2314 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2316 if ((!item->states) || (!item->current_state)) return NULL;
2317 if (item->current_state == item->states) return NULL;
2319 return eina_list_data_get(item->current_state);
2322 EAPI Elm_Toolbar_Item_State *
2323 elm_toolbar_item_state_next(Elm_Object_Item *it)
2325 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2329 Eina_List *next_state;
2330 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2333 wd = elm_widget_data_get(obj);
2334 if (!wd) return NULL;
2335 if (!item->states) return NULL;
2337 next_state = eina_list_next(item->current_state);
2339 next_state = eina_list_next(item->states);
2340 return eina_list_data_get(next_state);
2343 EAPI Elm_Toolbar_Item_State *
2344 elm_toolbar_item_state_prev(Elm_Object_Item *it)
2346 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
2350 Eina_List *prev_state;
2351 Elm_Toolbar_Item *item = (Elm_Toolbar_Item *)it;
2354 wd = elm_widget_data_get(obj);
2355 if (!wd) return NULL;
2356 if (!item->states) return NULL;
2358 prev_state = eina_list_prev(item->current_state);
2359 if ((!prev_state) || (prev_state == item->states))
2360 prev_state = eina_list_last(item->states);
2361 return eina_list_data_get(prev_state);
2365 elm_toolbar_icon_order_lookup_set(Evas_Object *obj, Elm_Icon_Lookup_Order order)
2367 ELM_CHECK_WIDTYPE(obj, widtype);
2368 Elm_Toolbar_Item *it;
2369 Widget_Data *wd = elm_widget_data_get(obj);
2372 wd->lookup_order = order;
2373 EINA_INLIST_FOREACH(wd->items, it)
2374 elm_icon_order_lookup_set(it->icon, order);
2376 elm_icon_order_lookup_set(wd->more_item->icon, order);
2379 EAPI Elm_Icon_Lookup_Order
2380 elm_toolbar_icon_order_lookup_get(const Evas_Object *obj)
2382 ELM_CHECK_WIDTYPE(obj, widtype) ELM_ICON_LOOKUP_THEME_FDO;
2383 Widget_Data *wd = elm_widget_data_get(obj);
2384 if (!wd) return ELM_ICON_LOOKUP_THEME_FDO;
2385 return wd->lookup_order;
2389 elm_toolbar_horizontal_set(Evas_Object *obj, Eina_Bool horizontal)
2391 ELM_CHECK_WIDTYPE(obj, widtype);
2392 Widget_Data *wd = elm_widget_data_get(obj);
2394 wd->vertical = !horizontal;
2396 evas_object_size_hint_align_set(wd->bx, 0.5, wd->align);
2398 evas_object_size_hint_align_set(wd->bx, wd->align, 0.5);
2403 elm_toolbar_horizontal_get(const Evas_Object *obj)
2405 ELM_CHECK_WIDTYPE(obj, widtype) EINA_FALSE;
2406 Widget_Data *wd = elm_widget_data_get(obj);
2407 if (!wd) return EINA_FALSE;
2408 return !wd->vertical;
2412 elm_toolbar_items_count(const Evas_Object *obj)
2414 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2415 Widget_Data *wd = elm_widget_data_get(obj);
2417 return wd->item_count;
2421 elm_toolbar_standard_priority_set(Evas_Object *obj, int priority)
2423 ELM_CHECK_WIDTYPE(obj, widtype);
2424 Widget_Data *wd = elm_widget_data_get(obj);
2426 wd->standard_priority = priority;
2427 _resize(obj, NULL, NULL, NULL);
2431 elm_toolbar_standard_priority_get(const Evas_Object *obj)
2433 ELM_CHECK_WIDTYPE(obj, widtype) 0;
2434 Widget_Data *wd = elm_widget_data_get(obj);
2436 return wd->standard_priority;
2440 elm_toolbar_select_mode_set(Evas_Object *obj, Elm_Object_Select_Mode mode)
2442 ELM_CHECK_WIDTYPE(obj, widtype);
2443 Widget_Data *wd = elm_widget_data_get(obj);
2445 if (mode >= ELM_OBJECT_SELECT_MODE_MAX)
2447 if ((mode == ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2448 (wd->select_mode != ELM_OBJECT_SELECT_MODE_ALWAYS) &&
2450 _item_select(ELM_TOOLBAR_ITEM_FROM_INLIST(wd->items));
2451 if (wd->select_mode != mode)
2452 wd->select_mode = mode;
2455 EAPI Elm_Object_Select_Mode
2456 elm_toolbar_select_mode_get(const Evas_Object *obj)
2458 ELM_CHECK_WIDTYPE(obj, widtype) ELM_OBJECT_SELECT_MODE_MAX;
2459 Widget_Data *wd = elm_widget_data_get(obj);
2460 if (!wd) return ELM_OBJECT_SELECT_MODE_MAX;
2461 return wd->select_mode;