all this for elm_theme_data_get

SVN revision: 63331
This commit is contained in:
Mike Blumenkrantz 2011-09-12 01:05:07 +00:00
parent 821ad97778
commit f0cdbd0da3
3 changed files with 103 additions and 1 deletions

View File

@ -3439,6 +3439,18 @@ extern "C" {
* for more information.
*/
EAPI Elm_Theme *elm_object_theme_get(const Evas_Object *obj) EINA_ARG_NONNULL(1);
/**
* Get a data item from a theme
*
* @param th The theme, or NULL for default theme
* @param key The data key to search with
* @return The data value, or NULL on failure
*
* This function is used to return data items from edc in @p th, an overlay, or an extension.
* It works the same way as edje_file_data_get() except that the return is stringshared.
*/
EAPI const char *elm_theme_data_get(Elm_Theme *th, const char *key) EINA_ARG_NONNULL(2);
/**
* @}
*/

View File

@ -44,6 +44,7 @@ struct _Elm_Theme
Eina_List *themes;
Eina_List *extension;
Eina_Hash *cache;
Eina_Hash *cache_data;
Elm_Theme *ref_theme;
Eina_List *referrers;
const char *theme;

View File

@ -3,7 +3,7 @@
static Elm_Theme theme_default =
{
NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1
NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, 1
};
static Eina_List *themes = NULL;
@ -23,6 +23,11 @@ _elm_theme_clear(Elm_Theme *th)
eina_hash_free(th->cache);
th->cache = NULL;
}
if (th->cache_data)
{
eina_hash_free(th->cache_data);
th->cache_data = NULL;
}
if (th->theme)
{
eina_stringshare_del(th->theme);
@ -110,6 +115,79 @@ _elm_theme_group_file_find(Elm_Theme *th, const char *group)
return NULL;
}
static const char *
_elm_theme_find_data_try(Elm_Theme *th, const char *f, const char *key)
{
char *data;
const char *t;
data = edje_file_data_get(f, key);
t = eina_stringshare_add(data);
free(data);
if (t)
{
eina_hash_add(th->cache, key, t);
return t;
}
return NULL;
}
static const char *
_elm_theme_theme_data_try(Elm_Theme *th, const char *home, const char *f, const char *key)
{
char buf[PATH_MAX];
const char *data = NULL;
if ((f[0] == '/') || ((f[0] == '.') && (f[1] == '/')) ||
((f[0] == '.') && (f[1] == '.') && (f[2] == '/')) ||
((isalpha(f[0])) && (f[1] == ':')))
return _elm_theme_find_data_try(th, f, key);
else if (((f[0] == '~') && (f[1] == '/')))
{
snprintf(buf, sizeof(buf), "%s/%s", home, f + 2);
return _elm_theme_find_try(th, buf, key);
}
snprintf(buf, sizeof(buf), "%s/.elementary/themes/%s.edj", home, f);
data = _elm_theme_find_data_try(th, buf, key);
if (data) return data;
snprintf(buf, sizeof(buf), "%s/themes/%s.edj", _elm_data_dir, f);
data = _elm_theme_find_data_try(th, buf, key);
return data;
}
static const char *
_elm_theme_data_find(Elm_Theme *th, const char *key)
{
const Eina_List *l;
const char *f;
static const char *home = NULL;
const char *data = eina_hash_find(th->cache_data, key);
if (data) return data;
if (!home)
{
home = getenv("HOME");
if (!home) home = "";
}
EINA_LIST_FOREACH(th->overlay, l, f)
{
data = _elm_theme_theme_data_try(th, home, f, key);
if (data) return data;
}
EINA_LIST_FOREACH(th->themes, l, f)
{
data = _elm_theme_theme_data_try(th, home, f, key);
if (data) return data;
}
EINA_LIST_FOREACH(th->extension, l, f)
{
data = _elm_theme_theme_data_try(th, home, f, key);
if (data) return data;
}
if (th->ref_theme) return _elm_theme_data_find(th->ref_theme, key);
return NULL;
}
Eina_Bool
_elm_theme_object_set(Evas_Object *parent, Evas_Object *o, const char *clas, const char *group, const char *style)
{
@ -224,6 +302,8 @@ _elm_theme_parse(Elm_Theme *th, const char *theme)
}
if (th->cache) eina_hash_free(th->cache);
th->cache = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del));
if (th->cache_data) eina_hash_free(th->cache_data);
th->cache_data = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del));
EINA_LIST_FREE(th->themes, p) eina_stringshare_del(p);
@ -487,6 +567,8 @@ elm_theme_flush(Elm_Theme *th)
if (!th) th = &(theme_default);
if (th->cache) eina_hash_free(th->cache);
th->cache = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del));
if (th->cache_data) eina_hash_free(th->cache_data);
th->cache_data = eina_hash_string_superfast_new(EINA_FREE_CB(eina_stringshare_del));
_elm_win_rescale(th, EINA_TRUE);
if (th->referrers)
{
@ -610,3 +692,10 @@ elm_object_theme_get(const Evas_Object *obj)
EINA_SAFETY_ON_NULL_RETURN_VAL(obj, NULL);
return elm_widget_theme_get(obj);
}
EAPI const char *
elm_theme_data_get(Elm_Theme *th, const char *key)
{
if (!th) th = &(theme_default);
return _elm_theme_data_find(th, key);
}