From d9b421de4056a28584a3db9ea488fa674653dbd2 Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Mon, 13 Aug 2007 17:00:37 +0000 Subject: [PATCH] Make ::find_child_by_id() a method of ClutterContainer Finding a child by its ID is a method that should be used by every container and not only by ClutterGroup. This is needed to actually fix the picking in ClutterStage. --- clutter/clutter-container.c | 22 ++++++++++ clutter/clutter-container.h | 66 +++++++++++++++++------------- clutter/clutter-group.c | 66 ++++++++++++++++++------------ clutter/clutter-group.h | 4 +- doc/reference/Makefile.am | 2 +- doc/reference/clutter-sections.txt | 1 + 6 files changed, 103 insertions(+), 58 deletions(-) diff --git a/clutter/clutter-container.c b/clutter/clutter-container.c index ca1881081..2f918074c 100644 --- a/clutter/clutter-container.c +++ b/clutter/clutter-container.c @@ -377,3 +377,25 @@ clutter_container_foreach (ClutterContainer *container, CLUTTER_CONTAINER_GET_IFACE (container)->foreach (container, callback, user_data); } +/** + * clutter_container_find_child_by_id: + * @container: a #ClutterContainer + * @child_id: the unique id of an actor + * + * Finds a child actor of a container by its unique ID. Search recurses + * into any child container. + * + * Return value: The child actor with the requested id, or %NULL if no + * actor with that id was found + * + * Since: 0.6 + */ +ClutterActor * +clutter_container_find_child_by_id (ClutterContainer *container, + guint child_id) +{ + g_return_val_if_fail (CLUTTER_IS_CONTAINER (container), NULL); + + return CLUTTER_CONTAINER_GET_IFACE (container)->find_child_by_id (container, + child_id); +} diff --git a/clutter/clutter-container.h b/clutter/clutter-container.h index 103f17ed5..0e85d2ac8 100644 --- a/clutter/clutter-container.h +++ b/clutter/clutter-container.h @@ -46,6 +46,9 @@ typedef struct _ClutterContainerIface ClutterContainerIface; * @add: virtual function for adding an actor to the container * @remove: virtual function for removing an actor from the container * @foreach: virtual function for iterating over the container's children + * @find_child_by_id: virtual function for searching a container children + * using its unique id. Should recurse through its children. This function + * is used when "picking" actors (e.g. by clutter_stage_get_actor_at_pos()) * @actor_added: signal class handler for ClutterContainer::actor_added * @actor_removed: signal class handler for ClutterContainer::actor_removed * @@ -59,14 +62,16 @@ struct _ClutterContainerIface GTypeInterface g_iface; /*< public >*/ - void (* add) (ClutterContainer *container, - ClutterActor *actor); - void (* remove) (ClutterContainer *container, - ClutterActor *actor); - void (* foreach) (ClutterContainer *container, - ClutterCallback callback, - gpointer user_data); - + void (* add) (ClutterContainer *container, + ClutterActor *actor); + void (* remove) (ClutterContainer *container, + ClutterActor *actor); + void (* foreach) (ClutterContainer *container, + ClutterCallback callback, + gpointer user_data); + ClutterActor *(* find_child_by_id) (ClutterContainer *container, + guint child_id); + /* signals */ void (* actor_added) (ClutterContainer *container, ClutterActor *actor); @@ -74,28 +79,31 @@ struct _ClutterContainerIface ClutterActor *actor); }; -GType clutter_container_get_type (void) G_GNUC_CONST; +GType clutter_container_get_type (void) G_GNUC_CONST; + +void clutter_container_add (ClutterContainer *container, + ClutterActor *first_actor, + ...) G_GNUC_NULL_TERMINATED; +void clutter_container_add_actor (ClutterContainer *container, + ClutterActor *actor); +void clutter_container_add_valist (ClutterContainer *container, + ClutterActor *first_actor, + va_list var_args); +void clutter_container_remove (ClutterContainer *container, + ClutterActor *first_actor, + ...) G_GNUC_NULL_TERMINATED; +void clutter_container_remove_actor (ClutterContainer *container, + ClutterActor *actor); +void clutter_container_remove_valist (ClutterContainer *container, + ClutterActor *first_actor, + va_list var_args); +GList * clutter_container_get_children (ClutterContainer *container); +void clutter_container_foreach (ClutterContainer *container, + ClutterCallback callback, + gpointer user_data); +ClutterActor *clutter_container_find_child_by_id (ClutterContainer *container, + guint child_id); -void clutter_container_add (ClutterContainer *container, - ClutterActor *first_actor, - ...) G_GNUC_NULL_TERMINATED; -void clutter_container_add_actor (ClutterContainer *container, - ClutterActor *actor); -void clutter_container_add_valist (ClutterContainer *container, - ClutterActor *first_actor, - va_list var_args); -void clutter_container_remove (ClutterContainer *container, - ClutterActor *first_actor, - ...) G_GNUC_NULL_TERMINATED; -void clutter_container_remove_actor (ClutterContainer *container, - ClutterActor *actor); -void clutter_container_remove_valist (ClutterContainer *container, - ClutterActor *first_actor, - va_list var_args); -GList *clutter_container_get_children (ClutterContainer *container); -void clutter_container_foreach (ClutterContainer *container, - ClutterCallback callback, - gpointer user_data); G_END_DECLS diff --git a/clutter/clutter-group.c b/clutter/clutter-group.c index 9b8464591..5d5ce4747 100644 --- a/clutter/clutter-group.c +++ b/clutter/clutter-group.c @@ -282,12 +282,48 @@ clutter_group_real_foreach (ClutterContainer *container, (* callback) (CLUTTER_ACTOR (l->data), user_data); } +static ClutterActor * +clutter_group_real_find_child_by_id (ClutterContainer *container, + guint child_id) +{ + ClutterGroup *self = CLUTTER_GROUP (container); + ClutterGroupPrivate *priv = self->priv; + ClutterActor *actor = NULL; + GList *l; + + if (clutter_actor_get_id (CLUTTER_ACTOR (self)) == child_id) + return CLUTTER_ACTOR (self); + + for (l = priv->children; l; l = l->next) + { + ClutterActor *child = l->data; + + if (clutter_actor_get_id (child) == child_id) + { + actor = child; + break; + } + + if (CLUTTER_IS_CONTAINER (child)) + { + ClutterContainer *c = CLUTTER_CONTAINER (child); + + actor = clutter_container_find_child_by_id (c, child_id); + if (actor) + break; + } + } + + return actor; +} + static void clutter_container_iface_init (ClutterContainerIface *iface) { iface->add = clutter_group_real_add; iface->remove = clutter_group_real_remove; iface->foreach = clutter_group_real_foreach; + iface->find_child_by_id = clutter_group_real_find_child_by_id; } static void @@ -534,38 +570,16 @@ clutter_group_get_nth_child (ClutterGroup *self, * into any child groups. * * Returns: the #ClutterActor if found, or NULL. + * + * Deprecated: 0.6: Use clutter_container_find_child_by_id() instead. */ ClutterActor * clutter_group_find_child_by_id (ClutterGroup *self, guint id) { - ClutterActor *actor = NULL; - GList *l; - g_return_val_if_fail (CLUTTER_IS_GROUP (self), NULL); - if (clutter_actor_get_id (CLUTTER_ACTOR (self)) == id) - return CLUTTER_ACTOR (self); - - for (l = self->priv->children; l; l = l->next) - { - ClutterActor *child = l->data; - - if (clutter_actor_get_id (child) == id) - { - actor = child; - break; - } - - if (CLUTTER_IS_GROUP (child)) - { - actor = clutter_group_find_child_by_id (CLUTTER_GROUP (child), id); - if (actor) - break; - } - } - - return actor; + return clutter_container_find_child_by_id (CLUTTER_CONTAINER (self), id); } /** @@ -577,7 +591,7 @@ clutter_group_find_child_by_id (ClutterGroup *self, * FIXME */ void -clutter_group_raise (ClutterGroup *self, +clutter_group_raise (ClutterGroup *self, ClutterActor *actor, ClutterActor *sibling) { diff --git a/clutter/clutter-group.h b/clutter/clutter-group.h index 85c817b77..360bdf23c 100644 --- a/clutter/clutter-group.h +++ b/clutter/clutter-group.h @@ -86,8 +86,6 @@ struct _ClutterGroupClass GType clutter_group_get_type (void) G_GNUC_CONST; ClutterActor *clutter_group_new (void); -ClutterActor *clutter_group_find_child_by_id (ClutterGroup *self, - guint id); ClutterActor *clutter_group_get_nth_child (ClutterGroup *self, gint index_); gint clutter_group_get_n_children (ClutterGroup *self); @@ -104,6 +102,8 @@ void clutter_group_add_many_valist (ClutterGroup *group, va_list var_args); void clutter_group_remove (ClutterGroup *group, ClutterActor *actor); +ClutterActor *clutter_group_find_child_by_id (ClutterGroup *self, + guint id); #endif /* CLUTTER_DISABLE_DEPRECATED */ void clutter_group_raise (ClutterGroup *self, diff --git a/doc/reference/Makefile.am b/doc/reference/Makefile.am index 0e17a1909..c7f81461a 100644 --- a/doc/reference/Makefile.am +++ b/doc/reference/Makefile.am @@ -25,7 +25,7 @@ SCANGOBJ_OPTIONS=--type-init-func="clutter_base_init()" # Extra options to supply to gtkdoc-scan. # e.g. SCAN_OPTIONS=--deprecated-guards="GTK_DISABLE_DEPRECATED" -SCAN_OPTIONS= +SCAN_OPTIONS=--deprecated-guards="CLUTTER_DISABLE_DEPRECATED" # Extra options to supply to gtkdoc-mkdb. # e.g. MKDB_OPTIONS=--sgml-mode --output-format=xml diff --git a/doc/reference/clutter-sections.txt b/doc/reference/clutter-sections.txt index 6f25aae97..6026a4534 100644 --- a/doc/reference/clutter-sections.txt +++ b/doc/reference/clutter-sections.txt @@ -218,6 +218,7 @@ clutter_container_remove clutter_container_remove_valist clutter_container_get_children clutter_container_foreach +clutter_container_find_child_by_id ClutterContainer CLUTTER_TYPE_CONTAINER