From: Enlightenment S. <no-...@en...> - 2011-11-29 14:03:28
|
Log: elm genlist: Added elm_genlist_item_fields_update(). Patch by Hyoyoung Chang <hyo...@sa...> 2011/10/27 Hyoyoung Chang <hyo...@sa...>: > 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 Author: seoz Date: 2011-11-29 06:03:14 -0800 (Tue, 29 Nov 2011) New Revision: 65688 Trac: http://trac.enlightenment.org/e/changeset/65688 Modified: trunk/elementary/src/bin/test_genlist.c trunk/elementary/src/lib/Elementary.h.in trunk/elementary/src/lib/elm_genlist.c Modified: trunk/elementary/src/bin/test_genlist.c =================================================================== --- trunk/elementary/src/bin/test_genlist.c 2011-11-29 09:40:49 UTC (rev 65687) +++ trunk/elementary/src/bin/test_genlist.c 2011-11-29 14:03:14 UTC (rev 65688) @@ -567,6 +567,22 @@ 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 @@ 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); Modified: trunk/elementary/src/lib/Elementary.h.in =================================================================== --- trunk/elementary/src/lib/Elementary.h.in 2011-11-29 09:40:49 UTC (rev 65687) +++ trunk/elementary/src/lib/Elementary.h.in 2011-11-29 14:03:14 UTC (rev 65688) @@ -18483,6 +18483,13 @@ 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 @@ */ 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 Modified: trunk/elementary/src/lib/elm_genlist.c =================================================================== --- trunk/elementary/src/lib/elm_genlist.c 2011-11-29 09:40:49 UTC (rev 65687) +++ trunk/elementary/src/lib/elm_genlist.c 2011-11-29 14:03:14 UTC (rev 65688) @@ -1,5 +1,5 @@ #include <assert.h> - +#include <fnmatch.h> #include <Elementary.h> #include <Elementary_Cursor.h> #include "elm_priv.h" @@ -1651,7 +1651,8 @@ 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 @@ *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 @@ } 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 @@ 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 @@ 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 @@ *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 @@ 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 @@ 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 @@ } 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) { |