[gtk+/resizegrips] Fix various corner cases



commit 76443417c82d29040077e534a74068df42b0ab77
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Oct 3 00:37:26 2010 -0400

    Fix various corner cases
    
    In the RTL case, ranges were not moved correctly. Also, make
    ranges listen for notify::resize-grip-visible.

 gtk/gtkrange.c  |  201 ++++++++++++++++++++++---------------------------------
 gtk/gtkwindow.c |   37 +++++-----
 2 files changed, 98 insertions(+), 140 deletions(-)
---
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index 939df45..0cda3cf 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -186,6 +186,8 @@ static void gtk_range_size_request   (GtkWidget        *widget,
                                       GtkRequisition   *requisition);
 static void gtk_range_size_allocate  (GtkWidget        *widget,
                                       GtkAllocation    *allocation);
+static void gtk_range_hierarchy_changed (GtkWidget     *widget,
+                                         GtkWidget     *previous_toplevel);
 static void gtk_range_realize        (GtkWidget        *widget);
 static void gtk_range_unrealize      (GtkWidget        *widget);
 static void gtk_range_map            (GtkWidget        *widget);
@@ -216,7 +218,8 @@ static void update_slider_position   (GtkRange	       *range,
 				      gint              mouse_x,
 				      gint              mouse_y);
 static void stop_scrolling           (GtkRange         *range);
-static gint get_fixup_for_window_grip (GtkWidget       *widget);
+static gboolean modify_allocation_for_window_grip (GtkWidget     *widget,
+                                                   GtkAllocation *allocation);
 
 /* Range methods */
 
@@ -292,8 +295,9 @@ gtk_range_class_init (GtkRangeClass *class)
   widget_class->destroy = gtk_range_destroy;
   widget_class->size_request = gtk_range_size_request;
   widget_class->size_allocate = gtk_range_size_allocate;
+  widget_class->hierarchy_changed = gtk_range_hierarchy_changed;
   widget_class->realize = gtk_range_realize;
-  widget_class->unrealize = gtk_range_unrealize;  
+  widget_class->unrealize = gtk_range_unrealize;
   widget_class->map = gtk_range_map;
   widget_class->unmap = gtk_range_unmap;
   widget_class->draw = gtk_range_draw;
@@ -1571,122 +1575,63 @@ gtk_range_size_request (GtkWidget      *widget,
   requisition->height = range_rect.height + border.top + border.bottom;
 }
 
-static GtkWidget *
-find_toplevel_window (GtkWidget *widget)
-{
-  if (GTK_IS_WINDOW (widget))
-    {
-      return widget;
-    }
-  else if (gtk_widget_get_parent (widget))
-    {
-      return find_toplevel_window (gtk_widget_get_parent (widget));
-    }
-  else
-    {
-      return NULL;
-    }
-}
-
-static gint
-get_fixup_for_window_grip (GtkWidget *widget)
+static gboolean
+modify_allocation_for_window_grip (GtkWidget     *widget,
+                                   GtkAllocation *allocation)
 {
-  GtkWidget *window;
   GtkRange *range = GTK_RANGE (widget);
+  GtkRangePrivate *priv = range->priv;
+  GtkWidget *window;
+  GdkRectangle grip_rect;
+  GdkRectangle translated_rect;
+  gint x;
+  gint y;
 
-  window = find_toplevel_window (widget);
-  if (window == NULL)
-    {
-      return 0;
-    }
+  window = gtk_widget_get_toplevel (widget);
+  if (!GTK_IS_WINDOW (window))
+    return FALSE;
 
   if (!gtk_window_resize_grip_is_visible (GTK_WINDOW (window)))
-    {
-      return 0;
-    }
-
-  if (gtk_window_get_has_resize_grip (GTK_WINDOW (window)))
-    {
-      GtkRangePrivate *priv;
-      GdkRectangle grip_rect;
-      GdkRectangle orig_rect;
-      GdkRectangle translated_rect;
-      gint x = 0;
-      gint y = 0;
-
-      priv = range->priv;
+    return FALSE;
 
-      gtk_range_calc_layout (range, priv->adjustment->value);
+  /* Get the area of the window's corner grip */
+  gtk_window_get_resize_grip_area (GTK_WINDOW (window), &grip_rect);
 
-      /* Get the area of the window's corner grip */
-      gtk_window_get_resize_grip_area (GTK_WINDOW (window),
-                                       &grip_rect);
+  x = 0;
+  y = 0;
 
-      /* Get the area of the stepper that might be blocked by the grip */
-      if (gtk_widget_get_direction (window) == GTK_TEXT_DIR_LTR)
-        {
-          orig_rect = priv->stepper_d;
-        }
-      else
-        {
-          orig_rect = priv->stepper_a;
-        }
+  /* Translate the stepper's area into window coords */
+  if (gtk_widget_translate_coordinates (gtk_widget_get_parent (widget),
+                                        window,
+                                        allocation->x,
+                                        allocation->y,
+                                        &x,
+                                        &y))
+    {
+      translated_rect.x = x;
+      translated_rect.y = y;
+      translated_rect.width = allocation->width;
+      translated_rect.height = allocation->height;
 
-      /* Translate the stepper's area into window coords */
-      if (gtk_widget_translate_coordinates (widget,
-                                            window,
-                                            orig_rect.x - 1,
-                                            orig_rect.y - 1,
-                                            &x,
-                                            &y))
+      /* If the stepper button intersects the window resize grip.. */
+      if (gdk_rectangle_intersect (&grip_rect, &translated_rect, NULL))
         {
-          translated_rect.x = x;
-          translated_rect.y = y;
-          translated_rect.width = orig_rect.width;
-          translated_rect.height = orig_rect.height;
-
-          /* If the stepper button intersects the window resize grip.. */
-          if (gdk_rectangle_intersect (&grip_rect, &translated_rect, NULL))
+          if (priv->orientation == GTK_ORIENTATION_HORIZONTAL)
             {
-              gint grip_height;
-              gint grip_width;
-
-              /* Return the height of the grip */
-              gtk_widget_style_get (window,
-                                    "resize-grip-height", &grip_height,
-                                    "resize-grip-width",  &grip_width,
-                                    NULL);
-
-              if (gtk_orientable_get_orientation (GTK_ORIENTABLE (range)) == GTK_ORIENTATION_HORIZONTAL)
-                return grip_width;
-              else
-                return grip_height;
+              allocation->width -= grip_rect.width;
+              if (gtk_widget_get_direction (window) == GTK_TEXT_DIR_RTL)
+                allocation->x += grip_rect.width;
+            }
+          else
+            {
+              allocation->height -= grip_rect.height;
             }
-        }
-    }
-
-  return 0;
-}
-
-static void
-fixup_for_window_grip (GtkWidget *widget)
-{
-  GtkAllocation allocation;
-  gint fixup;
-
-  fixup = get_fixup_for_window_grip (widget);
-  gtk_widget_get_allocation (widget, &allocation);
 
-  if (gtk_orientable_get_orientation (GTK_ORIENTABLE (widget)) == GTK_ORIENTATION_VERTICAL)
-    {
-      allocation.height -= fixup;
-    }
-  else
-    {
-      allocation.width -= fixup;
+          return TRUE;
+        }
     }
 
-  gtk_widget_set_allocation (widget, &allocation);
+  return FALSE;
 }
 
 static void
@@ -1695,21 +1640,8 @@ gtk_range_size_allocate (GtkWidget     *widget,
 {
   GtkRange *range = GTK_RANGE (widget);
   GtkRangePrivate *priv = range->priv;
-  gint fixup;
-
-  gtk_widget_set_allocation (widget, allocation);
-
-  fixup = get_fixup_for_window_grip (widget);
-
-  if (gtk_orientable_get_orientation (GTK_ORIENTABLE (range)) == GTK_ORIENTATION_VERTICAL)
-    {
-      allocation->height -= fixup;
-    }
-  else
-    {
-      allocation->width -= fixup;
-    }
 
+  modify_allocation_for_window_grip (widget, allocation);
   gtk_widget_set_allocation (widget, allocation);
 
   priv->recalc_marks = TRUE;
@@ -1724,6 +1656,33 @@ gtk_range_size_allocate (GtkWidget     *widget,
 }
 
 static void
+resize_grip_visible_changed (GObject    *object,
+                             GParamSpec *pspec,
+                             gpointer    user_data)
+{
+  gtk_widget_queue_resize (GTK_WIDGET (user_data));
+}
+
+static void
+gtk_range_hierarchy_changed (GtkWidget *widget,
+                             GtkWidget *previous_toplevel)
+{
+  GtkRange *range = GTK_RANGE (widget);
+  GtkRangePrivate *priv = range->priv;
+  GtkWidget *window;
+
+  if (previous_toplevel)
+    g_signal_handlers_disconnect_by_func (previous_toplevel,
+                                          G_CALLBACK (resize_grip_visible_changed),
+                                          widget);
+
+  window = gtk_widget_get_toplevel (widget);
+  if (GTK_IS_WINDOW (window))
+    g_signal_connect (window, "notify::resize-grip-visible",
+                      G_CALLBACK (resize_grip_visible_changed), widget);
+}
+
+static void
 gtk_range_realize (GtkWidget *widget)
 {
   GtkAllocation allocation;
@@ -1731,10 +1690,10 @@ gtk_range_realize (GtkWidget *widget)
   GtkRangePrivate *priv = range->priv;
   GdkWindow *window;
   GdkWindowAttr attributes;
-  gint attributes_mask;  
+  gint attributes_mask;
 
   gtk_range_calc_layout (range, priv->adjustment->value);
-  
+
   gtk_widget_set_realized (widget, TRUE);
 
   window = gtk_widget_get_parent_window (widget);
@@ -1742,6 +1701,8 @@ gtk_range_realize (GtkWidget *widget)
   g_object_ref (window);
 
   gtk_widget_get_allocation (widget, &allocation);
+  if (modify_allocation_for_window_grip (widget, &allocation))
+    gtk_widget_set_allocation (widget, &allocation);
 
   attributes.window_type = GDK_WINDOW_CHILD;
   attributes.x = allocation.x;
@@ -1764,8 +1725,6 @@ gtk_range_realize (GtkWidget *widget)
   gdk_window_set_user_data (priv->event_window, range);
 
   gtk_widget_style_attach (widget);
-
-  fixup_for_window_grip (widget);
 }
 
 static void
diff --git a/gtk/gtkwindow.c b/gtk/gtkwindow.c
index 9b7d2d4..effe9cd 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -120,9 +120,9 @@ struct _GtkWindowPrivate
   guint    keys_changed_handler;
 
   /* Don't use this value, it's only used for determining when
-   * to fire notify events on the "resize-grip-is-visible" property.
+   * to fire notify events on the "resize-grip-visible" property.
    */
-  gboolean resize_grip_is_visible;
+  gboolean resize_grip_visible;
 
   guint16  configure_request_count;
 
@@ -864,7 +864,7 @@ gtk_window_class_init (GtkWindowClass *klass)
                                    g_param_spec_boolean ("resize-grip-visible",
                                                          P_("Resize grip is visible"),
                                                          P_("Specifies whether the window's resize grip is visible."),
-                                                         TRUE,
+                                                         FALSE,
                                                          GTK_PARAM_READABLE));
 
 
@@ -5313,18 +5313,16 @@ update_grip_visibility (GtkWindow *window)
   gboolean val = gtk_window_resize_grip_is_visible (window);
 
   if (val)
-    {
-      gdk_window_show (window->priv->grip_window);
-    }
+    gdk_window_show (window->priv->grip_window);
   else
-    {
-      gdk_window_hide (window->priv->grip_window);
-    }
+    gdk_window_hide (window->priv->grip_window);
 
-  if (val != window->priv->resize_grip_is_visible)
-    g_object_notify (G_OBJECT (window), "resize-grip-visible");
+  if (window->priv->resize_grip_visible != val)
+    {
+      window->priv->resize_grip_visible = val;
 
-  window->priv->resize_grip_is_visible = val;
+      g_object_notify (G_OBJECT (window), "resize-grip-visible");
+    }
 }
 
 /**
@@ -5340,18 +5338,19 @@ update_grip_visibility (GtkWindow *window)
 gboolean
 gtk_window_resize_grip_is_visible (GtkWindow *window)
 {
-  GdkWindowState state;
-
   g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
 
-  if (!gtk_widget_get_realized (GTK_WIDGET (window)))
+  if (!window->priv->resizable)
     return FALSE;
 
-  state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
-
-  if (state & GDK_WINDOW_STATE_MAXIMIZED || state & GDK_WINDOW_STATE_FULLSCREEN)
+  if (gtk_widget_get_realized (GTK_WIDGET (window)))
     {
-      return FALSE;
+      GdkWindowState state;
+
+      state = gdk_window_get_state (gtk_widget_get_window (GTK_WIDGET (window)));
+
+      if (state & GDK_WINDOW_STATE_MAXIMIZED || state & GDK_WINDOW_STATE_FULLSCREEN)
+        return FALSE;
     }
 
   return window->priv->has_resize_grip;



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