[gtk+] GtkApplicationWindow: Fix resize grip positioning



commit 681871dd9ed12b8dae9a685f176c1e6de4a962e3
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Jan 20 01:01:08 2012 -0500

    GtkApplicationWindow: Fix resize grip positioning
    
    Based on a patch by Carlos Garcia Campos, bug 668248

 gtk/gtkapplicationwindow.c |    3 +-
 gtk/gtkwindow.c            |   65 ++++++++++++++++++++++++++++---------------
 gtk/gtkwindowprivate.h     |    3 ++
 3 files changed, 47 insertions(+), 24 deletions(-)
---
diff --git a/gtk/gtkapplicationwindow.c b/gtk/gtkapplicationwindow.c
index 9a7aa35..a95dcb6 100644
--- a/gtk/gtkapplicationwindow.c
+++ b/gtk/gtkapplicationwindow.c
@@ -24,6 +24,7 @@
 #include "gtkapplicationwindow.h"
 
 #include "gtkapplicationprivate.h"
+#include "gtkwindowprivate.h"
 #include "gtkmodelmenu.h"
 #include "gactionmuxer.h"
 #include "gtkaccelgroup.h"
@@ -635,7 +636,7 @@ gtk_application_window_real_size_allocate (GtkWidget     *widget,
       gint menubar_height;
       GtkWidget *child;
 
-      gtk_widget_set_allocation (widget, allocation);
+      _gtk_window_set_allocation (GTK_WINDOW (widget), allocation);
 
       gtk_widget_get_preferred_height_for_width (window->priv->menubar, allocation->width, &menubar_height, NULL);
 
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 0204252..0241cf8 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -5530,34 +5530,55 @@ set_grip_position (GtkWindow *window)
                           rect.width, rect.height);
 }
 
-static void
-gtk_window_size_allocate (GtkWidget     *widget,
-			  GtkAllocation *allocation)
+/* _gtk_window_set_allocation:
+ * @window: a #GtkWindow
+ * @allocation: the new allocation
+ *
+ * This function is like gtk_widget_set_allocation()
+ * but does the necessary extra work to update
+ * the resize grip positioning, etc.
+ *
+ * Call this instead of gtk_widget_set_allocation()
+ * when overriding ::size_allocate in a GtkWindow
+ * subclass without chaining up.
+ */
+void
+_gtk_window_set_allocation (GtkWindow     *window,
+                            GtkAllocation *allocation)
 {
-  GtkWindow *window = GTK_WINDOW (widget);
-  GtkAllocation child_allocation;
-  GtkWidget *child;
-  guint border_width;
+  GtkWidget *widget = (GtkWidget *)window;
 
   gtk_widget_set_allocation (widget, allocation);
 
   if (gtk_widget_get_realized (widget))
     {
-      /* If it's not a toplevel we're embedded, we need to resize the window's 
-       * window and skip the grip.
+      /* If it's not a toplevel we're embedded, we need to resize
+       * the window's window and skip the grip.
        */
       if (!gtk_widget_is_toplevel (widget))
-	{
-	  gdk_window_move_resize (gtk_widget_get_window (widget),
-				  allocation->x, allocation->y,
-				  allocation->width, allocation->height);
-	}
+        {
+          gdk_window_move_resize (gtk_widget_get_window (widget),
+                                  allocation->x, allocation->y,
+                                  allocation->width, allocation->height);
+        }
       else
-	{
-	  update_grip_visibility (window);
-	  set_grip_position (window);
-	}
+        {
+          update_grip_visibility (window);
+          set_grip_position (window);
+        }
     }
+}
+
+static void
+gtk_window_size_allocate (GtkWidget     *widget,
+                          GtkAllocation *allocation)
+{
+  GtkWindow *window = GTK_WINDOW (widget);
+  GtkAllocation child_allocation;
+  GtkWidget *child;
+  guint border_width;
+
+  _gtk_window_set_allocation (window, allocation);
 
   child = gtk_bin_get_child (&(window->bin));
   if (child && gtk_widget_get_visible (child))
@@ -5565,10 +5586,8 @@ gtk_window_size_allocate (GtkWidget     *widget,
       border_width = gtk_container_get_border_width (GTK_CONTAINER (window));
       child_allocation.x = border_width;
       child_allocation.y = border_width;
-      child_allocation.width =
-	MAX (1, (gint)allocation->width - child_allocation.x * 2);
-      child_allocation.height =
-	MAX (1, (gint)allocation->height - child_allocation.y * 2);
+      child_allocation.width = MAX (1, allocation->width - border_width * 2);
+      child_allocation.height = MAX (1, allocation->height - border_width * 2);
 
       gtk_widget_size_allocate (child, &child_allocation);
     }
@@ -5904,7 +5923,7 @@ gtk_window_get_has_resize_grip (GtkWindow *window)
  * Since: 3.0
  */
 gboolean
-gtk_window_get_resize_grip_area (GtkWindow *window,
+gtk_window_get_resize_grip_area (GtkWindow    *window,
                                  GdkRectangle *rect)
 {
   GtkWidget *widget = GTK_WIDGET (window);
diff --git a/gtk/gtkwindowprivate.h b/gtk/gtkwindowprivate.h
index 4c95531..5629392 100644
--- a/gtk/gtkwindowprivate.h
+++ b/gtk/gtkwindowprivate.h
@@ -68,6 +68,9 @@ void            _gtk_window_get_wmclass            (GtkWindow  *window,
                                                     gchar     **wmclass_name,
                                                     gchar     **wmclass_class);
 
+void            _gtk_window_set_allocation         (GtkWindow     *window,
+                                                    GtkAllocation *allocation);
+
 typedef void (*GtkWindowKeysForeachFunc) (GtkWindow      *window,
                                           guint           keyval,
                                           GdkModifierType modifiers,



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