Index: trunk/src/user32/Makefile
===================================================================
--- trunk/src/user32/Makefile	(revision 3658)
+++ trunk/src/user32/Makefile	(revision 3662)
@@ -1,3 +1,3 @@
-# $Id: Makefile,v 1.70 2000-05-05 11:32:35 sandervl Exp $
+# $Id: Makefile,v 1.71 2000-06-07 14:51:23 sandervl Exp $
 
 #
@@ -43,5 +43,4 @@
 $(OBJDIR)\display.obj \
 $(OBJDIR)\pmwindow.obj \
-$(OBJDIR)\pmframe.obj \
 $(OBJDIR)\win32class.obj \
 $(OBJDIR)\win32wnd.obj \
Index: trunk/src/user32/USER32.DEF
===================================================================
--- trunk/src/user32/USER32.DEF	(revision 3658)
+++ trunk/src/user32/USER32.DEF	(revision 3662)
@@ -1,3 +1,3 @@
-; $Id: USER32.DEF,v 1.31 2000-06-01 11:27:55 sandervl Exp $
+; $Id: USER32.DEF,v 1.32 2000-06-07 14:51:24 sandervl Exp $
 
 ;Created by BLAST for IBM's compiler
@@ -13,4 +13,5 @@
     _GpiQueryDCData             = PMGPI.665
     _GpiEnableYInversion        = PMGPI.723
+    _GpiQueryYInversion         = PMGPI.726
     _HPSToHDC                   = PMWINX.1022
     _DeleteHDC                  = PMWINX.1023
Index: trunk/src/user32/button.cpp
===================================================================
--- trunk/src/user32/button.cpp	(revision 3658)
+++ trunk/src/user32/button.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: button.cpp,v 1.36 2000-06-01 11:27:56 sandervl Exp $ */
+/* $Id: button.cpp,v 1.37 2000-06-07 14:51:24 sandervl Exp $ */
 /* File: button.cpp -- Button type widgets
  *
@@ -176,18 +176,10 @@
 static LRESULT BUTTON_EraseBkgnd(HWND hwnd,WPARAM wParam,LPARAM lParam)
 {
-  //SvL: This is wrong: should be 
+  DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0f;
   //SvL: TODO: NT does something extra for ownerdrawn buttons; check this 
-//  if(style == BS_OWNERDRAW) {
-//        return DefWindowProcA(hwnd, WM_ERASEBKGND, wParam, lParam);
-//  }
-//  return 1;
-
-  //SvL: Erase background for groupboxes as the paint function only draws
-  //     a box
-  DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0f;
-//  if(style == BS_GROUPBOX) {
+  if(style == BS_OWNERDRAW) {
         return DefWindowProcA(hwnd, WM_ERASEBKGND, wParam, lParam);
-//  }
-//  return 1;
+  }
+  return 1;
 }
 
@@ -325,5 +317,5 @@
   DWORD style = GetWindowLongA(hwnd,GWL_STYLE) & 0x0f;
 
-  //if (style == BS_GROUPBOX) return HTTRANSPARENT;
+  if (style == BS_GROUPBOX) return HTTRANSPARENT;
 
   return DefWindowProcA(hwnd,WM_NCHITTEST,wParam,lParam);
@@ -1205,5 +1197,4 @@
     wndClass.cbWndExtra    = sizeof(BUTTONINFO);
     wndClass.hCursor       = LoadCursorA(0,IDC_ARROWA);
-//    wndClass.hbrBackground = (HBRUSH)0;
     wndClass.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
     wndClass.lpszClassName = BUTTONCLASSNAME;
Index: trunk/src/user32/clipboard.cpp
===================================================================
--- trunk/src/user32/clipboard.cpp	(revision 3658)
+++ trunk/src/user32/clipboard.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: clipboard.cpp,v 1.7 2000-04-29 18:28:34 sandervl Exp $ */
+/* $Id: clipboard.cpp,v 1.8 2000-06-07 14:51:25 sandervl Exp $ */
 
 /*
@@ -40,6 +40,6 @@
     }
     dprintf(("USER32:  ChangeClipboardChain\n"));
-    return O32_ChangeClipboardChain(wndRemove->getOS2FrameWindowHandle(),
-                                    wndNext->getOS2FrameWindowHandle());
+    return O32_ChangeClipboardChain(wndRemove->getOS2WindowHandle(),
+                                    wndNext->getOS2WindowHandle());
 }
 //******************************************************************************
@@ -108,5 +108,5 @@
     hwndOwner = O32_GetClipboardOwner();
 
-    window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwndOwner);
+    window = Win32BaseWindow::GetWindowFromOS2Handle(hwndOwner);
     if(!window) {
         //an OS/2 window probably owns the clipboard, we pretend nobody owns it
@@ -125,5 +125,5 @@
     hwndViewer = O32_GetClipboardViewer();
 
-    window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwndViewer);
+    window = Win32BaseWindow::GetWindowFromOS2Handle(hwndViewer);
     if(!window) {
         //probably an OS/2 window, we pretend it's nobody
@@ -142,5 +142,5 @@
     hwnd = O32_GetOpenClipboardWindow();
 
-    window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwnd);
+    window = Win32BaseWindow::GetWindowFromOS2Handle(hwnd);
     if(!window) {
         //probably an OS/2 window, we pretend it's nobody
@@ -176,5 +176,5 @@
     }
     dprintf(("USER32:  OpenClipboard\n"));
-    return O32_OpenClipboard(window->getOS2FrameWindowHandle());
+    return O32_OpenClipboard(window->getOS2WindowHandle());
 }
 //******************************************************************************
@@ -219,7 +219,7 @@
     }
     dprintf(("USER32:  SetClipboardViewer\n"));
-    hwndOld = O32_SetClipboardViewer(wndnew->getOS2FrameWindowHandle());
-
-    wndold = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwndOld);
+    hwndOld = O32_SetClipboardViewer(wndnew->getOS2WindowHandle());
+
+    wndold = Win32BaseWindow::GetWindowFromOS2Handle(hwndOld);
     if(!wndold) {
         //probably an OS/2 window, so pretend it's nobody
Index: trunk/src/user32/dc.cpp
===================================================================
--- trunk/src/user32/dc.cpp	(revision 3658)
+++ trunk/src/user32/dc.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: dc.cpp,v 1.58 2000-06-01 11:27:56 sandervl Exp $ */
+/* $Id: dc.cpp,v 1.59 2000-06-07 14:51:25 sandervl Exp $ */
 
 /*
@@ -22,4 +22,5 @@
 #include <stdlib.h>
 
+#include <string.h>
 #include <win32type.h>
 #include <win32api.h>
@@ -301,4 +302,130 @@
 //******************************************************************************
 //******************************************************************************
+VOID removeClientArea(pDCData pHps)
+{
+ POINTL point;
+
+   // This function checks to see if a client area is currently selected, if
+   // it is the origin plus the visible region of the frame are restored.
+
+   pHps->isClient = FALSE;
+
+   GreGetDCOrigin(pHps->hps, &point);
+
+   if(pHps->isClientArea)
+   {
+   	dprintf2(("removeClientArea: (%d,%d) -> (%d,%d)", point.x, point.y, pHps->ptlOrigin.x, pHps->ptlOrigin.y));
+      	pHps->isClientArea = FALSE;
+      	GreSetupDC(pHps->hps,
+                   pHps->hrgnVis,
+                   pHps->ptlOrigin.x,
+                   pHps->ptlOrigin.y,
+                   0,
+                   SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
+   }
+   else dprintf(("removeClientArea: (%d,%d)", point.x, point.y));
+
+}
+//******************************************************************************
+//******************************************************************************
+HRGN selectClientArea(Win32BaseWindow *window, pDCData pHps, PRECTL prclPaint)
+{
+   // This function checks to see if the DC needs to be adjusted to a client
+   // area and makes the adjustment.
+   RECTL rcl, rcltemp;
+   HRGN  hrgnRect, hrgnClip, hrgnOldClip = 0;
+   HWND  hwnd;
+   LONG  rc;
+   PRECT pClient = window->getClientRectPtr();
+   PRECT pWindow = window->getWindowRect();
+
+   if(pClient->left == 0 && pClient->top == 0 &&
+      window->getClientHeight() == window->getWindowHeight() && 
+      window->getClientWidth()  == window->getWindowWidth())
+   {
+	//client rectangle = frame rectangle -> no change necessary
+        //only setup the clip region
+	goto setupclipregion;
+   }
+
+   pHps->isClient = TRUE;
+
+   hwnd = window->getOS2WindowHandle();
+
+   mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&rcl);
+
+   //convert to screen coordinates
+   GreGetDCOrigin(pHps->hps, (PPOINTL)&rcltemp);
+   rcl.xLeft   += rcltemp.xLeft;
+   rcl.xRight  += rcltemp.xLeft;
+   rcl.yTop    += rcltemp.yBottom;
+   rcl.yBottom += rcltemp.yBottom;
+	
+   pHps->ptlOrigin.x = rcltemp.xLeft;
+   pHps->ptlOrigin.y = rcltemp.yBottom;
+ 
+   dprintf2(("selectClientArea: (%d,%d) -> (%d,%d)", rcltemp.xLeft, rcltemp.yBottom, rcl.xLeft, rcl.yBottom));
+
+   if(pHps->hrgnVis == 0)
+       	pHps->hrgnVis = GreCreateRectRegion(pHps->hps, &rcl, 1);
+
+   hrgnRect = GreCreateRectRegion(pHps->hps, &rcl, 1);
+
+   // Query the visible region
+   GreCopyClipRegion(pHps->hps, pHps->hrgnVis, 0, COPYCRGN_VISRGN);
+   GpiQueryRegionBox(pHps->hps, pHps->hrgnVis, &rcltemp);
+   // And the visible region of the frame with the client rectangle
+   // to get the new visible region
+   GreCombineRegion(pHps->hps, hrgnRect, pHps->hrgnVis, hrgnRect, CRGN_AND);
+      
+   // Set the new origin plus visible region in the DC
+   GreSetupDC(pHps->hps,
+              hrgnRect,
+              rcl.xLeft,
+              rcl.yBottom,
+              NULL,
+              SETUPDC_ORIGIN | SETUPDC_VISRGN | SETUPDC_RECALCCLIP);
+
+/*
+      	GpiQueryRegionBox(pHps->hps, hrgnClip, &rcltemp);
+      	GpiQueryRegionBox(pHps->hps, hrgnOldClip, &rcltemp);
+
+      	GpiQueryRegionBox(pHps->hps, hrgnRect, &rcltemp);
+
+      	GreGetDCOrigin(pHps->hps, (PPOINTL)&rcltemp);
+
+      	GreCopyClipRegion(pHps->hps, hrgnRect, 0, COPYCRGN_VISRGN);
+      	GpiQueryRegionBox(pHps->hps, hrgnRect, &rcltemp);
+      
+      	GreCopyClipRegion(pHps->hps, hrgnRect, 0, COPYCRGN_ALLINTERSECT);
+      	GpiQueryRegionBox(pHps->hps, hrgnRect, &rcltemp);
+      
+      	GreCopyClipRegion(pHps->hps, hrgnRect, 0, COPYCRGN_CLIPRGN);
+      	GpiQueryRegionBox(pHps->hps, hrgnRect, &rcltemp);
+*/
+   pHps->isClientArea = TRUE;
+
+   // Destroy the region now we have finished with it.
+   GreDestroyRegion(pHps->hps, hrgnRect);
+
+setupclipregion:
+   if(prclPaint) {
+	hrgnClip = GpiQueryClipRegion(pHps->hps);
+      	if(hrgnClip) {
+      		rc = GreIntersectClipRectangle(pHps->hps, prclPaint);
+		if(rc == RGN_ERROR) {
+			dprintf(("selectClientArea: GreIntersectClipRectangle returned RGN_ERROR!"));
+		}
+      	}
+      	else {
+      		hrgnClip = GreCreateRectRegion(pHps->hps, prclPaint, 1);
+      		GreSelectClipRegion(pHps->hps, hrgnClip, &hrgnOldClip);
+	}
+   }
+
+   return hrgnOldClip;
+}
+//******************************************************************************
+//******************************************************************************
 LONG clientHeight(Win32BaseWindow *wnd, HWND hwnd, pDCData pHps)
 {
@@ -308,8 +435,11 @@
    if ((hwnd != 0) || (pHps == 0))
    {
-      if (wnd)
-         return (wnd->getClientHeight());
-      else
-         return OSLibQueryScreenHeight();
+      	if(wnd) {
+		if(pHps && !pHps->isClientArea) {
+			return (wnd->getWindowHeight());
+		}
+         	else	return (wnd->getClientHeight());
+	}
+      	else  	return OSLibQueryScreenHeight();
    }
    else if (pHps->bitmapHandle)
@@ -430,108 +560,4 @@
 //******************************************************************************
 //******************************************************************************
-#if 0
-HDC WIN32API BeginPaint (HWND hWnd, PPAINTSTRUCT_W lpps)
-{
-   HWND     hwnd = hWnd ? hWnd : HWND_DESKTOP;
-   pDCData  pHps = NULLHANDLE;
-   RECTL    rect;
-   HPS      hPS_ownDC = NULLHANDLE;
-
-   if ( !lpps )
-   {
-      SetLastError(ERROR_INVALID_PARAMETER_W);
-      return (HDC)NULLHANDLE;
-   }
-
-   Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
-
-#if 0
-   if ((hwnd != HWND_DESKTOP) && wnd->isOwnDC())
-   {
-        hPS_ownDC = wnd->getOwnDC();
-        //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
-        if(hPS_ownDC) {
-                pHps = (pDCData)GpiQueryDCData(hPS_ownDC);
-                if (!pHps)
-                {
-                        SetLastError(ERROR_INVALID_PARAMETER_W);
-                        return (HDC)NULLHANDLE;
-                }
-        }
-   }
-#endif
-
-   HWND hwndClient = wnd->getOS2WindowHandle();
-   HPS  hps = WinBeginPaint(hwndClient, hPS_ownDC, &rect);
-
-   if (!pHps)
-   {
-      HDC hdc = HPSToHDC (hwndClient, hps, NULL, NULL);
-      pHps = (pDCData)GpiQueryDCData(hps);
-   }
-
-   if (hPS_ownDC == 0)
-      setMapMode (wnd, pHps, MM_TEXT_W);
-   else
-      setPageXForm (wnd, pHps);
-
-   pHps->hdcType = TYPE_3;
-
-   HideCaret(hwnd);
-
-   if(wnd->needsEraseBkgnd()) {
-        wnd->setEraseBkgnd(FALSE);
-        lpps->fErase = (wnd->MsgEraseBackGround(pHps->hps) != 0);
-   }
-   else lpps->fErase = TRUE;
-   lpps->hdc = (HDC)hps;
-
-   if (!hPS_ownDC)
-   {
-      long height  = wnd->getClientHeight();
-
-      rect.yTop    = height - rect.yTop;
-      rect.yBottom = height - rect.yBottom;
-   }
-   else
-   {
-      rect.yTop--;
-      rect.yBottom--;
-      GpiConvert(pHps->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)&rect);
-   }
-
-   WINRECT_FROM_PMRECT(lpps->rcPaint, rect);
-   dprintf(("USER32: BeginPaint %x -> hdc %x (%d,%d)(%d,%d)", hWnd, pHps->hps, lpps->rcPaint.left, lpps->rcPaint.top, lpps->rcPaint.right, lpps->rcPaint.bottom));
-
-   SetLastError(0);
-   return (HDC)pHps->hps;
-}
-
-BOOL WIN32API EndPaint (HWND hwnd, const PAINTSTRUCT_W *pPaint)
-{
- pDCData pHps;
-
-   dprintf (("USER32: EndPaint(%x)", hwnd));
-
-   ShowCaret(hwnd);
-   if (!pPaint || !pPaint->hdc )
-      return TRUE;
-
-   Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
-
-   if (!wnd) goto exit;
-
-   //SvL: Hack for memory.exe (doesn't get repainted properly otherwise)
-   pHps = (pDCData)GpiQueryDCData((HPS)pPaint->hdc);
-   if (pHps && (pHps->hdcType == TYPE_3)) {
-          WinEndPaint (pHps->hps);
-   }
-   wnd->setEraseBkgnd(TRUE);
-
-exit:
-   SetLastError(0);
-   return TRUE;
-}
-#else
 HDC WIN32API BeginPaint (HWND hWnd, PPAINTSTRUCT_W lpps)
 {
@@ -540,7 +566,10 @@
  HPS      hPS_ownDC = NULLHANDLE, hpsPaint = 0;
  RECTL    rectl = {0, 0, 1, 1};
- HRGN     hrgnUpdate, hrgnOld;
+ HRGN     hrgnUpdate, hrgnOld, hrgnOldClip;
  LONG     lComplexity;
-
+ RECTL    rectlClient;
+ RECTL    rectlClip;
+
+   memset(lpps, 0, sizeof(*lpps));
    Win32BaseWindow *wnd = Win32BaseWindow::GetWindowFromHandle(hwnd);
    if(!lpps || !wnd) {
@@ -567,5 +596,5 @@
    }
    if(!hpsPaint) {
-        hpsPaint = GetDCEx(hwnd, 0, DCX_CACHE_W);
+        hpsPaint = GetDCEx(hwnd, 0, (DCX_CACHE_W|DCX_WINDOW_W|DCX_USESTYLE_W));
         pHps = (pDCData)GpiQueryDCData(hpsPaint);
         if (!pHps)
@@ -577,37 +606,49 @@
    }
 
-#if 0
-   HPS  hps = WinBeginPaint(hwndClient, hPS_ownDC, &rect);
-
-   if (!pHps)
-   {
-      HDC hdc = HPSToHDC (hwndClient, hps, NULL, NULL);
-      pHps = (pDCData)GpiQueryDCData(hps);
-   }
-#endif
-
-   if (hPS_ownDC == 0)
+   if(WinQueryUpdateRect(hwndClient, &rectl) == FALSE) {
+	memset(&rectl, 0, sizeof(rectl));
+        dprintf (("USER32: WARNING: WinQueryUpdateRect failed (error or no update rectangle)!!"));
+
+	mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&rectlClient);
+	WinOffsetRect(NULL, &rectlClient, -rectlClient.xLeft, -rectlClient.yBottom);
+
+   	hrgnOldClip = selectClientArea(wnd, pHps, &rectlClient);
+        //save old clip region (restored for CS_OWNDC windows in EndPaint)
+        wnd->SetClipRegion(hrgnOldClip);
+	lComplexity = RGN_NULL;
+   }
+   else {
+   	HRGN hrgnTmp = GpiCreateRegion(pHps->hps, 1, &rectl);
+
+   	WinQueryUpdateRegion(hwndClient, hrgnTmp);
+
+   	RGNRECT rgnrect = {0, 12, 0, RECTDIR_LFRT_TOPBOT};
+   	RECTL   rectls[12], rcltemp;
+   	GpiQueryRegionRects(pHps->hps, hrgnTmp, &rcltemp, &rgnrect, &rectls[0]);
+	GpiDestroyRegion(pHps->hps, hrgnTmp);
+
+        WinValidateRect(hwndClient, &rectl, FALSE);
+
+	mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&rectlClient);
+	WinIntersectRect(NULL, &rectlClip, &rectl, &rectlClient);
+	WinOffsetRect(NULL, &rectlClip, -rectlClient.xLeft, -rectlClient.yBottom);
+ 
+   	hrgnOldClip = selectClientArea(wnd, pHps, &rectlClip);
+
+        //save old clip region (restored for CS_OWNDC windows in EndPaint)
+        wnd->SetClipRegion(hrgnOldClip);
+	memcpy(&rectl, &rectlClip, sizeof(RECTL));
+	lComplexity = RGN_RECT;
+   }
+
+   if(hPS_ownDC == 0)
       setMapMode (wnd, pHps, MM_TEXT_W);
    else
-      setPageXForm (wnd, pHps);
+      setPageXForm(wnd, pHps);
 
    pHps->hdcType = TYPE_3;
 
-   hrgnUpdate  = GpiCreateRegion(pHps->hps, 1, &rectl);
-   lComplexity = WinQueryUpdateRegion(hwndClient, hrgnUpdate);
-   if(lComplexity == RGN_ERROR) {
-        dprintf (("USER32: BeginPaint update region error!!"));
-        SetLastError(ERROR_INVALID_PARAMETER_W);
-        return 0;
-   }
-   WinQueryUpdateRect(hwndClient, &rectl);
-
-   if(lComplexity != RGN_NULL) {
-        WinValidateRegion(hwndClient, hrgnUpdate, FALSE);
-
-        GpiSetClipRegion(pHps->hps, hrgnUpdate, &hrgnOld);
-        //save old clip region (restored for CS_OWNDC windows in EndPaint)
-        wnd->SetClipRegion(hrgnOld);
-   }
+   HideCaret(hwnd);
+   WinShowTrackRect(wnd->getOS2WindowHandle(), FALSE);
 
    if(wnd->needsEraseBkgnd() && lComplexity != RGN_NULL) {
@@ -631,6 +672,4 @@
    }
 
-   HideCaret(hwnd);
-
    SetLastError(0);
    dprintf(("USER32: BeginPaint %x -> hdc %x (%d,%d)(%d,%d)", hWnd, pHps->hps, lpps->rcPaint.left, lpps->rcPaint.top, lpps->rcPaint.right, lpps->rcPaint.bottom));
@@ -657,9 +696,11 @@
    if (pHps && (pHps->hdcType == TYPE_3))
    {
-        GpiSetClipRegion(pHps->hps, NULLHANDLE, &hrgnOld);
+	removeClientArea(pHps);
         if(hrgnOld) {
+        	GpiSetClipRegion(pHps->hps, NULLHANDLE, &hrgnOld);
                 GpiDestroyRegion(pHps->hps, hrgnOld);
         }
         if(hwnd == HWND_DESKTOP || !wnd->isOwnDC()) {
+   		pHps->hdcType = TYPE_1; //otherwise Open32's ReleaseDC fails
                 ReleaseDC(hwnd, pPaint->hdc);
         }
@@ -671,6 +712,4 @@
                 pHps->hdcType = TYPE_1;
         }
-
-////    WinEndPaint (pHps->hps);
    }
    else {
@@ -679,4 +718,5 @@
    wnd->setEraseBkgnd(TRUE);
    ShowCaret(hwnd);
+   WinShowTrackRect(wnd->getOS2WindowHandle(), TRUE);
 
 exit:
@@ -684,21 +724,73 @@
    return TRUE;
 }
+//******************************************************************************
+//******************************************************************************
+int WIN32API GetClipBox( HDC hdc, PRECT lpRect)
+{
+ pDCData  pHps = (pDCData)GpiQueryDCData((HPS)hdc);
+ RECTL    rectl;
+ LONG     lComplexity;
+ int      rc;
+
+    if(!hdc || !lpRect || !pHps) {
+    	dprintf(("GDI32: GetClipBox %x %x ERROR_INVALID_PARAMETER", hdc, lpRect));
+	SetLastError(ERROR_INVALID_PARAMETER_W);
+	return ERROR_W;
+    }
+    if(pHps->isPrinter)
+    {
+        lpRect->left   = 0;
+        lpRect->top    = 0;
+        lpRect->right  = GetDeviceCaps( hdc, HORZRES_W);
+        lpRect->bottom = GetDeviceCaps( hdc, VERTRES_W);
+
+        rc = SIMPLEREGION_W;
+    }
+    else {
+    	lComplexity = GpiQueryClipBox(pHps->hps, &rectl);
+    	if(lComplexity == RGN_ERROR) 
+    	{
+		rc = ERROR_W;
+    	}
+    	else
+	if(lComplexity == RGN_NULL) 
+    	{
+		memset(lpRect, 0, sizeof(*lpRect));
+		rc = NULLREGION_W;
+	}
+	else {
+		lpRect->left   = rectl.xLeft;
+		lpRect->right  = rectl.xRight;
+#if 0
+		lpRect->top    = pHps->height - rectl.yTop;
+		lpRect->bottom = pHps->height - rectl.yBottom;
+#else
+		//No conversion required as GpiQueryClipBox is affected by
+                //the y-inversion of the window
+		lpRect->top    = rectl.yBottom;
+		lpRect->bottom = rectl.yTop;
 #endif
-//******************************************************************************
-//******************************************************************************
-int WIN32API GetClipBox( HDC arg1, PRECT  arg2)
+		//Convert including/including to including/excluding
+		if(lpRect->left != lpRect->right) {
+			lpRect->right++;
+		}
+		if(lpRect->top != lpRect->bottom) {
+			lpRect->bottom++;
+		}
+		rc = (lComplexity == RGN_RECT) ? SIMPLEREGION_W : COMPLEXREGION_W;
+    	}
+    }
+    dprintf(("GDI32: GetClipBox of %X returned %d\n", hdc, rc));
+    return rc;
+}
+//******************************************************************************
+//******************************************************************************
+int WIN32API GetClipRgn( HDC hdc, HRGN hRgn)
 {
  int rc;
 
-  rc = O32_GetClipBox(arg1, arg2);
-  dprintf(("GDI32: GetClipBox of %X returned %d\n", arg1, rc));
-  return(rc);
-}
-//******************************************************************************
-//******************************************************************************
-int WIN32API GetClipRgn( HDC hdc, HRGN hRgn)
-{
-    dprintf(("GDI32: GetClipRgn"));
-    return O32_GetClipRgn(hdc, hRgn);
+    rc = O32_GetClipRgn(hdc, hRgn);
+    dprintf(("GDI32: GetClipRgn %x %x returned %x", hdc, hRgn, rc));
+    return rc;
 }
 //******************************************************************************
@@ -708,6 +800,7 @@
    if (!hwnd)
    {
-      SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
-      return FALSE;
+	dprintf(("GetUpdateRect %x %x %d -> invalid handle!!", hwnd, pRect, erase));
+      	SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
+      	return FALSE;
    }
 
@@ -717,7 +810,10 @@
    if (!wnd)
    {
-      SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
-      return FALSE;
-   }
+      	SetLastError(ERROR_INVALID_WINDOW_HANDLE_W);
+	dprintf(("GetUpdateRect %x %x %d -> invalid handle!!", hwnd, pRect, erase));
+      	return FALSE;
+   }
+
+   dprintf(("GetUpdateRect %x %x %d", hwnd, pRect, erase));
 
    BOOL updateRegionExists = WinQueryUpdateRect (wnd->getOS2WindowHandle(), pRect ? &rectl : NULL);
@@ -781,8 +877,8 @@
 //******************************************************************************
 //******************************************************************************
-BOOL SYSTEM GetOS2UpdateRect(HWND hwnd,LPRECT pRect)
+BOOL GetOS2UpdateRect(Win32BaseWindow *window, LPRECT pRect)
 {
    RECTL rectl;
-   BOOL updateRegionExists = WinQueryUpdateRect(hwnd,pRect ? &rectl:NULL);
+   BOOL updateRegionExists = WinQueryUpdateRect(window->getOS2WindowHandle(),pRect ? &rectl:NULL);
 
    if (!pRect)
@@ -793,5 +889,5 @@
      //CB: for PM empty rect is valid
      if ((rectl.xLeft == rectl.xRight) || (rectl.yTop == rectl.yBottom)) return FALSE;
-     mapOS2ToWin32Rect(hwnd,(PRECTLOS2)&rectl,pRect);
+     mapOS2ToWin32Rect(window->getWindowHeight(), (PRECTLOS2)&rectl,pRect);
    }
    else
@@ -836,9 +932,27 @@
 //      isOwnDC = wnd->isOwnDC() && wnd->getOwnDC();
         isOwnDC = wnd->isOwnDC() && (wnd->getOwnDC() == hdc);
-   }
-   if (isOwnDC)
-      rc = TRUE;
-   else
-      rc = O32_ReleaseDC (0, hdc);
+   	if(!isOwnDC)
+   	{
+ 		pDCData  pHps = (pDCData)GpiQueryDCData((HPS)hdc);
+		if(pHps && pHps->psType == MICRO_CACHED) {
+        		removeClientArea(pHps);
+			if(pHps->hrgnVis) {
+   				GreDestroyRegion(pHps->hps, pHps->hrgnVis);
+				pHps->hrgnVis = 0;
+			}
+		}	
+		else {
+			dprintf(("ERROR: ReleaseDC: pHps == NULL!!"));
+			DebugInt3();
+		}
+   	}
+   }
+
+   if(isOwnDC) {
+      	rc = TRUE;
+   }
+   else {
+      	rc = O32_ReleaseDC (0, hdc);
+   }
 
    dprintf(("ReleaseDC %x %x", hwnd, hdc));
@@ -851,4 +965,8 @@
 // DCX_EXCLUDERGN (complex regions allowed)
 // DCX_INTERSECTRGN (complex regions allowed)
+// DCX_USESTYLE
+// DCX_CLIPSIBLINGS
+// DCX_CLIPCHILDREN
+// DCX_PARENTCLIP
 //
 //TODO: WM_SETREDRAW affects drawingAllowed flag!!
@@ -880,20 +998,11 @@
                 return 0;
         }
-//SvL: Experimental change (doesn't work right)
-#if 0
-        if(wnd->fHasParentDC() && wnd->getParent()) {
-                wnd = wnd->getParent();
-        }
-#endif
-        if (flags & DCX_WINDOW_W)
-                hWindow = wnd->getOS2FrameWindowHandle();
-        else
-                hWindow = wnd->getOS2WindowHandle();
+        hWindow = wnd->getOS2WindowHandle();
    }
 
    isWindowOwnDC = (((hWindow == HWND_DESKTOP) ? FALSE : (wnd->isOwnDC()))
-                 && !(flags & (DCX_CACHE_W | DCX_WINDOW_W)));
-
-   if (isWindowOwnDC)
+                 && !(flags & DCX_CACHE_W));
+
+   if(isWindowOwnDC)
    {
       hps = wnd->getOwnDC();
@@ -904,7 +1013,12 @@
             goto error;
 
+         if(flags & DCX_WINDOW_W)
+            removeClientArea(pHps);
+         else
+            selectClientArea(wnd, pHps, NULL);
+
          setPageXForm (wnd, pHps);
-
          pHps->hdcType = TYPE_1;
+
          dprintf (("User32: GetDCEx hwnd %x (%x %x) -> wnd %x hdc %x", hwnd, hrgn, flags, wnd, hps));
          return (HDC)hps;
@@ -914,5 +1028,5 @@
    }
 
-   if (isWindowOwnDC)
+   if(isWindowOwnDC)
    {
       SIZEL sizel = {0,0};
@@ -924,9 +1038,37 @@
    else
    {
-      if (hWindow == HWND_DESKTOP)
+      if (hWindow == HWND_DESKTOP) {
          hps = WinGetScreenPS (hWindow);
-      else
-         hps = WinGetPS (hWindow);
-
+      }
+      else {
+	int clipstyle = 0;
+	int clipwnd   = HWND_TOP;
+	if(flags & (DCX_USESTYLE_W)) {
+		int style = wnd->getStyle();
+		if(style & WS_CLIPCHILDREN_W) {
+			clipstyle |= PSF_CLIPCHILDREN;
+		}
+		if(style & WS_CLIPSIBLINGS_W) {
+			clipstyle |= PSF_CLIPSIBLINGS;
+		}
+		if(wnd->fHasParentDC()) {
+			clipstyle |= PSF_PARENTCLIP;
+		}
+	}
+	if(flags & DCX_CLIPSIBLINGS_W) {
+		clipstyle |= PSF_CLIPSIBLINGS;
+	}
+	if(flags & DCX_CLIPCHILDREN_W) {
+		clipstyle |= PSF_CLIPCHILDREN;
+	}
+	if(flags & DCX_PARENTCLIP_W) {
+		clipstyle |= PSF_PARENTCLIP;
+	}
+        if(clipstyle) {
+		dprintf2(("WinGetClipPS style %x", clipstyle));
+		hps = WinGetClipPS(hWindow, clipwnd, clipstyle);
+	}
+	else	hps = WinGetPS (hWindow);
+      }
       psType = MICRO_CACHED;
    }
@@ -937,4 +1079,13 @@
    HPSToHDC (hWindow, hps, NULL, NULL);
    pHps = (pDCData)GpiQueryDCData (hps);
+
+   if(!(flags & DCX_WINDOW_W))
+   {
+ 	selectClientArea(wnd, pHps, NULL);
+   }
+   else removeClientArea(pHps);
+
+
+   setMapMode(wnd, pHps, MM_TEXT_W);
 
    if ((flags & DCX_EXCLUDERGN_W) || (flags & DCX_INTERSECTRGN_W))
@@ -1037,5 +1188,5 @@
 {
   if (!hwnd) hwnd = GetDesktopWindow();
-  return GetDCEx (hwnd, NULL, DCX_USESTYLE_W | DCX_WINDOW_W);
+  return GetDCEx (hwnd, NULL, DCX_WINDOW_W);
 }
 //******************************************************************************
@@ -1091,5 +1242,5 @@
 	//TODO: If frame, exclude client window from update
         if(redraw & RDW_FRAME_W) {
-		hwnd = wnd->getOS2FrameWindowHandle();
+		hwnd = wnd->getOS2WindowHandle();
 	}
 	else   	hwnd = wnd->getOS2WindowHandle();
@@ -1254,4 +1405,5 @@
 }
 //******************************************************************************
+//TODO: Change for client rectangle!!!!!
 //******************************************************************************
 BOOL setPMRgnIntoWinRgn (HRGN hrgnPM, HRGN hrgnWin, LONG height)
@@ -1313,11 +1465,12 @@
 }
 //******************************************************************************
-//******************************************************************************
-BOOL WIN32API ScrollDC (HDC hDC, int dx, int dy, const RECT *pScroll,
-                        const RECT *pClip, HRGN hrgnUpdate, LPRECT pRectUpdate)
+//TODO: Check if this one works correctly...
+//******************************************************************************
+BOOL WIN32API ScrollDC(HDC hDC, int dx, int dy, const RECT *pScroll,
+                       const RECT *pClip, HRGN hrgnUpdate, LPRECT pRectUpdate)
 {
    BOOL rc = TRUE;
 
-   dprintf (("USER32:  ScrollDC"));
+   dprintf (("USER32: ScrollDC %x (%d,%d), %x %x %x %x", hDC, dx, dy, pScroll, pClip, hrgnUpdate, pRectUpdate));
 
    if (!hDC)
@@ -1341,38 +1494,35 @@
    dy = (int)(ptl[1].y - ptl[0].y);
 
-   RECTL scrollRect;
-   RECTL clipRect;
+   RECT scrollRect;
+   RECT clipRect;
 
    if (pClip)
    {
-      clipRect.xLeft   = min (pClip->left, pClip->right);
-      clipRect.xRight  = max (pClip->left, pClip->right);
-      clipRect.yTop    = max (pClip->top,  pClip->bottom);
-      clipRect.yBottom = min (pClip->top,  pClip->bottom);
+      memcpy(&clipRect, pClip, sizeof(clipRect));
 
       if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
-          (clipRect.xLeft   != clipRect.xRight)   &&
-          (clipRect.yBottom != clipRect.yTop))
+          (clipRect.left   != clipRect.right)   &&
+          (clipRect.bottom != clipRect.top))
       {
           if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
-              clipRect.xRight -= abs(pHps->worldXDeltaFor1Pixel);
+              clipRect.right -= abs(pHps->worldXDeltaFor1Pixel);
           else
-              clipRect.xLeft  += abs(pHps->worldXDeltaFor1Pixel);
+              clipRect.left  += abs(pHps->worldXDeltaFor1Pixel);
 
           if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
-              clipRect.yTop    -= abs(pHps->worldYDeltaFor1Pixel);
+              clipRect.bottom -= abs(pHps->worldYDeltaFor1Pixel);
           else
-              clipRect.yBottom += abs(pHps->worldYDeltaFor1Pixel);
-      }
-      GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&clipRect);
-      if (clipRect.xRight < clipRect.xLeft) {
-         ULONG temp      = clipRect.xLeft;
-         clipRect.xLeft  = clipRect.xRight;
-         clipRect.xRight = temp;
-      }
-      if (clipRect.yTop < clipRect.yBottom) {
-         ULONG temp       = clipRect.yBottom;
-         clipRect.yBottom = clipRect.yTop;
-         clipRect.yTop    = temp;
+              clipRect.top    += abs(pHps->worldYDeltaFor1Pixel);
+      }
+      GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&clipRect);
+      if (clipRect.right < clipRect.left) {
+         ULONG temp     = clipRect.left;
+         clipRect.left  = clipRect.right;
+         clipRect.right = temp;
+      }
+      if (clipRect.bottom < clipRect.top) {
+         ULONG temp       = clipRect.top;
+         clipRect.top     = clipRect.bottom;
+         clipRect.bottom  = temp;
       }
    }
@@ -1380,39 +1530,66 @@
    if (pScroll)
    {
-      scrollRect.xLeft   = min (pScroll->left, pScroll->right);
-      scrollRect.xRight  = max (pScroll->left, pScroll->right);
-      scrollRect.yTop    = max (pScroll->top,  pScroll->bottom);
-      scrollRect.yBottom = min (pScroll->top,  pScroll->bottom);
+      memcpy(&scrollRect, pScroll, sizeof(scrollRect));
 
       if ((pHps->graphicsMode == GM_COMPATIBLE_W) &&
-          (scrollRect.xLeft   != scrollRect.xRight)   &&
-          (scrollRect.yBottom != scrollRect.yTop))
+          (scrollRect.left != scrollRect.right)   &&
+          (scrollRect.top  != scrollRect.bottom))
       {
           if (abs((int)pHps->viewportXExt) <= abs((int)pHps->windowExt.cx))
-              scrollRect.xRight -= abs(pHps->worldXDeltaFor1Pixel);
+              scrollRect.right -= abs(pHps->worldXDeltaFor1Pixel);
           else
-              scrollRect.xLeft  += abs(pHps->worldXDeltaFor1Pixel);
+              scrollRect.left  += abs(pHps->worldXDeltaFor1Pixel);
 
           if (abs((int)pHps->viewportYExt) <= abs((int)pHps->windowExt.cy))
-              scrollRect.yTop    -= abs(pHps->worldYDeltaFor1Pixel);
+              scrollRect.bottom  -= abs(pHps->worldYDeltaFor1Pixel);
           else
-              scrollRect.yBottom += abs(pHps->worldYDeltaFor1Pixel);
+              scrollRect.top     += abs(pHps->worldYDeltaFor1Pixel);
       }
       GpiConvert (pHps->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)&scrollRect);
-      if (scrollRect.xRight < scrollRect.xLeft) {
-         ULONG temp        = scrollRect.xLeft;
-         scrollRect.xLeft  = scrollRect.xRight;
-         scrollRect.xRight = temp;
-      }
-      if (scrollRect.yTop < scrollRect.yBottom) {
-         ULONG temp         = scrollRect.yBottom;
-         scrollRect.yBottom = scrollRect.yTop;
-         scrollRect.yTop    = temp;
-      }
-   }
-   RECTL rectlUpdate;
-   HRGN  hrgn;
-
-   LONG lComplexity = WinScrollWindow (hwnd, dx, dy, (pScroll) ? &scrollRect : NULL, (pClip) ? &clipRect : NULL, hrgn, &rectlUpdate, 0);
+      if (scrollRect.right < scrollRect.left) {
+         ULONG temp       = scrollRect.left;
+         scrollRect.left  = scrollRect.right;
+         scrollRect.right = temp;
+      }
+      if (scrollRect.bottom < scrollRect.top) {
+         ULONG temp        = scrollRect.top;
+         scrollRect.top    = scrollRect.bottom;
+         scrollRect.bottom = temp;
+      }
+   }
+   RECTL  rectlUpdate;
+   HRGN   hrgn;
+   RECTL  clientRect;
+   RECTL  clipOS2;
+   RECTL  scrollOS2;
+   PRECTL pScrollOS2 = NULL;
+   PRECTL pClipOS2   = NULL;
+
+   mapWin32ToOS2Rect(wnd->getWindowHeight(), wnd->getClientRectPtr(), (PRECTLOS2)&clientRect);
+
+   if(pScroll) {
+        mapWin32ToOS2RectClientToFrame(wnd, &scrollRect, (PRECTLOS2)&scrollOS2);
+        pScrollOS2 = &scrollOS2;
+
+        //Scroll rectangle relative to client area
+        WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
+   }
+   else {
+	pScrollOS2 = &clientRect;
+   }
+
+   if(pClip) {
+         mapWin32ToOS2RectClientToFrame(wnd, &clipRect, (PRECTLOS2)&clipOS2);
+         pClipOS2 = &clipOS2;
+
+         //Clip rectangle relative to client area
+         WinIntersectRect((HAB) 0, pClipOS2, pClipOS2, &clientRect);
+   }
+   else {
+	 pClipOS2 = &clientRect;
+   }
+
+   LONG lComplexity = WinScrollWindow(hwnd, dx, dy, pScrollOS2, 
+                                      pClipOS2, hrgn, &rectlUpdate, 0);
    if (lComplexity == RGN_ERROR)
    {
@@ -1421,10 +1598,6 @@
 
    RECT winRectUpdate;
-   LONG height = wnd->getClientHeight();
-
-   winRectUpdate.left   = rectlUpdate.xLeft;
-   winRectUpdate.right  = rectlUpdate.xRight;
-   winRectUpdate.top    = height - rectlUpdate.yTop;
-   winRectUpdate.bottom = height - rectlUpdate.yBottom;
+
+   mapOS2ToWin32Rect(wnd->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
 
    if (pRectUpdate)
@@ -1432,5 +1605,5 @@
 
    if (hrgnUpdate)
-      rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, height);
+      rc = setPMRgnIntoWinRgn(hrgn, hrgnUpdate, wnd->getWindowHeight());
 
    return (rc);
@@ -1438,56 +1611,4 @@
 //******************************************************************************
 //******************************************************************************
-#if 1
-BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
-{
- Win32BaseWindow *window;
- APIRET  rc;
- RECTL   clientRect;
- PRECT   pClientRect;
- RECTL   scrollRect;
- RECTL   clipRect;
- PRECTL  pScrollRect = NULL;
- PRECTL  pClipRect   = NULL;
- ULONG   scrollFlags = SW_INVALIDATERGN;
-
-    window = Win32BaseWindow::GetWindowFromHandle(hwnd);
-    if(!window) {
-        dprintf(("ScrollWindow, window %x not found", hwnd));
-        return 0;
-    }
-    dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
-
-    pClientRect = window->getClientRectPtr();
-    clientRect.xLeft   = 0;
-    clientRect.yBottom = 0;
-    clientRect.xRight  = pClientRect->right - pClientRect->left;
-    clientRect.yTop    = pClientRect->bottom - pClientRect->top;
-
-    if(pScroll) {
-         mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
-         pScrollRect = &scrollRect;
-
-         //Scroll rectangle relative to client area
-         WinIntersectRect ((HAB) 0, pScrollRect, pScrollRect, &clientRect);
-    }
-    else scrollFlags |= SW_SCROLLCHILDREN;
-
-    if(pClip) {
-         mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
-         pClipRect = &clipRect;
-
-         //Clip rectangle relative to client area
-         WinIntersectRect ((HAB) 0, pClipRect, pClipRect, &clientRect);
-    }
-
-    dy = revertDy (window, dy);
-
-    rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
-                         pScrollRect, pClipRect, NULLHANDLE,
-                         NULL, scrollFlags);
-
-    return (rc != RGN_ERROR);
-}
-#else
 BOOL WIN32API ScrollWindow(HWND hwnd, int dx, int dy, const RECT *pScroll, const RECT *pClip)
 {
@@ -1497,6 +1618,6 @@
  RECTL   scrollRect;
  RECTL   clipRect;
- PRECTL  pScrollRect = NULL;
- PRECTL  pClipRect   = NULL;
+ PRECTL  pScrollOS2 = NULL;
+ PRECTL  pClipOS2   = NULL;
  ULONG   scrollFlags = SW_INVALIDATERGN;
 
@@ -1507,39 +1628,28 @@
     }
     dprintf(("ScrollWindow %x %d %d %x %x", hwnd, dx, dy, pScroll, pClip));
-    mapWin32ToOS2Rect(window,window->getClientRectPtr(),(PRECTLOS2)&clientRect);
-#if 0
-    //Rectangle could be relative to parent window, so fix this
-    if(clientRect.yBottom != 0) {
-        clientRect.yTop   -= clientRect.yBottom;
-        clientRect.yBottom = 0;
-    }
-    if(clientRect.xLeft != 0) {
-        clientRect.xRight -= clientRect.xLeft;
-        clientRect.xLeft   = 0;
-    }
-#endif
+
+    mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&clientRect);
+
     if(pScroll) {
-         mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
-         pScrollRect = &scrollRect;
-
-         //Scroll rectangle relative to client area
-         pScrollRect->xLeft   += clientRect.xLeft;
-         pScrollRect->xRight  += clientRect.xLeft;
-         pScrollRect->yTop    += clientRect.yBottom;
-         pScrollRect->yBottom += clientRect.yBottom;
-         WinIntersectRect ((HAB) 0, pScrollRect, pScrollRect, &clientRect);
-    }
-    else scrollFlags |= SW_SCROLLCHILDREN;
+        mapWin32ToOS2RectClientToFrame(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
+        pScrollOS2 = &scrollRect;
+
+        //Scroll rectangle relative to client area
+        WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
+    }
+    else {
+	pScrollOS2 = &clientRect;
+	scrollFlags |= SW_SCROLLCHILDREN;
+    }
 
     if(pClip) {
-         mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
-         pClipRect = &clipRect;
+         mapWin32ToOS2RectClientToFrame(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
+         pClipOS2 = &clipRect;
 
          //Clip rectangle relative to client area
-         pClipRect->xLeft     += clientRect.xLeft;
-         pClipRect->xRight    += clientRect.xLeft;
-         pClipRect->yTop      += clientRect.yBottom;
-         pClipRect->yBottom   += clientRect.yBottom;
-         WinIntersectRect ((HAB) 0, pClipRect, pClipRect, &clientRect);
+         WinIntersectRect ((HAB) 0, pClipOS2, pClipOS2, &clientRect);
+    }
+    else {
+	 pClipOS2 = &clientRect;
     }
 
@@ -1547,10 +1657,9 @@
 
     rc = WinScrollWindow(window->getOS2WindowHandle(), dx, dy,
-                         pScrollRect, pClipRect, NULLHANDLE,
+                         pScrollOS2, pClipOS2, NULLHANDLE,
                          NULL, scrollFlags);
 
     return (rc != RGN_ERROR);
 }
-#endif
 //******************************************************************************
 //******************************************************************************
@@ -1558,10 +1667,13 @@
                             HRGN hrgnUpdate, PRECT pRectUpdate, UINT scrollFlag)
 {
-    Win32BaseWindow *window;
-    APIRET  rc;
-    RECTL   scrollRect;
-    RECTL   clipRect;
-    ULONG   scrollFlags = 0;
-    int     regionType = ERROR_W;
+ Win32BaseWindow *window;
+ APIRET  rc;
+ RECTL   clientRect;
+ RECTL   scrollRect;
+ RECTL   clipRect;
+ PRECTL  pScrollOS2 = NULL;
+ PRECTL  pClipOS2   = NULL;
+ ULONG   scrollFlags = 0;
+ int     regionType = ERROR_W;
 
     window = Win32BaseWindow::GetWindowFromHandle(hwnd);
@@ -1578,6 +1690,28 @@
     if (scrollFlag & SW_SCROLLCHILDREN_W)  scrollFlags |= SW_SCROLLCHILDREN;
 
-    if(pScroll) mapWin32ToOS2Rect(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
-    if(pClip)   mapWin32ToOS2Rect(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
+    mapWin32ToOS2Rect(window->getWindowHeight(), window->getClientRectPtr(), (PRECTLOS2)&clientRect);
+
+    if(pScroll) {
+        mapWin32ToOS2RectClientToFrame(window,(RECT *)pScroll, (PRECTLOS2)&scrollRect);
+        pScrollOS2 = &scrollRect;
+
+        //Scroll rectangle relative to client area
+        WinIntersectRect ((HAB) 0, pScrollOS2, pScrollOS2, &clientRect);
+    }
+    else {
+	pScrollOS2 = &clientRect;
+	scrollFlags |= SW_SCROLLCHILDREN;  //TODO: ?????
+    }
+
+    if(pClip) {
+         mapWin32ToOS2RectClientToFrame(window,(RECT *)pClip, (PRECTLOS2)&clipRect);
+         pClipOS2 = &clipRect;
+
+         //Clip rectangle relative to client area
+         WinIntersectRect ((HAB) 0, pClipOS2, pClipOS2, &clientRect);
+    }
+    else {
+	 pClipOS2 = &clientRect;
+    }
 
     RECTL rectlUpdate;
@@ -1593,6 +1727,6 @@
 
     LONG lComplexity = WinScrollWindow (window->getOS2WindowHandle(), dx, dy,
-                                        (pScroll) ? &scrollRect : NULL,
-                                        (pClip) ? &clipRect : NULL,
+                                        pScrollOS2,
+                                        pClipOS2,
                                         hrgn, &rectlUpdate, scrollFlags);
     if (lComplexity == RGN_ERROR)
@@ -1602,10 +1736,6 @@
 
     RECT winRectUpdate;
-    LONG height = window->getClientHeight();
-
-    winRectUpdate.left   = rectlUpdate.xLeft;
-    winRectUpdate.right  = rectlUpdate.xRight;
-    winRectUpdate.top    = height - rectlUpdate.yTop;
-    winRectUpdate.bottom = height - rectlUpdate.yBottom;
+
+    mapOS2ToWin32Rect(window->getWindowHeight(), (PRECTLOS2)&rectlUpdate, &winRectUpdate);
 
     if (pRectUpdate)
@@ -1613,9 +1743,9 @@
 
     if (hrgnUpdate)
-       rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, height);
-
+       rc = setPMRgnIntoWinRgn (hrgn, hrgnUpdate, window->getWindowHeight());
+
+#if 0
     //SvL: WinScrollWindow already invalidates the area; no need to do it again
     //(call to invalidateRect was wrong; has to include erase flag)
-#if 0
     if ((scrollFlag & SW_INVALIDATE_W) &&
         ((lComplexity == RGN_RECT) || (lComplexity == RGN_COMPLEX)))
Index: trunk/src/user32/dc.h
===================================================================
--- trunk/src/user32/dc.h	(revision 3658)
+++ trunk/src/user32/dc.h	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: dc.h,v 1.12 2000-06-01 11:27:57 sandervl Exp $ */
+/* $Id: dc.h,v 1.13 2000-06-07 14:51:25 sandervl Exp $ */
 /*
  * public dc functions
@@ -17,4 +17,5 @@
 extern void releaseOwnDC (HDC hps);
 
+BOOL GetOS2UpdateRect(Win32BaseWindow *window,LPRECT pRect);
 
 #ifdef INCLUDED_BY_DC
@@ -168,5 +169,16 @@
 }
 
-//LONG    APIENTRY GpiQueryYInversion (HPS hps);
+LONG APIENTRY _GpiQueryYInversion(ULONG hps);
+
+inline LONG GpiQueryYInversion(ULONG hps)
+{
+ LONG yyrc;
+ USHORT sel = RestoreOS2FS();
+
+    yyrc = _GpiQueryYInversion(hps);
+    SetFS(sel);
+
+    return yyrc;
+}
 
 PVOID   APIENTRY _GpiAllocateDCData (HPS GpiH, ULONG size);
@@ -446,17 +458,4 @@
 
     yyrc = _O32_GetClipRgn(a, b);
-    SetFS(sel);
-
-    return yyrc;
-} 
-
-int       OPEN32API _O32_GetClipBox( HDC, PRECT );
-
-inline int O32_GetClipBox(HDC a, PRECT b)
-{
- int yyrc;
- USHORT sel = RestoreOS2FS();
-
-    yyrc = _O32_GetClipBox(a, b);
     SetFS(sel);
 
@@ -554,4 +553,8 @@
    #define GreCombineRegion(a,b,c,d,e) (INT) _Gre32Entry7((ULONG)(HDC)(a),(ULONG)(HRGN)(b),(ULONG)(HRGN)(c),(ULONG)(HRGN)(d),(ULONG)(ULONG)(e),0L,0x00004065L)
    #define GreDestroyRegion(a,b) (BOOL) _Gre32Entry4((ULONG)(HDC)(a),(ULONG)(HRGN)(b),0L,0x00004063L)
+   #define GreGetDCOrigin(a,b) (BOOL) _Gre32Entry4((ULONG)(HDC)(a),(ULONG)(PPOINTL)(b),0L,0x000040BAL)
+   #define GreDeviceSetDCOrigin(a,b) (BOOL) _Gre32Entry4((ULONG)(HDC)(a),(ULONG)(PPOINTL)(b),0L,0x000040BBL)
+   #define GreSelectClipRegion(a,b,c) (INT) _Gre32Entry5((ULONG)(HDC)(a),(ULONG)(HRGN)(b),(ULONG)(PHRGN)(c),0L,0x00004074L)
+   #define GreIntersectClipRectangle(a,b) (INT) _Gre32Entry4((ULONG)(HDC)(a),(ULONG)(PRECTL)(b),0L,0x00004075L)
 
 #endif //INCLUDED_BY_DC
Index: trunk/src/user32/oslibgdi.cpp
===================================================================
--- trunk/src/user32/oslibgdi.cpp	(revision 3658)
+++ trunk/src/user32/oslibgdi.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: oslibgdi.cpp,v 1.11 2000-03-13 13:10:45 sandervl Exp $ */
+/* $Id: oslibgdi.cpp,v 1.12 2000-06-07 14:51:26 sandervl Exp $ */
 /*
  * Window GDI wrapper functions for OS/2
@@ -30,12 +30,13 @@
 Single y mapping:
  mapScreenY()
- mapY()
- mapOS2ToWin32Y()
- mapWin32ToOS2Y()
- mapWin32Y()
+ mapY()			//only reverses y
+ mapOS2ToWin32Y()	//reverse y + subtract parent client offset
+ mapOS2ToWin32X()	//subtract parent client offset
+
+ mapWin32ToOS2Y()	//reverse y + add parent client offset
+ mapWin32ToOS2Y()	//add parent client offset
 
 Single point mapping:
  mapScreenPoint()
- mapPoint()
  mapOS2ToWin32Point()
  mapWin32ToOS2Point()
@@ -52,7 +53,4 @@
  copyOS2ToWin32Rect()
  copyWin32ToOS2Rect()
-
-Child origin:
- mapOS2ToWin32ChildOrigin()
 */
 
@@ -70,92 +68,4 @@
 {
   return screenH-1-screenPosY;
-}
-//******************************************************************************
-// To translation between OS/2 <-> Win32
-//******************************************************************************
-INT mapY(HWND os2Client,INT clientPosY)
-{
-  RECTL rect;
-
-  if (os2Client == OSLIB_HWND_DESKTOP) os2Client = HWND_DESKTOP; //client shouldn't be desktop
-  if (!WinQueryWindowRect(os2Client,&rect)) return 0;
-
-  return rect.yTop-1-clientPosY;
-}
-//******************************************************************************
-// To translation between OS/2 <-> Win32
-//******************************************************************************
-INT mapY(Win32BaseWindow *win32wnd,INT clientPosY)
-{
-  if (!win32wnd) return 0;
-
-  return win32wnd->getClientHeight()-1-clientPosY;
-}
-//******************************************************************************
-//******************************************************************************
-INT mapOS2ToWin32Y(HWND os2From,HWND os2To,INT fromPosY)
-{
-  POINTL pt;
-  RECTL rect;
-
-  if (os2From == OSLIB_HWND_DESKTOP) os2From = HWND_DESKTOP;
-  if (os2To == OSLIB_HWND_DESKTOP) os2To = HWND_DESKTOP;
-  if (os2From != os2To)
-  {
-    pt.x = 0;
-    pt.y = fromPosY;
-    if (!WinMapWindowPoints(os2From,os2To,&pt,1)) return 0;
-  } else pt.y = fromPosY;
-  if (!WinQueryWindowRect(os2To,&rect)) return 0;
-
-  return rect.yTop-1-pt.y;
-}
-//******************************************************************************
-//******************************************************************************
-INT mapOS2ToWin32Y(Win32BaseWindow *wndFrom,Win32BaseWindow *wndTo,INT fromPosY)
-{
-  POINTL pt;
-
-  if (!wndFrom || !wndTo) return 0;
-  if (wndFrom != wndTo)
-  {
-    pt.x = 0;
-    pt.y = fromPosY;
-    if (!WinMapWindowPoints(wndFrom->getOS2WindowHandle(),wndTo->getOS2WindowHandle(),&pt,1)) return 0;
-  } else pt.y = fromPosY;
-
-  return wndTo->getClientHeight()-1-pt.y;
-}
-//******************************************************************************
-//******************************************************************************
-INT mapWin32Y(HWND os2From,HWND os2To,INT fromPosY)
-{
-  POINTL pt;
-  RECTL rect;
-
-  if (os2From == OSLIB_HWND_DESKTOP) os2From = HWND_DESKTOP;
-  if (os2To == OSLIB_HWND_DESKTOP) os2To = HWND_DESKTOP;
-  if (os2From == os2To) return fromPosY;
-  if (!WinQueryWindowRect(os2From,&rect)) return 0;
-  pt.y = rect.yTop-1-fromPosY;
-  pt.x = 0;
-  if (!WinMapWindowPoints(os2From,os2To,&pt,1)) return 0;
-  if (!WinQueryWindowRect(os2To,&rect)) return 0;
-
-  return rect.yTop-1-pt.y;
-}
-//******************************************************************************
-//******************************************************************************
-INT mapWin32Y(Win32BaseWindow *wndFrom,Win32BaseWindow *wndTo,INT fromPosY)
-{
-  POINTL pt;
-
-  if (!wndFrom || !wndTo) return 0;
-  if (wndFrom == wndTo) return fromPosY;
-  pt.y = wndFrom->getClientHeight()-1-fromPosY;
-  pt.x = 0;
-  if (!WinMapWindowPoints(wndFrom->getOS2WindowHandle(),wndTo->getOS2WindowHandle(),&pt,1)) return 0;
-
-  return wndTo->getClientHeight()-1-pt.y;
 }
 //******************************************************************************
@@ -182,91 +92,12 @@
 // To translation between OS/2 <-> Win32
 //******************************************************************************
-BOOL mapPoint(HWND os2Client,OSLIBPOINT *clientPt)
+BOOL mapOS2ToWin32Rect(int height, PRECTLOS2 rectOS2, PRECT rectWin32)
 {
-  RECTL rect;
-
-  if (!clientPt) return FALSE;
-  if (os2Client == OSLIB_HWND_DESKTOP) os2Client = HWND_DESKTOP; //client shouldn't be desktop
-  if (!WinQueryWindowRect(os2Client,&rect)) return 0;
-  clientPt->y = rect.yTop-1-clientPt->y;
-
-  return TRUE;
-}
-//******************************************************************************
-// To translation between OS/2 <-> Win32
-//******************************************************************************
-BOOL mapPoint(Win32BaseWindow *win32wnd,OSLIBPOINT *clientPt)
-{
-  if (!win32wnd || !clientPt) return FALSE;
-  clientPt->y = win32wnd->getClientHeight()-1-clientPt->y;
-
-  return TRUE;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL mapOS2ToWin32Point(HWND os2From,HWND os2To,OSLIBPOINT *fromPt)
-{
-  RECTL rect;
-
-  if (os2From == OSLIB_HWND_DESKTOP) os2From = HWND_DESKTOP;
-  if (os2To == OSLIB_HWND_DESKTOP) os2To = HWND_DESKTOP;
-  if (os2From != os2To)
-  {
-    if (!WinMapWindowPoints(os2From,os2To,(PPOINTL)fromPt,1)) return FALSE;
+  if(!rectOS2 || !rectWin32) {
+	DebugInt3();
+  	return FALSE;
   }
-  if (!WinQueryWindowRect(os2To,&rect)) return FALSE;
-  fromPt->y = rect.yTop-1-fromPt->y;
-
-  return TRUE;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL mapOS2ToWin32Point(Win32BaseWindow *wndFrom,Win32BaseWindow *wndTo,OSLIBPOINT *fromPt)
-{
-  if (!wndFrom || !wndTo) return 0;
-  if (wndFrom != wndTo)
-  {
-    if (!WinMapWindowPoints(wndFrom->getOS2WindowHandle(),wndTo->getOS2WindowHandle(),(PPOINTL)fromPt,1)) return FALSE;
-  }
-  fromPt->y = wndTo->getClientHeight()-1-fromPt->y;
-
-  return TRUE;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL mapWin32Point(HWND os2From,HWND os2To,OSLIBPOINT *fromPt)
-{
-  RECTL rect;
-
-  if (os2From == OSLIB_HWND_DESKTOP) os2From = HWND_DESKTOP;
-  if (os2To == OSLIB_HWND_DESKTOP) os2To = HWND_DESKTOP;
-  if (os2From == os2To) return TRUE;
-  if (!WinQueryWindowRect(os2From,&rect)) return 0;
-  fromPt->y = rect.yTop-1-fromPt->y;
-  if (!WinMapWindowPoints(os2From,os2To,(PPOINTL)fromPt,1)) return 0;
-  if (!WinQueryWindowRect(os2To,&rect)) return 0;
-  fromPt->y = rect.yTop-1-fromPt->y;
-
-  return TRUE;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL mapWin32Point(Win32BaseWindow *wndFrom,Win32BaseWindow *wndTo,OSLIBPOINT *fromPt)
-{
-  if (!wndFrom || !wndTo) return FALSE;
-  if (wndFrom == wndTo) return TRUE;
-  fromPt->y = wndFrom->getClientHeight()-1-fromPt->y;
-  if (!WinMapWindowPoints(wndFrom->getOS2WindowHandle(),wndTo->getOS2WindowHandle(),(PPOINTL)fromPt,1)) return 0;
-  fromPt->y = wndTo->getClientHeight()-1-fromPt->y;
-
-  return TRUE;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL mapOS2ToWin32ScreenRect(PRECTLOS2 rectOS2,PRECT rectWin32)
-{
-  if (!rectOS2 || !rectWin32) return FALSE;
-  rectWin32->bottom = ScreenHeight-rectOS2->yBottom;
-  rectWin32->top    = ScreenHeight-rectOS2->yTop;
+  rectWin32->bottom = height-rectOS2->yBottom;
+  rectWin32->top    = height-rectOS2->yTop;
   rectWin32->left   = rectOS2->xLeft;
   rectWin32->right  = rectOS2->xRight;
@@ -276,9 +107,12 @@
 //******************************************************************************
 //******************************************************************************
-BOOL mapWin32ToOS2ScreenRect(PRECT rectWin32,PRECTLOS2 rectOS2)
+BOOL mapWin32ToOS2Rect(int height, PRECT rectWin32, PRECTLOS2 rectOS2)
 {
-  if (!rectOS2 || !rectWin32) return FALSE;
-  rectOS2->yBottom = ScreenHeight-rectWin32->bottom;
-  rectOS2->yTop    = ScreenHeight-rectWin32->top;
+  if(!rectOS2 || !rectWin32) {
+	DebugInt3();
+  	return FALSE;
+  }
+  rectOS2->yBottom = height-rectWin32->bottom;
+  rectOS2->yTop    = height-rectWin32->top;
   rectOS2->xLeft   = rectWin32->left;
   rectOS2->xRight  = rectWin32->right;
@@ -288,156 +122,22 @@
 //******************************************************************************
 //******************************************************************************
-BOOL mapOS2ToWin32Rect(HWND os2Client,PRECTLOS2 rectOS2,PRECT rectWin32)
+BOOL mapWin32ToOS2RectClientToFrame(Win32BaseWindow *window, PRECT rectWin32,PRECTLOS2 rectOS2)
 {
-  RECTL rect;
+ int height;
+ int xclientorg;
+ int yclientorg;
 
-  if (!rectOS2 || !rectWin32) return FALSE;
-  if (os2Client == OSLIB_HWND_DESKTOP) os2Client = HWND_DESKTOP; //shouldn't be the case
-  if (!WinQueryWindowRect(os2Client,&rect)) return FALSE;
-  rectWin32->bottom = rect.yTop-rectOS2->yBottom;
-  rectWin32->top    = rect.yTop-rectOS2->yTop;
-  rectWin32->left   = rectOS2->xLeft;
-  rectWin32->right  = rectOS2->xRight;
+  if(!window || !rectOS2 || !rectWin32) {
+	DebugInt3();
+  	return FALSE;
+  }
+  height     = window->getWindowHeight();
+  xclientorg = window->getClientRectPtr()->left;
+  yclientorg = window->getClientRectPtr()->top;
 
-  return TRUE;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL mapOS2ToWin32Rect(Win32BaseWindow *win32wnd,PRECTLOS2 rectOS2,PRECT rectWin32)
-{
-  INT windowH;
-
-  if (!win32wnd || !rectOS2 || !rectWin32) return FALSE;
-  windowH = win32wnd->getClientHeight();
-  rectWin32->bottom = windowH-rectOS2->yBottom;
-  rectWin32->top    = windowH-rectOS2->yTop;
-  rectWin32->left   = rectOS2->xLeft;
-  rectWin32->right  = rectOS2->xRight;
-
-  return TRUE;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL mapOS2ToWin32Rect(HWND os2From,HWND os2To,PRECTLOS2 rectOS2,PRECT rectWin32)
-{
-  RECTL rect,temp;
-
-  if (!rectOS2 || !rectWin32) return FALSE;
-  if (os2From == OSLIB_HWND_DESKTOP) os2From = HWND_DESKTOP;
-  if (os2To == OSLIB_HWND_DESKTOP) os2To = HWND_DESKTOP;
-  temp = *((PRECTL)rectOS2);
-  if (os2From != os2To)
-  {
-    if (!WinMapWindowPoints(os2From,os2To,(PPOINTL)&temp,2)) return FALSE;
-  }
-  if (!WinQueryWindowRect(os2To,&rect)) return FALSE;
-  rectWin32->bottom = rect.yTop-temp.yBottom;
-  rectWin32->top    = rect.yTop-temp.yTop;
-  rectWin32->left   = temp.xLeft;
-  rectWin32->right  = temp.xRight;
-
-  return TRUE;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL mapOS2ToWin32Rect(Win32BaseWindow *wndFrom,Win32BaseWindow *wndTo,PRECTLOS2 rectOS2,PRECT rectWin32)
-{
-  RECTL temp;
-  INT windowH;
-
-  if (!wndFrom || !wndTo || !rectOS2 || !rectWin32) return FALSE;
-  temp = *((PRECTL)rectOS2);
-  if (wndFrom != wndTo)
-  {
-    if (!WinMapWindowPoints(wndFrom->getOS2WindowHandle(),wndTo->getOS2WindowHandle(),(PPOINTL)&temp,2)) return FALSE;
-  }
-  windowH = wndTo->getClientHeight();
-  rectWin32->bottom = windowH-temp.yBottom;
-  rectWin32->top    = windowH-temp.yTop;
-  rectWin32->left   = temp.xLeft;
-  rectWin32->right  = temp.xRight;
-
-  return TRUE;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL mapWin32ToOS2Rect(HWND os2Client,PRECT rectWin32,PRECTLOS2 rectOS2)
-{
-  RECTL rect;
-
-  if (!rectOS2 || !rectWin32) return FALSE;
-  if (os2Client == OSLIB_HWND_DESKTOP) os2Client = HWND_DESKTOP; //shouldn't be the case
-  if (!WinQueryWindowRect(os2Client,&rect)) return FALSE;
-  rectOS2->yBottom = rect.yTop-rectWin32->bottom;
-  rectOS2->yTop    = rect.yTop-rectWin32->top;
-  rectOS2->xLeft   = rectWin32->left;
-  rectOS2->xRight  = rectWin32->right;
-
-  return TRUE;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL mapWin32ToOS2Rect(Win32BaseWindow *win32wnd,PRECT rectWin32,PRECTLOS2 rectOS2)
-{
-  INT windowH;
-
-  if (!win32wnd || !rectOS2 || !rectWin32) return FALSE;
-  windowH = win32wnd->getClientHeight();
-  rectOS2->yBottom = windowH-rectWin32->bottom;
-  rectOS2->yTop    = windowH-rectWin32->top;
-  rectOS2->xLeft   = rectWin32->left;
-  rectOS2->xRight  = rectWin32->right;
-
-  return TRUE;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL mapWin32ToOS2Rect(HWND os2From,HWND os2To,PRECT rectWin32,PRECTLOS2 rectOS2)
-{
-  RECTL rect;
-
-  if (!rectOS2 || !rectWin32) return FALSE;
-  if (os2From == OSLIB_HWND_DESKTOP) os2From = HWND_DESKTOP;
-  if (os2To == OSLIB_HWND_DESKTOP) os2To = HWND_DESKTOP;
-  if (!WinQueryWindowRect(os2From,&rect)) return FALSE;
-  rectOS2->yBottom = rect.yTop-rectWin32->bottom;
-  rectOS2->yTop    = rect.yTop-rectWin32->top;
-  rectOS2->xLeft   = rectWin32->left;
-  rectOS2->xRight  = rectWin32->right;
-  if (os2From != os2To)
-  {
-    if (!WinMapWindowPoints(os2From,os2To,(PPOINTL)rectOS2,2)) return FALSE;
-  }
-
-  return TRUE;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL mapWin32ToOS2Rect(Win32BaseWindow *wndFrom,Win32BaseWindow *wndTo,PRECT rectWin32,PRECTLOS2 rectOS2)
-{
-  INT windowH;
-
-  if (!wndFrom || !wndTo || !rectOS2 || !rectWin32) return FALSE;
-  windowH = wndFrom->getClientHeight();
-  rectOS2->yBottom = windowH-rectWin32->bottom;
-  rectOS2->yTop    = windowH-rectWin32->top;
-  rectOS2->xLeft   = rectWin32->left;
-  rectOS2->xRight  = rectWin32->right;
-  if (wndFrom != wndTo)
-  {
-    if (!WinMapWindowPoints(wndFrom->getOS2WindowHandle(),wndTo->getOS2WindowHandle(),(PPOINTL)rectOS2,2)) return FALSE;
-  }
-
-  return TRUE;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL mapWin32Rect(HWND os2From,HWND os2To,PRECT rectWin32)
-{
-  RECTL rect;
-
-  mapWin32ToOS2Rect(os2From,rectWin32,(PRECTLOS2)&rect);
-  WinMapWindowPoints((os2From == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP:os2From,(os2To == OSLIB_HWND_DESKTOP) ? HWND_DESKTOP:os2To,(PPOINTL)&rect,2);
-  mapOS2ToWin32Rect(os2To,(PRECTLOS2)&rect,rectWin32);
+  rectOS2->yBottom = height - (rectWin32->bottom + yclientorg);
+  rectOS2->yTop    = height - (rectWin32->top + yclientorg);
+  rectOS2->xLeft   = rectWin32->left  - xclientorg;
+  rectOS2->xRight  = rectWin32->right - xclientorg;
 
   return TRUE;
@@ -467,71 +167,2 @@
 //******************************************************************************
 //******************************************************************************
-INT mapOS2ToWin32ChildOrigin(INT parentH,INT parentPosY,INT childH)
-{
-  return parentH-parentPosY-childH;//Does: parentH-1-parentPosY-(childH-1)
-}
-//******************************************************************************
-//******************************************************************************
-HDC OSLibWinBeginPaint(HWND hwnd, RECT *rectWin32)
-{
- RECTL rectl;
-
-    if(WinQueryUpdateRect(hwnd, &rectl) == FALSE)
-    {
-        dprintf(("BeginPaint, NO update rectl"));
-        return 0;
-    }
-    mapOS2ToWin32Rect(hwnd,(RECTLOS2 *)&rectl, rectWin32);
-    return WinBeginPaint(hwnd, NULLHANDLE, &rectl);
-}
-//******************************************************************************
-//******************************************************************************
-BOOL OSLibWinEndPaint(HDC hdc)
-{
-  return WinEndPaint((HPS)hdc);
-}
-//******************************************************************************
-//******************************************************************************
-HDC OSLibWinGetPS(HWND hwnd)
-{
-  if(hwnd == OSLIB_HWND_DESKTOP)
-        hwnd = HWND_DESKTOP;
-
-  return (HDC)WinGetPS(hwnd);
-}
-//******************************************************************************
-//******************************************************************************
-BOOL OSLibWinReleasePS(HDC hdc)
-{
-  return WinReleasePS((HPS)hdc);
-}
-//******************************************************************************
-//******************************************************************************
-BOOL OSLibWinInvalidateRect(HWND hwnd, PRECT pRect, BOOL fIncludeChildren)
-{
- RECTLOS2 rectl;
-
-    if(pRect) {
-        mapWin32ToOS2Rect(hwnd,pRect, &rectl);
-        return WinInvalidateRect(hwnd, (PRECTL)&rectl, fIncludeChildren);
-    }
-    return WinInvalidateRect(hwnd, NULL, fIncludeChildren);
-}
-//******************************************************************************
-//Returns rectangle in Win32 window coordinates
-//******************************************************************************
-BOOL OSLibWinQueryUpdateRect(HWND hwnd, PRECT pRect)
-{
- BOOL rc;
- RECTLOS2 rectl;
-
-  rc = WinQueryUpdateRect(hwnd, (PRECTL)&rectl);
-  if(rc) {
-        mapOS2ToWin32Rect(hwnd,&rectl, pRect);
-  }
-  else  memset(pRect, 0, sizeof(RECT));
-  return rc;
-}
-//******************************************************************************
-//******************************************************************************
-
Index: trunk/src/user32/oslibgdi.h
===================================================================
--- trunk/src/user32/oslibgdi.h	(revision 3658)
+++ trunk/src/user32/oslibgdi.h	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: oslibgdi.h,v 1.5 2000-01-18 20:08:10 sandervl Exp $ */
+/* $Id: oslibgdi.h,v 1.6 2000-06-07 14:51:26 sandervl Exp $ */
 /*
  * Window GDI wrapper functions for OS/2
@@ -32,42 +32,79 @@
 } OSLIBPOINT;
 
-HDC   OSLibWinBeginPaint(HWND hwnd, RECT *pRectl);
-BOOL  OSLibWinEndPaint(HDC hdc);
-
-HDC   OSLibWinGetPS(HWND hwnd);
-BOOL  OSLibWinReleasePS(HDC hdc);
-
-BOOL  OSLibWinInvalidateRect(HWND hwnd, PRECT pRect, BOOL fIncludeChildren); //must be RECTL pointer!
-BOOL  OSLibWinQueryUpdateRect(HWND hwnd, PRECT pRect);
-
 //Mapping functions
 
 INT  mapScreenY(INT screenPosY);
 INT  mapScreenY(INT screenH,INT screenPosY);
-INT  mapY(HWND os2Client,INT clientPosY);
-INT  mapY(Win32BaseWindow *win32wnd,INT clientPosY);
-INT  mapOS2ToWin32Y(HWND os2From,HWND os2To,INT fromPosY);
+INT inline mapY(INT height, int y)
+{
+   return height - 1 - y;
+}
+
+INT inline mapY(Win32BaseWindow *win32wnd,INT y)
+{
+   return win32wnd->getWindowHeight() - 1 - y;
+}
+
+INT inline mapOS2ToWin32Y(Win32BaseWindow *win32wnd,INT y)
+{
+   return win32wnd->getWindowHeight() - 1 - (y + win32wnd->getClientRectPtr()->top);
+}
+
+INT inline mapOS2ToWin32X(Win32BaseWindow *win32wnd,INT x)
+{
+   return x - win32wnd->getClientRectPtr()->left;
+}
+
+INT inline mapWin32ToOS2Y(Win32BaseWindow *win32wnd,INT y)
+{
+   if(win32wnd->getParent()) {
+	return win32wnd->getWindowHeight() - 1 - (y - win32wnd->getParent()->getClientRectPtr()->top);
+   }
+   else	return y;
+}
+
+INT inline mapWin32ToOS2X(Win32BaseWindow *win32wnd,INT x)
+{
+   if(win32wnd->getParent()) {
+	return x + win32wnd->getParent()->getClientRectPtr()->left;
+   }
+   else	return x;
+}
+
 INT  mapOS2ToWin32Y(Win32BaseWindow *wndFrom,Win32BaseWindow *wndTo,INT fromPosY);
-INT  mapWin32Y(HWND os2From,HWND os2To,INT fromPosY);
 INT  mapWin32Y(Win32BaseWindow *wndFrom,Win32BaseWindow *wndTo,INT fromPosY);
 BOOL mapScreenPoint(OSLIBPOINT *screenPt);
 BOOL mapScreenPoint(INT screenH,OSLIBPOINT *screenPt);
-BOOL mapPoint(HWND os2Client,OSLIBPOINT *clientPt);
-BOOL mapPoint(Win32BaseWindow *win32wnd,OSLIBPOINT *clientPt);
-BOOL mapOS2ToWin32Point(HWND os2From,HWND os2To,OSLIBPOINT *fromPt);
-BOOL mapOS2ToWin32Point(Win32BaseWindow *wndFrom,Win32BaseWindow *wndTo,OSLIBPOINT *fromPt);
-BOOL mapWin32Point(HWND os2From,HWND os2To,OSLIBPOINT *fromPt);
-BOOL mapWin32Point(Win32BaseWindow *wndFrom,Win32BaseWindow *wndTo,OSLIBPOINT *fromPt);
-BOOL mapOS2ToWin32ScreenRect(PRECTLOS2 rectOS2,PRECT rectWin32);
-BOOL mapWin32ToOS2ScreenRect(PRECT rectWin32,PRECTLOS2 rectOS2);
-BOOL mapOS2ToWin32Rect(HWND os2Client,PRECTLOS2 rectOS2,PRECT rectWin32);
-BOOL mapOS2ToWin32Rect(Win32BaseWindow *win32wnd,PRECTLOS2 rectOS2,PRECT rectWin32);
-BOOL mapOS2ToWin32Rect(HWND os2From,HWND os2To,PRECTLOS2 rectOS2,PRECT rectWin32);
-BOOL mapOS2ToWin32Rect(Win32BaseWindow *wndFrom,Win32BaseWindow *wndTo,PRECTLOS2 rectOS2,PRECT rectWin32);
-BOOL mapWin32ToOS2Rect(HWND os2Client,PRECT rectWin32,PRECTLOS2 rectOS2);
-BOOL mapWin32ToOS2Rect(Win32BaseWindow *win32wnd,PRECT rectWin32,PRECTLOS2 rectOS2);
-BOOL mapWin32ToOS2Rect(HWND os2From,HWND os2To,PRECT rectWin32,PRECTLOS2 rectOS2);
-BOOL mapWin32ToOS2Rect(Win32BaseWindow *wndFrom,Win32BaseWindow *wndTo,PRECT rectWin32,PRECTLOS2 rectOS2);
-BOOL mapWin32Rect(HWND os2From,HWND os2To,PRECT rectWin32);
+
+BOOL mapOS2ToWin32Rect(int height, PRECTLOS2 rectOS2, PRECT rectWin32);
+BOOL mapWin32ToOS2Rect(int height, PRECT rectWin32,PRECTLOS2 rectOS2);
+
+BOOL mapWin32ToOS2RectClientToFrame(Win32BaseWindow *window, PRECT rectWin32,PRECTLOS2 rectOS2);
+
+#define mapWin32ToOS2RectFrame(window, rectWin32, rectOS2) \
+        if(window->getParent()) { \
+		mapWin32ToOS2Rect(window->getParent()->getWindowHeight(), rectWin32, rectOS2); \
+        } \
+        else    mapWin32ToOS2Rect(OSLibQueryScreenHeight(), rectWin32, rectOS2);
+
+#define mapWin32ToOS2RectClient(window, rectWin32, rectOS2) \
+        mapWin32ToOS2Rect(window->getClientHeight(), rectWin32, rectOS2)
+
+#define mapWin32ToOS2ScreenRect(rectOS2, rectWin32) \
+        mapWin32ToOS2Rect(OSLibQueryScreenHeight(), rectOS2, rectWin32)
+
+#define mapOS2ToWin32RectFrame(window, rectOS2, rectWin32) \
+        if(window->getParent()) { \
+		mapOS2ToWin32Rect(window->getParent()->getWindowHeight(), rectOS2, rectWin32); \
+        } \
+        else    mapOS2ToWin32Rect(OSLibQueryScreenHeight(), rectOS2, rectWin32);
+        
+
+#define mapOS2ToWin32RectClient(window, rectOS2, rectWin32) \
+        mapOS2ToWin32Rect(window->getClientHeight(), rectOS2, rectWin32)
+
+#define mapOS2ToWin32ScreenRect(rectOS2, rectWin32) \
+        mapOS2ToWin32Rect(OSLibQueryScreenHeight(), rectOS2, rectWin32)
+
 BOOL copyOS2ToWin32Rect(PRECTLOS2 rectOS2,PRECT rectWin32);
 BOOL copyWin32ToOS2WindowRect(PRECT rectWin32,PRECTLOS2 rectOS2);
Index: trunk/src/user32/oslibmsgtranslate.cpp
===================================================================
--- trunk/src/user32/oslibmsgtranslate.cpp	(revision 3658)
+++ trunk/src/user32/oslibmsgtranslate.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: oslibmsgtranslate.cpp,v 1.33 2000-05-29 22:43:31 sandervl Exp $ */
+/* $Id: oslibmsgtranslate.cpp,v 1.34 2000-06-07 14:51:26 sandervl Exp $ */
 /*
  * Window message translation functions for OS/2
@@ -143,5 +143,4 @@
   memset(winMsg, 0, sizeof(MSG));
   win32wnd = Win32BaseWindow::GetWindowFromOS2Handle(os2Msg->hwnd);
-  if (!win32wnd) win32wnd = Win32BaseWindow::GetWindowFromOS2FrameHandle(os2Msg->hwnd);
 
   //PostThreadMessage posts WIN32APP_POSTMSG msg without window handle
@@ -159,154 +158,4 @@
     winMsg->hwnd = win32wnd->getWindowHandle();
 
-  if (win32wnd && (os2Msg->hwnd == win32wnd->getOS2FrameWindowHandle()))
-  {
-    //special frame messages
-
-    switch (os2Msg->msg)
-    {
-      case WM_HITTEST:
-        winMsg->message = WINWM_NCHITTEST;
-        winMsg->wParam  = 0;
-        winMsg->lParam  = MAKELONG(winMsg->pt.x,winMsg->pt.y);
-
-	if(!win32wnd->IsWindowEnabled()) {
-		if(win32wnd->getParent()) {
-			winMsg->hwnd = win32wnd->getParent()->getWindowHandle();
-		}
-		else	goto dummymessage; //don't send mouse messages to disabled windows
-	}
-        return TRUE;
-
-      case WM_BUTTON1DOWN:
-      case WM_BUTTON1UP:
-      case WM_BUTTON1DBLCLK:
-      case WM_BUTTON2DOWN:
-      case WM_BUTTON2UP:
-      case WM_BUTTON2DBLCLK:
-      case WM_BUTTON3DOWN:
-      case WM_BUTTON3UP:
-      case WM_BUTTON3DBLCLK:
-        //WM_NC*BUTTON* is posted when the cursor is in a non-client area of the window
-
-#ifdef ODIN_HITTEST
-	//Send WM_HITTEST message
-        win32wnd->sendHitTest(MAKELONG(winMsg->pt.x,winMsg->pt.y));
-#endif
-
-	//if a window is disabled, it's parent receives the mouse messages
-	if(!win32wnd->IsWindowEnabled()) {
-		if(win32wnd->getParent()) {
-			win32wnd = win32wnd->getParent();
-		}
-		dprintf(("Rerouting mouse messages to parent %x of disabled window %x", win32wnd->getWindowHandle(), winMsg->hwnd));
-		fWasDisabled = TRUE;
-	}
-
-        if (IsNCMouseMsg(win32wnd)) {
-            winMsg->message = WINWM_NCLBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
-            winMsg->wParam  = win32wnd->getLastHitTestVal();
-            winMsg->lParam  = MAKELONG(winMsg->pt.x, winMsg->pt.y); //screen coordinates
-        }
-        else {
-            point.x         = (*(POINTS *)&os2Msg->mp1).x;
-            point.y         = (*(POINTS *)&os2Msg->mp1).y;
-            ClientPoint.x   = point.x;
-            ClientPoint.y   = mapOS2ToWin32Y(os2Msg->hwnd,win32wnd->getOS2WindowHandle(),point.y);
-
-            winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
-            winMsg->wParam  = GetMouseKeyState();
-            winMsg->lParam  = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
-        }
-        if(ISMOUSE_CAPTURED())
-        {
-            if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
-                goto dummymessage; //dinput swallowed message
-            }
-        }
-	if(fWasDisabled) {
-		if(win32wnd) {
-			winMsg->hwnd = win32wnd->getWindowHandle();
-		}
-		else	goto dummymessage; //don't send mouse messages to disabled windows
-	}
-        return TRUE;
-
-      case WM_BUTTON2MOTIONSTART:
-      case WM_BUTTON2MOTIONEND:
-      case WM_BUTTON2CLICK:
-      case WM_BUTTON1MOTIONSTART:
-      case WM_BUTTON1MOTIONEND:
-      case WM_BUTTON1CLICK:
-      case WM_BUTTON3MOTIONSTART:
-      case WM_BUTTON3MOTIONEND:
-      case WM_BUTTON3CLICK:
-        goto dummymessage;
-
-      case WM_MOUSEMOVE:
-      {
-        //WM_NCMOUSEMOVE is posted when the cursor moves into a non-client area of the window
-
-#ifdef ODIN_HITTEST
-	//Send WM_HITTEST message
-        win32wnd->sendHitTest(MAKELONG(winMsg->pt.x,winMsg->pt.y));
-#endif
-	//if a window is disabled, it's parent receives the mouse messages
-	if(!win32wnd->IsWindowEnabled()) {
-		if(win32wnd->getParent()) {
-			win32wnd = win32wnd->getParent();
-		}
-		dprintf(("Rerouting mouse messages to parent %x of disabled window %x", win32wnd->getWindowHandle(), winMsg->hwnd));
-		fWasDisabled = TRUE;
-	}
-        if (IsNCMouseMsg(win32wnd))
-        {
-          winMsg->message = WINWM_NCMOUSEMOVE;
-          winMsg->wParam  = (WPARAM)win32wnd->getLastHitTestVal();
-          winMsg->lParam  = MAKELONG(winMsg->pt.x,winMsg->pt.y);
-        }
-        else
-        {
-          winMsg->message = WINWM_MOUSEMOVE;
-          winMsg->wParam  = GetMouseKeyState();
-          winMsg->lParam  = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapOS2ToWin32Y(win32wnd->getOS2FrameWindowHandle(),win32wnd->getOS2WindowHandle(),SHORT2FROMMP(os2Msg->mp1)));
-        }
-        if(ISMOUSE_CAPTURED())
-        {
-            if(DInputMouseHandler(win32wnd->getWindowHandle(), winMsg->message, winMsg->pt.x, winMsg->pt.y)) {
-                goto dummymessage; //dinput swallowed message
-            }
-        }
-	if(fWasDisabled) {
-		if(win32wnd) {
-			winMsg->hwnd = win32wnd->getWindowHandle();
-		}
-		else	goto dummymessage; //don't send mouse messages to disabled windows
-	}
-        //OS/2 Window coordinates -> Win32 Window coordinates
-        return TRUE;
-      }
-
-      case WM_PAINT:
-      {
-        winMsg->message = WINWM_NCPAINT;
-        return TRUE;
-      }
-
-      case WM_ACTIVATE:
-      {
-        winMsg->message = WINWM_NCACTIVATE;
-        winMsg->wParam  = SHORT1FROMMP(os2Msg->mp1);
-
-        return TRUE;
-      }
-      case WM_WINDOWPOSCHANGED:
-      {
-        //todo: proper translation
-        return FALSE;
-      }
-    }
-    //do normal translation for all other messages
-  }
-
   switch(os2Msg->msg)
   {
@@ -383,21 +232,17 @@
             }
         }
-        OSLibMapSWPtoWINDOWPOS(pswp, &thdb->wp, &swpOld, hParent, win32wnd->getOS2FrameWindowHandle());
+        if(win32wnd->getParent()) {
+   	      OSLibMapSWPtoWINDOWPOS(pswp, &thdb->wp, &swpOld, win32wnd->getParent()->getWindowHeight(), 
+                                     win32wnd->getParent()->getClientRectPtr()->left,
+                                     win32wnd->getParent()->getClientRectPtr()->top,
+                                     win32wnd->getOS2WindowHandle());
+        } 
+        else  OSLibMapSWPtoWINDOWPOS(pswp, &thdb->wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, win32wnd->getOS2WindowHandle());
 
         if (!win32wnd->CanReceiveSizeMsgs())    goto dummymessage;
-
-        ULONG windowStyle = WinQueryWindowULong(os2Msg->hwnd, QWL_STYLE);
-        win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MAXIMIZE_W|WS_MINIMIZE_W));
-        if (windowStyle & WS_MINIMIZED) {
-            win32wnd->setStyle(win32wnd->getStyle() | WS_MINIMIZE_W);
-        }
-        else
-        if (windowStyle & WS_MAXIMIZED) {
-            win32wnd->setStyle(win32wnd->getStyle() | WS_MAXIMIZE_W);
-        }
 
         if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
                 dprintf(("Set client rectangle to (%d,%d)(%d,%d)", swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy));
-                win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
+/////                win32wnd->setClientRect(swpOld.x, swpOld.y, swpOld.x + swpOld.cx, swpOld.y + swpOld.cy);
 
                 thdb->wp.hwnd = win32wnd->getWindowHandle();
@@ -408,16 +253,8 @@
                         thdb->wp.hwndInsertAfter = wndAfter->getWindowHandle();
                 }
-
-                PRECT lpRect = win32wnd->getWindowRect();
-                //SvL: Only send it when the client has changed & the frame hasn't
-                //     If the frame size/position has changed, pmframe.cpp will send
-                //     this message
-                if(lpRect->right == thdb->wp.x+thdb->wp.cx && lpRect->bottom == thdb->wp.y+thdb->wp.cy) {
-                        winMsg->message = WINWM_WINDOWPOSCHANGED;
-                        winMsg->lParam  = (LPARAM)&thdb->wp;
-                        break;
-                }
-        }
-        goto dummymessage;
+        }
+        winMsg->message = WINWM_WINDOWPOSCHANGED;
+        winMsg->lParam  = (LPARAM)&thdb->wp;
+        break;
     }
 
@@ -434,5 +271,5 @@
 	}
 
-        if(WinQueryWindowULong(os2Msg->hwnd, QWL_STYLE) & WS_MINIMIZED)
+        if(win32wnd->getStyle() & WS_MINIMIZE_W)
         {
            fMinimized = TRUE;
@@ -497,4 +334,5 @@
         win32wnd->sendHitTest(MAKELONG(winMsg->pt.x,winMsg->pt.y));
 #endif
+        win32wnd->sendHitTest(MAKELONG(winMsg->pt.x,winMsg->pt.y));
 
 	//if a window is disabled, it's parent receives the mouse messages
@@ -514,6 +352,6 @@
             point.x         = (*(POINTS *)&os2Msg->mp1).x;
             point.y         = (*(POINTS *)&os2Msg->mp1).y;
-            ClientPoint.x   = point.x;
-            ClientPoint.y   = mapY(os2Msg->hwnd,point.y);
+            ClientPoint.x   = mapOS2ToWin32X(win32wnd, point.x);
+            ClientPoint.y   = mapOS2ToWin32Y(win32wnd, point.y);
 
             winMsg->message = WINWM_LBUTTONDOWN + (os2Msg->msg - WM_BUTTON1DOWN);
@@ -571,7 +409,12 @@
         else
         {
+          point.x         = (*(POINTS *)&os2Msg->mp1).x;
+          point.y         = (*(POINTS *)&os2Msg->mp1).y;
+          ClientPoint.x   = mapOS2ToWin32X(win32wnd, point.x);
+          ClientPoint.y   = mapOS2ToWin32Y(win32wnd, point.y);
+
           winMsg->message = WINWM_MOUSEMOVE;
           winMsg->wParam  = GetMouseKeyState();
-          winMsg->lParam  = MAKELONG(SHORT1FROMMP(os2Msg->mp1),mapY(win32wnd,SHORT2FROMMP(os2Msg->mp1)));
+          winMsg->lParam  = MAKELONG(ClientPoint.x, ClientPoint.y); //client coordinates
         }
         if((fMsgRemoved == MSG_REMOVE) && ISMOUSE_CAPTURED())
Index: trunk/src/user32/oslibwin.cpp
===================================================================
--- trunk/src/user32/oslibwin.cpp	(revision 3658)
+++ trunk/src/user32/oslibwin.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: oslibwin.cpp,v 1.78 2000-05-26 18:43:34 sandervl Exp $ */
+/* $Id: oslibwin.cpp,v 1.79 2000-06-07 14:51:26 sandervl Exp $ */
 /*
  * Window API wrappers for OS/2
@@ -53,11 +53,10 @@
 //******************************************************************************
 HWND OSLibWinCreateWindow(HWND hwndParent,ULONG dwWinStyle,
-                          char *pszName, HWND Owner, ULONG fHWND_BOTTOM, HWND *hwndFrame,
+                          char *pszName, HWND Owner, ULONG fHWND_BOTTOM, 
                           ULONG id, BOOL fTaskList,BOOL fShellPosition,
                           int classStyle)
 {
  HWND  hwndClient;
-
-  dprintf(("WinCreateWindow %x %s %x task %d shell %d classstyle %x", hwndParent, pszName, id, fTaskList, fShellPosition, classStyle));
+ ULONG dwFrameStyle = 0;
 
   if(pszName && *pszName == 0) {
@@ -70,17 +69,11 @@
         Owner = HWND_DESKTOP;
   }
-  ULONG dwClientStyle = 0;
-  ULONG dwFrameStyle = 0;
-
   BOOL TopLevel = hwndParent == HWND_DESKTOP;
-
-  FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
 
   if(classStyle & CS_SAVEBITS_W) dwWinStyle |= WS_SAVEBITS;
   if(classStyle & CS_PARENTDC_W) dwWinStyle |= WS_PARENTCLIP;
 
-  dwClientStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP | WS_CLIPSIBLINGS);
-
-  dwFrameStyle |= FCF_NOBYTEALIGN;
+  dwWinStyle = dwWinStyle & ~(WS_TABSTOP | WS_GROUP);
+
   if(fTaskList)
   {
@@ -89,21 +82,23 @@
   if (fShellPosition) dwFrameStyle |= FCF_SHELLPOSITION;
 
-  dwWinStyle &= ~WS_CLIPCHILDREN;
+  FRAMECDATA FCData = {sizeof (FRAMECDATA), 0, 0, 0};
   FCData.flCreateFlags = dwFrameStyle;
 
-  *hwndFrame = WinCreateWindow (hwndParent,
-                                TopLevel ? WC_FRAME : WIN32_INNERFRAME,
-                                pszName, dwWinStyle, 0, 0, 0, 0,
-                                Owner, HWND_TOP,
-                                id, &FCData, NULL);
-
-  if (*hwndFrame) {
-    hwndClient = WinCreateWindow (*hwndFrame, (classStyle & CS_SAVEBITS_W) ? WIN32_STDCLASS2:WIN32_STDCLASS,
-                                  NULL, dwClientStyle, 0, 0, 0, 0,
-                                  *hwndFrame, HWND_TOP, FID_CLIENT, NULL, NULL);
-    return hwndClient;
-  }
-  dprintf(("OSLibWinCreateWindow: (FRAME) WinCreateStdWindow failed (%x)", WinGetLastError(GetThreadHAB())));
-  return 0;
+  dprintf(("WinCreateWindow %x %s %x task %d shell %d classstyle %x winstyle %x", hwndParent, pszName, id, fTaskList, fShellPosition, classStyle, dwWinStyle));
+
+#if 1
+  return WinCreateWindow (hwndParent,
+//                          TopLevel ? WIN32_STDFRAMECLASS : WIN32_STDCLASS,
+                          WIN32_STDFRAMECLASS,
+                          pszName, dwWinStyle, 0, 0, 0, 0,
+                          Owner, HWND_TOP,
+                          id, &FCData, NULL);
+#else
+  return WinCreateWindow (hwndParent,
+                          WIN32_STDCLASS,
+                          pszName, dwWinStyle, 0, 0, 0, 0,
+                          Owner, HWND_TOP,
+                          id, NULL, NULL);
+#endif
 }
 //******************************************************************************
@@ -258,19 +253,21 @@
 //******************************************************************************
 //******************************************************************************
-BOOL OSLibWinQueryWindowRect(HWND hwnd, PRECT pRect, int RelativeTo)
+#if 0
+BOOL OSLibWinQueryWindowRect(Win32BaseWindow *window, PRECT pRect, int RelativeTo)
 {
  BOOL     rc;
  RECTLOS2 rectl;
 
-  rc = WinQueryWindowRect(hwnd, (PRECTL)&rectl);
+  rc = WinQueryWindowRect(window->getOS2WindowHandle(), (PRECTL)&rectl);
   if(rc) {
         if(RelativeTo == RELATIVE_TO_SCREEN) {
-                mapOS2ToWin32Rect(hwnd,OSLIB_HWND_DESKTOP,&rectl,pRect);
+                mapOS2ToWin32RectFrame(window,windowDesktop,&rectl,pRect);
         }
-        else    mapOS2ToWin32Rect(hwnd,&rectl,pRect);
+        else    mapOS2ToWin32RectFrame(window,&rectl,pRect);
   }
   else  memset(pRect, 0, sizeof(RECT));
   return rc;
 }
+#endif
 //******************************************************************************
 //******************************************************************************
@@ -294,5 +291,11 @@
 BOOL OSLibWinSetActiveWindow(HWND hwnd)
 {
-  return WinSetActiveWindow(HWND_DESKTOP, hwnd);
+ BOOL rc;
+
+  rc = WinSetActiveWindow(HWND_DESKTOP, hwnd);
+  if(rc == FALSE) {
+	dprintf(("WinSetActiveWindow %x failure: %x", hwnd, OSLibWinGetLastError()));
+  }
+  return rc;
 }
 //******************************************************************************
@@ -392,19 +395,18 @@
 //******************************************************************************
 //******************************************************************************
-void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld, HWND hParent, HWND hFrame)
+void OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld, 
+                            int parentHeight, int clientOrgX, int clientOrgY, 
+                            HWND hwnd)
 {
    HWND hWindow            = pswp->hwnd;
    HWND hWndInsertAfter    = pswp->hwndInsertBehind;
-   long x                  = pswp->x;
-   long y                  = pswp->y;
+   long x                  = pswp->x - clientOrgX;
+   long y                  = pswp->y + clientOrgY;
    long cx                 = pswp->cx;
    long cy                 = pswp->cy;
    UINT fuFlags            = (UINT)pswp->fl;
-   ULONG parentHeight;
 
    HWND   hWinAfter;
    ULONG  flags = 0;
-   SWP    swpFrame, swpClient;
-   POINTL point;
 
    HWND  hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
@@ -429,28 +431,7 @@
     if (  fuFlags & SWP_NOADJUST)    flags |= SWP_NOSENDCHANGING_W;
 
-    WinQueryWindowPos(hFrame, &swpFrame);
-
     if(fuFlags & (SWP_MOVE | SWP_SIZE))
     {
-        point.x = swpFrame.x;
-        point.y = swpFrame.y;
-
-        if (hParent)
-        {
-          RECTL parentRect;
-
-          WinQueryWindowRect(hParent,&parentRect);
-          parentHeight = parentRect.yTop;
-        } else
-        {
-          parentHeight = ScreenHeight;
-        }
-
-        point.y = parentHeight-point.y-swpFrame.cy;
-
-        cy = swpFrame.cy;
-        cx = swpFrame.cx;
-        x  = point.x;
-        y  = point.y;
+        y  = parentHeight - y - pswp->cy;
 
         if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
@@ -470,5 +451,5 @@
 
     pswpOld->x  = pswp->x;
-    pswpOld->y  = swpFrame.cy-pswp->y-pswp->cy;
+    pswpOld->y  = parentHeight-pswp->y-pswp->cy;
     pswpOld->cx = pswp->cx;
     pswpOld->cy = pswp->cy;
@@ -487,96 +468,6 @@
 //******************************************************************************
 //******************************************************************************
-void OSLibMapSWPtoWINDOWPOSFrame(PSWP pswp, struct tagWINDOWPOS *pwpos, PSWP pswpOld, HWND hParent, HWND hFrame)
-{
-   HWND hWindow            = pswp->hwnd;
-   HWND hWndInsertAfter    = pswp->hwndInsertBehind;
-   long x                  = pswp->x;
-   long y                  = pswp->y;
-   long cx                 = pswp->cx;
-   long cy                 = pswp->cy;
-   UINT fuFlags            = (UINT)pswp->fl;
-   ULONG parentHeight;
-
-   HWND   hWinAfter;
-   ULONG  flags = 0;
-   SWP    swpClient;
-   POINTL point;
-
-   HWND  hWnd = (hWindow == HWND_DESKTOP) ? HWND_DESKTOP_W: hWindow;
-
-    if (hWndInsertAfter == HWND_TOP)
-        hWinAfter = HWND_TOP_W;
-    else if (hWndInsertAfter == HWND_BOTTOM)
-        hWinAfter = HWND_BOTTOM_W;
-    else
-        hWinAfter = (HWND) hWndInsertAfter;
-
-    //***********************************
-    // convert PM flags to Windows flags
-    //***********************************
-    if (!(fuFlags & SWP_SIZE))       flags |= SWP_NOSIZE_W;
-    if (!(fuFlags & SWP_MOVE))       flags |= SWP_NOMOVE_W;
-    if (!(fuFlags & SWP_ZORDER))     flags |= SWP_NOZORDER_W;
-    if (  fuFlags & SWP_NOREDRAW)    flags |= SWP_NOREDRAW_W;
-    if (!(fuFlags & SWP_ACTIVATE))   flags |= SWP_NOACTIVATE_W;
-    if (  fuFlags & SWP_SHOW)        flags |= SWP_SHOWWINDOW_W;
-    if (  fuFlags & SWP_HIDE)        flags |= SWP_HIDEWINDOW_W;
-    if (  fuFlags & SWP_NOADJUST)    flags |= SWP_NOSENDCHANGING_W;
-
-    WinQueryWindowPos(WinWindowFromID(hFrame, FID_CLIENT), &swpClient);
-
-    if(fuFlags & (SWP_MOVE | SWP_SIZE))
-    {
-        if (hParent)
-        {
-          RECTL parentRect;
-
-          WinQueryWindowRect(hParent,&parentRect);
-          parentHeight = parentRect.yTop;
-        } else
-        {
-          parentHeight = ScreenHeight;
-        }
-
-        point.x = x;
-        point.y = parentHeight-y-cy;
-
-        x  = point.x;
-        y  = point.y;
-
-        if ((pswp->x == pswpOld->x) && (pswp->y == pswpOld->y))
-            flags |= SWP_NOMOVE_W;
-
-        if ((pswp->cx == pswpOld->cx) && (pswp->cy == pswpOld->cy))
-            flags |= SWP_NOSIZE_W;
-
-        if (fuFlags & SWP_SIZE)
-        {
-            if (pswp->cy != pswpOld->cy)
-            {
-                flags &= ~SWP_NOMOVE_W;
-            }
-        }
-    }
-
-    pswpOld->x  = swpClient.x;
-    pswpOld->y  = pswp->cy-swpClient.y-swpClient.cy;
-    pswpOld->cx = swpClient.cx;
-    pswpOld->cy = swpClient.cy;
-
-    dprintf(("window (%d,%d)(%d,%d)  client (%d,%d)(%d,%d)",
-             x,y,cx,cy, pswpOld->x,pswpOld->y,pswpOld->cx,pswpOld->cy));
-
-    pwpos->flags            = (UINT)flags;
-    pwpos->cy               = cy;
-    pwpos->cx               = cx;
-    pwpos->x                = x;
-    pwpos->y                = y;
-    pwpos->hwndInsertAfter  = hWinAfter;
-    pwpos->hwnd             = hWindow;
-}
-//******************************************************************************
-//******************************************************************************
-void OSLibMapWINDOWPOStoSWP(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, HWND hParent, HWND hFrame)
+void OSLibMapWINDOWPOStoSWP(struct tagWINDOWPOS *pwpos, PSWP pswp, PSWP pswpOld, 
+                            int parentHeight, int clientOrgX, int clientOrgY, HWND hFrame)
 {
  BOOL fCvt = FALSE;
@@ -584,10 +475,9 @@
    HWND hWnd            = pwpos->hwnd;
    HWND hWndInsertAfter = pwpos->hwndInsertAfter;
-   long x               = pwpos->x;
-   long y               = pwpos->y;
+   long x               = pwpos->x + clientOrgX;
+   long y               = pwpos->y + clientOrgY;
    long cx              = pwpos->cx;
    long cy              = pwpos->cy;
    UINT fuFlags         = pwpos->flags;
-   ULONG parentHeight;
 
    HWND  hWinAfter;
@@ -617,20 +507,15 @@
    if (  fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
 
-   if (flags & (SWP_MOVE | SWP_SIZE))
+   if(flags & (SWP_MOVE | SWP_SIZE))
    {
-      if (hParent == NULLHANDLE)
-        parentHeight = ScreenHeight;
-      else
-        parentHeight = OSLibGetWindowHeight(hParent);
-
-      if ((flags & SWP_MOVE) == 0)
+      if((flags & SWP_MOVE) == 0)
       {
          x = pswpOld->x;
          y = pswpOld->y;
 
-         y = parentHeight-y-pswpOld->cy;
-      }
-
-      if (flags & SWP_SIZE)
+         y = parentHeight - y - pswpOld->cy;
+     }
+
+      if(flags & SWP_SIZE)
       {
          if (cy != pswpOld->cy)
@@ -642,5 +527,5 @@
          cy = pswpOld->cy;
       }
-      y  = parentHeight-y-cy;
+      y = parentHeight - y - cy;
 
       if ((pswpOld->x == x) && (pswpOld->y == y))
@@ -664,88 +549,5 @@
 //Position in screen coordinates
 //******************************************************************************
-void OSLibMapWINDOWPOStoSWPFrame(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, HWND hParent, HWND hFrame)
-{
- BOOL fCvt = FALSE;
-
-   HWND hWnd            = pwpos->hwnd;
-   HWND hWndInsertAfter = pwpos->hwndInsertAfter;
-   long x               = pwpos->x;
-   long y               = pwpos->y;
-   long cx              = pwpos->cx;
-   long cy              = pwpos->cy;
-   UINT fuFlags         = pwpos->flags;
-   ULONG parentHeight;
-
-   HWND  hWinAfter;
-   ULONG flags = 0;
-   HWND  hWindow = hWnd ? (HWND)hWnd : HWND_DESKTOP;
-
-   if (hWndInsertAfter == HWND_TOPMOST_W)
-//      hWinAfter = HWND_TOPMOST;
-      hWinAfter = HWND_TOP;
-   else if (hWndInsertAfter == HWND_NOTOPMOST_W)
-//      hWinAfter = HWND_NOTOPMOST;
-      hWinAfter = HWND_TOP;
-   else if (hWndInsertAfter == HWND_TOP_W)
-      hWinAfter = HWND_TOP;
-   else if (hWndInsertAfter == HWND_BOTTOM_W)
-      hWinAfter = HWND_BOTTOM;
-   else
-      hWinAfter = (HWND) hWndInsertAfter;
-
-   if (!(fuFlags & SWP_NOSIZE_W    )) flags |= SWP_SIZE;
-   if (!(fuFlags & SWP_NOMOVE_W    )) flags |= SWP_MOVE;
-   if (!(fuFlags & SWP_NOZORDER_W  )) flags |= SWP_ZORDER;
-   if (  fuFlags & SWP_NOREDRAW_W  )  flags |= SWP_NOREDRAW;
-   if (!(fuFlags & SWP_NOACTIVATE_W)) flags |= SWP_ACTIVATE;
-   if (  fuFlags & SWP_SHOWWINDOW_W)  flags |= SWP_SHOW;
-   if (  fuFlags & SWP_HIDEWINDOW_W)  flags |= SWP_HIDE;
-   if (  fuFlags & SWP_NOSENDCHANGING_W) flags |= SWP_NOADJUST;
-
-   if (flags & (SWP_MOVE | SWP_SIZE))
-   {
-      if (hParent)
-      {
-        RECTL parentRect;
-
-        WinQueryWindowRect(hParent,&parentRect);
-        parentHeight = parentRect.yTop;
-      } else
-      {
-        parentHeight = ScreenHeight;
-      }
-
-      if (flags & SWP_SIZE)
-      {
-         if (cy != pswpOld->cy)
-            flags |= SWP_MOVE;
-      }
-      else
-      {
-         cx = pswpOld->cx;
-         cy = pswpOld->cy;
-      }
-      y  = parentHeight-y-cy;
-
-      if ((pswpOld->x == x) && (pswpOld->y == y))
-         flags &= ~SWP_MOVE;
-
-      if ((pswpOld->cx == cx) && (pswpOld->cy == cy))
-         flags &= ~SWP_SIZE;
-   }
-
-   pswp->fl               = flags;
-   pswp->cy               = cy;
-   pswp->cx               = cx;
-   pswp->x                = x;
-   pswp->y                = y;
-   pswp->hwndInsertBehind = hWinAfter;
-   pswp->hwnd             = hWindow;
-   pswp->ulReserved1      = 0;
-   pswp->ulReserved2      = 0;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL  OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
+BOOL OSLibWinCalcFrameRect(HWND hwndFrame, RECT *pRect, BOOL fClient)
 {
  BOOL rc;
Index: trunk/src/user32/oslibwin.h
===================================================================
--- trunk/src/user32/oslibwin.h	(revision 3658)
+++ trunk/src/user32/oslibwin.h	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: oslibwin.h,v 1.45 2000-05-26 18:43:34 sandervl Exp $ */
+/* $Id: oslibwin.h,v 1.46 2000-06-07 14:51:27 sandervl Exp $ */
 /*
  * Window API wrappers for OS/2
@@ -40,5 +40,5 @@
 HWND  OSLibWinCreateWindow(HWND hwndParent,ULONG dwWinStyle,
                            char *pszName, HWND Owner, ULONG fBottom,
-                           HWND *hwndFrame, ULONG id, BOOL fTaskList,BOOL fShellPosition, int classStyle);
+                           ULONG id, BOOL fTaskList,BOOL fShellPosition, int classStyle);
 
 BOOL  OSLibWinConvertStyle(ULONG dwStyle, ULONG dwExStyle, ULONG *OSWinStyle);
@@ -73,6 +73,7 @@
 ULONG OSLibGetWindowHeight(HWND hwnd); //for point transformation
 
-extern ULONG ScreenHeight;
+extern ULONG ScreenHeight, ScreenWidth;
 inline ULONG OSLibQueryScreenHeight(void) { return (ScreenHeight); }
+inline ULONG OSLibQueryScreenWidth(void)  { return (ScreenWidth); }
 
 //reserved deleted
@@ -220,5 +221,5 @@
 #define RELATIVE_TO_WINDOW 0
 #define RELATIVE_TO_SCREEN 1
-BOOL  OSLibWinQueryWindowRect(HWND hwnd, PRECT pRect, int RelativeTo = RELATIVE_TO_WINDOW);
+BOOL  OSLibWinQueryWindowRect(Win32BaseWindow *window, PRECT pRect, int RelativeTo = RELATIVE_TO_WINDOW);
 BOOL  OSLibWinCalcFrameRect(HWND hwnd, RECT *pRect, BOOL fClient);
 BOOL  OSLibGetMinMaxInfo(HWND hwndFrame, MINMAXINFO *pMinMax);
@@ -247,8 +248,9 @@
 
 BOOL  OSLibWinQueryWindowPos (HWND hwnd, PSWP pswp);
-void  OSLibMapSWPtoWINDOWPOS(PSWP pswp, struct tagWINDOWPOS *pwpos, PSWP pswpOld, HWND hParent, HWND hFrame);
-void  OSLibMapSWPtoWINDOWPOSFrame(PSWP pswp, struct tagWINDOWPOS *pwpos, PSWP pswpOld, HWND hParent, HWND hFrame);
-void  OSLibMapWINDOWPOStoSWP(struct tagWINDOWPOS *pwpos, PSWP pswp, PSWP pswpOld, HWND hParent, HWND hFrame);
-void  OSLibMapWINDOWPOStoSWPFrame(PWINDOWPOS pwpos, PSWP pswp, PSWP pswpOld, HWND hParent, HWND hFrame);
+void  OSLibMapSWPtoWINDOWPOS(PSWP pswp, PWINDOWPOS pwpos, PSWP pswpOld, 
+                            int parentHeight, int clientOrgX, int clientOrgY, 
+                            HWND hwnd);
+void  OSLibMapWINDOWPOStoSWP(struct tagWINDOWPOS *pwpos, PSWP pswp, PSWP pswpOld, 
+                             int parentHeight, int clientOrgX, int clientOrgY, HWND hFrame);
 
 HWND  OSLibWinBeginEnumWindows(HWND hwnd);
Index: trunk/src/user32/pmwindow.cpp
===================================================================
--- trunk/src/user32/pmwindow.cpp	(revision 3658)
+++ trunk/src/user32/pmwindow.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: pmwindow.cpp,v 1.91 2000-05-24 19:30:06 sandervl Exp $ */
+/* $Id: pmwindow.cpp,v 1.92 2000-06-07 14:51:27 sandervl Exp $ */
 /*
  * Win32 Window Managment Code for OS/2
@@ -15,4 +15,5 @@
 #define INCL_GPICONTROL         /* GPI control Functions        */
 #define INCL_DOSPROCESS
+#define INCL_WINTRACKRECT
 
 #include <os2wrap.h>
@@ -52,4 +53,6 @@
 MRESULT EXPENTRY Win32WindowProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2);
 
+PFNWP PMFrameWindowProc = 0;
+
 //******************************************************************************
 //Initialize PM; create hab, message queue and register special Win32 window classes
@@ -57,6 +60,5 @@
 BOOL InitPM()
 {
-  CLASSINFO FrameClassInfo;
-
+ 
   hab = WinInitialize(0);
   dprintf(("Winitialize returned %x", hab));
@@ -96,61 +98,44 @@
      (PSZ)WIN32_STDCLASS,               /* Window class name            */
      (PFNWP)Win32WindowProc,            /* Address of window procedure  */
-#ifdef ODIN_HITTEST
-     0,
-#else
      CS_HITTEST,
-#endif
      NROF_WIN32WNDBYTES)) {
         dprintf(("WinRegisterClass Win32BaseWindow failed"));
         return(FALSE);
-   }
+  }
+
+  CLASSINFO FrameClassInfo;
+  if(!WinQueryClassInfo (hab, WC_FRAME, &FrameClassInfo)) {
+     dprintf (("WinQueryClassInfo WC_FRAME failed"));
+     return (FALSE);
+  }
+  dprintf(("WC_FRAME style %x", FrameClassInfo.flClassStyle));
+
+  PMFrameWindowProc = FrameClassInfo.pfnWindowProc;
   if(!WinRegisterClass(                 /* Register window class        */
      hab,                               /* Anchor block handle          */
-     (PSZ)WIN32_STDCLASS2,              /* Window class name            */
+     (PSZ)WIN32_STDFRAMECLASS,          /* Window class name            */
      (PFNWP)Win32WindowProc,            /* Address of window procedure  */
-#ifdef ODIN_HITTEST
-     CS_SAVEBITS,
-#else
-     CS_SAVEBITS | CS_HITTEST,
-#endif
-     NROF_WIN32WNDBYTES)) {
-        dprintf(("WinRegisterClass Win32BaseWindow failed"));
+     CS_HITTEST | CS_FRAME,
+     FrameClassInfo.cbWindowData+NROF_WIN32WNDBYTES)) {
+        dprintf(("WinRegisterClass Win32BaseWindow failed %x", WinGetLastError(hab)));
         return(FALSE);
-   }
-   if (!WinQueryClassInfo (hab, WC_FRAME, &FrameClassInfo)) {
-     dprintf (("WinQueryClassInfo WC_FRAME failed"));
-     return (FALSE);
-   }
-   FrameClassInfo.flClassStyle &= ~(CS_PUBLIC | CS_CLIPSIBLINGS);
-   if (!WinRegisterClass (hab,
-                          WIN32_INNERFRAME,
-                          FrameClassInfo.pfnWindowProc,
-#ifdef ODIN_HITTEST
-                          FrameClassInfo.flClassStyle,
-#else
-                          FrameClassInfo.flClassStyle | CS_HITTEST,
-#endif
-                          FrameClassInfo.cbWindowData)) {
-     dprintf (("WinRegisterClass Win32InnerFrame failed"));
-     return (FALSE);
-   }
-
-   WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
-   ScreenWidth  = desktopRectl.xRight;
-   ScreenHeight = desktopRectl.yTop;
-
-
-   HDC   hdc;              /* Device-context handle                */
-   /* context data structure */
-   DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
-                       NULL, NULL, NULL};
-
-   /* create memory device context */
-   hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
-   DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, (PLONG)&ScreenBitsPerPel);
-   DevCloseDC(hdc);
-
-   dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight));
-   return TRUE;
+  }
+
+  WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
+  ScreenWidth  = desktopRectl.xRight;
+  ScreenHeight = desktopRectl.yTop;
+
+  HDC   hdc;              /* Device-context handle                */
+  /* context data structure */
+  DEVOPENSTRUC dop = {NULL, "DISPLAY", NULL, NULL, NULL, NULL,
+                     NULL, NULL, NULL};
+
+  /* create memory device context */
+  hdc = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
+  DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, (PLONG)&ScreenBitsPerPel);
+  DevCloseDC(hdc);
+
+  dprintf(("InitPM: Desktop (%d,%d)", ScreenWidth, ScreenHeight));
+  return TRUE;
 } /* End of main */
 //******************************************************************************
@@ -223,10 +208,12 @@
         win32wnd = (Win32BaseWindow *)thdb->newWindow;
         thdb->newWindow = 0;
-
-        if(win32wnd->MsgCreate(WinQueryWindow(hwnd, QW_PARENT), hwnd) == FALSE)
+        if(win32wnd->MsgCreate(hwnd) == FALSE)
         {
             RestoreOS2TIB();
             return (MRESULT)TRUE; //discontinue window creation
         }
+        RestoreOS2TIB();
+	PMFrameWindowProc(hwnd, msg, mp1, mp2);
+  	SetWin32TIB();
     createfail:
         RestoreOS2TIB();
@@ -247,5 +234,6 @@
         dprintf(("OS2: WM_DESTROY %x", hwnd));
         win32wnd->MsgDestroy();
-        break;
+        WinSetVisibleRegionNotify(hwnd, FALSE);
+	goto RunDefWndProc;
 
     case WM_ENABLE:
@@ -261,23 +249,215 @@
     case WM_ADJUSTWINDOWPOS:
     {
-      PSWP      pswp   = (PSWP)mp1;
-        dprintf(("PMWINDOW: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
-        goto RunDefWndProc;
+      PSWP     pswp = (PSWP)mp1;
+      SWP      swpOld;
+      WINDOWPOS wp,wpOld;
+      HWND      hParent = NULLHANDLE, hwndAfter;
+
+        dprintf(("OS2: WM_ADJUSTWINDOWPOS %x %x %x (%d,%d) (%d,%d)", win32wnd->getWindowHandle(), pswp->hwnd, pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
+
+        //CB: show dialog in front of owner
+        if (win32wnd->IsModalDialogOwner())
+        {
+          pswp->fl |= SWP_ZORDER;
+          pswp->hwndInsertBehind = win32wnd->getOS2HwndModalDialog();
+          if (pswp->fl & SWP_ACTIVATE)
+          {
+            pswp->fl &= ~SWP_ACTIVATE;
+            WinSetWindowPos(win32wnd->getOS2HwndModalDialog(),0,0,0,0,0,SWP_ACTIVATE);
+          }
+        }
+
+        if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
+            goto RunDefWndProc;
+
+        if(!win32wnd->CanReceiveSizeMsgs())
+            break;
+
+        WinQueryWindowPos(hwnd, &swpOld);
+        if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
+            if (win32wnd->isChild()) {
+                if(win32wnd->getParent()) {
+                        hParent = win32wnd->getParent()->getOS2WindowHandle();
+                }
+                else    goto RunDefWndProc;
+            }
+        }
+        hwndAfter = pswp->hwndInsertBehind;
+        if(win32wnd->getParent()) {
+   	      OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getWindowHeight(), 
+                                     win32wnd->getParent()->getClientRectPtr()->left,
+                                     win32wnd->getParent()->getClientRectPtr()->top,
+                                     hwnd);
+        } 
+        else  OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
+
+        wp.hwnd = win32wnd->getWindowHandle();
+        if ((pswp->fl & SWP_ZORDER) && (pswp->hwndInsertBehind > HWND_BOTTOM))
+        {
+           Win32BaseWindow *wndAfter = Win32BaseWindow::GetWindowFromOS2Handle(pswp->hwndInsertBehind);
+           if(wndAfter) wp.hwndInsertAfter = wndAfter->getWindowHandle();
+        }
+
+        wpOld = wp;
+        win32wnd->MsgPosChanging((LPARAM)&wp);
+
+        if ((wp.hwndInsertAfter != wpOld.hwndInsertAfter) ||
+            (wp.x != wpOld.x) || (wp.y != wpOld.y) || (wp.cx != wpOld.cx) || (wp.cy != wpOld.cy) || (wp.flags != wpOld.flags))
+        {
+          dprintf(("OS2: WM_ADJUSTWINDOWPOS, app changed windowpos struct"));
+          dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
+
+          if(win32wnd->getParent()) {
+          	OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, win32wnd->getParent()->getWindowHeight(),
+                	               win32wnd->getParent()->getClientRectPtr()->left,
+                        	       win32wnd->getParent()->getClientRectPtr()->top,
+                                       hwnd);
+          } 
+          else  OSLibMapWINDOWPOStoSWP(&wp, pswp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
+
+          dprintf(("%x (%d,%d), (%d,%d)", pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
+          pswp->fl |= SWP_NOADJUST;
+          pswp->hwndInsertBehind = hwndAfter;
+          pswp->hwnd = hwnd;
+
+          RestoreOS2TIB();
+          return (MRESULT)0xf;
+        }
+        RestoreOS2TIB();
+        return (MRESULT)0;
     }
 
     case WM_WINDOWPOSCHANGED:
     {
-        if(pWinMsg->message != 0)
-                win32wnd->MsgPosChanged((LPARAM)&thdb->wp);
-        goto RunDefWndProc;
+      PSWP      pswp   = (PSWP)mp1,pswpOld = pswp+1;
+      SWP       swpOld = *(pswp + 1);
+      WINDOWPOS wp;
+      HWND      hParent = NULLHANDLE;
+      RECTL rect;
+
+        dprintf(("OS2: WM_WINDOWPOSCHANGED (%x) %x %x (%d,%d) (%d,%d)", mp2, win32wnd->getWindowHandle(), pswp->fl, pswp->x, pswp->y, pswp->cx, pswp->cy));
+
+        if ((pswp->fl & (SWP_SIZE | SWP_MOVE | SWP_ZORDER)) == 0)
+        {
+                goto RunDefWndProc;
+        }
+
+        if(pswp->fl & (SWP_MOVE | SWP_SIZE)) {
+            if(win32wnd->isChild()) {
+                if(win32wnd->getParent()) {
+                        hParent = win32wnd->getParent()->getOS2WindowHandle();
+                }
+                else    goto PosChangedEnd; //parent has just been destroyed
+            }
+        }
+
+
+        if(win32wnd->getParent()) {
+   	      OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, win32wnd->getParent()->getWindowHeight(), 
+                                     win32wnd->getParent()->getClientRectPtr()->left,
+                                     win32wnd->getParent()->getClientRectPtr()->top,
+                                     hwnd);
+        } 
+        else  OSLibMapSWPtoWINDOWPOS(pswp, &wp, &swpOld, OSLibQueryScreenHeight(), 0, 0, hwnd);
+
+        if((pswp->fl & (SWP_MOVE | SWP_SIZE)) && !(win32wnd->getStyle() & WS_MINIMIZE_W))
+        {
+          //Note: Also updates the new window rectangle
+          win32wnd->MsgFormatFrame(&wp);
+
+          //CB: todo: use result for WM_CALCVALIDRECTS
+          mapWin32ToOS2RectFrame(win32wnd, win32wnd->getClientRectPtr(), (PRECTLOS2)&rect);
+
+          if(win32wnd->CanReceiveSizeMsgs())
+            win32wnd->MsgPosChanged((LPARAM)&wp);
+
+          if((pswp->fl & SWP_SIZE) && ((pswp->cx != pswpOld->cx) || (pswp->cy != pswpOld->cy)))
+          {
+            //redraw the frame (to prevent unnecessary client updates)
+            BOOL redrawAll = FALSE;
+
+            if (win32wnd->getWindowClass())
+            {
+              DWORD dwStyle = win32wnd->getWindowClass()->getClassLongA(GCL_STYLE_W);
+
+              if ((dwStyle & CS_HREDRAW_W) && (pswp->cx != pswpOld->cx))
+                redrawAll = TRUE;
+              else if ((dwStyle & CS_VREDRAW_W) && (pswp->cy != pswpOld->cy))
+                redrawAll = TRUE;
+            } else redrawAll = TRUE;
+
+            if (redrawAll)
+            {
+              //CB: redraw all children for now
+              //    -> problems with update region if we don't do it
+              //       todo: rewrite whole handling
+              WinInvalidateRect(hwnd,NULL,TRUE);
+            }
+            else
+            {
+              HPS hps = WinGetPS(hwnd);
+              RECTL frame,client,arcl[4];
+
+              WinQueryWindowRect(hwnd,&frame);
+               //top
+              arcl[0].xLeft = 0;
+              arcl[0].xRight = frame.xRight;
+              arcl[0].yBottom = rect.yTop;
+              arcl[0].yTop = frame.yTop;
+               //right
+              arcl[1].xLeft = rect.xRight;
+              arcl[1].xRight = frame.xRight;
+              arcl[1].yBottom = 0;
+              arcl[1].yTop = frame.yTop;
+               //left
+              arcl[2].xLeft = 0;
+              arcl[2].xRight = rect.xLeft;
+              arcl[2].yBottom = 0;
+              arcl[2].yTop = frame.yTop;
+               //bottom
+              arcl[3].xLeft = 0;
+              arcl[3].xRight = frame.xRight;
+              arcl[3].yBottom = 0;
+              arcl[3].yTop = rect.yBottom;
+
+              HRGN hrgn = GpiCreateRegion(hps,4,(PRECTL)&arcl);
+
+              WinInvalidateRegion(hwnd,hrgn,FALSE);
+              GpiDestroyRegion(hps,hrgn);
+              WinReleasePS(hps);
+            }
+          }
+        }
+        else
+        {
+          if(win32wnd->CanReceiveSizeMsgs())
+            win32wnd->MsgPosChanged((LPARAM)&wp);
+        }
+
+PosChangedEnd:
+        RestoreOS2TIB();
+        return (MRESULT)FALSE;
     }
 
     case WM_ACTIVATE:
     {
+        USHORT flags = WinQueryWindowUShort(hwnd,QWS_FLAGS);
+
         dprintf(("OS2: WM_ACTIVATE %x %x %x", hwnd, mp1, mp2));
 
-        if(win32wnd->IsWindowCreated())
+        if(win32wnd->IsWindowCreated()) 
+        {
+          WinSetWindowUShort(hwnd,QWS_FLAGS,mp1 ? (flags | FF_ACTIVE):(flags & ~FF_ACTIVE));
           win32wnd->MsgActivate((LOWORD(pWinMsg->wParam) == WA_ACTIVE_W) ? 1 : 0, HIWORD(pWinMsg->wParam), pWinMsg->lParam, (HWND)mp2);
 
+          //CB: show owner behind the dialog
+          if(win32wnd->IsModalDialog())
+          {
+            Win32BaseWindow *topOwner = win32wnd->getOwner()->GetTopParent();
+
+            if(topOwner) WinSetWindowPos(topOwner->getOS2WindowHandle(),hwnd,0,0,0,0,SWP_ZORDER);
+          }
+        }
+
         break;
     }
@@ -289,8 +469,33 @@
     }
 
+
     case WM_MINMAXFRAME:
     {
-        dprintf(("OS2: WM_MINMAXFRAME"));
-        break;
+      PSWP swp = (PSWP)mp1;
+
+      if (!win32wnd->IsWindowCreated()) goto RunDefFrameProc;
+      dprintf(("OS2: WM_MINMAXFRAME %x",hwnd));
+      if ((swp->fl & SWP_MAXIMIZE) == SWP_MAXIMIZE)
+      {
+        win32wnd->setStyle((win32wnd->getStyle() & ~WS_MINIMIZE_W) | WS_MAXIMIZE_W);
+
+        RECT rect;
+
+        rect.left = rect.top = rect.right = rect.bottom = 0;
+        win32wnd->AdjustMaximizedRect(&rect);
+        swp->x += rect.left;
+        swp->cx += rect.right-rect.left;
+        swp->y -= rect.bottom;
+        swp->cy += rect.bottom-rect.top;
+      }
+      else if ((swp->fl & SWP_MINIMIZE) == SWP_MINIMIZE)
+      {
+        win32wnd->setStyle((win32wnd->getStyle() & ~WS_MAXIMIZE_W) | WS_MINIMIZE_W);
+      }
+      else if ((swp->fl & SWP_RESTORE) == SWP_RESTORE)
+      {
+        win32wnd->setStyle(win32wnd->getStyle() & ~(WS_MINIMIZE_W | WS_MAXIMIZE_W));
+      }
+      goto RunDefFrameProc;
     }
 
@@ -322,8 +527,29 @@
     }
 #else
-      dprintf(("PMWINDOW: WM_CALCVALIDRECTS"));
+      dprintf(("PMWINDOW: WM_CALCVALIDRECTS %x", win32wnd->getWindowHandle()));
       RestoreOS2TIB();
       return (MRESULT)(CVR_ALIGNLEFT | CVR_ALIGNTOP);
 #endif
+
+    case WM_VRNENABLED:
+        if(!win32wnd->isComingToTop() && ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == WS_EX_TOPMOST_W))
+        {
+                HWND hwndrelated;
+                Win32BaseWindow *topwindow;
+
+                win32wnd->setComingToTop(TRUE);
+
+                hwndrelated = WinQueryWindow(hwnd, QW_PREV);
+                dprintf(("WM_VRNENABLED hwndrelated = %x (hwnd=%x)", hwndrelated, hwnd));
+                topwindow = Win32BaseWindow::GetWindowFromOS2Handle(hwndrelated);
+                if(topwindow == NULL || ((win32wnd->getExStyle() & WS_EX_TOPMOST_W) == 0)) {
+                        //put window at the top of z order
+                        WinSetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_ZORDER );
+                }
+
+                win32wnd->setComingToTop(FALSE);
+                break;
+        }
+        goto RunDefWndProc;
 
     case WM_SETFOCUS:
@@ -350,11 +576,18 @@
     //**************************************************************************
     case WM_HITTEST:
-	if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
-		win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
-	}
-        if(win32wnd)
-	        rc = win32wnd->MsgHitTest(pWinMsg);
-        break;
-
+    {
+        if(win32wnd->getWindowHandle() != pWinMsg->hwnd) {
+                win32wnd = Win32BaseWindow::GetWindowFromHandle(pWinMsg->hwnd);
+        }
+        if(win32wnd && win32wnd->IsWindowCreated())
+        {
+          MRESULT rc;
+
+          rc = (MRESULT)win32wnd->MsgHitTest(pWinMsg);
+          RestoreOS2TIB();
+          return rc;
+        }
+        return (MRESULT)HT_NORMAL;
+    }
 
     case WM_BUTTON1DOWN:
@@ -452,10 +685,24 @@
     case WM_PAINT:
     {
-//     RECTL rectl;
-
-        dprintf(("OS2: WM_PAINT"));
-        win32wnd->DispatchMsgA(pWinMsg);
+      RECTL rectl;
+
+   	WinQueryUpdateRect(hwnd, &rectl);
+        dprintf(("OS2: WM_PAINT (%d,%d) (%d,%d)", rectl.xLeft, rectl.yBottom, rectl.xRight, rectl.yTop));
+        if(win32wnd->IsWindowCreated()) 
+	{
+   	  	PRECT pClient = win32wnd->getClientRectPtr();
+   	  	PRECT pWindow = win32wnd->getWindowRect();
+
+   		if(!(pClient->left == 0 && pClient->top == 0 &&
+      		   win32wnd->getClientHeight() == win32wnd->getWindowHeight() && 
+      		   win32wnd->getClientWidth()  == win32wnd->getWindowWidth()))
+   		{
+	        	win32wnd->MsgNCPaint();
+		}
+        	win32wnd->DispatchMsgA(pWinMsg);
+        }
 	//SvL: Not calling the default window procedure causes all sorts of
         //     strange problems (redraw & hanging app)
+        //     -> check what WinBeginPaint does what we're forgetting in BeginPaint
 //   	WinQueryUpdateRect(hwnd, &rectl);
 //        if(rectl.xLeft == 0 && rectl.yTop == 0 && rectl.xRight == 0 && rectl.yBottom == 0) {
@@ -465,12 +712,5 @@
 //	dprintf(("Update rectangle (%d,%d)(%d,%d) not empty, msg %x", rectl.xLeft, rectl.yTop, rectl.xRight, rectl.yBottom, pWinMsg->message));
 	goto RunDefWndProc;
-    }
-
-    case WM_CONTEXTMENU:
-    {
-        win32wnd->DispatchMsgA(pWinMsg);
-
-        RestoreOS2TIB();
-        return (MRESULT)TRUE;
+//        break;
     }
 
@@ -482,7 +722,81 @@
     }
 
+#if 0
+    case WM_CONTEXTMENU:
+    {
+        win32wnd->DispatchMsgA(pWinMsg);
+
+        RestoreOS2TIB();
+        return (MRESULT)TRUE;
+    }
+#endif
+
     case WM_FOCUSCHANGE:
         dprintf(("OS2: WM_FOCUSCHANGE %x", win32wnd->getWindowHandle()));
         goto RunDefWndProc;
+
+    case WM_QUERYTRACKINFO:
+    {
+      PTRACKINFO trackInfo = (PTRACKINFO)mp2;
+
+        dprintf(("OS2: WM_QUERYTRACKINFO %x", win32wnd->getWindowHandle()));
+      	RestoreOS2TIB();
+      	PMFrameWindowProc(hwnd,msg,mp1,mp2);
+      	SetWin32TIB();
+      	trackInfo->cxBorder = 4;
+      	trackInfo->cyBorder = 4;
+      	win32wnd->AdjustTrackInfo((PPOINT)&trackInfo->ptlMinTrackSize,(PPOINT)&trackInfo->ptlMaxTrackSize);
+      	RestoreOS2TIB();
+      	return (MRESULT)TRUE;
+    }
+
+    case WM_QUERYBORDERSIZE:
+    {
+      PWPOINT size = (PWPOINT)mp1;
+
+      dprintf(("OS2: WM_QUERYBORDERSIZE %x", win32wnd->getWindowHandle()));
+
+      size->x = 0;
+      size->y = 0;
+      RestoreOS2TIB();
+      return (MRESULT)TRUE;
+    }
+
+    case WM_FORMATFRAME:
+        dprintf(("OS2: WM_FORMATFRAME %x", win32wnd->getWindowHandle()));
+        break;
+
+#if 0 
+    case WM_ADJUSTFRAMEPOS:
+        dprintf(("OS2: WM_ADJUSTFRAMEPOS %x", win32wnd->getWindowHandle()));
+        break;
+
+    case WM_QUERYFRAMEINFO:
+        dprintf(("OS2: WM_QUERYFRAMEINFO %x", win32wnd->getWindowHandle()));
+	return (MRESULT)(FI_FRAME|FI_ACTIVATEOK);
+
+    case WM_QUERYFOCUSCHAIN:
+    {
+      USHORT fsCmd = SHORT1FROMMP(mp1);
+
+        dprintf(("OS2: WM_QUERYFOCUSCHAIN %x %x %x", win32wnd->getWindowHandle(), mp1, mp2));
+	switch(fsCmd) {
+        case QFC_NEXTINCHAIN:
+    		break;
+	case QFC_ACTIVE:
+	case QFC_FRAME:
+		if(win32wnd->GetTopParent()) {
+			dprintf(("Frame = %x", win32wnd->GetTopParent()->getOS2WindowHandle()));
+			return (MRESULT)win32wnd->GetTopParent()->getOS2WindowHandle();
+		}
+		break;
+	case QFC_SELECTACTIVE:
+		break;
+	case QFC_PARTOFCHAIN:
+		return (MRESULT)TRUE;
+	}
+        break;
+    }
+#endif
 
     case WM_INITMENU:
@@ -511,17 +825,99 @@
     case WM_SEMANTICEVENT:
     default:
-        //dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
+//        dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
         RestoreOS2TIB();
-        return WinDefWindowProc( hwnd, msg, mp1, mp2 );
+        return PMFrameWindowProc(hwnd, msg, mp1, mp2);
+//        return WinDefWindowProc( hwnd, msg, mp1, mp2 );
   }
   RestoreOS2TIB();
   return (MRESULT)rc;
 
+RunDefFrameProc:
+  RestoreOS2TIB();
+  return PMFrameWindowProc(hwnd, msg, mp1, mp2);
+
 RunDefWndProc:
 //  dprintf(("OS2: RunDefWndProc msg %x for %x", msg, hwnd));
   RestoreOS2TIB();
-
-  return WinDefWindowProc( hwnd, msg, mp1, mp2 );
+  return PMFrameWindowProc(hwnd, msg, mp1, mp2);
+//  return WinDefWindowProc( hwnd, msg, mp1, mp2 );
 } /* End of Win32WindowProc */
 //******************************************************************************
+//TODO: Quickly moving a window two times doesn't force a repaint (1st time)
 //******************************************************************************
+VOID FrameTrackFrame(Win32BaseWindow *win32wnd,DWORD flags)
+{
+  TRACKINFO track;
+  RECTL     rcl;
+  PRECT     pWindowRect;
+  HWND      hwndTracking;
+  HPS       hpsTrack;
+  LONG      parentHeight, parentWidth;
+
+   track.cxBorder = 4;
+   track.cyBorder = 4;  /* 4 pel wide lines used for rectangle */
+   track.cxGrid = 1;
+   track.cyGrid = 1;    /* smooth tracking with mouse */
+   track.cxKeyboard = 8;
+   track.cyKeyboard = 8; /* faster tracking using cursor keys */
+
+   pWindowRect = win32wnd->getWindowRect();
+   if(win32wnd->getParent()) {
+	parentHeight = win32wnd->getParent()->getWindowHeight();
+	parentWidth  = win32wnd->getParent()->getWindowWidth();
+	hwndTracking = win32wnd->getParent()->getOS2WindowHandle();
+	hpsTrack     = WinGetPS(hwndTracking);	
+   }
+   else {
+	parentHeight = OSLibQueryScreenHeight();
+	parentWidth  = OSLibQueryScreenWidth();
+	hwndTracking = HWND_DESKTOP;
+	hpsTrack     = NULL;
+   }
+
+   rcl.xLeft   = pWindowRect->left;
+   rcl.yTop    = OSLibQueryScreenHeight() - pWindowRect->top;
+   rcl.xRight  = pWindowRect->right;
+   rcl.yBottom = OSLibQueryScreenHeight() - pWindowRect->bottom;
+   if(hwndTracking != HWND_DESKTOP) {
+   	WinMapWindowPoints(win32wnd->getOS2WindowHandle(), HWND_DESKTOP, (PPOINTL)&rcl, 2);
+   }
+   WinCopyRect(hab, &track.rclTrack, &rcl);   /* starting point */
+ 
+   WinSetRect(hab, &track.rclBoundary, 0, 0, parentWidth, parentHeight); /* bounding rectangle */
+ 
+   track.ptlMinTrackSize.x = 10;
+   track.ptlMinTrackSize.y = 10;  /* set smallest allowed size of rectangle */
+   track.ptlMaxTrackSize.x = parentWidth;
+   track.ptlMaxTrackSize.y = parentHeight; /* set largest allowed size of rectangle */
+
+   win32wnd->AdjustTrackInfo((PPOINT)&track.ptlMinTrackSize, (PPOINT)&track.ptlMaxTrackSize);
+ 
+   track.fs = flags;
+ 
+   if(WinTrackRect(HWND_DESKTOP, NULL, &track) )
+   {
+   	if(hpsTrack)	WinReleasePS(hpsTrack);
+
+     	/* if successful copy final position back */
+	if(!WinEqualRect(0, &rcl, &track.rclTrack)) {
+		if(flags == TF_MOVE) {
+			WinSetWindowPos(win32wnd->getOS2WindowHandle(), 
+                                        0, track.rclTrack.xLeft, track.rclTrack.yBottom, 
+                                        0, 0, SWP_MOVE);
+		}
+		else {
+			WinSetWindowPos(win32wnd->getOS2WindowHandle(), 
+                                        0, track.rclTrack.xLeft, track.rclTrack.yBottom, 
+                                        track.rclTrack.xRight - track.rclTrack.xLeft, 
+                                        track.rclTrack.yTop - track.rclTrack.yBottom, 
+                                        SWP_SIZE|SWP_MOVE);
+		}
+	}
+	return;
+   }
+   if(hpsTrack)	WinReleasePS(hpsTrack);
+   return;
+}
+//******************************************************************************
+//******************************************************************************
Index: trunk/src/user32/pmwindow.h
===================================================================
--- trunk/src/user32/pmwindow.h	(revision 3658)
+++ trunk/src/user32/pmwindow.h	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: pmwindow.h,v 1.8 2000-01-18 20:08:13 sandervl Exp $ */
+/* $Id: pmwindow.h,v 1.9 2000-06-07 14:51:27 sandervl Exp $ */
 /*
  * Win32 Window Managment Code for OS/2
@@ -9,11 +9,8 @@
 #define __PMWINDOW_H__
 
-#define WIN32_STDCLASS   "Win32WindowClass"
-#define WIN32_STDCLASS2  "Win32WindowClass2"
-#define WIN32_INNERFRAME "Win32InnerFrameClass"
+#define WIN32_STDCLASS      "Win32WindowClass"
+#define WIN32_STDFRAMECLASS "Win32FrameClass"
 
 BOOL InitPM();
-
-PVOID SubclassWithDefHandler(HWND hwnd);
 
 void RegisterSystemClasses(ULONG hModule);
Index: trunk/src/user32/unknown.cpp
===================================================================
--- trunk/src/user32/unknown.cpp	(revision 3658)
+++ trunk/src/user32/unknown.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: unknown.cpp,v 1.8 2000-02-16 14:34:38 sandervl Exp $ */
+/* $Id: unknown.cpp,v 1.9 2000-06-07 14:51:28 sandervl Exp $ */
 
 /*
@@ -180,17 +180,3 @@
 
 
-/***********************************************************************
- *           SetInternalWindowPos   (USER32.483)
- */
-void WIN32API SetInternalWindowPos(HWND    hwnd,
-                                   UINT    showCmd,
-                                   LPRECT  rect,
-                                   LPPOINT pt )
-{
-  dprintf(("USER32: SetInternalWindowPos(%08xh,%08xh,%08xh,%08xh) not implemented.\n",
-           hwnd,
-           showCmd,
-           rect,
-           pt));
-}
 
Index: trunk/src/user32/user32.cpp
===================================================================
--- trunk/src/user32/user32.cpp	(revision 3658)
+++ trunk/src/user32/user32.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: user32.cpp,v 1.82 2000-05-28 19:50:54 sandervl Exp $ */
+/* $Id: user32.cpp,v 1.83 2000-06-07 14:51:28 sandervl Exp $ */
 
 /*
@@ -1706,5 +1706,5 @@
 int WIN32API FillRect(HDC hDC, const RECT * lprc, HBRUSH hbr)
 {
-    dprintf2(("USER32:  FillRect (%d,%d)(%d,%d) brush %X\n", lprc->left, lprc->top, lprc->right, lprc->bottom, hbr));
+    dprintf(("USER32:  FillRect (%d,%d)(%d,%d) brush %X\n", lprc->left, lprc->top, lprc->right, lprc->bottom, hbr));
     return O32_FillRect(hDC,lprc,hbr);
 }
Index: trunk/src/user32/win32dlg.cpp
===================================================================
--- trunk/src/user32/win32dlg.cpp	(revision 3658)
+++ trunk/src/user32/win32dlg.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: win32dlg.cpp,v 1.49 2000-05-03 18:35:53 sandervl Exp $ */
+/* $Id: win32dlg.cpp,v 1.50 2000-06-07 14:51:29 sandervl Exp $ */
 /*
  * Win32 Dialog Code for OS/2
@@ -212,5 +212,5 @@
 //******************************************************************************
 //******************************************************************************
-ULONG Win32Dialog::MsgCreate(HWND hwndFrame, HWND hwndClient)
+ULONG Win32Dialog::MsgCreate(HWND hwndOS2)
 {
  CREATESTRUCTA  *cs = tmpcs;  //pointer to CREATESTRUCT used in CreateWindowExA method
@@ -218,5 +218,5 @@
  LPSTR  dlgTemplate = tmpDlgTemplate;
 
-    Win32BaseWindow::MsgCreate(hwndFrame, hwndClient);
+    Win32BaseWindow::MsgCreate(hwndOS2);
 
     if(!isUnicode) {
@@ -303,5 +303,5 @@
         topOwner->setModalDialogOwner(TRUE);
         hwndOldDialog = topOwner->getOS2HwndModalDialog();
-        topOwner->setOS2HwndModalDialog(OS2HwndFrame);
+        topOwner->setOS2HwndModalDialog(OS2Hwnd);
         ShowWindow(SW_SHOW);
 
Index: trunk/src/user32/win32dlg.h
===================================================================
--- trunk/src/user32/win32dlg.h	(revision 3658)
+++ trunk/src/user32/win32dlg.h	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: win32dlg.h,v 1.10 2000-01-18 20:08:16 sandervl Exp $ */
+/* $Id: win32dlg.h,v 1.11 2000-06-07 14:51:30 sandervl Exp $ */
 /*
  * Win32 Dialog Code for OS/2
@@ -73,5 +73,5 @@
          BOOL   MapDialogRect(LPRECT rect);
 
-virtual  ULONG  MsgCreate(HWND hwndFrame, HWND hwndClient);
+virtual  ULONG  MsgCreate(HWND hwndOS2);
 
 virtual	 LONG   SetWindowLongA(int index, ULONG value, BOOL fUnicode = FALSE);
Index: trunk/src/user32/win32wbase.cpp
===================================================================
--- trunk/src/user32/win32wbase.cpp	(revision 3658)
+++ trunk/src/user32/win32wbase.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: win32wbase.cpp,v 1.197 2000-06-01 11:27:57 sandervl Exp $ */
+/* $Id: win32wbase.cpp,v 1.198 2000-06-07 14:51:30 sandervl Exp $ */
 /*
  * Win32 Window Base Class for OS/2
@@ -15,5 +15,7 @@
  * TODO: Not thread/process safe
  *
- * NOTE: Client rectangle always relative to frame window; window rectangle in screen coordinates
+ * NOTE: Client rectangle always relative to frame window
+ *       Window rectangle in parent coordinates (relative to parent's client window)
+ *       (screen coord. if no parent)
  *
  * Project Odin Software License can be found in LICENSE.TXT
@@ -39,5 +41,4 @@
 #include "win32wndhandle.h"
 #include "dc.h"
-#include "pmframe.h"
 #include "win32wdesktop.h"
 #include "pmwindow.h"
@@ -104,5 +105,4 @@
   magic            = WIN32PM_MAGIC;
   OS2Hwnd          = 0;
-  OS2HwndFrame     = 0;
   hSysMenu         = 0;
   Win32Hwnd        = 0;
@@ -126,5 +126,4 @@
   hotkey           = 0;
 
-  pOldFrameProc = NULL;
 
   hwndLinkAfter    = HWND_BOTTOM;
@@ -156,4 +155,6 @@
   dwThreadId         = GetCurrentThreadId();
   dwProcessId        = currentProcessId;
+
+  memset(&windowpos, 0, sizeof(windowpos));
 }
 //******************************************************************************
@@ -166,5 +167,5 @@
     }
 
-    OSLibWinSetVisibleRegionNotify(OS2HwndFrame, FALSE);
+    OSLibWinSetVisibleRegionNotify(OS2Hwnd, FALSE);
     OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32WNDPTR, 0);
     OSLibWinSetWindowULong(OS2Hwnd, OFFSET_WIN32PM_MAGIC, 0);
@@ -412,4 +413,5 @@
 
   hwndLinkAfter = HWND_TOP;
+#if 1
   if(CONTROLS_IsControl(this, BUTTON_CONTROL) && ((dwStyle & 0x0f) == BS_GROUPBOX))
   {
@@ -418,4 +420,5 @@
   }
   else
+#endif
   if(CONTROLS_IsControl(this, STATIC_CONTROL) && !(dwStyle & WS_GROUP)) {
         dwStyle |= WS_CLIPSIBLINGS;
@@ -515,5 +518,5 @@
                                  (owner) ? owner->getOS2WindowHandle() : OSLIB_HWND_DESKTOP,
                                  (hwndLinkAfter == HWND_BOTTOM) ? TRUE : FALSE,
-                                 &OS2HwndFrame, 0, fTaskList,fXDefault | fCXDefault,windowClass->getStyle());
+                                 0, fTaskList,fXDefault | fCXDefault,windowClass->getStyle());
   if(OS2Hwnd == 0) {
         dprintf(("Window creation failed!!"));
@@ -521,5 +524,5 @@
         return FALSE;
   }
-  OSLibWinSetVisibleRegionNotify(OS2HwndFrame, TRUE);
+  OSLibWinSetVisibleRegionNotify(OS2Hwnd, TRUE);
   SetLastError(0);
   return TRUE;
@@ -527,11 +530,10 @@
 //******************************************************************************
 //******************************************************************************
-BOOL Win32BaseWindow::MsgCreate(HWND hwndFrame, HWND hwndClient)
+BOOL Win32BaseWindow::MsgCreate(HWND hwndOS2)
 {
  CREATESTRUCTA  *cs = tmpcs;  //pointer to CREATESTRUCT used in CreateWindowExA method
  POINT maxSize, maxPos, minTrack, maxTrack;
 
-  OS2Hwnd      = hwndClient;
-  OS2HwndFrame = hwndFrame;
+  OS2Hwnd      = hwndOS2;
 
   fNoSizeMsg = TRUE;
@@ -556,5 +558,5 @@
 
     //SvL: Returns invalid rectangle (not the expected shell default size)
-    OSLibWinQueryWindowRect(OS2HwndFrame,&rect,RELATIVE_TO_SCREEN);
+    OSLibWinQueryWindowRect(OS2Hwnd,&rect,RELATIVE_TO_SCREEN);
     if (getParent()) mapWin32Rect(OSLIB_HWND_DESKTOP,getParent()->getOS2WindowHandle(),&rect);
     if (fXDefault)
@@ -575,6 +577,4 @@
 #endif
 
-  OSLibWinSetOwner(OS2Hwnd, OS2HwndFrame);
-
   fakeWinBase.hwndThis     = OS2Hwnd;
   fakeWinBase.pWindowClass = windowClass;
@@ -582,16 +582,15 @@
   //Set icon from window or class
   if (hIcon)
-    OSLibWinSetIcon(OS2HwndFrame,hIcon);
+    OSLibWinSetIcon(OS2Hwnd,hIcon);
   else if (windowClass->getIcon())
-    OSLibWinSetIcon(OS2HwndFrame,windowClass->getIcon());
+    OSLibWinSetIcon(OS2Hwnd,windowClass->getIcon());
 
   /* Get class or window DC if needed */
   if(windowClass->getStyle() & CS_OWNDC) {
         dprintf(("Class with CS_OWNDC style"));
-        ownDC = GetDC(getWindowHandle()); //TODO: or GetWindowDC???
+        ownDC = GetDCEx(getWindowHandle(), NULL, DCX_USESTYLE);
   }
   else
   if (windowClass->getStyle() & CS_PARENTDC)  {
-        dprintf(("WARNING: Class with CS_PARENTDC style!"));
         fParentDC = TRUE;
         ownDC = 0;
@@ -624,7 +623,4 @@
   hSysMenu = (dwStyle & WS_SYSMENU) ? MENU_GetSysMenu(Win32Hwnd,0):0;
 
-  // Subclass frame
-  pOldFrameProc = FrameSubclassFrameWindow(this);
-
   /* Send the WM_GETMINMAXINFO message and fix the size if needed */
   if ((cs->style & WS_THICKFRAME) || !(cs->style & (WS_POPUP | WS_CHILD)))
@@ -656,5 +652,4 @@
   OffsetRect(&rectClient, -rectClient.left, -rectClient.top);
 
-  if (getParent()) mapWin32Rect(getParent()->getOS2WindowHandle(),OSLIB_HWND_DESKTOP,&rectWindow);
   /* Send the WM_CREATE message
    * Perhaps we shouldn't allow width/height changes as well.
@@ -667,5 +662,5 @@
 
   if(fTaskList) {
-  	hTaskList = OSLibWinAddToTaskList(OS2HwndFrame, windowNameA, (cs->style & WS_VISIBLE) ? 1 : 0);
+  	hTaskList = OSLibWinAddToTaskList(OS2Hwnd, windowNameA, (cs->style & WS_VISIBLE) ? 1 : 0);
   }
 
@@ -690,9 +685,8 @@
         rectWindow.bottom = cs->y+cs->cy;
         tmpRect = rectWindow;
-        if (getParent()) mapWin32Rect(getParent()->getOS2WindowHandle(),OSLIB_HWND_DESKTOP,&rectWindow);
-        OffsetRect(&rectWindow, maxPos.x - rectWindow.left, maxPos.y - rectWindow.top);
 
         rectClient = rectWindow;
         OffsetRect(&rectClient, -rectClient.left, -rectClient.top);
+        OffsetRect(&rectWindow, maxPos.x - rectWindow.left, maxPos.y - rectWindow.top);
 
         //set the window size and update the client
@@ -855,7 +849,7 @@
 ULONG Win32BaseWindow::MsgHitTest(MSG *msg)
 {
-  lastHitTestVal = DispatchMessageA(msg);
-
-  dprintf2(("MsgHitTest %x (%d,%d) (%d,%d) (%d,%d) returned %x", getWindowHandle(), LOWORD(msg->lParam), HIWORD(msg->lParam), rectWindow.left, rectWindow.right, rectWindow.top, rectWindow.bottom, lastHitTestVal));
+  lastHitTestVal = DispatchMsgA(msg);
+
+  dprintf2(("MsgHitTest %x (%d,%d) (%d,%d) (%d,%d) returned %x", getWindowHandle(), LOWORD(msg->lParam), HIWORD(msg->lParam), rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom, lastHitTestVal));
 
   if (lastHitTestVal == HTTRANSPARENT)
@@ -878,10 +872,9 @@
     //default processing is cancelled
     //TODO: According to Wine we should proceed anyway if window is sysmodal
-#if 0
     if(SendInternalMessageA(WM_NCACTIVATE, fActivate, 0) == FALSE && !fActivate)
     {
+	dprintf(("WARNING: WM_NCACTIVATE return code = FALSE -> cancel processing"));
         return 0;
     }
-#endif
     /* child windows get WM_CHILDACTIVATE message */
     if((getStyle() & (WS_CHILD | WS_POPUP)) == WS_CHILD )
@@ -995,5 +988,5 @@
 
                     //SvL: Calling OSLibSetActiveWindow(hwndTop); causes focus problems
-                    if (win32top) OSLibWinSetFocus(win32top->getOS2FrameWindowHandle());
+                    if (win32top) OSLibWinSetFocus(win32top->getOS2WindowHandle());
                 }
         }
@@ -1023,5 +1016,5 @@
 
     if (hdcErase == 0)
-        hdcErase = O32_GetDC(OS2Hwnd);
+        hdcErase = GetDC(getWindowHandle());
 
     if(IsWindowIconic())
@@ -1030,5 +1023,5 @@
         rc = SendInternalMessageA(WM_ERASEBKGND, hdcErase, 0);
     if (hdc == 0)
-        O32_ReleaseDC(OS2Hwnd, hdcErase);
+        ReleaseDC(getWindowHandle(), hdcErase);
     return (rc);
 }
@@ -1055,5 +1048,5 @@
   RECT rect;
 
-  if (GetOS2UpdateRect(OS2HwndFrame,&rect))
+  if(GetOS2UpdateRect(this,&rect))
   {
     HRGN hrgn;
@@ -1073,5 +1066,5 @@
         if (!hrgn) return 0;
 
-        rc = SendInternalMessageA(WM_NCPAINT,hrgn,0);
+        rc = SendInternalMessageA(WM_NCPAINT, hrgn, 0);
 
         DeleteObject(hrgn);
@@ -1093,31 +1086,19 @@
   if(lpWndPos)
   {
-    POINT point;
-
-    //set new window rectangle
-    point.x = lpWndPos->x;
-    point.y = lpWndPos->y;
-    if (getParent()) ClientToScreen(getParent()->getWindowHandle(),&point);
-
-    setWindowRect(point.x,point.y,point.x+lpWndPos->cx,point.y+lpWndPos->cy);
-    newWindowRect = rectWindow;
+    	//set new window rectangle
+    	setWindowRect(lpWndPos->x, lpWndPos->y, lpWndPos->x+lpWndPos->cx,
+                      lpWndPos->y+lpWndPos->cy);
+    	newWindowRect = rectWindow;
   }
   else {
-    wndPos.hwnd  = getWindowHandle();
-    wndPos.hwndInsertAfter = 0;
-    newWindowRect= rectWindow;
-    if (getParent()) {
-        mapWin32Rect(OSLIB_HWND_DESKTOP,getParent()->getOS2WindowHandle(),&newWindowRect);
-    }
-    wndPos.x     = newWindowRect.left;
-    wndPos.y     = newWindowRect.top;
-    wndPos.cx    = newWindowRect.right - newWindowRect.left;
-    wndPos.cy    = newWindowRect.bottom - newWindowRect.top;
-    wndPos.flags = SWP_FRAMECHANGED;
-    lpWndPos     = &wndPos;
-
-    if (getParent()) {
-        newWindowRect= rectWindow; //reset; was modified
-    }
+    	wndPos.hwnd  = getWindowHandle();
+    	wndPos.hwndInsertAfter = 0;
+    	newWindowRect= rectWindow;
+    	wndPos.x     = newWindowRect.left;
+    	wndPos.y     = newWindowRect.top;
+    	wndPos.cx    = newWindowRect.right - newWindowRect.left;
+    	wndPos.cy    = newWindowRect.bottom - newWindowRect.top;
+    	wndPos.flags = SWP_FRAMECHANGED;
+    	lpWndPos     = &wndPos;
   }
 
@@ -1125,4 +1106,5 @@
 
   dprintf(("MsgFormatFrame: old client rect (%d,%d)(%d,%d), new client (%d,%d)(%d,%d)", client.left, client.top, client.right, client.bottom, rectClient.left, rectClient.top, rectClient.right, rectClient.bottom));
+  dprintf(("MsgFormatFrame: old window rect (%d,%d)(%d,%d), new window (%d,%d)(%d,%d)", oldWindowRect.left, oldWindowRect.top, oldWindowRect.right, oldWindowRect.bottom, rectWindow.left, rectWindow.top, rectWindow.right, rectWindow.bottom));
   return rc;
 }
@@ -1169,6 +1151,5 @@
 BOOL Win32BaseWindow::isFrameWindow()
 {
-//    if(isMDIChild() || IsDialog() || (getParent() == NULL || getParent() == windowDesktop) && ((dwStyle & WS_CAPTION) == WS_CAPTION))
-    if((dwStyle & WS_CAPTION) == WS_CAPTION || dwStyle & (WS_VSCROLL|WS_HSCROLL))
+    if(getParent() == NULL)
         return TRUE;
 
@@ -1343,5 +1324,5 @@
           HandleNCPaint((HRGN)1);
           if(hTaskList) {
-		OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
+		OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
 	  }
         }
@@ -1355,5 +1336,5 @@
       {
         setStyle(getStyle() | WS_VISIBLE);
-        OSLibWinEnableWindowUpdate(OS2HwndFrame,TRUE);
+        OSLibWinEnableWindowUpdate(OS2Hwnd,TRUE);
       }
       else
@@ -1362,5 +1343,5 @@
         {
           setStyle(getStyle() & ~WS_VISIBLE);
-          OSLibWinEnableWindowUpdate(OS2HwndFrame,FALSE);
+          OSLibWinEnableWindowUpdate(OS2Hwnd,FALSE);
         }
       }
@@ -1742,5 +1723,5 @@
               hIcon = (HICON)lParam;
               if ((dwStyle & WS_CAPTION) == WS_CAPTION)
-                OSLibWinSetIcon(OS2HwndFrame,hIcon);
+                OSLibWinSetIcon(OS2Hwnd,hIcon);
             }
           }
@@ -1803,5 +1784,5 @@
           HandleNCPaint((HRGN)1);
           if(hTaskList) {
-		OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
+		OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
 	  }
         }
@@ -1868,11 +1849,11 @@
                 if (getParent())
                 {
-                  POINTS pt = MAKEPOINTS(lParam);
-                  POINT point;
-
-                  point.x = pt.x;
-                  point.y = pt.y;
-                  mapWin32Point(OS2Hwnd,getParent()->getOS2WindowHandle(),(OSLIBPOINT*)&point);
-                  NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y));
+                  	POINTS pt = MAKEPOINTS(lParam);
+                  	POINT point;
+
+                  	point.x = pt.x;
+                  	point.y = pt.y;
+			MapWindowPoints(getWindowHandle(), getParent()->getWindowHandle(), &point, 1);
+                  	NotifyParent(Msg,wParam,MAKELPARAM(point.x,point.y));
                 }
                 rc = win32wndproc(getWindowHandle(), Msg, wParam, lParam);
@@ -2057,79 +2038,84 @@
 BOOL Win32BaseWindow::ShowWindow(ULONG nCmdShow)
 {
- ULONG showstate = 0;
+ ULONG swp = 0;
  HWND  hWinAfter;
  BOOL  rc,wasVisible,showFlag;
+ RECT  newPos = {0, 0, 0, 0};
 
     dprintf(("ShowWindow %x %x", getWindowHandle(), nCmdShow));
 
+    wasVisible = (getStyle() & WS_VISIBLE) != 0;
+
     switch(nCmdShow)
     {
-    case SW_SHOW:
-    case SW_SHOWDEFAULT: //todo
-        showstate = SWPOS_SHOW | SWPOS_ACTIVATE;
-        break;
-    case SW_HIDE:
-        if (!wasVisible) return wasVisible;
-         if(GetCapture() == getWindowHandle() || IsChild(GetCapture()))
-           ReleaseCapture();
-
-        showstate = SWPOS_HIDE;
-        break;
-    case SW_RESTORE:
-        showstate = SWPOS_RESTORE | SWPOS_SHOW | SWPOS_ACTIVATE;
-        break;
-    case SW_MINIMIZE:
-        showstate = SWPOS_MINIMIZE;
-        break;
-    case SW_SHOWMAXIMIZED:
-        showstate = SWPOS_MAXIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
-        break;
-    case SW_SHOWMINIMIZED:
-        showstate = SWPOS_MINIMIZE | SWPOS_SHOW | SWPOS_ACTIVATE;
-        break;
-    case SW_SHOWMINNOACTIVE:
-        showstate = SWPOS_MINIMIZE | SWPOS_SHOW;
-        break;
-    case SW_SHOWNA:
-        showstate = SWPOS_SHOW;
-        break;
-    case SW_SHOWNOACTIVATE:
-        showstate = SWPOS_SHOW;
-        break;
-    case SW_SHOWNORMAL:
-        showstate = SWPOS_RESTORE | SWPOS_ACTIVATE | SWPOS_SHOW;
-        break;
-    }
-
-    /* We can't activate a child window (WINE) */
+        case SW_HIDE:
+            if (!wasVisible) goto END;
+	    swp |= SWP_HIDEWINDOW | SWP_NOSIZE | SWP_NOMOVE | 
+   	           SWP_NOACTIVATE | SWP_NOZORDER;
+	    break;
+
+	case SW_SHOWMINNOACTIVE:
+            swp |= SWP_NOACTIVATE | SWP_NOZORDER;
+            /* fall through */
+	case SW_SHOWMINIMIZED:
+            swp |= SWP_SHOWWINDOW;
+            /* fall through */
+	case SW_MINIMIZE:
+            swp |= SWP_FRAMECHANGED;
+            if( !(getStyle() & WS_MINIMIZE) )
+		 swp |= MinMaximize(SW_MINIMIZE, &newPos );
+            else swp |= SWP_NOSIZE | SWP_NOMOVE;
+	    break;
+
+	case SW_SHOWMAXIMIZED: /* same as SW_MAXIMIZE */
+            swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
+            if( !(getStyle() & WS_MAXIMIZE) )
+		 swp |= MinMaximize(SW_MAXIMIZE, &newPos );
+            else swp |= SWP_NOSIZE | SWP_NOMOVE;
+            break;
+
+	case SW_SHOWNA:
+            swp |= SWP_NOACTIVATE | SWP_NOZORDER;
+            /* fall through */
+	case SW_SHOW:
+	    swp |= SWP_SHOWWINDOW | SWP_NOSIZE | SWP_NOMOVE;
+
+	    /*
+	     * ShowWindow has a little peculiar behavior that if the
+	     * window is already the topmost window, it will not
+	     * activate it.
+	     */
+	    if (::GetTopWindow((HWND)0)==getWindowHandle() && (wasVisible || GetActiveWindow() == getWindowHandle()))
+	      swp |= SWP_NOACTIVATE;
+
+	    break;
+
+	case SW_SHOWNOACTIVATE:
+            swp |= SWP_NOZORDER;
+            if (GetActiveWindow()) swp |= SWP_NOACTIVATE;
+            /* fall through */
+	case SW_SHOWNORMAL:  /* same as SW_NORMAL: */
+	case SW_SHOWDEFAULT: /* FIXME: should have its own handler */
+	case SW_RESTORE:
+	    swp |= SWP_SHOWWINDOW | SWP_FRAMECHANGED;
+
+            if( getStyle() & (WS_MINIMIZE | WS_MAXIMIZE) )
+		 swp |= MinMaximize(SW_RESTORE, &newPos );
+            else swp |= SWP_NOSIZE | SWP_NOMOVE;
+	    break;
+    }
+
+    showFlag = (nCmdShow != SW_HIDE);
+    if (showFlag != wasVisible)
+    {
+        SendInternalMessageA(WM_SHOWWINDOW, showFlag, 0 );
+        if (!::IsWindow( getWindowHandle() )) goto END;
+    }
+
+    /* We can't activate a child window */
     if((getStyle() & WS_CHILD) && !(getExStyle() & WS_EX_MDICHILD))
-        showstate &= ~SWPOS_ACTIVATE;
-
-    if(showstate & SWPOS_SHOW) {
-         setStyle(getStyle() | WS_VISIBLE);
-	 if(hTaskList) {
-		OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
-	 }
-    }
-    else {
-	if(hTaskList) {
-		OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
-	}
-	setStyle(getStyle() & ~WS_VISIBLE);
-    }
-    showFlag = (nCmdShow != SW_HIDE);
-
-    rc = OSLibWinShowWindow(OS2HwndFrame, showstate);
-    OSLibWinShowWindow(OS2Hwnd, showstate);
-
-    SendInternalMessageA(WM_SHOWWINDOW, (showstate & SWPOS_SHOW) ? 1 : 0, 0);
-
-    //CB: PMFrame: WM_MINMAXFRAME SWP_* handling isn't always successful!
-    if ((showstate & SWPOS_MAXIMIZE) == SWPOS_MAXIMIZE)
-      setStyle((getStyle() & ~WS_MINIMIZE) | WS_MAXIMIZE);
-    else if ((showstate & SWPOS_MINIMIZE) == SWPOS_MINIMIZE)
-      setStyle((getStyle() & ~WS_MAXIMIZE) | WS_MINIMIZE);
-    else if ((showstate & SWPOS_RESTORE) == SWPOS_RESTORE)
-      setStyle(getStyle() & ~(WS_MINIMIZE | WS_MAXIMIZE));
+        swp |= SWP_NOACTIVATE | SWP_NOZORDER;
+
+    SetWindowPos(HWND_TOP, newPos.left, newPos.top, newPos.right, newPos.bottom, LOWORD(swp));
 
     if (flags & WIN_NEED_SIZE)
@@ -2150,6 +2136,6 @@
         SendInternalMessageA(WM_MOVE,0,MAKELONG(rectClient.left,rectClient.top));
     }
-
-    return rc;
+END:
+    return wasVisible;
 }
 //******************************************************************************
@@ -2160,4 +2146,5 @@
    Win32BaseWindow *window;
    HWND hParent = 0;
+   RECT oldClientRect = rectClient;
 
     if (fuFlags &
@@ -2224,20 +2211,27 @@
     if(~fuFlags & (SWP_NOMOVE | SWP_NOSIZE))
     {
-       if (isChild())
-       {
-            Win32BaseWindow *windowParent = getParent();
-            if(windowParent) {
-                hParent = getParent()->getOS2WindowHandle();
-        }
-        else    dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
-       }
-       OSLibWinQueryWindowPos(OS2HwndFrame, &swpOld);
-    }
-
-    OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, hParent, OS2HwndFrame);
+        if (isChild())
+        {
+            if(!getParent()) {
+		dprintf(("WARNING: Win32BaseWindow::SetWindowPos window %x is child but has no parent!!", getWindowHandle()));
+            }
+        }
+        OSLibWinQueryWindowPos(OS2Hwnd, &swpOld);
+    }
+
+    if(getParent()) {
+          OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, getParent()->getWindowHeight(),
+                                 getParent()->getClientRectPtr()->left,
+                                 getParent()->getClientRectPtr()->top,
+                                 OS2Hwnd);
+    } 
+    else  OSLibMapWINDOWPOStoSWP(&wpos, &swp, &swpOld, OSLibQueryScreenHeight(), 0, 0, OS2Hwnd);
     if (swp.fl == 0) {
-        if (fuFlags & SWP_FRAMECHANGED)
-        {
-            FrameUpdateClient(this);
+        if(fuFlags & SWP_FRAMECHANGED)
+        {            
+        	MsgFormatFrame(NULL);
+		UnionRect(&oldClientRect, &oldClientRect, &rectClient);
+		InvalidateRect(getWindowHandle(), &oldClientRect, TRUE);
+//TODO: move child windows!!
         }
         return TRUE;
@@ -2249,5 +2243,5 @@
         Win32BaseWindow *wndBehind = Win32BaseWindow::GetWindowFromHandle(swp.hwndInsertBehind);
         if(wndBehind) {
-            swp.hwndInsertBehind   = wndBehind->getOS2FrameWindowHandle();
+            swp.hwndInsertBehind   = wndBehind->getOS2WindowHandle();
         }
         else {
@@ -2256,14 +2250,13 @@
         }
     }
-    swp.hwnd = OS2HwndFrame;
+    swp.hwnd = OS2Hwnd;
 
     dprintf (("WinSetWindowPos %x %x (%d,%d)(%d,%d) %x", swp.hwnd, swp.hwndInsertBehind, swp.x, swp.y, swp.cx, swp.cy, swp.fl));
+    rc = OSLibWinSetMultWindowPos(&swp, 1);
 
     if(fuFlags & SWP_SHOWWINDOW && !IsWindowVisible()) {
         setStyle(getStyle() | WS_VISIBLE);
-        //SvL: TODO: Send WM_SHOWWINDOW??
-        OSLibWinShowWindow(OS2Hwnd, SWPOS_SHOW);
 	if(hTaskList) {
-		OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
+		OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
 	}
     }
@@ -2271,11 +2264,8 @@
     if(fuFlags & SWP_HIDEWINDOW && IsWindowVisible()) {
         setStyle(getStyle() & ~WS_VISIBLE);
-        //SvL: TODO: Send WM_SHOWWINDOW??
-        OSLibWinShowWindow(OS2Hwnd, SWPOS_HIDE);
 	if(hTaskList) {
-		OSLibWinChangeTaskList(hTaskList, OS2HwndFrame, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
+		OSLibWinChangeTaskList(hTaskList, OS2Hwnd, getWindowNameA(), (getStyle() & WS_VISIBLE) ? 1 : 0);
 	}
     }
-    rc = OSLibWinSetMultWindowPos(&swp, 1);
 
     if(rc == FALSE)
@@ -2287,28 +2277,67 @@
     if((fuFlags & SWP_FRAMECHANGED) && (fuFlags & (SWP_NOMOVE | SWP_NOSIZE) == (SWP_NOMOVE | SWP_NOSIZE)))
     {
-        FrameUpdateClient(this);
+	UnionRect(&oldClientRect, &oldClientRect, &rectClient);
+	InvalidateRect(getWindowHandle(), &oldClientRect, TRUE);
+//TODO: move child windows!!
     }
     return (rc);
 }
 //******************************************************************************
-//TODO: WPF_RESTOREMAXIMIZED
-//******************************************************************************
-BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *winpos)
-{
-   if(isFrameWindow())
+//******************************************************************************
+BOOL Win32BaseWindow::SetWindowPlacement(WINDOWPLACEMENT *wndpl)
+{
+   windowpos.ptMinPosition    = wndpl->ptMinPosition;
+   windowpos.ptMaxPosition    = wndpl->ptMaxPosition;
+   windowpos.rcNormalPosition = wndpl->rcNormalPosition;
+
+   if(getStyle() & WS_MINIMIZE )
    {
-      // Set the minimized position
-      if (winpos->flags & WPF_SETMINPOSITION)
-      {
-         OSLibSetWindowMinPos(OS2HwndFrame, winpos->ptMinPosition.x, winpos->ptMinPosition.y);
-      }
-
-      //TODO: Max position
-
-      // Set the new restore position.
-      OSLibSetWindowRestoreRect(OS2HwndFrame, &winpos->rcNormalPosition);
+	//TODO: Why can't this be (0,0)?
+	if(wndpl->flags & WPF_SETMINPOSITION && !(!windowpos.ptMinPosition.x && !windowpos.ptMinPosition.y)) {
+		SetWindowPos(0, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
+		     	     0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
+	} 
    }
-
-   return ShowWindow(winpos->showCmd);
+   else
+   if(getStyle() & WS_MAXIMIZE )
+   {
+	//TODO: Why can't this be (0,0)?
+    	if(windowpos.ptMaxPosition.x != 0 || windowpos.ptMaxPosition.y != 0 )
+		SetWindowPos(0, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
+              	             0, 0, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
+   }
+   else {
+    	SetWindowPos(0, windowpos.rcNormalPosition.left, windowpos.rcNormalPosition.top,
+		     windowpos.rcNormalPosition.right - windowpos.rcNormalPosition.left,
+		     windowpos.rcNormalPosition.bottom - windowpos.rcNormalPosition.top,
+		     SWP_NOZORDER | SWP_NOACTIVATE );
+   }
+   ShowWindow(wndpl->showCmd);
+   if( ::IsWindow(getWindowHandle()) && getStyle() & WS_MINIMIZE )
+   {
+    	/* SDK: ...valid only the next time... */
+    	if(wndpl->flags & WPF_RESTORETOMAXIMIZED) 
+		setFlags(getFlags() | WIN_RESTORE_MAX);
+   }
+   return TRUE;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL Win32BaseWindow::GetWindowPlacement(LPWINDOWPLACEMENT wndpl)
+{
+   wndpl->length  = sizeof(*wndpl);
+   if(getStyle() & WS_MINIMIZE )
+   	wndpl->showCmd = SW_SHOWMINIMIZED;
+   else wndpl->showCmd = (getStyle() & WS_MAXIMIZE) ? SW_SHOWMAXIMIZED : SW_SHOWNORMAL;
+
+   if(getFlags() & WIN_RESTORE_MAX )
+        wndpl->flags = WPF_RESTORETOMAXIMIZED;
+   else wndpl->flags = 0;
+
+   wndpl->ptMinPosition    = windowpos.ptMinPosition;
+   wndpl->ptMaxPosition    = windowpos.ptMaxPosition;
+   wndpl->rcNormalPosition = windowpos.rcNormalPosition;
+
+   return TRUE;
 }
 //******************************************************************************
@@ -2360,5 +2389,5 @@
 
     fDestroyWindowCalled = TRUE;
-    return OSLibWinDestroyWindow(OS2HwndFrame);
+    return OSLibWinDestroyWindow(OS2Hwnd);
 }
 //******************************************************************************
@@ -2373,13 +2402,12 @@
 HWND Win32BaseWindow::GetParent()
 {
- Win32BaseWindow *wndparent;
-
-    if ((!(getStyle() & (WS_POPUP|WS_CHILD))))
-    {
-        return 0;
-    }
-    wndparent = ((getStyle() & WS_CHILD) ? getParent() : getOwner());
-
-    return (wndparent) ? wndparent->getWindowHandle() : 0;
+  if(getStyle() & WS_CHILD) {
+	if(getParent()) {
+		return getParent()->getWindowHandle();
+	}
+	DebugInt3();
+	return 0;
+  }
+  else 	return (getOwner()) ? getOwner()->getWindowHandle() : 0;
 }
 //******************************************************************************
@@ -2390,4 +2418,5 @@
  Win32BaseWindow *newparent;
  Win32BaseWindow *oldparent = (Win32BaseWindow *)ChildWindow::GetParent();
+ BOOL fShow = FALSE;
 
    if(oldparent) {
@@ -2397,4 +2426,11 @@
    else oldhwnd = 0;
 
+   /* Windows hides the window first, then shows it again
+    * including the WM_SHOWWINDOW messages and all */
+   if(fCreated && (getStyle() & WS_VISIBLE)) {
+      	ShowWindow(SW_HIDE);
+	fShow = TRUE;
+   }
+
    newparent = GetWindowFromHandle(hwndNewParent);
    if(newparent)
@@ -2402,13 +2438,23 @@
         setParent(newparent);
         getParent()->AddChild(this);
-        OSLibWinSetParent(getOS2FrameWindowHandle(), getParent()->getOS2WindowHandle());
-        return oldhwnd;
+        OSLibWinSetParent(getOS2WindowHandle(), getParent()->getOS2WindowHandle());
    }
    else {
         setParent(windowDesktop);
         windowDesktop->AddChild(this);
-        OSLibWinSetParent(getOS2FrameWindowHandle(), OSLIB_HWND_DESKTOP);
-        return oldhwnd;
+        OSLibWinSetParent(getOS2WindowHandle(), OSLIB_HWND_DESKTOP);
    }
+   /* SetParent additionally needs to make hwndChild the topmost window
+      in the x-order and send the expected WM_WINDOWPOSCHANGING and
+      WM_WINDOWPOSCHANGED notification messages. 
+   */
+   if(fCreated) {
+   	SetWindowPos(HWND_TOPMOST, 0, 0, 0, 0,
+        	     SWP_NOMOVE|SWP_NOSIZE|(fShow? SWP_SHOWWINDOW : 0));
+
+   /* FIXME: a WM_MOVE is also generated (in the DefWindowProc handler
+    * for WM_WINDOWPOSCHANGED) in Windows, should probably remove SWP_NOMOVE */
+   }
+   return oldhwnd;
 }
 //******************************************************************************
@@ -2601,5 +2647,4 @@
                 hwnd = OSLibWinQueryClientWindow(hwnd);
                 if(hwnd)  wnd = GetWindowFromOS2Handle(hwnd);
-                if(!hwnd) wnd = GetWindowFromOS2FrameHandle(hwnd);
             }
 
@@ -2703,6 +2748,6 @@
 
     dprintf(("SetActiveWindow %x", getWindowHandle()));
-    if(OSLibWinSetActiveWindow(OS2HwndFrame) == FALSE) {
-        dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2HwndFrame));
+    if(OSLibWinSetActiveWindow(OS2Hwnd) == FALSE) {
+        dprintf(("OSLibWinSetActiveWindow %x returned FALSE!", OS2Hwnd));
     }
     hwndActive = GetActiveWindow();
@@ -2721,5 +2766,5 @@
         SendMessageA(WM_CANCELMODE, 0, 0);
   }
-  OSLibWinEnableWindow(OS2HwndFrame, fEnable);
+  OSLibWinEnableWindow(OS2Hwnd, fEnable);
   if(fEnable == FALSE) {
         //SvL: No need to clear focus as PM already does this
@@ -2735,5 +2780,5 @@
 BOOL Win32BaseWindow::CloseWindow()
 {
-  return OSLibWinMinimizeWindow(OS2HwndFrame);
+  return OSLibWinMinimizeWindow(OS2Hwnd);
 }
 //******************************************************************************
@@ -2756,5 +2801,5 @@
 BOOL Win32BaseWindow::IsWindowEnabled()
 {
-    return OSLibWinIsWindowEnabled(OS2HwndFrame);
+    return OSLibWinIsWindowEnabled(OS2Hwnd);
 }
 //******************************************************************************
@@ -2762,8 +2807,9 @@
 BOOL Win32BaseWindow::IsWindowVisible()
 {
+    //TODO: Do we have to check the state of the parent window? (as Wine does)
 #if 1
     return (dwStyle & WS_VISIBLE) == WS_VISIBLE;
 #else
-    return OSLibWinIsWindowVisible(OS2HwndFrame);
+    return OSLibWinIsWindowVisible(OS2Hwnd);
 #endif
 }
@@ -2900,5 +2946,5 @@
                 setStyle(ss.styleNew);
                 SendInternalMessageA(WM_STYLECHANGED,GWL_STYLE,(LPARAM)&ss);
-////                OSLibSetWindowStyle(getOS2FrameWindowHandle(), getStyle(), getExStyle(),
+////                OSLibSetWindowStyle(getOS2WindowHandle(), getStyle(), getExStyle(),
 ////                                    windowClass->getStyle() & CS_SAVEBITS);
 #ifdef DEBUG
@@ -2961,8 +3007,5 @@
         break;
     case GWL_HWNDPARENT:
-        if(getParent()) {
-            value = getParent()->getWindowHandle();
-        }
-        else value = 0;
+	value = GetParent();
         break;
     case GWL_ID:
@@ -3029,6 +3072,4 @@
 }
 //******************************************************************************
-//Note: Should return NULL if window is frame window! (IsOS2FrameWindowHandle depends on this
-//      behaviour)
 //******************************************************************************
 Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2Handle(HWND hwnd)
@@ -3053,10 +3094,4 @@
 //******************************************************************************
 //******************************************************************************
-Win32BaseWindow *Win32BaseWindow::GetWindowFromOS2FrameHandle(HWND hwnd)
-{
-    return GetWindowFromOS2Handle(OSLibWinWindowFromID(hwnd,OSLIB_FID_CLIENT));
-}
-//******************************************************************************
-//******************************************************************************
 HWND Win32BaseWindow::Win32ToOS2Handle(HWND hwnd)
 {
@@ -3071,24 +3106,8 @@
 //******************************************************************************
 //******************************************************************************
-HWND Win32BaseWindow::Win32ToOS2FrameHandle(HWND hwnd)
-{
-    Win32BaseWindow *window = GetWindowFromHandle(hwnd);
-
-    if(window) {
-            return window->getOS2FrameWindowHandle();
-    }
-//    dprintf2(("Win32BaseWindow::Win32ToOS2FrameHandle: not a win32 window %x", hwnd));
-    return hwnd;
-}
-//******************************************************************************
-//******************************************************************************
 HWND Win32BaseWindow::OS2ToWin32Handle(HWND hwnd)
 {
     Win32BaseWindow *window = GetWindowFromOS2Handle(hwnd);
 
-    if(window) {
-            return window->getWindowHandle();
-    }
-    window = GetWindowFromOS2FrameHandle(hwnd);
     if(window) {
             return window->getWindowHandle();
@@ -3099,16 +3118,4 @@
 }
 //******************************************************************************
-//******************************************************************************
-BOOL Win32BaseWindow::IsOS2FrameWindowHandle(HWND hwndWin32, HWND hwndOS2)
-{
- Win32BaseWindow *window = GetWindowFromHandle(hwndWin32);
-
-    if(window->getOS2FrameWindowHandle() == hwndOS2) {
-        return TRUE;
-    }
-    return FALSE;
-}
-//******************************************************************************
-// GetNextDlgTabItem32   (USER32.276)
 //******************************************************************************
 HWND Win32BaseWindow::getNextDlgTabItem(HWND hwndCtrl, BOOL fPrevious)
Index: trunk/src/user32/win32wbase.h
===================================================================
--- trunk/src/user32/win32wbase.h	(revision 3658)
+++ trunk/src/user32/win32wbase.h	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: win32wbase.h,v 1.96 2000-05-26 18:43:35 sandervl Exp $ */
+/* $Id: win32wbase.h,v 1.97 2000-06-07 14:51:31 sandervl Exp $ */
 /*
  * Win32 Window Base Class for OS/2
@@ -104,5 +104,5 @@
 virtual        ~Win32BaseWindow();
 
-virtual  ULONG  MsgCreate(HWND hwndFrame, HWND hwndClient);
+virtual  ULONG  MsgCreate(HWND hwndOS2);
          ULONG  MsgQuit();
          ULONG  MsgClose();
@@ -145,5 +145,4 @@
          HWND   getWindowHandle()               { return Win32Hwnd; };
          HWND   getOS2WindowHandle()            { return OS2Hwnd; };
-         HWND   getOS2FrameWindowHandle()       { return OS2HwndFrame; };
  Win32WndClass *getWindowClass()                { return windowClass; };
 
@@ -212,4 +211,5 @@
          BOOL   SetWindowPos(HWND hwndInsertAfter, int x, int y, int cx, int cy, UINT fuFlags);
          BOOL   SetWindowPlacement(WINDOWPLACEMENT *winpos);
+         BOOL   GetWindowPlacement(LPWINDOWPLACEMENT winpos);
          BOOL   DestroyWindow();
          HWND   SetActiveWindow();
@@ -297,19 +297,10 @@
 
     static HWND Win32ToOS2Handle(HWND hwnd);
-    static HWND Win32ToOS2FrameHandle(HWND hwnd);
     static HWND OS2ToWin32Handle(HWND hwnd);
-    static BOOL IsOS2FrameWindowHandle(HWND hwndWin32, HWND hwndOS2);
 
 static Win32BaseWindow *GetWindowFromHandle(HWND hwnd);
 static Win32BaseWindow *GetWindowFromOS2Handle(HWND hwnd);
-static Win32BaseWindow *GetWindowFromOS2FrameHandle(HWND hwnd);
 
     static void DestroyAll();
-
-       PVOID getOldFrameProc() { return pOldFrameProc; };
-       VOID  setOldFrameProc(PVOID aOldFrameProc) { pOldFrameProc = aOldFrameProc; };
-
-       PVOID getOldWndProc() { return pOldWndProc; }
-       VOID  setOldWndProc(PVOID aOldWndProc) { pOldWndProc = aOldWndProc; }
 
 protected:
@@ -326,5 +317,4 @@
 
         HWND    OS2Hwnd;
-        HWND    OS2HwndFrame;
         HMENU   hSysMenu;
         HWND    Win32Hwnd;
@@ -371,7 +361,4 @@
         DWORD   dwThreadId;             //id of thread that created this window
         DWORD   dwProcessId;            //id of process that created this window
-        PVOID   pOldFrameProc;
-
-        PVOID   pOldWndProc;
 
    Win32BaseWindow *owner;
@@ -385,6 +372,7 @@
         ULONG   nrUserWindowLong;
 
-        RECT    rectWindow; //relative to screen
-        RECT    rectClient;  //relative to parent
+        RECT    rectWindow; //relative to parent
+        RECT    rectClient;  //relative to frame
+WINDOWPLACEMENT windowpos;
 
     PROPERTY   *propertyList;
@@ -405,4 +393,5 @@
 #ifndef OS2_INCLUDED
         void  GetMinMaxInfo(POINT *maxSize, POINT *maxPos, POINT *minTrack, POINT *maxTrack );
+        UINT  MinMaximize(UINT cmd, LPRECT lpRect);
         LONG  HandleWindowPosChanging(WINDOWPOS *winpos);
         LONG  HandleNCActivate(WPARAM wParam);
Index: trunk/src/user32/win32wbasenonclient.cpp
===================================================================
--- trunk/src/user32/win32wbasenonclient.cpp	(revision 3658)
+++ trunk/src/user32/win32wbasenonclient.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: win32wbasenonclient.cpp,v 1.23 2000-05-28 16:43:47 sandervl Exp $ */
+/* $Id: win32wbasenonclient.cpp,v 1.24 2000-06-07 14:51:32 sandervl Exp $ */
 /*
  * Win32 Window Base Class for OS/2 (non-client methods)
@@ -211,7 +211,9 @@
   }
 
-  pt.x -= rectWindow.left;
-  pt.y -= rectWindow.top;
-  SCROLL_HandleScrollEvent(Win32Hwnd,0,MAKELONG(pt.x,pt.y),scrollbar,WM_LBUTTONDOWN);
+  ScreenToClient(getWindowHandle(), &pt);
+  pt.x += rectClient.left;
+  pt.y += rectClient.top;
+
+  SCROLL_HandleScrollEvent(getWindowHandle(),0,MAKELONG(pt.x,pt.y),scrollbar,WM_LBUTTONDOWN);
   if (GetCapture() != Win32Hwnd) return;
   do
@@ -224,6 +226,9 @@
         case WM_LBUTTONUP:
         case WM_MOUSEMOVE:
-            pt.x = msg.pt.x-rectWindow.left;
-            pt.y = msg.pt.y-rectWindow.top;
+            pt.x = msg.pt.x;
+            pt.y = msg.pt.y;
+            ScreenToClient(getWindowHandle(), &pt);
+  	    pt.x += rectClient.left;
+  	    pt.y += rectClient.top;
             msg.lParam = MAKELONG(pt.x,pt.y);
 
@@ -262,9 +267,11 @@
         {
             //SvL: Calling topparent->SetActiveWindow() causes focus problems
-            OSLibWinSetFocus(topparent->getOS2FrameWindowHandle());
+//	    topparent->SetActiveWindow();
+            OSLibWinSetFocus(topparent->getOS2WindowHandle());
         }
 
         if (GetActiveWindow() == topparent->getWindowHandle())
             SendInternalMessageA(WM_SYSCOMMAND,SC_MOVE+HTCAPTION,lParam);
+        else dprintf(("ACtive window (%x) != toplevel wnd %x", OSLibWinQueryActiveWindow(), topparent->getWindowHandle()));
         break;
     }
@@ -425,7 +432,9 @@
 LONG Win32BaseWindow::HandleNCHitTest(POINT pt)
 {
-  RECT rect = rectWindow;
+  RECT rect;
 
   if (dwStyle & WS_MINIMIZE) return HTCAPTION;
+
+  GetWindowRect(getWindowHandle(), &rect);
 
   if (!PtInRect(&rect,pt)) return HTNOWHERE;
@@ -1007,4 +1016,5 @@
     //only redraw caption
     GetRgnBox(clip,&rectClip);
+#if 1
     //SvL: I'm getting paint problems when clipping a dc created in GetDCEx
     //     with a region that covers the entire window (RealPlayer 7 Update 1)
@@ -1016,4 +1026,5 @@
         rectClip = rect;
     }
+#endif
   }
   else
@@ -1122,5 +1133,5 @@
   }
 
-  ReleaseDC(Win32Hwnd,hdc);
+  ReleaseDC(getWindowHandle(),hdc);
   IncreaseLogCount();
   dprintf(("**DoNCPaint %x DONE", getWindowHandle()));
@@ -1305,5 +1316,5 @@
 
     case SC_TASKLIST:
-        OSLibWinShowTaskList(getOS2FrameWindowHandle());
+        OSLibWinShowTaskList(getOS2WindowHandle());
         break;
 
Index: trunk/src/user32/win32wbasepos.cpp
===================================================================
--- trunk/src/user32/win32wbasepos.cpp	(revision 3658)
+++ trunk/src/user32/win32wbasepos.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: win32wbasepos.cpp,v 1.14 2000-05-28 16:43:47 sandervl Exp $ */
+/* $Id: win32wbasepos.cpp,v 1.15 2000-06-07 14:51:32 sandervl Exp $ */
 /*
  * Win32 Window Base Class for OS/2 (nonclient/position methods)
@@ -37,4 +37,5 @@
 #include "pmframe.h"
 #include "win32wdesktop.h"
+#include <win\hook.h>
 
 #define DBG_LOCALLOG	DBG_win32wbasepos
@@ -130,28 +131,42 @@
    LONG result;
 
-   params.rgrc[0] = *newWindowRect;
-   if (calcValidRect)
-   {
-        winposCopy = *winpos;
-        params.rgrc[1] = *oldWindowRect;
-        if(getParent()) {//in parent coordinates
-            MapWindowPoints(getWindowHandle(), getParent()->getWindowHandle(), (POINT *)oldClientRect, 2);
-        }
-        else {//in screen coordinates (just add window rectangle origin (already in screen coordinates))
-            OffsetRect(oldClientRect, rectWindow.left, rectWindow.top);
-        }
-        params.rgrc[2] = *oldClientRect;
-        params.lppos = &winposCopy;
-   }
-   result = SendInternalMessageA(WM_NCCALCSIZE, calcValidRect, (LPARAM)&params );
-
-   /* If the application send back garbage, ignore it */
-   if (params.rgrc[0].left <= params.rgrc[0].right && params.rgrc[0].top <= params.rgrc[0].bottom)
-   {
-        *newClientRect = params.rgrc[0];
-        //client rectangle now in screen coordinates; convert to 'frame' coordinates
-        OffsetRect(newClientRect, -rectWindow.left, -rectWindow.top);
-   }
-
+   /* Send WM_NCCALCSIZE message to get new client area */
+//   if((winpos->flags & (SWP_FRAMECHANGED | SWP_NOSIZE)) != SWP_NOSIZE )
+//   {
+   	params.rgrc[0] = *newWindowRect;
+   	if(calcValidRect)
+   	{
+        	winposCopy = *winpos;
+	        params.rgrc[1] = *oldWindowRect;
+	        //client rectangel must be in parent coordinates
+	        OffsetRect(oldClientRect, rectWindow.left, rectWindow.top);
+
+	        params.rgrc[2] = *oldClientRect;
+	        params.lppos = &winposCopy;
+   	}
+   	result = SendInternalMessageA(WM_NCCALCSIZE, calcValidRect, (LPARAM)&params );
+
+   	/* If the application send back garbage, ignore it */
+   	if(params.rgrc[0].left <= params.rgrc[0].right && params.rgrc[0].top <= params.rgrc[0].bottom)
+   	{
+        	*newClientRect = params.rgrc[0];
+	        //client rectangle now in parent coordinates; convert to 'frame' coordinates
+	        OffsetRect(newClientRect, -rectWindow.left, -rectWindow.top);
+   	}
+
+        /* FIXME: WVR_ALIGNxxx */
+        if(newClientRect->left != rectClient.left || newClientRect->top  != rectClient.top)
+           winpos->flags &= ~SWP_NOCLIENTMOVE;
+
+        if((newClientRect->right - newClientRect->left != rectClient.right - rectClient.left) ||
+           (newClientRect->bottom - newClientRect->top != rectClient.bottom - rectClient.top))
+             winpos->flags &= ~SWP_NOCLIENTSIZE;
+
+//   }
+//   else
+//   if(!(winpos->flags & SWP_NOMOVE) && 
+//       (newClientRect->left != rectClient.left || newClientRect->top != rectClient.top)) {
+//            winpos->flags &= ~SWP_NOCLIENTMOVE;
+//   }
    return result;
 }
@@ -175,5 +190,89 @@
     return 0;
 }
+/******************************************************************************
+ *           WINPOS_MinMaximize
+ *
+ * Fill in lpRect and return additional flags to be used with SetWindowPos().
+ * This function assumes that 'cmd' is different from the current window
+ * state.
+ */
+UINT Win32BaseWindow::MinMaximize(UINT cmd, LPRECT lpRect)
+{
+    UINT swpFlags = 0;
+    POINT size;
+
+    size.x = rectWindow.left; 
+    size.y = rectWindow.top;
+
+    if(IsRectEmpty(&windowpos.rcNormalPosition)) {
+	CopyRect(&windowpos.rcNormalPosition, &rectWindow);
+    }
+    if(!HOOK_CallHooksA(WH_CBT, HCBT_MINMAX, getWindowHandle(), cmd))
+    {
+	if(getStyle() & WS_MINIMIZE )
+	{
+	    if(!SendInternalMessageA(WM_QUERYOPEN, 0, 0L))
+		return (SWP_NOSIZE | SWP_NOMOVE);
+	}
+	switch( cmd )
+	{
+	    case SW_MINIMIZE:
+		if( getStyle() & WS_MAXIMIZE)
+		{
+		     	setFlags(getFlags() | WIN_RESTORE_MAX);
+		     	setStyle(getStyle() & ~WS_MAXIMIZE);
+                }
+                else	setFlags(getFlags() & ~WIN_RESTORE_MAX);
+
+		setStyle(getStyle() | WS_MINIMIZE);
+
+		SetRect(lpRect, windowpos.ptMinPosition.x, windowpos.ptMinPosition.y,
+		        GetSystemMetrics(SM_CXICON), GetSystemMetrics(SM_CYICON) );
+		break;
+
+	    case SW_MAXIMIZE:
+                GetMinMaxInfo(&size, &windowpos.ptMaxPosition, NULL, NULL );
+
+		if(getStyle() & WS_MINIMIZE )
+		{
+		     setStyle(getStyle() & ~WS_MINIMIZE);
+		}
+                setStyle(getStyle() | WS_MAXIMIZE);
+
+		SetRect(lpRect, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y,
+		        size.x, size.y );
+		break;
+
+	    case SW_RESTORE:
+		if(getStyle() & WS_MINIMIZE)
+		{
+		     	setStyle(getStyle() & ~WS_MINIMIZE);
+
+		     	if( getFlags() & WIN_RESTORE_MAX)
+		     	{
+			 	/* Restore to maximized position */
+                         	GetMinMaxInfo(&size, &windowpos.ptMaxPosition, NULL, NULL);
+			 	setStyle(getStyle() | WS_MAXIMIZE);
+			 	SetRect(lpRect, windowpos.ptMaxPosition.x, windowpos.ptMaxPosition.y, size.x, size.y);
+			 	break;
+		     	}
+		} 
+		else 
+	        if( !(getStyle() & WS_MAXIMIZE) ) 
+			return 0;
+ 	        else 	setStyle(getStyle() & ~WS_MAXIMIZE);
+
+		/* Restore to normal position */
+
+		*lpRect = windowpos.rcNormalPosition;
+		lpRect->right -= lpRect->left; 
+		lpRect->bottom -= lpRect->top;
+		break;
+	}
+    } 
+    else swpFlags |= SWP_NOSIZE | SWP_NOMOVE;
+
+    return swpFlags;
+}
 //******************************************************************************
 //******************************************************************************
-
Index: trunk/src/user32/win32wdesktop.cpp
===================================================================
--- trunk/src/user32/win32wdesktop.cpp	(revision 3658)
+++ trunk/src/user32/win32wdesktop.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: win32wdesktop.cpp,v 1.12 2000-02-16 14:28:24 sandervl Exp $ */
+/* $Id: win32wdesktop.cpp,v 1.13 2000-06-07 14:51:33 sandervl Exp $ */
 /*
  * Win32 Desktop Window for OS/2
@@ -46,7 +46,10 @@
 Win32Desktop::Win32Desktop() : Win32BaseWindow(OBJTYPE_WINDOW)
 {
-  OSLibWinQueryWindowRect(OSLIB_HWND_DESKTOP, &rectWindow, RELATIVE_TO_SCREEN);
+  rectWindow.left   = 0;
+  rectWindow.top    = 0;
+  rectWindow.right  = OSLibQueryScreenWidth();
+  rectWindow.bottom = OSLibQueryScreenHeight();
+
   OS2Hwnd      = OSLIB_HWND_DESKTOP;
-  OS2HwndFrame = OSLIB_HWND_DESKTOP;
   rectClient   = rectWindow;
 
Index: trunk/src/user32/win32wmdiclient.cpp
===================================================================
--- trunk/src/user32/win32wmdiclient.cpp	(revision 3658)
+++ trunk/src/user32/win32wmdiclient.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: win32wmdiclient.cpp,v 1.28 2000-05-28 16:43:47 sandervl Exp $ */
+/* $Id: win32wmdiclient.cpp,v 1.29 2000-06-07 14:51:33 sandervl Exp $ */
 /*
  * Win32 MDI Client Window Class for OS/2
@@ -985,4 +985,5 @@
     SetRectEmpty( &childRect );
 
+    //TODO: Check if this goes correctly
     for (win32wnd = (Win32BaseWindow*)win32wnd->getFirstChild();win32wnd;win32wnd = (Win32BaseWindow*)win32wnd->getNextChild())
     {
Index: trunk/src/user32/window.cpp
===================================================================
--- trunk/src/user32/window.cpp	(revision 3658)
+++ trunk/src/user32/window.cpp	(revision 3662)
@@ -1,3 +1,3 @@
-/* $Id: window.cpp,v 1.67 2000-05-10 13:14:44 sandervl Exp $ */
+/* $Id: window.cpp,v 1.68 2000-06-07 14:51:33 sandervl Exp $ */
 /*
  * Win32 window apis for OS/2
@@ -7,7 +7,8 @@
  * Copyright 2000 Christoph Bratschi (cbratschi@datacomm.ch)
  *
- * Parts based on Wine Windows code (windows\win.c, windows\property.c)
+ * Parts based on Wine Windows code (windows\win.c, windows\property.c, windows\winpos.c)
  *
- * Copyright 1993, 1994 Alexandre Julliard
+ * Copyright 1993, 1994, 1995 Alexandre Julliard
+ *           1995, 1996, 1999 Alex Korobka
  *
  * Project Odin Software License can be found in LICENSE.TXT
@@ -445,4 +446,60 @@
 {
     return SetWindowPos( hwnd, HWND_TOP, 0, 0, 0, 0, SWP_NOMOVE|SWP_NOSIZE );
+}
+/***********************************************************************
+ *           SetInternalWindowPos   (USER32.483)
+ */
+void WIN32API SetInternalWindowPos(HWND    hwnd,
+                                   UINT    showCmd,
+                                   LPRECT  lpRect,
+                                   LPPOINT lpPoint )
+{
+    dprintf(("USER32: SetInternalWindowPos(%08xh,%08xh,%08xh,%08xh)",
+           hwnd, showCmd, lpRect, lpPoint));
+
+    if( IsWindow(hwnd) )
+    {
+	WINDOWPLACEMENT wndpl;
+	UINT flags;
+
+        GetWindowPlacement(hwnd, &wndpl);
+	wndpl.length  = sizeof(wndpl);
+	wndpl.showCmd = showCmd;
+	wndpl.flags = 0;
+
+	if(lpPoint)
+	{
+            wndpl.flags |= WPF_SETMINPOSITION;
+	    wndpl.ptMinPosition = *lpPoint;
+	}
+	if(lpRect)
+	{
+            wndpl.rcNormalPosition = *lpRect;
+	}
+        SetWindowPlacement( hwnd, &wndpl);
+    }
+
+}
+/***********************************************************************
+ *           GetInternalWindowPos   (USER32.245)
+ */
+UINT WIN32API GetInternalWindowPos(HWND    hwnd,
+                                   LPRECT  rectWnd,
+                                   LPPOINT ptIcon )
+{
+    WINDOWPLACEMENT wndpl;
+
+    dprintf(("USER32: GetInternalWindowPos(%08xh,%08xh,%08xh)\n",
+             hwnd,
+             rectWnd,
+             ptIcon));
+
+    if(GetWindowPlacement( hwnd, &wndpl ))
+    {
+        if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
+        if (ptIcon)  *ptIcon = wndpl.ptMinPosition;
+        return wndpl.showCmd;
+    }
+    return 0;
 }
 //******************************************************************************
@@ -519,14 +576,33 @@
         dprintf(("SetWindowPlacement, window %x not found", hwnd));
         SetLastError(ERROR_INVALID_WINDOW_HANDLE);
-        return 0;
-    }
+        return FALSE;
+    }
+    if(!winpos) {
+        dprintf(("SetWindowPlacement %x invalid parameter", hwnd));
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+    dprintf(("USER32: SetWindowPlacement %x %x", hwnd, winpos));
     return window->SetWindowPlacement((WINDOWPLACEMENT *)winpos);
 }
 //******************************************************************************
 //******************************************************************************
-BOOL WIN32API GetWindowPlacement(HWND hwnd, LPWINDOWPLACEMENT arg2)
-{
-    dprintf(("USER32:  GetWindowPlacement\n"));
-    return O32_GetWindowPlacement(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd), arg2);
+BOOL WIN32API GetWindowPlacement(HWND hwnd, LPWINDOWPLACEMENT winpos)
+{
+  Win32BaseWindow *window;
+
+    window = Win32BaseWindow::GetWindowFromHandle(hwnd);
+    if(!window) {
+        dprintf(("GetWindowPlacement, window %x not found", hwnd));
+        SetLastError(ERROR_INVALID_WINDOW_HANDLE);
+        return FALSE;
+    }
+    if(!winpos) {
+        dprintf(("GetWindowPlacement %x invalid parameter", hwnd));
+        SetLastError(ERROR_INVALID_PARAMETER);
+        return FALSE;
+    }
+    dprintf(("USER32: GetWindowPlacement %x %x", hwnd, winpos));
+    return window->GetWindowPlacement(winpos);
 }
 //******************************************************************************
@@ -609,32 +685,8 @@
 //******************************************************************************
 //******************************************************************************
-/***********************************************************************
- *           GetInternalWindowPos   (USER32.245)
- */
-UINT WIN32API GetInternalWindowPos(HWND    hwnd,
-                                   LPRECT  rectWnd,
-                                   LPPOINT ptIcon )
-{
-    WINDOWPLACEMENT wndpl;
-
-    dprintf(("USER32: GetInternalWindowPos(%08xh,%08xh,%08xh)\n",
-             hwnd,
-             rectWnd,
-             ptIcon));
-
-    if (GetWindowPlacement( hwnd, &wndpl ))
-    {
-        if (rectWnd) *rectWnd = wndpl.rcNormalPosition;
-        if (ptIcon)  *ptIcon = wndpl.ptMinPosition;
-        return wndpl.showCmd;
-    }
-    return 0;
-}
-//******************************************************************************
-//******************************************************************************
 BOOL WIN32API IsZoomed(HWND hwnd)
 {
     dprintf(("USER32:  IsZoomed\n"));
-    return O32_IsZoomed(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd));
+    return O32_IsZoomed(Win32BaseWindow::Win32ToOS2Handle(hwnd));
 }
 //******************************************************************************
@@ -643,5 +695,5 @@
 {
     dprintf(("USER32:  LockWindowUpdate\n"));
-    return O32_LockWindowUpdate(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd));
+    return O32_LockWindowUpdate(Win32BaseWindow::Win32ToOS2Handle(hwnd));
 }
 //******************************************************************************
@@ -665,5 +717,10 @@
         return FALSE;
     }
-    *pRect = *window->getWindowRect(); //always in screen coordinates
+    *pRect = *window->getWindowRect();
+
+    //convert from parent coordinates to screen (if necessary)
+    if(window->getParent()) {
+    	 MapWindowPoints(window->getParent()->getWindowHandle(), 0, (PPOINT)pRect, 2);
+    }
 
     dprintf(("GetWindowRect %x (%d,%d) (%d,%d)", hwnd, pRect->left, pRect->top, pRect->right, pRect->bottom));
@@ -862,4 +919,43 @@
 /* Coordinate Space and Transformation Functions */
 //******************************************************************************
+/*******************************************************************
+ *         WINPOS_GetWinOffset
+ *
+ * Calculate the offset between the origin of the two windows. Used
+ * to implement MapWindowPoints.
+ */
+static void WINPOS_GetWinOffset( Win32BaseWindow *wndFrom, Win32BaseWindow *wndTo,
+                                 POINT *offset )
+{
+ Win32BaseWindow *window;
+
+    offset->x = offset->y = 0;
+
+    /* Translate source window origin to screen coords */
+    if(wndFrom != windowDesktop)
+    {
+	window = wndFrom;
+        while(window)
+        {
+            offset->x += window->getClientRectPtr()->left + window->getWindowRect()->left;
+            offset->y += window->getClientRectPtr()->top + window->getWindowRect()->top;
+            window = window->getParent();
+        }
+    }
+
+    /* Translate origin to destination window coords */
+    if(wndTo != windowDesktop)
+    {
+	window = wndTo;
+        while(window)
+        {
+            offset->x -= window->getClientRectPtr()->left + window->getWindowRect()->left;
+            offset->y -= window->getClientRectPtr()->top + window->getWindowRect()->top;
+            window = window->getParent();
+        }
+    }
+}
+//******************************************************************************
+//******************************************************************************
 int WIN32API MapWindowPoints(HWND hwndFrom, HWND hwndTo, LPPOINT lpPoints,
                              UINT cPoints)
@@ -867,5 +963,5 @@
  Win32BaseWindow *wndfrom, *wndto;
  int retval = 0;
- OSLIBPOINT point;
+ POINT offset;
 
     SetLastError(0);
@@ -899,22 +995,13 @@
         return 0; //nothing to do
 
-    dprintf(("USER32: MapWindowPoints %x to %x (%d,%d) (%d)", hwndFrom, hwndTo, lpPoints->x, lpPoints->y, cPoints));
-    point.x = lpPoints->x;
-    point.y = lpPoints->y;
-    if (!mapWin32Point(wndfrom,wndto,&point))
-    {
-      	SetLastError(ERROR_INVALID_WINDOW_HANDLE);
-      	return 0;
-    }
-
-    short int xinc = point.x - lpPoints->x;
-    short int yinc = point.y - lpPoints->y;
+    dprintf2(("USER32: MapWindowPoints %x to %x (%d,%d) (%d)", hwndFrom, hwndTo, lpPoints->x, lpPoints->y, cPoints));
+    WINPOS_GetWinOffset(wndfrom, wndto, &offset);
 
     for(int i=0;i<cPoints;i++)
     {
-        lpPoints[i].x += xinc;
-        lpPoints[i].y += yinc;
-    }
-    retval = ((LONG)yinc << 16) | xinc;
+        lpPoints[i].x += offset.x;
+        lpPoints[i].y += offset.y;
+    }
+    retval = ((LONG)offset.y << 16) | offset.x;
     return retval;
 }
@@ -927,5 +1014,7 @@
     BOOL rc;
 
-    if (!hwnd) return (TRUE);
+    if(!hwnd) {
+	return (TRUE);
+    }
     wnd = Win32BaseWindow::GetWindowFromHandle (hwnd);
     if (!wnd) {
@@ -938,7 +1027,7 @@
     POINT tmp = *pt;
 #endif
-    rc = mapWin32Point(OSLIB_HWND_DESKTOP, wnd->getOS2WindowHandle(), (OSLIBPOINT*)pt);
-    dprintf(("ScreenToClient %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
-    return rc;
+    MapWindowPoints(0, hwnd, pt, 1);
+    dprintf2(("ScreenToClient %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
+    return TRUE;
 }
 //******************************************************************************
@@ -1049,5 +1138,4 @@
     Win32BaseWindow *wnd;
     PRECT rcl;
-    BOOL rc;
 
     if (!hwnd) {
@@ -1064,8 +1152,8 @@
     POINT tmp = *pt;
 #endif
-    rc = mapWin32Point(wnd->getOS2WindowHandle(),OSLIB_HWND_DESKTOP,(OSLIBPOINT*)pt);
-    dprintf(("ClientToScreen %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
-
-    return rc;
+    MapWindowPoints(hwnd, 0, pt, 1);
+    dprintf2(("ClientToScreen %x (%d,%d) -> (%d,%d)", hwnd, tmp.x, tmp.y, pt->x, pt->y));
+
+    return TRUE;
 }
 //******************************************************************************
@@ -1397,5 +1485,5 @@
 {
     dprintf(("USER32:  ArrangeIconicWindows %x", hwnd));
-    return O32_ArrangeIconicWindows(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd));
+    return O32_ArrangeIconicWindows(Win32BaseWindow::Win32ToOS2Handle(hwnd));
 }
 //******************************************************************************
@@ -1416,5 +1504,5 @@
 {
     dprintf(("USER32:  ShowOwnedPopups (OPEN32: todo) %x", hwnd));
-    return O32_ShowOwnedPopups(Win32BaseWindow::Win32ToOS2FrameHandle(hwnd), arg2);
+    return O32_ShowOwnedPopups(Win32BaseWindow::Win32ToOS2Handle(hwnd), arg2);
 }
 //******************************************************************************
