From a2532b8ef0a69b00019d3ea5cf87032de4fdd201 Mon Sep 17 00:00:00 2001 From: Andrii Kroitor Date: Wed, 15 Nov 2017 10:41:45 +0200 Subject: [PATCH] genlist: fix state corruption of content When using reusable content, genlist preserves old object's state and is expecting reusable_content_get callback to change all needed properties. But there was an inconsistency: it was silently re-enabling the old content. @fix --- src/bin/elementary/test_genlist.c | 26 +++++++++++++++++++++++--- src/lib/elementary/elm_genlist.c | 3 --- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/bin/elementary/test_genlist.c b/src/bin/elementary/test_genlist.c index 789b7b0..7db6920 100644 --- a/src/bin/elementary/test_genlist.c +++ b/src/bin/elementary/test_genlist.c @@ -5537,23 +5537,43 @@ gl_re2_reusable_content_get(void *data, Evas_Object *obj, int num = (int)(uintptr_t)data; char buf[64]; + // Returning NULL from this callback means that content_get should be used instead. + // In this case if old object is not NULL, it will be deleted by genlist. if (!enabled || !old) return NULL; + // Genlist preserves whole state of the old content. + // But we don't know for which item it was used before. We know only that + // the old item had same item_class, same tree mode and that content was created for "part". + // This means that we should apply all item-specific properties to the old object. if (!strcmp(part, "elm.swallow.icon")) { printf("REUSING content (icon) for item # %d\n", num); - snprintf(buf, sizeof(buf), "Content for item # %d", num); + // No need to change color, because all contents for "elm.swallow.icon" + // have same red color + snprintf(buf, sizeof(buf), "Reused content for item # %d", num); + // But we need to set correct text, because it's different for different items elm_object_text_set(old, buf); + // Object is ready for use. return old; } if (!strcmp(part, "elm.swallow.end")) { printf("REUSING content (end) for item # %d\n", num); - snprintf(buf, sizeof(buf), "Content for item # %d", num); + // Also not changing color, it's already correct. + snprintf(buf, sizeof(buf), "Reused content for item # %d", num); + // Updating text. elm_object_text_set(old, buf); - if ((num % 5) == 0) elm_object_disabled_set(old, EINA_TRUE); + // Changing disabled state of content: + if ((num % 5) == 0) + // disabling every 5th item's content in the same way as in content_get + elm_object_disabled_set(old, EINA_TRUE); + else + // but also explicitly enabling other contents, because the old object + // could be disabled if it was used in one of the 5th items previously + elm_object_disabled_set(old, EINA_FALSE); + // Object is ready for use. return old; } diff --git a/src/lib/elementary/elm_genlist.c b/src/lib/elementary/elm_genlist.c index 6fb54d3..c2d59bb 100644 --- a/src/lib/elementary/elm_genlist.c +++ b/src/lib/elementary/elm_genlist.c @@ -1695,9 +1695,6 @@ _content_cache_add(Elm_Gen_Item *it, Eina_List **cache) Evas_Object *content = NULL; EINA_LIST_FREE(it->contents, content) { - if (efl_isa(content, ELM_WIDGET_CLASS) && elm_widget_disabled_get(content)) - elm_widget_disabled_set(content, EINA_FALSE); - *cache = eina_list_append(*cache, content); eina_hash_del_by_key(pd->content_item_map, &content); } -- 2.7.4