From a69cc68c578d731ebb0be763971f7c596e94706b Mon Sep 17 00:00:00 2001 From: Bruno Dilly Date: Wed, 17 Nov 2010 17:15:28 +0000 Subject: [PATCH] Add elm_genlist_item_item_class_update 1. elm_genlist_item_item_class_update() API It is required to change an item's item class on run-time. Applications want to change a certain item's style and callbacks dynamically. This looks ok because changing one item's style does not affect performance, And this API uses elm_genlist_item_update internally. API name follows elementary naming conventions. I've also added test code to elementary_test, Genlist 7. 2. constant to macro. I replaced 2 constants for max_item_per_block and longpress_timeout to macros. This could be used in other places of the code. 3. duplicated assignment. In elm_genlist_item_append, it->before = 0 is written in if and else. I put this statement out of if(). 4. fix doxygen typo I fixed elm_genlist_compress_mode_set doxygen. By: Daniel Juyung Seo SVN revision: 54639 --- legacy/elementary/src/bin/test_genlist.c | 21 ++++++++++++--- legacy/elementary/src/lib/Elementary.h.in | 1 + legacy/elementary/src/lib/elm_genlist.c | 32 ++++++++++++++++++----- 3 files changed, 45 insertions(+), 9 deletions(-) diff --git a/legacy/elementary/src/bin/test_genlist.c b/legacy/elementary/src/bin/test_genlist.c index 450fc4fde2..52f07fde72 100644 --- a/legacy/elementary/src/bin/test_genlist.c +++ b/legacy/elementary/src/bin/test_genlist.c @@ -1195,6 +1195,15 @@ struct genlist7_data Evas_Object *win, *pager; }; +static Elm_Genlist_Item_Class itc7; +static void +gl_sel7(void *data, Evas_Object *obj, void *event_info) +{ + if (!event_info) return; + elm_genlist_item_item_class_update(event_info, &itc7); + printf("sel item data [%p] on genlist obj [%p], item pointer [%p], new item style [%s] \n", data, obj, event_info, itc7.item_style); +} + static void test_genlist7_back_cb(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) { @@ -1277,20 +1286,26 @@ test_genlist7(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_in itc2.func.state_get = gl2_state_get; itc2.func.del = gl2_del; + itc7.item_style = "double_label"; + itc7.func.label_get = gl5_label_get; + itc7.func.icon_get = gl5_icon_get; + itc7.func.state_get = gl5_state_get; + itc7.func.del = gl5_del; + tit[0].mode = 0; tit[0].item = elm_genlist_item_append(gl, &itc2, &(tit[0])/* item data */, NULL/* parent */, - ELM_GENLIST_ITEM_NONE, gl_sel/* func */, + ELM_GENLIST_ITEM_NONE, gl_sel7/* func */, NULL/* func data */); tit[1].mode = 1; tit[1].item = elm_genlist_item_append(gl, &itc2, &(tit[1])/* item data */, NULL/* parent */, - ELM_GENLIST_ITEM_NONE, gl_sel/* func */, + ELM_GENLIST_ITEM_NONE, gl_sel7/* func */, NULL/* func data */); tit[2].mode = 2; tit[2].item = elm_genlist_item_append(gl, &itc2, &(tit[2])/* item data */, NULL/* parent */, - ELM_GENLIST_ITEM_NONE, gl_sel/* func */, + ELM_GENLIST_ITEM_NONE, gl_sel7/* func */, NULL/* func data */); evas_object_resize(win, 320, 320); diff --git a/legacy/elementary/src/lib/Elementary.h.in b/legacy/elementary/src/lib/Elementary.h.in index d8dd985789..9594917842 100644 --- a/legacy/elementary/src/lib/Elementary.h.in +++ b/legacy/elementary/src/lib/Elementary.h.in @@ -1665,6 +1665,7 @@ extern "C" { EAPI void elm_genlist_item_icons_orphan(Elm_Genlist_Item *it); EAPI const Evas_Object *elm_genlist_item_object_get(const Elm_Genlist_Item *it); EAPI void elm_genlist_item_update(Elm_Genlist_Item *item); + EAPI void elm_genlist_item_item_class_update(Elm_Genlist_Item *it, const Elm_Genlist_Item_Class *itc); EAPI void elm_genlist_item_tooltip_text_set(Elm_Genlist_Item *item, const char *text); EAPI void elm_genlist_item_tooltip_content_cb_set(Elm_Genlist_Item *item, Elm_Tooltip_Item_Content_Cb func, const void *data, Evas_Smart_Cb del_cb); EAPI void elm_genlist_item_tooltip_unset(Elm_Genlist_Item *item); diff --git a/legacy/elementary/src/lib/elm_genlist.c b/legacy/elementary/src/lib/elm_genlist.c index 895324453e..7e47866b1f 100644 --- a/legacy/elementary/src/lib/elm_genlist.c +++ b/legacy/elementary/src/lib/elm_genlist.c @@ -3,6 +3,8 @@ #include "elm_priv.h" #define SWIPE_MOVES 12 +#define MAX_ITEMS_PER_BLOCK 32 +#define LONGPRESS_TIMEOUT 1.0 /** * @defgroup Genlist Genlist @@ -2123,9 +2125,9 @@ elm_genlist_add(Evas_Object *parent) wd->obj = obj; wd->mode = ELM_LIST_SCROLL; - wd->max_items_per_block = 32; + wd->max_items_per_block = MAX_ITEMS_PER_BLOCK; wd->item_cache_max = wd->max_items_per_block * 2; - wd->longpress_timeout = 1.0; + wd->longpress_timeout = LONGPRESS_TIMEOUT; evas_object_smart_callback_add(obj, "scroll-hold-on", _hold_on, obj); evas_object_smart_callback_add(obj, "scroll-hold-off", _hold_off, obj); @@ -2423,7 +2425,6 @@ elm_genlist_item_append(Evas_Object *obj, const Elm_Genlist_Item_Class *itc, { wd->items = eina_inlist_append(wd->items, EINA_INLIST_GET(it)); it->rel = NULL; - it->before = 0; } else { @@ -2437,8 +2438,8 @@ elm_genlist_item_append(Evas_Object *obj, const Elm_Genlist_Item_Class *itc, EINA_INLIST_GET(it2)); it->rel = it2; it->rel->relcount++; - it->before = 0; } + it->before = 0; _item_queue(wd, it); return it; } @@ -3555,6 +3556,25 @@ elm_genlist_item_update(Elm_Genlist_Item *it) it->wd->update_job = ecore_job_add(_update_job, it->wd); } +/** + * Update the item class of an item + * + * @param it The item + * @parem itc The item class for the item + * + * @ingroup Genlist + */ +EAPI void +elm_genlist_item_item_class_update(Elm_Genlist_Item *it, const Elm_Genlist_Item_Class *itc) +{ + ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it); + if (!it->block) return; + if (!itc) return; + if (it->delete_me) return; + it->itc = itc; + elm_genlist_item_update(it); +} + static Evas_Object * _elm_genlist_item_label_create(void *data, Evas_Object *obj, void *item __UNUSED__) { @@ -3960,8 +3980,8 @@ elm_genlist_no_select_mode_get(const Evas_Object *obj) * Set compress mode * * This will enable the compress mode where items are "compressed" horizontally - * to fit the genlist scrollable viewport width. this is special for gnelist. - * do not rely on elm_genlist_horizontal_mode_set() being set to + * to fit the genlist scrollable viewport width. This is special for genlist. + * Do not rely on elm_genlist_horizontal_mode_set() being set to * ELM_LIST_COMPRESS to work as genlist needs to handle it specially. * * @param obj The genlist object