| 1 | /* $Id: transform.cpp,v 1.9 2004-01-11 11:42:23 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * GDI32 coordinate & transformation code | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 2000 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 7 | * | 
|---|
| 8 | * TODO: Metafile recording | 
|---|
| 9 | * TODO: Translate & set the last error for Gpi operations | 
|---|
| 10 | * | 
|---|
| 11 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 12 | * | 
|---|
| 13 | */ | 
|---|
| 14 | #define  INCL_GPI | 
|---|
| 15 | #define  INCL_WIN | 
|---|
| 16 | #include <os2wrap.h> //need odin wrappers | 
|---|
| 17 |  | 
|---|
| 18 | #include <win32type.h> | 
|---|
| 19 | #include <win32api.h> | 
|---|
| 20 | #include <winconst.h> | 
|---|
| 21 | #include <stdlib.h> | 
|---|
| 22 | #include <stdarg.h> | 
|---|
| 23 | #include <string.h> | 
|---|
| 24 | #include <misc.h> | 
|---|
| 25 | #include <odinwrap.h> | 
|---|
| 26 | #include <objhandle.h> | 
|---|
| 27 | #include <dcdata.h> | 
|---|
| 28 | #include <winuser32.h> | 
|---|
| 29 | #include "oslibgpi.h" | 
|---|
| 30 |  | 
|---|
| 31 | #define DBG_LOCALLOG    DBG_transform | 
|---|
| 32 | #include "dbglocal.h" | 
|---|
| 33 |  | 
|---|
| 34 | static const XFORM_W  XFORMIdentity    = { 1.0, 0.0, 0.0, 1.0, 0, 0 }; | 
|---|
| 35 |  | 
|---|
| 36 | //region.cpp (todo; move to header) | 
|---|
| 37 | LONG hdcHeight(HWND hwnd, pDCData pHps); | 
|---|
| 38 | LONG hdcWidth(HWND hwnd, pDCData pHps); | 
|---|
| 39 |  | 
|---|
| 40 | //****************************************************************************** | 
|---|
| 41 | //****************************************************************************** | 
|---|
| 42 | BOOL WIN32API LPtoDP(HDC hdc, PPOINT lpPoints, int nCount) | 
|---|
| 43 | { | 
|---|
| 44 | BOOL ret; | 
|---|
| 45 |  | 
|---|
| 46 | dprintf(("LPtoDP %x %x %d", hdc, lpPoints, nCount)); | 
|---|
| 47 |  | 
|---|
| 48 | #ifdef DEBUG | 
|---|
| 49 | if(nCount && lpPoints) { | 
|---|
| 50 | for(int i=0;i<nCount;i++) { | 
|---|
| 51 | dprintf(("LPtoDP in (%d,%d)", lpPoints[i].x, lpPoints[i].y)); | 
|---|
| 52 | } | 
|---|
| 53 | } | 
|---|
| 54 | #endif | 
|---|
| 55 | ret = O32_LPtoDP(hdc, lpPoints, nCount); | 
|---|
| 56 | #ifdef DEBUG | 
|---|
| 57 | if(nCount && lpPoints) { | 
|---|
| 58 | for(int i=0;i<nCount;i++) { | 
|---|
| 59 | dprintf(("LPtoDP out (%d,%d)", lpPoints[i].x, lpPoints[i].y)); | 
|---|
| 60 | } | 
|---|
| 61 | } | 
|---|
| 62 | #endif | 
|---|
| 63 | return ret; | 
|---|
| 64 | } | 
|---|
| 65 | //****************************************************************************** | 
|---|
| 66 | //****************************************************************************** | 
|---|
| 67 | BOOL WIN32API DPtoLP(HDC hdc, PPOINT lpPoints, int nCount) | 
|---|
| 68 | { | 
|---|
| 69 | BOOL ret; | 
|---|
| 70 | LONG hdcwidth, hdcheight; | 
|---|
| 71 | pDCData pHps; | 
|---|
| 72 |  | 
|---|
| 73 | pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 74 | if(!pHps) | 
|---|
| 75 | { | 
|---|
| 76 | dprintf(("WARNING: DPtoLP %x invalid handle!!", hdc)); | 
|---|
| 77 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 78 | return FALSE; | 
|---|
| 79 | } | 
|---|
| 80 |  | 
|---|
| 81 | dprintf(("GDI32: DPtoLP %x %x %d", hdc, lpPoints, nCount)); | 
|---|
| 82 |  | 
|---|
| 83 | //GpiConvert doesn't like illegal values; TODO: check what NT does | 
|---|
| 84 | if(nCount && lpPoints) { | 
|---|
| 85 | hdcwidth  = hdcWidth(0, pHps); | 
|---|
| 86 | hdcheight = hdcHeight(0, pHps); | 
|---|
| 87 | for(int i=0;i<nCount;i++) { | 
|---|
| 88 | dprintf(("DPtoLP in (%d,%d)", lpPoints[i].x, lpPoints[i].y)); | 
|---|
| 89 | if(lpPoints[i].x > hdcwidth) { | 
|---|
| 90 | dprintf(("WARNING: DPtoLP correcting x value; hdcwidth = %d", hdcwidth)); | 
|---|
| 91 | lpPoints[i].x = hdcwidth; | 
|---|
| 92 | } | 
|---|
| 93 | if(lpPoints[i].y > hdcheight) { | 
|---|
| 94 | dprintf(("WARNING: DPtoLP correcting y value; hdcheight = %d", hdcheight)); | 
|---|
| 95 | lpPoints[i].y = hdcheight; | 
|---|
| 96 | } | 
|---|
| 97 | } | 
|---|
| 98 | } | 
|---|
| 99 |  | 
|---|
| 100 | ret = O32_DPtoLP(hdc, lpPoints, nCount); | 
|---|
| 101 | #ifdef DEBUG | 
|---|
| 102 | if(nCount && lpPoints) { | 
|---|
| 103 | for(int i=0;i<nCount;i++) { | 
|---|
| 104 | dprintf(("DPtoLP out (%d,%d)", lpPoints[i].x, lpPoints[i].y)); | 
|---|
| 105 | } | 
|---|
| 106 | } | 
|---|
| 107 | #endif | 
|---|
| 108 | return ret; | 
|---|
| 109 | } | 
|---|
| 110 | //****************************************************************************** | 
|---|
| 111 | //****************************************************************************** | 
|---|
| 112 | BOOL WIN32API SetWorldTransform(HDC hdc, const XFORM_W * pXform) | 
|---|
| 113 | { | 
|---|
| 114 | BOOL ret; | 
|---|
| 115 |  | 
|---|
| 116 | //Only proceed if DC is in GM_ADVANCED mode, unless it's a metafile PS | 
|---|
| 117 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 118 | if(!pHps || ((pHps->graphicsMode != GM_ADVANCED_W) && !pHps->isMetaPS)) | 
|---|
| 119 | { | 
|---|
| 120 | dprintf(("WARNING: SetWorldTransform %x %x; not in GM_ADVANCED mode!!", hdc, pXform)); | 
|---|
| 121 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 122 | return FALSE; | 
|---|
| 123 | } | 
|---|
| 124 |  | 
|---|
| 125 | if(!pXform) | 
|---|
| 126 | { | 
|---|
| 127 | dprintf(("WARNING: SetWorldTransform %x %x; invalid parameter!!", hdc, pXform)); | 
|---|
| 128 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 129 | return FALSE; | 
|---|
| 130 | } | 
|---|
| 131 |  | 
|---|
| 132 | //todo: metafile recording!!!! | 
|---|
| 133 |  | 
|---|
| 134 | MATRIXLF  matrixlf; | 
|---|
| 135 | matrixlf.fxM11  = pXform->eM11 * (float)0x10000; | 
|---|
| 136 | matrixlf.fxM12  = pXform->eM12 * (float)0x10000; | 
|---|
| 137 | matrixlf.lM13   = 0; | 
|---|
| 138 | matrixlf.fxM21  = pXform->eM21 * (float)0x10000; | 
|---|
| 139 | matrixlf.fxM22  = pXform->eM22 * (float)0x10000; | 
|---|
| 140 | matrixlf.lM23   = 0; | 
|---|
| 141 | matrixlf.lM31   = pXform->eDx; | 
|---|
| 142 | matrixlf.lM32   = pXform->eDy; | 
|---|
| 143 | matrixlf.lM33   = 1; | 
|---|
| 144 |  | 
|---|
| 145 | ret = GpiSetModelTransformMatrix(pHps->hps, 9, &matrixlf, TRANSFORM_REPLACE); | 
|---|
| 146 | if(ret) | 
|---|
| 147 | { | 
|---|
| 148 | TestWideLine(pHps); | 
|---|
| 149 | Calculate1PixelDelta(pHps); | 
|---|
| 150 | pHps->xform = *pXform;          // save transform in DC struct | 
|---|
| 151 | dprintf(("SetWorldTransform %x %x", hdc, pXform)); | 
|---|
| 152 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 153 | } | 
|---|
| 154 | else { | 
|---|
| 155 | dprintf(("WARNING: SetWorldTransform %x %x; GpiSetModelTransformMatrix failed!!", hdc, pXform)); | 
|---|
| 156 | SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error | 
|---|
| 157 | } | 
|---|
| 158 | return ret; | 
|---|
| 159 | } | 
|---|
| 160 | //****************************************************************************** | 
|---|
| 161 | //****************************************************************************** | 
|---|
| 162 | BOOL WIN32API GetWorldTransform(HDC hdc, LPXFORM_W pXform) | 
|---|
| 163 | { | 
|---|
| 164 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 165 | if(!pHps) | 
|---|
| 166 | { | 
|---|
| 167 | dprintf(("WARNING: GetWorldTransform %x %x -> INVALID HDC", hdc, pXform)); | 
|---|
| 168 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 169 | return FALSE; | 
|---|
| 170 | } | 
|---|
| 171 |  | 
|---|
| 172 | if (!pXform) | 
|---|
| 173 | { | 
|---|
| 174 | dprintf(("WARNING: GetWorldTransform %x NULL -> INVALID parameter", hdc)); | 
|---|
| 175 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 176 | return FALSE; | 
|---|
| 177 | } | 
|---|
| 178 |  | 
|---|
| 179 | *pXform = pHps->xform; | 
|---|
| 180 |  | 
|---|
| 181 | dprintf(("WARNING: GetWorldTransform %x %x", hdc, pXform)); | 
|---|
| 182 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 183 | return TRUE; | 
|---|
| 184 | } | 
|---|
| 185 | //****************************************************************************** | 
|---|
| 186 | //****************************************************************************** | 
|---|
| 187 | BOOL WIN32API ModifyWorldTransform(HDC hdc, const XFORM_W *pXform, DWORD mode) | 
|---|
| 188 | { | 
|---|
| 189 | MATRIXLF matrixlf; | 
|---|
| 190 | LONG     lOptions; | 
|---|
| 191 | BOOL     ret; | 
|---|
| 192 |  | 
|---|
| 193 | //Only proceed if DC is in GM_ADVANCED mode, unless it's a metafile PS | 
|---|
| 194 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 195 | if(!pHps || ((pHps->graphicsMode != GM_ADVANCED_W) && !pHps->isMetaPS)) | 
|---|
| 196 | { | 
|---|
| 197 | dprintf(("WARNING: ModifyWorldTransform %x %x %x; not in GM_ADVANCED mode!!", hdc, pXform, mode)); | 
|---|
| 198 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 199 | return FALSE; | 
|---|
| 200 | } | 
|---|
| 201 |  | 
|---|
| 202 | if(mode == MWT_IDENTITY_W) | 
|---|
| 203 | { | 
|---|
| 204 | matrixlf.fxM11  = MAKEFIXED(1,0); | 
|---|
| 205 | matrixlf.fxM12  = 0; | 
|---|
| 206 | matrixlf.lM13   = 0; | 
|---|
| 207 | matrixlf.fxM21  = 0; | 
|---|
| 208 | matrixlf.fxM22  = MAKEFIXED(1,0); | 
|---|
| 209 | matrixlf.lM23   = 0; | 
|---|
| 210 | matrixlf.lM31   = 0; | 
|---|
| 211 | matrixlf.lM32   = 0; | 
|---|
| 212 | matrixlf.lM33   = MAKEFIXED(1,0); | 
|---|
| 213 |  | 
|---|
| 214 | lOptions = TRANSFORM_REPLACE; | 
|---|
| 215 | } | 
|---|
| 216 | else | 
|---|
| 217 | if(mode == MWT_LEFTMULTIPLY_W  || mode == MWT_RIGHTMULTIPLY_W) | 
|---|
| 218 | { | 
|---|
| 219 | matrixlf.fxM11  = pXform->eM11 * (float)0x10000; | 
|---|
| 220 | matrixlf.fxM12  = pXform->eM12 * (float)0x10000; | 
|---|
| 221 | matrixlf.lM13   = 0; | 
|---|
| 222 | matrixlf.fxM21  = pXform->eM21 * (float)0x10000; | 
|---|
| 223 | matrixlf.fxM22  = pXform->eM22 * (float)0x10000; | 
|---|
| 224 | matrixlf.lM23   = 0; | 
|---|
| 225 | matrixlf.lM31   = pXform->eDx; | 
|---|
| 226 | matrixlf.lM32   = pXform->eDy; | 
|---|
| 227 | matrixlf.lM33   = 1; | 
|---|
| 228 |  | 
|---|
| 229 | if(mode == MWT_LEFTMULTIPLY_W) { | 
|---|
| 230 | lOptions = TRANSFORM_PREEMPT; | 
|---|
| 231 | } | 
|---|
| 232 | else lOptions = TRANSFORM_ADD; | 
|---|
| 233 | } | 
|---|
| 234 | else | 
|---|
| 235 | { | 
|---|
| 236 | dprintf(("WARNING: ModifyWorldTransform %x %x %x; invalid parameter!!", hdc, pXform, mode)); | 
|---|
| 237 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 238 | return FALSE; | 
|---|
| 239 | } | 
|---|
| 240 | //todo: metafile recording!!! | 
|---|
| 241 |  | 
|---|
| 242 | ret = GpiSetModelTransformMatrix( pHps->hps, 9, &matrixlf, lOptions); | 
|---|
| 243 | if(ret) | 
|---|
| 244 | { | 
|---|
| 245 | if(mode == MWT_IDENTITY_W) { | 
|---|
| 246 | pHps->xform = XFORMIdentity; | 
|---|
| 247 | } | 
|---|
| 248 | else GetWorldTransform(hdc, &pHps->xform); | 
|---|
| 249 |  | 
|---|
| 250 | dprintf(("ModifyWorldTransform %x %x %d", hdc, pXform, mode)); | 
|---|
| 251 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 252 | } | 
|---|
| 253 | else { | 
|---|
| 254 | dprintf(("ModifyWorldTransform %x %x %d; GpiSetModelTransformMatrix failed!!", hdc, pXform, mode)); | 
|---|
| 255 | SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error | 
|---|
| 256 | } | 
|---|
| 257 |  | 
|---|
| 258 | return ret; | 
|---|
| 259 | } | 
|---|
| 260 | //****************************************************************************** | 
|---|
| 261 | //****************************************************************************** | 
|---|
| 262 | BOOL WIN32API OffsetViewportOrgEx(HDC hdc, int xOffset, int yOffset, LPPOINT pPoint) | 
|---|
| 263 | { | 
|---|
| 264 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 265 |  | 
|---|
| 266 | if(pHps && changePageXForm(pHps, (PPOINTL) &pHps->viewportOrg, | 
|---|
| 267 | xOffset + pHps->viewportOrg.x, | 
|---|
| 268 | yOffset + pHps->viewportOrg.y, | 
|---|
| 269 | (PPOINTL) pPoint)) | 
|---|
| 270 | { | 
|---|
| 271 | //todo: metafile recording!!! | 
|---|
| 272 | dprintf(("OffsetViewportOrgEx %x (%d,%d) %x", hdc, xOffset, yOffset)); | 
|---|
| 273 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 274 | return TRUE; | 
|---|
| 275 | } | 
|---|
| 276 |  | 
|---|
| 277 | dprintf(("WARNING: OffsetViewportOrgEx %x (%d,%d) %x; HDC invalid or changePageXForm failed!!", hdc, xOffset, yOffset)); | 
|---|
| 278 | SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error | 
|---|
| 279 | return FALSE; | 
|---|
| 280 | } | 
|---|
| 281 | //****************************************************************************** | 
|---|
| 282 | //****************************************************************************** | 
|---|
| 283 | BOOL WIN32API OffsetWindowOrgEx(HDC hdc, int xOffset, int yOffset, LPPOINT pPoint) | 
|---|
| 284 | { | 
|---|
| 285 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 286 |  | 
|---|
| 287 | if(pHps && changePageXForm(pHps, (PPOINTL) &pHps->windowOrg, | 
|---|
| 288 | xOffset + pHps->windowOrg.x, | 
|---|
| 289 | yOffset + pHps->windowOrg.y, | 
|---|
| 290 | (PPOINTL) pPoint)) | 
|---|
| 291 | { | 
|---|
| 292 | //todo: metafile recording!!! | 
|---|
| 293 | dprintf(("OffsetWindowOrgEx %x (%d,%d) %x", hdc, xOffset, yOffset)); | 
|---|
| 294 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 295 | return TRUE; | 
|---|
| 296 | } | 
|---|
| 297 |  | 
|---|
| 298 | dprintf(("WARNING: OffsetWindowOrgEx %x (%d,%d) %x; HDC invalid or changePageXForm failed!!", hdc, xOffset, yOffset)); | 
|---|
| 299 | SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error | 
|---|
| 300 | return FALSE; | 
|---|
| 301 | } | 
|---|
| 302 | //****************************************************************************** | 
|---|
| 303 | //****************************************************************************** | 
|---|
| 304 | BOOL WIN32API ScaleViewportExtEx(HDC hdc, int xNum, int xDenom, int yNum, int yDenom, LPSIZE pSize) | 
|---|
| 305 | { | 
|---|
| 306 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 307 |  | 
|---|
| 308 | if(!pHps) | 
|---|
| 309 | { | 
|---|
| 310 | dprintf(("WARNING: ScaleViewportExtEx %x (%d,%d) (%d,%d), %x; HDC INVALID!!1", hdc, xNum, xDenom, yNum, yDenom, pSize)); | 
|---|
| 311 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 312 | return FALSE; | 
|---|
| 313 | } | 
|---|
| 314 |  | 
|---|
| 315 | if(xNum && yNum && xDenom && yDenom && | 
|---|
| 316 | (pHps->MapMode == MM_ISOTROPIC_W || pHps->MapMode == MM_ANISOTROPIC_W)) | 
|---|
| 317 | { | 
|---|
| 318 | if(changePageXForm(pHps, NULL, pHps->viewportXExt * xNum / xDenom, | 
|---|
| 319 | pHps->viewportYExt * yNum / yDenom, (PPOINTL) pSize)) | 
|---|
| 320 | { | 
|---|
| 321 | //todo: metafile recording!!! | 
|---|
| 322 | dprintf(("ScaleViewportExtEx %x (%d,%d) (%d,%d), %x", hdc, xNum, xDenom, yNum, yDenom, pSize)); | 
|---|
| 323 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 324 | return TRUE; | 
|---|
| 325 | } | 
|---|
| 326 |  | 
|---|
| 327 | dprintf(("WARNING: ScaleViewportExtEx %x (%d,%d) (%d,%d), %x; changePageXForm failed!!", hdc, xNum, xDenom, yNum, yDenom, pSize)); | 
|---|
| 328 | SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error | 
|---|
| 329 | return FALSE; | 
|---|
| 330 | } | 
|---|
| 331 | else | 
|---|
| 332 | { | 
|---|
| 333 | pHps->lWndXExtSave = pHps->viewportXExt * xNum / xDenom; | 
|---|
| 334 | pHps->lWndYExtSave = pHps->viewportYExt * yNum / yDenom; | 
|---|
| 335 |  | 
|---|
| 336 | //function is a no-op if map mode is not (AN)ISOTROPIC; NT returns TRUE | 
|---|
| 337 | dprintf(("ScaleViewportExtEx %x (%d,%d) (%d,%d), %x", hdc, xNum, xDenom, yNum, yDenom, pSize)); | 
|---|
| 338 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 339 | return TRUE; | 
|---|
| 340 | } | 
|---|
| 341 | } | 
|---|
| 342 | //****************************************************************************** | 
|---|
| 343 | //****************************************************************************** | 
|---|
| 344 | BOOL WIN32API ScaleWindowExtEx(HDC hdc, int xNum, int xDenom, int yNum, int yDenom, LPSIZE pSize ) | 
|---|
| 345 | { | 
|---|
| 346 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 347 |  | 
|---|
| 348 | if(pHps && xDenom && yDenom) | 
|---|
| 349 | { | 
|---|
| 350 | if(changePageXForm(pHps, (PPOINTL) &pHps->windowExt, | 
|---|
| 351 | pHps->windowExt.cx * xNum / xDenom, | 
|---|
| 352 | pHps->windowExt.cy * yNum / yDenom, | 
|---|
| 353 | (PPOINTL) pSize)) | 
|---|
| 354 | { | 
|---|
| 355 | //todo: metafile recording!!! | 
|---|
| 356 | dprintf(("ScaleWindowExtEx %x (%d,%d) (%d,%d), %x", hdc, xNum, xDenom, yNum, yDenom, pSize)); | 
|---|
| 357 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 358 | return TRUE; | 
|---|
| 359 | } | 
|---|
| 360 |  | 
|---|
| 361 | dprintf(("WARNING: ScaleWindowExtEx %x (%d,%d) (%d,%d), %x; changePageXForm failed!!", hdc, xNum, xDenom, yNum, yDenom, pSize)); | 
|---|
| 362 | SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error | 
|---|
| 363 | return FALSE; | 
|---|
| 364 | } | 
|---|
| 365 |  | 
|---|
| 366 | dprintf(("WARNING: ScaleWindowExtEx %x (%d,%d) (%d,%d), %x; invalid HDC!!", hdc, xNum, xDenom, yNum, yDenom, pSize)); | 
|---|
| 367 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 368 | return FALSE; | 
|---|
| 369 | } | 
|---|
| 370 | //****************************************************************************** | 
|---|
| 371 | //****************************************************************************** | 
|---|
| 372 | int WIN32API SetMapMode(HDC hdc, int mode) | 
|---|
| 373 | { | 
|---|
| 374 | pDCData  pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 375 | if(!pHps) | 
|---|
| 376 | { | 
|---|
| 377 | dprintf(("WARNING: SetMapMode %x %d; invalid HDC!!", hdc, mode)); | 
|---|
| 378 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 379 | return 0; | 
|---|
| 380 | } | 
|---|
| 381 |  | 
|---|
| 382 | //todo: metafile recording!!! | 
|---|
| 383 | dprintf(("SetMapMode %x %x", hdc, mode)); | 
|---|
| 384 | return setMapModeDC(pHps, mode); | 
|---|
| 385 | } | 
|---|
| 386 | //****************************************************************************** | 
|---|
| 387 | //****************************************************************************** | 
|---|
| 388 | int WIN32API GetMapMode(HDC hdc) | 
|---|
| 389 | { | 
|---|
| 390 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 391 | if(pHps) { | 
|---|
| 392 | dprintf(("GDI32: GetMapMode %x -> %d", hdc, pHps->MapMode)); | 
|---|
| 393 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 394 | return pHps->MapMode; | 
|---|
| 395 | } | 
|---|
| 396 | dprintf(("WARNING: GetMapMode %x invalid HDC!!", hdc)); | 
|---|
| 397 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 398 | return 0; | 
|---|
| 399 | } | 
|---|
| 400 | //****************************************************************************** | 
|---|
| 401 | //****************************************************************************** | 
|---|
| 402 | BOOL WIN32API SetViewportExtEx( HDC hdc, int xExt, int yExt, LPSIZE pSize) | 
|---|
| 403 | { | 
|---|
| 404 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 405 | if (!pHps) | 
|---|
| 406 | { | 
|---|
| 407 | dprintf(("WARNING: SetViewPortExtEx: HDC %x not found!!", hdc)); | 
|---|
| 408 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 409 | return FALSE; | 
|---|
| 410 | } | 
|---|
| 411 |  | 
|---|
| 412 | if(xExt && yExt) | 
|---|
| 413 | { | 
|---|
| 414 | //todo: metafile recording!!! (always) | 
|---|
| 415 | if (pHps->MapMode == MM_ISOTROPIC_W || pHps->MapMode == MM_ANISOTROPIC_W ) | 
|---|
| 416 | { | 
|---|
| 417 | if(changePageXForm(pHps, NULL, xExt, yExt, (PPOINTL)pSize)) | 
|---|
| 418 | { | 
|---|
| 419 | dprintf(("SetViewPortExtEx: %x (%d,%d), %x", hdc, xExt, yExt, pSize)); | 
|---|
| 420 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 421 | return TRUE; | 
|---|
| 422 | } | 
|---|
| 423 | } | 
|---|
| 424 | else | 
|---|
| 425 | { | 
|---|
| 426 | pHps->lVwpXExtSave = xExt, pHps->lVwpYExtSave = yExt; | 
|---|
| 427 |  | 
|---|
| 428 | //function is a no-op if map mode is not (AN)ISOTROPIC; NT returns TRUE | 
|---|
| 429 | dprintf(("SetViewPortExtEx: %x (%d,%d), %x", hdc, xExt, yExt, pSize)); | 
|---|
| 430 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 431 | return TRUE; | 
|---|
| 432 | } | 
|---|
| 433 |  | 
|---|
| 434 | dprintf(("WARNING: SetViewPortExtEx: %x (%d,%d) -> changePageXForm failed!!!, %x", hdc, xExt, yExt, pSize)); | 
|---|
| 435 | SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error | 
|---|
| 436 | return FALSE; | 
|---|
| 437 | } | 
|---|
| 438 |  | 
|---|
| 439 | dprintf(("WARNING: SetViewPortExtEx: %x (%d,%d) -> invalid parameters!!!, %x", hdc, xExt, yExt, pSize)); | 
|---|
| 440 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 441 | return FALSE; | 
|---|
| 442 | } | 
|---|
| 443 | //****************************************************************************** | 
|---|
| 444 | //****************************************************************************** | 
|---|
| 445 | BOOL WIN32API GetViewportExtEx(HDC hdc, LPSIZE pSize) | 
|---|
| 446 | { | 
|---|
| 447 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 448 | if(!pHps) | 
|---|
| 449 | { | 
|---|
| 450 | dprintf(("WARNING: GetViewportExtEx %x %x -> INVALID HDC", hdc, pSize)); | 
|---|
| 451 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 452 | return FALSE; | 
|---|
| 453 | } | 
|---|
| 454 |  | 
|---|
| 455 | if(!pSize) | 
|---|
| 456 | { | 
|---|
| 457 | dprintf(("WARNING: GetViewportExtEx %x NULL -> INVALID parameter", hdc)); | 
|---|
| 458 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 459 | return FALSE; | 
|---|
| 460 | } | 
|---|
| 461 |  | 
|---|
| 462 | pSize->cx = (LONG)pHps->viewportXExt; | 
|---|
| 463 | pSize->cy = (LONG)pHps->viewportYExt; | 
|---|
| 464 | dprintf(("GDI32: GetViewportExtEx %x -> (%d,%d)", hdc, pSize->cx, pSize->cy)); | 
|---|
| 465 |  | 
|---|
| 466 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 467 | return TRUE; | 
|---|
| 468 | } | 
|---|
| 469 | //****************************************************************************** | 
|---|
| 470 | //****************************************************************************** | 
|---|
| 471 | BOOL WIN32API SetViewportOrgEx(HDC hdc, int xOrg, int yOrg, LPPOINT pPoint) | 
|---|
| 472 | { | 
|---|
| 473 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 474 |  | 
|---|
| 475 | if(pHps) | 
|---|
| 476 | { | 
|---|
| 477 | if(changePageXForm(pHps, (PPOINTL) &pHps->viewportOrg, xOrg, | 
|---|
| 478 | yOrg, (PPOINTL) pPoint)) | 
|---|
| 479 | { | 
|---|
| 480 | //todo: metafile recording!!! | 
|---|
| 481 | dprintf(("SetViewPortOrgEx: %x (%d,%d), %x", hdc, xOrg, yOrg, pPoint)); | 
|---|
| 482 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 483 | return TRUE; | 
|---|
| 484 | } | 
|---|
| 485 | dprintf(("WARNING: SetViewPortOrgEx: %x (%d,%d) %x-> changePageXForm failed!!!, %x", hdc, xOrg, yOrg, pPoint)); | 
|---|
| 486 | SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error | 
|---|
| 487 | return FALSE; | 
|---|
| 488 | } | 
|---|
| 489 |  | 
|---|
| 490 | dprintf(("WARNING: SetViewPortOrgEx: HDC %x not found!!", hdc)); | 
|---|
| 491 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 492 | return FALSE; | 
|---|
| 493 | } | 
|---|
| 494 | //****************************************************************************** | 
|---|
| 495 | //****************************************************************************** | 
|---|
| 496 | BOOL WIN32API GetViewportOrgEx(HDC hdc, LPPOINT pPoint) | 
|---|
| 497 | { | 
|---|
| 498 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 499 | if(!pHps) | 
|---|
| 500 | { | 
|---|
| 501 | dprintf(("WARNING: GetViewportOrgEx %x %x -> INVALID HDC", hdc, pPoint)); | 
|---|
| 502 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 503 | return FALSE; | 
|---|
| 504 | } | 
|---|
| 505 |  | 
|---|
| 506 | if(!pPoint) | 
|---|
| 507 | { | 
|---|
| 508 | dprintf(("WARNING: GetViewportOrgEx %x NULL -> INVALID parameter", hdc)); | 
|---|
| 509 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 510 | return FALSE; | 
|---|
| 511 | } | 
|---|
| 512 |  | 
|---|
| 513 | pPoint->x = pHps->viewportOrg.x; | 
|---|
| 514 | pPoint->y = pHps->viewportOrg.y; | 
|---|
| 515 |  | 
|---|
| 516 | dprintf(("GDI32: GetViewportOrgEx %x -> (%d,%d)", hdc, pPoint->x, pPoint->y)); | 
|---|
| 517 |  | 
|---|
| 518 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 519 | return TRUE; | 
|---|
| 520 | } | 
|---|
| 521 | //****************************************************************************** | 
|---|
| 522 | //****************************************************************************** | 
|---|
| 523 | BOOL WIN32API SetWindowExtEx(HDC hdc, int xExt, int yExt, LPSIZE pSize) | 
|---|
| 524 | { | 
|---|
| 525 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 526 | if(!pHps) | 
|---|
| 527 | { | 
|---|
| 528 | dprintf(("WARNING: SetWindowExtEx: HDC %x not found!!", hdc)); | 
|---|
| 529 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 530 | return FALSE; | 
|---|
| 531 | } | 
|---|
| 532 |  | 
|---|
| 533 | if(xExt && yExt) | 
|---|
| 534 | { | 
|---|
| 535 | //todo: metafile recording!!! (always) | 
|---|
| 536 |  | 
|---|
| 537 | if(pHps->MapMode == MM_ISOTROPIC_W || pHps->MapMode == MM_ANISOTROPIC_W) | 
|---|
| 538 | { | 
|---|
| 539 | if(changePageXForm(pHps, (PPOINTL) &pHps->windowExt, | 
|---|
| 540 | xExt, yExt, (PPOINTL) pSize) ) | 
|---|
| 541 | { | 
|---|
| 542 | dprintf(("SetWindowExtEx: %x (%d,%d), %x", hdc, xExt, yExt, pSize)); | 
|---|
| 543 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 544 | return TRUE; | 
|---|
| 545 | } | 
|---|
| 546 | dprintf(("WARNING: SetWindowExtEx: %x (%d,%d) -> changePageXForm failed!!!, %x", hdc, xExt, yExt, pSize)); | 
|---|
| 547 | SetLastError(ERROR_INVALID_PARAMETER_W);    //TODO: translate PM error | 
|---|
| 548 | return FALSE; | 
|---|
| 549 | } | 
|---|
| 550 | else | 
|---|
| 551 | { | 
|---|
| 552 | pHps->lWndXExtSave = xExt, pHps->lWndYExtSave = yExt; | 
|---|
| 553 |  | 
|---|
| 554 | //function is a no-op if map mode is not (AN)ISOTROPIC; NT returns TRUE | 
|---|
| 555 | dprintf(("SetWindowExtEx: %x (%d,%d), %x", hdc, xExt, yExt, pSize)); | 
|---|
| 556 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 557 | return TRUE; | 
|---|
| 558 | } | 
|---|
| 559 | } | 
|---|
| 560 | dprintf(("WARNING: SetWindowExtEx %x (%d,%d) %x; invalid parameter", hdc, xExt, yExt, pSize)); | 
|---|
| 561 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 562 | return FALSE; | 
|---|
| 563 | } | 
|---|
| 564 | //****************************************************************************** | 
|---|
| 565 | //****************************************************************************** | 
|---|
| 566 | BOOL WIN32API GetWindowExtEx(HDC hdc, LPSIZE pSize) | 
|---|
| 567 | { | 
|---|
| 568 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 569 | if(!pHps) | 
|---|
| 570 | { | 
|---|
| 571 | dprintf(("WARNING: GetWindowExtEx %x %x -> INVALID HDC", hdc, pSize)); | 
|---|
| 572 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 573 | return FALSE; | 
|---|
| 574 | } | 
|---|
| 575 |  | 
|---|
| 576 | if(!pSize) | 
|---|
| 577 | { | 
|---|
| 578 | dprintf(("WARNING: GetWindowExtEx %x NULL -> INVALID parameter", hdc)); | 
|---|
| 579 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 580 | return FALSE; | 
|---|
| 581 | } | 
|---|
| 582 |  | 
|---|
| 583 | pSize->cx = pHps->windowExt.cx; | 
|---|
| 584 | pSize->cy = pHps->windowExt.cy; | 
|---|
| 585 |  | 
|---|
| 586 | dprintf(("GDI32: GetWindowExtEx %x -> (%d,%d)", hdc, pSize->cx, pSize->cy)); | 
|---|
| 587 |  | 
|---|
| 588 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 589 | return TRUE; | 
|---|
| 590 | } | 
|---|
| 591 | //****************************************************************************** | 
|---|
| 592 | //****************************************************************************** | 
|---|
| 593 | BOOL WIN32API SetWindowOrgEx(HDC hdc, int xOrg, int yOrg, LPPOINT pPoint) | 
|---|
| 594 | { | 
|---|
| 595 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 596 | if(pHps) | 
|---|
| 597 | { | 
|---|
| 598 | if(changePageXForm(pHps, (PPOINTL) &pHps->windowOrg, xOrg, | 
|---|
| 599 | yOrg, (PPOINTL) pPoint)) | 
|---|
| 600 | { | 
|---|
| 601 | //todo: metafile recording!!! | 
|---|
| 602 |  | 
|---|
| 603 | dprintf(("SetWindowOrgEx: %x (%d,%d), %x", hdc, xOrg, yOrg, pPoint)); | 
|---|
| 604 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 605 | return TRUE; | 
|---|
| 606 | } | 
|---|
| 607 | //todo: set correct error | 
|---|
| 608 | dprintf(("WARNING: SetWindowOrgEx: %x (%d,%d) %x -> changePageXForm failed!!!, %x", hdc, xOrg, yOrg, pPoint)); | 
|---|
| 609 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 610 | return FALSE; | 
|---|
| 611 | } | 
|---|
| 612 | dprintf(("WARNING: SetWindowOrgEx: HDC %x not found!!", hdc)); | 
|---|
| 613 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 614 | return FALSE; | 
|---|
| 615 | } | 
|---|
| 616 | //****************************************************************************** | 
|---|
| 617 | //****************************************************************************** | 
|---|
| 618 | BOOL WIN32API GetWindowOrgEx(HDC hdc, LPPOINT pPoint) | 
|---|
| 619 | { | 
|---|
| 620 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 621 | if(!pHps) | 
|---|
| 622 | { | 
|---|
| 623 | dprintf(("WARNING: GetWindowOrgEx %x %x -> INVALID HDC", hdc, pPoint)); | 
|---|
| 624 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 625 | return FALSE; | 
|---|
| 626 | } | 
|---|
| 627 |  | 
|---|
| 628 | if(!pPoint) | 
|---|
| 629 | { | 
|---|
| 630 | dprintf(("WARNING: GetWindowOrgEx %x NULL -> INVALID parameter", hdc)); | 
|---|
| 631 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 632 | return FALSE; | 
|---|
| 633 | } | 
|---|
| 634 |  | 
|---|
| 635 | pPoint->x = pHps->windowOrg.x; | 
|---|
| 636 | pPoint->y = pHps->windowOrg.y; | 
|---|
| 637 |  | 
|---|
| 638 | dprintf(("GDI32: GetWindowOrgEx %x -> (%d,%d)", hdc, pPoint->x, pPoint->y)); | 
|---|
| 639 |  | 
|---|
| 640 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 641 | return TRUE; | 
|---|
| 642 | } | 
|---|
| 643 | //****************************************************************************** | 
|---|
| 644 | //****************************************************************************** | 
|---|
| 645 | int WIN32API SetGraphicsMode(HDC hdc, int iMode) | 
|---|
| 646 | { | 
|---|
| 647 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 648 | if(!pHps) | 
|---|
| 649 | { | 
|---|
| 650 | dprintf(("WARNING: SetGraphicsMode HDC %x NOT FOUND!!", hdc)); | 
|---|
| 651 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 652 | return 0; | 
|---|
| 653 | } | 
|---|
| 654 |  | 
|---|
| 655 | if(iMode != GM_COMPATIBLE_W  && iMode != GM_ADVANCED_W) | 
|---|
| 656 | { | 
|---|
| 657 | dprintf(("WARNING: SetGraphicsMode invalid mode %x!!", iMode)); | 
|---|
| 658 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 659 | return 0; | 
|---|
| 660 | } | 
|---|
| 661 |  | 
|---|
| 662 | //Only switch from GM_ADVANCED_W to GM_COMPATIBLE_W if default matrix is active | 
|---|
| 663 | if (iMode == GM_COMPATIBLE_W  &&  pHps->graphicsMode == GM_ADVANCED_W) | 
|---|
| 664 | { | 
|---|
| 665 | MATRIXLF matrixlf; | 
|---|
| 666 |  | 
|---|
| 667 | if(!GpiQueryModelTransformMatrix(pHps->hps, 9, &matrixlf)) | 
|---|
| 668 | { | 
|---|
| 669 | dprintf(("WARNING: SetGraphicsMode %x %d; GpiQueryModelTransformMatrix failed!", hdc, iMode)); | 
|---|
| 670 | SetLastError(ERROR_INVALID_PARAMETER_W);  //todo translate PM error!! | 
|---|
| 671 | return 0; | 
|---|
| 672 |  | 
|---|
| 673 | } | 
|---|
| 674 |  | 
|---|
| 675 | if (!(matrixlf.fxM11 == MAKEFIXED(1,0) && matrixlf.fxM12 == MAKEFIXED(0,0) && | 
|---|
| 676 | matrixlf.fxM21 == MAKEFIXED(0,0) && matrixlf.fxM22 == MAKEFIXED(1,0) && | 
|---|
| 677 | matrixlf.lM31  == 0 && matrixlf.lM32  == 0 )) | 
|---|
| 678 | { | 
|---|
| 679 | dprintf(("WARNING: SetGraphicsMode %x %d; can't complete!", hdc, iMode)); | 
|---|
| 680 | SetLastError(ERROR_CAN_NOT_COMPLETE_W);  // done by NT | 
|---|
| 681 | return 0; | 
|---|
| 682 | } | 
|---|
| 683 | } | 
|---|
| 684 | int oldMode = pHps->graphicsMode; | 
|---|
| 685 |  | 
|---|
| 686 | dprintf(("SetGraphicsMode %x %d (old mode %d)", hdc, iMode, oldMode)); | 
|---|
| 687 | pHps->graphicsMode = iMode; | 
|---|
| 688 |  | 
|---|
| 689 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 690 | return oldMode; | 
|---|
| 691 | } | 
|---|
| 692 | //****************************************************************************** | 
|---|
| 693 | //****************************************************************************** | 
|---|
| 694 | int WIN32API GetGraphicsMode(HDC hdc) | 
|---|
| 695 | { | 
|---|
| 696 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 697 | if (!pHps) | 
|---|
| 698 | { | 
|---|
| 699 | dprintf(("WARNING: GetGraphicsMode HDC %x NOT FOUND!!", hdc)); | 
|---|
| 700 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 701 | return 0; | 
|---|
| 702 | } | 
|---|
| 703 |  | 
|---|
| 704 | dprintf(("GetGraphicsMode %x = %x", hdc, pHps->graphicsMode)); | 
|---|
| 705 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 706 | return pHps->graphicsMode; | 
|---|
| 707 | } | 
|---|
| 708 | //****************************************************************************** | 
|---|
| 709 | //****************************************************************************** | 
|---|