1 #include <Elementary.h>
4 typedef struct _Widget_Data Widget_Data;
5 typedef struct _Elm_Menu_Item Elm_Menu_Item;
10 Elm_Menu_Item *parent;
19 Evas_Object *hv, *bx, *location;
24 Eina_Bool separator : 1;
25 Eina_Bool selected : 1;
26 Eina_Bool object_item : 1;
31 Evas_Object *hv, *bx, *location, *parent, *obj;
33 Evas_Coord xloc, yloc;
36 static const char *widtype = NULL;
37 static void _del_hook(Evas_Object *obj);
38 static void _theme_hook(Evas_Object *obj);
39 static void _item_disable_hook(Elm_Object_Item *it);
40 static void _sizing_eval(Evas_Object *obj);
41 static void _submenu_sizing_eval(Elm_Menu_Item *parent);
42 static void _item_sizing_eval(Elm_Menu_Item *item);
43 static void _submenu_hide(Elm_Menu_Item *item);
44 static void _submenu_open(void *data, Evas_Object *obj, const char *emission, const char *source);
45 static void _parent_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
46 static void _parent_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
47 static void _menu_hide(void *data, Evas_Object *obj, void *event_info);
49 static const char SIG_CLICKED[] = "clicked";
51 static const Evas_Smart_Cb_Description _signals[] = {
58 _del_item(Elm_Menu_Item *item)
62 EINA_LIST_FREE(item->submenu.items, child)
65 if (item->label) eina_stringshare_del(item->label);
66 if (item->submenu.hv) evas_object_del(item->submenu.hv);
67 if (item->submenu.location) evas_object_del(item->submenu.location);
68 if (item->icon_str) eina_stringshare_del(item->icon_str);
69 elm_widget_item_free(item);
73 _del_pre_hook(Evas_Object *obj)
76 Widget_Data *wd = elm_widget_data_get(obj);
79 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE, _parent_resize, obj);
80 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL, _parent_del, wd);
82 EINA_LIST_FREE(wd->items, item)
85 if (wd->hv) evas_object_del(wd->hv);
86 if (wd->location) evas_object_del(wd->location);
90 _del_hook(Evas_Object *obj)
92 Widget_Data *wd = elm_widget_data_get(obj);
97 _theme_hook(Evas_Object *obj)
99 Eina_List *l, *_l, *_ll, *ll = NULL;
101 Widget_Data *wd = elm_widget_data_get(obj);
103 _elm_widget_mirrored_reload(obj);
104 ll = eina_list_append(ll, wd->items);
105 EINA_LIST_FOREACH(ll, _ll, l)
107 EINA_LIST_FOREACH(l, _l, item)
109 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(obj));
110 ll = eina_list_append(ll, item->submenu.items);
112 _elm_theme_object_set(obj, VIEW(item), "menu", "separator",
113 elm_widget_style_get(obj));
114 else if (item->submenu.bx)
116 _elm_theme_object_set
117 (obj, VIEW(item), "menu", "item_with_submenu",
118 elm_widget_style_get(obj));
119 elm_object_item_text_set((Elm_Object_Item *)item,
121 elm_menu_item_icon_name_set((Elm_Object_Item *)item,
126 _elm_theme_object_set(obj, VIEW(item), "menu", "item",
127 elm_widget_style_get(obj));
128 elm_object_item_text_set((Elm_Object_Item *)item,
130 elm_menu_item_icon_name_set((Elm_Object_Item *)item,
133 _item_disable_hook((Elm_Object_Item *)item);
134 edje_object_scale_set(VIEW(item), elm_widget_scale_get(obj) *
142 _item_text_set_hook(Elm_Object_Item *it,
148 if (part && strcmp(part, "default")) return;
150 item = (Elm_Menu_Item *)it;
152 eina_stringshare_replace(&item->label, label);
155 edje_object_signal_emit(VIEW(item), "elm,state,text,visible", "elm");
157 edje_object_signal_emit(VIEW(item), "elm,state,text,hidden", "elm");
159 edje_object_message_signal_process(VIEW(item));
160 edje_object_part_text_set(VIEW(item), "elm.text", label);
161 _sizing_eval(WIDGET(item));
165 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
167 if (part && strcmp(part, "default")) return NULL;
168 return ((Elm_Menu_Item *)it)->label;
172 _item_content_set_hook(Elm_Object_Item *it,
174 Evas_Object *content)
177 if (part && strcmp(part, "default")) return;
179 item = (Elm_Menu_Item *)it;
180 if (content == item->content) return;
182 if (item->content) evas_object_del(item->content);
184 item->content = content;
185 elm_widget_sub_object_add(WIDGET(item), item->content);
187 edje_object_part_swallow(VIEW(item), "elm.swallow.content", item->content);
188 _sizing_eval(WIDGET(item));
192 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
194 if (part && strcmp(part, "default")) return NULL;
195 return ((Elm_Menu_Item *)it)->content;
199 _item_disable_hook(Elm_Object_Item *it)
201 Elm_Menu_Item *item = (Elm_Menu_Item *)it;
203 if (elm_widget_item_disabled_get(item))
205 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
206 if (item->submenu.open) _submenu_hide(item);
209 edje_object_signal_emit(VIEW(item), "elm,state,enabled", "elm");
211 edje_object_message_signal_process(VIEW(item));
215 _sizing_eval(Evas_Object *obj)
219 Evas_Coord x_p, y_p, w_p, h_p, x2, y2, w2, h2, bx, by, bw, bh;
220 Widget_Data *wd = elm_widget_data_get(obj);
221 if ((!wd) || (!wd->parent)) return;
222 EINA_LIST_FOREACH(wd->items,l,item) _item_sizing_eval(item);
223 evas_object_geometry_get(wd->location, &x_p, &y_p, &w_p, &h_p);
224 evas_object_geometry_get(wd->parent, &x2, &y2, &w2, &h2);
225 evas_object_geometry_get(wd->bx, &bx, &by, &bw, &bh);
230 if (elm_widget_mirrored_get(obj))
233 if (x_p+bw > x2+w2) x_p -= x_p+bw - (x2+w2);
234 if (x_p < x2) x_p += x2 - x_p;
236 if (y_p+h_p+bh > y2+h2) y_p -= y_p+h_p+bh - (y2+h2);
237 if (y_p < y2) y_p += y2 - y_p;
240 evas_object_move(wd->location, x_p, y_p);
241 evas_object_resize(wd->location, bw, h_p);
242 evas_object_size_hint_min_set(wd->location, bw, h_p);
243 evas_object_size_hint_max_set(wd->location, bw, h_p);
244 elm_hover_target_set(wd->hv, wd->location);
246 EINA_LIST_FOREACH(wd->items,l,item)
248 if (item->submenu.open) _submenu_sizing_eval(item);
253 _submenu_sizing_eval(Elm_Menu_Item *parent)
257 Evas_Coord x_p, y_p, w_p, h_p, x2, y2, w2, h2, bx, by, bw, bh, px, py, pw, ph;
258 Widget_Data *wd = elm_widget_data_get(WIDGET(parent));
260 EINA_LIST_FOREACH(parent->submenu.items, l, item) _item_sizing_eval(item);
261 evas_object_geometry_get(parent->submenu.location, &x_p, &y_p, &w_p, &h_p);
262 evas_object_geometry_get(VIEW(parent), &x2, &y2, &w2, &h2);
263 evas_object_geometry_get(parent->submenu.bx, &bx, &by, &bw, &bh);
264 evas_object_geometry_get(wd->parent, &px, &py, &pw, &ph);
269 /* If it overflows on the right, adjust the x */
270 if ((x_p + bw > px + pw) || elm_widget_mirrored_get(WIDGET(parent)))
273 /* If it overflows on the left, adjust the x - usually only happens
274 * with an RTL interface */
278 /* If after all the adjustments it still overflows, fix it */
279 if (x_p + bw > px + pw)
283 y_p -= y_p+bh - (py+ph);
287 evas_object_move(parent->submenu.location, x_p, y_p);
288 evas_object_resize(parent->submenu.location, bw, h_p);
289 evas_object_size_hint_min_set(parent->submenu.location, bw, h_p);
290 evas_object_size_hint_max_set(parent->submenu.location, bw, h_p);
291 elm_hover_target_set(parent->submenu.hv, parent->submenu.location);
293 EINA_LIST_FOREACH(parent->submenu.items, l, item)
295 if (item->submenu.open)
296 _submenu_sizing_eval(item);
301 _item_sizing_eval(Elm_Menu_Item *item)
303 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
304 if (!item->separator)
305 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
306 edje_object_size_min_restricted_calc(VIEW(item), &minw, &minh, minw, minh);
307 if (!item->separator)
308 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
309 evas_object_size_hint_min_set(VIEW(item), minw, minh);
310 evas_object_size_hint_max_set(VIEW(item), maxw, maxh);
314 _menu_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
320 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
326 _parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
328 Widget_Data *wd = data;
329 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE, _parent_resize, wd->obj);
334 _item_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
336 Elm_Menu_Item *item = data;
337 if (item->submenu.open) _submenu_sizing_eval(item);
341 _hover_clicked_cb(void *data, Evas_Object *obj, void *event_info)
343 _menu_hide(data, obj, event_info);
344 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
348 _menu_hide(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
351 Elm_Menu_Item *item2;
352 Widget_Data *wd = elm_widget_data_get(data);
354 evas_object_hide(wd->hv);
355 evas_object_hide(data);
357 EINA_LIST_FOREACH(wd->items, l, item2)
359 if (item2->submenu.open) _submenu_hide(item2);
364 _submenu_hide(Elm_Menu_Item *item)
367 Elm_Menu_Item *item2;
368 evas_object_hide(item->submenu.hv);
369 item->submenu.open = EINA_FALSE;
370 EINA_LIST_FOREACH(item->submenu.items, l, item2)
372 if (item2->submenu.open) _submenu_hide(item2);
377 _menu_item_select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
379 Elm_Menu_Item *item = data;
380 if (item->submenu.items)
382 if (!item->submenu.open) _submenu_open(item, NULL, NULL, NULL);
383 else _submenu_hide(item);
386 _menu_hide(WIDGET(item), NULL, NULL);
388 if (item->func) item->func((void *)(item->base.data), WIDGET(item), item);
392 _menu_item_activate(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
395 Elm_Menu_Item *item2;
396 Elm_Menu_Item *item = data;
400 EINA_LIST_FOREACH(item->parent->submenu.items, l, item2)
403 elm_menu_item_selected_set((Elm_Object_Item *)item2, 0);
408 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
409 EINA_LIST_FOREACH(wd->items, l, item2)
412 elm_menu_item_selected_set((Elm_Object_Item *)item2, 0);
418 _menu_item_inactivate(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
420 Elm_Menu_Item *item = data;
422 if (item->submenu.open) _submenu_hide(item);
426 _submenu_open(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
428 Elm_Menu_Item *item = data;
429 item->submenu.open = EINA_TRUE;
430 evas_object_show(item->submenu.hv);
431 _submenu_sizing_eval(item);
435 _show(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
437 Widget_Data *wd = elm_widget_data_get(data);
439 evas_object_show(wd->hv);
443 _item_obj_create(Elm_Menu_Item *item)
445 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
447 VIEW(item) = edje_object_add(evas_object_evas_get(wd->bx));
448 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
449 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
450 evas_object_size_hint_fill_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
451 _elm_theme_object_set(WIDGET(item), VIEW(item), "menu", "item", elm_widget_style_get(WIDGET(item)));
452 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
453 _menu_item_select, item);
454 edje_object_signal_callback_add(VIEW(item), "elm,action,activate", "",
455 _menu_item_activate, item);
456 edje_object_signal_callback_add(VIEW(item), "elm,action,inactivate", "",
457 _menu_item_inactivate, item);
458 evas_object_show(VIEW(item));
462 _item_separator_obj_create(Elm_Menu_Item *item)
464 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
466 VIEW(item) = edje_object_add(evas_object_evas_get(wd->bx));
467 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
468 evas_object_size_hint_fill_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
469 _elm_theme_object_set(WIDGET(item), VIEW(item), "menu", "separator", elm_widget_style_get(WIDGET(item)));
470 edje_object_signal_callback_add(VIEW(item), "elm,action,activate", "",
471 _menu_item_activate, item);
472 evas_object_show(VIEW(item));
476 _item_submenu_obj_create(Elm_Menu_Item *item)
478 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
480 item->submenu.location = elm_icon_add(wd->bx);
481 item->submenu.hv = elm_hover_add(wd->bx);
482 elm_widget_mirrored_set(item->submenu.hv, EINA_FALSE);
483 elm_hover_target_set(item->submenu.hv, item->submenu.location);
484 elm_hover_parent_set(item->submenu.hv, wd->parent);
485 elm_object_style_set(item->submenu.hv, "submenu");
487 item->submenu.bx = elm_box_add(wd->bx);
488 elm_widget_mirrored_set(item->submenu.bx, EINA_FALSE);
489 evas_object_size_hint_weight_set(item->submenu.bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
490 evas_object_show(item->submenu.bx);
491 elm_object_part_content_set(item->submenu.hv, elm_hover_best_content_location_get(item->submenu.hv, ELM_HOVER_AXIS_VERTICAL), item->submenu.bx);
493 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
494 _elm_theme_object_set(WIDGET(item), VIEW(item), "menu", "item_with_submenu", elm_widget_style_get(WIDGET(item)));
495 elm_object_item_text_set((Elm_Object_Item *)item,
498 elm_menu_item_icon_name_set((Elm_Object_Item *)item,
500 edje_object_signal_callback_add(VIEW(item), "elm,action,open", "",
501 _submenu_open, item);
502 evas_object_event_callback_add(VIEW(item), EVAS_CALLBACK_MOVE, _item_move_resize, item);
503 evas_object_event_callback_add(VIEW(item), EVAS_CALLBACK_RESIZE, _item_move_resize, item);
505 evas_object_event_callback_add(item->submenu.bx, EVAS_CALLBACK_RESIZE, _menu_resize, WIDGET(item));
509 elm_menu_add(Evas_Object *parent)
515 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
517 ELM_SET_WIDTYPE(widtype, "menu");
518 elm_widget_type_set(obj, "menu");
519 elm_widget_sub_object_add(parent, obj);
520 elm_widget_data_set(obj, wd);
521 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
522 elm_widget_del_hook_set(obj, _del_hook);
523 elm_widget_theme_hook_set(obj, _theme_hook);
524 elm_widget_can_focus_set(obj, EINA_FALSE);
526 wd->location = elm_icon_add(obj);
530 wd->hv = elm_hover_add(obj);
531 elm_widget_mirrored_set(wd->hv, EINA_FALSE);
532 elm_hover_parent_set(wd->hv, parent);
533 elm_hover_target_set(wd->hv, wd->location);
534 elm_object_style_set(wd->hv, "menu");
535 evas_object_smart_callback_add(wd->hv, "clicked", _hover_clicked_cb, obj);
537 wd->bx = elm_box_add(obj);
538 elm_widget_mirrored_set(wd->bx, EINA_FALSE);
539 evas_object_size_hint_weight_set(wd->bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
540 evas_object_show(wd->bx);
541 elm_object_part_content_set(wd->hv, elm_hover_best_content_location_get(wd->hv, ELM_HOVER_AXIS_VERTICAL), wd->bx);
543 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_RESIZE, _parent_resize, wd->obj);
544 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_DEL, _parent_del, wd);
546 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _show, obj);
548 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _menu_resize, obj);
550 evas_object_smart_callbacks_descriptions_set(obj, _signals);
557 elm_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
559 Eina_List *l, *_l, *_ll, *ll = NULL;
561 ELM_CHECK_WIDTYPE(obj, widtype);
562 Widget_Data *wd = elm_widget_data_get(obj);
565 if (wd->parent == parent) return;
568 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE, _parent_resize, wd->obj);
569 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL, _parent_del, wd);
574 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_RESIZE, _parent_resize, wd->obj);
575 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_DEL, _parent_del, wd);
577 elm_hover_parent_set(wd->hv, parent);
579 ll = eina_list_append(ll, wd->items);
580 EINA_LIST_FOREACH(ll, _ll, l)
582 EINA_LIST_FOREACH(l, _l, item)
584 if (item->submenu.hv)
586 elm_hover_parent_set(item->submenu.hv, parent);
587 ll = eina_list_append(ll, item->submenu.items);
595 elm_menu_parent_get(const Evas_Object *obj)
597 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
598 Widget_Data *wd = elm_widget_data_get(obj);
599 if (!wd) return NULL;
604 elm_menu_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
606 ELM_CHECK_WIDTYPE(obj, widtype);
607 Widget_Data *wd = elm_widget_data_get(obj);
615 elm_menu_close(Evas_Object *obj)
617 ELM_CHECK_WIDTYPE(obj, widtype);
618 Widget_Data *wd = elm_widget_data_get(obj);
619 _menu_hide(obj, wd->hv, NULL);
623 elm_menu_item_object_get(const Elm_Object_Item *it)
625 return VIEW(((Elm_Menu_Item *)it));
629 _item_clone(Evas_Object *obj, Elm_Menu_Item *parent, Elm_Menu_Item *item)
631 Elm_Object_Item *new_item;
632 Elm_Menu_Item *subitem;
636 new_item = elm_menu_item_separator_add(obj, (Elm_Object_Item *) parent);
638 new_item = elm_menu_item_add(obj,
639 (Elm_Object_Item *) parent,
644 elm_object_item_disabled_set(new_item,
645 elm_widget_item_disabled_get(item));
647 EINA_LIST_FOREACH(item->submenu.items, iter, subitem)
648 _item_clone(obj, (Elm_Menu_Item *) new_item, subitem);
652 elm_menu_clone(Evas_Object *from_menu, Evas_Object *to_menu, Elm_Object_Item *parent)
654 ELM_CHECK_WIDTYPE(from_menu, widtype);
655 ELM_CHECK_WIDTYPE(to_menu, widtype);
656 Widget_Data *from_wd = elm_widget_data_get(from_menu);
660 if (!from_wd) return;
661 EINA_LIST_FOREACH(from_wd->items, iter, item)
662 _item_clone(to_menu, (Elm_Menu_Item *) parent, item);
666 _elm_menu_item_add_helper(Evas_Object *obj, Elm_Menu_Item *parent, Elm_Menu_Item *subitem, Widget_Data *wd)
670 if (!parent->submenu.bx) _item_submenu_obj_create(parent);
671 elm_box_pack_end(parent->submenu.bx, VIEW(subitem));
672 parent->submenu.items = eina_list_append(parent->submenu.items, subitem);
673 subitem->idx = eina_list_count(parent->submenu.items) - 1;
677 elm_box_pack_end(wd->bx, VIEW(subitem));
678 wd->items = eina_list_append(wd->items, subitem);
679 subitem->idx = eina_list_count(wd->items) - 1;
686 _item_del_pre_hook(Elm_Object_Item *it)
688 Elm_Menu_Item *item = (Elm_Menu_Item *)it;
689 Elm_Object_Item *_item;
691 EINA_LIST_FREE(item->submenu.items, _item) elm_object_item_del(_item);
692 if (item->label) eina_stringshare_del(item->label);
693 if (item->content) evas_object_del(item->content);
694 if (item->submenu.hv) evas_object_del(item->submenu.hv);
695 if (item->submenu.location) evas_object_del(item->submenu.location);
698 item->parent->submenu.items = eina_list_remove(item->parent->submenu.items, item);
701 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
702 wd->items = eina_list_remove(wd->items, item);
708 EAPI Elm_Object_Item *
709 elm_menu_item_add(Evas_Object *obj, Elm_Object_Item *parent, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
711 Elm_Menu_Item *subitem;
712 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
713 Widget_Data *wd = elm_widget_data_get(obj);
714 Evas_Object *icon_obj;
716 if (!wd) return NULL;
717 icon_obj = elm_icon_add(obj);
718 if (!icon_obj) return NULL;
719 subitem = elm_widget_item_new(obj, Elm_Menu_Item);
722 evas_object_del(icon_obj);
726 elm_widget_item_del_pre_hook_set(subitem, _item_del_pre_hook);
727 elm_widget_item_disable_hook_set(subitem, _item_disable_hook);
728 elm_widget_item_text_set_hook_set(subitem, _item_text_set_hook);
729 elm_widget_item_text_get_hook_set(subitem, _item_text_get_hook);
730 elm_widget_item_content_set_hook_set(subitem, _item_content_set_hook);
731 elm_widget_item_content_get_hook_set(subitem, _item_content_get_hook);
733 subitem->base.data = data;
734 subitem->func = func;
735 subitem->parent = (Elm_Menu_Item *) parent;
736 subitem->content = icon_obj;
738 _item_obj_create(subitem);
739 elm_object_item_text_set((Elm_Object_Item *) subitem, label);
741 elm_widget_sub_object_add(WIDGET(subitem), subitem->content);
742 edje_object_part_swallow(VIEW(subitem), "elm.swallow.content", subitem->content);
744 elm_menu_item_icon_name_set((Elm_Object_Item *) subitem, icon);
746 _elm_menu_item_add_helper(obj, (Elm_Menu_Item *) parent, subitem, wd);
748 return (Elm_Object_Item *) subitem;
752 elm_menu_item_index_get(const Elm_Object_Item *it)
754 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
755 return ((Elm_Menu_Item *)it)->idx;
759 elm_menu_item_icon_name_set(Elm_Object_Item *it, const char *icon)
761 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
762 EINA_SAFETY_ON_NULL_RETURN(icon);
764 Elm_Menu_Item *item = (Elm_Menu_Item *)it;
767 if ((item->icon_str) && (!strcmp(item->icon_str, icon))) return;
768 if ((snprintf(icon_tmp, sizeof(icon_tmp), "menu/%s", icon) > 0) &&
769 (elm_icon_standard_set(item->content, icon_tmp) ||
770 elm_icon_standard_set(item->content, icon)))
772 eina_stringshare_replace(&item->icon_str, icon);
773 edje_object_signal_emit(VIEW(item), "elm,state,icon,visible", "elm");
776 edje_object_signal_emit(VIEW(item), "elm,state,icon,hidden", "elm");
777 edje_object_message_signal_process(VIEW(item));
778 _sizing_eval(WIDGET(item));
781 EAPI Elm_Object_Item *
782 elm_menu_item_separator_add(Evas_Object *obj, Elm_Object_Item *parent)
784 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
785 Elm_Menu_Item *subitem;
786 Widget_Data *wd = elm_widget_data_get(obj);
787 Elm_Menu_Item *p_item = (Elm_Menu_Item *) parent;
788 if (!wd) return NULL;
789 /* don't add a separator as the first item */
790 if (!wd->items) return NULL;
791 /* don't allow adding more than one separator in a row */
792 if (p_item) subitem = eina_list_last(p_item->submenu.items)->data;
793 else subitem = eina_list_last(wd->items)->data;
794 if (subitem->separator) return NULL;
796 subitem = elm_widget_item_new(obj, Elm_Menu_Item);
797 if (!subitem) return NULL;
799 elm_widget_item_del_pre_hook_set(subitem, _item_del_pre_hook);
800 elm_widget_item_disable_hook_set(subitem, _item_disable_hook);
801 elm_widget_item_text_set_hook_set(subitem, _item_text_set_hook);
802 elm_widget_item_text_get_hook_set(subitem, _item_text_get_hook);
803 elm_widget_item_content_set_hook_set(subitem, _item_content_set_hook);
804 elm_widget_item_content_get_hook_set(subitem, _item_content_get_hook);
806 subitem->separator = EINA_TRUE;
807 _item_separator_obj_create(subitem);
810 elm_box_pack_end(wd->bx, VIEW(subitem));
811 wd->items = eina_list_append(wd->items, subitem);
815 if (!p_item->submenu.bx) _item_submenu_obj_create(p_item);
816 elm_box_pack_end(p_item->submenu.bx, VIEW(subitem));
817 p_item->submenu.items = eina_list_append(p_item->submenu.items,
821 return (Elm_Object_Item *) subitem;
825 elm_menu_item_icon_name_get(const Elm_Object_Item *it)
827 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
828 return ((Elm_Menu_Item *)it)->icon_str;
832 elm_menu_item_is_separator(Elm_Object_Item *it)
834 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
835 return ((Elm_Menu_Item *)it)->separator;
838 EAPI const Eina_List *
839 elm_menu_item_subitems_get(const Elm_Object_Item *it)
841 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
842 return ((Elm_Menu_Item *)it)->submenu.items;
845 EAPI const Eina_List *
846 elm_menu_items_get(const Evas_Object * obj)
848 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
849 Widget_Data *wd = elm_widget_data_get(obj);
854 elm_menu_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
856 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
857 Elm_Menu_Item *item = (Elm_Menu_Item *)it;
859 if (selected == item->selected) return;
860 item->selected = selected;
863 edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
864 _menu_item_activate(item, NULL, NULL, NULL);
868 edje_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
869 _menu_item_inactivate(item, NULL, NULL, NULL);
871 edje_object_message_signal_process(VIEW(item));
875 elm_menu_item_selected_get(const Elm_Object_Item *it)
877 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
878 return ((Elm_Menu_Item *)it)->selected;
881 EAPI Elm_Object_Item *
882 elm_menu_item_prev_get(const Elm_Object_Item *it)
884 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
885 Elm_Menu_Item *item = (Elm_Menu_Item *)it;
889 Eina_List *l = eina_list_data_find_list(item->parent->submenu.items,
891 l = eina_list_prev(l);
897 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
898 if (!wd || !wd->items) return NULL;
899 Eina_List *l = eina_list_data_find_list(wd->items, item);
900 l = eina_list_prev(l);
907 EAPI Elm_Object_Item *
908 elm_menu_item_next_get(const Elm_Object_Item *it)
910 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
911 Elm_Menu_Item *item = (Elm_Menu_Item *)it;
915 Eina_List *l = eina_list_data_find_list(item->parent->submenu.items,
917 l = eina_list_next(l);
923 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
924 if (!wd || !wd->items) return NULL;
925 Eina_List *l = eina_list_data_find_list(wd->items, item);
926 l = eina_list_next(l);
933 EAPI Elm_Object_Item *
934 elm_menu_first_item_get(const Evas_Object * obj)
936 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
937 Widget_Data *wd = elm_widget_data_get(obj);
938 if (!wd) return NULL;
939 if (wd->items) return wd->items->data;
943 EAPI Elm_Object_Item *
944 elm_menu_last_item_get(const Evas_Object * obj)
946 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
947 Widget_Data *wd = elm_widget_data_get(obj);
948 if (!wd) return NULL;
949 Eina_List *l = eina_list_last(wd->items);
950 if (l) return l->data;
954 EAPI Elm_Object_Item *
955 elm_menu_selected_item_get(const Evas_Object * obj)
957 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
958 Widget_Data *wd = elm_widget_data_get(obj);
959 if (!wd) return NULL;
962 EINA_LIST_FOREACH(wd->items, l, item)
964 if (item->selected) return ((Elm_Object_Item *)item);