From 653766f0429e16655a5a9913be3c91766db2e1c6 Mon Sep 17 00:00:00 2001 From: seoz Date: Tue, 29 Nov 2011 14:03:14 +0000 Subject: [PATCH] elm genlist: Added elm_genlist_item_fields_update(). Patch by Hyoyoung Chang 2011/10/27 Hyoyoung Chang : > Dear developers > > I made a patch to add elm_genlist_item_fields_update function. > It can be used to updating genlist's item part without realize/unrealize > itself. > > Prototype is > elm_genlist_item_fields_update > (Elm_Genlist_Item *it, const char *part, Elm_Genlist_Item_Field_Flags itf) > > Part supports globbing. Passing "*" to part means updating all parts. > Item field can be one of icon, content and state. > I think it's useful to speed up if an app updates frequently. > > Thanks git-svn-id: svn+ssh://svn.enlightenment.org/var/svn/e/trunk/elementary@65688 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/bin/test_genlist.c | 24 ++++++++++--- src/lib/Elementary.h.in | 28 +++++++++++++++ src/lib/elm_genlist.c | 94 ++++++++++++++++++++++++++++++++++++++++++------- 3 files changed, 130 insertions(+), 16 deletions(-) diff --git a/src/bin/test_genlist.c b/src/bin/test_genlist.c index f97bc08..fa4f96e 100644 --- a/src/bin/test_genlist.c +++ b/src/bin/test_genlist.c @@ -567,6 +567,22 @@ my_gl_update(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED_ elm_genlist_item_update(tit->item); } +static void +my_gl_labels_update(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) +{ + Testitem *tit = data; + tit->mode++; + elm_genlist_item_fields_update(tit->item, "*", ELM_GENLIST_ITEM_FIELD_LABEL); +} + +static void +my_gl_contents_update(void *data, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) +{ + Testitem *tit = data; + tit->mode++; + elm_genlist_item_fields_update(tit->item, "*", ELM_GENLIST_ITEM_FIELD_CONTENT); +} + void test_genlist3(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_info __UNUSED__) { @@ -629,16 +645,16 @@ test_genlist3(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_in evas_object_show(bt); bt = elm_button_add(win); - elm_object_text_set(bt, "[2]"); - evas_object_smart_callback_add(bt, "clicked", my_gl_update, &(tit[1])); + elm_object_text_set(bt, "labels"); + evas_object_smart_callback_add(bt, "clicked", my_gl_labels_update, &(tit[1])); evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0); elm_box_pack_end(bx2, bt); evas_object_show(bt); bt = elm_button_add(win); - elm_object_text_set(bt, "[3]"); - evas_object_smart_callback_add(bt, "clicked", my_gl_update, &(tit[2])); + elm_object_text_set(bt, "contents"); + evas_object_smart_callback_add(bt, "clicked", my_gl_contents_update, &(tit[2])); evas_object_size_hint_align_set(bt, EVAS_HINT_FILL, EVAS_HINT_FILL); evas_object_size_hint_weight_set(bt, EVAS_HINT_EXPAND, 0.0); elm_box_pack_end(bx2, bt); diff --git a/src/lib/Elementary.h.in b/src/lib/Elementary.h.in index d2573e5..0499e57 100644 --- a/src/lib/Elementary.h.in +++ b/src/lib/Elementary.h.in @@ -18483,6 +18483,13 @@ extern "C" { ELM_GENLIST_ITEM_SUBITEMS = (1 << 0), /**< may expand and have child items */ ELM_GENLIST_ITEM_GROUP = (1 << 1) /**< index of a group of items */ } Elm_Genlist_Item_Flags; + typedef enum _Elm_Genlist_Item_Field_Flags + { + ELM_GENLIST_ITEM_FIELD_ALL = 0, + ELM_GENLIST_ITEM_FIELD_LABEL = (1 << 0), + ELM_GENLIST_ITEM_FIELD_CONTENT = (1 << 1), + ELM_GENLIST_ITEM_FIELD_STATE = (1 << 2) + } Elm_Genlist_Item_Field_Flags; typedef struct _Elm_Genlist_Item_Class Elm_Genlist_Item_Class; /**< Genlist item class definition structs */ #define Elm_Genlist_Item_Class Elm_Gen_Item_Class typedef struct _Elm_Genlist_Item Elm_Genlist_Item; /**< Item of Elm_Genlist. Sub-type of Elm_Widget_Item */ @@ -19565,6 +19572,27 @@ extern "C" { */ EAPI void elm_genlist_item_demote(Elm_Gen_Item *it) EINA_ARG_NONNULL(1); /** + * Update the part of an item + * + * @param it The item + * @param parts The name of item's part + * @param itf The flags of item's part type + * + * This updates an item's part by calling item's fetching functions again + * to get the icons, labels and states. Use this when the original + * item data has changed and the changes are desired to be reflected. + * Second parts argument is used for globbing to match '*', '?', and '.' + * It can be used at updating multi fields. + * + * Use elm_genlist_realized_items_update() to update an item's all + * property. + * + * @see elm_genlist_item_update() + * + * @ingroup Genlist + */ + EAPI void elm_genlist_item_fields_update(Elm_Genlist_Item *it, const char *parts, Elm_Genlist_Item_Field_Flags itf) EINA_ARG_NONNULL(1); + /** * Update the item class of an item * * @param it The item diff --git a/src/lib/elm_genlist.c b/src/lib/elm_genlist.c index 3eb2580..210d46e 100644 --- a/src/lib/elm_genlist.c +++ b/src/lib/elm_genlist.c @@ -1,5 +1,5 @@ #include - +#include #include #include #include "elm_priv.h" @@ -1651,7 +1651,8 @@ _item_del_hook(void *data __UNUSED__, Evas_Object *obj __UNUSED__, void *event_i static void _item_label_realize(Elm_Gen_Item *it, Evas_Object *target, - Eina_List **source) + Eina_List **source, + const char *parts) { if (it->itc->func.label_get) { @@ -1661,6 +1662,9 @@ _item_label_realize(Elm_Gen_Item *it, *source = elm_widget_stringlist_get(edje_object_data_get(target, "labels")); EINA_LIST_FOREACH(*source, l, key) { + if (parts && fnmatch(parts, key, FNM_PERIOD)) + continue; + char *s = it->itc->func.label_get ((void *)it->base.data, WIDGET(it), key); @@ -1678,9 +1682,42 @@ _item_label_realize(Elm_Gen_Item *it, } static Eina_List * +_item_content_unrealize(Elm_Gen_Item *it, + Evas_Object *target, + Eina_List **source, + const char *parts) +{ + Eina_List *res = it->content_objs; + + if (it->itc->func.content_get) + { + const Eina_List *l; + const char *key; + Evas_Object *ic = NULL; + + EINA_LIST_FOREACH(*source, l, key) + { + if (parts && fnmatch(parts, key, FNM_PERIOD)) + continue; + + ic = edje_object_part_swallow_get(target, key); + if (ic) + { + res = eina_list_remove(res, ic); + edje_object_part_unswallow(target, ic); + evas_object_del(ic); + } + } + } + + return res; +} + +static Eina_List * _item_content_realize(Elm_Gen_Item *it, Evas_Object *target, - Eina_List **source) + Eina_List **source, + const char *parts) { Eina_List *res = NULL; @@ -1691,8 +1728,15 @@ _item_content_realize(Elm_Gen_Item *it, Evas_Object *ic = NULL; *source = elm_widget_stringlist_get(edje_object_data_get(target, "contents")); + + if (parts && (eina_list_count(*source) != eina_list_count(it->content_objs))) + res = it->content_objs; + EINA_LIST_FOREACH(*source, l, key) { + if (parts && fnmatch(parts, key, FNM_PERIOD)) + continue; + if (it->itc->func.content_get) ic = it->itc->func.content_get ((void *)it->base.data, WIDGET(it), key); @@ -1714,7 +1758,8 @@ _item_content_realize(Elm_Gen_Item *it, static void _item_state_realize(Elm_Gen_Item *it, Evas_Object *target, - Eina_List **source) + Eina_List **source, + const char *parts) { if (it->itc->func.state_get) { @@ -1725,6 +1770,9 @@ _item_state_realize(Elm_Gen_Item *it, *source = elm_widget_stringlist_get(edje_object_data_get(target, "states")); EINA_LIST_FOREACH(*source, l, key) { + if (parts && fnmatch(parts, key, FNM_PERIOD)) + continue; + Eina_Bool on = it->itc->func.state_get ((void *)it->base.data, WIDGET(it), key); @@ -1883,9 +1931,9 @@ _item_realize(Elm_Gen_Item *it, will clean our mess */ assert(eina_list_count(it->content_objs) == 0); - _item_label_realize(it, VIEW(it), &it->labels); - it->content_objs = _item_content_realize(it, VIEW(it), &it->contents); - _item_state_realize(it, VIEW(it), &it->states); + _item_label_realize(it, VIEW(it), &it->labels, NULL); + it->content_objs = _item_content_realize(it, VIEW(it), &it->contents, NULL); + _item_state_realize(it, VIEW(it), &it->states, NULL); if (!it->item->mincalcd) { @@ -2854,11 +2902,11 @@ _mode_item_realize(Elm_Gen_Item *it) will clean our mess */ assert(eina_list_count(it->item->mode_content_objs) == 0); - _item_label_realize(it, it->item->mode_view, &it->item->mode_labels); - it->item->mode_content_objs = _item_content_realize(it, - it->item->mode_view, - &it->item->mode_contents); - _item_state_realize(it, it->item->mode_view, &it->item->mode_states); + _item_label_realize(it, it->item->mode_view, &it->item->mode_labels, NULL); + it->item->mode_content_objs = + _item_content_realize(it, it->item->mode_view, + &it->item->mode_contents, NULL); + _item_state_realize(it, it->item->mode_view, &it->item->mode_states, NULL); edje_object_part_swallow(it->item->mode_view, edje_object_data_get(it->item->mode_view, "mode_part"), @@ -4184,6 +4232,28 @@ elm_genlist_item_update(Elm_Gen_Item *it) } EAPI void +elm_genlist_item_fields_update(Elm_Genlist_Item *it, + const char *parts, + Elm_Genlist_Item_Field_Flags itf) +{ + ELM_WIDGET_ITEM_WIDTYPE_CHECK_OR_RETURN(it); + if (!it->item->block) return; + if (it->delete_me) return; + + if ((!itf) || (itf & ELM_GENLIST_ITEM_FIELD_LABEL)) + _item_label_realize(it, it->base.view, &it->labels, parts); + if ((!itf) || (itf & ELM_GENLIST_ITEM_FIELD_CONTENT)) + { + it->content_objs = _item_content_unrealize(it, it->base.view, + &it->contents, parts); + it->content_objs = _item_content_realize(it, it->base.view, + &it->contents, parts); + } + if ((!itf) || (itf & ELM_GENLIST_ITEM_FIELD_STATE)) + _item_state_realize(it, it->base.view, &it->states, parts); +} + +EAPI void elm_genlist_item_item_class_update(Elm_Gen_Item *it, const Elm_Genlist_Item_Class *itc) { -- 2.7.4