rimmed pushed a commit to branch master. http://git.enlightenment.org/tools/eflete.git/commit/?id=67756ab6ae7147b20bad0cbc04fd57fb281e2313
commit 67756ab6ae7147b20bad0cbc04fd57fb281e2313 Author: Vitalii Vorobiov <vi.vorob...@samsung.com> Date: Tue Sep 13 18:39:50 2016 +0300 resource_manager: Style has Style_Tag structures which uses Fonts dependencies --- src/bin/common/signals.h | 14 ++++++ src/bin/editor/editor.h | 1 - src/bin/editor/editor_top_level.c | 19 +------- src/bin/resource_manager/resource_manager2.h | 30 ++++--------- src/bin/resource_manager/resource_manager_build.c | 23 ++++++++++ src/bin/resource_manager/resource_manager_free.c | 20 +++++++++ src/bin/resource_manager/resource_manager_load.c | 50 +++++++++++++++++---- .../resource_manager/resource_manager_private.h | 9 ++++ src/bin/resource_manager/resource_manager_react.c | 51 +++++++++++++++++++++- src/bin/ui/property/property_textblock.c | 14 ++++++ 10 files changed, 181 insertions(+), 50 deletions(-) diff --git a/src/bin/common/signals.h b/src/bin/common/signals.h index 0b81705..f831e05 100644 --- a/src/bin/common/signals.h +++ b/src/bin/common/signals.h @@ -576,6 +576,20 @@ typedef struct { */ #define SIGNAL_EDITOR_STYLE_DELETED "SIGNAL_EDITOR_STYLE_DELETED" +typedef struct { + const char *style_name; + const char *tag_name; + const char *old_value; + const char *value; +} Font_Change; +/** + * emited when font was changed in property of textblock manager. + * eventinfo - Font_Change struct + * + * @ingroup Window + */ +#define SIGNAL_EDITOR_STYLE_TAG_CHANGED "SIGNAL_EDITOR_STYLE_TAG_CHANGED" + /** * emited when part state is selected. * eventinfo - EEditor_State struct diff --git a/src/bin/editor/editor.h b/src/bin/editor/editor.h index c2e2d7f..2aa511d 100644 --- a/src/bin/editor/editor.h +++ b/src/bin/editor/editor.h @@ -225,7 +225,6 @@ typedef enum { RM_ATTRIBUTE_RESOURCES_COLORCLASS_COLORS, RM_ATTRIBUTE_RESOURCES_STYLE_TAG_ADDED, RM_ATTRIBUTE_RESOURCES_STYLE_TAG_DELETED, - RM_ATTRIBUTE_RESOURCES_STYLE_TAG_CHANGED, RM_ATTRIBUTE_RESOURCES_LAST } RM_Attribute_Resources; diff --git a/src/bin/editor/editor_top_level.c b/src/bin/editor/editor_top_level.c index ff67492..c493e4b 100644 --- a/src/bin/editor/editor_top_level.c +++ b/src/bin/editor/editor_top_level.c @@ -309,25 +309,8 @@ editor_style_tag_value_set(Evas_Object *obj, const char *name, const char *tag, CRIT_ON_FAIL(edje_edit_style_tag_value_set(obj, name, tag, value)); - Editor_Attribute_Resource_Change send; - send.attribute = RM_ATTRIBUTE_RESOURCES_STYLE_TAG_CHANGED; - send.style_name = eina_stringshare_add(name); - send.tag_name = eina_stringshare_add(tag); - send.tag_value = eina_stringshare_add(value); - if (!editor_save(obj)) - { - eina_stringshare_del(send.tag_value); - eina_stringshare_del(send.tag_name); - eina_stringshare_del(send.style_name); - return false; /* i hope it will never happen */ - } + return false; /* i hope it will never happen */ _editor_project_changed(); - if (!_editor_signals_blocked) - evas_object_smart_callback_call(ap.win, SIGNAL_EDITOR_RM_ATTRIBUTE_CHANGED, &send); - - eina_stringshare_del(send.tag_value); - eina_stringshare_del(send.tag_name); - eina_stringshare_del(send.style_name); return true; } diff --git a/src/bin/resource_manager/resource_manager2.h b/src/bin/resource_manager/resource_manager2.h index d2d7d62..e3301e9 100644 --- a/src/bin/resource_manager/resource_manager2.h +++ b/src/bin/resource_manager/resource_manager2.h @@ -42,6 +42,7 @@ enum _Resource2_Type RESOURCE2_TYPE_FONT, RESOURCE2_TYPE_COLORCLASS, RESOURCE2_TYPE_STYLE, + RESOURCE2_TYPE_STYLE_TAG, RESOURCE2_TYPE_SIZECLASS, RESOURCE2_TYPE_TEXTCLASS, RESOURCE2_TYPE_VIBRO, /* something for now? */ @@ -74,6 +75,7 @@ typedef struct _Style2 Style2; typedef struct _Image2 Image2; typedef struct _Image_Set2 Image_Set2; typedef struct _Tone2 Tone2; +typedef struct _Style_Tag2 Style_Tag2; typedef struct _Colorclass2 Colorclass2; typedef struct _Sound2 Sound2; @@ -148,30 +150,14 @@ struct _Style2 { Resource2_Internal common; Eina_Stringshare *raw_style; //for set to textblock and to edje_edit + Eina_List *tags; +}; - /* all parsed values goes below */ +struct _Style_Tag2 +{ + Resource2_Internal common; Eina_Stringshare *font; - int font_size; - int font_style_weight; - int font_style_width; - struct { - int r, g, b, a; - } color, bg_color, outer_color, inner_color, shadow_color; - int font_align_hor; - int font_valign_hor; - int left_margin, right_margin; - int wrap; - int linerelsize, linesize, tabstops; - Eina_Bool pass, bg_check, ellipsis_check; - int ellipsis_value; - int glow_style; - int direction; - Eina_Bool strikethrough_check; - struct { - int r, g, b, a; - } underone_color, undertwo_color, strikethrough_color, dash_color; - int underline; - int dash_width, dash_gap; + Style2 *style; }; struct _Image2 diff --git a/src/bin/resource_manager/resource_manager_build.c b/src/bin/resource_manager/resource_manager_build.c index e3d47f0..0ece470 100644 --- a/src/bin/resource_manager/resource_manager_build.c +++ b/src/bin/resource_manager/resource_manager_build.c @@ -313,6 +313,26 @@ _group_dependency_load(Project *pro, Group2 *group) } void +_style_dependency_load(Project *pro) +{ + Style2 *style; + Resource2 *res; + Eina_List *l1, *l2; + Style_Tag2 *tag; + + /* image_set */ + EINA_LIST_FOREACH(pro->RM.styles, l1, style) + { + EINA_LIST_FOREACH(style->tags, l2, tag) + { + res = resource_manager_find(pro->RM.fonts, tag->font); + if (res) + _resource_usage_resource_add((Resource2 *)tag, res); + } + } +} + +void _resource_dependency_load(Project *pro) { Group2 *group; @@ -333,6 +353,9 @@ _resource_dependency_load(Project *pro) edje_edit_string_list_free(set_images); } + /* font <===> style dependencies */ + _style_dependency_load(pro); + /* groups */ EINA_LIST_FOREACH(pro->RM.groups, l1, group) { diff --git a/src/bin/resource_manager/resource_manager_free.c b/src/bin/resource_manager/resource_manager_free.c index 71796f5..9584d3f 100644 --- a/src/bin/resource_manager/resource_manager_free.c +++ b/src/bin/resource_manager/resource_manager_free.c @@ -202,8 +202,28 @@ _resource_colorclass_del(Project *pro, Colorclass2 *res_colorclass) } void +_resource_style_tag_free(Style_Tag2 *res) +{ + _resource_usage_dependency_cleanup((Resource2 *)res); + + res->style->tags = eina_list_remove(res->style->tags, res); + + eina_stringshare_del(res->common.name); + eina_stringshare_del(res->font); + eina_list_free(res->common.used_in); + eina_list_free(res->common.uses___); + free(res); +} + +void _resource_style_free(Project *pro, Style2 *res) { + Style_Tag2 *tag; + EINA_LIST_FREE(res->tags, tag) + { + _resource_style_tag_free(tag); + } + pro->RM.styles = eina_list_remove(pro->RM.styles, res); eina_stringshare_del(res->common.name); diff --git a/src/bin/resource_manager/resource_manager_load.c b/src/bin/resource_manager/resource_manager_load.c index e8842e3..41eef79 100644 --- a/src/bin/resource_manager/resource_manager_load.c +++ b/src/bin/resource_manager/resource_manager_load.c @@ -354,11 +354,44 @@ _colorclasses_resources_load(Project *project) } Eina_Bool +_styles_tag_resources_load(Project *pro, Eina_Stringshare *name, Style2 *style) +{ + char *pch, *tok, *data; + Eina_Stringshare *value; + Style_Tag2 *res; + + value = edje_edit_style_tag_value_get(pro->global_object, + style->common.name, + name); + data = strdup(value); + edje_edit_string_free(data); + pch = strstr(data, "font"); + if (!pch) + { + free(data); + return false; + } + pch += strlen("font"); + tok = strtok(pch, " ="); + if (pch) + { + res = mem_calloc(1, sizeof(Style_Tag2)); + res->common.type = RESOURCE2_TYPE_STYLE_TAG; + res->common.name = eina_stringshare_add(name); + res->font = eina_stringshare_add(tok); + style->tags = eina_list_append(style->tags, res); + res->style = style; + } + free(data); + return true; +} + +Eina_Bool _styles_resources_load(Project *project) { - Eina_List *styles, *l; + Eina_List *styles, *tags, *l2, *l1; Style2 *res; - Eina_Stringshare *name; + Eina_Stringshare *name, *tag_value; assert(project != NULL); @@ -368,17 +401,18 @@ _styles_resources_load(Project *project) edje_edit_string_list_free(styles); return false; } - EINA_LIST_FOREACH(styles, l, name) + EINA_LIST_FOREACH(styles, l1, name) { res = mem_calloc(1, sizeof(Style2)); res->common.type = RESOURCE2_TYPE_STYLE; res->common.name = eina_stringshare_add(name); - project->RM.styles = eina_list_append(project->RM.styles, res); - TODO("parse all values and find dependencies in here like that:"); - /* - STYLES uses FONT, COLOR_CLASS?, VIBRO? - */ + tags = edje_edit_style_tags_list_get(project->global_object, name); + EINA_LIST_FOREACH(tags, l2, tag_value) + { + _styles_tag_resources_load(project, tag_value, res); + } + project->RM.styles = eina_list_append(project->RM.styles, res); } edje_edit_string_list_free(styles); return true; diff --git a/src/bin/resource_manager/resource_manager_private.h b/src/bin/resource_manager/resource_manager_private.h index e30d9ab..9dae289 100644 --- a/src/bin/resource_manager/resource_manager_private.h +++ b/src/bin/resource_manager/resource_manager_private.h @@ -54,6 +54,9 @@ Eina_Bool _colorclasses_resources_load(Project *project); Eina_Bool +_styles_tag_resources_load(Project *pro, Eina_Stringshare *name, Style2 *style); + +Eina_Bool _styles_resources_load(Project *project); Eina_Bool @@ -117,6 +120,9 @@ _group_dependency_load(Project *pro, Group2 *group); void _resource_dependency_load(Project *pro); +void +_style_dependency_load(Project *pro); + /* REACTION TO EDITOR AND EDJE EDIT */ void @@ -190,6 +196,9 @@ void _resource_colorclass_del(Project *pro, Colorclass2 *res_colorclass); void +_resource_style_tag_free(Style_Tag2 *res); + +void _resource_style_free(Project *pro, Style2 *res); void diff --git a/src/bin/resource_manager/resource_manager_react.c b/src/bin/resource_manager/resource_manager_react.c index 76acd6e..56a701a 100644 --- a/src/bin/resource_manager/resource_manager_react.c +++ b/src/bin/resource_manager/resource_manager_react.c @@ -52,6 +52,8 @@ _property_resource_attribute_changed(void *data, void *event_info) { Colorclass2 *cc_res; + Style2 *style_res; + Style_Tag2 *style_tag; Editor_Attribute_Resource_Change *change = event_info; Project *pro = (Project *)data; @@ -82,8 +84,22 @@ _property_resource_attribute_changed(void *data, cc_res->color3.a = change->a3; break; case RM_ATTRIBUTE_RESOURCES_STYLE_TAG_ADDED: + style_res = (Style2 *)resource_manager_find(pro->RM.styles, + change->style_name); + style_tag = mem_calloc(1, sizeof(Style_Tag2)); + style_tag->common.type = RESOURCE2_TYPE_STYLE_TAG; + style_tag->common.name = eina_stringshare_add(change->tag_name); + style_tag->style = style_res; + + style_res->tags = eina_list_append(style_res->tags, style_tag); + break; case RM_ATTRIBUTE_RESOURCES_STYLE_TAG_DELETED: - case RM_ATTRIBUTE_RESOURCES_STYLE_TAG_CHANGED: + style_res = (Style2 *)resource_manager_find(pro->RM.styles, + change->style_name); + style_tag = (Style_Tag2 *)resource_manager_find(style_res->tags, + change->tag_name); + _resource_style_tag_free(style_tag); + break; default: break; } @@ -633,6 +649,37 @@ _style_deleted(void *data, } static void +_style_changed(void *data, + Evas_Object *obj __UNUSED__, + void *ei) +{ + Font_Change *font_change = (Font_Change *)ei; + Project *pro = (Project *)data; + Style2 *res_style; + Style_Tag2 *res_tag; + Resource2 *old_source, *source; + + res_style = (Style2 *)resource_manager_find(pro->RM.styles, font_change->style_name); + res_tag = (Style_Tag2 *)resource_manager_find(res_style->tags, + font_change->tag_name); + if (res_tag->font) + { + old_source = resource_manager_find(pro->RM.fonts, res_tag->font); + if (old_source) + _resource_usage_resource_del((Resource2 *)res_tag, old_source); + eina_stringshare_del(res_tag->font); + res_tag->font = NULL; + } + if (font_change->value) + { + res_tag->font = eina_stringshare_add(font_change->value); + source = resource_manager_find(pro->RM.fonts, res_tag->font); + if (source) + _resource_usage_resource_add((Resource2 *)res_tag, source); + } +} + +static void _part_renamed(void *data, Evas_Object *obj __UNUSED__, void *ei) @@ -900,6 +947,7 @@ _resource_callbacks_register(Project *project) evas_object_smart_callback_add(ap.win, SIGNAL_EDITOR_IMAGE_DELETED, image_deleted, project); evas_object_smart_callback_add(ap.win, SIGNAL_EDITOR_STYLE_ADDED, _style_added, project); evas_object_smart_callback_add(ap.win, SIGNAL_EDITOR_STYLE_DELETED, _style_deleted, project); + evas_object_smart_callback_add(ap.win, SIGNAL_EDITOR_STYLE_TAG_CHANGED, _style_changed, project); /* already implemented stack of editor changes */ evas_object_smart_callback_add(ap.win, SIGNAL_PART_RENAMED, _part_renamed, project); @@ -939,6 +987,7 @@ _resource_callbacks_unregister(Project *project) evas_object_smart_callback_del_full(ap.win, SIGNAL_EDITOR_IMAGE_DELETED, image_deleted, project); evas_object_smart_callback_del_full(ap.win, SIGNAL_EDITOR_STYLE_ADDED, _style_added, project); evas_object_smart_callback_del_full(ap.win, SIGNAL_EDITOR_STYLE_DELETED, _style_deleted, project); + evas_object_smart_callback_del_full(ap.win, SIGNAL_EDITOR_STYLE_TAG_CHANGED, _style_changed, project); /* already implemented stack of editor changes */ evas_object_smart_callback_del_full(ap.win, SIGNAL_PART_RENAMED, _part_renamed, project); diff --git a/src/bin/ui/property/property_textblock.c b/src/bin/ui/property/property_textblock.c index ffb76c3..875c3da 100644 --- a/src/bin/ui/property/property_textblock.c +++ b/src/bin/ui/property/property_textblock.c @@ -547,12 +547,26 @@ _change_cb(Property_Attribute *pa, Property_Action *action) switch (action->type.attribute_textblock) { case ATTRIBUTE_TEXTBLOCK_ITEM_TEXT_FONT_NAME: + TODO("Refactor this"); + Font_Change font_change; + font_change.old_value = eina_stringshare_add(tpd.font); + font_change.value = eina_stringshare_add(str_val1); + font_change.style_name = eina_stringshare_add(tpd.current_style.st_name); + font_change.tag_name = eina_stringshare_add(tpd.current_style.st_tag); + + evas_object_smart_callback_call(ap.win, SIGNAL_EDITOR_STYLE_TAG_CHANGED, &font_change); + if (tpd.font) eina_stringshare_del(tpd.font); tpd.font = eina_stringshare_add(str_val1); _style_edit_update(); CRIT_ON_FAIL(editor_save(ap.project->global_object)); ap.project->changed = true; + + eina_stringshare_del(font_change.old_value); + eina_stringshare_del(font_change.value); + eina_stringshare_del(font_change.tag_name); + eina_stringshare_del(font_change.style_name); break; case ATTRIBUTE_TEXTBLOCK_ITEM_TEXT_FONT_STYLE_WEIGHT: assert(cb_item != NULL); --