[gtk+] Container: Fix scrolled coord in set_focus_child()



commit c4865bed432073ff8ed0551e16169c57f5633b32
Author: Daniel Boles <dboles src gnome org>
Date:   Mon Aug 7 18:25:28 2017 +0100

    Container: Fix scrolled coord in set_focus_child()
    
    Commit 885bcd9fe4b6b4ecb003570ea0520cf42ec737a9 trampled the bit here
    that is meant to translate between the nominated focus child and the
    actual innermost one that is used for updating the h/v adjustments.
    
    So, we need to save the passed focus child before diving into its
    children, then translate and get allocations between them both. This
    makes GTK+ 4 behave like GTK+ 3 again: instead of priv->focus_child and
    focus_child, we now have focus_child and child, serving the roles of the
    nominated focus child and its innermost focus child respectively.
    
    This also ditches the unnecessary call to Widget:get_focus_child(), as
    Container::set_focus_child() gets that same new child as an argument.

 gtk/gtkcontainer.c |   20 +++++++++-----------
 1 files changed, 9 insertions(+), 11 deletions(-)
---
diff --git a/gtk/gtkcontainer.c b/gtk/gtkcontainer.c
index 0a2dbf9..bc52c99 100644
--- a/gtk/gtkcontainer.c
+++ b/gtk/gtkcontainer.c
@@ -2032,15 +2032,11 @@ gtk_container_compute_expand (GtkWidget         *widget,
 }
 
 static void
-gtk_container_real_set_focus_child (GtkContainer     *container,
-                                    GtkWidget        *child)
+gtk_container_real_set_focus_child (GtkContainer *container,
+                                    GtkWidget    *focus_child)
 {
-  GtkWidget *focus_child;
-
   g_return_if_fail (GTK_IS_CONTAINER (container));
-  g_return_if_fail (child == NULL || GTK_IS_WIDGET (child));
-
-  focus_child = gtk_widget_get_focus_child (GTK_WIDGET (container));
+  g_return_if_fail (focus_child == NULL || GTK_IS_WIDGET (focus_child));
 
   /* check for h/v adjustments
    */
@@ -2055,17 +2051,19 @@ gtk_container_real_set_focus_child (GtkContainer     *container,
       vadj = g_object_get_qdata (G_OBJECT (container), vadjustment_key_id);
       if (hadj || vadj)
         {
-          while (gtk_widget_get_focus_child (focus_child))
-            focus_child = gtk_widget_get_focus_child (focus_child);
+          GtkWidget *child = focus_child;
+
+          while (gtk_widget_get_focus_child (child))
+            child = gtk_widget_get_focus_child (child);
 
-          gtk_widget_translate_coordinates (focus_child, focus_child,
+          gtk_widget_translate_coordinates (child, focus_child,
                                             0, 0, &x, &y);
 
           _gtk_widget_get_allocation (focus_child, &allocation);
           x += allocation.x;
           y += allocation.y;
 
-          _gtk_widget_get_allocation (focus_child, &allocation);
+          _gtk_widget_get_allocation (child, &allocation);
 
           if (vadj)
             gtk_adjustment_clamp_page (vadj, y, y + allocation.height);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]