From de49e98ddeb8a990eef3ec09a46873812c4e0317 Mon Sep 17 00:00:00 2001 From: barbieri Date: Sat, 25 Oct 2008 02:49:19 +0000 Subject: [PATCH] Add member_{add,del} as smart callbacks. On the let's break 'em all bandwagon, add the two callbacks (or virtuals if you like the name) so we can know when some object is attached or detached as a member of our object, this will help eliminate confusing and duplicate functions like evas_object_smart_clipped_smart_add(). Please recompile *ALL* your libs and applications that depend on Evas and Smart Objects, like ETK. git-svn-id: http://svn.enlightenment.org/svn/e/trunk/evas@37084 7cbeb6ba-43b4-40fd-8cce-4c39aea84d33 --- src/lib/Evas.h | 6 +-- src/lib/canvas/evas_object_smart.c | 11 ++++- src/lib/canvas/evas_object_smart_clipped.c | 65 ++++++++++-------------------- 3 files changed, 34 insertions(+), 48 deletions(-) diff --git a/src/lib/Evas.h b/src/lib/Evas.h index 6e8b9cd..450abfb 100644 --- a/src/lib/Evas.h +++ b/src/lib/Evas.h @@ -138,7 +138,7 @@ typedef enum _Evas_Aspect_Control } Evas_Aspect_Control; -#define EVAS_SMART_CLASS_VERSION 2 /** the version you have to put into the version field in the smart class struct */ +#define EVAS_SMART_CLASS_VERSION 3 /** the version you have to put into the version field in the smart class struct */ struct _Evas_Smart_Class /** a smart object class */ { const char *name; /** the string name of the class */ @@ -155,6 +155,8 @@ struct _Evas_Smart_Class /** a smart object class */ void (*clip_set) (Evas_Object *o, Evas_Object *clip); // FIXME: DELETE ME void (*clip_unset) (Evas_Object *o); // FIXME: DELETE ME void (*calculate) (Evas_Object *o); + void (*member_add) (Evas_Object *o, Evas_Object *child); + void (*member_del) (Evas_Object *o, Evas_Object *child); const void *data; }; @@ -960,8 +962,6 @@ extern "C" { EAPI Evas_Object *evas_object_smart_clipped_clipper_get(Evas_Object *obj); EAPI void evas_object_smart_clipped_smart_set(Evas_Smart_Class *sc); - EAPI void evas_object_smart_clipped_member_add(Evas_Object *obj, Evas_Object *member); - EAPI void evas_object_smart_clipped_member_del(Evas_Object *member); /* convenience */ EAPI void evas_object_smart_move_children_relative(Evas_Object *obj, Evas_Coord dx, Evas_Coord dy); diff --git a/src/lib/canvas/evas_object_smart.c b/src/lib/canvas/evas_object_smart.c index 9adb241..291f854 100644 --- a/src/lib/canvas/evas_object_smart.c +++ b/src/lib/canvas/evas_object_smart.c @@ -194,6 +194,8 @@ evas_object_smart_member_add(Evas_Object *obj, Evas_Object *smart_obj) evas_object_smart_member_cache_invalidate(obj); obj->restack = 1; evas_object_change(obj); + if (smart_obj->smart.smart->smart_class->member_add) + smart_obj->smart.smart->smart_class->member_add(smart_obj, obj); } /** @@ -211,6 +213,7 @@ EAPI void evas_object_smart_member_del(Evas_Object *obj) { Evas_Object_Smart *o; + Evas_Object *smart_obj; MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ); return; @@ -218,6 +221,10 @@ evas_object_smart_member_del(Evas_Object *obj) if (!obj->smart.parent) return; + smart_obj = obj->smart.parent; + if (smart_obj->smart.smart->smart_class->member_del) + smart_obj->smart.smart->smart_class->member_del(smart_obj, obj); + o = (Evas_Object_Smart *)(obj->smart.parent->object_data); o->contained = eina_inlist_remove(o->contained, EINA_INLIST_GET(obj)); obj->smart.parent = NULL; @@ -526,11 +533,11 @@ evas_object_smart_calculate(Evas_Object *obj) { Evas_Object_Smart *o; MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ); - return 0; + return; MAGIC_CHECK_END(); o = obj->object_data; MAGIC_CHECK(o, Evas_Object_Smart, MAGIC_OBJ_SMART); - return 0; + return; MAGIC_CHECK_END(); if (obj->smart.smart->smart_class->calculate) diff --git a/src/lib/canvas/evas_object_smart_clipped.c b/src/lib/canvas/evas_object_smart_clipped.c index f4ddf01..e9b0d47 100644 --- a/src/lib/canvas/evas_object_smart_clipped.c +++ b/src/lib/canvas/evas_object_smart_clipped.c @@ -60,14 +60,17 @@ static void evas_object_smart_clipped_smart_add(Evas_Object *obj) { Evas_Object_Smart_Clipped_Data *cso; + Evas_Object *clipper; cso = evas_object_smart_data_get(obj); if (!cso) cso = malloc(sizeof(*cso)); /* users can provide it or realloc() later */ cso->evas = evas_object_evas_get(obj); - cso->clipper = evas_object_rectangle_add(cso->evas); - evas_object_smart_member_add(cso->clipper, obj); + clipper = evas_object_rectangle_add(cso->evas); + cso->clipper = NULL; + evas_object_smart_member_add(clipper, obj); + cso->clipper = clipper; evas_object_color_set(cso->clipper, 255, 255, 255, 255); evas_object_move(cso->clipper, -10000, -10000); evas_object_resize(cso->clipper, 20000, 20000); @@ -84,6 +87,13 @@ evas_object_smart_clipped_smart_del(Evas_Object *obj) Eina_List *lst, *itr; Evas_Object *data; + if (cso->clipper) + { + Evas_Object *clipper = cso->clipper; + cso->clipper = NULL; + evas_object_del(clipper); + } + lst = evas_object_smart_members_get(obj); EINA_LIST_FOREACH(lst, itr, data) evas_object_del(data); @@ -138,59 +148,26 @@ evas_object_smart_clipped_smart_clip_unset(Evas_Object *obj) evas_object_clip_unset(cso->clipper); } -/** - * Add the given member to clipped smart object. - * - * This method is equivalent to evas_object_smart_member_add(), but - * will do extra work required to have clipped smart object to use the - * clipper, also shows the clipper if this is the first object and - * object is visible. - * - * @warning the parameter order is different from - * evas_object_smart_member_add() - * - * @param obj the smart object to use. - * @param member the child/member to add to @a obj - * - * @todo add member_add() callback to Evas_Smart_Class. - */ -EAPI void -evas_object_smart_clipped_member_add(Evas_Object *obj, Evas_Object *member) +static void +evas_object_smart_clipped_smart_member_add(Evas_Object *obj, Evas_Object *member) { CSO_DATA_GET_OR_RETURN(obj, cso); - - evas_object_smart_member_add(member, obj); - /* begin: code that should be done from inside member_add() hook */ + if (!cso->clipper) + return; evas_object_clip_set(member, cso->clipper); if (evas_object_visible_get(obj)) evas_object_show(cso->clipper); - /* end */ } -/** - * Remove the given member from clipped smart object. - * - * This method is equivalent to evas_object_smart_member_del(), but - * will do extra work required to have clipped smart object to stop - * using the clipper, also hide the clipper if this is the last - * object. - * - * @param member the child/member to remove from its parent smart object. - * - * @todo add member_del() callback to Evas_Smart_Class. - */ -EAPI void -evas_object_smart_clipped_member_del(Evas_Object *member) +static void +evas_object_smart_clipped_smart_member_del(Evas_Object *obj, Evas_Object *member) { - Evas_Object *obj = evas_object_smart_parent_get(member); CSO_DATA_GET_OR_RETURN(obj, cso); - - evas_object_smart_member_del(member); - /* begin: code that should be done from inside member_del() hook */ + if (!cso->clipper) + return; evas_object_clip_unset(member); if (!evas_object_clipees_get(cso->clipper)) evas_object_hide(cso->clipper); - /* end */ } /** @@ -249,6 +226,8 @@ evas_object_smart_clipped_smart_set(Evas_Smart_Class *sc) sc->color_set = evas_object_smart_clipped_smart_color_set; sc->clip_set = evas_object_smart_clipped_smart_clip_set; sc->clip_unset = evas_object_smart_clipped_smart_clip_unset; + sc->member_add = evas_object_smart_clipped_smart_member_add; + sc->member_del = evas_object_smart_clipped_smart_member_del; } /** -- 2.7.4