[gtk+/resizegrips] Add resize-grip-visible property to GtkWindow, fix initial display of scrollbars.



commit b986c0ce7ffdd3a453f15647cd7fdde3cbe5d743
Author: Cody Russell <bratsche gnome org>
Date:   Thu Sep 30 20:16:43 2010 -0500

    Add resize-grip-visible property to GtkWindow, fix initial display of scrollbars.

 gtk/gtkrange.c  |   28 ++++++++++++++++++++++++++--
 gtk/gtkwindow.c |   27 ++++++++++++++++++++++++++-
 2 files changed, 52 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gtkrange.c b/gtk/gtkrange.c
index 0da7247..939df45 100644
--- a/gtk/gtkrange.c
+++ b/gtk/gtkrange.c
@@ -216,6 +216,7 @@ 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);
 
 /* Range methods */
 
@@ -1634,8 +1635,8 @@ get_fixup_for_window_grip (GtkWidget *widget)
       /* Translate the stepper's area into window coords */
       if (gtk_widget_translate_coordinates (widget,
                                             window,
-                                            orig_rect.x,
-                                            orig_rect.y,
+                                            orig_rect.x - 1,
+                                            orig_rect.y - 1,
                                             &x,
                                             &y))
         {
@@ -1668,6 +1669,27 @@ get_fixup_for_window_grip (GtkWidget *widget)
 }
 
 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;
+    }
+
+  gtk_widget_set_allocation (widget, &allocation);
+}
+
+static void
 gtk_range_size_allocate (GtkWidget     *widget,
                          GtkAllocation *allocation)
 {
@@ -1742,6 +1764,8 @@ 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 5867753..9b7d2d4 100644
--- a/gtk/gtkwindow.c
+++ b/gtk/gtkwindow.c
@@ -119,6 +119,11 @@ struct _GtkWindowPrivate
   guint    frame_top;
   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.
+   */
+  gboolean resize_grip_is_visible;
+
   guint16  configure_request_count;
 
   /* The following flags are initially TRUE (before a window is mapped).
@@ -205,6 +210,7 @@ enum {
   PROP_TRANSIENT_FOR,
   PROP_OPACITY,
   PROP_HAS_RESIZE_GRIP,
+  PROP_RESIZE_GRIP_VISIBLE,
 
   /* Readonly properties */
   PROP_IS_ACTIVE,
@@ -853,6 +859,14 @@ gtk_window_class_init (GtkWindowClass *klass)
                                                          TRUE,
                                                          GTK_PARAM_READWRITE));
 
+  g_object_class_install_property (gobject_class,
+                                   PROP_RESIZE_GRIP_VISIBLE,
+                                   g_param_spec_boolean ("resize-grip-visible",
+                                                         P_("Resize grip is visible"),
+                                                         P_("Specifies whether the window's resize grip is visible."),
+                                                         TRUE,
+                                                         GTK_PARAM_READABLE));
+
 
   /**
    * GtkWindow:gravity:
@@ -1304,6 +1318,10 @@ gtk_window_get_property (GObject      *object,
       break;
     case PROP_HAS_RESIZE_GRIP:
       g_value_set_boolean (value, priv->has_resize_grip);
+      break;
+    case PROP_RESIZE_GRIP_VISIBLE:
+      g_value_set_boolean (value, gtk_window_resize_grip_is_visible (window));
+      break;
     case PROP_MNEMONICS_VISIBLE:
       g_value_set_boolean (value, priv->mnemonics_visible);
       break;
@@ -5292,7 +5310,9 @@ gtk_window_set_has_resize_grip (GtkWindow *window,
 static void
 update_grip_visibility (GtkWindow *window)
 {
-  if (gtk_window_resize_grip_is_visible (window))
+  gboolean val = gtk_window_resize_grip_is_visible (window);
+
+  if (val)
     {
       gdk_window_show (window->priv->grip_window);
     }
@@ -5300,6 +5320,11 @@ update_grip_visibility (GtkWindow *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");
+
+  window->priv->resize_grip_is_visible = val;
 }
 
 /**



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