* @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.
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
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);
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);