forked from enlightenment/efl
eo: eo_composite_attach check composite class, disallow duplicates
eo_composite_attach fail if the class of the composite is not listed in the parent class extensions, or if there is already a composite of the same class. The later because calls are forwarded to the first responding composite, see _eo_op_internal().
This commit is contained in:
parent
f98c1393b8
commit
e199230615
|
@ -936,13 +936,16 @@ EAPI Eina_Bool eo_destructed_is(const Eo *obj);
|
|||
* @brief Make an object a composite object of another.
|
||||
* @param comp_obj the object that will be used to composite parent.
|
||||
* @param parent the "parent" object.
|
||||
* @return EINA_TRUE if successfull. EINA_FALSE otherwise.
|
||||
*
|
||||
* The class of comp_obj must be part of the extensions of the class of the parent.
|
||||
* It is not possible to attach more then 1 composite of the same class.
|
||||
* This functions also sets the parent of comp_obj to parent.
|
||||
*
|
||||
* @see eo_composite_detach()
|
||||
* @see eo_composite_is()
|
||||
*/
|
||||
EAPI void eo_composite_attach(Eo *comp_obj, Eo *parent);
|
||||
EAPI Eina_Bool eo_composite_attach(Eo *comp_obj, Eo *parent);
|
||||
|
||||
/**
|
||||
* @brief Detach a composite object from another object.
|
||||
|
|
|
@ -1485,16 +1485,31 @@ eo_shutdown(void)
|
|||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
EAPI Eina_Bool
|
||||
eo_composite_attach(Eo *comp_obj_id, Eo *parent_id)
|
||||
{
|
||||
EO_OBJ_POINTER_RETURN(comp_obj_id, comp_obj);
|
||||
EO_OBJ_POINTER_RETURN(parent_id, parent);
|
||||
EO_OBJ_POINTER_RETURN_VAL(comp_obj_id, comp_obj, EINA_FALSE);
|
||||
EO_OBJ_POINTER_RETURN_VAL(parent_id, parent, EINA_FALSE);
|
||||
|
||||
if (!eo_isa(parent_id, _eo_class_id_get(comp_obj->klass))) return EINA_FALSE;
|
||||
|
||||
{
|
||||
Eina_List *itr;
|
||||
Eo *emb_obj_id;
|
||||
EINA_LIST_FOREACH(parent->composite_objects, itr, emb_obj_id)
|
||||
{
|
||||
EO_OBJ_POINTER_RETURN_VAL(emb_obj_id, emb_obj, EINA_FALSE);
|
||||
if(emb_obj->klass == comp_obj->klass)
|
||||
return EINA_FALSE;
|
||||
}
|
||||
}
|
||||
|
||||
comp_obj->composite = EINA_TRUE;
|
||||
parent->composite_objects = eina_list_prepend(parent->composite_objects, comp_obj_id);
|
||||
|
||||
eo_do(comp_obj_id, eo_parent_set(parent_id));
|
||||
|
||||
return EINA_TRUE;
|
||||
}
|
||||
|
||||
EAPI void
|
||||
|
|
|
@ -33,6 +33,9 @@ main(int argc, char *argv[])
|
|||
Eo *obj = eo_add(COMP_CLASS, NULL);
|
||||
eo_do(obj, eo_event_callback_add(EV_A_CHANGED, _a_changed_cb, NULL));
|
||||
|
||||
fail_if(!eo_isa(obj, COMP_CLASS));
|
||||
fail_if(!eo_isa(obj, SIMPLE_CLASS));
|
||||
|
||||
int a;
|
||||
eo_do(obj, simple_a_set(1));
|
||||
fail_if(!cb_called);
|
||||
|
@ -53,8 +56,11 @@ main(int argc, char *argv[])
|
|||
fail_if(!eo_composite_is(simple));
|
||||
eo_composite_detach(simple, obj);
|
||||
fail_if(eo_composite_is(simple));
|
||||
eo_composite_attach(simple, obj);
|
||||
fail_if(!eo_composite_attach(simple, obj));
|
||||
fail_if(!eo_composite_is(simple));
|
||||
fail_if(eo_composite_attach(simple, obj));
|
||||
|
||||
fail_if(eo_composite_attach(obj, simple));
|
||||
|
||||
eo_unref(simple);
|
||||
eo_unref(obj);
|
||||
|
|
Loading…
Reference in New Issue