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;
18 Evas_Object *hv, *bx, *location;
23 Eina_Bool separator : 1;
24 Eina_Bool selected : 1;
25 Eina_Bool object_item : 1;
30 Evas_Object *hv, *bx, *location, *parent, *obj;
32 Evas_Coord xloc, yloc;
35 static const char *widtype = NULL;
36 static void _del_hook(Evas_Object *obj);
37 static void _theme_hook(Evas_Object *obj);
38 static void _item_disable_hook(Elm_Object_Item *it);
39 static void _sizing_eval(Evas_Object *obj);
40 static void _submenu_sizing_eval(Elm_Menu_Item *parent);
41 static void _item_sizing_eval(Elm_Menu_Item *item);
42 static void _submenu_hide(Elm_Menu_Item *item);
43 static void _submenu_open(void *data, Evas_Object *obj, const char *emission, const char *source);
44 static void _parent_resize(void *data, Evas *e, Evas_Object *obj, void *event_info);
45 static void _parent_del(void *data, Evas *e, Evas_Object *obj, void *event_info);
46 static void _menu_hide(void *data, Evas_Object *obj, void *event_info);
48 static const char SIG_CLICKED[] = "clicked";
50 static const Evas_Smart_Cb_Description _signals[] = {
57 _del_item(Elm_Menu_Item *item)
61 EINA_LIST_FREE(item->submenu.items, child)
64 if (item->label) eina_stringshare_del(item->label);
65 if (item->submenu.hv) evas_object_del(item->submenu.hv);
66 if (item->submenu.location) evas_object_del(item->submenu.location);
67 if (item->icon_str) eina_stringshare_del(item->icon_str);
68 elm_widget_item_free(item);
72 _del_pre_hook(Evas_Object *obj)
75 Widget_Data *wd = elm_widget_data_get(obj);
78 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE, _parent_resize, obj);
79 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL, _parent_del, wd);
81 EINA_LIST_FREE(wd->items, item)
84 if (wd->hv) evas_object_del(wd->hv);
85 if (wd->location) evas_object_del(wd->location);
89 _del_hook(Evas_Object *obj)
91 Widget_Data *wd = elm_widget_data_get(obj);
96 _theme_hook(Evas_Object *obj)
98 Eina_List *l, *_l, *_ll, *ll = NULL;
100 Widget_Data *wd = elm_widget_data_get(obj);
102 _elm_widget_mirrored_reload(obj);
103 ll = eina_list_append(ll, wd->items);
104 EINA_LIST_FOREACH(ll, _ll, l)
106 EINA_LIST_FOREACH(l, _l, item)
108 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(obj));
109 ll = eina_list_append(ll, item->submenu.items);
111 _elm_theme_object_set(obj, VIEW(item), "menu", "separator",
112 elm_widget_style_get(obj));
113 else if (item->submenu.bx)
115 _elm_theme_object_set
116 (obj, VIEW(item), "menu", "item_with_submenu",
117 elm_widget_style_get(obj));
118 elm_object_item_text_set((Elm_Object_Item *) item,
120 elm_menu_item_object_icon_name_set((Elm_Object_Item *) item,
125 _elm_theme_object_set(obj, VIEW(item), "menu", "item",
126 elm_widget_style_get(obj));
127 elm_object_item_text_set((Elm_Object_Item *) item,
129 elm_menu_item_object_icon_name_set((Elm_Object_Item *) item,
132 _item_disable_hook((Elm_Object_Item *) item);
133 edje_object_scale_set(VIEW(item), elm_widget_scale_get(obj) *
141 _item_text_set_hook(Elm_Object_Item *it,
147 if (part && strcmp(part, "default")) return;
149 item = (Elm_Menu_Item *) it;
151 eina_stringshare_replace(&item->label, label);
154 edje_object_signal_emit(VIEW(item), "elm,state,text,visible", "elm");
156 edje_object_signal_emit(VIEW(item), "elm,state,text,hidden", "elm");
158 edje_object_message_signal_process(VIEW(item));
159 edje_object_part_text_set(VIEW(item), "elm.text", label);
160 _sizing_eval(WIDGET(item));
164 _item_text_get_hook(const Elm_Object_Item *it, const char *part)
166 if (part && strcmp(part, "default")) return NULL;
167 return ((Elm_Menu_Item *) it)->label;
171 _item_content_set_hook(Elm_Object_Item *it,
173 Evas_Object *content)
177 if (part && strcmp(part, "default")) return;
179 item = (Elm_Menu_Item *) it;
183 elm_widget_sub_object_del(WIDGET(item), item->content);
184 evas_object_del(item->content);
187 item->content = content;
189 elm_widget_sub_object_add(WIDGET(item), item->content);
190 edje_object_part_swallow(VIEW(item), "elm.swallow.content", item->content);
191 _sizing_eval(WIDGET(item));
195 _item_content_get_hook(const Elm_Object_Item *it, const char *part)
197 if (part && strcmp(part, "default")) return NULL;
198 return ((Elm_Menu_Item *) it)->content;
202 _item_disable_hook(Elm_Object_Item *it)
204 Elm_Menu_Item *item = (Elm_Menu_Item *) it;
206 if (elm_widget_item_disabled_get(item))
208 edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm");
209 if (item->submenu.open) _submenu_hide(item);
212 edje_object_signal_emit(VIEW(item), "elm,state,enabled", "elm");
214 edje_object_message_signal_process(VIEW(item));
218 _sizing_eval(Evas_Object *obj)
222 Evas_Coord x_p, y_p, w_p, h_p, x2, y2, w2, h2, bx, by, bw, bh;
223 Widget_Data *wd = elm_widget_data_get(obj);
224 if ((!wd) || (!wd->parent)) return;
225 EINA_LIST_FOREACH(wd->items,l,item) _item_sizing_eval(item);
226 evas_object_geometry_get(wd->location, &x_p, &y_p, &w_p, &h_p);
227 evas_object_geometry_get(wd->parent, &x2, &y2, &w2, &h2);
228 evas_object_geometry_get(wd->bx, &bx, &by, &bw, &bh);
233 if (elm_widget_mirrored_get(obj))
236 if (x_p+bw > x2+w2) x_p -= x_p+bw - (x2+w2);
237 if (x_p < x2) x_p += x2 - x_p;
239 if (y_p+h_p+bh > y2+h2) y_p -= y_p+h_p+bh - (y2+h2);
240 if (y_p < y2) y_p += y2 - y_p;
243 evas_object_move(wd->location, x_p, y_p);
244 evas_object_resize(wd->location, bw, h_p);
245 evas_object_size_hint_min_set(wd->location, bw, h_p);
246 evas_object_size_hint_max_set(wd->location, bw, h_p);
247 elm_hover_target_set(wd->hv, wd->location);
249 EINA_LIST_FOREACH(wd->items,l,item)
251 if (item->submenu.open) _submenu_sizing_eval(item);
256 _submenu_sizing_eval(Elm_Menu_Item *parent)
260 Evas_Coord x_p, y_p, w_p, h_p, x2, y2, w2, h2, bx, by, bw, bh, px, py, pw, ph;
261 Widget_Data *wd = elm_widget_data_get(WIDGET(parent));
263 EINA_LIST_FOREACH(parent->submenu.items, l, item) _item_sizing_eval(item);
264 evas_object_geometry_get(parent->submenu.location, &x_p, &y_p, &w_p, &h_p);
265 evas_object_geometry_get(VIEW(parent), &x2, &y2, &w2, &h2);
266 evas_object_geometry_get(parent->submenu.bx, &bx, &by, &bw, &bh);
267 evas_object_geometry_get(wd->parent, &px, &py, &pw, &ph);
272 /* If it overflows on the right, adjust the x */
273 if ((x_p + bw > px + pw) || elm_widget_mirrored_get(WIDGET(parent)))
276 /* If it overflows on the left, adjust the x - usually only happens
277 * with an RTL interface */
281 /* If after all the adjustments it still overflows, fix it */
282 if (x_p + bw > px + pw)
286 y_p -= y_p+bh - (py+ph);
290 evas_object_move(parent->submenu.location, x_p, y_p);
291 evas_object_resize(parent->submenu.location, bw, h_p);
292 evas_object_size_hint_min_set(parent->submenu.location, bw, h_p);
293 evas_object_size_hint_max_set(parent->submenu.location, bw, h_p);
294 elm_hover_target_set(parent->submenu.hv, parent->submenu.location);
296 EINA_LIST_FOREACH(parent->submenu.items, l, item)
298 if (item->submenu.open)
299 _submenu_sizing_eval(item);
304 _item_sizing_eval(Elm_Menu_Item *item)
306 Evas_Coord minw = -1, minh = -1, maxw = -1, maxh = -1;
307 if (!item->separator)
308 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
309 edje_object_size_min_restricted_calc(VIEW(item), &minw, &minh, minw, minh);
310 if (!item->separator)
311 elm_coords_finger_size_adjust(1, &minw, 1, &minh);
312 evas_object_size_hint_min_set(VIEW(item), minw, minh);
313 evas_object_size_hint_max_set(VIEW(item), maxw, maxh);
317 _menu_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
323 _parent_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
329 _parent_del(void *data, Evas *e __UNUSED__, Evas_Object *obj, void *event_info __UNUSED__)
331 Widget_Data *wd = data;
332 evas_object_event_callback_del_full(obj, EVAS_CALLBACK_RESIZE, _parent_resize, wd->obj);
337 _item_move_resize(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
339 Elm_Menu_Item *item = data;
340 if (item->submenu.open) _submenu_sizing_eval(item);
344 _hover_clicked_cb(void *data, Evas_Object *obj, void *event_info)
346 _menu_hide(data, obj, event_info);
347 evas_object_smart_callback_call(data, SIG_CLICKED, NULL);
351 _menu_hide(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
354 Elm_Menu_Item *item2;
355 Widget_Data *wd = elm_widget_data_get(data);
357 evas_object_hide(wd->hv);
358 evas_object_hide(data);
360 EINA_LIST_FOREACH(wd->items, l, item2)
362 if (item2->submenu.open) _submenu_hide(item2);
367 _submenu_hide(Elm_Menu_Item *item)
370 Elm_Menu_Item *item2;
371 evas_object_hide(item->submenu.hv);
372 item->submenu.open = EINA_FALSE;
373 EINA_LIST_FOREACH(item->submenu.items, l, item2)
375 if (item2->submenu.open) _submenu_hide(item2);
380 _menu_item_select(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
382 Elm_Menu_Item *item = data;
383 if (item->submenu.items)
385 if (!item->submenu.open) _submenu_open(item, NULL, NULL, NULL);
386 else _submenu_hide(item);
389 _menu_hide(WIDGET(item), NULL, NULL);
391 if (item->func) item->func((void *)(item->base.data), WIDGET(item), item);
395 _menu_item_activate(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
398 Elm_Menu_Item *item2;
399 Elm_Menu_Item *item = data;
403 EINA_LIST_FOREACH(item->parent->submenu.items, l, item2)
406 elm_menu_item_selected_set((Elm_Object_Item *) item2, 0);
411 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
412 EINA_LIST_FOREACH(wd->items, l, item2)
415 elm_menu_item_selected_set((Elm_Object_Item *) item2, 0);
421 _menu_item_inactivate(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
423 Elm_Menu_Item *item = data;
425 if (item->submenu.open) _submenu_hide(item);
429 _submenu_open(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__)
431 Elm_Menu_Item *item = data;
432 item->submenu.open = EINA_TRUE;
433 evas_object_show(item->submenu.hv);
434 _sizing_eval(WIDGET(item));
438 _show(void *data, Evas *e __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__)
440 Widget_Data *wd = elm_widget_data_get(data);
442 evas_object_show(wd->hv);
446 _item_obj_create(Elm_Menu_Item *item)
448 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
450 VIEW(item) = edje_object_add(evas_object_evas_get(wd->bx));
451 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
452 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
453 evas_object_size_hint_fill_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
454 _elm_theme_object_set(WIDGET(item), VIEW(item), "menu", "item", elm_widget_style_get(WIDGET(item)));
455 edje_object_signal_callback_add(VIEW(item), "elm,action,click", "",
456 _menu_item_select, item);
457 edje_object_signal_callback_add(VIEW(item), "elm,action,activate", "",
458 _menu_item_activate, item);
459 edje_object_signal_callback_add(VIEW(item), "elm,action,inactivate", "",
460 _menu_item_inactivate, item);
461 evas_object_show(VIEW(item));
465 _item_separator_obj_create(Elm_Menu_Item *item)
467 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
469 VIEW(item) = edje_object_add(evas_object_evas_get(wd->bx));
470 evas_object_size_hint_weight_set(VIEW(item), EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
471 evas_object_size_hint_fill_set(VIEW(item), EVAS_HINT_FILL, EVAS_HINT_FILL);
472 _elm_theme_object_set(WIDGET(item), VIEW(item), "menu", "separator", elm_widget_style_get(WIDGET(item)));
473 edje_object_signal_callback_add(VIEW(item), "elm,action,activate", "",
474 _menu_item_activate, item);
475 evas_object_show(VIEW(item));
479 _item_submenu_obj_create(Elm_Menu_Item *item)
481 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
483 item->submenu.location = elm_icon_add(wd->bx);
484 item->submenu.hv = elm_hover_add(wd->bx);
485 elm_widget_mirrored_set(item->submenu.hv, EINA_FALSE);
486 elm_hover_target_set(item->submenu.hv, item->submenu.location);
487 elm_hover_parent_set(item->submenu.hv, wd->parent);
488 elm_object_style_set(item->submenu.hv, "submenu");
490 item->submenu.bx = elm_box_add(wd->bx);
491 elm_widget_mirrored_set(item->submenu.bx, EINA_FALSE);
492 evas_object_size_hint_weight_set(item->submenu.bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
493 evas_object_show(item->submenu.bx);
494 elm_object_part_content_set(item->submenu.hv, elm_hover_best_content_location_get(item->submenu.hv, ELM_HOVER_AXIS_VERTICAL), item->submenu.bx);
496 edje_object_mirrored_set(VIEW(item), elm_widget_mirrored_get(WIDGET(item)));
497 _elm_theme_object_set(WIDGET(item), VIEW(item), "menu", "item_with_submenu", elm_widget_style_get(WIDGET(item)));
498 elm_object_item_text_set((Elm_Object_Item *) item,
501 elm_menu_item_object_icon_name_set((Elm_Object_Item *) item,
503 edje_object_signal_callback_add(VIEW(item), "elm,action,open", "",
504 _submenu_open, item);
505 evas_object_event_callback_add(VIEW(item), EVAS_CALLBACK_MOVE, _item_move_resize, item);
506 evas_object_event_callback_add(VIEW(item), EVAS_CALLBACK_RESIZE, _item_move_resize, item);
508 evas_object_event_callback_add(item->submenu.bx, EVAS_CALLBACK_RESIZE, _menu_resize, WIDGET(item));
512 elm_menu_add(Evas_Object *parent)
518 ELM_WIDGET_STANDARD_SETUP(wd, Widget_Data, parent, e, obj, NULL);
520 ELM_SET_WIDTYPE(widtype, "menu");
521 elm_widget_type_set(obj, "menu");
522 elm_widget_sub_object_add(parent, obj);
523 elm_widget_data_set(obj, wd);
524 elm_widget_del_pre_hook_set(obj, _del_pre_hook);
525 elm_widget_del_hook_set(obj, _del_hook);
526 elm_widget_theme_hook_set(obj, _theme_hook);
527 elm_widget_can_focus_set(obj, EINA_FALSE);
529 wd->location = elm_icon_add(obj);
533 wd->hv = elm_hover_add(obj);
534 elm_widget_mirrored_set(wd->hv, EINA_FALSE);
535 elm_hover_parent_set(wd->hv, parent);
536 elm_hover_target_set(wd->hv, wd->location);
537 elm_object_style_set(wd->hv, "menu");
538 evas_object_smart_callback_add(wd->hv, "clicked", _hover_clicked_cb, obj);
540 wd->bx = elm_box_add(obj);
541 elm_widget_mirrored_set(wd->bx, EINA_FALSE);
542 evas_object_size_hint_weight_set(wd->bx, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
543 evas_object_show(wd->bx);
544 elm_object_part_content_set(wd->hv, elm_hover_best_content_location_get(wd->hv, ELM_HOVER_AXIS_VERTICAL), wd->bx);
546 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_RESIZE, _parent_resize, wd->obj);
547 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_DEL, _parent_del, wd);
549 evas_object_event_callback_add(obj, EVAS_CALLBACK_SHOW, _show, obj);
551 evas_object_event_callback_add(wd->bx, EVAS_CALLBACK_RESIZE, _menu_resize, obj);
553 evas_object_smart_callbacks_descriptions_set(obj, _signals);
560 elm_menu_parent_set(Evas_Object *obj, Evas_Object *parent)
562 Eina_List *l, *_l, *_ll, *ll = NULL;
564 ELM_CHECK_WIDTYPE(obj, widtype);
565 Widget_Data *wd = elm_widget_data_get(obj);
568 if (wd->parent == parent) return;
571 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_RESIZE, _parent_resize, wd->obj);
572 evas_object_event_callback_del_full(wd->parent, EVAS_CALLBACK_DEL, _parent_del, wd);
577 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_RESIZE, _parent_resize, wd->obj);
578 evas_object_event_callback_add(wd->parent, EVAS_CALLBACK_DEL, _parent_del, wd);
580 elm_hover_parent_set(wd->hv, parent);
582 ll = eina_list_append(ll, wd->items);
583 EINA_LIST_FOREACH(ll, _ll, l)
585 EINA_LIST_FOREACH(l, _l, item)
587 if (item->submenu.hv)
589 elm_hover_parent_set(item->submenu.hv, parent);
590 ll = eina_list_append(ll, item->submenu.items);
598 elm_menu_parent_get(const Evas_Object *obj)
600 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
601 Widget_Data *wd = elm_widget_data_get(obj);
602 if (!wd) return NULL;
607 elm_menu_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
609 ELM_CHECK_WIDTYPE(obj, widtype);
610 Widget_Data *wd = elm_widget_data_get(obj);
618 elm_menu_close(Evas_Object *obj)
620 ELM_CHECK_WIDTYPE(obj, widtype);
621 Widget_Data *wd = elm_widget_data_get(obj);
622 _menu_hide(obj, wd->hv, NULL);
626 elm_menu_item_object_get(const Elm_Object_Item *it)
628 return VIEW(((Elm_Menu_Item *) it));
632 _item_clone(Evas_Object *obj, Elm_Menu_Item *parent, Elm_Menu_Item *item)
634 Elm_Object_Item *new_item;
635 Elm_Menu_Item *subitem;
639 new_item = elm_menu_item_separator_add(obj, (Elm_Object_Item *) parent);
641 new_item = elm_menu_item_add(obj,
642 (Elm_Object_Item *) parent,
647 elm_object_item_disabled_set(new_item,
648 elm_widget_item_disabled_get(item));
650 EINA_LIST_FOREACH(item->submenu.items, iter, subitem)
651 _item_clone(obj, (Elm_Menu_Item *) new_item, subitem);
655 elm_menu_clone(Evas_Object *from_menu, Evas_Object *to_menu, Elm_Object_Item *parent)
657 ELM_CHECK_WIDTYPE(from_menu, widtype);
658 ELM_CHECK_WIDTYPE(to_menu, widtype);
659 Widget_Data *from_wd = elm_widget_data_get(from_menu);
663 if (!from_wd) return;
664 EINA_LIST_FOREACH(from_wd->items, iter, item)
665 _item_clone(to_menu, (Elm_Menu_Item *) parent, item);
669 _elm_menu_item_add_helper(Evas_Object *obj, Elm_Menu_Item *parent, Elm_Menu_Item *subitem, Widget_Data *wd)
673 if (!parent->submenu.bx) _item_submenu_obj_create(parent);
674 elm_box_pack_end(parent->submenu.bx, VIEW(subitem));
675 parent->submenu.items = eina_list_append(parent->submenu.items, subitem);
676 subitem->idx = eina_list_count(parent->submenu.items) - 1;
680 elm_box_pack_end(wd->bx, VIEW(subitem));
681 wd->items = eina_list_append(wd->items, subitem);
682 subitem->idx = eina_list_count(wd->items) - 1;
689 _item_del_pre_hook(Elm_Object_Item *it)
691 Elm_Menu_Item *item = (Elm_Menu_Item *) it;
692 Elm_Object_Item *_item;
694 EINA_LIST_FREE(item->submenu.items, _item) elm_object_item_del(_item);
695 if (item->label) eina_stringshare_del(item->label);
696 if (item->content) evas_object_del(item->content);
697 if (item->submenu.hv) evas_object_del(item->submenu.hv);
698 if (item->submenu.location) evas_object_del(item->submenu.location);
701 item->parent->submenu.items = eina_list_remove(item->parent->submenu.items, item);
704 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
705 wd->items = eina_list_remove(wd->items, item);
711 EAPI Elm_Object_Item *
712 elm_menu_item_add(Evas_Object *obj, Elm_Object_Item *parent, const char *icon, const char *label, Evas_Smart_Cb func, const void *data)
714 Elm_Menu_Item *subitem;
715 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
716 Widget_Data *wd = elm_widget_data_get(obj);
717 Evas_Object *icon_obj;
719 if (!wd) return NULL;
720 icon_obj = elm_icon_add(obj);
721 if (!icon_obj) return NULL;
722 subitem = elm_widget_item_new(obj, Elm_Menu_Item);
725 evas_object_del(icon_obj);
729 elm_widget_item_del_pre_hook_set(subitem, _item_del_pre_hook);
730 elm_widget_item_disable_hook_set(subitem, _item_disable_hook);
731 elm_widget_item_text_set_hook_set(subitem, _item_text_set_hook);
732 elm_widget_item_text_get_hook_set(subitem, _item_text_get_hook);
733 elm_widget_item_content_set_hook_set(subitem, _item_content_set_hook);
734 elm_widget_item_content_get_hook_set(subitem, _item_content_get_hook);
736 subitem->base.data = data;
737 subitem->func = func;
738 subitem->parent = (Elm_Menu_Item *) parent;
739 subitem->content = icon_obj;
741 _item_obj_create(subitem);
742 elm_object_item_text_set((Elm_Object_Item *) subitem, label);
744 elm_widget_sub_object_add(WIDGET(subitem), subitem->content);
745 edje_object_part_swallow(VIEW(subitem), "elm.swallow.content", subitem->content);
747 elm_menu_item_object_icon_name_set((Elm_Object_Item *) subitem, icon);
749 _elm_menu_item_add_helper(obj, (Elm_Menu_Item *) parent, subitem, wd);
751 return (Elm_Object_Item *) subitem;
754 EAPI Elm_Object_Item *
755 elm_menu_item_add_object(Evas_Object *obj, Elm_Object_Item *parent, Evas_Object *subobj, Evas_Smart_Cb func, const void *data)
757 Elm_Menu_Item *subitem;
758 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
759 Widget_Data *wd = elm_widget_data_get(obj);
761 if (!wd) return NULL;
762 subitem = elm_widget_item_new(obj, Elm_Menu_Item);
763 if (!subitem) return NULL;
765 elm_widget_item_del_pre_hook_set(subitem, _item_del_pre_hook);
766 elm_widget_item_disable_hook_set(subitem, _item_disable_hook);
767 elm_widget_item_text_set_hook_set(subitem, _item_text_set_hook);
768 elm_widget_item_text_get_hook_set(subitem, _item_text_get_hook);
769 elm_widget_item_content_set_hook_set(subitem, _item_content_set_hook);
770 elm_widget_item_content_get_hook_set(subitem, _item_content_get_hook);
772 subitem->base.data = data;
773 subitem->func = func;
774 subitem->parent = (Elm_Menu_Item *) parent;
775 subitem->object_item = EINA_TRUE;
776 subitem->content = subobj;
778 _item_obj_create(subitem);
780 elm_widget_sub_object_add(WIDGET(subitem), subitem->content);
781 edje_object_part_swallow(VIEW(subitem), "elm.swallow.content", subobj);
782 _sizing_eval(WIDGET(subitem));
784 _elm_menu_item_add_helper(obj, (Elm_Menu_Item *) parent, subitem, wd);
786 return (Elm_Object_Item *) subitem;
790 elm_menu_item_index_get(const Elm_Object_Item *it)
792 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, 0);
793 return ((Elm_Menu_Item *) it)->idx;
797 elm_menu_item_label_set(Elm_Object_Item *it, const char *label)
799 _item_text_set_hook(it, NULL, label);
803 elm_menu_item_label_get(const Elm_Object_Item *it)
805 return _item_text_get_hook(it, NULL);
809 elm_menu_item_object_icon_name_set(Elm_Object_Item *it, const char *icon)
811 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
812 EINA_SAFETY_ON_NULL_RETURN(icon);
814 Elm_Menu_Item *item = (Elm_Menu_Item *) it;
817 if ((item->icon_str) && (!strcmp(item->icon_str, icon))) return;
818 if ((snprintf(icon_tmp, sizeof(icon_tmp), "menu/%s", icon) > 0) &&
819 (elm_icon_standard_set(item->content, icon_tmp) ||
820 elm_icon_standard_set(item->content, icon)))
822 eina_stringshare_replace(&item->icon_str, icon);
823 edje_object_signal_emit(VIEW(item), "elm,state,icon,visible", "elm");
826 edje_object_signal_emit(VIEW(item), "elm,state,icon,hidden", "elm");
827 edje_object_message_signal_process(VIEW(item));
828 _sizing_eval(WIDGET(item));
832 elm_menu_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled)
834 elm_object_item_disabled_set(it, disabled);
838 elm_menu_item_disabled_get(const Elm_Object_Item *it)
840 return elm_object_item_disabled_get(it);
843 EAPI Elm_Object_Item *
844 elm_menu_item_separator_add(Evas_Object *obj, Elm_Object_Item *parent)
846 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
847 Elm_Menu_Item *subitem;
848 Widget_Data *wd = elm_widget_data_get(obj);
849 Elm_Menu_Item *p_item = (Elm_Menu_Item *) parent;
850 if (!wd) return NULL;
851 /* don't add a separator as the first item */
852 if (!wd->items) return NULL;
853 /* don't allow adding more than one separator in a row */
854 if (p_item) subitem = eina_list_last(p_item->submenu.items)->data;
855 else subitem = eina_list_last(wd->items)->data;
856 if (subitem->separator) return NULL;
858 subitem = elm_widget_item_new(obj, Elm_Menu_Item);
859 if (!subitem) return NULL;
861 elm_widget_item_del_pre_hook_set(subitem, _item_del_pre_hook);
862 elm_widget_item_disable_hook_set(subitem, _item_disable_hook);
863 elm_widget_item_text_set_hook_set(subitem, _item_text_set_hook);
864 elm_widget_item_text_get_hook_set(subitem, _item_text_get_hook);
865 elm_widget_item_content_set_hook_set(subitem, _item_content_set_hook);
866 elm_widget_item_content_get_hook_set(subitem, _item_content_get_hook);
868 subitem->separator = EINA_TRUE;
869 _item_separator_obj_create(subitem);
872 elm_box_pack_end(wd->bx, VIEW(subitem));
873 wd->items = eina_list_append(wd->items, subitem);
877 if (!p_item->submenu.bx) _item_submenu_obj_create(p_item);
878 elm_box_pack_end(p_item->submenu.bx, VIEW(subitem));
879 p_item->submenu.items = eina_list_append(p_item->submenu.items,
883 return (Elm_Object_Item *) subitem;
887 elm_menu_item_object_content_set(Elm_Object_Item *it, Evas_Object *obj)
889 _item_content_set_hook(it, NULL, obj);
894 elm_menu_item_object_content_get(const Elm_Object_Item *it)
896 return _item_content_get_hook(it, NULL);
900 elm_menu_item_object_icon_name_get(const Elm_Object_Item *it)
902 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
903 return ((Elm_Menu_Item *) it)->icon_str;
907 elm_menu_item_is_separator(Elm_Object_Item *it)
909 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
910 return ((Elm_Menu_Item *) it)->separator;
914 elm_menu_item_del(Elm_Object_Item *it)
916 elm_object_item_del(it);
920 elm_menu_item_del_cb_set(Elm_Object_Item *it, Evas_Smart_Cb func)
922 elm_object_item_del_cb_set(it, func);
926 elm_menu_item_data_get(const Elm_Object_Item *it)
928 return elm_object_item_data_get(it);
932 elm_menu_item_data_set(Elm_Object_Item *it, const void *data)
934 elm_object_item_data_set(it, (void *) data);
937 EAPI const Eina_List *
938 elm_menu_item_subitems_get(const Elm_Object_Item *it)
940 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
941 return ((Elm_Menu_Item *) it)->submenu.items;
944 EAPI const Eina_List *
945 elm_menu_items_get(const Evas_Object * obj)
947 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
948 Widget_Data *wd = elm_widget_data_get(obj);
953 elm_menu_item_selected_set(Elm_Object_Item *it, Eina_Bool selected)
955 ELM_OBJ_ITEM_CHECK_OR_RETURN(it);
956 Elm_Menu_Item *item = (Elm_Menu_Item *) it;
958 if (selected == item->selected) return;
959 item->selected = selected;
962 edje_object_signal_emit(VIEW(item), "elm,state,selected", "elm");
963 _menu_item_activate(item, NULL, NULL, NULL);
967 edje_object_signal_emit(VIEW(item), "elm,state,unselected", "elm");
968 _menu_item_inactivate(item, NULL, NULL, NULL);
970 edje_object_message_signal_process(VIEW(item));
974 elm_menu_item_selected_get(const Elm_Object_Item *it)
976 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE);
977 return ((Elm_Menu_Item *) it)->selected;
980 EAPI Elm_Object_Item *
981 elm_menu_item_prev_get(const Elm_Object_Item *it)
983 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
984 Elm_Menu_Item *item = (Elm_Menu_Item *) it;
988 Eina_List *l = eina_list_data_find_list(item->parent->submenu.items,
990 l = eina_list_prev(l);
996 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
997 if (!wd || !wd->items) return NULL;
998 Eina_List *l = eina_list_data_find_list(wd->items, item);
999 l = eina_list_prev(l);
1000 if (!l) return NULL;
1006 EAPI Elm_Object_Item *
1007 elm_menu_item_next_get(const Elm_Object_Item *it)
1009 ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL);
1010 Elm_Menu_Item *item = (Elm_Menu_Item *) it;
1014 Eina_List *l = eina_list_data_find_list(item->parent->submenu.items,
1016 l = eina_list_next(l);
1017 if (!l) return NULL;
1022 Widget_Data *wd = elm_widget_data_get(WIDGET(item));
1023 if (!wd || !wd->items) return NULL;
1024 Eina_List *l = eina_list_data_find_list(wd->items, item);
1025 l = eina_list_next(l);
1026 if (!l) return NULL;
1032 EINA_DEPRECATED EAPI Evas_Object *
1033 elm_menu_item_menu_get(const Elm_Object_Item *it)
1035 return elm_object_item_widget_get(it);
1038 EAPI Elm_Object_Item *
1039 elm_menu_first_item_get(const Evas_Object * obj)
1041 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1042 Widget_Data *wd = elm_widget_data_get(obj);
1043 if (!wd) return NULL;
1044 if (wd->items) return wd->items->data;
1048 EAPI Elm_Object_Item *
1049 elm_menu_last_item_get(const Evas_Object * obj)
1051 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1052 Widget_Data *wd = elm_widget_data_get(obj);
1053 if (!wd) return NULL;
1054 Eina_List *l = eina_list_last(wd->items);
1055 if (l) return l->data;
1059 EAPI Elm_Object_Item *
1060 elm_menu_selected_item_get(const Evas_Object * obj)
1062 ELM_CHECK_WIDTYPE(obj, widtype) NULL;
1063 Widget_Data *wd = elm_widget_data_get(obj);
1064 if (!wd) return NULL;
1066 Elm_Menu_Item *item;
1067 EINA_LIST_FOREACH(wd->items, l, item)
1069 if (item->selected) return ((Elm_Object_Item *) item);