From 75fc1b9a3a846ef0248ef8993e4bee27d91fef57 Mon Sep 17 00:00:00 2001 From: hermet Date: Thu, 17 Nov 2011 02:16:38 +0000 Subject: [PATCH] elementary/ctxpopup, flipselector - applied elm_object_item common apis. git-svn-id: https://svn.enlightenment.org/svn/e/trunk/elementary@65325 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- doc/widgets/widget_preview_ctxpopup.c | 2 +- src/bin/test_ctxpopup.c | 8 +- src/examples/ctxpopup_example_01.c | 8 +- src/lib/Elementary.h.in | 20 +++- src/lib/elc_ctxpopup.c | 190 +++++++++++++++++++++++----------- src/lib/elm_flipselector.c | 8 +- 6 files changed, 160 insertions(+), 76 deletions(-) diff --git a/doc/widgets/widget_preview_ctxpopup.c b/doc/widgets/widget_preview_ctxpopup.c index 5b71284..c2819d6 100644 --- a/doc/widgets/widget_preview_ctxpopup.c +++ b/doc/widgets/widget_preview_ctxpopup.c @@ -20,7 +20,7 @@ ic = elm_icon_add(ctxpopup); elm_icon_standard_set(ic, "folder"); elm_icon_scale_set(ic, EINA_FALSE, EINA_FALSE); Elm_Object_Item *it = elm_ctxpopup_item_append(ctxpopup, "Navigate to folder", ic, NULL, NULL); -elm_ctxpopup_item_disabled_set(it, EINA_TRUE); +elm_object_item_disabled_set(it, EINA_TRUE); evas_object_size_hint_weight_set(ctxpopup, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND); evas_object_move(ctxpopup, 0, 0); diff --git a/src/bin/test_ctxpopup.c b/src/bin/test_ctxpopup.c index c40b231..dc4fd10 100644 --- a/src/bin/test_ctxpopup.c +++ b/src/bin/test_ctxpopup.c @@ -35,10 +35,10 @@ _list_item_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_in ITEM_NEW(ctxpopup, "Save file", "file"); ITEM_NEW(ctxpopup, "Delete file", "delete"); ITEM_NEW(ctxpopup, "Navigate to folder", "folder"); - elm_ctxpopup_item_disabled_set(it, EINA_TRUE); + elm_object_item_disabled_set(it, EINA_TRUE); ITEM_NEW(ctxpopup, "Edit entry", "edit"); ITEM_NEW(ctxpopup, "Set date and time", "clock"); - elm_ctxpopup_item_disabled_set(it, EINA_TRUE); + elm_object_item_disabled_set(it, EINA_TRUE); evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y); evas_object_size_hint_max_set(ctxpopup, 240, 240); @@ -60,7 +60,7 @@ _list_item_cb2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_i ITEM_NEW(ctxpopup, NULL, "delete"); ITEM_NEW(ctxpopup, NULL, "folder"); ITEM_NEW(ctxpopup, NULL, "edit"); - elm_ctxpopup_item_disabled_set(it, EINA_TRUE); + elm_object_item_disabled_set(it, EINA_TRUE); ITEM_NEW(ctxpopup, NULL, "clock"); evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y); @@ -82,7 +82,7 @@ _list_item_cb3(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_i ITEM_NEW(ctxpopup, "Eet", NULL); ITEM_NEW(ctxpopup, "Evas", NULL); ITEM_NEW(ctxpopup, "Ecore", NULL); - elm_ctxpopup_item_disabled_set(it, EINA_TRUE); + elm_object_item_disabled_set(it, EINA_TRUE); ITEM_NEW(ctxpopup, "Embryo", NULL); ITEM_NEW(ctxpopup, "Edje", NULL); diff --git a/src/examples/ctxpopup_example_01.c b/src/examples/ctxpopup_example_01.c index b938634..52c713c 100644 --- a/src/examples/ctxpopup_example_01.c +++ b/src/examples/ctxpopup_example_01.c @@ -9,7 +9,7 @@ static void _ctxpopup_item_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info) { - printf("ctxpopup item selected: %s\n", elm_ctxpopup_item_label_get(event_info)); + printf("ctxpopup item selected: %s\n", elm_object_item_text_get(event_info)); } Elm_Object_Item *item_new(Evas_Object *ctxpopup, const char * label, const char *icon) @@ -33,10 +33,10 @@ _list_item_cb(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_in item_new(ctxpopup, "Save file", "file"); item_new(ctxpopup, "Delete file", "delete"); it = item_new(ctxpopup, "Navigate to folder", "folder"); - elm_ctxpopup_item_disabled_set(it, EINA_TRUE); + elm_object_item_disabled_set(it, EINA_TRUE); item_new(ctxpopup, "Edit entry", "edit"); it = item_new(ctxpopup, "Set date and time", "clock"); - elm_ctxpopup_item_disabled_set(it, EINA_TRUE); + elm_object_item_disabled_set(it, EINA_TRUE); evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y); evas_object_size_hint_max_set(ctxpopup, 240, 240); @@ -61,7 +61,7 @@ _list_item_cb2(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_i item_new(ctxpopup, NULL, "delete"); item_new(ctxpopup, NULL, "folder"); it = item_new(ctxpopup, NULL, "edit"); - elm_ctxpopup_item_disabled_set(it, EINA_TRUE); + elm_object_item_disabled_set(it, EINA_TRUE); item_new(ctxpopup, NULL, "clock"); evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y); diff --git a/src/lib/Elementary.h.in b/src/lib/Elementary.h.in index b2c315d..62a848d 100644 --- a/src/lib/Elementary.h.in +++ b/src/lib/Elementary.h.in @@ -26735,8 +26735,9 @@ extern "C" { * @param disabled @c EINA_TRUE to disable it, @c EINA_FALSE to enable it * * When disabled the item is greyed out to indicate it's state. + * @deprecated use elm_object_item_disabled_set() instead */ - EAPI void elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled) EINA_ARG_NONNULL(1); + EINA_DEPRECATED EAPI void elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled) EINA_ARG_NONNULL(1); /** * @brief Get the ctxpopup item's disabled/enabled state. * @@ -26756,8 +26757,10 @@ extern "C" { * * @see elm_ctxpopup_item_append() * @see elm_ctxpopup_item_icon_set() + * + * @deprecated use elm_object_item_content_part_get() instead */ - EAPI Evas_Object *elm_ctxpopup_item_icon_get(const Elm_Object_Item *it) EINA_ARG_NONNULL(1); + EINA_DEPRECATED EAPI Evas_Object *elm_ctxpopup_item_icon_get(const Elm_Object_Item *it) EINA_ARG_NONNULL(1); /** * @brief Sets the side icon associated with the ctxpopup item * @@ -26769,8 +26772,11 @@ extern "C" { * dissapear from the first item. * * @see elm_ctxpopup_item_append() + * + * @deprecated use elm_object_item_content_part_set() instead + * */ - EAPI void elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon) EINA_ARG_NONNULL(1); + EINA_DEPRECATED EAPI void elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon) EINA_ARG_NONNULL(1); /** * @brief Get the label for the given ctxpopup item. * @@ -26780,15 +26786,19 @@ extern "C" { * * @see elm_ctxpopup_item_append() * @see elm_ctxpopup_item_label_set() + * + * @deprecated use elm_object_item_text_get() instead */ - EAPI const char *elm_ctxpopup_item_label_get(const Elm_Object_Item *it) EINA_ARG_NONNULL(1); + EINA_DEPRECATED EAPI const char *elm_ctxpopup_item_label_get(const Elm_Object_Item *it) EINA_ARG_NONNULL(1); /** * @brief (Re)set the label on the given ctxpopup item. * * @param it Ctxpopup item * @param label String to set as label + * + * @deprecated use elm_object_item_text_set() instead */ - EAPI void elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label) EINA_ARG_NONNULL(1); + EINA_DEPRECATED EAPI void elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label) EINA_ARG_NONNULL(1); /** * @brief Set an elm widget as the content of the ctxpopup. * diff --git a/src/lib/elc_ctxpopup.c b/src/lib/elc_ctxpopup.c index 95e84df..9ee79c3 100644 --- a/src/lib/elc_ctxpopup.c +++ b/src/lib/elc_ctxpopup.c @@ -12,7 +12,6 @@ struct _Elm_Ctxpopup_Item const char *label; Evas_Object *icon; Evas_Smart_Cb func; - Eina_Bool disabled:1; }; struct _Widget_Data @@ -81,7 +80,21 @@ static void _content_set_hook(Evas_Object *obj, static Evas_Object * _content_unset_hook(Evas_Object *obj, const char *item __UNUSED__); static Evas_Object * _content_get_hook(const Evas_Object *obj, - const char *item __UNUSED__); + const char *part); +static void _item_text_set_hook(Elm_Object_Item *it, + const char *part, + const char *label); +static const char * _item_text_get_hook(const Elm_Object_Item *it, + const char *part); +static void _item_content_set_hook(Elm_Object_Item *it, + const char *part, + Evas_Object *content); +static Evas_Object * _item_content_get_hook(const Elm_Object_Item *it, + const char *part); +static void _item_disable_set_hook(Elm_Object_Item *it); +static void _item_signal_emit_hook(Elm_Object_Item *it, + const char *emission, + const char *source); static void _bg_clicked_cb(void *data, Evas_Object *obj, const char *emission, const char *source); @@ -780,7 +793,7 @@ _theme_hook(Evas_Object *obj) if (item->label) edje_object_part_text_set(VIEW(item), "elm.text", item->label); - if (item->disabled) + if (elm_widget_item_disabled_get(item)) edje_object_signal_emit(VIEW(item), "elm,state,disabled", "elm"); /* @@ -893,6 +906,106 @@ _content_get_hook(const Evas_Object *obj, const char *part) } static void +_item_text_set_hook(Elm_Object_Item *it, + const char *part, + const char *label) +{ + ELM_OBJ_ITEM_CHECK_OR_RETURN(it); + + Widget_Data *wd; + Elm_Ctxpopup_Item *ctxpopup_it; + + if (part && strcmp(part, "default")) return; + + ctxpopup_it = (Elm_Ctxpopup_Item *) it; + + wd = elm_widget_data_get(WIDGET(ctxpopup_it)); + if (!wd) return; + + _item_label_set(ctxpopup_it, label); + wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN; + + if (wd->visible) + { + _scroller_size_reset(wd); + _sizing_eval(WIDGET(ctxpopup_it)); + } +} + +static const char * +_item_text_get_hook(const Elm_Object_Item *it, const char *part) +{ + ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL); + Elm_Ctxpopup_Item *ctxpopup_it; + if (part && strcmp(part, "default")) return NULL; + ctxpopup_it = (Elm_Ctxpopup_Item *) it; + return ctxpopup_it->label; +} + +static void +_item_content_set_hook(Elm_Object_Item *it, + const char *part, + Evas_Object *content) +{ + ELM_OBJ_ITEM_CHECK_OR_RETURN(it); + Widget_Data *wd; + Elm_Ctxpopup_Item *ctxpopup_it; + + if (part && strcmp(part, "icon")) return; + + ctxpopup_it = (Elm_Ctxpopup_Item *) it; + + wd = elm_widget_data_get(WIDGET(ctxpopup_it)); + if (!wd) return; + + _item_icon_set(ctxpopup_it, content); + wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN; + + if (wd->visible) + { + _scroller_size_reset(wd); + _sizing_eval(WIDGET(ctxpopup_it)); + } +} + +static Evas_Object * +_item_content_get_hook(const Elm_Object_Item *it, const char *part) +{ + ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL); + Elm_Ctxpopup_Item *ctxpopup_it; + if (part && strcmp(part, "icon")) return NULL; + ctxpopup_it = (Elm_Ctxpopup_Item *) it; + return ctxpopup_it->icon; +} + +static void +_item_disable_set_hook(Elm_Object_Item *it) +{ + ELM_OBJ_ITEM_CHECK_OR_RETURN(it); + + Widget_Data *wd; + Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it; + + wd = elm_widget_data_get(WIDGET(ctxpopup_it)); + if (!wd) return; + + if (elm_widget_item_disabled_get(it)) + edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm"); + else + edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm"); +} + +static void +_item_signal_emit_hook(Elm_Object_Item *it, + const char *emission, + const char *source) +{ + ELM_OBJ_ITEM_CHECK_OR_RETURN(it); + Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it; + edje_object_signal_emit(VIEW(ctxpopup_it), emission, source); +} + +static void _bg_clicked_cb(void *data, Evas_Object *obj __UNUSED__, const char *emission __UNUSED__, const char *source __UNUSED__) { @@ -1041,7 +1154,7 @@ _item_select_cb(void *data, Evas_Object *obj __UNUSED__, Elm_Ctxpopup_Item *item = data; if (!item) return; - if (item->disabled) return; + if (elm_widget_item_disabled_get(item)) return; if (item->func) item->func((void*) item->base.data, WIDGET(item), data); @@ -1224,57 +1337,25 @@ elm_ctxpopup_add(Evas_Object *parent) EAPI Evas_Object * elm_ctxpopup_item_icon_get(const Elm_Object_Item *it) { - ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL); - Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it; - return ctxpopup_it->icon; + return _item_content_get_hook(it, "icon"); } EAPI void elm_ctxpopup_item_icon_set(Elm_Object_Item *it, Evas_Object *icon) { - ELM_OBJ_ITEM_CHECK_OR_RETURN(it); - - Widget_Data *wd; - Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it; - - wd = elm_widget_data_get(WIDGET(ctxpopup_it)); - if (!wd) return; - - _item_icon_set(ctxpopup_it, icon); - - if (wd->visible) - { - _scroller_size_reset(wd); - _sizing_eval(WIDGET(ctxpopup_it)); - } + _item_content_set_hook(it, "icon", icon); } EAPI const char * elm_ctxpopup_item_label_get(const Elm_Object_Item *it) { - ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL); - Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it; - return ctxpopup_it->label; + return _item_text_get_hook(it, NULL); } EAPI void elm_ctxpopup_item_label_set(Elm_Object_Item *it, const char *label) { - ELM_OBJ_ITEM_CHECK_OR_RETURN(it); - - Widget_Data *wd; - Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it; - - wd = elm_widget_data_get(WIDGET(ctxpopup_it)); - if (!wd) return; - - _item_label_set(ctxpopup_it, label); - - if (wd->visible) - { - _scroller_size_reset(wd); - _sizing_eval(WIDGET(ctxpopup_it)); - } + _item_text_set_hook(it, NULL, label); } EAPI void @@ -1411,6 +1492,13 @@ elm_ctxpopup_item_append(Evas_Object *obj, const char *label, item = elm_widget_item_new(obj, Elm_Ctxpopup_Item); if (!item) return NULL; + elm_widget_item_disable_set_hook_set(item, _item_disable_set_hook); + elm_widget_item_text_set_hook_set(item, _item_text_set_hook); + elm_widget_item_text_get_hook_set(item, _item_text_get_hook); + elm_widget_item_content_set_hook_set(item, _item_content_set_hook); + elm_widget_item_content_get_hook_set(item, _item_content_get_hook); + elm_widget_item_signal_emit_hook_set(item, _item_signal_emit_hook); + //The first item is appended. if (wd->content) evas_object_del(elm_object_content_unset(obj)); @@ -1474,31 +1562,13 @@ elm_ctxpopup_item_del(Elm_Object_Item *it) EAPI void elm_ctxpopup_item_disabled_set(Elm_Object_Item *it, Eina_Bool disabled) { - ELM_OBJ_ITEM_CHECK_OR_RETURN(it); - - Widget_Data *wd; - Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it; - - wd = elm_widget_data_get(WIDGET(ctxpopup_it)); - if (!wd) return; - - if (disabled == ctxpopup_it->disabled) - return; - - if (disabled) - edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,disabled", "elm"); - else - edje_object_signal_emit(VIEW(ctxpopup_it), "elm,state,enabled", "elm"); - - ctxpopup_it->disabled = !!disabled; + elm_object_item_disabled_set(it, disabled); } EAPI Eina_Bool elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it) { - ELM_OBJ_ITEM_CHECK_OR_RETURN(it, EINA_FALSE); - Elm_Ctxpopup_Item *ctxpopup_it = (Elm_Ctxpopup_Item *) it; - return ctxpopup_it->disabled; + return elm_object_item_disabled_get(it); } EAPI void diff --git a/src/lib/elm_flipselector.c b/src/lib/elm_flipselector.c index d1176d3..fa327b4 100644 --- a/src/lib/elm_flipselector.c +++ b/src/lib/elm_flipselector.c @@ -70,7 +70,7 @@ static const Evas_Smart_Cb_Description _signals[] = { static void _item_text_set_hook(Elm_Object_Item *it, - const char *part __UNUSED__, + const char *part, const char *label) { ELM_OBJ_ITEM_CHECK_OR_RETURN(it); @@ -81,6 +81,8 @@ _item_text_set_hook(Elm_Object_Item *it, if (!label) return; + if (part && strcmp(part ,"default")) return; + item = (Elm_Flipselector_Item *) it; wd = elm_widget_data_get(WIDGET(item)); if ((!wd) || (!wd->items)) return; @@ -102,7 +104,7 @@ _item_text_set_hook(Elm_Object_Item *it, } static const char * -_item_text_get_hook(const Elm_Object_Item *it, const char *part __UNUSED__) +_item_text_get_hook(const Elm_Object_Item *it, const char *part) { ELM_OBJ_ITEM_CHECK_OR_RETURN(it, NULL); @@ -110,6 +112,8 @@ _item_text_get_hook(const Elm_Object_Item *it, const char *part __UNUSED__) Widget_Data *wd; Eina_List *l; + if (part && strcmp(part ,"default")) return NULL; + item = (Elm_Flipselector_Item *) it; wd = elm_widget_data_get(WIDGET(item)); if ((!wd) || (!wd->items)) return NULL; -- 2.7.4