From d72c60d2690aac0745923b4d1ea3e758102593a4 Mon Sep 17 00:00:00 2001 From: Carsten Haitzler Date: Wed, 28 Dec 2011 05:07:31 +0000 Subject: [PATCH] add recursive name fund func evas_object_name_child_find() SVN revision: 66587 --- legacy/evas/ChangeLog | 4 ++++ legacy/evas/src/lib/Evas.h | 26 +++++++++++++++++++++ legacy/evas/src/lib/canvas/evas_name.c | 32 ++++++++++++++++++++++++++ 3 files changed, 62 insertions(+) diff --git a/legacy/evas/ChangeLog b/legacy/evas/ChangeLog index d95ab7d8da..28d7f452c7 100644 --- a/legacy/evas/ChangeLog +++ b/legacy/evas/ChangeLog @@ -596,3 +596,7 @@ * Add feature to get number of pressed devices (help fix ecore-evas bug). +2011-12-28 Carsten Haitzler (The Rasterman) + + * Add recursive name find function - evas_object_name_child_find() + diff --git a/legacy/evas/src/lib/Evas.h b/legacy/evas/src/lib/Evas.h index ae0584fa27..a0a29e5ef1 100644 --- a/legacy/evas/src/lib/Evas.h +++ b/legacy/evas/src/lib/Evas.h @@ -5791,10 +5791,36 @@ EAPI Evas_Object *evas_focus_get (const Evas *e) EINA_WA * @param name The given name. * @return If successful, the Evas object with the given name. Otherwise, * @c NULL. + * + * This looks for the evas object given a name by evas_object_name_set(). If + * the name is not unique canvas-wide, then which one of the many objects + * with that name is returned is undefined, so only use this if you can ensure + * the object name is unique. + * * @ingroup Evas_Object_Group_Find */ EAPI Evas_Object *evas_object_name_find (const Evas *e, const char *name) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE; +/** + * Retrieves the object from children of the given objec with the given name. + * @param obj The parent (smart) object whose children to search. + * @param name The given name. + * @param recurse set to EINA_TRUE if this is to recurse down child objects. + * @return If successful, the Evas object with the given name. Otherwise, + * @c NULL. + * + * This looks for the evas object given a name by evas_object_name_set(), but + * it ONLY looks at the children of the biecjt *p obj, and will only recurse + * into thsoe children if @p recurse is set to EINA_TRUE. If the name is not + * unique within immediate children (or the whole child tree) then it is not + * defined which child object will be returned. + * + * @since 1.2 + * + * @ingroup Evas_Object_Group_Find + */ +EAPI Evas_Object *evas_object_name_child_find (const Evas_Object *obj, const char *name, Eina_Bool recurse) EINA_WARN_UNUSED_RESULT EINA_ARG_NONNULL(1) EINA_PURE; + /** * Retrieve the Evas object stacked at the top of a given position in * a canvas diff --git a/legacy/evas/src/lib/canvas/evas_name.c b/legacy/evas/src/lib/canvas/evas_name.c index c42f94165e..2a74805ef0 100644 --- a/legacy/evas/src/lib/canvas/evas_name.c +++ b/legacy/evas/src/lib/canvas/evas_name.c @@ -38,3 +38,35 @@ evas_object_name_find(const Evas *e, const char *name) if (!name) return NULL; return (Evas_Object *)eina_hash_find(e->name_hash, name); } + +static Evas_Object * +_evas_object_name_child_find(const Evas_Object *obj, const char *name, Eina_Bool recurse) +{ + const Eina_Inlist *lst; + Evas_Object *child; + + if (!obj->smart.smart) return NULL; + lst = evas_object_smart_members_get_direct(obj); + EINA_INLIST_FOREACH(lst, child) + { + if (child->delete_me) continue; + if (!child->name) continue; + if (!strcmp(name, child->name)) return child; + if (recurse) + { + if ((obj = _evas_object_name_child_find(child, name, recurse))) + return obj; + } + } + return NULL; +} + +EAPI Evas_Object * +evas_object_name_child_find(const Evas_Object *obj, const char *name, Eina_Bool recurse) +{ + MAGIC_CHECK(obj, Evas_Object, MAGIC_OBJ); + return NULL; + MAGIC_CHECK_END(); + if (!name) return NULL; + return _evas_object_name_child_find(obj, name, recurse); +}