From f572922b866d106a51b3adec9d5b92435337b856 Mon Sep 17 00:00:00 2001 From: JEONGHYUN YUN Date: Wed, 12 Jul 2017 15:04:18 +0900 Subject: [PATCH] elm_ctxpopup: Add APIs to insert before/after item to a ctxpopup object. Summary: There were only 2 APIs (item_append, item_prepend) for ctxpopup item add. Added more item add APIs (item_insert_before and item_insert_after) for convenience. Test Plan: 1. launch elementary_test - ctxpopup 2. click Ctxpopup with callback function sample 3. check whether there are 3 items on ctxpopup Reviewers: jpeg Subscribers: cedric, jpeg Differential Revision: https://phab.enlightenment.org/D5004 Change-Id: Iaee2310ff78dd727e7edfd420d14913fec02b4cd Signed-off-by: JEONGHYUN YUN --- src/bin/test_ctxpopup.c | 7 ++--- src/lib/elc_ctxpopup.c | 62 +++++++++++++++++++++++++++++++++++++++++++ src/lib/elm_ctxpopup.eo | 34 ++++++++++++++++++++++++ src/mobile_lib/elc_ctxpopup.c | 14 ++++++++++ 4 files changed, 114 insertions(+), 3 deletions(-) diff --git a/src/bin/test_ctxpopup.c b/src/bin/test_ctxpopup.c index 4f807f6..f668548 100644 --- a/src/bin/test_ctxpopup.c +++ b/src/bin/test_ctxpopup.c @@ -308,14 +308,15 @@ _list_item_cb7(void *data EINA_UNUSED, Evas_Object *obj, void *event_info EINA_U { Evas_Object *ctxpopup; Evas_Coord x,y; + Elm_Object_Item *item; if (list_mouse_down > 0) return; ctxpopup = elm_ctxpopup_add(obj); evas_object_smart_callback_add(ctxpopup, "dismissed", _dismissed, NULL); - elm_ctxpopup_item_append(ctxpopup, "Disable this item", NULL, _ctxpopup_item_disable_cb, ctxpopup); - elm_ctxpopup_item_append(ctxpopup, "Delete this ctxpopup", NULL, _ctxpopup_item_delete_cb, ctxpopup); - elm_ctxpopup_item_append(ctxpopup, "Another item", NULL, _ctxpopup_item_cb, NULL); + item = elm_ctxpopup_item_append(ctxpopup, "Disable this item", NULL, _ctxpopup_item_disable_cb, ctxpopup); + elm_ctxpopup_item_insert_before(ctxpopup, item, "Delete this ctxpopup", NULL, _ctxpopup_item_delete_cb, ctxpopup); + elm_ctxpopup_item_insert_after(ctxpopup, item, "Another item", NULL, _ctxpopup_item_cb, NULL); evas_pointer_canvas_xy_get(evas_object_evas_get(obj), &x, &y); evas_object_size_hint_max_set(ctxpopup, 240, 240); diff --git a/src/lib/elc_ctxpopup.c b/src/lib/elc_ctxpopup.c index 3e90037..b004a81 100644 --- a/src/lib/elc_ctxpopup.c +++ b/src/lib/elc_ctxpopup.c @@ -1378,6 +1378,68 @@ _elm_ctxpopup_item_eo_base_constructor(Eo *obj, Elm_Ctxpopup_Item_Data *it) } EOLIAN static Elm_Object_Item* +_elm_ctxpopup_item_insert_before(Eo *obj, Elm_Ctxpopup_Data *sd, Elm_Object_Item *eo_before, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data) +{ + Eo *eo_item; + + EINA_SAFETY_ON_NULL_RETURN_VAL(eo_before, NULL); + ELM_CTXPOPUP_ITEM_DATA_GET(eo_before, before_it); + ELM_CTXPOPUP_ITEM_CHECK_OR_RETURN(before_it, NULL); + + if (!before_it->list_item) return NULL; + + eo_item = eo_add(ELM_CTXPOPUP_ITEM_CLASS, obj, elm_obj_ctxpopup_item_init(func, data)); + if (!eo_item) return NULL; + + ELM_CTXPOPUP_ITEM_DATA_GET(eo_item, item); + + item->list_item = + elm_list_item_insert_before(sd->list, before_it->list_item, label, icon, NULL, _item_wrap_cb, item); + eo_ref(item->list_item); + sd->items = eina_list_prepend_relative(sd->items, eo_item, eo_before); + + if (sd->visible) elm_layout_sizing_eval(obj); + + /* TIZEN_ONLY(20170710): add color_class parent-child relationship */ + Elm_Widget_Item_Data *wd = eo_data_scope_get(item->list_item, ELM_WIDGET_ITEM_CLASS); + VIEW(item) = wd->view; + /* END */ + + return eo_item; +} + +EOLIAN static Elm_Object_Item* +_elm_ctxpopup_item_insert_after(Eo *obj, Elm_Ctxpopup_Data *sd, Elm_Object_Item *eo_after, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data) +{ + Eo *eo_item; + + EINA_SAFETY_ON_NULL_RETURN_VAL(eo_after, NULL); + ELM_CTXPOPUP_ITEM_DATA_GET(eo_after, after_it); + ELM_CTXPOPUP_ITEM_CHECK_OR_RETURN(after_it, NULL); + + if (!after_it->list_item) return NULL; + + eo_item = eo_add(ELM_CTXPOPUP_ITEM_CLASS, obj, elm_obj_ctxpopup_item_init(func, data)); + if (!eo_item) return NULL; + + ELM_CTXPOPUP_ITEM_DATA_GET(eo_item, item); + + item->list_item = + elm_list_item_insert_after(sd->list, after_it->list_item, label, icon, NULL, _item_wrap_cb, item); + eo_ref(item->list_item); + sd->items = eina_list_append_relative(sd->items, eo_item, eo_after); + + if (sd->visible) elm_layout_sizing_eval(obj); + + /* TIZEN_ONLY(20170710): add color_class parent-child relationship */ + Elm_Widget_Item_Data *wd = eo_data_scope_get(item->list_item, ELM_WIDGET_ITEM_CLASS); + VIEW(item) = wd->view; + /* END */ + + return eo_item; +} + +EOLIAN static Elm_Object_Item* _elm_ctxpopup_item_append(Eo *obj, Elm_Ctxpopup_Data *sd, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data) { Eo *eo_item; diff --git a/src/lib/elm_ctxpopup.eo b/src/lib/elm_ctxpopup.eo index d390d24..46ec1ed 100644 --- a/src/lib/elm_ctxpopup.eo +++ b/src/lib/elm_ctxpopup.eo @@ -216,6 +216,40 @@ class Elm.Ctxpopup (Elm.Layout, Elm_Interface_Atspi_Widget_Action) \@endif ]] } + item_insert_before @internal { + [[Insert a new item to a ctxpopup object before item $before. + + See also elm_object_content_set. + + @since 1.21 + ]] + return: Elm.Widget_Item *; [[A handle to the item added or $null, on errors.]] + + params { + @in before: Elm.Widget_Item *; [[The ctxpopup item to insert before.]] + @in label: const(char)*; [[The Label of the new item]] + @in icon: Evas.Object * @optional; [[Icon to be set on new item]] + @in func: Evas_Smart_Cb @optional; [[Convenience function called when item selected]] + @in data: const(void)* @optional; [[Data passed to $func]] + } + } + item_insert_after @internal { + [[Insert a new item to a ctxpopup object after item $after. + + See also elm_object_content_set. + + @since 1.21 + ]] + return: Elm.Widget_Item *; [[A handle to the item added or $null, on errors.]] + + params { + @in after: Elm.Widget_Item *; [[The ctxpopup item to insert after.]] + @in label: const(char)*; [[The Label of the new item]] + @in icon: Evas.Object * @optional; [[Icon to be set on new item]] + @in func: Evas_Smart_Cb @optional; [[Convenience function called when item selected]] + @in data: const(void)* @optional; [[Data passed to $func]] + } + } item_append { [[Add a new item to a ctxpopup object. diff --git a/src/mobile_lib/elc_ctxpopup.c b/src/mobile_lib/elc_ctxpopup.c index 7317292..f9f024b 100644 --- a/src/mobile_lib/elc_ctxpopup.c +++ b/src/mobile_lib/elc_ctxpopup.c @@ -2234,6 +2234,20 @@ _item_new(Evas_Object *obj, } EOLIAN static Elm_Object_Item* +_elm_ctxpopup_item_insert_before(Eo *obj, Elm_Ctxpopup_Data *sd, Elm_Object_Item *eo_before, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data) +{ + // This will be implemented later on. + return NULL; +} + +EOLIAN static Elm_Object_Item* +_elm_ctxpopup_item_insert_after(Eo *obj, Elm_Ctxpopup_Data *sd, Elm_Object_Item *eo_after, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data) +{ + // This will be implemented later on. + return NULL; +} + +EOLIAN static Elm_Object_Item* _elm_ctxpopup_item_append(Eo *obj, Elm_Ctxpopup_Data *sd, const char *label, Evas_Object *icon, Evas_Smart_Cb func, const void *data) { Elm_Ctxpopup_Item_Data *item; -- 2.7.4