Index: trunk/src/gdi32/dbglocal.cpp
===================================================================
--- trunk/src/gdi32/dbglocal.cpp	(revision 4555)
+++ trunk/src/gdi32/dbglocal.cpp	(revision 4557)
@@ -1,3 +1,3 @@
-/* $Id: dbglocal.cpp,v 1.4 2000-08-18 18:14:56 sandervl Exp $ */
+/* $Id: dbglocal.cpp,v 1.5 2000-11-05 18:48:16 sandervl Exp $ */
 
 /*
@@ -38,5 +38,6 @@
 "blit",
 "rgbcvt",
-"objhandle"
+"objhandle",
+"transform"
 };
 //******************************************************************************
Index: trunk/src/gdi32/dbglocal.h
===================================================================
--- trunk/src/gdi32/dbglocal.h	(revision 4555)
+++ trunk/src/gdi32/dbglocal.h	(revision 4557)
@@ -1,3 +1,3 @@
-/* $Id: dbglocal.h,v 1.4 2000-08-18 18:14:56 sandervl Exp $ */
+/* $Id: dbglocal.h,v 1.5 2000-11-05 18:48:19 sandervl Exp $ */
 
 /*
@@ -18,5 +18,5 @@
 
 #define DBG_ENVNAME        "dbg_gdi32"
-#define DBG_ENVNAME_LVL2   "dbg_user32_lvl2"
+#define DBG_ENVNAME_LVL2   "dbg_gdi32_lvl2"
 
 #define DBG_gdi32           0
@@ -38,5 +38,6 @@
 #define DBG_rgbcvt          16
 #define DBG_objhandle       17
-#define DBG_MAXFILES        18
+#define DBG_transform       18
+#define DBG_MAXFILES        19
 
 extern USHORT DbgEnabled[DBG_MAXFILES];
Index: trunk/src/gdi32/gdi32.cpp
===================================================================
--- trunk/src/gdi32/gdi32.cpp	(revision 4555)
+++ trunk/src/gdi32/gdi32.cpp	(revision 4557)
@@ -1,3 +1,3 @@
-/* $Id: gdi32.cpp,v 1.58 2000-11-04 16:29:23 sandervl Exp $ */
+/* $Id: gdi32.cpp,v 1.59 2000-11-05 18:48:21 sandervl Exp $ */
 
 /*
@@ -193,11 +193,4 @@
     dprintf(("GDI32: GetDCOrgEx\n"));
     return O32_GetDCOrgEx(arg1, arg2);
-}
-//******************************************************************************
-//******************************************************************************
-BOOL WIN32API GetWindowExtEx(HDC arg1, PSIZE arg2)
-{
-    dprintf(("GDI32: GetWindowExtEx\n"));
-    return O32_GetWindowExtEx(arg1, arg2);
 }
 //******************************************************************************
@@ -599,6 +592,6 @@
     rc = O32_Escape(hdc, nEscape, cbInput, lpvInData, lpvOutData);
     if(rc == 0) {
-    	 dprintf(("GDI32: Escape %x %d %d %x %x returned %d (WARNING: might not be implemented!!) ", hdc, nEscape, cbInput, lpvInData, lpvOutData, rc));
-    } 
+         dprintf(("GDI32: Escape %x %d %d %x %x returned %d (WARNING: might not be implemented!!) ", hdc, nEscape, cbInput, lpvInData, lpvOutData, rc));
+    }
     else dprintf(("GDI32: Escape %x %d %d %x %x returned %d ", hdc, nEscape, cbInput, lpvInData, lpvOutData, rc));
 
@@ -739,11 +732,4 @@
 
     return(rc);
-}
-//******************************************************************************
-//******************************************************************************
-int WIN32API GetGraphicsMode(HDC arg1)
-{
-    dprintf(("GDI32: GetGraphicsMode"));
-    return O32_GetGraphicsMode(arg1);
 }
 //******************************************************************************
@@ -950,61 +936,7 @@
 //******************************************************************************
 //******************************************************************************
-BOOL WIN32API GetViewportOrgEx( HDC hdc, PPOINT pPoint)
-{
- BOOL rc;
-
-    rc = O32_GetViewportOrgEx(hdc, pPoint);
-    if(pPoint) {
-    	 dprintf(("GDI32: GetViewportOrgEx %x returned %d (%d,%d)", hdc, rc, pPoint->x, pPoint->y));
-    }
-    else dprintf(("GDI32: GetViewportOrgEx %x NULL returned %d (%d,%d)", hdc, rc));
-    return rc;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL WIN32API GetWindowOrgEx(HDC hdc, PPOINT pPoint)
-{
- BOOL rc;
-
-    rc = O32_GetWindowOrgEx(hdc, pPoint);
-    if(pPoint) {
-         dprintf(("GDI32: GetWindowOrgEx %x returned %d (%d,%d)", hdc, rc, pPoint->x, pPoint->y));
-    }
-    else dprintf(("GDI32: GetWindowOrgEx %x NULL returned %d", hdc, rc));
-    return rc;
-}
-//******************************************************************************
-//******************************************************************************
-BOOL WIN32API GetWorldTransform( HDC arg1, LPXFORM  arg2)
-{
-    dprintf(("GDI32: GetWorldTransform"));
-    return O32_GetWorldTransform(arg1, arg2);
-}
-//******************************************************************************
-//******************************************************************************
 ODINFUNCTION3(BOOL, LPtoDP, HDC, hdc, PPOINT, lpPoints, int, nCount)
 {
     return O32_LPtoDP(hdc, lpPoints, nCount);
-}
-//******************************************************************************
-//******************************************************************************
-BOOL WIN32API ModifyWorldTransform( HDC arg1, const XFORM *arg2, DWORD  arg3)
-{
-    dprintf(("GDI32: ModifyWorldTransform"));
-    return O32_ModifyWorldTransform(arg1, (LPXFORM)arg2, arg3);
-}
-//******************************************************************************
-//******************************************************************************
-BOOL WIN32API OffsetViewportOrgEx( HDC arg1, int arg2, int arg3, PPOINT  arg4)
-{
-    dprintf(("GDI32: OffsetViewportOrgEx"));
-    return O32_OffsetViewportOrgEx(arg1, arg2, arg3, arg4);
-}
-//******************************************************************************
-//******************************************************************************
-BOOL WIN32API OffsetWindowOrgEx( HDC arg1, int arg2, int arg3, PPOINT  arg4)
-{
-    dprintf(("GDI32: OffsetWindowOrgEx"));
-    return O32_OffsetWindowOrgEx(arg1, arg2, arg3, arg4);
 }
 //******************************************************************************
@@ -1116,18 +1048,4 @@
 //******************************************************************************
 //******************************************************************************
-BOOL WIN32API ScaleViewportExtEx( HDC arg1, int arg2, int arg3, int arg4, int arg5, PSIZE  arg6)
-{
-    dprintf(("GDI32: ScaleViewportExtEx"));
-    return O32_ScaleViewportExtEx(arg1, arg2, arg3, arg4, arg5, arg6);
-}
-//******************************************************************************
-//******************************************************************************
-BOOL WIN32API ScaleWindowExtEx( HDC arg1, int arg2, int arg3, int arg4, int arg5, PSIZE  arg6)
-{
-    dprintf(("GDI32: ScaleWindowExtEx"));
-    return O32_ScaleWindowExtEx(arg1, arg2, arg3, arg4, arg5, arg6);
-}
-//******************************************************************************
-//******************************************************************************
 int WIN32API SetArcDirection( HDC arg1, int  arg2)
 {
@@ -1154,11 +1072,4 @@
 //******************************************************************************
 //******************************************************************************
-int WIN32API SetGraphicsMode(HDC arg1, int  arg2)
-{
-    dprintf(("GDI32: SetGraphicsMode"));
-    return O32_SetGraphicsMode(arg1, arg2);
-}
-//******************************************************************************
-//******************************************************************************
 ODINFUNCTION2(DWORD, SetMapperFlags, HDC, hdc, DWORD, dwFlag)
 {
@@ -1194,35 +1105,4 @@
 {
     return O32_SetTextJustification(hdc, nBreakExtra, nBreakCount);
-}
-//******************************************************************************
-//******************************************************************************
-BOOL WIN32API SetViewportOrgEx( HDC hdc, int x, int y, PPOINT lpPoint)
-{
-    if(lpPoint) {
-    	 dprintf(("GDI32: SetViewportOrgEx %x %d %d (%d,%d)", hdc, x, y, lpPoint->x, lpPoint->y));
-    }
-    else dprintf(("GDI32: SetViewportOrgEx %x %d %d NULL", hdc, x, y));
-    return O32_SetViewportOrgEx(hdc, x, y, lpPoint);
-}
-//******************************************************************************
-//******************************************************************************
-BOOL WIN32API SetWindowExtEx( HDC arg1, int arg2, int arg3, PSIZE  arg4)
-{
-    dprintf(("GDI32: SetWindowExtEx"));
-    return O32_SetWindowExtEx(arg1, arg2, arg3, arg4);
-}
-//******************************************************************************
-//******************************************************************************
-BOOL WIN32API SetWindowOrgEx( HDC arg1, int arg2, int arg3, PPOINT  arg4)
-{
-    dprintf(("GDI32: SetWindowOrgEx"));
-    return O32_SetWindowOrgEx(arg1, arg2, arg3, arg4);
-}
-//******************************************************************************
-//******************************************************************************
-BOOL WIN32API SetWorldTransform( HDC arg1, const XFORM *arg2)
-{
-    dprintf(("GDI32: SetWorldTransform"));
-    return O32_SetWorldTransform(arg1, (LPXFORM)arg2);
 }
 //******************************************************************************
@@ -1622,6 +1502,6 @@
 
 BOOL WIN32API CombineTransform(LPXFORM lLPXFORMResult,
-                                  CONST   XFORM *lLPXFORM1,
-                                  CONST   XFORM *lLPXFORM2)
+                               CONST   XFORM *lLPXFORM1,
+                               CONST   XFORM *lLPXFORM2)
 {
   dprintf(("GDI32: CombineTransform(%08xh,%08xh,%08xh).\n",
Index: trunk/src/gdi32/makefile
===================================================================
--- trunk/src/gdi32/makefile	(revision 4555)
+++ trunk/src/gdi32/makefile	(revision 4557)
@@ -1,3 +1,3 @@
-# $Id: makefile,v 1.28 2000-11-04 16:29:24 sandervl Exp $
+# $Id: makefile,v 1.29 2000-11-05 18:48:22 sandervl Exp $
 
 #
@@ -42,4 +42,5 @@
 $(OBJDIR)\oslibgpi.obj \
 $(OBJDIR)\region.obj \
+$(OBJDIR)\transform.obj \
 $(OBJDIR)\metafile.obj \
 $(OBJDIR)\dibitmap.obj \
Index: trunk/src/gdi32/region.cpp
===================================================================
--- trunk/src/gdi32/region.cpp	(revision 4555)
+++ trunk/src/gdi32/region.cpp	(revision 4557)
@@ -1,3 +1,3 @@
-/* $Id: region.cpp,v 1.15 2000-11-04 16:29:24 sandervl Exp $ */
+/* $Id: region.cpp,v 1.16 2000-11-05 18:48:22 sandervl Exp $ */
 
 /*
@@ -67,9 +67,9 @@
 //******************************************************************************
 //******************************************************************************
-static LONG clientHeight(HWND hwnd, pDCData pHps)
+static LONG hdcHeight(HWND hwnd, pDCData pHps)
 {
     if(hwnd == 0 && pHps != 0)
         hwnd = pHps->hwnd;
-  
+
     if(hwnd != 0 || pHps == 0)
     {
@@ -112,9 +112,9 @@
 //******************************************************************************
 //******************************************************************************
-static LONG clientWidth(HWND hwnd, pDCData pHps)
+static LONG hdcWidth(HWND hwnd, pDCData pHps)
 {
     if(hwnd == 0 && pHps != 0)
         hwnd = pHps->hwnd;
-  
+
     if(hwnd != 0 || pHps == 0)
     {
@@ -176,6 +176,6 @@
     }
     else {
-        wHeight = clientHeight(hwnd, pHps);
-        wWidth  = clientWidth(hwnd, pHps);
+        wHeight = hdcHeight(hwnd, pHps);
+        wWidth  = hdcWidth(hwnd, pHps);
     }
 
@@ -565,7 +565,7 @@
             //Convert coordinates from PM to win32
             if (pHps->yInvert > 0) {
-   	         LONG temp     = pHps->yInvert - rectl.yBottom;
+             LONG temp     = pHps->yInvert - rectl.yBottom;
                  rectl.yBottom = pHps->yInvert - rectl.yTop;
-	         rectl.yTop    = temp;
+             rectl.yTop    = temp;
             }
 #endif
@@ -589,5 +589,5 @@
     }
 //    if(lpRect->left == 0 && lpRect->top == 0 && lpRect->right == 0 && lpRect->bottom == 0)
-// 	DebugInt3();
+//  DebugInt3();
     dprintf(("GDI32: GetClipBox of %X returned %d; (%d,%d)(%d,%d)", hdc, rc, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom));
     return rc;
Index: trunk/src/gdi32/transform.cpp
===================================================================
--- trunk/src/gdi32/transform.cpp	(revision 4557)
+++ trunk/src/gdi32/transform.cpp	(revision 4557)
@@ -0,0 +1,636 @@
+/* $Id: transform.cpp,v 1.1 2000-11-05 18:48:22 sandervl Exp $ */
+
+/*
+ * GDI32 coordinate & translformation code
+ *
+ * Copyright 2000 Sander van Leeuwen (sandervl@xs4all.nl)
+ *
+ * TODO: Metafile recording
+ * TODO: Translate & set the last error for Gpi operations
+ *
+ * Project Odin Software License can be found in LICENSE.TXT
+ *
+ */
+#define  INCL_GPI
+#define  INCL_WIN
+#include <os2wrap.h> //need odin wrappers
+
+#include <win32type.h>
+#include <win32api.h>
+#include <winconst.h>
+#include <stdlib.h>
+#include <stdarg.h>
+#include <string.h>
+#include <misc.h>
+#include <odinwrap.h>
+#include <objhandle.h>
+#include <dcdata.h>
+#include <winuser32.h>
+#include <win32wnd.h>
+#include "oslibgpi.h"
+
+#define DBG_LOCALLOG    DBG_transform
+#include "dbglocal.h"
+
+static const XFORM_W  XFORMIdentity    = { 1.0, 0.0, 0.0, 1.0, 0, 0 };
+
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API SetWorldTransform(HDC hdc, const XFORM_W * pXform)
+{
+ BOOL ret;
+
+    //Only proceed if DC is in GM_ADVANCED mode, unless it's a metafile PS
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+    if(!pHps || ((pHps->graphicsMode != GM_ADVANCED_W) && !pHps->isMetaPS))
+    {
+        dprintf(("WARNING: SetWorldTransform %x %x; not in GM_ADVANCED mode!!", hdc, pXform));
+        SetLastError(ERROR_INVALID_HANDLE_W);
+        return FALSE;
+    }
+
+    if(!pXform)
+    {
+        dprintf(("WARNING: SetWorldTransform %x %x; invalid parameter!!", hdc, pXform));
+        SetLastError(ERROR_INVALID_PARAMETER_W);
+        return FALSE;
+    }
+
+    //todo: metafile recording!!!!
+
+    MATRIXLF  matrixlf;
+    matrixlf.fxM11  = pXform->eM11 * (float)0x10000;
+    matrixlf.fxM12  = pXform->eM12 * (float)0x10000;
+    matrixlf.lM13   = 0;
+    matrixlf.fxM21  = pXform->eM21 * (float)0x10000;
+    matrixlf.fxM22  = pXform->eM22 * (float)0x10000;
+    matrixlf.lM23   = 0;
+    matrixlf.lM31   = pXform->eDx;
+    matrixlf.lM32   = pXform->eDy;
+    matrixlf.lM33   = 1;
+
+    ret = GpiSetModelTransformMatrix(pHps->hps, 9, &matrixlf, TRANSFORM_REPLACE);
+    if(ret)
+    {
+        TestWideLine(pHps);
+        Calculate1PixelDelta(pHps);
+        pHps->xform = *pXform;          // save transform in DC struct
+        dprintf(("SetWorldTransform %x %x", hdc, pXform));
+        SetLastError(ERROR_SUCCESS_W);
+    }
+    else {
+        dprintf(("WARNING: SetWorldTransform %x %x; GpiSetModelTransformMatrix failed!!", hdc, pXform));
+        SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error
+    }
+    return ret;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API GetWorldTransform(HDC hdc, LPXFORM_W pXform)
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+    if(!pHps)
+    {
+        dprintf(("WARNING: GetWorldTransform %x %x -> INVALID HDC", hdc, pXform));
+        SetLastError(ERROR_INVALID_HANDLE_W);
+        return FALSE;
+    }
+
+    if (!pXform)
+    {
+        dprintf(("WARNING: GetWorldTransform %x NULL -> INVALID parameter", hdc));
+        SetLastError(ERROR_INVALID_PARAMETER_W);
+        return FALSE;
+    }
+
+    *pXform = pHps->xform;
+
+    dprintf(("WARNING: GetWorldTransform %x %x", hdc, pXform));
+    SetLastError(ERROR_SUCCESS_W);
+    return TRUE;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API ModifyWorldTransform(HDC hdc, const XFORM_W *pXform, DWORD mode)
+{
+  MATRIXLF matrixlf;
+  LONG     lOptions;
+  BOOL     ret;
+
+    //Only proceed if DC is in GM_ADVANCED mode, unless it's a metafile PS
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+    if(!pHps || ((pHps->graphicsMode != GM_ADVANCED_W) && !pHps->isMetaPS))
+    {
+        dprintf(("WARNING: ModifyWorldTransform %x %x %x; not in GM_ADVANCED mode!!", hdc, pXform, mode));
+        SetLastError(ERROR_INVALID_HANDLE_W);
+        return FALSE;
+    }
+
+    if(mode == MWT_IDENTITY_W)
+    {
+        matrixlf.fxM11  = MAKEFIXED(1,0);
+        matrixlf.fxM12  = 0;
+        matrixlf.lM13   = 0;
+        matrixlf.fxM21  = 0;
+        matrixlf.fxM22  = MAKEFIXED(1,0);
+        matrixlf.lM23   = 0;
+        matrixlf.lM31   = 0;
+        matrixlf.lM32   = 0;
+        matrixlf.lM33   = MAKEFIXED(1,0);
+
+        lOptions = TRANSFORM_REPLACE;
+    }
+    else
+    if(mode == MWT_LEFTMULTIPLY_W  || mode == MWT_RIGHTMULTIPLY_W)
+    {
+        matrixlf.fxM11  = pXform->eM11 * (float)0x10000;
+        matrixlf.fxM12  = pXform->eM12 * (float)0x10000;
+        matrixlf.lM13   = 0;
+        matrixlf.fxM21  = pXform->eM21 * (float)0x10000;
+        matrixlf.fxM22  = pXform->eM22 * (float)0x10000;
+        matrixlf.lM23   = 0;
+        matrixlf.lM31   = pXform->eDx;
+        matrixlf.lM32   = pXform->eDy;
+        matrixlf.lM33   = 1;
+
+        if(mode == MWT_LEFTMULTIPLY_W) {
+             lOptions = TRANSFORM_PREEMPT;
+        }
+        else lOptions = TRANSFORM_ADD;
+    }
+    else
+    {
+        dprintf(("WARNING: ModifyWorldTransform %x %x %x; invalid parameter!!", hdc, pXform, mode));
+        SetLastError(ERROR_INVALID_PARAMETER_W);
+        return FALSE;
+    }
+    //todo: metafile recording!!!
+
+    ret = GpiSetModelTransformMatrix( pHps->hps, 9, &matrixlf, lOptions);
+    if(ret)
+    {
+        if(mode == MWT_IDENTITY_W) {
+             pHps->xform = XFORMIdentity;
+        }
+        else GetWorldTransform(hdc, &pHps->xform);
+
+        dprintf(("ModifyWorldTransform %x %x %d", hdc, pXform, mode));
+        SetLastError(ERROR_SUCCESS_W);
+    }
+    else {
+        dprintf(("ModifyWorldTransform %x %x %d; GpiSetModelTransformMatrix failed!!", hdc, pXform, mode));
+        SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error
+    }
+
+    return ret;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API OffsetViewportOrgEx(HDC hdc, int xOffset, int yOffset, LPPOINT pPoint)
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+
+    if(pHps && changePageXForm(pHps, (PPOINTL) &pHps->viewportOrg,
+                               xOffset + pHps->viewportOrg.x,
+                               yOffset + pHps->viewportOrg.y,
+                               (PPOINTL) pPoint))
+    {
+        //todo: metafile recording!!!
+        dprintf(("OffsetViewportOrgEx %x (%d,%d) %x", hdc, xOffset, yOffset));
+        SetLastError(ERROR_SUCCESS_W);
+        return TRUE;
+    }
+
+    dprintf(("WARNING: OffsetViewportOrgEx %x (%d,%d) %x; HDC invalid or changePageXForm failed!!", hdc, xOffset, yOffset));
+    SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error
+    return FALSE;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API OffsetWindowOrgEx(HDC hdc, int xOffset, int yOffset, LPPOINT pPoint)
+{
+   pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+
+    if(pHps && changePageXForm(pHps, (PPOINTL) &pHps->windowOrg,
+                               xOffset + pHps->windowOrg.x,
+                               yOffset + pHps->windowOrg.y,
+                               (PPOINTL) pPoint))
+    {
+        //todo: metafile recording!!!
+        dprintf(("OffsetWindowOrgEx %x (%d,%d) %x", hdc, xOffset, yOffset));
+        SetLastError(ERROR_SUCCESS_W);
+        return TRUE;
+    }
+
+    dprintf(("WARNING: OffsetWindowOrgEx %x (%d,%d) %x; HDC invalid or changePageXForm failed!!", hdc, xOffset, yOffset));
+    SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error
+    return FALSE;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API ScaleViewportExtEx(HDC hdc, int xNum, int xDenom, int yNum, int yDenom, LPSIZE pSize)
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+
+    if(!pHps)
+    {
+        dprintf(("WARNING: ScaleViewportExtEx %x (%d,%d) (%d,%d), %x; HDC INVALID!!1", hdc, xNum, xDenom, yNum, yDenom, pSize));
+        SetLastError(ERROR_INVALID_PARAMETER_W);
+        return FALSE;
+    }
+
+    if(xNum && yNum && xDenom && yDenom &&
+       (pHps->MapMode == MM_ISOTROPIC_W || pHps->MapMode == MM_ANISOTROPIC_W))
+    {
+        if(changePageXForm(pHps, NULL, pHps->viewportXExt * xNum / xDenom,
+                           pHps->viewportYExt * yNum / yDenom, (PPOINTL) pSize))
+        {
+            //todo: metafile recording!!!
+            dprintf(("ScaleViewportExtEx %x (%d,%d) (%d,%d), %x", hdc, xNum, xDenom, yNum, yDenom, pSize));
+            SetLastError(ERROR_SUCCESS_W);
+            return TRUE;
+        }
+
+        dprintf(("WARNING: ScaleViewportExtEx %x (%d,%d) (%d,%d), %x; changePageXForm failed!!", hdc, xNum, xDenom, yNum, yDenom, pSize));
+        SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error
+        return FALSE;
+    }
+    else
+    {
+        pHps->lWndXExtSave = pHps->viewportXExt * xNum / xDenom;
+        pHps->lWndYExtSave = pHps->viewportYExt * yNum / yDenom;
+
+        //function is a no-op if map mode is not (AN)ISOTROPIC; NT returns TRUE
+        dprintf(("ScaleViewportExtEx %x (%d,%d) (%d,%d), %x", hdc, xNum, xDenom, yNum, yDenom, pSize));
+        SetLastError(ERROR_SUCCESS_W);
+        return TRUE;
+    }
+}
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API ScaleWindowExtEx(HDC hdc, int xNum, int xDenom, int yNum, int yDenom, LPSIZE pSize )
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+
+    if(pHps && xDenom && yDenom)
+    {
+        if(changePageXForm(pHps, (PPOINTL) &pHps->windowExt,
+                           pHps->windowExt.cx * xNum / xDenom,
+                           pHps->windowExt.cy * yNum / yDenom,
+                           (PPOINTL) pSize))
+        {
+            //todo: metafile recording!!!
+            dprintf(("ScaleWindowExtEx %x (%d,%d) (%d,%d), %x", hdc, xNum, xDenom, yNum, yDenom, pSize));
+            SetLastError(ERROR_SUCCESS_W);
+            return TRUE;
+        }
+
+        dprintf(("WARNING: ScaleWindowExtEx %x (%d,%d) (%d,%d), %x; changePageXForm failed!!", hdc, xNum, xDenom, yNum, yDenom, pSize));
+        SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error
+        return FALSE;
+    }
+
+    dprintf(("WARNING: ScaleWindowExtEx %x (%d,%d) (%d,%d), %x; invalid HDC!!", hdc, xNum, xDenom, yNum, yDenom, pSize));
+    SetLastError(ERROR_INVALID_PARAMETER_W);
+    return FALSE;
+}
+//******************************************************************************
+//******************************************************************************
+int WIN32API SetMapMode(HDC hdc, int mode)
+{
+    pDCData  pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+    if(!pHps)
+    {
+        dprintf(("WARNING: SetMapMode %x %d; invalid HDC!!", hdc, mode));
+        SetLastError(ERROR_INVALID_HANDLE_W);
+        return 0;
+    }
+
+    //todo: metafile recording!!!
+    return setMapMode(pHps, mode);
+}
+//******************************************************************************
+//******************************************************************************
+int WIN32API GetMapMode(HDC hdc)
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+    if(pHps) {
+        dprintf(("GDI32: GetMapMode %x -> %d", hdc, pHps->MapMode));
+        SetLastError(ERROR_SUCCESS_W);
+        return pHps->MapMode;
+    }
+    dprintf(("WARNING: GetMapMode %x invalid HDC!!", hdc));
+    SetLastError(ERROR_INVALID_HANDLE_W);
+    return 0;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API SetViewportExtEx( HDC hdc, int xExt, int yExt, LPSIZE pSize)
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+    if (!pHps)
+    {
+        dprintf(("WARNING: SetViewPortExtEx: HDC %x not found!!", hdc));
+        SetLastError(ERROR_INVALID_HANDLE_W);
+        return FALSE;
+    }
+
+    if(xExt && yExt)
+    {
+        //todo: metafile recording!!! (always)
+        if (pHps->MapMode == MM_ISOTROPIC_W || pHps->MapMode == MM_ANISOTROPIC_W )
+        {
+            if(changePageXForm(pHps, NULL, xExt, yExt, (PPOINTL)pSize))
+            {
+                dprintf(("SetViewPortExtEx: %x (%d,%d), %x", hdc, xExt, yExt, pSize));
+                SetLastError(ERROR_SUCCESS_W);
+                return TRUE;
+            }
+        }
+        else
+        {
+            pHps->lVwpXExtSave = xExt, pHps->lVwpYExtSave = yExt;
+
+            //function is a no-op if map mode is not (AN)ISOTROPIC; NT returns TRUE
+            dprintf(("SetViewPortExtEx: %x (%d,%d), %x", hdc, xExt, yExt, pSize));
+            SetLastError(ERROR_SUCCESS_W);
+            return TRUE;
+        }
+
+        dprintf(("WARNING: SetViewPortExtEx: %x (%d,%d) -> changePageXForm failed!!!, %x", hdc, xExt, yExt, pSize));
+        SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error
+        return FALSE;
+    }
+
+    dprintf(("WARNING: SetViewPortExtEx: %x (%d,%d) -> invalid parameters!!!, %x", hdc, xExt, yExt, pSize));
+    SetLastError(ERROR_INVALID_PARAMETER_W);
+    return FALSE;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API GetViewportExtEx(HDC hdc, LPSIZE pSize)
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+    if(!pHps)
+    {
+        dprintf(("WARNING: GetViewportExtEx %x %x -> INVALID HDC", hdc, pSize));
+        SetLastError(ERROR_INVALID_HANDLE_W);
+        return FALSE;
+    }
+
+    if(!pSize)
+    {
+        dprintf(("WARNING: GetViewportExtEx %x NULL -> INVALID parameter", hdc));
+        SetLastError(ERROR_INVALID_PARAMETER_W);
+        return FALSE;
+    }
+
+    pSize->cx = (LONG)pHps->viewportXExt;
+    pSize->cy = (LONG)pHps->viewportYExt;
+    dprintf(("GDI32: GetViewportExtEx %x -> (%d,%d)", hdc, pSize->cx, pSize->cy));
+
+    SetLastError(ERROR_SUCCESS_W);
+    return TRUE;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API SetViewportOrgEx(HDC hdc, int xOrg, int yOrg, LPPOINT pPoint)
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+
+    if(pHps)
+    {
+        if(changePageXForm(pHps, (PPOINTL) &pHps->viewportOrg, xOrg,
+                           yOrg, (PPOINTL) pPoint))
+        {
+            //todo: metafile recording!!!
+            dprintf(("SetViewPortOrgEx: %x (%d,%d), %x", hdc, xOrg, yOrg, pPoint));
+            SetLastError(ERROR_SUCCESS_W);
+            return TRUE;
+        }
+        dprintf(("WARNING: SetViewPortOrgEx: %x (%d,%d) %x-> changePageXForm failed!!!, %x", hdc, xOrg, yOrg, pPoint));
+        SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error
+        return FALSE;
+    }
+
+    dprintf(("WARNING: SetViewPortOrgEx: HDC %x not found!!", hdc));
+    SetLastError(ERROR_INVALID_PARAMETER_W);
+    return FALSE;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API GetViewportOrgEx(HDC hdc, LPPOINT pPoint)
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+    if(!pHps)
+    {
+        dprintf(("WARNING: GetViewportOrgEx %x %x -> INVALID HDC", hdc, pPoint));
+        SetLastError(ERROR_INVALID_HANDLE_W);
+        return FALSE;
+    }
+
+    if(!pPoint)
+    {
+        dprintf(("WARNING: GetViewportOrgEx %x NULL -> INVALID parameter", hdc));
+        SetLastError(ERROR_INVALID_PARAMETER_W);
+        return FALSE;
+    }
+
+    pPoint->x = pHps->viewportOrg.x;
+    pPoint->y = pHps->viewportOrg.y;
+
+    dprintf(("GDI32: GetViewportOrgEx %x -> (%d,%d)", hdc, pPoint->x, pPoint->y));
+
+    SetLastError(ERROR_SUCCESS_W);
+    return TRUE;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API SetWindowExtEx(HDC hdc, int xExt, int yExt, LPSIZE pSize)
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+    if(!pHps)
+    {
+        dprintf(("WARNING: SetWindowExtEx: HDC %x not found!!", hdc));
+        SetLastError(ERROR_INVALID_HANDLE_W);
+        return FALSE;
+    }
+
+    if(xExt && yExt)
+    {
+        //todo: metafile recording!!! (always)
+
+        if(pHps->MapMode == MM_ISOTROPIC_W || pHps->MapMode == MM_ANISOTROPIC_W)
+        {
+            if(changePageXForm(pHps, (PPOINTL) &pHps->windowExt,
+                               xExt, yExt, (PPOINTL) pSize) )
+            {
+                dprintf(("SetWindowExtEx: %x (%d,%d), %x", hdc, xExt, yExt, pSize));
+                SetLastError(ERROR_SUCCESS_W);
+                return TRUE;
+            }
+            dprintf(("WARNING: SetWindowExtEx: %x (%d,%d) -> changePageXForm failed!!!, %x", hdc, xExt, yExt, pSize));
+            SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error
+            return FALSE;
+        }
+        else
+        {
+            pHps->lWndXExtSave = xExt, pHps->lWndYExtSave = yExt;
+
+            //function is a no-op if map mode is not (AN)ISOTROPIC; NT returns TRUE
+            dprintf(("SetWindowExtEx: %x (%d,%d), %x", hdc, xExt, yExt, pSize));
+            SetLastError(ERROR_SUCCESS_W);
+            return TRUE;
+        }
+    }
+    dprintf(("WARNING: SetWindowExtEx %x (%d,%d) %x; invalid parameter", hdc, xExt, yExt, pSize));
+    SetLastError(ERROR_INVALID_PARAMETER_W);
+    return FALSE;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API GetWindowExtEx(HDC hdc, LPSIZE pSize)
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+    if(!pHps)
+    {
+        dprintf(("WARNING: GetWindowExtEx %x %x -> INVALID HDC", hdc, pSize));
+        SetLastError(ERROR_INVALID_HANDLE_W);
+        return FALSE;
+    }
+
+    if(!pSize)
+    {
+        dprintf(("WARNING: GetWindowExtEx %x NULL -> INVALID parameter", hdc));
+        SetLastError(ERROR_INVALID_PARAMETER_W);
+        return FALSE;
+    }
+
+    pSize->cx = pHps->windowExt.cx;
+    pSize->cy = pHps->windowExt.cy;
+
+    dprintf(("GDI32: GetWindowExtEx %x -> (%d,%d)", hdc, pSize->cx, pSize->cy));
+
+    SetLastError(ERROR_SUCCESS_W);
+    return TRUE;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API SetWindowOrgEx(HDC hdc, int xOrg, int yOrg, LPPOINT pPoint)
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+    if(pHps)
+    {
+        if(changePageXForm(pHps, (PPOINTL) &pHps->windowOrg, xOrg,
+                           yOrg, (PPOINTL) pPoint))
+        {
+            //todo: metafile recording!!!
+
+            dprintf(("SetWindowOrgEx: %x (%d,%d), %x", hdc, xOrg, yOrg, pPoint));
+            SetLastError(ERROR_SUCCESS_W);
+            return TRUE;
+        }
+        //todo: set correct error
+        dprintf(("WARNING: SetWindowOrgEx: %x (%d,%d) %x -> changePageXForm failed!!!, %x", hdc, xOrg, yOrg, pPoint));
+        SetLastError(ERROR_INVALID_PARAMETER_W);
+        return FALSE;
+    }
+    dprintf(("WARNING: SetWindowOrgEx: HDC %x not found!!", hdc));
+    SetLastError(ERROR_INVALID_PARAMETER_W);
+    return FALSE;
+}
+//******************************************************************************
+//******************************************************************************
+BOOL WIN32API GetWindowOrgEx(HDC hdc, LPPOINT pPoint)
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+    if(!pHps)
+    {
+        dprintf(("WARNING: GetWindowOrgEx %x %x -> INVALID HDC", hdc, pPoint));
+        SetLastError(ERROR_INVALID_HANDLE_W);
+        return FALSE;
+    }
+
+    if(!pPoint)
+    {
+        dprintf(("WARNING: GetWindowOrgEx %x NULL -> INVALID parameter", hdc));
+        SetLastError(ERROR_INVALID_PARAMETER_W);
+        return FALSE;
+    }
+
+    pPoint->x = pHps->windowOrg.x;
+    pPoint->y = pHps->windowOrg.y;
+
+    dprintf(("GDI32: GetWindowOrgEx %x -> (%d,%d)", hdc, pPoint->x, pPoint->y));
+
+    SetLastError(ERROR_SUCCESS_W);
+    return TRUE;
+}
+//******************************************************************************
+//******************************************************************************
+int WIN32API SetGraphicsMode(HDC hdc, int iMode)
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+    if(!pHps)
+    {
+        dprintf(("WARNING: SetGraphicsMode HDC %x NOT FOUND!!", hdc));
+        SetLastError(ERROR_INVALID_HANDLE_W);
+        return 0;
+    }
+
+    if(iMode != GM_COMPATIBLE_W  && iMode != GM_ADVANCED_W)
+    {
+        dprintf(("WARNING: SetGraphicsMode invalid mode %x!!", iMode));
+        SetLastError(ERROR_INVALID_PARAMETER_W);
+        return 0;
+    }
+
+    //Only switch from GM_ADVANCED_W to GM_COMPATIBLE_W if default matrix is active
+    if (iMode == GM_COMPATIBLE_W  &&  pHps->graphicsMode == GM_ADVANCED_W)
+    {
+        MATRIXLF matrixlf;
+
+        if(!GpiQueryModelTransformMatrix(pHps->hps, 9, &matrixlf))
+        {
+            dprintf(("WARNING: SetGraphicsMode %x %d; GpiQueryModelTransformMatrix failed!", hdc, iMode));
+            SetLastError(ERROR_INVALID_PARAMETER_W);  //todo translate PM error!!
+            return 0;
+
+        }
+
+        if (!(matrixlf.fxM11 == MAKEFIXED(1,0) && matrixlf.fxM12 == MAKEFIXED(0,0) &&
+              matrixlf.fxM21 == MAKEFIXED(0,0) && matrixlf.fxM22 == MAKEFIXED(1,0) &&
+              matrixlf.lM31  == 0 && matrixlf.lM32  == 0 ))
+        {
+            dprintf(("WARNING: SetGraphicsMode %x %d; can't complete!", hdc, iMode));
+            SetLastError(ERROR_CAN_NOT_COMPLETE_W);  // done by NT
+            return 0;
+        }
+    }
+    int oldMode = pHps->graphicsMode;
+
+    dprintf(("SetGraphicsMode %x %d (old mode %d)", hdc, iMode, oldMode));
+    pHps->graphicsMode = iMode;
+
+    SetLastError(ERROR_SUCCESS_W);
+    return oldMode;
+}
+//******************************************************************************
+//******************************************************************************
+int WIN32API GetGraphicsMode(HDC hdc)
+{
+    pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
+    if (!pHps)
+    {
+        dprintf(("WARNING: GetGraphicsMode HDC %x NOT FOUND!!", hdc));
+        SetLastError(ERROR_INVALID_HANDLE_W);
+        return 0;
+    }
+
+    dprintf(("GetGraphicsMode %x = %x", hdc, pHps->graphicsMode));
+    SetLastError(ERROR_SUCCESS_W);
+    return pHps->graphicsMode;
+}
+//******************************************************************************
+//******************************************************************************
+
