gtk+ r20268 - in branches/gtk-2-12: . gtk



Author: tml
Date: Mon Jun  2 11:08:54 2008
New Revision: 20268
URL: http://svn.gnome.org/viewvc/gtk+?rev=20268&view=rev

Log:
2008-03-20  Tor Lillqvist  <tml novell com>

	Merge from trunk:

	Bug 314084 - GTK+ dialogs should not be placed partially offscreen

	* gtk/gtkwindow.c (clamp): New function. Clamps a window position
	in one dimension, or centered in case it doesn't fit.
	(clamp_window_to_rectangle): Simplify. Call clamp() for x and y
	dimensions.



Modified:
   branches/gtk-2-12/ChangeLog
   branches/gtk-2-12/gtk/gtkwindow.c

Modified: branches/gtk-2-12/gtk/gtkwindow.c
==============================================================================
--- branches/gtk-2-12/gtk/gtkwindow.c	(original)
+++ branches/gtk-2-12/gtk/gtkwindow.c	Mon Jun  2 11:08:54 2008
@@ -5516,27 +5516,40 @@
 }
 
 static void
+clamp (gint *base,
+       gint  extent,
+       gint  clamp_base,
+       gint  clamp_extent)
+{
+  if (extent > clamp_extent)
+    /* Center */
+    *base = clamp_base + clamp_extent/2 - extent/2;
+  else if (*base < clamp_base)
+    *base = clamp_base;
+  else if (*base + extent > clamp_base + clamp_extent)
+    *base = clamp_base + clamp_extent - extent;
+}
+
+static void
 clamp_window_to_rectangle (gint               *x,
                            gint               *y,
                            gint                w,
                            gint                h,
                            const GdkRectangle *rect)
 {
-  gint outside_w, outside_h;
-  
-  outside_w = (*x + w) - (rect->x + rect->width);
-  if (outside_w > 0)
-    *x -= outside_w;
-
-  outside_h = (*y + h) - (rect->y + rect->height);
-  if (outside_h > 0)
-    *y -= outside_h; 
-
-  /* if larger than the screen, center on the screen. */
-  if (*x < rect->x)
-    *x += (rect->x - *x) / 2;
-  if (*y < rect->y)
-    *y += (rect->y - *y) / 2;
+#ifdef DEBUGGING_OUTPUT
+  g_print ("%s: %+d%+d %dx%d: %+d%+d: %dx%d", __FUNCTION__, rect->x, rect->y, rect->width, rect->height, *x, *y, w, h);
+#endif
+
+  /* If it is too large, center it. If it fits on the monitor but is
+   * partially outside, move it to the closest edge. Do this
+   * separately in x and y directions.
+   */
+  clamp (x, w, rect->x, rect->width);
+  clamp (y, h, rect->y, rect->height);
+#ifdef DEBUGGING_OUTPUT
+  g_print (" ==> %+d%+d: %dx%d\n", *x, *y, w, h);
+#endif
 }
 
 



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