From 2864757ca6538bbaaa1706b7cacfc9842139eac0 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: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/elementary@65325 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- doc/widgets/widget_preview_ctxpopup.c | 2 +- src/bin/test_ctxpopup.c | 10 +- src/examples/ctxpopup_example_01.c | 8 +- src/lib/Elementary.h.in | 27 ++++- src/lib/elc_ctxpopup.c | 190 +++++++++++++++++++++++----------- src/lib/elm_flipselector.c | 8 +- 6 files changed, 167 insertions(+), 78 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 ac6d030..01189b5 100644 --- a/src/bin/test_ctxpopup.c +++ b/src/bin/test_ctxpopup.c @@ -41,7 +41,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)); + elm_object_item_text_get(event_info)); } #define ITEM_NEW(_hov, _label, _icon) \ @@ -72,10 +72,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); @@ -102,7 +102,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); @@ -129,7 +129,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 5c12139..85e7eb4 100644 --- a/src/lib/Elementary.h.in +++ b/src/lib/Elementary.h.in @@ -26553,6 +26553,12 @@ extern "C" { * Default contents parts of the ctxpopup widget that you can use for are: * @li "default" - A content of the ctxpopup * + * Default contents parts of the naviframe items that you can use for are: + * @li "icon" - A icon in the title area + * + * Default text parts of the naviframe items that you can use for are: + * @li "default" - Title label in the title area + * * @ref tutorial_ctxpopup shows the usage of a good deal of the API. * @{ */ @@ -26652,8 +26658,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. * @@ -26661,6 +26668,7 @@ extern "C" { * @return disabled @c EINA_TRUE, if disabled, @c EINA_FALSE otherwise * * @see elm_ctxpopup_item_disabled_set() + * @deprecated use elm_object_item_disabled_get() instead */ EAPI Eina_Bool elm_ctxpopup_item_disabled_get(const Elm_Object_Item *it) EINA_ARG_NONNULL(1); /** @@ -26672,8 +26680,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 * @@ -26685,8 +26695,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. * @@ -26696,15 +26709,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 7c0daa1..7b318a5 100644 --- a/src/lib/elc_ctxpopup.c +++ b/src/lib/elc_ctxpopup.c @@ -10,7 +10,6 @@ struct _Elm_Ctxpopup_Item const char *label; Evas_Object *icon; Evas_Smart_Cb func; - Eina_Bool disabled:1; }; struct _Widget_Data @@ -80,6 +79,20 @@ static Evas_Object * _content_unset_hook(Evas_Object *obj, const char *part__); static Evas_Object * _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); +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); @@ -767,7 +780,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"); edje_object_message_signal_process(VIEW(item)); @@ -858,6 +871,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__) { @@ -969,7 +1082,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); @@ -1148,59 +1261,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); - wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN; - - 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); - wd->dir = ELM_CTXPOPUP_DIRECTION_UNKNOWN; - - if (wd->visible) - { - _scroller_size_reset(wd); - _sizing_eval(WIDGET(ctxpopup_it)); - } + _item_text_set_hook(it, NULL, label); } EAPI void @@ -1331,6 +1410,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. content = elm_object_content_unset(obj); if (content) evas_object_del(content); @@ -1401,31 +1487,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 3eee668..f0788e4 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