partial window position/size patch



Hi,

Here's an initial cut at this patch.

gtk_window_set_default_size() is changed to a) always work after
mapping the window and b) have a new name, gtk_window_set_size().  The
old name still exists for backward compat.

gtk_window_set_policy() is also deprecated, in favor of
gtk_window_set_resizeable(), because only 2 of the 8 possible policies
made any sense.

The rest of the rationale is in my previous mail on this topic.

I haven't yet implemented gtk_window_set_frame_size(),
gtk_window_get_frame_size(), or the functions to get desktop/workspace
extents.

Havoc


Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gtk+/ChangeLog,v
retrieving revision 1.1810
diff -u -u -r1.1810 ChangeLog
--- ChangeLog	2001/03/12 21:01:51	1.1810
+++ ChangeLog	2001/03/14 21:19:47
@@ -1,3 +1,23 @@
+2001-03-13  Havoc Pennington  <hp redhat com>
+
+	* gdk/x11/gdkwindow-x11.c (gdk_window_get_frame_extents): function
+	to get the size of the window manager frame, basically the same
+	code that gdk_window_get_root_origin() had
+	(gdk_window_get_root_origin): use gdk_window_get_frame_extents()
+
+	* gtk/gtkwindow.c (gtk_window_set_default_size): use
+	gdk_window_resize() if the window is realized and resizeable
+
+	* gdk/x11/gdkwindow-x11.c (gdk_window_set_geometry_hints): fix
+	typo so that setting gravity works
+
+	* gtk/gtkwindow.c (gtk_window_move_resize): don't ever use
+	allocation if auto_shrink is on, even if the default size
+	has not changed.
+
+	* gtk/gtkwidget.c (gtk_widget_render_icon): remove bogus
+	g_return_if_fail
+
 2001-03-12  Havoc Pennington  <hp redhat com>
 
 	* gtk/gtkwindow.c (gtk_window_class_init): Patch from John Margaglione 
Index: gdk/gdkwindow.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkwindow.c,v
retrieving revision 1.110
diff -u -u -r1.110 gdkwindow.c
--- gdk/gdkwindow.c	2001/03/09 13:28:18	1.110
+++ gdk/gdkwindow.c	2001/03/14 21:19:47
@@ -2150,4 +2150,3 @@
 {
   debug_updates = setting;
 }
-
Index: gdk/gdkwindow.h
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/gdkwindow.h,v
retrieving revision 1.18
diff -u -u -r1.18 gdkwindow.h
--- gdk/gdkwindow.h	2001/03/05 15:08:36	1.18
+++ gdk/gdkwindow.h	2001/03/14 21:19:48
@@ -403,6 +403,8 @@
 void	      gdk_window_get_root_origin (GdkWindow	  *window,
 					  gint		  *x,
 					  gint		  *y);
+void          gdk_window_get_frame_extents (GdkWindow     *window,
+                                            GdkRectangle  *rect);
 GdkWindow*    gdk_window_get_pointer	 (GdkWindow	  *window,
 					  gint		  *x,
 					  gint		  *y,
Index: gdk/x11/gdkwindow-x11.c
===================================================================
RCS file: /cvs/gnome/gtk+/gdk/x11/gdkwindow-x11.c,v
retrieving revision 1.109
diff -u -u -r1.109 gdkwindow-x11.c
--- gdk/x11/gdkwindow-x11.c	2001/03/05 15:08:36	1.109
+++ gdk/x11/gdkwindow-x11.c	2001/03/14 21:19:48
@@ -1344,7 +1344,8 @@
   if (geom_mask & GDK_HINT_WIN_GRAVITY)
     {
       size_hints.flags |= PWinGravity;
-      size_hints.width_inc = geometry->win_gravity;
+
+      size_hints.win_gravity = geometry->win_gravity;
     }
   
   /* FIXME: Would it be better to delete this property of
@@ -1609,6 +1610,19 @@
     }
 }
 
+/**
+ * gdk_window_get_origin:
+ * @window: a #GdkWindow
+ * @x: return location for X coordinate
+ * @y: return location for Y coordinate
+ * 
+ * Obtains the position of a window in root window coordinates.
+ * (Compare with gdk_window_get_position() and
+ * gdk_window_get_geometry() which return the position of a window
+ * relative to its parent window.)
+ * 
+ * Return value: not meaningful, ignore
+ **/
 gint
 gdk_window_get_origin (GdkWindow *window,
 		       gint      *x,
@@ -1641,6 +1655,21 @@
   return return_val;
 }
 
+/**
+ * gdk_window_get_deskrelative_origin:
+ * @window: a #GdkWindow
+ * @x: return location for X coordinate
+ * @y: return location for Y coordinate
+ * 
+ * This gets the origin of a #GdkWindow relative to
+ * an Enlightenment-window-manager desktop. As long as you don't
+ * assume that the user's desktop/workspace covers the entire
+ * root window (i.e. you don't assume that the desktop begins
+ * at root window coordinate 0,0) this function is not necessary.
+ * It's deprecated for that reason.
+ * 
+ * Return value: not meaningful
+ **/
 gboolean
 gdk_window_get_deskrelative_origin (GdkWindow *window,
 				    gint      *x,
@@ -1705,11 +1734,49 @@
   return return_val;
 }
 
+/**
+ * gdk_window_get_root_origin:
+ * @window: a #GdkWindow
+ * @x: return location for X position of window frame
+ * @y: return location for Y position of window frame
+ *
+ * Obtains the top-left corner of the window manager frame in root
+ * window coordinates.
+ * 
+ **/
 void
 gdk_window_get_root_origin (GdkWindow *window,
 			    gint      *x,
 			    gint      *y)
 {
+  GdkRectangle rect;
+
+  g_return_if_fail (GDK_IS_WINDOW (window));
+
+  gdk_window_get_frame_extents (window, &rect);
+
+  if (x)
+    *x = rect.x;
+
+  if (y)
+    *y = rect.y;
+}
+
+/**
+ * gdk_window_get_frame_extents:
+ * @window: a #GdkWindow
+ * @rect: rectangle to fill with bounding box of the window frame
+ *
+ * Obtains the bounding box of the window, including window manager
+ * titlebar/borders if any. The frame position is given in root window
+ * coordinates. To get the position of the window itself (rather than
+ * the frame) in root window coordinates, use gdk_window_get_origin().
+ * 
+ **/
+void
+gdk_window_get_frame_extents (GdkWindow    *window,
+                              GdkRectangle *rect)
+{
   GdkWindowObject *private;
   Window xwindow;
   Window xparent;
@@ -1717,15 +1784,16 @@
   Window *children;
   unsigned int nchildren;
   
-  g_return_if_fail (window != NULL);
   g_return_if_fail (GDK_IS_WINDOW (window));
+  g_return_if_fail (rect != NULL);
   
   private = (GdkWindowObject*) window;
-  if (x)
-    *x = 0;
-  if (y)
-    *y = 0;
-
+  
+  rect->x = 0;
+  rect->y = 0;
+  rect->width = 1;
+  rect->height = 1;
+  
   if (GDK_WINDOW_DESTROYED (window))
     return;
   
@@ -1755,10 +1823,10 @@
       
       if (XGetGeometry (GDK_WINDOW_XDISPLAY (window), xwindow, &root, &wx, &wy, &ww, &wh, &wb, &wd))
 	{
-	  if (x)
-	    *x = wx;
-	  if (y)
-	    *y = wy;
+          rect->x = wx;
+          rect->y = wy;
+          rect->width = ww;
+          rect->height = wh;
 	}
     }
 }
Index: gtk/gtkwidget.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwidget.c,v
retrieving revision 1.193
diff -u -u -r1.193 gtkwidget.c
--- gtk/gtkwidget.c	2001/03/12 18:46:53	1.193
+++ gtk/gtkwidget.c	2001/03/14 21:19:48
@@ -3777,7 +3777,6 @@
   
   g_return_val_if_fail (GTK_IS_WIDGET (widget), NULL);
   g_return_val_if_fail (stock_id != NULL, NULL);
-  g_return_val_if_fail (size != NULL, NULL);
   
   gtk_widget_ensure_style (widget);
   
@@ -3875,7 +3874,9 @@
  * window; most window managers will do the centering on your behalf
  * if you call gtk_window_set_transient_for(), and it's really not
  * possible to get the centering to work correctly in all cases from
- * application code.
+ * application code. But if you insist, use gtk_window_set_position()
+ * to set #GTK_WIN_POS_CENTER_ON_PARENT, don't do the centering
+ * manually.
  **/
 void
 gtk_widget_set_uposition (GtkWidget *widget,
Index: gtk/gtkwindow.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwindow.c,v
retrieving revision 1.104
diff -u -u -r1.104 gtkwindow.c
--- gtk/gtkwindow.c	2001/03/12 21:01:53	1.104
+++ gtk/gtkwindow.c	2001/03/14 21:19:48
@@ -76,7 +76,7 @@
   PROP_DEFAULT_WIDTH,
   PROP_DEFAULT_HEIGHT,
   PROP_DESTROY_WITH_PARENT,
-
+  
   LAST_ARG
 };
 
@@ -93,7 +93,7 @@
   GdkGeometry    geometry;	/* Geometry hints */
   GdkWindowHints mask;
   GtkWidget     *widget;	/* subwidget to which hints apply */
-  gint           width;		/* Default size */
+  gint           width;		/* gtk_window_set_default_size () */
   gint           height;
 
   GtkWindowLastGeometryInfo last;
@@ -406,6 +406,7 @@
   window->frame_top = 0;
   window->frame_bottom = 0;
   window->type_hint = GDK_WINDOW_TYPE_HINT_NORMAL;
+  window->gravity = GDK_GRAVITY_NORTH_WEST;
   window->decorated = TRUE;
   
   gtk_widget_ref (GTK_WIDGET (window));
@@ -1334,7 +1335,23 @@
   if (height >= 0)
     g_object_notify (G_OBJECT (window), "height");
   
-  gtk_widget_queue_resize (GTK_WIDGET (window));
+  if (GTK_WIDGET_REALIZED (window) && window->allow_grow)
+    {
+      /* Resize as if the user had resized */
+      GdkGeometry new_geometry;
+      GdkWindowHints new_flags;
+      
+      gtk_window_compute_hints (window, &new_geometry, &new_flags);
+      gtk_window_constrain_size (window,
+                                 &new_geometry, new_flags,
+                                 width, height,
+                                 &width, &height);          
+      
+      gdk_window_resize (GTK_WIDGET (window)->window,
+                         width, height);
+    }
+  else
+    gtk_widget_queue_resize (GTK_WIDGET (window));
 }
   
 static void
@@ -2324,10 +2341,10 @@
   /* From the default size and the allocation, figure out the size
    * the window should be.
    */
-  if (!default_size_changed ||
-      (!window->auto_shrink &&
-       new_width <= widget->allocation.width &&
-       new_height <= widget->allocation.height))
+  if (!window->auto_shrink &&
+      (!default_size_changed ||
+       (new_width <= widget->allocation.width &&
+        new_height <= widget->allocation.height)))
     {
       new_width = widget->allocation.width;
       new_height = widget->allocation.height;
@@ -2546,6 +2563,10 @@
        geometry_a->height_inc != geometry_b->height_inc))
     return FALSE;
 
+  if ((flags_a & GDK_HINT_WIN_GRAVITY) &&
+      (geometry_a->win_gravity != geometry_b->win_gravity))
+    return FALSE;
+  
   return TRUE;
 }
 
@@ -2830,6 +2851,9 @@
       new_geometry->max_width = requisition.width;
       new_geometry->max_height = requisition.height;
     }
+
+  *new_flags |= GDK_HINT_WIN_GRAVITY;
+  new_geometry->win_gravity = window->gravity;
 }
 
 /* Compute a new position for the window based on a new
@@ -3306,7 +3330,352 @@
 }
 
 
+/**
+ * gtk_window_set_resizeable:
+ * @window: a #GtkWindow
+ * @setting: %TRUE if the user can resize this window
+ *
+ * Toggles whether the user can resize a window. Windows are user resizeable
+ * by default.
+ * 
+ **/
+void
+gtk_window_set_resizeable (GtkWindow *window,
+                                gboolean   setting)
+{
+  g_return_if_fail (GTK_IS_WINDOW (window));
+
+  if (setting)
+    gtk_window_set_policy (window, FALSE, TRUE, FALSE);
+  else
+    gtk_window_set_policy (window, FALSE, FALSE, TRUE);
+}
+
+/**
+ * gtk_window_get_resizeable:
+ * @window: a #GtkWindow
+ * 
+ * Gets the value set by gtk_window_set_resizeable().
+ * 
+ * Return value: %TRUE if the user can resize the window
+ **/
+gboolean
+gtk_window_get_resizeable (GtkWindow *window)
+{
+  g_return_val_if_fail (GTK_IS_WINDOW (window), FALSE);
+
+  /* allow_grow is most likely to indicate the semantic concept we
+   * mean by "resizeable" (and will be a reliable indicator if
+   * set_policy() hasn't been called)
+   */
+  return window->allow_grow;
+}
+
+
+/**
+ * gtk_window_set_size:
+ * @window: a #GtkWindow
+ * @width: width, or -1 to use the default width
+ * @height: height, or -1 to use the default height
+ *
+ * Sets the size of @window, but only works for resizeable windows
+ * (see gtk_window_set_resizeable()). Setting the size emulates a user
+ * resize operation. Therefore, setting the size less than the minimum
+ * size for the window will simply make the window its minimum size,
+ * and the user will be able to change the size that's set.
+ *
+ * This call also sets the default size of the window, so replaces
+ * gtk_window_set_default_size().
+ *
+ * To set a minimum size, or to set the size of a non-resizeable window,
+ * use gtk_widget_set_usize() on the window. Though normally it makes
+ * more sense to instead call gtk_widget_set_usize() on a child widget inside
+ * the window, rather than the window itself.
+ *
+ * Under the X Window System, window managers are allowed to ignore GTK+'s
+ * request to change a window's size. So your program should not rely on
+ * getting a specific size. (And, as noted in gtk_window_get_size(),
+ * a program that crucially relies on a specific size will generally have
+ * race conditions and be buggy anyway - rather than assuming a
+ * call to gtk_window_set_size() has taken effect, you should react
+ * to configure_event signals on your #GtkWindow.)
+ *
+ * If you set a geometry widget for the window with
+ * gtk_window_set_geometry_hints(), the size applies to the geometry
+ * widget, not the window itself.
+ *
+ * If you've called the deprecated gtk_window_set_policy() function,
+ * gtk_window_set_size() may not behave as expected, due to interaction
+ * with window policies.
+ **/
+void
+gtk_window_set_size (GtkWindow *window,
+                     gint       width,
+                     gint       height)
+{
+  g_return_if_fail (GTK_IS_WINDOW (window));
+  g_return_if_fail (width != 0);
+  g_return_if_fail (height != 0);
+  
+  /* set_default_size() uses "0" to mean "unset", but we allow "-1"
+   * for that in this newer function
+   */
+  if (width < 0)
+    width = 0;
+  if (height < 0)
+    height = 0;
+
+  gtk_window_set_default_size (window, width, height);
+}
+
+/**
+ * gtk_window_get_size:
+ * @window: a #GtkWindow
+ * @width: return location for current width, or %NULL
+ * @height: return location for current height, or %NULL
+ * 
+ * Obtains the current size of @window. If the window is not onscreen
+ * (i.e. has not been received its first configure_event after being
+ * shown with gtk_widget_show()), the size will be the size GTK+ will
+ * request for this window when it's shown.  The window manager may
+ * not choose to give the window exactly this requested size.
+ *
+ * In general, code which depends on window size should be written in
+ * a signal handler connected to configure_event on the window, and
+ * use the size stored in the #GdkEventConfigure. This way you can
+ * respond to changes in size caused by the user or by the window
+ * manager, in addition to changes in size created by your program. If
+ * you call gtk_window_get_size() and then assume that size is
+ * accurate, you have a race condition, because the user or window
+ * manager may resize the window between your call to
+ * gtk_window_get_size() and your assumption of accuracy.
+ *
+ * If you set a geometry widget for the window with gtk_window_set_geometry_hints(),
+ * the size applies to the geometry widget, not the window itself.
+ * 
+ **/
+void
+gtk_window_get_size (GtkWindow *window,
+                     gint      *width,
+                     gint      *height)
+{
+  g_return_if_fail (GTK_IS_WINDOW (window));
+
+  if (GTK_WIDGET_REALIZED (window))
+    {
+      gdk_window_get_size (GTK_WIDGET (window)->window,
+                           width, height);
+    }
+  else
+    {
+      GdkGeometry new_geometry;
+      GdkWindowHints new_flags;
+      gint w, h;
+      
+      gtk_window_compute_default_size (window, &w, &h);
+      
+      gtk_window_compute_hints (window, &new_geometry, &new_flags);
+      gtk_window_constrain_size (window,
+                                 &new_geometry, new_flags,
+                                 w, h,
+                                 &w, &h);
+
+      if (width)
+        *width = w;
+      if (height)
+        *height = h;
+    }
+}
+
+/**
+ * gtk_window_set_location:
+ * @window: a #GtkWindow
+ * @root_x: X position of gravity-determined reference point in root window coordinates
+ * @root_y: Y position of gravity-determined reference point in root window coordinates
+ *
+ * Requests a new position for a #GtkWindow. The position is given in
+ * root window coordinates, and is the position of the window's
+ * "reference point" as determined by the window gravity (see
+ * gtk_window_set_gravity()). By default, the reference point is the
+ * northwest (top left) corner of the window's titlebar.  So if you
+ * set the window position to (0,0), the window's titlebar will end up
+ * in the top left corner of the root window. Note that the root
+ * window does not always correspond to the user's desktop area, so
+ * you may want to call gdk_workspace_get_extents() or
+ * gdk_desktop_get_extents() to decide where to place a window.  The
+ * extents of the root window can be obtained using gdk_screen_width()
+ * and gdk_screen_height().
+ * 
+ **/
+void
+gtk_window_set_location (GtkWindow *window,
+                         gint       root_x,
+                         gint       root_y)
+{
+  g_return_if_fail (GTK_IS_WINDOW (window));
+
+  gtk_widget_set_uposition (GTK_WIDGET (window), root_x, root_y);
+}
+
+/**
+ * gtk_window_get_location:
+ * @window: a #GtkWindow
+ * @root_x: return location for X coordinate of gravity-determined reference point
+ * @root_y: return location for Y coordinate of gravity-determined reference point
+ *
+ * Attempts to obtain the current position of the reference point, as
+ * set by gtk_window_set_position(). This computation is accurate when
+ * the reference point is a corner of the window itself (as with
+ * #GDK_GRAVITY_STATIC), but may not be accurate when the reference
+ * point is a position on the titlebar or window border, because the X
+ * Window System does not provide a reliable way of obtaining this
+ * information. GTK+ will do a "best guess" which may not be fully
+ * accurate with some window managers, but will probably be
+ * reasonable.
+ * 
+ **/
+void
+gtk_window_get_location (GtkWindow *window,
+                         gint      *root_x,
+                         gint      *root_y)
+{
+  GdkRectangle frame_extents;
+  GtkWidget *widget;
+  
+  g_return_if_fail (GTK_IS_WINDOW (window));
+
+  widget = GTK_WIDGET (window);
+  
+  if (GTK_WIDGET_REALIZED (window))
+    {
+      if (window->gravity == GDK_GRAVITY_STATIC)
+        {
+          gdk_window_get_origin (widget->window, root_x, root_y);
+          return;
+        }
+      else
+        {
+          gint x, y;
+          
+          gdk_window_get_frame_extents (widget->window, &frame_extents);
+          
+          x = frame_extents.x;
+          y = frame_extents.y;
+
+          switch (window->gravity)
+            {
+            case GDK_GRAVITY_NORTH:
+            case GDK_GRAVITY_CENTER:
+            case GDK_GRAVITY_SOUTH:
+              x += frame_extents.width / 2;
+              break;
+            case GDK_GRAVITY_SOUTH_EAST:
+            case GDK_GRAVITY_EAST:
+            case GDK_GRAVITY_NORTH_EAST:
+              x += frame_extents.width;
+              break;
+            default:
+              break;
+            }
+
+          switch (window->gravity)
+            {
+            case GDK_GRAVITY_WEST:
+            case GDK_GRAVITY_CENTER:
+            case GDK_GRAVITY_EAST:
+              y += frame_extents.height / 2;
+              break;
+            case GDK_GRAVITY_SOUTH_WEST:
+            case GDK_GRAVITY_SOUTH:
+            case GDK_GRAVITY_SOUTH_EAST:
+              y += frame_extents.height;
+              break;
+            default:
+              break;
+            }
+
+          if (root_x)
+            *root_x = x;
+          if (root_y)
+            *root_y = y;
+        }
+    }
+  else
+    {
+      /* We really don't have a location yet, so we make up some stuff,
+       * using the uposition if it's been set.
+       */
+      if (root_x)
+        *root_x = 0;
+
+      if (root_y)
+        *root_y = 0;
+      
+      aux_info = gtk_object_get_data (GTK_OBJECT (widget), "gtk-aux-info");
+      if (aux_info)
+        {
+          if (root_x && aux_info->x >= 0)
+            *root_x = aux_info->x;
+          if (root_y && aux_info->y >= 0)
+            *root_y = aux_info->y;
+        }
+    }
+}
+
+/**
+ * gtk_window_set_gravity:
+ * @window: a #GtkWindow
+ * @gravity: window gravity
+ *
+ * Window gravity defines the "reference point" to be used when
+ * positioning or resizing a window. Calls to
+ * gtk_window_set_position() will position a different point on the
+ * window depending on the window gravity. When the user resizes a window,
+ * the reference point determined by the window's gravity will stay in
+ * a fixed location as the window is resized.
+ *
+ * See #GdkGravity for full details. To briefly summarize,
+ * #GDK_GRAVITY_NORTH_WEST means that the reference point is the
+ * northwest (top left) corner of the window
+ * frame. #GDK_GRAVITY_SOUTH_EAST would be the bottom right corner of
+ * the frame, and so on. If you want to position the window contents,
+ * rather than the window manager's frame, #GDK_GRAVITY_STATIC moves
+ * the reference point to the northwest corner of the #GtkWindow
+ * itself.
+ *
+ * The default window gravity is #GDK_GRAVITY_NORTH_WEST.
+ * 
+ **/
+void
+gtk_window_set_gravity (GtkWindow *window,
+                        GdkGravity gravity)
+{
+  g_return_if_fail (GTK_IS_WINDOW (window));
 
+  if (gravity != window->gravity)
+    {
+      window->gravity = gravity;
 
+      /* This is sort of odd, but it keeps the hints recomputation
+       * in one place. Otherwise we're likely to mess up the
+       * recording of the last hints, etc.
+       */
+      gtk_widget_queue_resize (GTK_WIDGET (window));
+    }
+}
 
+/**
+ * gtk_window_get_gravity:
+ * @window: a #GtkWindow
+ * 
+ * Gets the value set by gtk_window_set_gravity().
+ * 
+ * Return value: window gravity
+ **/
+GdkGravity
+gtk_window_get_gravity (GtkWindow *window)
+{
+  g_return_val_if_fail (GTK_IS_WINDOW (window), 0);
 
+  return window->gravity;
+}
Index: gtk/gtkwindow.h
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/gtkwindow.h,v
retrieving revision 1.29
diff -u -u -r1.29 gtkwindow.h
--- gtk/gtkwindow.h	2001/03/09 16:43:19	1.29
+++ gtk/gtkwindow.h	2001/03/14 21:19:48
@@ -93,7 +93,9 @@
 
   guint decorated : 1;
   
-  GdkWindowTypeHint type_hint : 2;
+  GdkWindowTypeHint type_hint : 3;
+
+  GdkGravity gravity : 5;
   
   guint frame_left;
   guint frame_top;
@@ -121,10 +123,6 @@
 						const gchar         *wmclass_class);
 void       gtk_window_set_role                 (GtkWindow           *window,
                                                 const gchar         *role);
-void       gtk_window_set_policy               (GtkWindow           *window,
-						gint                 allow_shrink,
-						gint                 allow_grow,
-						gint                 auto_shrink);
 void       gtk_window_add_accel_group          (GtkWindow           *window,
 						GtkAccelGroup	    *accel_group);
 void       gtk_window_remove_accel_group       (GtkWindow           *window,
@@ -140,22 +138,41 @@
 						GdkWindowTypeHint    hint);
 void       gtk_window_set_destroy_with_parent  (GtkWindow           *window,
                                                 gboolean             setting);
-void       gtk_window_set_geometry_hints       (GtkWindow           *window,
-						GtkWidget           *geometry_widget,
-						GdkGeometry         *geometry,
-						GdkWindowHints       geom_mask);
 void       gtk_window_set_decorations_hint     (GtkWindow	    *window,
                                                 GdkWMDecoration      decorations);
 void       gtk_window_set_functions_hint       (GtkWindow	    *window,
                                                 GdkWMFunction	     functions);
 
-/* The following differs from gtk_widget_set_usize, in that
- * gtk_widget_set_usize() overrides the requisition, so sets a minimum
- * size, while this only sets the size requested from the WM.
- */
-void       gtk_window_set_default_size         (GtkWindow           *window,
-						gint                 width,
-						gint                 height);
+
+void       gtk_window_set_resizeable           (GtkWindow           *window,
+                                                gboolean             setting);
+gboolean   gtk_window_get_resizeable           (GtkWindow           *window);
+
+
+void       gtk_window_set_size                 (GtkWindow           *window,
+                                                gint                 width,
+                                                gint                 height);
+void       gtk_window_get_size                 (GtkWindow           *window,
+                                                gint                *width,
+                                                gint                *height);
+
+void       gtk_window_set_location             (GtkWindow           *window,
+                                                gint                 root_x,
+                                                gint                 root_y);
+void       gtk_window_get_location             (GtkWindow           *window,
+                                                gint                *root_x,
+                                                gint                *root_y);
+
+void       gtk_window_set_gravity              (GtkWindow           *window,
+                                                GdkGravity           gravity);
+GdkGravity gtk_window_get_gravity              (GtkWindow           *window);
+
+
+void       gtk_window_set_geometry_hints       (GtkWindow           *window,
+						GtkWidget           *geometry_widget,
+						GdkGeometry         *geometry,
+						GdkWindowHints       geom_mask);
+
 /* gtk_window_set_has_frame () must be called before realizing the window_*/
 void       gtk_window_set_has_frame            (GtkWindow *window);
 void       gtk_window_set_frame_dimensions     (GtkWindow *window, 
@@ -183,6 +200,20 @@
 void     gtk_window_maximize      (GtkWindow *window);
 void     gtk_window_unmaximize    (GtkWindow *window);
 
+
+#ifndef GTK_DISABLE_DEPRECATED
+void       gtk_window_set_policy               (GtkWindow           *window,
+						gint                 allow_shrink,
+						gint                 allow_grow,
+						gint                 auto_shrink);
+/* The following differs from gtk_widget_set_usize, in that
+ * gtk_widget_set_usize() overrides the requisition, so sets a minimum
+ * size, while this only sets the size requested from the WM.
+ */
+void       gtk_window_set_default_size         (GtkWindow           *window,
+						gint                 width,
+						gint                 height);
+#endif
 
 /* --- internal functions --- */
 void       gtk_window_set_focus                (GtkWindow           *window,
Index: gtk/testgtk.c
===================================================================
RCS file: /cvs/gnome/gtk+/gtk/testgtk.c,v
retrieving revision 1.228
diff -u -u -r1.228 testgtk.c
--- gtk/testgtk.c	2001/03/08 17:13:11	1.228
+++ gtk/testgtk.c	2001/03/14 21:19:48
@@ -7949,6 +7949,325 @@
 }
 
 /*
+ * Window sizing
+ */
+
+static gint
+configure_event_callback (GtkWidget *widget,
+                          GdkEventConfigure *event,
+                          gpointer data)
+{
+  GtkWidget *label = data;
+  gchar *msg;
+  gint x, y;
+
+  gtk_window_get_location (GTK_WINDOW (widget), &x, &y);
+  
+  msg = g_strdup_printf ("event: %d,%d  %d x %d\n"
+                         "location: %d, %d",
+                         event->x, event->y, event->width, event->height,
+                         x, y);
+  
+  gtk_label_set_text (GTK_LABEL (label), msg);
+
+  g_free (msg);
+
+  return FALSE;
+}
+
+static void
+get_ints (GtkWidget *window,
+          gint      *a,
+          gint      *b)
+{
+  GtkWidget *spin1;
+  GtkWidget *spin2;
+
+  spin1 = g_object_get_data (G_OBJECT (window), "spin1");
+  spin2 = g_object_get_data (G_OBJECT (window), "spin2");
+
+  *a = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin1));
+  *b = gtk_spin_button_get_value_as_int (GTK_SPIN_BUTTON (spin2));
+}
+
+static void
+set_size_callback (GtkWidget *widget,
+                   gpointer   data)
+{
+  gint w, h;
+  
+  get_ints (data, &w, &h);
+
+  gtk_window_set_size (g_object_get_data (data, "target"),
+                       w, h);
+}
+     
+static void
+set_default_size_callback (GtkWidget *widget,
+                           gpointer   data)
+{
+  gint w, h;
+  
+  get_ints (data, &w, &h);
+
+  gtk_window_set_default_size (g_object_get_data (data, "target"),
+                               w, h);
+}
+
+static void
+set_usize_callback (GtkWidget *widget,
+                    gpointer   data)
+{
+  gint w, h;
+  
+  get_ints (data, &w, &h);
+
+  gtk_widget_set_usize (g_object_get_data (data, "target"),
+                        w, h);
+}
+
+static void
+set_location_callback (GtkWidget *widget,
+                       gpointer   data)
+{
+  gint x, y;
+  
+  get_ints (data, &x, &y);
+
+  gtk_window_set_location (g_object_get_data (data, "target"),
+                           x, y);
+}
+
+static void
+allow_shrink_callback (GtkWidget *widget,
+                       gpointer   data)
+{
+  g_object_set (G_OBJECT (g_object_get_data (data, "target")),
+                "allow_shrink",
+                GTK_TOGGLE_BUTTON (widget)->active,
+                NULL);
+}
+
+static void
+allow_grow_callback (GtkWidget *widget,
+                     gpointer   data)
+{
+  g_object_set (G_OBJECT (g_object_get_data (data, "target")),
+                "allow_grow",
+                GTK_TOGGLE_BUTTON (widget)->active,
+                NULL);
+}
+
+static void
+auto_shrink_callback (GtkWidget *widget,
+                      gpointer   data)
+{
+  g_object_set (G_OBJECT (g_object_get_data (data, "target")),
+                "auto_shrink",
+                GTK_TOGGLE_BUTTON (widget)->active,
+                NULL);
+}
+
+static void
+gravity_selected (GtkWidget *widget,
+                  gpointer data)
+{
+  gtk_window_set_gravity (G_OBJECT (g_object_get_data (data, "target")),
+                          gtk_option_menu_get_history (GTK_OPTION_MENU (widget)) + GDK_GRAVITY_NORTH_WEST);
+}
+
+static GtkWidget*
+window_controls (GtkWidget *window)
+{
+  GtkWidget *control_window;
+  GtkWidget *label;
+  GtkWidget *vbox;
+  GtkWidget *button;
+  GtkWidget *spin;
+  GtkAdjustment *adj;
+  GtkWidget *om;
+  GtkWidget *menu;
+  gint i;
+  
+  control_window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+  gtk_window_set_title (GTK_WINDOW (control_window), "Size controls");
+  
+  g_object_set_data (G_OBJECT (control_window),
+                     "target",
+                     window);
+  
+  gtk_signal_connect_object (GTK_OBJECT (control_window),
+                             "destroy",
+                             GTK_SIGNAL_FUNC (gtk_widget_destroy),
+                             GTK_OBJECT (window));
+
+  vbox = gtk_vbox_new (FALSE, 5);
+  
+  gtk_container_add (GTK_CONTAINER (control_window), vbox);
+  
+  label = gtk_label_new ("<no configure events>");
+  gtk_box_pack_start (GTK_BOX (vbox), label, FALSE, FALSE, 0);
+  
+  gtk_signal_connect (GTK_OBJECT (window),
+                      "configure_event",
+                      GTK_SIGNAL_FUNC (configure_event_callback),
+                      label);
+
+  adj = (GtkAdjustment *) gtk_adjustment_new (10.0, -3.0, 800.0, 1.0,
+                                              5.0, 0.0);
+  spin = gtk_spin_button_new (adj, 0, 0);
+
+  gtk_box_pack_start (GTK_BOX (vbox), spin, FALSE, FALSE, 0);
+
+  g_object_set_data (G_OBJECT (control_window), "spin1", spin);
+
+  adj = (GtkAdjustment *) gtk_adjustment_new (10.0, -3.0, 800.0, 1.0,
+                                              5.0, 0.0);
+  spin = gtk_spin_button_new (adj, 0, 0);
+
+  gtk_box_pack_start (GTK_BOX (vbox), spin, FALSE, FALSE, 0);
+
+  g_object_set_data (G_OBJECT (control_window), "spin2", spin);
+
+  button = gtk_button_new_with_label ("Queue resize");
+  gtk_signal_connect_object (GTK_WIDGET (button),
+                             "clicked",
+                             GTK_SIGNAL_FUNC (gtk_widget_queue_resize),
+                             GTK_OBJECT (control_window));
+  gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+  
+  button = gtk_button_new_with_label ("Set size");
+  gtk_signal_connect (GTK_WIDGET (button),
+                      "clicked",
+                      GTK_SIGNAL_FUNC (set_size_callback),
+                      GTK_OBJECT (control_window));
+  gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+  button = gtk_button_new_with_label ("Set default size");
+  gtk_signal_connect (GTK_WIDGET (button),
+                      "clicked",
+                      GTK_SIGNAL_FUNC (set_default_size_callback),
+                      GTK_OBJECT (control_window));
+  gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+  button = gtk_button_new_with_label ("Set usize");
+  gtk_signal_connect (GTK_WIDGET (button),
+                      "clicked",
+                      GTK_SIGNAL_FUNC (set_usize_callback),
+                      GTK_OBJECT (control_window));
+  gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+  button = gtk_button_new_with_label ("Set location");
+  gtk_signal_connect (GTK_WIDGET (button),
+                      "clicked",
+                      GTK_SIGNAL_FUNC (set_location_callback),
+                      GTK_OBJECT (control_window));
+  gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+  button = gtk_check_button_new_with_label ("Allow shrink");
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
+  gtk_signal_connect (GTK_WIDGET (button),
+                      "toggled",
+                      GTK_SIGNAL_FUNC (allow_shrink_callback),
+                      GTK_OBJECT (control_window));
+  gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+  button = gtk_check_button_new_with_label ("Allow grow");
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), TRUE);
+  gtk_signal_connect (GTK_WIDGET (button),
+                      "toggled",
+                      GTK_SIGNAL_FUNC (allow_grow_callback),
+                      GTK_OBJECT (control_window));
+  gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+  
+  button = gtk_check_button_new_with_label ("Auto shrink");
+  gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button), FALSE);
+  gtk_signal_connect (GTK_WIDGET (button),
+                      "toggled",
+                      GTK_SIGNAL_FUNC (auto_shrink_callback),
+                      GTK_OBJECT (control_window));
+  gtk_box_pack_end (GTK_BOX (vbox), button, FALSE, FALSE, 0);
+
+  menu = gtk_menu_new ();
+  
+  i = 0;
+  while (i < 10)
+    {
+      GtkWidget *mi;
+      static gchar *names[10] = {
+        "GDK_GRAVITY_NORTH_WEST",
+        "GDK_GRAVITY_NORTH",
+        "GDK_GRAVITY_NORTH_EAST",
+        "GDK_GRAVITY_WEST",
+        "GDK_GRAVITY_CENTER",
+        "GDK_GRAVITY_EAST",
+        "GDK_GRAVITY_SOUTH_WEST",
+        "GDK_GRAVITY_SOUTH",
+        "GDK_GRAVITY_SOUTH_EAST",
+        "GDK_GRAVITY_STATIC",
+        NULL
+      };
+
+      g_assert (names[i]);
+      
+      mi = gtk_menu_item_new_with_label (names[i]);
+
+      gtk_menu_shell_append (GTK_MENU_SHELL (menu), mi);
+
+      ++i;
+    }
+  
+  gtk_widget_show_all (menu);
+  
+  om = gtk_option_menu_new ();
+  gtk_option_menu_set_menu (GTK_OPTION_MENU (om), menu);
+  
+
+  gtk_signal_connect (GTK_OBJECT (om),
+                      "changed",
+                      GTK_SIGNAL_FUNC (gravity_selected),
+                      control_window);
+
+  gtk_box_pack_end (GTK_BOX (vbox), om, FALSE, FALSE, 0);
+  
+  gtk_widget_show_all (vbox);
+  
+  return control_window;
+}
+
+void
+create_window_sizing (void)
+{
+  static GtkWidget *window = NULL;
+  
+  if (!window)
+    {
+      GtkWidget *label;
+      
+      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
+
+      label = gtk_label_new (NULL);
+      gtk_label_set_markup (GTK_LABEL (label), "<span foreground=\"purple\"><big>Window being resized</big></span>\nBlah blah blah blah\nblah blah blah\nblah blah blah blah blah");
+      gtk_container_add (GTK_CONTAINER (window), label);
+      gtk_widget_show (label);
+      
+      gtk_signal_connect (GTK_OBJECT (window), "destroy",
+			  GTK_SIGNAL_FUNC(gtk_widget_destroyed),
+			  &window);
+
+      gtk_window_set_title (GTK_WINDOW (window), "Window to size");
+
+      gtk_widget_show (window_controls (window));
+    }
+
+  if (!GTK_WIDGET_VISIBLE (window))
+    gtk_widget_show (window);
+  else
+    gtk_widget_destroy (window);
+}
+
+/*
  * GtkProgressBar
  */
 
@@ -9649,6 +9968,7 @@
       { "tooltips", create_tooltips },
       { "tree", create_tree_mode_window},
       { "WM hints", create_wmhints },
+      { "window sizing", create_window_sizing },
       { "window states", create_window_states }
     };
   int nbuttons = sizeof (buttons) / sizeof (buttons[0]);





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