1 #include <Elementary.h>
8 * A menu is a list of items displayed above the window. Each item can
9 * have a sub-menu. The menu object can be used to display a menu on right
10 * click, in a toolbar, anywhere.
12 * Signals that you can add callbacks for are:
14 * "clicked" - the user clicked the empty space in the menu to dismiss.
18 typedef struct _Widget_Data Widget_Data;
23 Elm_Menu_Item *parent;
30 Evas_Object *hv, *bx, *location;
35 Eina_Bool separator : 1;
36 Eina_Bool disabled : 1;
37 Eina_Bool selected: 1;
42 Evas_Object *hv, *bx, *location, *parent, *obj;
44 Evas_Coord xloc, yloc;
47 static const char *widtype = NULL;
48 static void _del_hook(Evas_Object *obj);
49 static void _theme_hook(Evas_Object *obj);
50 static void _sizing_eval(Evas_Object *obj);
51 static void _submenu_sizing_eval(Elm_Menu_Item *parent);
52 static void _item_sizing_eval(Elm_Menu_Item *item);
53 static void _submenu_hide(Elm_Menu_Item *item);
54 static void _submenu_open(void *data, Evas_Object *obj, const char *emission, const char *source);
55 static void _parent_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
56 static void _parent_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
57 static void _menu_hide(void *data, Evas_Object *obj, void *event_info);
59 static const char SIG_CLICKED[] = "clicked";
61 static const Evas_Smart_Cb_Description _signals[] = {
68 _del_item(Elm_Menu_Item *item)
72 elm_widget_item_pre_notify_del(item);
74 EINA_LIST_FREE(item->submenu.items, child)
77 if (item->label) eina_stringshare_del(item->label);
78 if (item->submenu.hv) evas_object_del(item->submenu.hv);
79 if (item->submenu.location) evas_object_del(item->submenu.location);
80 if (item->icon_str) eina_stringshare_del(item->icon_str);
81 elm_widget_item_del(item);
85 _del_pre_hook(Evas_Object *obj)
88 Widget_Data *wd = elm_widget_data_get(obj);
91 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE, _parent_resize, obj);
92 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL, _parent_del, wd);
94 EINA_LIST_FREE(wd->items, item)
97 if (wd->hv) evas_object_del(wd->hv);
98 if (wd->location) evas_object_del(wd->location);
102 _del_hook(Evas_Object *obj)
104 Widget_Data *wd = elm_widget_data_get(obj);
109 _theme_hook(Evas_Object *obj)
111 Eina_List *l, *_l, *_ll, *ll = NULL;
113 Widget_Data *wd = elm_widget_data_get(obj);
115 _elm_widget_mirrored_reload(obj);
116 ll = eina_list_append(ll, wd->items);
117 EINA_LIST_FOREACH(ll, _ll, l)
119 EINA_LIST_FOREACH(l, _l, item)
121 edje_object_mirrored_set(item->base.view, elm_widget_mirrored_get(obj));
122 ll = eina_list_append(ll, item->submenu.items);
124 _elm_theme_object_set(obj, item->base.view, "menu", "separator",
125 elm_widget_style_get(obj));
126 else if (item->submenu.bx)
128 _elm_theme_object_set
129 (obj, item->base.view, "menu", "item_with_submenu",
130 elm_widget_style_get(obj));
131 elm_menu_item_label_set(item, item->label);
132 elm_menu_item_icon_set(item, item->icon_str);
136 _elm_theme_object_set(obj, item->base.view, "menu", "item",
137 elm_widget_style_get(obj));
138 elm_menu_item_label_set(item, item->label);
139 elm_menu_item_icon_set(item, item->icon_str);
142 edje_object_signal_emit
143 (item->base.view, "elm,state,disabled", "elm");
145 edje_object_signal_emit
146 (item->base.view, "elm,state,enabled", "elm");
147 edje_object_message_signal_process(item->base.view);
148 edje_object_scale_set(item->base.view, elm_widget_scale_get(obj) *
156 _sizing_eval(Evas_Object *obj)
160 Evas_Coord x_p, y_p, w_p, h_p, x2, y2, w2, h2, bx, by, bw, bh;
161 Widget_Data *wd = elm_widget_data_get(obj);
162 if ((!wd) || (!wd->parent)) return;
163 EINA_LIST_FOREACH(wd->items,l,item) _item_sizing_eval(item);
164 evas_object_geometry_get(wd->location, &x_p, &y_p, &w_p, &h_p);
165 evas_object_geometry_get(wd->parent, &x2, &y2, &w2, &h2);
166 evas_object_geometry_get(wd->bx, &bx, &by, &bw, &bh);
171 if (elm_widget_mirrored_get(obj))
174 if (x_p+bw > x2+w2) x_p -= x_p+bw - (x2+w2);
175 if (x_p < x2) x_p += x2 - x_p;
177 if (y_p+h_p+bh > y2+h2) y_p -= y_p+h_p+bh - (y2+h2);
178 if (y_p < y2) y_p += y2 - y_p;
181 evas_object_move(wd->location, x_p, y_p);
182 evas_object_resize(wd->location, bw, h_p);
183 evas_object_size_hint_min_set(wd->location, bw, h_p);
184 evas_object_size_hint_max_set(wd->location, bw, h_p);
185 elm_hover_target_set(wd->hv, wd->location);
187 EINA_LIST_FOREACH(wd->items,l,item)
189 if (item->submenu.open) _submenu_sizing_eval(item);
194 _submenu_sizing_eval(Elm_Menu_Item *parent)
198 Evas_Coord x_p, y_p, w_p, h_p, x2, y2, w2, h2, bx, by, bw, bh, px, py, pw, ph;
199 Widget_Data *wd = elm_widget_data_get(parent->base.widget);
201 EINA_LIST_FOREACH(parent->submenu.items, l, item) _item_sizing_eval(item);
202 evas_object_geometry_get(parent->submenu.location, &x_p, &y_p, &w_p, &h_p);
203 evas_object_geometry_get(parent->base.view, &x2, &y2, &w2, &h2);
204 evas_object_geometry_get(parent->submenu.bx, &bx, &by, &bw, &bh);
205 evas_object_geometry_get(wd->parent, &px, &py, &pw, &ph);
210 /* If it overflows on the right, adjust the x */
211 if ((x_p + bw > px + pw) || elm_widget_mirrored_get(parent->base.widget))
214 /* If it overflows on the left, adjust the x - usually only happens
215 * with an RTL interface */
219 /* If after all the adjustments it still overflows, fix it */
220 if (x_p + bw > px + pw)
224 y_p -= y_p+bh - (py+ph);
228 evas_object_move(parent->submenu.location, x_p, y_p);
229 evas_object_resize(parent->submenu.location, bw, h_p);
230 evas_object_size_hint_min_set(parent->submenu.location, bw, h_p);
231 evas_object_size_hint_max_set(parent->submenu.location, bw, h_p);
232 elm_hover_target_set(parent->submenu.hv, parent->submenu.location);
234 EINA_LIST_FOREACH(parent->submenu.items, l, item)
236 if (item->submenu.open)
237 _submenu_sizing_eval(item);
242 _item_sizing_eval(Elm_Menu_Item *item)
244 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
245 if (!item->separator)
246 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
247 edje_object_size_min_restricted_calc(item->base.view, &minw, &minh, minw, minh);
248 if (!item->separator)
249 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
250 evas_object_size_hint_min_set(item->base.view, minw, minh);
251 evas_object_size_hint_max_set(item->base.view, maxw, maxh);
255 _menu_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
261 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
267 _parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
269 Widget_Data *wd = data;
270 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE, _parent_resize, wd->obj);
275 _item_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
277 Elm_Menu_Item *item = data;
278 if (item->submenu.open) _submenu_sizing_eval(item);
282 _hover_clicked_cb(void *data, Evas_Object *obj, void *event_info)
284 _menu_hide(data, obj, event_info);
285 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
289 _menu_hide(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
292 Elm_Menu_Item *item2;
293 Widget_Data *wd = elm_widget_data_get(data);
295 evas_object_hide(wd->hv);
296 evas_object_hide(data);
298 EINA_LIST_FOREACH(wd->items, l, item2)
300 if (item2->submenu.open) _submenu_hide(item2);
305 _submenu_hide(Elm_Menu_Item *item)
308 Elm_Menu_Item *item2;
309 evas_object_hide(item->submenu.hv);
310 item->submenu.open = EINA_FALSE;
311 EINA_LIST_FOREACH(item->submenu.items, l, item2)
313 if (item2->submenu.open) _submenu_hide(item2);
318 _menu_item_select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
320 Elm_Menu_Item *item = data;
321 if (item->submenu.items)
323 if (!item->submenu.open) _submenu_open(item, NULL, NULL, NULL);
324 else _submenu_hide(item);
327 _menu_hide(item->base.widget, NULL, NULL);
329 if (item->func) item->func((void *)(item->base.data), item->base.widget, item);
333 _menu_item_activate(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
336 Elm_Menu_Item *item2;
337 Elm_Menu_Item *item = data;
341 EINA_LIST_FOREACH(item->parent->submenu.items, l, item2)
343 if (item2 != item) elm_menu_item_selected_set(item2, 0);
348 Widget_Data *wd = elm_widget_data_get(item->base.widget);
349 EINA_LIST_FOREACH(wd->items, l, item2)
351 if (item2 != item) elm_menu_item_selected_set(item2, 0);
357 _menu_item_inactivate(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
359 Elm_Menu_Item *item = data;
361 if (item->submenu.open) _submenu_hide(item);
365 _submenu_open(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
367 Elm_Menu_Item *item = data;
368 item->submenu.open = EINA_TRUE;
369 evas_object_show(item->submenu.hv);
370 _sizing_eval(item->base.widget);
374 _show(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
376 Widget_Data *wd = elm_widget_data_get(data);
378 evas_object_show(wd->hv);
382 _item_obj_create(Elm_Menu_Item *item)
384 Widget_Data *wd = elm_widget_data_get(item->base.widget);
386 item->base.view = edje_object_add(evas_object_evas_get(wd->bx));
387 edje_object_mirrored_set(item->base.view, elm_widget_mirrored_get(item->base.widget));
388 evas_object_size_hint_weight_set(item->base.view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
389 evas_object_size_hint_fill_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
390 _elm_theme_object_set(item->base.widget, item->base.view, "menu", "item", elm_widget_style_get(item->base.widget));
391 edje_object_signal_callback_add(item->base.view, "elm,action,click", "",
392 _menu_item_select, item);
393 edje_object_signal_callback_add(item->base.view, "elm,action,activate", "",
394 _menu_item_activate, item);
395 edje_object_signal_callback_add(item->base.view, "elm,action,inactivate", "",
396 _menu_item_inactivate, item);
397 evas_object_show(item->base.view);
401 _item_separator_obj_create(Elm_Menu_Item *item)
403 Widget_Data *wd = elm_widget_data_get(item->base.widget);
405 item->base.view = edje_object_add(evas_object_evas_get(wd->bx));
406 evas_object_size_hint_weight_set(item->base.view, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
407 evas_object_size_hint_fill_set(item->base.view, EVAS_HINT_FILL, EVAS_HINT_FILL);
408 _elm_theme_object_set(item->base.widget, item->base.view, "menu", "separator", elm_widget_style_get(item->base.widget));
409 edje_object_signal_callback_add(item->base.view, "elm,action,activate", "",
410 _menu_item_activate, item);
411 evas_object_show(item->base.view);
415 _item_submenu_obj_create(Elm_Menu_Item *item)
417 Widget_Data *wd = elm_widget_data_get(item->base.widget);
419 item->submenu.location = elm_icon_add(wd->bx);
420 item->submenu.hv = elm_hover_add(wd->bx);
421 elm_widget_mirrored_set(item->submenu.hv, EINA_FALSE);
422 elm_hover_target_set(item->submenu.hv, item->submenu.location);
423 elm_hover_parent_set(item->submenu.hv, wd->parent);
424 elm_object_style_set(item->submenu.hv, "submenu");
426 item->submenu.bx = elm_box_add(wd->bx);
427 elm_widget_mirrored_set(item->submenu.bx, EINA_FALSE);
428 evas_object_size_hint_weight_set(item->submenu.bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
429 evas_object_show(item->submenu.bx);
430 elm_hover_content_set(item->submenu.hv, elm_hover_best_content_location_get(item->submenu.hv, ELM_HOVER_AXIS_VERTICAL), item->submenu.bx);
432 edje_object_mirrored_set(item->base.view, elm_widget_mirrored_get(item->base.widget));
433 _elm_theme_object_set(item->base.widget, item->base.view, "menu", "item_with_submenu", elm_widget_style_get(item->base.widget));
434 elm_menu_item_label_set(item, item->label);
435 elm_menu_item_icon_set(item, item->icon_str);
437 edje_object_signal_callback_add(item->base.view, "elm,action,open", "",
438 _submenu_open, item);
439 evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_MOVE, _item_move_resize, item);
440 evas_object_event_callback_add(item->base.view, EVAS_CALLBACK_RESIZE, _item_move_resize, item);
442 evas_object_event_callback_add(item->submenu.bx, EVAS_CALLBACK_RESIZE, _menu_resize, item->base.widget);
446 * Add a new menu to the parent
448 * @param parent The parent object.
449 * @return The new object or NULL if it cannot be created.
454 elm_menu_add(Evas_Object *parent)
460 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
462 ELM_SET_WIDTYPE(widtype, "menu");
463 elm_widget_type_set(obj, "menu");
464 elm_widget_sub_object_add(parent, obj);
465 elm_widget_data_set(obj, wd);
466 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
467 elm_widget_del_hook_set(obj, _del_hook);
468 elm_widget_theme_hook_set(obj, _theme_hook);
469 elm_widget_can_focus_set(obj, EINA_FALSE);
471 wd->location = elm_icon_add(obj);
475 wd->hv = elm_hover_add(obj);
476 elm_widget_mirrored_set(wd->hv, EINA_FALSE);
477 elm_hover_parent_set(wd->hv, parent);
478 elm_hover_target_set(wd->hv, wd->location);
479 elm_object_style_set(wd->hv, "menu");
480 evas_object_smart_callback_add(wd->hv, "clicked", _hover_clicked_cb, obj);
482 wd->bx = elm_box_add(obj);
483 elm_widget_mirrored_set(wd->bx, EINA_FALSE);
484 evas_object_size_hint_weight_set(wd->bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
485 evas_object_show(wd->bx);
486 elm_hover_content_set(wd->hv, elm_hover_best_content_location_get(wd->hv, ELM_HOVER_AXIS_VERTICAL), wd->bx);
488 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_RESIZE, _parent_resize, wd->obj);
489 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_DEL, _parent_del, wd);
491 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _show, obj);
493 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _menu_resize, obj);
495 evas_object_smart_callbacks_descriptions_set(obj, _signals);
504 * @param obj The menu object.
505 * @param parent The new parent.
510 elm_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
512 Eina_List *l, *_l, *_ll, *ll = NULL;
514 ELM_CHECK_WIDTYPE(obj, widtype);
515 Widget_Data *wd = elm_widget_data_get(obj);
518 if (wd->parent == parent) return;
521 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE, _parent_resize, wd->obj);
522 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL, _parent_del, wd);
527 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_RESIZE, _parent_resize, wd->obj);
528 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_DEL, _parent_del, wd);
530 elm_hover_parent_set(wd->hv, parent);
532 ll = eina_list_append(ll, wd->items);
533 EINA_LIST_FOREACH(ll, _ll, l)
535 EINA_LIST_FOREACH(l, _l, item)
537 if (item->submenu.hv)
539 elm_hover_parent_set(item->submenu.hv, parent);
540 ll = eina_list_append(ll, item->submenu.items);
550 * @param obj The menu object.
551 * @return The parent.
556 elm_menu_parent_get(const Evas_Object *obj)
558 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
559 Widget_Data *wd = elm_widget_data_get(obj);
560 if (!wd) return NULL;
565 * Move the menu to a new position
567 * @param obj The menu object.
568 * @param x The new position.
569 * @param y The new position.
574 elm_menu_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
576 ELM_CHECK_WIDTYPE(obj, widtype);
577 Widget_Data *wd = elm_widget_data_get(obj);
585 * Close a opened menu
587 * @param obj the menu object
593 elm_menu_close(Evas_Object *obj)
595 ELM_CHECK_WIDTYPE(obj, widtype);
596 Widget_Data *wd = elm_widget_data_get(obj);
597 _menu_hide(obj, wd->hv, NULL);
601 * Get the Evas_Object of an Elm_Menu_Item
603 * @param item The menu item object.
608 elm_menu_item_object_get(const Elm_Menu_Item *item)
610 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
611 return item->base.view;
615 _item_clone(Evas_Object *obj, Elm_Menu_Item *parent, Elm_Menu_Item *item)
617 Elm_Menu_Item *new_item, *subitem;
621 new_item = elm_menu_item_separator_add(obj, parent);
623 new_item = elm_menu_item_add(obj, parent, item->icon_str, item->label, item->func, item->base.data);
624 elm_menu_item_disabled_set(new_item, item->disabled);
626 EINA_LIST_FOREACH(item->submenu.items, iter, subitem)
627 _item_clone(obj, new_item, subitem);
631 elm_menu_clone(Evas_Object *from_menu, Evas_Object *to_menu, Elm_Menu_Item *parent)
633 ELM_CHECK_WIDTYPE(from_menu, widtype);
634 ELM_CHECK_WIDTYPE(to_menu, widtype);
635 Widget_Data *from_wd = elm_widget_data_get(from_menu);
639 if (!from_wd) return;
640 EINA_LIST_FOREACH(from_wd->items, iter, item)
641 _item_clone(to_menu, parent, item);
645 * Add an item at the end
647 * @param obj The menu object.
648 * @param icon A icon display on the item. The icon will be destryed by the menu.
649 * @param label The label of the item.
650 * @param func Function called when the user select the item.
651 * @param data Data sent by the callback.
652 * @return Returns the new item.
657 elm_menu_item_add(Evas_Object *obj, Elm_Menu_Item *parent, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
659 Elm_Menu_Item *subitem;
660 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
661 Widget_Data *wd = elm_widget_data_get(obj);
662 Evas_Object *icon_obj;
664 if (!wd) return NULL;
665 icon_obj = elm_icon_add(obj);
666 if (!icon_obj) return NULL;
667 subitem = elm_widget_item_new(obj, Elm_Menu_Item);
670 evas_object_del(icon_obj);
673 subitem->base.data = data;
674 subitem->func = func;
675 subitem->parent = parent;
676 subitem->icon = icon_obj;
678 _item_obj_create(subitem);
679 elm_menu_item_label_set(subitem, label);
681 elm_widget_sub_object_add(subitem->base.widget, subitem->icon);
682 edje_object_part_swallow(subitem->base.view, "elm.swallow.content", subitem->icon);
683 if (icon) elm_menu_item_icon_set(subitem, icon);
687 if (!parent->submenu.bx) _item_submenu_obj_create(parent);
688 elm_box_pack_end(parent->submenu.bx, subitem->base.view);
689 parent->submenu.items = eina_list_append(parent->submenu.items, subitem);
693 elm_box_pack_end(wd->bx, subitem->base.view);
694 wd->items = eina_list_append(wd->items, subitem);
702 * Set the label of a menu item
704 * @param item The menu item object.
705 * @param label The label to set for @p item
710 elm_menu_item_label_set(Elm_Menu_Item *item, const char *label)
712 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
713 eina_stringshare_replace(&item->label, label);
716 edje_object_signal_emit(item->base.view, "elm,state,text,visible", "elm");
718 edje_object_signal_emit(item->base.view, "elm,state,text,hidden", "elm");
720 edje_object_message_signal_process(item->base.view);
721 edje_object_part_text_set(item->base.view, "elm.text", label);
722 _sizing_eval(item->base.widget);
726 * Get the label of a menu item
728 * @param item The menu item object.
729 * @return The label of @p item
734 elm_menu_item_label_get(const Elm_Menu_Item *item)
736 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
741 * Set the icon of a menu item
743 * Once the icon object is set, a previously set one will be deleted.
745 * @param item The menu item object.
746 * @param icon The icon object to set for @p item
751 elm_menu_item_icon_set(Elm_Menu_Item *item, const char *icon)
754 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
755 EINA_SAFETY_ON_NULL_RETURN(icon);
757 if ((item->icon_str) && (!strcmp(item->icon_str, icon))) return;
758 if ((snprintf(icon_tmp, sizeof(icon_tmp), "menu/%s", icon) > 0) &&
759 (elm_icon_standard_set(item->icon, icon_tmp)))
761 eina_stringshare_replace(&item->icon_str, icon);
762 edje_object_signal_emit(item->base.view, "elm,state,icon,visible", "elm");
765 edje_object_signal_emit(item->base.view, "elm,state,icon,hidden", "elm");
766 edje_object_message_signal_process(item->base.view);
767 _sizing_eval(item->base.widget);
771 * Set the disabled state of @p item.
773 * @param item The menu item object.
774 * @param disabled The enabled/disabled state of the item
779 elm_menu_item_disabled_set(Elm_Menu_Item *item, Eina_Bool disabled)
781 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
782 if (disabled == item->disabled) return;
783 item->disabled = !!disabled;
786 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
787 if (item->submenu.open) _submenu_hide(item);
790 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
791 edje_object_message_signal_process(item->base.view);
795 * Get the disabled state of @p item.
797 * @param item The menu item object.
798 * @return The enabled/disabled state of the item
803 elm_menu_item_disabled_get(const Elm_Menu_Item *item)
805 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
806 return item->disabled;
810 * Add a separator item to menu @p obj under @p parent.
812 * @param obj The menu object
813 * @param parent The item to add the separator under
815 * @return The created item or NULL on failure
820 elm_menu_item_separator_add(Evas_Object *obj, Elm_Menu_Item *parent)
822 Elm_Menu_Item *subitem;
823 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
824 Widget_Data *wd = elm_widget_data_get(obj);
825 if (!wd) return NULL;
826 /* don't add a separator as the first item */
827 if (!wd->items) return NULL;
828 /* don't allow adding more than one separator in a row */
829 if (parent) subitem = eina_list_last(parent->submenu.items)->data;
830 else subitem = eina_list_last(wd->items)->data;
831 if (subitem->separator) return NULL;
833 subitem = elm_widget_item_new(obj, Elm_Menu_Item);
834 if (!subitem) return NULL;
835 subitem->base.widget = obj;
836 subitem->separator = 1;
837 _item_separator_obj_create(subitem);
840 elm_box_pack_end(wd->bx, subitem->base.view);
841 wd->items = eina_list_append(wd->items, subitem);
845 if (!parent->submenu.bx) _item_submenu_obj_create(parent);
846 elm_box_pack_end(parent->submenu.bx, subitem->base.view);
847 parent->submenu.items = eina_list_append(parent->submenu.items, subitem);
854 * Get the icon object from a menu item
856 * @param item The menu item object
857 * @return The icon object or NULL if there's no icon
861 EAPI const Evas_Object *
862 elm_menu_item_object_icon_get(const Elm_Menu_Item *item)
864 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
865 return (const Evas_Object *)item->icon;
869 * Get the string representation from the icon of a menu item
871 * @param item The menu item object.
872 * @return The string representation of @p item's icon or NULL
877 elm_menu_item_icon_get(const Elm_Menu_Item *item)
879 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
880 return item->icon_str;
884 * Returns whether @p item is a separator.
886 * @param item The item to check
887 * @return If true, @p item is a separator
892 elm_menu_item_is_separator(Elm_Menu_Item *item)
894 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
895 return item->separator;
899 * Deletes an item from the menu.
901 * @param item The item to delete.
906 elm_menu_item_del(Elm_Menu_Item *item)
908 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
909 Elm_Menu_Item *_item;
911 elm_widget_item_pre_notify_del(item);
913 EINA_LIST_FREE(item->submenu.items, _item) elm_menu_item_del(_item);
914 if (item->label) eina_stringshare_del(item->label);
915 if (item->icon) evas_object_del(item->icon);
916 if (item->submenu.hv) evas_object_del(item->submenu.hv);
917 if (item->submenu.location) evas_object_del(item->submenu.location);
920 item->parent->submenu.items = eina_list_remove(item->parent->submenu.items, item);
923 Widget_Data *wd = elm_widget_data_get(item->base.widget);
924 wd->items = eina_list_remove(wd->items, item);
927 elm_widget_item_del(item);
931 * Set the function called when a menu item is freed.
933 * @param item The item to set the callback on
934 * @param func The function called
939 elm_menu_item_del_cb_set(Elm_Menu_Item *item, Evas_Smart_Cb func)
941 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
942 elm_widget_item_del_cb_set(item, func);
946 * Returns the data associated with menu item @p item.
948 * @param item The item
949 * @return The data associated with @p item
954 elm_menu_item_data_get(const Elm_Menu_Item *item)
956 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
957 return elm_widget_item_data_get(item);
961 * Sets the data to be associated with menu item @p item.
963 * @param item The item
964 * @param data The data to be associated with @p item
969 elm_menu_item_data_set(Elm_Menu_Item *item, const void *data)
971 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
972 elm_widget_item_data_set(item, data);
976 * Returns a list of @p item's subitems.
978 * @param item The item
979 * @return An Eina_List* of @p item's subitems
983 EAPI const Eina_List *
984 elm_menu_item_subitems_get(const Elm_Menu_Item *item)
986 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
987 return item->submenu.items;
991 * Returns a list of @p item's items.
993 * @param obj The menu object
994 * @return An Eina_List* of @p item's items
998 EAPI const Eina_List *
999 elm_menu_items_get(const Evas_Object * obj)
1001 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1002 Widget_Data *wd = elm_widget_data_get(obj);
1007 * Set the selected state of @p item.
1009 * @param item The menu item object.
1010 * @param selected The selected/unselected state of the item
1015 elm_menu_item_selected_set(Elm_Menu_Item *item, Eina_Bool selected)
1017 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1018 if (selected == item->selected) return;
1019 item->selected = selected;
1022 edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
1023 _menu_item_activate(item, NULL, NULL, NULL);
1027 edje_object_signal_emit(item->base.view, "elm,state,unselected", "elm");
1028 _menu_item_inactivate(item, NULL, NULL, NULL);
1030 edje_object_message_signal_process(item->base.view);
1034 * Get the selected state of @p item.
1036 * @param item The menu item object.
1037 * @return The selected/unselected state of the item
1042 elm_menu_item_selected_get(const Elm_Menu_Item *item)
1044 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1045 return item->selected;
1049 * Get the previous item in the menu.
1051 * @param item The menu item object.
1052 * @return The item before it, or NULL if none
1056 EAPI const Elm_Menu_Item *
1057 elm_menu_item_prev_get(const Elm_Menu_Item *it)
1059 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
1062 Eina_List *l = eina_list_data_find_list(it->parent->submenu.items, it);
1063 l = eina_list_prev(l);
1064 if (!l) return NULL;
1069 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1070 if (!wd | !wd->items) return NULL;
1071 Eina_List *l = eina_list_data_find_list(wd->items, it);
1072 l = eina_list_prev(l);
1073 if (!l) return NULL;
1080 * Get the next item in the menu.
1082 * @param item The menu item object.
1083 * @return The item after it, or NULL if none
1087 EAPI const Elm_Menu_Item *
1088 elm_menu_item_next_get(const Elm_Menu_Item *it)
1090 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
1093 Eina_List *l = eina_list_data_find_list(it->parent->submenu.items, it);
1094 l = eina_list_next(l);
1095 if (!l) return NULL;
1100 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1101 if (!wd | !wd->items) return NULL;
1102 Eina_List *l = eina_list_data_find_list(wd->items, it);
1103 l = eina_list_next(l);
1104 if (!l) return NULL;
1111 * Get the first item in the menu
1113 * @param obj The menu object
1114 * @return The first item, or NULL if none
1118 EAPI const Elm_Menu_Item *
1119 elm_menu_first_item_get(const Evas_Object * obj)
1121 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1122 Widget_Data *wd = elm_widget_data_get(obj);
1123 if (!wd) return NULL;
1124 if (wd->items) return wd->items->data;
1129 * Get the last item in the menu
1131 * @param obj The menu object
1132 * @return The last item, or NULL if none
1136 EAPI const Elm_Menu_Item *
1137 elm_menu_last_item_get(const Evas_Object * obj)
1139 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1140 Widget_Data *wd = elm_widget_data_get(obj);
1141 if (!wd) return NULL;
1142 Eina_List *l = eina_list_last(wd->items);
1143 if (l) return l->data;
1148 * Get the selected item in the menu
1150 * @param obj The menu object
1151 * @return The selected item, or NULL if none
1155 EAPI const Elm_Menu_Item *
1156 elm_menu_selected_item_get(const Evas_Object * obj)
1158 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1159 Widget_Data *wd = elm_widget_data_get(obj);
1160 if (!wd) return NULL;
1162 Elm_Menu_Item *item;
1163 EINA_LIST_FOREACH(wd->items, l, item)
1165 if (item->selected) return item;