changeset 1488:6771fa426ba4

Added auto-positioning and auto-sizing code for OS/2. Fixed existing re-positioning code to handle MDI windows properly.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Sat, 24 Dec 2011 16:01:23 +0000
parents 5e4ced521696
children 4c1c44af201a
files os2/dw.c
diffstat 1 files changed, 63 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/os2/dw.c	Sat Dec 24 15:18:00 2011 +0000
+++ b/os2/dw.c	Sat Dec 24 16:01:23 2011 +0000
@@ -4269,30 +4269,82 @@
 
       if(blah && !(blah->flags & DW_OS2_NEW_WINDOW))
       {
-         /* Make sure windows shown for the first time are
-          * completely visible if possible.
-          */
+         /* Handle auto-positioning and auto-sizing */
          ULONG cx = dw_screen_width(), cy = dw_screen_height();
+         HWND parent = WinQueryWindow(handle, QW_PARENT);
          int newx, newy, changed = 0;
          SWP swp;
 
+         /* If it is an MDI window...
+          * find the MDI area.
+          */
+         if(parent && parent != desktop)
+         {
+             WinQueryWindowPos(parent, &swp);
+             cx = swp.cx;
+             cy = swp.cy;
+             /* If the MDI parent isn't visible...
+              * we can't calculate. Drop out.
+              */
+             if(cx < 1 | cy < 1)
+             {
+                 WinSetWindowPos(handle, NULLHANDLE, 0, 0, 0, 0, SWP_MOVE);
+                 return rc;
+             }
+         }
+
          blah->flags |= DW_OS2_NEW_WINDOW;
 
          WinQueryWindowPos(handle, &swp);
 
-         newx = swp.x;
-         newy = swp.y;
-
-         if(swp.cx < cx && (swp.x+swp.cx) > cx)
+         /* If the size is 0 then auto-size */
+         if(swp.cx == 0 || swp.cy == 0)
+         {
+             dw_window_set_size(handle, 0, 0);
+             WinQueryWindowPos(handle, &swp);
+         }
+
+         /* If the position was not set... generate a default
+          * default one in a similar pattern to SHELLPOSITION.
+          */
+         if(swp.x == -2000 || swp.y == -2000)
+         {
+             static int defaultx = 0, defaulty = 0;
+             int maxx = cx / 4, maxy = cy / 4;
+
+             defaultx += 20;
+             defaulty += 20;
+
+             if(defaultx > maxx)
+                 defaultx = 20;
+             if(defaulty > maxy)
+                 defaulty = 20;
+
+             newx = defaultx;
+             /* Account for flipped Y */
+             newy = cy - defaulty - swp.cy;
+             changed = 1;
+         }
+         else
+         {
+             newx = swp.x;
+             newy = swp.y;
+         }
+
+         /* Make sure windows shown for the first time are
+          * completely visible if possible.
+          */
+         if(swp.cx < cx && (newx+swp.cx) > cx)
          {
             newx = (cx - swp.cx)/2;
             changed = 1;
          }
-         if(swp.cy < cy && (swp.y+swp.cy) > cy)
+         if(swp.cy < cy && (newy+swp.cy) > cy)
          {
             newy = (cy - swp.cy)/2;
             changed = 1;
          }
+
          if(changed)
             WinSetWindowPos(handle, NULLHANDLE, newx, newy, 0, 0, SWP_MOVE);
       }
@@ -4941,6 +4993,8 @@
    /* Then create the real window window without FCF_SHELLPOSITION */
    flStyle &= ~FCF_SHELLPOSITION;
    hwndframe = WinCreateStdWindow(hwndOwner, winStyle, &flStyle, (PSZ)ClassName, (PSZ)title, 0L, NULLHANDLE, 0L, &newbox->hwnd);
+   /* Default the window to a ridiculus place so it can't possibly be intentional */
+   WinSetWindowPos(hwndframe, NULLHANDLE, -2000, -2000, 0, 0, SWP_MOVE);
    newbox->hwndtitle = WinWindowFromID(hwndframe, FID_TITLEBAR);
    if(!newbox->titlebar && newbox->hwndtitle)
       WinSetParent(newbox->hwndtitle, HWND_OBJECT, FALSE);
@@ -5115,7 +5169,7 @@
                         NULL,
                         WS_VISIBLE | WS_CLIPCHILDREN |
                         FS_NOBYTEALIGN,
-                        0,0,2000,1000,
+                        0,0,0,0,
                         NULLHANDLE,
                         HWND_TOP,
                         id,