From 1e2b58a8c8e735983c4af07c1784a9759e6c4622 Mon Sep 17 00:00:00 2001 From: "shashank.p" Date: Mon, 9 Nov 2015 16:03:05 -0800 Subject: [PATCH] genlist: modified first/last/prev/next get API for filtered list. Summary: elm_genlist_first_item_get(), elm_genlist_last_item_get(), elm_genlist_item_prev_get(), elm_genlist_item_next_get() should return the next filtered item if filter is applied on the genlist. Test Plan: test_genlist.c => Genlist Filter demo updated Reviewers: shilpasingh, cedric, SanghyeonLee Subscribers: divyesh, rajeshps Differential Revision: https://phab.enlightenment.org/D3263 Signed-off-by: Cedric BAIL --- legacy/elementary/src/bin/test_genlist.c | 19 ++--- legacy/elementary/src/lib/elm_genlist.c | 72 ++++++++++++++++--- legacy/elementary/src/lib/elm_genlist.eo | 6 ++ .../elementary/src/lib/elm_genlist_common.h | 5 ++ legacy/elementary/src/lib/elm_genlist_item.eo | 6 ++ 5 files changed, 91 insertions(+), 17 deletions(-) diff --git a/legacy/elementary/src/bin/test_genlist.c b/legacy/elementary/src/bin/test_genlist.c index 2dd636e331..9ed37254e6 100644 --- a/legacy/elementary/src/bin/test_genlist.c +++ b/legacy/elementary/src/bin/test_genlist.c @@ -4996,7 +4996,6 @@ _entry_change_cb(void *data, Evas_Object *obj, void *event EINA_UNUSED) { api_data *api = (api_data *)data; char buf[100]; - Eina_Iterator *filter_iter; unsigned int count = 0; Elm_Object_Item *item; @@ -5010,15 +5009,19 @@ _entry_change_cb(void *data, Evas_Object *obj, void *event EINA_UNUSED) printf("Input data string empty; returning\n"); return; } - filter_iter = elm_genlist_filter_iterator_new(api->gl); - - EINA_ITERATOR_FOREACH(filter_iter, item) - if (item) count++; + item = elm_genlist_first_item_get(api->gl); + if (!item) + { + printf("No matches for the key %s\n", buf); + return; + } + while (item) + { + ++count; + item = elm_genlist_item_next_get(item); + } printf("Number of matches for %s is %d\n", buf, count); - //Iterator needs to be freed by application using eina_iterator_free - eina_iterator_free(filter_iter); - } void diff --git a/legacy/elementary/src/lib/elm_genlist.c b/legacy/elementary/src/lib/elm_genlist.c index a706bd947b..3c51e40d41 100644 --- a/legacy/elementary/src/lib/elm_genlist.c +++ b/legacy/elementary/src/lib/elm_genlist.c @@ -6526,7 +6526,22 @@ _elm_genlist_at_xy_item_get(const Eo *obj EINA_UNUSED, Elm_Genlist_Data *sd, Eva EOLIAN static Elm_Object_Item* _elm_genlist_first_item_get(Eo *obj EINA_UNUSED, Elm_Genlist_Data *sd) { - return EO_OBJ(ELM_GEN_ITEM_FROM_INLIST(sd->items)); + Elm_Gen_Item *it = ELM_GEN_ITEM_FROM_INLIST(sd->items); + + if (!sd->filter) + { + return EO_OBJ(it); + } + else + { + while (it) + { + if (_item_filtered_get(it)) break; + it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next); + } + if (it) return EO_OBJ(it); + return NULL; + } } EOLIAN static Elm_Object_Item* @@ -6535,19 +6550,44 @@ _elm_genlist_last_item_get(Eo *obj EINA_UNUSED, Elm_Genlist_Data *sd) Elm_Gen_Item *it; if (!sd->items) return NULL; - it = ELM_GEN_ITEM_FROM_INLIST(sd->items->last); - return EO_OBJ(it); + if (!sd->filter) + { + return EO_OBJ(it); + } + else + { + while (it) + { + if (_item_filtered_get(it)) break; + it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev); + } + if (it) return EO_OBJ(it); + return NULL; + } } EOLIAN static Elm_Object_Item * _elm_genlist_item_next_get(Eo *eo_it EINA_UNUSED, Elm_Gen_Item *it) { - while (it) + ELM_GENLIST_DATA_GET_FROM_ITEM(it, sd); + + if (!sd->filter) { - it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next); - if (it) break; + while (it) + { + it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next); + if (it) break; + } + } + else + { + while (it) + { + it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->next); + if (it && _item_filtered_get(it)) break; + } } if (it) return EO_OBJ(it); @@ -6557,10 +6597,24 @@ _elm_genlist_item_next_get(Eo *eo_it EINA_UNUSED, Elm_Gen_Item *it) EOLIAN static Elm_Object_Item * _elm_genlist_item_prev_get(Eo *eo_it EINA_UNUSED, Elm_Gen_Item *it) { - while (it) + ELM_GENLIST_DATA_GET_FROM_ITEM(it, sd); + + if (!it) return NULL; + if (!sd->filter) { - it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev); - if (it) break; + while (it) + { + it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev); + if (it) break; + } + } + else + { + while (it) + { + it = ELM_GEN_ITEM_FROM_INLIST(EINA_INLIST_GET(it)->prev); + if (it && _item_filtered_get(it)) break; + } } if (it) return EO_OBJ(it); diff --git a/legacy/elementary/src/lib/elm_genlist.eo b/legacy/elementary/src/lib/elm_genlist.eo index 5bf03a5889..ebe07333ab 100644 --- a/legacy/elementary/src/lib/elm_genlist.eo +++ b/legacy/elementary/src/lib/elm_genlist.eo @@ -283,6 +283,9 @@ class Elm.Genlist (Elm.Layout, Elm_Interface_Scrollable, Evas.Clickable_Interfac [[Get the first item in the genlist. This returns the first item in the list. + + If filter is set on genlist, it returns + the first filtered item in the list. ]] return: Elm.Widget_Item *; [[The first item or $null.]] } @@ -323,6 +326,9 @@ class Elm.Genlist (Elm.Layout, Elm_Interface_Scrollable, Evas.Clickable_Interfac [[Get the last item in the genlist This returns the last item in the list. + + If filter is set to genlist, it returns + last filtered item in the list. ]] return: Elm.Widget_Item *; } diff --git a/legacy/elementary/src/lib/elm_genlist_common.h b/legacy/elementary/src/lib/elm_genlist_common.h index d3ed39d2c6..b1d1d9f1bb 100644 --- a/legacy/elementary/src/lib/elm_genlist_common.h +++ b/legacy/elementary/src/lib/elm_genlist_common.h @@ -26,6 +26,11 @@ typedef Elm_Gen_Item_State_Get_Cb Elm_Genlist_Item_State_Get_Cb; */ typedef Elm_Gen_Item_Del_Cb Elm_Genlist_Item_Del_Cb; +/** + * @see Elm_Gen_Item_Filter_Get_Cb + */ +typedef Elm_Gen_Item_Filter_Get_Cb Elm_Genlist_Item_Filter_Get_Cb; + /** * Create a new genlist item class in a given genlist widget. * diff --git a/legacy/elementary/src/lib/elm_genlist_item.eo b/legacy/elementary/src/lib/elm_genlist_item.eo index ef35ded795..e78c956845 100644 --- a/legacy/elementary/src/lib/elm_genlist_item.eo +++ b/legacy/elementary/src/lib/elm_genlist_item.eo @@ -47,6 +47,9 @@ class Elm.Genlist_Item(Elm.Widget_Item) This returns the item placed before the $item, on the container genlist. + + If filter is set on genlist, this returns the filtered + item placed before $item in the list. ]] } values { @@ -60,6 +63,9 @@ class Elm.Genlist_Item(Elm.Widget_Item) This returns the item placed after the $item, on the container genlist. + + If filter is set on genlist, this returns the filtered + item placed after $item in the list. ]] } values {