changeset 1443:66999ff50174

Fix auto-sizing top-level windows with menus on Windows. Similar fix may need to be done for OS/2, but not sure if there is an AdjustWindowRect.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Thu, 08 Dec 2011 22:49:37 +0000
parents 02a329b2b0cd
children 914ac25f7d37
files win/dw.c
diffstat 1 files changed, 36 insertions(+), 34 deletions(-) [+]
line wrap: on
line diff
--- a/win/dw.c	Thu Dec 08 21:58:02 2011 +0000
+++ b/win/dw.c	Thu Dec 08 22:49:37 2011 +0000
@@ -6536,6 +6536,36 @@
 }
 
 /*
+ * The following is an attempt to dynamically size a window based on the size of its
+ * children before realization. Only applicable when width or height is less than one.
+ */
+void _get_window_for_size(HWND handle, unsigned long *width, unsigned long *height)
+{
+   Box *thisbox = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA);
+   
+   if(thisbox)
+   {
+      int depth = 0;
+      DWORD dwStyle = GetWindowLongPtr(handle, GWL_STYLE);
+      DWORD dwExStyle = GetWindowLongPtr(handle, GWL_EXSTYLE);
+      HMENU menu = GetMenu(handle) ;
+      RECT rc = { 0 } ;
+     
+      /* Calculate space requirements */
+      _resize_box(thisbox, &depth, *width, *height, 1);
+      
+      rc.right = thisbox->minwidth;
+      rc.bottom = thisbox->minheight;
+      
+      /* Take into account the window border and menu here */
+      AdjustWindowRectEx(&rc, dwStyle, menu ? TRUE : FALSE, dwExStyle);
+      
+      if ( *width < 1 ) *width = rc.right - rc.left;
+      if ( *height < 1 ) *height = rc.bottom - rc.top;
+   }
+}
+
+/*
  * Sets the size of a given window (widget).
  * Parameters:
  *          handle: Window (widget) handle.
@@ -6544,23 +6574,9 @@
  */
 void API dw_window_set_size(HWND handle, ULONG width, ULONG height)
 {
-   Box *thisbox;
-   
-   /*
-    * The following is an attempt to dynamically size a window based on the size of its
-    * children before realization. Only applicable when width or height is less than one.
-    */
-   if ( (width < 1 || height < 1) && (thisbox = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA)) )
-   {
-      int depth = 0, border = GetSystemMetrics(SM_CXSIZEFRAME) * 2;
-            
-      /* Calculate space requirements */
-      _resize_box(thisbox, &depth, width, height, 1);
-      
-      /* Might need to take into account the window border here */
-      if ( width < 1 ) width = thisbox->minwidth + border;
-      if ( height < 1 ) height = thisbox->minheight + GetSystemMetrics(SM_CYCAPTION) + border;
-   }
+   /* Attempt to auto-size */
+   if ( width < 1 || height < 1 )
+      _get_window_for_size(handle, &width, &height);
    
    /* Finally set the size */
    SetWindowPos(handle, (HWND)NULL, 0, 0, width, height, SWP_SHOWWINDOW | SWP_NOZORDER | SWP_NOMOVE);
@@ -6631,23 +6647,9 @@
  */
 void API dw_window_set_pos_size(HWND handle, long x, long y, ULONG width, ULONG height)
 {
-   Box *thisbox;
-   
-   /*
-    * The following is an attempt to dynamically size a window based on the size of its
-    * children before realization. Only applicable when width or height is less than one.
-    */
-   if ( (width < 1 || height < 1) && (thisbox = (Box *)GetWindowLongPtr(handle, GWLP_USERDATA)) )
-   {
-      int depth = 0, border = GetSystemMetrics(SM_CXSIZEFRAME) * 2;
-            
-      /* Calculate space requirements */
-      _resize_box(thisbox, &depth, width, height, 1);
-      
-      /* Might need to take into account the window border here */
-      if ( width < 1 ) width = thisbox->minwidth + border;
-      if ( height < 1 ) height = thisbox->minheight + GetSystemMetrics(SM_CYCAPTION) + border;
-   }
+   /* Attempt to auto-size */
+   if ( width < 1 || height < 1 )
+      _get_window_for_size(handle, &width, &height);
    
    /* Finally set the size */
    SetWindowPos(handle, (HWND)NULL, x, y, width, height, SWP_NOZORDER | SWP_SHOWWINDOW | SWP_NOACTIVATE);