1 #include <Elementary.h>
7 * A menu is a list of items displayed above the window. Each item can
8 * have a sub-menu. The menu object can be used to display a menu on right
9 * click, in a toolbar, anywhere.
11 * Signals that you can add callbacks for are:
13 * "clicked" - the user clicked the empty space in the menu to dismiss.
17 typedef struct _Widget_Data Widget_Data;
22 Elm_Menu_Item *parent;
29 Evas_Object *hv, *bx, *location;
34 Eina_Bool separator : 1;
35 Eina_Bool disabled : 1;
36 Eina_Bool selected : 1;
37 Eina_Bool object_item : 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 if (item->icon_str) 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.
604 * @return The edje object containing the swallowed content
609 elm_menu_item_object_get(const Elm_Menu_Item *item)
611 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
612 return item->base.view;
616 _item_clone(Evas_Object *obj, Elm_Menu_Item *parent, Elm_Menu_Item *item)
618 Elm_Menu_Item *new_item, *subitem;
622 new_item = elm_menu_item_separator_add(obj, parent);
624 new_item = elm_menu_item_add(obj, parent, item->icon_str, item->label, item->func, item->base.data);
625 elm_menu_item_disabled_set(new_item, item->disabled);
627 EINA_LIST_FOREACH(item->submenu.items, iter, subitem)
628 _item_clone(obj, new_item, subitem);
632 elm_menu_clone(Evas_Object *from_menu, Evas_Object *to_menu, Elm_Menu_Item *parent)
634 ELM_CHECK_WIDTYPE(from_menu, widtype);
635 ELM_CHECK_WIDTYPE(to_menu, widtype);
636 Widget_Data *from_wd = elm_widget_data_get(from_menu);
640 if (!from_wd) return;
641 EINA_LIST_FOREACH(from_wd->items, iter, item)
642 _item_clone(to_menu, parent, item);
646 * Add an item at the end
648 * @param obj The menu object.
649 * @param parent The parent menu item (optional)
650 * @param icon A icon display on the item. The icon will be destryed by the menu.
651 * @param label The label of the item.
652 * @param func Function called when the user select the item.
653 * @param data Data sent by the callback.
654 * @return Returns the new item.
659 elm_menu_item_add(Evas_Object *obj, Elm_Menu_Item *parent, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
661 Elm_Menu_Item *subitem;
662 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
663 Widget_Data *wd = elm_widget_data_get(obj);
664 Evas_Object *icon_obj;
666 if (!wd) return NULL;
667 icon_obj = elm_icon_add(obj);
668 if (!icon_obj) return NULL;
669 subitem = elm_widget_item_new(obj, Elm_Menu_Item);
672 evas_object_del(icon_obj);
675 subitem->base.data = data;
676 subitem->func = func;
677 subitem->parent = parent;
678 subitem->icon = icon_obj;
680 _item_obj_create(subitem);
681 elm_menu_item_label_set(subitem, label);
683 elm_widget_sub_object_add(subitem->base.widget, subitem->icon);
684 edje_object_part_swallow(subitem->base.view, "elm.swallow.content", subitem->icon);
685 if (icon) elm_menu_item_icon_set(subitem, icon);
689 if (!parent->submenu.bx) _item_submenu_obj_create(parent);
690 elm_box_pack_end(parent->submenu.bx, subitem->base.view);
691 parent->submenu.items = eina_list_append(parent->submenu.items, subitem);
695 elm_box_pack_end(wd->bx, subitem->base.view);
696 wd->items = eina_list_append(wd->items, subitem);
704 * Add an object swallowed in an item at the end
706 * @param obj The menu object.
707 * @param parent The parent menu item (optional)
708 * @param subobj The object to swallow
709 * @param func Function called when the user select the item.
710 * @param data Data sent by the callback.
711 * @return Returns the new item.
716 elm_menu_item_add_object(Evas_Object *obj, Elm_Menu_Item *parent, Evas_Object *subobj, Evas_Smart_Cb func, const void *data)
718 Elm_Menu_Item *subitem;
719 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
720 Widget_Data *wd = elm_widget_data_get(obj);
722 if (!wd) return NULL;
723 subitem = elm_widget_item_new(obj, Elm_Menu_Item);
724 if (!subitem) return NULL;
726 subitem->base.data = data;
727 subitem->func = func;
728 subitem->parent = parent;
729 subitem->object_item = EINA_TRUE;
730 subitem->icon = subobj;
732 _item_obj_create(subitem);
734 elm_widget_sub_object_add(subitem->base.widget, subitem->icon);
735 edje_object_part_swallow(subitem->base.view, "elm.swallow.content", subobj);
736 _sizing_eval(subitem->base.widget);
740 if (!parent->submenu.bx) _item_submenu_obj_create(parent);
741 elm_box_pack_end(parent->submenu.bx, subitem->base.view);
742 parent->submenu.items = eina_list_append(parent->submenu.items, subitem);
746 elm_box_pack_end(wd->bx, subitem->base.view);
747 wd->items = eina_list_append(wd->items, subitem);
755 * Set the label of a menu item
757 * @param item The menu item object.
758 * @param label The label to set for @p item
763 elm_menu_item_label_set(Elm_Menu_Item *item, const char *label)
765 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
766 eina_stringshare_replace(&item->label, label);
769 edje_object_signal_emit(item->base.view, "elm,state,text,visible", "elm");
771 edje_object_signal_emit(item->base.view, "elm,state,text,hidden", "elm");
773 edje_object_message_signal_process(item->base.view);
774 edje_object_part_text_set(item->base.view, "elm.text", label);
775 _sizing_eval(item->base.widget);
779 * Get the label of a menu item
781 * @param item The menu item object.
782 * @return The label of @p item
787 elm_menu_item_label_get(const Elm_Menu_Item *item)
789 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
794 * Set the icon of a menu item
796 * Once the icon object is set, a previously set one will be deleted.
798 * @param item The menu item object.
799 * @param icon The icon object to set for @p item
804 elm_menu_item_icon_set(Elm_Menu_Item *item, const char *icon)
807 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
808 EINA_SAFETY_ON_NULL_RETURN(icon);
810 if ((item->icon_str) && (!strcmp(item->icon_str, icon))) return;
811 if ((snprintf(icon_tmp, sizeof(icon_tmp), "menu/%s", icon) > 0) &&
812 (elm_icon_standard_set(item->icon, icon_tmp)))
814 eina_stringshare_replace(&item->icon_str, icon);
815 edje_object_signal_emit(item->base.view, "elm,state,icon,visible", "elm");
818 edje_object_signal_emit(item->base.view, "elm,state,icon,hidden", "elm");
819 edje_object_message_signal_process(item->base.view);
820 _sizing_eval(item->base.widget);
824 * Set the disabled state of @p item.
826 * @param item The menu item object.
827 * @param disabled The enabled/disabled state of the item
832 elm_menu_item_disabled_set(Elm_Menu_Item *item, Eina_Bool disabled)
834 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
835 if (disabled == item->disabled) return;
836 item->disabled = !!disabled;
839 edje_object_signal_emit(item->base.view, "elm,state,disabled", "elm");
840 if (item->submenu.open) _submenu_hide(item);
843 edje_object_signal_emit(item->base.view, "elm,state,enabled", "elm");
844 edje_object_message_signal_process(item->base.view);
848 * Get the disabled state of @p item.
850 * @param item The menu item object.
851 * @return The enabled/disabled state of the item
856 elm_menu_item_disabled_get(const Elm_Menu_Item *item)
858 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
859 return item->disabled;
863 * Add a separator item to menu @p obj under @p parent.
865 * @param obj The menu object
866 * @param parent The item to add the separator under
868 * @return The created item or NULL on failure
873 elm_menu_item_separator_add(Evas_Object *obj, Elm_Menu_Item *parent)
875 Elm_Menu_Item *subitem;
876 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
877 Widget_Data *wd = elm_widget_data_get(obj);
878 if (!wd) return NULL;
879 /* don't add a separator as the first item */
880 if (!wd->items) return NULL;
881 /* don't allow adding more than one separator in a row */
882 if (parent) subitem = eina_list_last(parent->submenu.items)->data;
883 else subitem = eina_list_last(wd->items)->data;
884 if (subitem->separator) return NULL;
886 subitem = elm_widget_item_new(obj, Elm_Menu_Item);
887 if (!subitem) return NULL;
888 subitem->base.widget = obj;
889 subitem->separator = 1;
890 _item_separator_obj_create(subitem);
893 elm_box_pack_end(wd->bx, subitem->base.view);
894 wd->items = eina_list_append(wd->items, subitem);
898 if (!parent->submenu.bx) _item_submenu_obj_create(parent);
899 elm_box_pack_end(parent->submenu.bx, subitem->base.view);
900 parent->submenu.items = eina_list_append(parent->submenu.items, subitem);
907 * Get the icon object from a menu item
909 * @param item The menu item object
910 * @return The icon object or NULL if there's no icon
911 * @note If @p item was added with elm_menu_item_add_object, this
912 * function will return the object passed.
916 EAPI const Evas_Object *
917 elm_menu_item_object_icon_get(const Elm_Menu_Item *item)
919 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
920 return (const Evas_Object *)item->icon;
924 * Get the string representation from the icon of a menu item
926 * @param item The menu item object.
927 * @return The string representation of @p item's icon or NULL
932 elm_menu_item_icon_get(const Elm_Menu_Item *item)
934 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
935 return item->icon_str;
939 * Returns whether @p item is a separator.
941 * @param item The item to check
942 * @return If true, @p item is a separator
947 elm_menu_item_is_separator(Elm_Menu_Item *item)
949 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
950 return item->separator;
954 * Deletes an item from the menu.
956 * @param item The item to delete.
961 elm_menu_item_del(Elm_Menu_Item *item)
963 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
964 Elm_Menu_Item *_item;
966 elm_widget_item_pre_notify_del(item);
968 EINA_LIST_FREE(item->submenu.items, _item) elm_menu_item_del(_item);
969 if (item->label) eina_stringshare_del(item->label);
970 if (item->icon) evas_object_del(item->icon);
971 if (item->submenu.hv) evas_object_del(item->submenu.hv);
972 if (item->submenu.location) evas_object_del(item->submenu.location);
975 item->parent->submenu.items = eina_list_remove(item->parent->submenu.items, item);
978 Widget_Data *wd = elm_widget_data_get(item->base.widget);
979 wd->items = eina_list_remove(wd->items, item);
982 elm_widget_item_del(item);
986 * Set the function called when a menu item is freed.
988 * @param item The item to set the callback on
989 * @param func The function called
994 elm_menu_item_del_cb_set(Elm_Menu_Item *item, Evas_Smart_Cb func)
996 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
997 elm_widget_item_del_cb_set(item, func);
1001 * Returns the data associated with menu item @p item.
1003 * @param item The item
1004 * @return The data associated with @p item
1009 elm_menu_item_data_get(const Elm_Menu_Item *item)
1011 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1012 return elm_widget_item_data_get(item);
1016 * Sets the data to be associated with menu item @p item.
1018 * @param item The item
1019 * @param data The data to be associated with @p item
1024 elm_menu_item_data_set(Elm_Menu_Item *item, const void *data)
1026 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1027 elm_widget_item_data_set(item, data);
1031 * Returns a list of @p item's subitems.
1033 * @param item The item
1034 * @return An Eina_List* of @p item's subitems
1038 EAPI const Eina_List *
1039 elm_menu_item_subitems_get(const Elm_Menu_Item *item)
1041 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL);
1042 return item->submenu.items;
1046 * Returns a list of @p item's items.
1048 * @param obj The menu object
1049 * @return An Eina_List* of @p item's items
1053 EAPI const Eina_List *
1054 elm_menu_items_get(const Evas_Object * obj)
1056 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1057 Widget_Data *wd = elm_widget_data_get(obj);
1062 * Set the selected state of @p item.
1064 * @param item The menu item object.
1065 * @param selected The selected/unselected state of the item
1070 elm_menu_item_selected_set(Elm_Menu_Item *item, Eina_Bool selected)
1072 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item);
1073 if (selected == item->selected) return;
1074 item->selected = selected;
1077 edje_object_signal_emit(item->base.view, "elm,state,selected", "elm");
1078 _menu_item_activate(item, NULL, NULL, NULL);
1082 edje_object_signal_emit(item->base.view, "elm,state,unselected", "elm");
1083 _menu_item_inactivate(item, NULL, NULL, NULL);
1085 edje_object_message_signal_process(item->base.view);
1089 * Get the selected state of @p item.
1091 * @param item The menu item object.
1092 * @return The selected/unselected state of the item
1097 elm_menu_item_selected_get(const Elm_Menu_Item *item)
1099 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE);
1100 return item->selected;
1104 * Get the previous item in the menu.
1106 * @param item The menu item object.
1107 * @return The item before it, or NULL if none
1111 EAPI const Elm_Menu_Item *
1112 elm_menu_item_prev_get(const Elm_Menu_Item *it)
1114 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
1117 Eina_List *l = eina_list_data_find_list(it->parent->submenu.items, it);
1118 l = eina_list_prev(l);
1119 if (!l) return NULL;
1124 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1125 if (!wd | !wd->items) return NULL;
1126 Eina_List *l = eina_list_data_find_list(wd->items, it);
1127 l = eina_list_prev(l);
1128 if (!l) return NULL;
1135 * Get the next item in the menu.
1137 * @param item The menu item object.
1138 * @return The item after it, or NULL if none
1142 EAPI const Elm_Menu_Item *
1143 elm_menu_item_next_get(const Elm_Menu_Item *it)
1145 ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it, NULL);
1148 Eina_List *l = eina_list_data_find_list(it->parent->submenu.items, it);
1149 l = eina_list_next(l);
1150 if (!l) return NULL;
1155 Widget_Data *wd = elm_widget_data_get(it->base.widget);
1156 if (!wd | !wd->items) return NULL;
1157 Eina_List *l = eina_list_data_find_list(wd->items, it);
1158 l = eina_list_next(l);
1159 if (!l) return NULL;
1166 * Get the first item in the menu
1168 * @param obj The menu object
1169 * @return The first item, or NULL if none
1173 EAPI const Elm_Menu_Item *
1174 elm_menu_first_item_get(const Evas_Object * obj)
1176 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1177 Widget_Data *wd = elm_widget_data_get(obj);
1178 if (!wd) return NULL;
1179 if (wd->items) return wd->items->data;
1184 * Get the last item in the menu
1186 * @param obj The menu object
1187 * @return The last item, or NULL if none
1191 EAPI const Elm_Menu_Item *
1192 elm_menu_last_item_get(const Evas_Object * obj)
1194 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1195 Widget_Data *wd = elm_widget_data_get(obj);
1196 if (!wd) return NULL;
1197 Eina_List *l = eina_list_last(wd->items);
1198 if (l) return l->data;
1203 * Get the selected item in the menu
1205 * @param obj The menu object
1206 * @return The selected item, or NULL if none
1210 EAPI const Elm_Menu_Item *
1211 elm_menu_selected_item_get(const Evas_Object * obj)
1213 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1214 Widget_Data *wd = elm_widget_data_get(obj);
1215 if (!wd) return NULL;
1217 Elm_Menu_Item *item;
1218 EINA_LIST_FOREACH(wd->items, l, item)
1220 if (item->selected) return item;