From 91848c5b433fbb2b0f2e6132b884b2b9b071ce96 Mon Sep 17 00:00:00 2001 From: Michael Bouchaud Date: Wed, 18 Sep 2013 00:46:46 +0200 Subject: [PATCH] elementary: add a way to add some custom part text and save it for Elm_Object_Item --- legacy/elementary/src/lib/elm_list.c | 5 ++- legacy/elementary/src/lib/elm_widget.c | 79 ++++++++++++++++++++++++++++++++++ legacy/elementary/src/lib/elm_widget.h | 25 +++++++++++ 3 files changed, 108 insertions(+), 1 deletion(-) diff --git a/legacy/elementary/src/lib/elm_list.c b/legacy/elementary/src/lib/elm_list.c index 086335c..3c8c314 100644 --- a/legacy/elementary/src/lib/elm_list.c +++ b/legacy/elementary/src/lib/elm_list.c @@ -707,6 +707,7 @@ _items_fix(Evas_Object *obj) { edje_object_part_text_escaped_set (VIEW(it), "elm.text", it->label); + elm_widget_item_part_text_custom_update(it); if ((!it->icon) && (minh[0] > 0)) { @@ -1411,6 +1412,7 @@ _item_text_set_hook(Elm_Object_Item *it, if (part && strcmp(part, "default")) { + elm_widget_item_part_text_custom_set(list_it, part, text); edje_object_part_text_escaped_set(VIEW(list_it), part, text); return; } @@ -1423,7 +1425,8 @@ static const char * _item_text_get_hook(const Elm_Object_Item *it, const char *part) { - if (part && strcmp(part, "default")) return NULL; + if (part && strcmp(part, "default")) + return elm_widget_item_part_text_custom_get(it, part); return ((Elm_List_Item *)it)->label; } diff --git a/legacy/elementary/src/lib/elm_widget.c b/legacy/elementary/src/lib/elm_widget.c index 3c20ecc..235fc15 100644 --- a/legacy/elementary/src/lib/elm_widget.c +++ b/legacy/elementary/src/lib/elm_widget.c @@ -30,6 +30,7 @@ EAPI Eo_Op ELM_WIDGET_BASE_ID = EO_NOOP; (elm_widget_focus_get(obj))) typedef struct _Elm_Event_Cb_Data Elm_Event_Cb_Data; +typedef struct _Elm_Label_Data Elm_Label_Data; typedef struct _Elm_Translate_String_Data Elm_Translate_String_Data; struct _Elm_Event_Cb_Data @@ -38,6 +39,12 @@ struct _Elm_Event_Cb_Data const void *data; }; +struct _Elm_Label_Data +{ + const char *part; + const char *text; +}; + struct _Elm_Translate_String_Data { EINA_INLIST; @@ -5003,6 +5010,7 @@ _elm_widget_item_free(Elm_Widget_Item *item) item->translate_strings); free(ts); } + eina_hash_free(item->labels); EINA_MAGIC_SET(item, EINA_MAGIC_NONE); free(item); @@ -5754,6 +5762,77 @@ _elm_widget_item_part_text_get(const Elm_Widget_Item *item, return item->text_get_func((Elm_Object_Item *)item, part); } +static void +_elm_widget_item_part_text_custom_free(void *data) +{ + Elm_Label_Data *label; + label = data; + eina_stringshare_del(label->part); + eina_stringshare_del(label->text); + free(label); +} + +EAPI void +_elm_widget_item_part_text_custom_set(Elm_Widget_Item *item, + const char *part, + const char *text) +{ + Elm_Label_Data *label; + ELM_WIDGET_ITEM_CHECK_OR_RETURN(item); + + if (!item->text_get_func) + { + ERR("%s does not support elm_object_item_part_text_get() API.", + elm_widget_type_get(item->widget)); + return; + } + if (!item->labels) + item->labels = + eina_hash_stringshared_new(_elm_widget_item_part_text_custom_free); + label = eina_hash_find(item->labels, part); + if (!label) + { + label = malloc(sizeof(Elm_Label_Data)); + label->part = eina_stringshare_add(part); + label->text = eina_stringshare_add(text); + eina_hash_add(item->labels, part, label); + } + else + eina_stringshare_replace(&label->text, text); +} + +EAPI const char * +_elm_widget_item_part_text_custom_get(Elm_Widget_Item *item, + const char *part) +{ + Elm_Label_Data *label; + ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, NULL); + label = eina_hash_find(item->labels, part); + return label ? label->text : NULL; +} + +static Eina_Bool +_elm_widget_item_part_text_custom_foreach(const Eina_Hash *labels EINA_UNUSED, + const void *key EINA_UNUSED, + void *data, + void *func_data) +{ + Elm_Label_Data *label; + Elm_Widget_Item *item; + label = data; + item = func_data; + item->text_set_func((Elm_Object_Item *)item, label->part, label->text); + return EINA_TRUE; +} + +EAPI void +_elm_widget_item_part_text_custom_update(Elm_Widget_Item *item) +{ + ELM_WIDGET_ITEM_CHECK_OR_RETURN(item); + eina_hash_foreach(item->labels, + _elm_widget_item_part_text_custom_foreach, item); +} + EAPI void _elm_widget_item_content_set_hook_set(Elm_Widget_Item *item, Elm_Widget_Content_Set_Cb func) diff --git a/legacy/elementary/src/lib/elm_widget.h b/legacy/elementary/src/lib/elm_widget.h index fb85c2a..c735b2d 100644 --- a/legacy/elementary/src/lib/elm_widget.h +++ b/legacy/elementary/src/lib/elm_widget.h @@ -579,6 +579,7 @@ struct _Elm_Widget_Item Eina_List *access_order; Eina_Inlist *translate_strings; Eina_List *signals; + Eina_Hash *labels; Evas_Object *track_obj; Eina_Bool disabled : 1; @@ -753,6 +754,9 @@ EAPI Evas_Object *_elm_widget_item_part_content_get(const Elm_Widget_Item *i EAPI Evas_Object *_elm_widget_item_part_content_unset(Elm_Widget_Item *item, const char *part); EAPI void _elm_widget_item_part_text_set(Elm_Widget_Item *item, const char *part, const char *label); EAPI const char *_elm_widget_item_part_text_get(const Elm_Widget_Item *item, const char *part); +EAPI void _elm_widget_item_part_text_custom_set(Elm_Widget_Item *item, const char *part, const char *label); +EAPI const char *_elm_widget_item_part_text_custom_get(Elm_Widget_Item *item, const char *part); +EAPI void _elm_widget_item_part_text_custom_update(Elm_Widget_Item *item); EAPI void _elm_widget_item_signal_callback_add(Elm_Widget_Item *item, const char *emission, const char *source, Elm_Widget_Item_Signal_Cb func, void *data); EAPI void *_elm_widget_item_signal_callback_del(Elm_Widget_Item *it, const char *emission, const char *source, Elm_Widget_Item_Signal_Cb func); @@ -1014,6 +1018,27 @@ EAPI void elm_widget_tree_dot_dump(const Evas_Object *top, FILE *out #define elm_widget_item_translate(item) \ _elm_widget_item_translate((Elm_Widget_Item *)item) +/** + * Convenience function to save additional text part content. + * @see _elm_widget_item_part_text_custom_set() + */ +#define elm_widget_item_part_text_custom_set(item, part, text) \ + _elm_widget_item_part_text_custom_set((Elm_Widget_Item *)item, part, text) + +/** + * Convenience function to get additional text part content. + * @see _elm_widget_item_part_text_custom_set() + */ +#define elm_widget_item_part_text_custom_get(item, part) \ + _elm_widget_item_part_text_custom_get((Elm_Widget_Item *)item, part) + +/** + * Convenience function to update additional text part content. + * @see _elm_widget_item_part_text_custom_set() + */ +#define elm_widget_item_part_text_custom_update(item) \ + _elm_widget_item_part_text_custom_update((Elm_Widget_Item *)item) + #define ELM_WIDGET_ITEM_CHECK_OR_RETURN(item, ...) \ do { \ if (!item) { \ -- 2.7.4