forked from enlightenment/efl
edje_cc now supports part.inherit for copying attributes of parts within a group more easily
@feature
This commit is contained in:
parent
79a6653f59
commit
4619c3de4e
|
@ -208,9 +208,10 @@ static void ob_collections_group_lua_script(void);
|
|||
|
||||
static void st_collections_group_parts_alias(void);
|
||||
|
||||
static Edje_Part *edje_cc_handlers_part_make(void);
|
||||
static Edje_Part *edje_cc_handlers_part_make(int);
|
||||
static void ob_collections_group_parts_part(void);
|
||||
static void st_collections_group_parts_part_name(void);
|
||||
static void st_collections_group_parts_part_inherit(void);
|
||||
static void st_collections_group_parts_part_type(void);
|
||||
#ifdef HAVE_EPHYSICS
|
||||
static void st_collections_group_parts_part_physics_body(void);
|
||||
|
@ -515,6 +516,7 @@ New_Statement_Handler statement_handlers[] =
|
|||
{"collections.group.parts.color_classes.color_class.color2", st_color_class_color2}, /* dup */
|
||||
{"collections.group.parts.color_classes.color_class.color3", st_color_class_color3}, /* dup */
|
||||
{"collections.group.parts.part.name", st_collections_group_parts_part_name},
|
||||
{"collections.group.parts.part.inherit", st_collections_group_parts_part_inherit},
|
||||
{"collections.group.parts.part.api", st_collections_group_parts_part_api},
|
||||
{"collections.group.parts.part.type", st_collections_group_parts_part_type},
|
||||
#ifdef HAVE_EPHYSICS
|
||||
|
@ -2815,136 +2817,19 @@ _edje_data_item_list_foreach(const Eina_Hash *hash EINA_UNUSED, const void *key,
|
|||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
@page edcref
|
||||
@property
|
||||
inherit
|
||||
@parameters
|
||||
[parent group name]
|
||||
@effect
|
||||
Parent group name for inheritance.
|
||||
Group "inherit" is used to inherit any predefined group and change
|
||||
some property which belongs to "part", "description", "items" or "program".
|
||||
The child group has the same property as parent group. If you specify the
|
||||
type again in an inherited part, it will cause an error (unless you plan
|
||||
to fix that).
|
||||
@endproperty
|
||||
@since 1.1.0
|
||||
*/
|
||||
#define STRDUP(x) x ? strdup(x) : NULL
|
||||
static void
|
||||
st_collections_group_inherit(void)
|
||||
_part_copy(Edje_Part *ep, Edje_Part *ep2)
|
||||
{
|
||||
Edje_Part_Collection *pc, *pc2;
|
||||
Edje_Part_Collection_Parser *pcp, *pcp2;
|
||||
Edje_Part *ep, *ep2;
|
||||
Edje_Part_Collection *pc;
|
||||
Edje_Part_Parser *epp, *epp2;
|
||||
Edje_Pack_Element *item, *item2;
|
||||
Edje_Pack_Element_Parser *pitem;
|
||||
Edje_Part_Description_Common *ed, *ed2;
|
||||
Edje_List_Foreach_Data fdata;
|
||||
Eina_List *l;
|
||||
char *parent_name;
|
||||
unsigned int i, j;
|
||||
unsigned int j;
|
||||
|
||||
check_arg_count(1);
|
||||
pc = eina_list_last_data_get(edje_collections);
|
||||
|
||||
pc = eina_list_data_get(eina_list_last(edje_collections));
|
||||
|
||||
parent_name = parse_str(0);
|
||||
|
||||
EINA_LIST_FOREACH(edje_collections, l, pc2)
|
||||
{
|
||||
if (!strcmp(parent_name, pc2->part))
|
||||
break;
|
||||
}
|
||||
if (!pc2)
|
||||
{
|
||||
ERR("parse error %s:%i. There isn't a group with the name %s",
|
||||
file_in, line - 1, parent_name);
|
||||
exit(-1);
|
||||
}
|
||||
if (pc2 == pc)
|
||||
{
|
||||
ERR("parse error %s:%i. You are trying to inherit '%s' from itself. That's not possible."
|
||||
"If there is another group of the same name, you want to inherit from that group and have the"
|
||||
"same name as that group, there is a trick ! Just put the inherit before the directive that set"
|
||||
"the name !", file_in, line - 1, parent_name);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (pc2->data)
|
||||
{
|
||||
char *key, *data;
|
||||
|
||||
memset(&fdata, 0, sizeof(Edje_List_Foreach_Data));
|
||||
eina_hash_foreach(pc2->data,
|
||||
_edje_data_item_list_foreach, &fdata);
|
||||
|
||||
if (!pc->data) pc->data = eina_hash_string_small_new(free);
|
||||
EINA_LIST_FREE(fdata.list, key)
|
||||
{
|
||||
data = eina_hash_find(pc2->data, key);
|
||||
eina_hash_direct_add(pc->data, key, data);
|
||||
}
|
||||
}
|
||||
|
||||
if (pc2->alias)
|
||||
{
|
||||
char *key, *alias;
|
||||
|
||||
memset(&fdata, 0, sizeof(Edje_List_Foreach_Data));
|
||||
eina_hash_foreach(pc2->alias,
|
||||
_edje_data_item_list_foreach, &fdata);
|
||||
if (!pc->alias) pc->alias = eina_hash_string_small_new(free);
|
||||
EINA_LIST_FREE(fdata.list, key)
|
||||
{
|
||||
alias = eina_hash_find(pc2->alias, key);
|
||||
eina_hash_direct_add(pc->alias, key, alias);
|
||||
}
|
||||
}
|
||||
if (pc2->aliased)
|
||||
{
|
||||
char *key, *aliased;
|
||||
|
||||
memset(&fdata, 0, sizeof(Edje_List_Foreach_Data));
|
||||
eina_hash_foreach(pc2->aliased,
|
||||
_edje_data_item_list_foreach, &fdata);
|
||||
if (!pc->aliased) pc->aliased = eina_hash_string_small_new(free);
|
||||
EINA_LIST_FREE(fdata.list, key)
|
||||
{
|
||||
aliased = eina_hash_find(pc2->aliased, key);
|
||||
eina_hash_direct_add(pc->aliased, key, aliased);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_EPHYSICS
|
||||
pc->physics.world.gravity.x = pc2->physics.world.gravity.x;
|
||||
pc->physics.world.gravity.y = pc2->physics.world.gravity.y;
|
||||
pc->physics.world.gravity.z = pc2->physics.world.gravity.z;
|
||||
pc->physics.world.depth = pc2->physics.world.depth;
|
||||
pc->physics.world.z = pc2->physics.world.z;
|
||||
pc->physics.world.rate = pc2->physics.world.rate;
|
||||
#endif
|
||||
|
||||
pc->prop.min.w = pc2->prop.min.w;
|
||||
pc->prop.min.h = pc2->prop.min.h;
|
||||
pc->prop.orientation = pc2->prop.orientation;
|
||||
|
||||
pc->lua_script_only = pc2->lua_script_only;
|
||||
|
||||
pcp = (Edje_Part_Collection_Parser *)pc;
|
||||
pcp2 = (Edje_Part_Collection_Parser *)pc2;
|
||||
pcp->default_mouse_events = pcp2->default_mouse_events;
|
||||
|
||||
// FIXME: Handle limits dup
|
||||
|
||||
#define STRDUP(x) x ? strdup(x) : NULL
|
||||
for (i = 0 ; i < pc2->parts_count ; i++)
|
||||
{
|
||||
// copy the part
|
||||
edje_cc_handlers_part_make();
|
||||
ep = pc->parts[i];
|
||||
ep2 = pc2->parts[i];
|
||||
ep->name = STRDUP(ep2->name);
|
||||
ep->source = STRDUP(ep2->source);
|
||||
ep->source2 = STRDUP(ep2->source2);
|
||||
|
@ -3047,6 +2932,134 @@ st_collections_group_inherit(void)
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@page edcref
|
||||
@property
|
||||
inherit
|
||||
@parameters
|
||||
[parent group name]
|
||||
@effect
|
||||
Parent group name for inheritance.
|
||||
Group "inherit" is used to inherit any predefined group and change
|
||||
some property which belongs to "part", "description", "items" or "program".
|
||||
The child group has the same property as parent group. If you specify the
|
||||
type again in an inherited part, it will cause an error (unless you plan
|
||||
to fix that).
|
||||
@endproperty
|
||||
@since 1.1.0
|
||||
*/
|
||||
static void
|
||||
st_collections_group_inherit(void)
|
||||
{
|
||||
Edje_Part_Collection *pc, *pc2;
|
||||
Edje_Part_Collection_Parser *pcp, *pcp2;
|
||||
Edje_Part *ep, *ep2;
|
||||
Edje_List_Foreach_Data fdata;
|
||||
Eina_List *l;
|
||||
char *parent_name;
|
||||
unsigned int i, j;
|
||||
|
||||
check_arg_count(1);
|
||||
|
||||
pc = eina_list_data_get(eina_list_last(edje_collections));
|
||||
|
||||
parent_name = parse_str(0);
|
||||
|
||||
EINA_LIST_FOREACH(edje_collections, l, pc2)
|
||||
{
|
||||
if (!strcmp(parent_name, pc2->part))
|
||||
break;
|
||||
}
|
||||
if (!pc2)
|
||||
{
|
||||
ERR("parse error %s:%i. There isn't a group with the name %s",
|
||||
file_in, line - 1, parent_name);
|
||||
exit(-1);
|
||||
}
|
||||
if (pc2 == pc)
|
||||
{
|
||||
ERR("parse error %s:%i. You are trying to inherit '%s' from itself. That's not possible."
|
||||
"If there is another group of the same name, you want to inherit from that group and have the"
|
||||
"same name as that group, there is a trick ! Just put the inherit before the directive that set"
|
||||
"the name !", file_in, line - 1, parent_name);
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
if (pc2->data)
|
||||
{
|
||||
char *key, *data;
|
||||
|
||||
memset(&fdata, 0, sizeof(Edje_List_Foreach_Data));
|
||||
eina_hash_foreach(pc2->data,
|
||||
_edje_data_item_list_foreach, &fdata);
|
||||
|
||||
if (!pc->data) pc->data = eina_hash_string_small_new(free);
|
||||
EINA_LIST_FREE(fdata.list, key)
|
||||
{
|
||||
data = eina_hash_find(pc2->data, key);
|
||||
eina_hash_direct_add(pc->data, key, data);
|
||||
}
|
||||
}
|
||||
|
||||
if (pc2->alias)
|
||||
{
|
||||
char *key, *alias;
|
||||
|
||||
memset(&fdata, 0, sizeof(Edje_List_Foreach_Data));
|
||||
eina_hash_foreach(pc2->alias,
|
||||
_edje_data_item_list_foreach, &fdata);
|
||||
if (!pc->alias) pc->alias = eina_hash_string_small_new(free);
|
||||
EINA_LIST_FREE(fdata.list, key)
|
||||
{
|
||||
alias = eina_hash_find(pc2->alias, key);
|
||||
eina_hash_direct_add(pc->alias, key, alias);
|
||||
}
|
||||
}
|
||||
if (pc2->aliased)
|
||||
{
|
||||
char *key, *aliased;
|
||||
|
||||
memset(&fdata, 0, sizeof(Edje_List_Foreach_Data));
|
||||
eina_hash_foreach(pc2->aliased,
|
||||
_edje_data_item_list_foreach, &fdata);
|
||||
if (!pc->aliased) pc->aliased = eina_hash_string_small_new(free);
|
||||
EINA_LIST_FREE(fdata.list, key)
|
||||
{
|
||||
aliased = eina_hash_find(pc2->aliased, key);
|
||||
eina_hash_direct_add(pc->aliased, key, aliased);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_EPHYSICS
|
||||
pc->physics.world.gravity.x = pc2->physics.world.gravity.x;
|
||||
pc->physics.world.gravity.y = pc2->physics.world.gravity.y;
|
||||
pc->physics.world.gravity.z = pc2->physics.world.gravity.z;
|
||||
pc->physics.world.depth = pc2->physics.world.depth;
|
||||
pc->physics.world.z = pc2->physics.world.z;
|
||||
pc->physics.world.rate = pc2->physics.world.rate;
|
||||
#endif
|
||||
|
||||
pc->prop.min.w = pc2->prop.min.w;
|
||||
pc->prop.min.h = pc2->prop.min.h;
|
||||
pc->prop.orientation = pc2->prop.orientation;
|
||||
|
||||
pc->lua_script_only = pc2->lua_script_only;
|
||||
|
||||
pcp = (Edje_Part_Collection_Parser *)pc;
|
||||
pcp2 = (Edje_Part_Collection_Parser *)pc2;
|
||||
pcp->default_mouse_events = pcp2->default_mouse_events;
|
||||
|
||||
// FIXME: Handle limits dup
|
||||
|
||||
for (i = 0 ; i < pc2->parts_count ; i++)
|
||||
{
|
||||
// copy the part
|
||||
edje_cc_handlers_part_make(-1);
|
||||
ep = pc->parts[i];
|
||||
ep2 = pc2->parts[i];
|
||||
_part_copy(ep, ep2);
|
||||
}
|
||||
|
||||
//copy programs
|
||||
for (j = 0 ; j < pc2->programs.fnmatch_count ; j++)
|
||||
{
|
||||
|
@ -3583,7 +3596,7 @@ st_collections_group_parts_alias(void)
|
|||
@endblock
|
||||
*/
|
||||
static Edje_Part *
|
||||
edje_cc_handlers_part_make(void)
|
||||
edje_cc_handlers_part_make(int id)
|
||||
{ /* Doing ob_collections_group_parts_part() job, without hierarchy */
|
||||
Edje_Part_Collection *pc;
|
||||
Edje_Part_Collection_Parser *pcp;
|
||||
|
@ -3593,6 +3606,8 @@ edje_cc_handlers_part_make(void)
|
|||
ep = mem_alloc(SZ(Edje_Part_Parser));
|
||||
|
||||
pc = eina_list_data_get(eina_list_last(edje_collections));
|
||||
if (id < 0)
|
||||
{
|
||||
pc->parts_count++;
|
||||
pc->parts = realloc(pc->parts, pc->parts_count * sizeof (Edje_Part *));
|
||||
if (!pc->parts)
|
||||
|
@ -3600,10 +3615,12 @@ edje_cc_handlers_part_make(void)
|
|||
ERR("Not enough memory.");
|
||||
exit(-1);
|
||||
}
|
||||
current_part = pc->parts[pc->parts_count - 1] = ep;
|
||||
id = pc->parts_count - 1;
|
||||
}
|
||||
current_part = pc->parts[id] = ep;
|
||||
pcp = (Edje_Part_Collection_Parser *)pc;
|
||||
|
||||
ep->id = pc->parts_count - 1;
|
||||
ep->id = id;
|
||||
ep->type = EDJE_PART_TYPE_IMAGE;
|
||||
ep->mouse_events = pcp->default_mouse_events;
|
||||
ep->repeat_events = 0;
|
||||
|
@ -3637,7 +3654,7 @@ static void
|
|||
ob_collections_group_parts_part(void)
|
||||
{
|
||||
Edje_Part *cp = current_part; /* Save to restore on pop */
|
||||
Edje_Part *ep = edje_cc_handlers_part_make(); /* This changes current_part */
|
||||
Edje_Part *ep = edje_cc_handlers_part_make(-1); /* This changes current_part */
|
||||
Edje_Part *prnt;
|
||||
|
||||
/* Add this new part to hierarchy stack (removed part finished parse) */
|
||||
|
@ -3689,6 +3706,52 @@ _part_free(Edje_Part *ep)
|
|||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
@page edcref
|
||||
@property
|
||||
inherit
|
||||
@parameters
|
||||
[part name]
|
||||
@effect
|
||||
Copies all attributes except part name from referenced part into current part.
|
||||
ALL existing attributes, except part name, are overwritten.
|
||||
@endproperty
|
||||
@since 1.10
|
||||
*/
|
||||
static void
|
||||
st_collections_group_parts_part_inherit(void)
|
||||
{
|
||||
char *name;
|
||||
Edje_Part_Collection *pc;
|
||||
unsigned int i;
|
||||
|
||||
check_arg_count(1);
|
||||
|
||||
name = parse_str(0);
|
||||
pc = eina_list_data_get(eina_list_last(edje_collections));
|
||||
for (i = 0; i < pc->parts_count; i++)
|
||||
{
|
||||
int id = current_part->id;
|
||||
const char *pname;
|
||||
|
||||
if (strcmp(pc->parts[i]->name, name)) continue;
|
||||
pname = current_part->name;
|
||||
current_part->name = NULL;
|
||||
_part_free(current_part);
|
||||
edje_cc_handlers_part_make(id);
|
||||
_part_copy(current_part, pc->parts[i]);
|
||||
free((void*)current_part->name);
|
||||
current_part->name = pname;
|
||||
free(name);
|
||||
return;
|
||||
}
|
||||
|
||||
ERR("Cannot inherit non-existing part '%s' in group '%s'", name, current_de->entry);
|
||||
exit(-1);
|
||||
|
||||
free(name);
|
||||
}
|
||||
|
||||
/**
|
||||
@page edcref
|
||||
@property
|
||||
|
|
Loading…
Reference in New Issue