From 399bb5a0baca0f3be33d31d318e28b9ad3bfbf00 Mon Sep 17 00:00:00 2001 From: Jee-Yong Um Date: Fri, 8 Jul 2016 10:50:16 -0700 Subject: [PATCH] edje: add a helper for recursive searching in hash Summary: If color class of an edje part is defined as "aaa/bbb/ccc/ddd", edje will search for color class by the following sequence. "aaa/bbb/ccc/ddd" "aaa/bbb/ddd" "aaa/ddd" "ddd" So, without additional lookup table, edje classes (color, text, size) can have the functionality like inheritance. Reviewers: jpeg, raster, cedric Subscribers: cedric Differential Revision: https://phab.enlightenment.org/D4127 Signed-off-by: Cedric Bail --- src/lib/edje/edje_util.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 48 insertions(+), 1 deletion(-) diff --git a/src/lib/edje/edje_util.c b/src/lib/edje/edje_util.c index 41c6989..83f8d1c 100644 --- a/src/lib/edje/edje_util.c +++ b/src/lib/edje/edje_util.c @@ -6028,6 +6028,53 @@ _edje_real_part_get(const Edje *ed, const char *part) return NULL; } +void * +_edje_hash_find_helper(const Eina_Hash *hash, const char *key) +{ + void *data; + int i, j; + char **tokens; + unsigned int tokens_count = 0; + Eina_Strbuf *buf = NULL; + + data = eina_hash_find(hash, key); + if (data) + return data; + + tokens = eina_str_split_full(key, "/", 0, &tokens_count); + + if ((tokens) && (tokens_count > 1)) + { + buf = eina_strbuf_new(); + + for (i = tokens_count - 2; i >= 0; i--) + { + for (j = 0; j < i; j++) + { + eina_strbuf_append(buf, tokens[j]); + eina_strbuf_append(buf, "/"); + } + eina_strbuf_append(buf, tokens[tokens_count - 1]); + + data = eina_hash_find(hash, eina_strbuf_string_get(buf)); + if (data) break; + + eina_strbuf_reset(buf); + } + } + + if (buf) + { + eina_strbuf_free(buf); + } + if (tokens) + { + free(tokens[0]); + free(tokens); + } + return data; +} + Edje_Color_Class * _edje_color_class_find(const Edje *ed, const char *color_class) { @@ -6057,7 +6104,7 @@ _edje_color_class_recursive_find_helper(const Edje *ed, Eina_Hash *hash, const c Edje_Color_Tree_Node *ctn = NULL; const char *parent; - cc = eina_hash_find(hash, color_class); + cc = _edje_hash_find_helper(hash, color_class); if (cc) return cc; else { -- 2.7.4