summaryrefslogtreecommitdiff
path: root/gtk/gtkbox.c
diff options
context:
space:
mode:
authorMichael Natterer <mitch@gimp.org>2011-09-26 00:46:16 +0200
committerMichael Natterer <mitch@gimp.org>2011-09-26 00:52:28 +0200
commita6151ebb9566ed39a6b100d1cca6d5eae7246201 (patch)
tree743a234020bf2ddd57b5a0c28d6ded2ff75794e1 /gtk/gtkbox.c
parent66becfdab111319f281f222129ba35e840b63cc6 (diff)
downloadgtk+-a6151ebb9566ed39a6b100d1cca6d5eae7246201.tar.gz
GtkBox: make get_path_for_child() work if there are internal children
Use foreach() instead of forall() to find the child's siblings because internal children of subclasses have no sibling relation to the box' children. Also deal with the subclass failing to implement get_path_for_child(). This caused an infinite widget path invalidation loop of sorts with GimpMessageBox, which is a vertical box with a decorative icon to the left.
Diffstat (limited to 'gtk/gtkbox.c')
-rw-r--r--gtk/gtkbox.c38
1 files changed, 25 insertions, 13 deletions
diff --git a/gtk/gtkbox.c b/gtk/gtkbox.c
index eacbabfad6..cb68b423b1 100644
--- a/gtk/gtkbox.c
+++ b/gtk/gtkbox.c
@@ -861,18 +861,24 @@ count_widget_position (GtkWidget *widget,
count->before++;
}
-static guint
-gtk_box_get_visible_position (GtkBox *box,
+static gint
+gtk_box_get_visible_position (GtkBox *box,
GtkWidget *child)
{
CountingData count = { child, FALSE, 0, 0 };
- /* forall iterates in visible order */
- gtk_container_forall (GTK_CONTAINER (box),
- count_widget_position,
- &count);
+ /* foreach iterates in visible order */
+ gtk_container_foreach (GTK_CONTAINER (box),
+ count_widget_position,
+ &count);
+
+ /* the child wasn't found, it's likely an internal child of some
+ * subclass, return -1 to indicate that there is no sibling relation
+ * to the regular box children
+ */
+ if (!count.found)
+ return -1;
- g_assert (count.found);
if (box->priv->orientation == GTK_ORIENTATION_HORIZONTAL &&
gtk_widget_get_direction (GTK_WIDGET (box)) == GTK_TEXT_DIR_RTL)
return count.after;
@@ -896,6 +902,8 @@ gtk_box_get_path_for_child (GtkContainer *container,
if (gtk_widget_get_visible (child))
{
+ gint position;
+
sibling_path = gtk_widget_path_new ();
/* get_children works in visible order */
@@ -911,13 +919,17 @@ gtk_box_get_path_for_child (GtkContainer *container,
gtk_widget_path_append_for_widget (sibling_path, list->data);
}
- g_list_free (children);
- gtk_widget_path_append_with_siblings (path,
- sibling_path,
- gtk_box_get_visible_position (box,
- child));
- gtk_widget_path_unref (sibling_path);
+ g_list_free (children);
+
+ position = gtk_box_get_visible_position (box, child);
+
+ if (position >= 0)
+ gtk_widget_path_append_with_siblings (path, sibling_path, position);
+ else
+ gtk_widget_path_append_for_widget (path, child);
+
+ gtk_widget_path_unref (sibling_path);
}
else
gtk_widget_path_append_for_widget (path, child);