From db05428b408bdb567d18ed3ea6debd156d4ab6f9 Mon Sep 17 00:00:00 2001 From: discomfitor Date: Fri, 29 Jul 2011 15:08:56 +0000 Subject: [PATCH] unbreak elm_menu_item api the following functions are now DEPRECATED and will be removed on 5 AUG 2011: elm_menu_item_object_icon_get -> elm_menu_item_object_content_get elm_menu_item_icon_get -> elm_menu_item_object_icon_name_get elm_menu_item_icon_set -> elm_menu_item_object_icon_name_set added the following NEW functions: elm_menu_item_object_content_set elm_menu_item_menu_get (this will probably be replaced by an eventual elm_object_item_owner_get() or whatever it gets named) git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/elementary@61899 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/Elementary.h.in | 11 +++-- src/lib/elm_menu.c | 108 +++++++++++++++++++++++++++++++++++++----------- 2 files changed, 93 insertions(+), 26 deletions(-) diff --git a/src/lib/Elementary.h.in b/src/lib/Elementary.h.in index bf78fb4..3ede57f 100644 --- a/src/lib/Elementary.h.in +++ b/src/lib/Elementary.h.in @@ -9809,9 +9809,13 @@ extern "C" { EAPI Elm_Menu_Item *elm_menu_item_add_object(Evas_Object *obj, Elm_Menu_Item *parent, Evas_Object *subobj, Evas_Smart_Cb func, const void *data) EINA_ARG_NONNULL(1); EAPI void elm_menu_item_label_set(Elm_Menu_Item *item, const char *label) EINA_ARG_NONNULL(1); EAPI const char *elm_menu_item_label_get(const Elm_Menu_Item *item) EINA_ARG_NONNULL(1); - EAPI void elm_menu_item_icon_set(Elm_Menu_Item *item, const char *icon) EINA_ARG_NONNULL(1, 2); - EAPI const char *elm_menu_item_icon_get(const Elm_Menu_Item *item) EINA_ARG_NONNULL(1); - EAPI const Evas_Object *elm_menu_item_object_icon_get(const Elm_Menu_Item *item) EINA_ARG_NONNULL(1); + EAPI void elm_menu_item_object_icon_name_set(Elm_Menu_Item *item, const char *icon) EINA_ARG_NONNULL(1, 2); + EAPI const char *elm_menu_item_object_icon_name_get(const Elm_Menu_Item *item) EINA_ARG_NONNULL(1); + EAPI void elm_menu_item_icon_set(Elm_Menu_Item *item, const char *icon) EINA_ARG_NONNULL(1, 2) EINA_DEPRECATED; + EAPI const char *elm_menu_item_icon_get(const Elm_Menu_Item *item) EINA_ARG_NONNULL(1) EINA_DEPRECATED; + EAPI Eina_Bool elm_menu_item_object_content_set(Elm_Menu_Item *item, Evas_Object *obj) EINA_ARG_NONNULL(1); + EAPI Evas_Object *elm_menu_item_object_content_get(const Elm_Menu_Item *item) EINA_ARG_NONNULL(1); + EAPI Evas_Object *elm_menu_item_object_icon_get(const Elm_Menu_Item *item) EINA_ARG_NONNULL(1) EINA_DEPRECATED; EAPI void elm_menu_item_selected_set(Elm_Menu_Item *item, Eina_Bool selected) EINA_ARG_NONNULL(1); EAPI Eina_Bool elm_menu_item_selected_get(const Elm_Menu_Item *item) EINA_ARG_NONNULL(1); EAPI void elm_menu_item_disabled_set(Elm_Menu_Item *item, Eina_Bool disabled) EINA_ARG_NONNULL(1); @@ -9824,6 +9828,7 @@ extern "C" { EAPI void elm_menu_item_data_set(Elm_Menu_Item *item, const void *data) EINA_ARG_NONNULL(1); EAPI const Eina_List *elm_menu_item_subitems_get(const Elm_Menu_Item *item) EINA_ARG_NONNULL(1); EAPI unsigned int elm_menu_item_index_get(const Elm_Menu_Item *item) EINA_ARG_NONNULL(1) EINA_PURE; + EAPI Evas_Object *elm_menu_item_menu_get(const Elm_Menu_Item *item) EINA_ARG_NONNULL(1) EINA_PURE; EAPI Elm_Menu_Item *elm_menu_selected_item_get(const Evas_Object * obj) EINA_ARG_NONNULL(1); EAPI Elm_Menu_Item *elm_menu_last_item_get(const Evas_Object * obj) EINA_ARG_NONNULL(1); EAPI Elm_Menu_Item *elm_menu_first_item_get(const Evas_Object * obj) EINA_ARG_NONNULL(1); diff --git a/src/lib/elm_menu.c b/src/lib/elm_menu.c index d7197a7..dcced64 100644 --- a/src/lib/elm_menu.c +++ b/src/lib/elm_menu.c @@ -20,7 +20,7 @@ struct _Elm_Menu_Item { Elm_Widget_Item base; Elm_Menu_Item *parent; - Evas_Object *icon; + Evas_Object *content; const char *icon_str; const char *label; Evas_Smart_Cb func; @@ -130,14 +130,14 @@ _theme_hook(Evas_Object *obj) (obj, item->base.view, "menu", "item_with_submenu", elm_widget_style_get(obj)); elm_menu_item_label_set(item, item->label); - elm_menu_item_icon_set(item, item->icon_str); + elm_menu_item_object_icon_name_set(item, item->icon_str); } else { _elm_theme_object_set(obj, item->base.view, "menu", "item", elm_widget_style_get(obj)); elm_menu_item_label_set(item, item->label); - elm_menu_item_icon_set(item, item->icon_str); + elm_menu_item_object_icon_name_set(item, item->icon_str); } if (item->disabled) edje_object_signal_emit @@ -433,7 +433,7 @@ _item_submenu_obj_create(Elm_Menu_Item *item) edje_object_mirrored_set(item->base.view, elm_widget_mirrored_get(item->base.widget)); _elm_theme_object_set(item->base.widget, item->base.view, "menu", "item_with_submenu", elm_widget_style_get(item->base.widget)); elm_menu_item_label_set(item, item->label); - if (item->icon_str) elm_menu_item_icon_set(item, item->icon_str); + if (item->icon_str) elm_menu_item_object_icon_name_set(item, item->icon_str); edje_object_signal_callback_add(item->base.view, "elm,action,open", "", _submenu_open, item); @@ -696,14 +696,14 @@ elm_menu_item_add(Evas_Object *obj, Elm_Menu_Item *parent, const char *icon, con subitem->base.data = data; subitem->func = func; subitem->parent = parent; - subitem->icon = icon_obj; + subitem->content = icon_obj; _item_obj_create(subitem); elm_menu_item_label_set(subitem, label); - elm_widget_sub_object_add(subitem->base.widget, subitem->icon); - edje_object_part_swallow(subitem->base.view, "elm.swallow.content", subitem->icon); - if (icon) elm_menu_item_icon_set(subitem, icon); + elm_widget_sub_object_add(subitem->base.widget, subitem->content); + edje_object_part_swallow(subitem->base.view, "elm.swallow.content", subitem->content); + if (icon) elm_menu_item_object_icon_name_set(subitem, icon); _elm_menu_item_add_helper(obj, parent, subitem, wd); @@ -737,11 +737,11 @@ elm_menu_item_add_object(Evas_Object *obj, Elm_Menu_Item *parent, Evas_Object *s subitem->func = func; subitem->parent = parent; subitem->object_item = EINA_TRUE; - subitem->icon = subobj; + subitem->content = subobj; _item_obj_create(subitem); - elm_widget_sub_object_add(subitem->base.widget, subitem->icon); + elm_widget_sub_object_add(subitem->base.widget, subitem->content); edje_object_part_swallow(subitem->base.view, "elm.swallow.content", subobj); _sizing_eval(subitem->base.widget); @@ -807,17 +807,17 @@ elm_menu_item_label_get(const Elm_Menu_Item *item) } /** - * Set the icon of a menu item + * Set the content of a menu item to an icon * - * Once the icon object is set, a previously set one will be deleted. + * Once this content object is set, any previously set object will be deleted. * * @param item The menu item object. - * @param icon The icon object to set for @p item + * @param icon The icon object to set for the content of @p item * * @ingroup Menu */ EAPI void -elm_menu_item_icon_set(Elm_Menu_Item *item, const char *icon) +elm_menu_item_object_icon_name_set(Elm_Menu_Item *item, const char *icon) { char icon_tmp[512]; ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item); @@ -825,7 +825,7 @@ elm_menu_item_icon_set(Elm_Menu_Item *item, const char *icon) if (!*icon) return; if ((item->icon_str) && (!strcmp(item->icon_str, icon))) return; if ((snprintf(icon_tmp, sizeof(icon_tmp), "menu/%s", icon) > 0) && - (elm_icon_standard_set(item->icon, icon_tmp))) + (elm_icon_standard_set(item->content, icon_tmp))) { eina_stringshare_replace(&item->icon_str, icon); edje_object_signal_emit(item->base.view, "elm,state,icon,visible", "elm"); @@ -836,6 +836,12 @@ elm_menu_item_icon_set(Elm_Menu_Item *item, const char *icon) _sizing_eval(item->base.widget); } +EAPI void +elm_menu_item_icon_set(Elm_Menu_Item *item, const char *icon) +{ + elm_menu_item_object_icon_name_set(item, icon); +} + /** * Set the disabled state of @p item. * @@ -920,20 +926,56 @@ elm_menu_item_separator_add(Evas_Object *obj, Elm_Menu_Item *parent) } /** - * Get the icon object from a menu item + * Set the content object of a menu item + * + * Use this function to change the object swallowed by a menu item, + * deleting any previously swallowed object. + * @param item The menu item object + * @param The content object or NULL + * @return EINA_TRUE on success, else EINA_FALSE + * + * @ingroup Menu + */ +EAPI Eina_Bool +elm_menu_item_object_content_set(Elm_Menu_Item *item, Evas_Object *obj) +{ + ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, EINA_FALSE); + if (item->content) + { + elm_widget_sub_object_del(item->base.widget, item->content); + evas_object_del(item->content); + } + + item->content = obj; + + elm_widget_sub_object_add(item->base.widget, item->content); + edje_object_part_swallow(item->base.view, "elm.swallow.content", item->content); + _sizing_eval(item->base.widget); + return EINA_TRUE; +} + +/** + * Get the content object of a menu item * * @param item The menu item object - * @return The icon object or NULL if there's no icon + * @return The content object or NULL * @note If @p item was added with elm_menu_item_add_object, this - * function will return the object passed. + * function will return the object passed, else it will return the + * icon object. * * @ingroup Menu */ -EAPI const Evas_Object * -elm_menu_item_object_icon_get(const Elm_Menu_Item *item) +EAPI Evas_Object * +elm_menu_item_object_content_get(const Elm_Menu_Item *item) { ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL); - return (const Evas_Object *)item->icon; + return item->content; +} + +EAPI Evas_Object * +elm_menu_item_object_icon_get(const Elm_Menu_Item *item) +{ + return elm_menu_item_object_content_get(item); } /** @@ -945,12 +987,18 @@ elm_menu_item_object_icon_get(const Elm_Menu_Item *item) * @ingroup Menu */ EAPI const char * -elm_menu_item_icon_get(const Elm_Menu_Item *item) +elm_menu_item_object_icon_name_get(const Elm_Menu_Item *item) { ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL); return item->icon_str; } +EAPI const char * +elm_menu_item_icon_get(const Elm_Menu_Item *item) +{ + return elm_menu_item_object_icon_name_get(item); +} + /** * Returns whether @p item is a separator. * @@ -983,7 +1031,7 @@ elm_menu_item_del(Elm_Menu_Item *item) EINA_LIST_FREE(item->submenu.items, _item) elm_menu_item_del(_item); if (item->label) eina_stringshare_del(item->label); - if (item->icon) evas_object_del(item->icon); + if (item->content) evas_object_del(item->content); if (item->submenu.hv) evas_object_del(item->submenu.hv); if (item->submenu.location) evas_object_del(item->submenu.location); @@ -1179,6 +1227,20 @@ elm_menu_item_next_get(const Elm_Menu_Item *it) } /** + * @brief Return a menu item's owner menu + * + * Use this function to get the menu object owning an item. + * @param item The menu item + * @return The menu object owning @p item, or NULL on failure + */ +EAPI Evas_Object * +elm_menu_item_menu_get(const Elm_Menu_Item *item) +{ + ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(item, NULL); + return item->base.widget; +} + +/** * Get the first item in the menu * * @param obj The menu object -- 2.7.4