From d4ff5e2d314ea98f91a13b29c597f4a710b640c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marco=20Trevisan=20=28Trevi=C3=B1o=29?= Date: Mon, 14 Oct 2019 16:38:59 +0200 Subject: [PATCH] clutter/actor: Remove deprecated clutter container foreach This is deprecated, so replace it with ClutterActorIter or alternative funcs https://gitlab.gnome.org/GNOME/mutter/merge_requests/816 --- clutter/clutter/clutter-container.c | 94 +------------------ clutter/clutter/clutter-container.h | 7 +- clutter/clutter/clutter-stage.c | 15 --- .../clutter/deprecated/clutter-container.h | 5 - clutter/clutter/deprecated/clutter-group.c | 38 +++----- cogl/tests/conform/test-readpixels.c | 6 +- cogl/tests/conform/test-viewport.c | 4 +- 7 files changed, 21 insertions(+), 148 deletions(-) diff --git a/clutter/clutter/clutter-container.c b/clutter/clutter/clutter-container.c index 78f8a24a3..2f3139e49 100644 --- a/clutter/clutter/clutter-container.c +++ b/clutter/clutter/clutter-container.c @@ -118,37 +118,6 @@ container_real_remove (ClutterContainer *container, clutter_actor_remove_child (CLUTTER_ACTOR (container), actor); } -typedef struct { - ClutterCallback callback; - gpointer data; -} ForeachClosure; - -static gboolean -foreach_cb (ClutterActor *actor, - gpointer data) -{ - ForeachClosure *clos = data; - - clos->callback (actor, clos->data); - - return TRUE; -} - -static void -container_real_foreach (ClutterContainer *container, - ClutterCallback callback, - gpointer user_data) -{ - ForeachClosure clos; - - clos.callback = callback; - clos.data = user_data; - - _clutter_actor_foreach_child (CLUTTER_ACTOR (container), - foreach_cb, - &clos); -} - static void container_real_raise (ClutterContainer *container, ClutterActor *child, @@ -243,7 +212,6 @@ clutter_container_default_init (ClutterContainerInterface *iface) iface->add = container_real_add; iface->remove = container_real_remove; - iface->foreach = container_real_foreach; iface->raise = container_real_raise; iface->lower = container_real_lower; iface->sort_depth_order = container_real_sort_depth_order; @@ -533,15 +501,6 @@ clutter_container_remove_valist (ClutterContainer *container, container_remove_valist (container, first_actor, var_args); } -static void -get_children_cb (ClutterActor *child, - gpointer data) -{ - GList **children = data; - - *children = g_list_prepend (*children, child); -} - /** * clutter_container_get_children: * @container: a #ClutterContainer @@ -559,60 +518,9 @@ get_children_cb (ClutterActor *child, GList * clutter_container_get_children (ClutterContainer *container) { - GList *retval; - g_return_val_if_fail (CLUTTER_IS_CONTAINER (container), NULL); - retval = NULL; - clutter_container_foreach (container, get_children_cb, &retval); - - return g_list_reverse (retval); -} - -/** - * clutter_container_foreach: - * @container: a #ClutterContainer - * @callback: (scope call): a function to be called for each child - * @user_data: data to be passed to the function, or %NULL - * - * Calls @callback for each child of @container that was added - * by the application (with clutter_container_add_actor()). - * - * This function calls the #ClutterContainerIface.foreach() - * virtual function, which has been deprecated. - * - * Since: 0.4 - * - * Deprecated: 1.10: Use clutter_actor_get_first_child() or - * clutter_actor_get_last_child() to retrieve the beginning of - * the list of children, and clutter_actor_get_next_sibling() - * and clutter_actor_get_previous_sibling() to iterate over it; - * alternatively, use the #ClutterActorIter API. - */ -void -clutter_container_foreach (ClutterContainer *container, - ClutterCallback callback, - gpointer user_data) -{ - g_return_if_fail (CLUTTER_IS_CONTAINER (container)); - g_return_if_fail (callback != NULL); - -#ifdef CLUTTER_ENABLE_DEBUG - if (G_UNLIKELY (_clutter_diagnostic_enabled ())) - { - ClutterContainerIface *iface = CLUTTER_CONTAINER_GET_IFACE (container); - - if (iface->foreach != container_real_foreach) - _clutter_diagnostic_message ("The ClutterContainer::foreach() " - "virtual function has been deprecated " - "and it should not be overridden by " - "newly written code"); - } -#endif /* CLUTTER_ENABLE_DEBUG */ - - CLUTTER_CONTAINER_GET_IFACE (container)->foreach (container, - callback, - user_data); + return clutter_actor_get_children (CLUTTER_ACTOR (container)); } /** diff --git a/clutter/clutter/clutter-container.h b/clutter/clutter/clutter-container.h index 02107394f..26b991c9c 100644 --- a/clutter/clutter/clutter-container.h +++ b/clutter/clutter/clutter-container.h @@ -59,8 +59,6 @@ typedef struct _ClutterContainerIface ClutterContainerIface; * function is deprecated, and it should not be overridden. * @remove: virtual function for removing an actor from the container. This * virtual function is deprecated, and it should not be overridden. - * @foreach: virtual function for iterating over the container's children. - * This virtual function is deprecated, and it should not be overridden. * @raise: virtual function for raising a child. This virtual function is * deprecated and it should not be overridden. * @lower: virtual function for lowering a child. This virtual function is @@ -82,7 +80,7 @@ typedef struct _ClutterContainerIface ClutterContainerIface; * @actor_removed: class handler for #ClutterContainer::actor-removed * @child_notify: class handler for #ClutterContainer::child-notify * - * Base interface for container actors. The @add, @remove and @foreach + * Base interface for container actors. The @add and @remove * virtual functions must be provided by any implementation; the other * virtual functions are optional. * @@ -98,9 +96,6 @@ struct _ClutterContainerIface ClutterActor *actor); void (* remove) (ClutterContainer *container, ClutterActor *actor); - void (* foreach) (ClutterContainer *container, - ClutterCallback callback, - gpointer user_data); /* child stacking */ void (* raise) (ClutterContainer *container, diff --git a/clutter/clutter/clutter-stage.c b/clutter/clutter/clutter-stage.c index 245cb8997..196237d89 100644 --- a/clutter/clutter/clutter-stage.c +++ b/clutter/clutter/clutter-stage.c @@ -249,20 +249,6 @@ clutter_stage_real_remove (ClutterContainer *container, clutter_actor_remove_child (CLUTTER_ACTOR (container), child); } -static void -clutter_stage_real_foreach (ClutterContainer *container, - ClutterCallback callback, - gpointer user_data) -{ - ClutterActorIter iter; - ClutterActor *child; - - clutter_actor_iter_init (&iter, CLUTTER_ACTOR (container)); - - while (clutter_actor_iter_next (&iter, &child)) - callback (child, user_data); -} - static void clutter_stage_real_raise (ClutterContainer *container, ClutterActor *child, @@ -293,7 +279,6 @@ clutter_container_iface_init (ClutterContainerIface *iface) { iface->add = clutter_stage_real_add; iface->remove = clutter_stage_real_remove; - iface->foreach = clutter_stage_real_foreach; iface->raise = clutter_stage_real_raise; iface->lower = clutter_stage_real_lower; iface->sort_depth_order = clutter_stage_real_sort_depth_order; diff --git a/clutter/clutter/deprecated/clutter-container.h b/clutter/clutter/deprecated/clutter-container.h index 545bf3b2b..8bb6f640c 100644 --- a/clutter/clutter/deprecated/clutter-container.h +++ b/clutter/clutter/deprecated/clutter-container.h @@ -65,11 +65,6 @@ void clutter_container_remove_valist (ClutterContaine CLUTTER_DEPRECATED_FOR(clutter_actor_get_children) GList * clutter_container_get_children (ClutterContainer *container); -CLUTTER_DEPRECATED -void clutter_container_foreach (ClutterContainer *container, - ClutterCallback callback, - gpointer user_data); - CLUTTER_DEPRECATED_FOR(clutter_actor_set_child_above_sibling) void clutter_container_raise_child (ClutterContainer *container, ClutterActor *actor, diff --git a/clutter/clutter/deprecated/clutter-group.c b/clutter/clutter/deprecated/clutter-group.c index d8f10652d..cc56c3bda 100644 --- a/clutter/clutter/deprecated/clutter-group.c +++ b/clutter/clutter/deprecated/clutter-group.c @@ -170,20 +170,6 @@ clutter_group_real_actor_removed (ClutterContainer *container, priv->children = g_list_remove (priv->children, actor); } -static void -clutter_group_real_foreach (ClutterContainer *container, - ClutterCallback callback, - gpointer user_data) -{ - ClutterGroupPrivate *priv = CLUTTER_GROUP (container)->priv; - - /* Using g_list_foreach instead of iterating the list manually - because it has better protection against the current node being - removed. This will happen for example if someone calls - clutter_container_foreach(container, clutter_actor_destroy) */ - g_list_foreach (priv->children, (GFunc) callback, user_data); -} - static void clutter_group_real_raise (ClutterContainer *container, ClutterActor *actor, @@ -285,7 +271,6 @@ clutter_container_iface_init (ClutterContainerIface *iface) iface->actor_added = clutter_group_real_actor_added; iface->remove = clutter_group_real_remove; iface->actor_removed = clutter_group_real_actor_removed; - iface->foreach = clutter_group_real_foreach; iface->raise = clutter_group_real_raise; iface->lower = clutter_group_real_lower; iface->sort_depth_order = clutter_group_real_sort_depth_order; @@ -391,21 +376,28 @@ clutter_group_dispose (GObject *object) } static void -clutter_group_real_show_all (ClutterActor *actor) +clutter_group_real_show_all (ClutterActor *self) { - clutter_container_foreach (CLUTTER_CONTAINER (actor), - CLUTTER_CALLBACK (clutter_actor_show), - NULL); - clutter_actor_show (actor); + ClutterActorIter iter; + ClutterActor *actor; + + clutter_actor_iter_init (&iter, self); + while (clutter_actor_iter_next (&iter, &actor)) + clutter_actor_show (actor); + + clutter_actor_show (self); } static void clutter_group_real_hide_all (ClutterActor *actor) { + ClutterActorIter iter; + clutter_actor_hide (actor); - clutter_container_foreach (CLUTTER_CONTAINER (actor), - CLUTTER_CALLBACK (clutter_actor_hide), - NULL); + + clutter_actor_iter_init (&iter, actor); + while (clutter_actor_iter_next (&iter, &actor)) + clutter_actor_hide (actor); } static gboolean diff --git a/cogl/tests/conform/test-readpixels.c b/cogl/tests/conform/test-readpixels.c index a180ec329..45d137791 100644 --- a/cogl/tests/conform/test-readpixels.c +++ b/cogl/tests/conform/test-readpixels.c @@ -152,6 +152,8 @@ test_readpixels (TestUtilsGTestFixture *fixture, { unsigned int idle_source; ClutterActor *stage; + ClutterActorIter iter; + ClutterActor *actor; stage = clutter_stage_get_default (); clutter_stage_set_color (CLUTTER_STAGE (stage), &stage_color); @@ -168,9 +170,7 @@ test_readpixels (TestUtilsGTestFixture *fixture, g_source_remove (idle_source); /* Remove all of the actors from the stage */ - clutter_container_foreach (CLUTTER_CONTAINER (stage), - (ClutterCallback) clutter_actor_destroy, - NULL); + clutter_actor_remove_all_children (stage); if (cogl_test_verbose ()) g_print ("OK\n"); diff --git a/cogl/tests/conform/test-viewport.c b/cogl/tests/conform/test-viewport.c index b694b1eac..308d740cd 100644 --- a/cogl/tests/conform/test-viewport.c +++ b/cogl/tests/conform/test-viewport.c @@ -406,9 +406,7 @@ test_viewport (TestUtilsGTestFixture *fixture, g_source_remove (idle_source); /* Remove all of the actors from the stage */ - clutter_container_foreach (CLUTTER_CONTAINER (stage), - (ClutterCallback) clutter_actor_destroy, - NULL); + clutter_actor_remove_all_children (stage); if (cogl_test_verbose ()) g_print ("OK\n");