| 1 | /* $Id: region.cpp,v 1.40 2004-02-16 15:20:12 sandervl Exp $ */ | 
|---|
| 2 |  | 
|---|
| 3 | /* | 
|---|
| 4 | * GDI32 region code | 
|---|
| 5 | * | 
|---|
| 6 | * Copyright 1998-2000 Sander van Leeuwen (sandervl@xs4all.nl) | 
|---|
| 7 | * Copyright 1998 Patrick Haller | 
|---|
| 8 | * Copyright 2002-2003 Innotek Systemberatung GmbH (sandervl@innotek.de) | 
|---|
| 9 | * | 
|---|
| 10 | * TODO: Metafile recording | 
|---|
| 11 | * TODO: Do we need to translate & set the last error for Gpi operations? | 
|---|
| 12 | * | 
|---|
| 13 | * | 
|---|
| 14 | * NOTE: In windows there is a clip and a visible region (just like in PM) | 
|---|
| 15 | *       We do not map the Win32 visible region to the PM visible region | 
|---|
| 16 | *       as that's rather annoying. | 
|---|
| 17 | *       Instead we use the intersection of the win32 visible and win32 clip | 
|---|
| 18 | *       region for the PM clip region. | 
|---|
| 19 | *       The original Win32 clip region is saved in pHps->hrgnWin32Clip. | 
|---|
| 20 | *       The Win32 visible region is saved in pHps->hrgnWinVis. | 
|---|
| 21 | * | 
|---|
| 22 | * | 
|---|
| 23 | * | 
|---|
| 24 | * Project Odin Software License can be found in LICENSE.TXT | 
|---|
| 25 | * | 
|---|
| 26 | */ | 
|---|
| 27 |  | 
|---|
| 28 | #define  INCL_GPI | 
|---|
| 29 | #define  INCL_WIN | 
|---|
| 30 | #include <os2wrap.h> //need odin wrappers | 
|---|
| 31 |  | 
|---|
| 32 | #include <win32type.h> | 
|---|
| 33 | #include <win32api.h> | 
|---|
| 34 | #include <winconst.h> | 
|---|
| 35 | #include <stdlib.h> | 
|---|
| 36 | #include <stdarg.h> | 
|---|
| 37 | #include <string.h> | 
|---|
| 38 | #include <misc.h> | 
|---|
| 39 | #include <objhandle.h> | 
|---|
| 40 | #include <dcdata.h> | 
|---|
| 41 | #include <winuser32.h> | 
|---|
| 42 | #include "oslibgpi.h" | 
|---|
| 43 | #include <stats.h> | 
|---|
| 44 | #include "dibsect.h" | 
|---|
| 45 | #include <wingdi32.h> | 
|---|
| 46 |  | 
|---|
| 47 | #define DBG_LOCALLOG    DBG_region | 
|---|
| 48 | #include "dbglocal.h" | 
|---|
| 49 |  | 
|---|
| 50 | //GPI and Windows use the same values | 
|---|
| 51 | #define GPI_TO_WIN_COMPLEXITY(a)        a | 
|---|
| 52 |  | 
|---|
| 53 | typedef enum | 
|---|
| 54 | { | 
|---|
| 55 | AS_DEVICE, | 
|---|
| 56 | AS_WORLD | 
|---|
| 57 | } InterpMode; | 
|---|
| 58 |  | 
|---|
| 59 | #define MEM_HPS_MAX 768 | 
|---|
| 60 |  | 
|---|
| 61 | int WIN32API OffsetRgn( HRGN  hrgn, int  xOffset, int  yOffset); | 
|---|
| 62 |  | 
|---|
| 63 | static void convertDeviceRect(HWND hwnd, pDCData pHps, PRECTL pRectl, ULONG count); | 
|---|
| 64 |  | 
|---|
| 65 | #define convertWinDeviceRectToPMDeviceRect(arg1, arg2, arg3) convertDeviceRect(arg1, arg2, arg3) | 
|---|
| 66 | #define convertPMDeviceRectToWinDeviceRect(arg1, arg2, arg3) convertDeviceRect(arg1, arg2, arg3) | 
|---|
| 67 |  | 
|---|
| 68 | inline void convertDeviceRect(pDCData pHps, PRECTL pRectl, ULONG count) | 
|---|
| 69 | { | 
|---|
| 70 | convertDeviceRect(0, pHps, pRectl, count); | 
|---|
| 71 | } | 
|---|
| 72 | inline void convertDeviceRect(HWND hwnd, PRECTL pRectl, ULONG count) | 
|---|
| 73 | { | 
|---|
| 74 | convertDeviceRect(hwnd, 0, pRectl, count); | 
|---|
| 75 | } | 
|---|
| 76 |  | 
|---|
| 77 | HPS hpsRegion = 0; | 
|---|
| 78 |  | 
|---|
| 79 |  | 
|---|
| 80 | #ifdef DEBUG | 
|---|
| 81 | //#define dprintfRegion(a,b,c) if(DbgEnabledLvl2GDI32[DBG_LOCALLOG] == 1) dprintfRegion1(a,b,c) | 
|---|
| 82 | //#define dprintfRegion(a,b,c) dprintfRegion1(a,b,c) | 
|---|
| 83 |  | 
|---|
| 84 | void dprintfRegion(HPS hps, HRGN hrgnClip) | 
|---|
| 85 | { | 
|---|
| 86 | RGNRECT rgnRect = {0, 16, 0, RECTDIR_LFRT_TOPBOT}; | 
|---|
| 87 | RECTL   rectRegion[16]; | 
|---|
| 88 | APIRET  rc; | 
|---|
| 89 |  | 
|---|
| 90 | dprintf(("dprintfRegion %x", hps)); | 
|---|
| 91 | rc = GpiQueryRegionRects(hps, hrgnClip, NULL, &rgnRect, &rectRegion[0]); | 
|---|
| 92 | for(int i=0;i<rgnRect.crcReturned;i++) { | 
|---|
| 93 | dprintf(("(%d,%d)(%d,%d)", rectRegion[i].xLeft, rectRegion[i].yBottom, rectRegion[i].xRight, rectRegion[i].yTop)); | 
|---|
| 94 | } | 
|---|
| 95 | } | 
|---|
| 96 | #else | 
|---|
| 97 | #define dprintfRegion(a,c) | 
|---|
| 98 | #endif | 
|---|
| 99 |  | 
|---|
| 100 | //****************************************************************************** | 
|---|
| 101 | //****************************************************************************** | 
|---|
| 102 | BOOL InitRegionSpace() | 
|---|
| 103 | { | 
|---|
| 104 | hpsRegion = WinGetScreenPS(HWND_DESKTOP); | 
|---|
| 105 | return hpsRegion != 0; | 
|---|
| 106 | } | 
|---|
| 107 | //****************************************************************************** | 
|---|
| 108 | //****************************************************************************** | 
|---|
| 109 | void DestroyRegionSpace() | 
|---|
| 110 | { | 
|---|
| 111 | if(hpsRegion) WinReleasePS(hpsRegion); | 
|---|
| 112 | hpsRegion = 0; | 
|---|
| 113 | } | 
|---|
| 114 | //****************************************************************************** | 
|---|
| 115 | //****************************************************************************** | 
|---|
| 116 | LONG hdcHeight(HWND hwnd, pDCData pHps) | 
|---|
| 117 | { | 
|---|
| 118 | if(hwnd == 0 && pHps != 0) | 
|---|
| 119 | hwnd = pHps->hwnd; | 
|---|
| 120 |  | 
|---|
| 121 | if(hwnd != 0 || pHps == 0) | 
|---|
| 122 | { | 
|---|
| 123 | RECT rect; | 
|---|
| 124 | RECTL rectl; | 
|---|
| 125 | LONG y = 0; | 
|---|
| 126 |  | 
|---|
| 127 | if(pHps && pHps->isClient) //client area | 
|---|
| 128 | { | 
|---|
| 129 | if(GetClientRect(OS2ToWin32Handle(hwnd), &rect) == TRUE) { | 
|---|
| 130 | y = rect.bottom - rect.top; | 
|---|
| 131 | } | 
|---|
| 132 | } | 
|---|
| 133 | else | 
|---|
| 134 | if(WinQueryWindowRect(hwnd, &rectl))    //whole window | 
|---|
| 135 | y = rectl.yTop; | 
|---|
| 136 |  | 
|---|
| 137 | return y; | 
|---|
| 138 | } | 
|---|
| 139 | else | 
|---|
| 140 | if(pHps->bitmapHandle) | 
|---|
| 141 | { | 
|---|
| 142 | return pHps->bitmapHeight; | 
|---|
| 143 | } | 
|---|
| 144 | else | 
|---|
| 145 | if(pHps->isMetaPS) | 
|---|
| 146 | { | 
|---|
| 147 | return 0; | 
|---|
| 148 | } | 
|---|
| 149 | else | 
|---|
| 150 | if(pHps->isPrinter) | 
|---|
| 151 | { | 
|---|
| 152 | return GetDeviceCaps(pHps->hps, VERTRES_W); | 
|---|
| 153 | } | 
|---|
| 154 | else | 
|---|
| 155 | { | 
|---|
| 156 | return MEM_HPS_MAX; | 
|---|
| 157 | } | 
|---|
| 158 | } | 
|---|
| 159 | //****************************************************************************** | 
|---|
| 160 | //****************************************************************************** | 
|---|
| 161 | LONG hdcWidth(HWND hwnd, pDCData pHps) | 
|---|
| 162 | { | 
|---|
| 163 | if(hwnd == 0 && pHps != 0) | 
|---|
| 164 | hwnd = pHps->hwnd; | 
|---|
| 165 |  | 
|---|
| 166 | if(hwnd != 0 || pHps == 0) | 
|---|
| 167 | { | 
|---|
| 168 | RECT rect; | 
|---|
| 169 | RECTL rectl; | 
|---|
| 170 | LONG x = 0; | 
|---|
| 171 |  | 
|---|
| 172 | if(pHps && pHps->isClient) //client area | 
|---|
| 173 | { | 
|---|
| 174 | if(GetClientRect(OS2ToWin32Handle(hwnd), &rect) == TRUE) { | 
|---|
| 175 | x = rect.right - rect.left; | 
|---|
| 176 | } | 
|---|
| 177 | } | 
|---|
| 178 | else | 
|---|
| 179 | if(WinQueryWindowRect(hwnd, &rectl))    //whole window | 
|---|
| 180 | x = rectl.xRight; | 
|---|
| 181 |  | 
|---|
| 182 | return x; | 
|---|
| 183 | } | 
|---|
| 184 | else | 
|---|
| 185 | if(pHps->bitmapHandle) | 
|---|
| 186 | { | 
|---|
| 187 | return pHps->bitmapWidth; | 
|---|
| 188 | } | 
|---|
| 189 | else | 
|---|
| 190 | if(pHps->isMetaPS) | 
|---|
| 191 | { | 
|---|
| 192 | return 0; | 
|---|
| 193 | } | 
|---|
| 194 | else | 
|---|
| 195 | if(pHps->isPrinter) | 
|---|
| 196 | { | 
|---|
| 197 | return GetDeviceCaps(pHps->hps, HORZRES_W); | 
|---|
| 198 | } | 
|---|
| 199 | //   else | 
|---|
| 200 | //     DebugInt3(); | 
|---|
| 201 | return 0; | 
|---|
| 202 | } | 
|---|
| 203 | //****************************************************************************** | 
|---|
| 204 | //****************************************************************************** | 
|---|
| 205 | static void convertWinWorldRectToPMDeviceRect(pDCData pHps_Hdc, PRECTL pRects, UINT count = 1) | 
|---|
| 206 | { | 
|---|
| 207 | PRECTL pRectl; | 
|---|
| 208 | for (int x=0; x < count; x++) | 
|---|
| 209 | { | 
|---|
| 210 | pRectl = &pRects[x]; | 
|---|
| 211 |  | 
|---|
| 212 | if(pRectl->yTop < pRectl->yBottom) { | 
|---|
| 213 | ULONG temp      = pRectl->yBottom; | 
|---|
| 214 | pRectl->yBottom = pRectl->yTop; | 
|---|
| 215 | pRectl->yTop    = temp; | 
|---|
| 216 | } | 
|---|
| 217 | BOOL success = GpiConvert( pHps_Hdc->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)pRectl); | 
|---|
| 218 | if(!success) | 
|---|
| 219 | { | 
|---|
| 220 | break; | 
|---|
| 221 | } | 
|---|
| 222 | if(pRectl->yTop < pRectl->yBottom) { | 
|---|
| 223 | ULONG temp      = pRectl->yBottom; | 
|---|
| 224 | pRectl->yBottom = pRectl->yTop; | 
|---|
| 225 | pRectl->yTop    = temp; | 
|---|
| 226 | } | 
|---|
| 227 | } | 
|---|
| 228 | } | 
|---|
| 229 | //****************************************************************************** | 
|---|
| 230 | //****************************************************************************** | 
|---|
| 231 | static void convertDeviceRect(HWND hwnd, pDCData pHps, PRECTL pRectl, ULONG count) | 
|---|
| 232 | { | 
|---|
| 233 | long wHeight, wWidth; | 
|---|
| 234 |  | 
|---|
| 235 | if(hwnd == HWND_DESKTOP) { | 
|---|
| 236 | wHeight = OSLibGetScreenHeight(); | 
|---|
| 237 | wWidth  = OSLibGetScreenWidth(); | 
|---|
| 238 | } | 
|---|
| 239 | else { | 
|---|
| 240 | wHeight = hdcHeight(hwnd, pHps); | 
|---|
| 241 | wWidth  = hdcWidth(hwnd, pHps); | 
|---|
| 242 | } | 
|---|
| 243 |  | 
|---|
| 244 | if(pHps) | 
|---|
| 245 | { | 
|---|
| 246 | wHeight += pHps->HPStoHDCInversionHeight; | 
|---|
| 247 | } | 
|---|
| 248 |  | 
|---|
| 249 | if(hwnd || (pHps && pHps->hwnd)) { | 
|---|
| 250 | for(int x=0; x < count; x++) | 
|---|
| 251 | { | 
|---|
| 252 | if(pRectl[x].xRight > wWidth) { | 
|---|
| 253 | pRectl[x].xRight = wWidth; | 
|---|
| 254 | } | 
|---|
| 255 | if(pRectl[x].yTop > wHeight) { | 
|---|
| 256 | pRectl[x].yTop = 0; | 
|---|
| 257 | } | 
|---|
| 258 | else pRectl[x].yTop    = wHeight - pRectl[x].yTop; | 
|---|
| 259 |  | 
|---|
| 260 | pRectl[x].yBottom = wHeight - pRectl[x].yBottom; | 
|---|
| 261 | } | 
|---|
| 262 | } | 
|---|
| 263 | else { | 
|---|
| 264 | for(int x=0; x < count; x++) | 
|---|
| 265 | { | 
|---|
| 266 | pRectl[x].yTop    = wHeight - pRectl[x].yTop; | 
|---|
| 267 | pRectl[x].yBottom = wHeight - pRectl[x].yBottom; | 
|---|
| 268 | } | 
|---|
| 269 | } | 
|---|
| 270 | } | 
|---|
| 271 | //****************************************************************************** | 
|---|
| 272 | //****************************************************************************** | 
|---|
| 273 | static void convertPMDeviceRectToWinWorldRect(pDCData pHps_Hdc, PRECTL pRectl) | 
|---|
| 274 | { | 
|---|
| 275 | GpiConvert(pHps_Hdc->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)pRectl ); | 
|---|
| 276 | } | 
|---|
| 277 | //****************************************************************************** | 
|---|
| 278 | //****************************************************************************** | 
|---|
| 279 | BOOL interpretRegionAs(pDCData pHps, HRGN hrgnDest, HRGN hrgnSrc, InterpMode mode) | 
|---|
| 280 | { | 
|---|
| 281 | BOOL success = FALSE; | 
|---|
| 282 | int  x, i; | 
|---|
| 283 | HPS  hpsDest; | 
|---|
| 284 |  | 
|---|
| 285 | if(pHps) | 
|---|
| 286 | { | 
|---|
| 287 | if(!hrgnDest) { | 
|---|
| 288 | hrgnDest = pHps->hrgnHDC; | 
|---|
| 289 | #ifdef DEBUG | 
|---|
| 290 | if(hrgnDest == 0) { | 
|---|
| 291 | DebugInt3(); | 
|---|
| 292 | } | 
|---|
| 293 | #endif | 
|---|
| 294 | } | 
|---|
| 295 | hpsDest  = pHps->hps; | 
|---|
| 296 | } | 
|---|
| 297 | else { | 
|---|
| 298 | DebugInt3(); | 
|---|
| 299 | return FALSE; | 
|---|
| 300 | } | 
|---|
| 301 |  | 
|---|
| 302 | RGNRECT  rgnRect; | 
|---|
| 303 | rgnRect.ircStart    = 1; | 
|---|
| 304 | rgnRect.crc         = 0; | 
|---|
| 305 | rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT; | 
|---|
| 306 | success = GpiQueryRegionRects(hpsRegion, hrgnSrc, NULL, &rgnRect, NULL); | 
|---|
| 307 | if(success) | 
|---|
| 308 | { | 
|---|
| 309 | if(rgnRect.crcReturned > 0) | 
|---|
| 310 | { | 
|---|
| 311 | rgnRect.crc = rgnRect.crcReturned; | 
|---|
| 312 | PRECTL pRectl = new RECTL[rgnRect.crcReturned]; | 
|---|
| 313 | success = GpiQueryRegionRects(hpsRegion, hrgnSrc, NULL, &rgnRect, pRectl); | 
|---|
| 314 | if(success) | 
|---|
| 315 | { | 
|---|
| 316 | if(mode == AS_DEVICE) | 
|---|
| 317 | { | 
|---|
| 318 | ULONG temp; | 
|---|
| 319 | for(x=0; x < rgnRect.crcReturned; x++) | 
|---|
| 320 | { | 
|---|
| 321 | temp = pRectl[x].yBottom; | 
|---|
| 322 | pRectl[x].yBottom = pRectl[x].yTop; | 
|---|
| 323 | pRectl[x].yTop    = temp; | 
|---|
| 324 | } | 
|---|
| 325 | convertWinDeviceRectToPMDeviceRect(pHps, pRectl, rgnRect.crcReturned); | 
|---|
| 326 | } | 
|---|
| 327 | else | 
|---|
| 328 | { | 
|---|
| 329 | GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, rgnRect.crcReturned<<1, (PPOINTL)pRectl); | 
|---|
| 330 |  | 
|---|
| 331 | ULONG temp; | 
|---|
| 332 | for(i=0; i < rgnRect.crcReturned; i++) | 
|---|
| 333 | { | 
|---|
| 334 | if(pRectl[i].yTop < pRectl[i].yBottom) | 
|---|
| 335 | { | 
|---|
| 336 | temp              = pRectl[i].yBottom + 1; | 
|---|
| 337 | pRectl[i].yBottom = pRectl[i].yTop + 1; | 
|---|
| 338 | pRectl[i].yTop    = temp; | 
|---|
| 339 | } | 
|---|
| 340 | else | 
|---|
| 341 | { | 
|---|
| 342 | pRectl[i].yTop++; | 
|---|
| 343 | pRectl[i].yBottom++; | 
|---|
| 344 | } | 
|---|
| 345 | } | 
|---|
| 346 | } | 
|---|
| 347 | success = GpiSetRegion(hpsDest, hrgnDest, rgnRect.crcReturned, pRectl); | 
|---|
| 348 | } | 
|---|
| 349 | delete[] pRectl; | 
|---|
| 350 | } | 
|---|
| 351 | else | 
|---|
| 352 | { | 
|---|
| 353 | success = GpiSetRegion(hpsDest, hrgnDest, 0, NULL); | 
|---|
| 354 | } | 
|---|
| 355 | } | 
|---|
| 356 | return success; | 
|---|
| 357 | } | 
|---|
| 358 | //****************************************************************************** | 
|---|
| 359 | //exported (used by user32) | 
|---|
| 360 | //****************************************************************************** | 
|---|
| 361 | BOOL WIN32API setWinDeviceRegionFromPMDeviceRegion(HRGN winHrgn, HRGN pmHrgn, pDCData pHpsPmHrgn, HWND hwndPmHrgn) | 
|---|
| 362 | { | 
|---|
| 363 | BOOL    success; | 
|---|
| 364 | int     x; | 
|---|
| 365 | BOOL    mustReleaseScreenPS = FALSE; | 
|---|
| 366 | HPS     hps; | 
|---|
| 367 |  | 
|---|
| 368 | if(pHpsPmHrgn || hwndPmHrgn) | 
|---|
| 369 | { | 
|---|
| 370 | if(pHpsPmHrgn) | 
|---|
| 371 | hps = pHpsPmHrgn->hps; | 
|---|
| 372 | else | 
|---|
| 373 | { | 
|---|
| 374 | hps = WinGetScreenPS(HWND_DESKTOP); | 
|---|
| 375 | mustReleaseScreenPS = TRUE; | 
|---|
| 376 | } | 
|---|
| 377 |  | 
|---|
| 378 | RGNRECT  rgnRect; | 
|---|
| 379 | rgnRect.ircStart    = 1; | 
|---|
| 380 | rgnRect.crc         = 0; | 
|---|
| 381 | rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT; | 
|---|
| 382 | success = GpiQueryRegionRects(hps, pmHrgn, NULL, &rgnRect, NULL); | 
|---|
| 383 | if(success ) | 
|---|
| 384 | { | 
|---|
| 385 | if(rgnRect.crcReturned > 0) | 
|---|
| 386 | { | 
|---|
| 387 | rgnRect.crc = rgnRect.crcReturned; | 
|---|
| 388 | PRECTL pRectl = new RECTL[rgnRect.crcReturned]; | 
|---|
| 389 | success = GpiQueryRegionRects(hps, pmHrgn, NULL, &rgnRect, pRectl); | 
|---|
| 390 | if(success) | 
|---|
| 391 | { | 
|---|
| 392 | if(pHpsPmHrgn) | 
|---|
| 393 | convertPMDeviceRectToWinDeviceRect(pHpsPmHrgn, pRectl, rgnRect.crcReturned); | 
|---|
| 394 | else | 
|---|
| 395 | convertPMDeviceRectToWinDeviceRect(hwndPmHrgn, pRectl, rgnRect.crcReturned); | 
|---|
| 396 |  | 
|---|
| 397 | for(x=0; x < rgnRect.crcReturned; x++) | 
|---|
| 398 | { | 
|---|
| 399 | ULONG temp         = pRectl[x].yBottom; | 
|---|
| 400 | pRectl[x].yBottom  = pRectl[x].yTop; | 
|---|
| 401 | pRectl[x].yTop     = temp; | 
|---|
| 402 | } | 
|---|
| 403 |  | 
|---|
| 404 | success = GpiSetRegion(hpsRegion, winHrgn, rgnRect.crcReturned, pRectl); | 
|---|
| 405 | } | 
|---|
| 406 | delete[] pRectl; | 
|---|
| 407 | } | 
|---|
| 408 | else | 
|---|
| 409 | { | 
|---|
| 410 | success = GpiSetRegion(hpsRegion, winHrgn, 0, NULL); | 
|---|
| 411 | } | 
|---|
| 412 | } | 
|---|
| 413 | } | 
|---|
| 414 | else | 
|---|
| 415 | success = FALSE; | 
|---|
| 416 |  | 
|---|
| 417 | if(mustReleaseScreenPS) | 
|---|
| 418 | WinReleasePS(hps); | 
|---|
| 419 |  | 
|---|
| 420 | return success; | 
|---|
| 421 | } | 
|---|
| 422 | //****************************************************************************** | 
|---|
| 423 | // GdiSetVisRgn | 
|---|
| 424 | // | 
|---|
| 425 | // Change the Win32 visible region to the specified region | 
|---|
| 426 | // | 
|---|
| 427 | // Parameters: | 
|---|
| 428 | // | 
|---|
| 429 | // pDCData pHps         - presentation space structure | 
|---|
| 430 | // HRGN hrgn            - region handle (GPI) | 
|---|
| 431 | // | 
|---|
| 432 | // | 
|---|
| 433 | // Returns:     - ERROR_W         -> failure | 
|---|
| 434 | //              - NULLREGION_W    -> empty region | 
|---|
| 435 | //              - SIMPLEREGION_W  -> rectangular region | 
|---|
| 436 | //              - COMPLEXREGION_W -> complex region | 
|---|
| 437 | // | 
|---|
| 438 | // NOTE: In windows there is a clip and a visible region (just like in PM) | 
|---|
| 439 | //       We do not map the Win32 visible region to the PM visible region | 
|---|
| 440 | //       as that's rather annoying. | 
|---|
| 441 | //       Instead we use the intersection of the win32 visible and win32 clip | 
|---|
| 442 | //       region for the PM clip region. | 
|---|
| 443 | //       The Win32 clip region is saved in pHps->hrgnWin32Clip. | 
|---|
| 444 | //       The Win32 visible region is saved in pHps->hrgnWinVis. | 
|---|
| 445 | // | 
|---|
| 446 | //****************************************************************************** | 
|---|
| 447 | INT WIN32API GdiSetVisRgn(pDCData pHps, HRGN hrgn) | 
|---|
| 448 | { | 
|---|
| 449 | HRGN hrgnNewClip = NULLHANDLE, hrgnOldClip = NULLHANDLE; | 
|---|
| 450 | LONG lComplexity = RGN_NULL; | 
|---|
| 451 | RECTL rectl = {0, 0, 1, 1}; | 
|---|
| 452 |  | 
|---|
| 453 | if(pHps == NULL) { | 
|---|
| 454 | DebugInt3(); | 
|---|
| 455 | return ERROR_W; | 
|---|
| 456 | } | 
|---|
| 457 |  | 
|---|
| 458 | if(hrgn != NULLHANDLE) | 
|---|
| 459 | { | 
|---|
| 460 | hrgnNewClip = GpiCreateRegion(pHps->hps, 1, &rectl); | 
|---|
| 461 | if(hrgnNewClip == NULLHANDLE) { | 
|---|
| 462 | dprintf(("ERROR: GdiCombineVisRgn: GpiCreateRegion failed!!")); | 
|---|
| 463 | DebugInt3(); | 
|---|
| 464 | goto failure; | 
|---|
| 465 | } | 
|---|
| 466 | //make a copy of the new visible region | 
|---|
| 467 | lComplexity = GpiCombineRegion(pHps->hps, hrgnNewClip, hrgn, NULLHANDLE, CRGN_COPY); | 
|---|
| 468 | } | 
|---|
| 469 | else { | 
|---|
| 470 | hrgnNewClip = NULLHANDLE; | 
|---|
| 471 | } | 
|---|
| 472 |  | 
|---|
| 473 | //and set that as the GPI clip region | 
|---|
| 474 | lComplexity = GpiSetClipRegion(pHps->hps, hrgnNewClip, &hrgnOldClip); | 
|---|
| 475 | if (lComplexity != RGN_ERROR) | 
|---|
| 476 | { | 
|---|
| 477 | //SvL: Must check if origin changed here. Sometimes happens when | 
|---|
| 478 | //     window looses focus. (don't know why....) | 
|---|
| 479 | checkOrigin(pHps); | 
|---|
| 480 |  | 
|---|
| 481 | if(hrgnOldClip) GpiDestroyRegion(pHps->hps, hrgnOldClip); | 
|---|
| 482 |  | 
|---|
| 483 | dprintf(("New visible region %x", hrgn)); | 
|---|
| 484 | pHps->hrgnWinVis = hrgn; | 
|---|
| 485 | return GPI_TO_WIN_COMPLEXITY(lComplexity); | 
|---|
| 486 | } | 
|---|
| 487 | failure: | 
|---|
| 488 | if(hrgnNewClip) GpiDestroyRegion(pHps->hps, hrgnNewClip); | 
|---|
| 489 |  | 
|---|
| 490 | return ERROR_W; | 
|---|
| 491 | } | 
|---|
| 492 | //****************************************************************************** | 
|---|
| 493 | // GdiCombineVisRgn | 
|---|
| 494 | // | 
|---|
| 495 | // Combine the specified region with the visible region according to the operation | 
|---|
| 496 | // | 
|---|
| 497 | // Parameters: | 
|---|
| 498 | // | 
|---|
| 499 | // pDCData pHps         - presentation space structure | 
|---|
| 500 | // HRGN hrgn            - region handle (Win32) | 
|---|
| 501 | // INT operation        - combine operation (RGN_*) | 
|---|
| 502 | // | 
|---|
| 503 | // | 
|---|
| 504 | // Returns:     - ERROR_W         -> failure | 
|---|
| 505 | //              - NULLREGION_W    -> empty region | 
|---|
| 506 | //              - SIMPLEREGION_W  -> rectangular region | 
|---|
| 507 | //              - COMPLEXREGION_W -> complex region | 
|---|
| 508 | // | 
|---|
| 509 | // NOTE: In windows there is a clip and a visible region (just like in PM) | 
|---|
| 510 | //       We do not map the Win32 visible region to the PM visible region | 
|---|
| 511 | //       as that's rather annoying. | 
|---|
| 512 | //       Instead we use the intersection of the win32 visible and win32 clip | 
|---|
| 513 | //       region for the PM clip region. | 
|---|
| 514 | //       The Win32 clip region is saved in pHps->hrgnWin32Clip. | 
|---|
| 515 | //       The Win32 visible region is saved in pHps->hrgnWinVis. | 
|---|
| 516 | // | 
|---|
| 517 | //****************************************************************************** | 
|---|
| 518 | INT WIN32API GdiCombineVisRgn(pDCData pHps, HRGN hrgn, INT operation) | 
|---|
| 519 | { | 
|---|
| 520 | #ifdef DEBUG_LOGGING | 
|---|
| 521 | HRGN hrgn1 = hrgn; | 
|---|
| 522 | #endif | 
|---|
| 523 | LONG lComplexity = RGN_NULL; | 
|---|
| 524 |  | 
|---|
| 525 | if(pHps == NULL) { | 
|---|
| 526 | DebugInt3(); | 
|---|
| 527 | return ERROR_W; | 
|---|
| 528 | } | 
|---|
| 529 |  | 
|---|
| 530 | hrgn = ObjQueryHandleData(hrgn, HNDL_REGION); | 
|---|
| 531 | if(hrgn == HANDLE_OBJ_ERROR || !pHps) { | 
|---|
| 532 | dprintf(("ERROR: GdiCombineVisRgn %x invalid handle", hrgn1)); | 
|---|
| 533 | return ERROR_W; | 
|---|
| 534 | } | 
|---|
| 535 | //interpretRegionAs converts the region and saves it in pHps->hrgnHDC | 
|---|
| 536 | if(!interpretRegionAs(pHps, 0, hrgn, AS_DEVICE) ) | 
|---|
| 537 | { | 
|---|
| 538 | dprintf(("ERROR: interpretRegionAs failed!!")); | 
|---|
| 539 | return ERROR_W; | 
|---|
| 540 | } | 
|---|
| 541 |  | 
|---|
| 542 | //If there is no visible region, then create one that covers the whole DC | 
|---|
| 543 | if(pHps->hrgnWinVis == NULLHANDLE) | 
|---|
| 544 | { | 
|---|
| 545 | RECTL rectl = {0, 0, hdcWidth(0, pHps), hdcHeight(0, pHps)}; | 
|---|
| 546 | dprintf(("No visible region: create one (0,0)(%d,%d)", rectl.xRight, rectl.yTop)); | 
|---|
| 547 | pHps->hrgnWinVis = GpiCreateRegion(pHps->hps, 1, &rectl); | 
|---|
| 548 | if(pHps->hrgnWinVis == NULLHANDLE) { | 
|---|
| 549 | dprintf(("ERROR: GdiCombineVisRgn: GpiCreateRegion failed!!")); | 
|---|
| 550 | DebugInt3(); | 
|---|
| 551 | goto failure; | 
|---|
| 552 | } | 
|---|
| 553 | } | 
|---|
| 554 |  | 
|---|
| 555 | LONG lMode; | 
|---|
| 556 | switch (operation) | 
|---|
| 557 | { | 
|---|
| 558 | case  RGN_AND_W  : lMode = CRGN_AND ; break; | 
|---|
| 559 | case  RGN_DIFF_W : lMode = CRGN_DIFF; break; | 
|---|
| 560 | default: | 
|---|
| 561 | dprintf(("ERROR: GdiCombineVisRgn %d invalid parameter", operation)); | 
|---|
| 562 | DebugInt3(); | 
|---|
| 563 | goto failure; | 
|---|
| 564 | } | 
|---|
| 565 | lComplexity = GpiCombineRegion(pHps->hps, pHps->hrgnWinVis, pHps->hrgnWinVis, pHps->hrgnHDC, lMode); | 
|---|
| 566 | if (lComplexity != RGN_ERROR) | 
|---|
| 567 | { | 
|---|
| 568 | return GdiSetVisRgn(pHps, pHps->hrgnWinVis); | 
|---|
| 569 | } | 
|---|
| 570 | dprintf(("ERROR: GdiCombineVisRgn: GpiCombineRegion failed")); | 
|---|
| 571 | DebugInt3(); | 
|---|
| 572 |  | 
|---|
| 573 | failure: | 
|---|
| 574 | return ERROR_W; | 
|---|
| 575 | } | 
|---|
| 576 | //****************************************************************************** | 
|---|
| 577 | // GdiCombineVisRgnClipRgn | 
|---|
| 578 | // | 
|---|
| 579 | // Combine the specified clip region with the visible region according to the operation | 
|---|
| 580 | // | 
|---|
| 581 | // Parameters: | 
|---|
| 582 | // | 
|---|
| 583 | // pDCData pHps         - presentation space structure | 
|---|
| 584 | // HRGN hrgn            - region handle (GPI) | 
|---|
| 585 | // INT operation        - combine operation (RGN_*) | 
|---|
| 586 | // | 
|---|
| 587 | // | 
|---|
| 588 | // Returns:     - ERROR_W         -> failure | 
|---|
| 589 | //              - NULLREGION_W    -> empty region | 
|---|
| 590 | //              - SIMPLEREGION_W  -> rectangular region | 
|---|
| 591 | //              - COMPLEXREGION_W -> complex region | 
|---|
| 592 | // | 
|---|
| 593 | // NOTE: In windows there is a clip and a visible region (just like in PM) | 
|---|
| 594 | //       We do not map the Win32 visible region to the PM visible region | 
|---|
| 595 | //       as that's rather annoying. | 
|---|
| 596 | //       Instead we use the intersection of the win32 visible and win32 clip | 
|---|
| 597 | //       region for the PM clip region. | 
|---|
| 598 | //       The Win32 clip region is saved in pHps->hrgnWin32Clip. | 
|---|
| 599 | //       The Win32 visible region is saved in pHps->hrgnWinVis. | 
|---|
| 600 | // | 
|---|
| 601 | //****************************************************************************** | 
|---|
| 602 | INT WIN32API GdiCombineVisRgnClipRgn(pDCData pHps, HRGN hrgn, INT operation) | 
|---|
| 603 | { | 
|---|
| 604 | HRGN hrgnClip = NULL, hrgnOldClip, hrgnNewClip; | 
|---|
| 605 | LONG lComplexity = RGN_NULL; | 
|---|
| 606 |  | 
|---|
| 607 | //Create a region that will be used for the new GPI clip region | 
|---|
| 608 | RECTL rectl = {0, 0, 1, 1}; | 
|---|
| 609 | hrgnNewClip = GpiCreateRegion(pHps->hps, 1, &rectl); | 
|---|
| 610 | if(hrgnNewClip == NULLHANDLE) { | 
|---|
| 611 | dprintf(("ERROR: GdiCombineVisRgnClipRgn: GpiCreateRegion failed!!")); | 
|---|
| 612 | DebugInt3(); | 
|---|
| 613 | return ERROR_W; | 
|---|
| 614 | } | 
|---|
| 615 |  | 
|---|
| 616 | if(hrgn == NULLHANDLE) | 
|---|
| 617 | { | 
|---|
| 618 | if(pHps->hrgnWin32Clip != NULL) | 
|---|
| 619 | { | 
|---|
| 620 | //Only reset the path if both the visible and clip regions are zero | 
|---|
| 621 | if(!pHps->hrgnWinVis) { | 
|---|
| 622 | GpiSetClipPath(pHps->hps, 0, SCP_RESET); | 
|---|
| 623 |  | 
|---|
| 624 | GpiDestroyRegion(pHps->hps, hrgnNewClip); | 
|---|
| 625 | hrgnNewClip = NULLHANDLE; | 
|---|
| 626 | } | 
|---|
| 627 | else | 
|---|
| 628 | {//set PM clip region to Win32 visible region | 
|---|
| 629 | lComplexity = GpiCombineRegion(pHps->hps, hrgnNewClip, pHps->hrgnWinVis, NULLHANDLE, CRGN_COPY); | 
|---|
| 630 | if(lComplexity == RGN_ERROR) { | 
|---|
| 631 | dprintf(("ERROR: GdiCombineVisRgnClipRgn: GpiSetClipRegion failed!!")); | 
|---|
| 632 | DebugInt3(); | 
|---|
| 633 | goto failure; | 
|---|
| 634 | } | 
|---|
| 635 | } | 
|---|
| 636 | dprintfRegion(pHps->hps, hrgnNewClip); | 
|---|
| 637 | lComplexity = GpiSetClipRegion(pHps->hps, hrgnNewClip, &hrgnOldClip); | 
|---|
| 638 | if(lComplexity == RGN_ERROR) { | 
|---|
| 639 | dprintf(("ERROR: GdiCombineVisRgnClipRgn: GpiSetClipRegion failed!!")); | 
|---|
| 640 | DebugInt3(); | 
|---|
| 641 | } | 
|---|
| 642 |  | 
|---|
| 643 | //SvL: Must check if origin changed here. Sometimes happens when | 
|---|
| 644 | //     window looses focus. (don't know why....) | 
|---|
| 645 | checkOrigin(pHps); | 
|---|
| 646 | if(hrgnOldClip) GpiDestroyRegion(pHps->hps, hrgnOldClip); | 
|---|
| 647 | } | 
|---|
| 648 | else | 
|---|
| 649 | {// already NULL, so nothing to do. | 
|---|
| 650 | GpiDestroyRegion(pHps->hps, hrgnNewClip); | 
|---|
| 651 | } | 
|---|
| 652 | pHps->hrgnWin32Clip = hrgn; | 
|---|
| 653 | return NULLREGION_W; | 
|---|
| 654 | } | 
|---|
| 655 |  | 
|---|
| 656 | LONG lMode; | 
|---|
| 657 | switch (operation) | 
|---|
| 658 | { | 
|---|
| 659 | case  RGN_AND_W  : lMode = CRGN_AND ; break;  //intersect clip & visible region | 
|---|
| 660 | default: | 
|---|
| 661 | dprintf(("ERROR: GdiCombineVisRgnClipRgn %d invalid parameter", operation)); | 
|---|
| 662 | DebugInt3(); | 
|---|
| 663 | goto failure; | 
|---|
| 664 | } | 
|---|
| 665 | // If there's no visible region (meaning entire DC is visible), then just set | 
|---|
| 666 | // the GPI clip region to the win32 clip region | 
|---|
| 667 | if (pHps->hrgnWinVis == NULLHANDLE) | 
|---|
| 668 | { | 
|---|
| 669 | lComplexity = GpiCombineRegion(pHps->hps, hrgnNewClip, hrgn, NULLHANDLE, CRGN_COPY); | 
|---|
| 670 | } | 
|---|
| 671 | else lComplexity = GpiCombineRegion(pHps->hps, hrgnNewClip, pHps->hrgnWinVis, hrgn, lMode); | 
|---|
| 672 |  | 
|---|
| 673 | if (lComplexity != RGN_ERROR) | 
|---|
| 674 | { | 
|---|
| 675 | dprintfRegion(pHps->hps, hrgnNewClip); | 
|---|
| 676 | //And activate the new clip region | 
|---|
| 677 | lComplexity = GpiSetClipRegion(pHps->hps, hrgnNewClip, &hrgnOldClip); | 
|---|
| 678 | if (lComplexity == RGN_ERROR ) | 
|---|
| 679 | { | 
|---|
| 680 | dprintf(("ERROR: GdiCombineVisRgnClipRgn: GpiSetClipRegion failed")); | 
|---|
| 681 | DebugInt3(); | 
|---|
| 682 | goto failure; | 
|---|
| 683 | } | 
|---|
| 684 | //SvL: Must check if origin changed here. Sometimes happens when | 
|---|
| 685 | //     window looses focus. (don't know why....) | 
|---|
| 686 | checkOrigin(pHps); | 
|---|
| 687 |  | 
|---|
| 688 | if(hrgnOldClip) GpiDestroyRegion(pHps->hps, hrgnOldClip); | 
|---|
| 689 |  | 
|---|
| 690 | pHps->hrgnWin32Clip = hrgn; | 
|---|
| 691 |  | 
|---|
| 692 | return GPI_TO_WIN_COMPLEXITY(lComplexity); | 
|---|
| 693 | } | 
|---|
| 694 | dprintf(("ERROR: GdiCombineVisRgnClipRgn: GpiCombineRegion failed")); | 
|---|
| 695 | DebugInt3(); | 
|---|
| 696 |  | 
|---|
| 697 | failure: | 
|---|
| 698 | if(hrgnNewClip) GpiDestroyRegion(pHps->hps, hrgnNewClip); | 
|---|
| 699 |  | 
|---|
| 700 | return ERROR_W; | 
|---|
| 701 | } | 
|---|
| 702 | //****************************************************************************** | 
|---|
| 703 | // GdiCopyClipRgn | 
|---|
| 704 | // | 
|---|
| 705 | // Duplicate the GPI region | 
|---|
| 706 | // | 
|---|
| 707 | // Parameters: | 
|---|
| 708 | // | 
|---|
| 709 | // pDCData pHps         - presentation space structure | 
|---|
| 710 | // | 
|---|
| 711 | // Returns:     - NULL     -> failure | 
|---|
| 712 | //              - <> NULL  -> GPI handle of copied region | 
|---|
| 713 | // | 
|---|
| 714 | //****************************************************************************** | 
|---|
| 715 | HRGN GdiCopyClipRgn(pDCData pHps) | 
|---|
| 716 | { | 
|---|
| 717 | HRGN hrgnNewClip; | 
|---|
| 718 | LONG lComplexity; | 
|---|
| 719 | RECTL rectl = {0, 0, 1, 1}; | 
|---|
| 720 |  | 
|---|
| 721 | hrgnNewClip = GpiCreateRegion(pHps->hps, 1, &rectl); | 
|---|
| 722 | if(hrgnNewClip == NULLHANDLE) { | 
|---|
| 723 | dprintf(("ERROR: GdiCopyClipRgn: GpiCreateRegion failed!!")); | 
|---|
| 724 | DebugInt3(); | 
|---|
| 725 | return NULLHANDLE; | 
|---|
| 726 | } | 
|---|
| 727 | lComplexity = GpiCombineRegion(pHps->hps, hrgnNewClip, pHps->hrgnWin32Clip, NULLHANDLE, CRGN_COPY); | 
|---|
| 728 | if (lComplexity != RGN_ERROR) | 
|---|
| 729 | { | 
|---|
| 730 | return hrgnNewClip; | 
|---|
| 731 | } | 
|---|
| 732 | dprintf(("GpiCombineRegion %x %x %x failed!!", pHps->hps, hrgnNewClip, pHps->hrgnWin32Clip)); | 
|---|
| 733 | DebugInt3(); | 
|---|
| 734 | return NULLHANDLE; | 
|---|
| 735 | } | 
|---|
| 736 | //****************************************************************************** | 
|---|
| 737 | // GdiDestroyRgn | 
|---|
| 738 | // | 
|---|
| 739 | // Destroy the GPI region | 
|---|
| 740 | // | 
|---|
| 741 | // Parameters: | 
|---|
| 742 | // | 
|---|
| 743 | // pDCData pHps         - presentation space structure | 
|---|
| 744 | // HRGN hrgn            - region handle (GPI) | 
|---|
| 745 | // | 
|---|
| 746 | // Returns:     - FALSE -> failure | 
|---|
| 747 | //              - TRUE  -> success | 
|---|
| 748 | // | 
|---|
| 749 | //****************************************************************************** | 
|---|
| 750 | BOOL GdiDestroyRgn(pDCData pHps, HRGN hrgn) | 
|---|
| 751 | { | 
|---|
| 752 | return GpiDestroyRegion(pHps->hps, hrgn); | 
|---|
| 753 | } | 
|---|
| 754 | //****************************************************************************** | 
|---|
| 755 | //****************************************************************************** | 
|---|
| 756 | int WIN32API ExtSelectClipRgn(HDC hdc, HRGN hrgn, int mode) | 
|---|
| 757 | { | 
|---|
| 758 | #ifdef DEBUG_LOGGING | 
|---|
| 759 | HRGN hrgn1 = hrgn; | 
|---|
| 760 | #endif | 
|---|
| 761 |  | 
|---|
| 762 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 763 | if (!pHps) | 
|---|
| 764 | { | 
|---|
| 765 | dprintf(("WARNING: ExtSelectRgn %x %x %d invalid hdc", hdc, hrgn, mode)); | 
|---|
| 766 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 767 | return ERROR_W; | 
|---|
| 768 | } | 
|---|
| 769 |  | 
|---|
| 770 | LONG lComplexity; | 
|---|
| 771 | HRGN hrgnCurrent = NULLHANDLE, hrgnOld = NULLHANDLE; | 
|---|
| 772 |  | 
|---|
| 773 | if(!hrgn && mode != RGN_COPY_W) | 
|---|
| 774 | { | 
|---|
| 775 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 776 | dprintf(("WARNING: ExtSelectRgn %x %x %d invalid parameter", hdc, hrgn1, mode)); | 
|---|
| 777 | return ERROR_W; | 
|---|
| 778 | } | 
|---|
| 779 |  | 
|---|
| 780 | LONG lMode; | 
|---|
| 781 | switch (mode) | 
|---|
| 782 | { | 
|---|
| 783 | case  RGN_AND_W  : lMode = CRGN_AND ; break; | 
|---|
| 784 | case  RGN_COPY_W : lMode = CRGN_COPY; break; | 
|---|
| 785 | case  RGN_DIFF_W : lMode = CRGN_DIFF; break; | 
|---|
| 786 | case  RGN_OR_W   : lMode = CRGN_OR  ; break; | 
|---|
| 787 | case  RGN_XOR_W  : lMode = CRGN_XOR ; break; | 
|---|
| 788 | default: | 
|---|
| 789 | { | 
|---|
| 790 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 791 | dprintf(("WARNING: ExtSelectRgn %x %x %d invalid parameter", hdc, hrgn1, mode)); | 
|---|
| 792 | return ERROR_W; | 
|---|
| 793 | } | 
|---|
| 794 | } | 
|---|
| 795 |  | 
|---|
| 796 | if(hrgn) | 
|---|
| 797 | { | 
|---|
| 798 | hrgn = ObjQueryHandleData(hrgn, HNDL_REGION); | 
|---|
| 799 | if(hrgn == HANDLE_OBJ_ERROR) { | 
|---|
| 800 | dprintf(("WARNING: ExtSelectRgn %x %x %d invalid region handle", hdc, hrgn1, mode)); | 
|---|
| 801 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 802 | return 0; | 
|---|
| 803 | } | 
|---|
| 804 | dprintfRegion(hdc, hrgn); | 
|---|
| 805 | } | 
|---|
| 806 |  | 
|---|
| 807 | //TODO: metafile recording | 
|---|
| 808 | if(hrgn) | 
|---|
| 809 | { | 
|---|
| 810 | //interpretRegionAs converts the region and saves it in pHps->hrgnHDC | 
|---|
| 811 | if(!interpretRegionAs(pHps, 0, hrgn, AS_DEVICE) ) | 
|---|
| 812 | { | 
|---|
| 813 | dprintf(("interpretRegionAs failed!!")); | 
|---|
| 814 | return ERROR_W; | 
|---|
| 815 | } | 
|---|
| 816 | } | 
|---|
| 817 | else | 
|---|
| 818 | { | 
|---|
| 819 | //Intersect the Windows clip region with the current visible region | 
|---|
| 820 | lComplexity = GdiCombineVisRgnClipRgn(pHps, NULLHANDLE, RGN_AND_W); | 
|---|
| 821 |  | 
|---|
| 822 | return NULLREGION_W; | 
|---|
| 823 | } | 
|---|
| 824 |  | 
|---|
| 825 | // get current clipping region | 
|---|
| 826 | hrgnOld     = pHps->hrgnWin32Clip; | 
|---|
| 827 | hrgnCurrent = hrgnOld; | 
|---|
| 828 |  | 
|---|
| 829 | if(hrgnCurrent == NULLHANDLE) | 
|---|
| 830 | {//if none, then create one | 
|---|
| 831 | lMode = CRGN_COPY; | 
|---|
| 832 | RECTL rectl = {0, 0, 1, 1}; | 
|---|
| 833 | hrgnCurrent = GpiCreateRegion(pHps->hps, 1, &rectl); | 
|---|
| 834 | } | 
|---|
| 835 |  | 
|---|
| 836 | HRGN hrgnSrc1; | 
|---|
| 837 | HRGN hrgnSrc2; | 
|---|
| 838 | if(lMode != CRGN_COPY) | 
|---|
| 839 | { | 
|---|
| 840 | hrgnSrc1 = hrgnCurrent; | 
|---|
| 841 | hrgnSrc2 = pHps->hrgnHDC; | 
|---|
| 842 | } | 
|---|
| 843 | else | 
|---|
| 844 | { | 
|---|
| 845 | hrgnSrc1 = pHps->hrgnHDC; | 
|---|
| 846 | hrgnSrc2 = NULLHANDLE; | 
|---|
| 847 | } | 
|---|
| 848 |  | 
|---|
| 849 | lComplexity = GpiCombineRegion(pHps->hps, hrgnCurrent, hrgnSrc1, hrgnSrc2, lMode); | 
|---|
| 850 | if (lComplexity != RGN_ERROR) | 
|---|
| 851 | { | 
|---|
| 852 | HRGN hrgnOld; | 
|---|
| 853 |  | 
|---|
| 854 | //Intersect the Windows clip region with the current visible region | 
|---|
| 855 | lComplexity = GdiCombineVisRgnClipRgn(pHps, hrgnCurrent, RGN_AND_W); | 
|---|
| 856 |  | 
|---|
| 857 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 858 |  | 
|---|
| 859 | if (lComplexity != RGN_ERROR) { | 
|---|
| 860 | return lComplexity; | 
|---|
| 861 | } | 
|---|
| 862 | } | 
|---|
| 863 | dprintf(("GpiCombineRegion failed %x %x %x %d", hrgnCurrent, hrgnSrc1, hrgnSrc2, lMode)); | 
|---|
| 864 | GpiDestroyRegion(pHps->hps, hrgnCurrent); //delete newly created region | 
|---|
| 865 |  | 
|---|
| 866 | SetLastError(ERROR_INVALID_PARAMETER_W); //TODO | 
|---|
| 867 | return ERROR_W; | 
|---|
| 868 | } | 
|---|
| 869 | //****************************************************************************** | 
|---|
| 870 | //****************************************************************************** | 
|---|
| 871 | int WIN32API SelectClipRgn(HDC hdc, HRGN hrgn) | 
|---|
| 872 | { | 
|---|
| 873 | return ExtSelectClipRgn(hdc, hrgn, RGN_COPY_W); | 
|---|
| 874 | } | 
|---|
| 875 | //****************************************************************************** | 
|---|
| 876 | // The GetClipBox function retrieves the dimensions of the tightest bounding | 
|---|
| 877 | // rectangle that can be drawn around the current visible area on the device. | 
|---|
| 878 | // The visible area is defined by the current clipping region or clip path, as well | 
|---|
| 879 | // as any overlapping windows. | 
|---|
| 880 | // | 
|---|
| 881 | // NOTE: We simply call GpiQueryClipBox as it behaves just like GetClipBox | 
|---|
| 882 | // | 
|---|
| 883 | //****************************************************************************** | 
|---|
| 884 | int WIN32API GetClipBox(HDC hdc, PRECT lpRect) | 
|---|
| 885 | { | 
|---|
| 886 | pDCData  pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 887 | RECTL    rectl; | 
|---|
| 888 | LONG     lComplexity; | 
|---|
| 889 | int      rc; | 
|---|
| 890 |  | 
|---|
| 891 | if(!hdc || !lpRect || !pHps) { | 
|---|
| 892 | dprintf(("GDI32: GetClipBox %x %x ERROR_INVALID_PARAMETER", hdc, lpRect)); | 
|---|
| 893 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 894 | return ERROR_W; | 
|---|
| 895 | } | 
|---|
| 896 | if(pHps->isPrinter) | 
|---|
| 897 | { | 
|---|
| 898 | //Some printers return the wrong clip box. Return the full page instead. | 
|---|
| 899 | //(TODO: which is incorrect!) | 
|---|
| 900 | lpRect->left   = 0; | 
|---|
| 901 | lpRect->top    = 0; | 
|---|
| 902 | lpRect->right  = GetDeviceCaps( hdc, HORZRES_W); | 
|---|
| 903 | lpRect->bottom = GetDeviceCaps( hdc, VERTRES_W); | 
|---|
| 904 | includeBottomRightPoint(pHps, (PPOINTLOS2)&rectl); | 
|---|
| 905 | convertPMDeviceRectToWinWorldRect(pHps, &rectl); | 
|---|
| 906 |  | 
|---|
| 907 | rc = SIMPLEREGION_W; | 
|---|
| 908 | } | 
|---|
| 909 | else { | 
|---|
| 910 | lComplexity = GpiQueryClipBox(pHps->hps, &rectl); | 
|---|
| 911 | if(lComplexity == RGN_ERROR) | 
|---|
| 912 | { | 
|---|
| 913 | rc = ERROR_W; | 
|---|
| 914 | } | 
|---|
| 915 | else | 
|---|
| 916 | if(lComplexity == RGN_NULL) | 
|---|
| 917 | { | 
|---|
| 918 | memset(lpRect, 0, sizeof(*lpRect)); | 
|---|
| 919 | rc = NULLREGION_W; | 
|---|
| 920 | } | 
|---|
| 921 | else { | 
|---|
| 922 | #ifndef INVERT | 
|---|
| 923 | //Convert coordinates from PM to win32 | 
|---|
| 924 | if (pHps->yInvert > 0) { | 
|---|
| 925 | LONG temp     = pHps->yInvert - rectl.yBottom; | 
|---|
| 926 | rectl.yBottom = pHps->yInvert - rectl.yTop; | 
|---|
| 927 | rectl.yTop    = temp; | 
|---|
| 928 | } | 
|---|
| 929 | #endif | 
|---|
| 930 | //Convert including/including to including/excluding | 
|---|
| 931 | includeBottomRightPoint(pHps, (PPOINTLOS2)&rectl); | 
|---|
| 932 |  | 
|---|
| 933 | lpRect->left   = rectl.xLeft; | 
|---|
| 934 | lpRect->right  = rectl.xRight; | 
|---|
| 935 |  | 
|---|
| 936 | if(rectl.yBottom > rectl.yTop) { | 
|---|
| 937 | lpRect->top    = rectl.yTop; | 
|---|
| 938 | lpRect->bottom = rectl.yBottom; | 
|---|
| 939 | } | 
|---|
| 940 | else { | 
|---|
| 941 | lpRect->top    = rectl.yBottom; | 
|---|
| 942 | lpRect->bottom = rectl.yTop; | 
|---|
| 943 | } | 
|---|
| 944 |  | 
|---|
| 945 | rc = GPI_TO_WIN_COMPLEXITY(lComplexity); | 
|---|
| 946 | } | 
|---|
| 947 | } | 
|---|
| 948 | //    if(lpRect->left == 0 && lpRect->top == 0 && lpRect->right == 0 && lpRect->bottom == 0) | 
|---|
| 949 | //  DebugInt3(); | 
|---|
| 950 | dprintf(("GDI32: GetClipBox of %X returned %d; (%d,%d)(%d,%d)", hdc, rc, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom)); | 
|---|
| 951 | return rc; | 
|---|
| 952 | } | 
|---|
| 953 | //****************************************************************************** | 
|---|
| 954 | //****************************************************************************** | 
|---|
| 955 | int WIN32API GetClipRgn(HDC hdc, HRGN hrgn) | 
|---|
| 956 | { | 
|---|
| 957 | pDCData    pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 958 | BOOL       success; | 
|---|
| 959 | LONG       lComplexity = RGN_RECT; | 
|---|
| 960 | HRGN       hrgnClip = NULL, hrgnTemp; | 
|---|
| 961 | #ifdef DEBUG_LOGGING | 
|---|
| 962 | HRGN hrgn1 = hrgn; | 
|---|
| 963 | #endif | 
|---|
| 964 |  | 
|---|
| 965 | hrgn = ObjQueryHandleData(hrgn, HNDL_REGION); | 
|---|
| 966 | if(hrgn == HANDLE_OBJ_ERROR || !pHps) { | 
|---|
| 967 | dprintf(("WARNING: GetClipRgn %x %x invalid handle", hdc, hrgn1)); | 
|---|
| 968 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 969 | return 0; | 
|---|
| 970 | } | 
|---|
| 971 |  | 
|---|
| 972 | if(pHps->hrgnWin32Clip) { | 
|---|
| 973 | dprintfRegion(hdc, pHps->hrgnWin32Clip); | 
|---|
| 974 | if(!setWinDeviceRegionFromPMDeviceRegion(hrgn, pHps->hrgnWin32Clip, pHps, NULL)) { | 
|---|
| 975 | dprintf(("WARNING: GetClipRgn setWinDeviceRegionFromPMDeviceRegion failed!")); | 
|---|
| 976 | GpiSetClipRegion(pHps->hps, hrgnClip, &hrgnTemp); | 
|---|
| 977 | SetLastError(ERROR_INVALID_PARAMETER_W); //todo right errror | 
|---|
| 978 | return 0; | 
|---|
| 979 | } | 
|---|
| 980 | } | 
|---|
| 981 | else { | 
|---|
| 982 | //no clip region; return NULL | 
|---|
| 983 | lComplexity = RGN_NULL; | 
|---|
| 984 | } | 
|---|
| 985 |  | 
|---|
| 986 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 987 | if(lComplexity == RGN_NULL) | 
|---|
| 988 | return 0; | 
|---|
| 989 | else return 1; | 
|---|
| 990 | } | 
|---|
| 991 | //****************************************************************************** | 
|---|
| 992 | // The GetRandomRgn function copies the system clipping region of a specified | 
|---|
| 993 | // device context to a specific region. | 
|---|
| 994 | // It returns the visible region of the specified device context in screen | 
|---|
| 995 | // coordinates (if it belongs to a window). | 
|---|
| 996 | // | 
|---|
| 997 | // VALUE = 1: This undocumented value will return the current Clip Region contained in the DC. | 
|---|
| 998 | // VALUE = 2: This undocumented value will return the current Meta Region contained in the DC. | 
|---|
| 999 | // VALUE = 3: This undocumented value will return the intersection of the Clip Region and Meta Region. | 
|---|
| 1000 | // VALUE = 4, SYSRGN: The only value that is documented and defined for this function. | 
|---|
| 1001 | //                    This value returns the System Region | 
|---|
| 1002 | //****************************************************************************** | 
|---|
| 1003 | INT WIN32API GetRandomRgn(HDC hdc, HRGN hrgn, INT iNum) | 
|---|
| 1004 | { | 
|---|
| 1005 | HWND hwnd; | 
|---|
| 1006 | INT  ret; | 
|---|
| 1007 |  | 
|---|
| 1008 | if(iNum != SYSRGN_W) { | 
|---|
| 1009 | dprintf(("WARNING: GetRandomRgn: invalid parameter %x", iNum)); | 
|---|
| 1010 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1011 | return ERROR_W; | 
|---|
| 1012 | } | 
|---|
| 1013 | ret = GetClipRgn(hdc, hrgn); | 
|---|
| 1014 |  | 
|---|
| 1015 | hwnd = WindowFromDC(hdc); | 
|---|
| 1016 | if(hwnd) { | 
|---|
| 1017 | POINT pt = {0,0}; | 
|---|
| 1018 | //map from client to desktop coordinates | 
|---|
| 1019 | MapWindowPoints(hwnd, 0, &pt, 1); | 
|---|
| 1020 |  | 
|---|
| 1021 | OffsetRgn(hrgn, pt.x, pt.y); | 
|---|
| 1022 | } | 
|---|
| 1023 | return ret; | 
|---|
| 1024 | } | 
|---|
| 1025 | //****************************************************************************** | 
|---|
| 1026 | //****************************************************************************** | 
|---|
| 1027 | int WIN32API ExcludeClipRect(HDC  hdc, int  left, int  top, int  right, int bottom) | 
|---|
| 1028 | { | 
|---|
| 1029 | pDCData  pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 1030 | if(!pHps) | 
|---|
| 1031 | { | 
|---|
| 1032 | dprintf(("ERROR: ExcludeClipRgn %x (%d,%d)(%d,%d) invalid hdc", hdc, left, top, right, bottom)); | 
|---|
| 1033 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1034 | return ERROR_W; | 
|---|
| 1035 | } | 
|---|
| 1036 |  | 
|---|
| 1037 | LONG   lComplexity; | 
|---|
| 1038 | RECTL  rectl = { left, bottom, right, top }; | 
|---|
| 1039 |  | 
|---|
| 1040 | excludeBottomRightPoint(pHps, (PPOINTLOS2)&rectl); | 
|---|
| 1041 | if(rectl.yTop < rectl.yBottom) { | 
|---|
| 1042 | ULONG temp    = rectl.yBottom; | 
|---|
| 1043 | rectl.yBottom = rectl.yTop; | 
|---|
| 1044 | rectl.yTop    = temp; | 
|---|
| 1045 | } | 
|---|
| 1046 |  | 
|---|
| 1047 | #ifndef INVERT | 
|---|
| 1048 | if (pHps->yInvert > 0) { | 
|---|
| 1049 | LONG temp     = pHps->yInvert - rectl.yBottom; | 
|---|
| 1050 | rectl.yBottom = pHps->yInvert - rectl.yTop; | 
|---|
| 1051 | rectl.yTop    = temp; | 
|---|
| 1052 | } | 
|---|
| 1053 | #endif | 
|---|
| 1054 |  | 
|---|
| 1055 | dprintf(("ExcludeClipRgn %x (%d,%d)(%d,%d)", hdc, left, top, right, bottom)); | 
|---|
| 1056 |  | 
|---|
| 1057 | lComplexity = GpiExcludeClipRectangle(pHps->hps, &rectl); | 
|---|
| 1058 | if (lComplexity == RGN_ERROR) { | 
|---|
| 1059 | dprintf(("ERROR: ExcludeClipRgn: GpiExcludeClipRectangle failed!!")); | 
|---|
| 1060 | SetLastError(ERROR_INVALID_PARAMETER_W); //TODO: wrong error | 
|---|
| 1061 | return ERROR_W; | 
|---|
| 1062 | } | 
|---|
| 1063 |  | 
|---|
| 1064 | //Ok, success. Now update the cached win32 clip region | 
|---|
| 1065 | if(pHps->hrgnWin32Clip != NULLHANDLE) | 
|---|
| 1066 | { | 
|---|
| 1067 | HRGN hrgnClipRect = GpiCreateRegion(pHps->hps, 1, &rectl); | 
|---|
| 1068 | if(hrgnClipRect == NULLHANDLE) { | 
|---|
| 1069 | dprintf(("ERROR: ExcludeClipRgn GpiCreateRegion failed!!")); | 
|---|
| 1070 | DebugInt3(); | 
|---|
| 1071 | SetLastError(ERROR_INVALID_PARAMETER_W); //TODO: wrong error | 
|---|
| 1072 | return ERROR_W; | 
|---|
| 1073 | } | 
|---|
| 1074 | //subtract rect region from clip region | 
|---|
| 1075 | lComplexity = GpiCombineRegion(pHps->hps, pHps->hrgnWin32Clip, pHps->hrgnWin32Clip, hrgnClipRect, CRGN_DIFF); | 
|---|
| 1076 | GpiDestroyRegion(pHps->hps, hrgnClipRect); | 
|---|
| 1077 |  | 
|---|
| 1078 | if (lComplexity == RGN_ERROR) { | 
|---|
| 1079 | dprintf(("ERROR: ExcludeClipRgn GpiCombineRegion failed!!")); | 
|---|
| 1080 | DebugInt3(); | 
|---|
| 1081 | SetLastError(ERROR_INVALID_PARAMETER_W); //TODO: wrong error | 
|---|
| 1082 | return ERROR_W; | 
|---|
| 1083 | } | 
|---|
| 1084 | } | 
|---|
| 1085 |  | 
|---|
| 1086 | //todo metafile recording | 
|---|
| 1087 |  | 
|---|
| 1088 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1089 | return lComplexity; | 
|---|
| 1090 | } | 
|---|
| 1091 | //****************************************************************************** | 
|---|
| 1092 | //****************************************************************************** | 
|---|
| 1093 | int WIN32API IntersectClipRect(HDC hdc, int left, int top, int right, int bottom) | 
|---|
| 1094 | { | 
|---|
| 1095 | pDCData  pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 1096 | LONG      lComplexity; | 
|---|
| 1097 | BOOL      success; | 
|---|
| 1098 |  | 
|---|
| 1099 | if(!pHps) { | 
|---|
| 1100 | dprintf(("WARNING: IntersectClipRect %x (%d,%d)(%d,%d) invalid hdc", hdc, left, top, right, bottom)); | 
|---|
| 1101 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1102 | return ERROR_W; | 
|---|
| 1103 | } | 
|---|
| 1104 | RECTL rectl = { left, bottom, right, top }; | 
|---|
| 1105 |  | 
|---|
| 1106 | excludeBottomRightPoint(pHps, (PPOINTLOS2)&rectl); | 
|---|
| 1107 | if(rectl.yTop < rectl.yBottom) { | 
|---|
| 1108 | ULONG temp    = rectl.yBottom; | 
|---|
| 1109 | rectl.yBottom = rectl.yTop; | 
|---|
| 1110 | rectl.yTop    = temp; | 
|---|
| 1111 | } | 
|---|
| 1112 |  | 
|---|
| 1113 | #ifndef INVERT | 
|---|
| 1114 | //Convert coordinates from PM to win32 | 
|---|
| 1115 | if (pHps->yInvert > 0) { | 
|---|
| 1116 | LONG temp     = pHps->yInvert - rectl.yBottom; | 
|---|
| 1117 | rectl.yBottom = pHps->yInvert - rectl.yTop; | 
|---|
| 1118 | rectl.yTop    = temp; | 
|---|
| 1119 | } | 
|---|
| 1120 | #endif | 
|---|
| 1121 |  | 
|---|
| 1122 | dprintf(("IntersectClipRect %x (%d,%d)(%d,%d)", hdc, left, top, right, bottom)); | 
|---|
| 1123 | lComplexity = GpiIntersectClipRectangle(pHps->hps, &rectl); | 
|---|
| 1124 | if (lComplexity == RGN_ERROR) { | 
|---|
| 1125 | dprintf(("ERROR: IntersectClipRect: GpiIntersectClipRectangle failed!!")); | 
|---|
| 1126 | SetLastError(ERROR_INVALID_PARAMETER_W); //TODO: wrong error | 
|---|
| 1127 | return ERROR_W; | 
|---|
| 1128 | } | 
|---|
| 1129 |  | 
|---|
| 1130 | //Ok, success. Now update the cached win32 clip region | 
|---|
| 1131 | if(pHps->hrgnWin32Clip != NULLHANDLE) | 
|---|
| 1132 | { | 
|---|
| 1133 | HRGN hrgnClipRect = GpiCreateRegion(pHps->hps, 1, &rectl); | 
|---|
| 1134 | if(hrgnClipRect == NULLHANDLE) { | 
|---|
| 1135 | dprintf(("ERROR: IntersectClipRect GpiCreateRegion failed!!")); | 
|---|
| 1136 | DebugInt3(); | 
|---|
| 1137 | SetLastError(ERROR_INVALID_PARAMETER_W); //TODO: wrong error | 
|---|
| 1138 | return ERROR_W; | 
|---|
| 1139 | } | 
|---|
| 1140 | //intersect rect region with clip region | 
|---|
| 1141 | lComplexity = GpiCombineRegion(pHps->hps, pHps->hrgnWin32Clip, pHps->hrgnWin32Clip, hrgnClipRect, CRGN_AND); | 
|---|
| 1142 | GpiDestroyRegion(pHps->hps, hrgnClipRect); | 
|---|
| 1143 |  | 
|---|
| 1144 | if (lComplexity == RGN_ERROR) { | 
|---|
| 1145 | dprintf(("ERROR: IntersectClipRect GpiCombineRegion failed!!")); | 
|---|
| 1146 | DebugInt3(); | 
|---|
| 1147 | SetLastError(ERROR_INVALID_PARAMETER_W); //TODO: wrong error | 
|---|
| 1148 | return ERROR_W; | 
|---|
| 1149 | } | 
|---|
| 1150 | } | 
|---|
| 1151 |  | 
|---|
| 1152 | //todo metafile recording | 
|---|
| 1153 |  | 
|---|
| 1154 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1155 | return lComplexity; | 
|---|
| 1156 | } | 
|---|
| 1157 | //****************************************************************************** | 
|---|
| 1158 | //****************************************************************************** | 
|---|
| 1159 | int WIN32API OffsetClipRgn(HDC  hdc, int  nXOffset, int  nYOffset ) | 
|---|
| 1160 | { | 
|---|
| 1161 | BOOL    success; | 
|---|
| 1162 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 1163 | LONG    lComplexity; | 
|---|
| 1164 |  | 
|---|
| 1165 | if(!pHps) { | 
|---|
| 1166 | dprintf(("OffsetClipRgn %x (%d,%d) invalid hdc", hdc, nXOffset, nYOffset)); | 
|---|
| 1167 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1168 | return ERROR_W; | 
|---|
| 1169 | } | 
|---|
| 1170 |  | 
|---|
| 1171 | dprintf(("OffsetClipRgn %x (%d,%d)", hdc, nXOffset, nYOffset)); | 
|---|
| 1172 | POINTL  pointl = { nXOffset, nYOffset }; | 
|---|
| 1173 | #ifndef INVERT | 
|---|
| 1174 | if (pHps->yInvert > 0) { | 
|---|
| 1175 | pointl.y = pHps->yInvert - pointl.y; | 
|---|
| 1176 | } | 
|---|
| 1177 | #endif | 
|---|
| 1178 |  | 
|---|
| 1179 | if(pHps->hrgnWin32Clip == NULLHANDLE) { | 
|---|
| 1180 | lComplexity = NULLREGION_W; | 
|---|
| 1181 | } | 
|---|
| 1182 | else { | 
|---|
| 1183 | lComplexity = GpiOffsetRegion(pHps->hps, pHps->hrgnWin32Clip, &pointl); | 
|---|
| 1184 | if (lComplexity == RGN_ERROR) { | 
|---|
| 1185 | dprintf(("ERROR: OffsetClipRgn: GpiOffsetRegion failed!!")); | 
|---|
| 1186 | SetLastError(ERROR_INVALID_PARAMETER_W); //TODO: wrong error | 
|---|
| 1187 | return ERROR_W; | 
|---|
| 1188 | } | 
|---|
| 1189 |  | 
|---|
| 1190 | //Intersect the Windows clip region with the current visible region | 
|---|
| 1191 | lComplexity = GdiCombineVisRgnClipRgn(pHps, pHps->hrgnWin32Clip, RGN_AND_W); | 
|---|
| 1192 |  | 
|---|
| 1193 | lComplexity = GPI_TO_WIN_COMPLEXITY(lComplexity); | 
|---|
| 1194 | } | 
|---|
| 1195 |  | 
|---|
| 1196 | //todo metafile recording | 
|---|
| 1197 |  | 
|---|
| 1198 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1199 | return lComplexity; | 
|---|
| 1200 | } | 
|---|
| 1201 | //****************************************************************************** | 
|---|
| 1202 | //****************************************************************************** | 
|---|
| 1203 | HRGN WIN32API CreatePolyPolygonRgn(const POINT *lppt, const int *pPolyCount, | 
|---|
| 1204 | int  nCount, int fnPolyFillMode) | 
|---|
| 1205 | { | 
|---|
| 1206 | LONG  flMode; | 
|---|
| 1207 |  | 
|---|
| 1208 | switch(fnPolyFillMode) | 
|---|
| 1209 | { | 
|---|
| 1210 | case ALTERNATE_W: | 
|---|
| 1211 | flMode = POLYGON_ALTERNATE; | 
|---|
| 1212 | break; | 
|---|
| 1213 | case WINDING_W: | 
|---|
| 1214 | flMode = POLYGON_WINDING; | 
|---|
| 1215 | break; | 
|---|
| 1216 | default: | 
|---|
| 1217 | dprintf(("WARNING: CreatePolyPolygonRgn %x %x %d %d invalid parameter", lppt, pPolyCount, nCount, fnPolyFillMode)); | 
|---|
| 1218 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1219 | return 0; | 
|---|
| 1220 | } | 
|---|
| 1221 |  | 
|---|
| 1222 | if(nCount < 1) | 
|---|
| 1223 | { | 
|---|
| 1224 | dprintf(("WARNING: CreatePolyPolygonRgn %x %x %d %d invalid parameter", lppt, pPolyCount, nCount, fnPolyFillMode)); | 
|---|
| 1225 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1226 | return 0; | 
|---|
| 1227 | } | 
|---|
| 1228 |  | 
|---|
| 1229 | PPOLYGON pPolygon = new POLYGON[nCount]; | 
|---|
| 1230 | if(!pPolygon) { | 
|---|
| 1231 | dprintf(("ERROR: CreatePolyPolygonRgn: out of memory!!")); | 
|---|
| 1232 | SetLastError(ERROR_OUTOFMEMORY_W); | 
|---|
| 1233 | return 0; | 
|---|
| 1234 | } | 
|---|
| 1235 | dprintf(("CreatePolyPolygonRgn %x %x %d %d", lppt, pPolyCount, nCount, fnPolyFillMode)); | 
|---|
| 1236 |  | 
|---|
| 1237 | PPOINTL pPointl = (PPOINTL)lppt+1;     // skip first point | 
|---|
| 1238 | for (int x=0; x < nCount; x++) { | 
|---|
| 1239 | pPolygon[x].ulPoints = (x == 0) ? pPolyCount[x] - 1 : pPolyCount[x]; | 
|---|
| 1240 | pPolygon[x].aPointl  = pPointl; | 
|---|
| 1241 | pPointl += pPolygon[x].ulPoints; | 
|---|
| 1242 | } | 
|---|
| 1243 | GpiMove(hpsRegion, (PPOINTL)lppt); | 
|---|
| 1244 | HRGN hrgn = GpiCreatePolygonRegion(hpsRegion, nCount, pPolygon, POLYGON_BOUNDARY | flMode); | 
|---|
| 1245 |  | 
|---|
| 1246 | delete[] pPolygon; | 
|---|
| 1247 |  | 
|---|
| 1248 | if(!hrgn) { | 
|---|
| 1249 | SetLastError(ERROR_INVALID_PARAMETER_W); //todo: not right | 
|---|
| 1250 | return 0; | 
|---|
| 1251 | } | 
|---|
| 1252 |  | 
|---|
| 1253 | if(ObjAllocateHandle(&hrgn, hrgn, HNDL_REGION) == FALSE) { | 
|---|
| 1254 | GpiDestroyRegion(hpsRegion, hrgn); | 
|---|
| 1255 | SetLastError(ERROR_OUTOFMEMORY_W); | 
|---|
| 1256 | return 0; | 
|---|
| 1257 | } | 
|---|
| 1258 | STATS_CreatePolyPolygonRgn(hrgn, lppt, pPolyCount, nCount, fnPolyFillMode); | 
|---|
| 1259 |  | 
|---|
| 1260 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1261 | return hrgn; | 
|---|
| 1262 | } | 
|---|
| 1263 | //****************************************************************************** | 
|---|
| 1264 | //****************************************************************************** | 
|---|
| 1265 | HRGN WIN32API CreateRectRgn(int  left, int  top, int  right, int  bottom) | 
|---|
| 1266 | { | 
|---|
| 1267 | HRGN   hrgn; | 
|---|
| 1268 | RECTL  rectl = { left, top < bottom ? top : bottom, right, top < bottom ? bottom : top }; | 
|---|
| 1269 |  | 
|---|
| 1270 | hrgn = GpiCreateRegion(hpsRegion, 1, &rectl); | 
|---|
| 1271 | if(!hrgn) { | 
|---|
| 1272 | dprintf(("WARNING: CreateRectRgn: GpiCreateRectRegion failed! %x", WinGetLastError(0))); | 
|---|
| 1273 | SetLastError(ERROR_INVALID_PARAMETER_W); //todo: not right | 
|---|
| 1274 | return 0; | 
|---|
| 1275 | } | 
|---|
| 1276 |  | 
|---|
| 1277 | if(ObjAllocateHandle(&hrgn, hrgn, HNDL_REGION) == FALSE) { | 
|---|
| 1278 | GpiDestroyRegion(hpsRegion, hrgn); | 
|---|
| 1279 | SetLastError(ERROR_OUTOFMEMORY_W); | 
|---|
| 1280 | return 0; | 
|---|
| 1281 | } | 
|---|
| 1282 | STATS_CreateRectRgn(hrgn, left, top, right, bottom); | 
|---|
| 1283 |  | 
|---|
| 1284 | dprintf(("CreateRectRegion (%d,%d)(%d,%d) returned %x", left, top, right, bottom, hrgn)); | 
|---|
| 1285 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1286 | return hrgn; | 
|---|
| 1287 | } | 
|---|
| 1288 | //****************************************************************************** | 
|---|
| 1289 | //****************************************************************************** | 
|---|
| 1290 | HRGN WIN32API CreateRectRgnIndirect( const RECT * lprc) | 
|---|
| 1291 | { | 
|---|
| 1292 | return CreateRectRgn(lprc->left, lprc->top, lprc->right, lprc->bottom); | 
|---|
| 1293 | } | 
|---|
| 1294 | //****************************************************************************** | 
|---|
| 1295 | //****************************************************************************** | 
|---|
| 1296 | HRGN WIN32API CreateRoundRectRgn(int  left, int  top, int  right, int  bottom, int  nWidthEllipse, int  nHeightEllipse) | 
|---|
| 1297 | { | 
|---|
| 1298 | HRGN   hrgn; | 
|---|
| 1299 | RECTL  rectl = { left, top < bottom ? top : bottom, right, top < bottom ? bottom : top }; | 
|---|
| 1300 |  | 
|---|
| 1301 | PPOINTL pPointl = (PPOINTL)&rectl; | 
|---|
| 1302 |  | 
|---|
| 1303 | GpiMove(hpsRegion, &pPointl[0]); | 
|---|
| 1304 | hrgn = GpiCreateRoundRectRegion(hpsRegion, &pPointl[1], labs(nWidthEllipse), labs(nHeightEllipse)); | 
|---|
| 1305 |  | 
|---|
| 1306 | if(!hrgn) { | 
|---|
| 1307 | SetLastError(ERROR_INVALID_PARAMETER_W); //todo: not right | 
|---|
| 1308 | dprintf(("WARNING: CreateRoundRectRgn: GpiCreateRoundRectRegion failed! %x", WinGetLastError(0))); | 
|---|
| 1309 | return 0; | 
|---|
| 1310 | } | 
|---|
| 1311 |  | 
|---|
| 1312 | if(ObjAllocateHandle(&hrgn, hrgn, HNDL_REGION) == FALSE) { | 
|---|
| 1313 | GpiDestroyRegion(hpsRegion, hrgn); | 
|---|
| 1314 | SetLastError(ERROR_OUTOFMEMORY_W); | 
|---|
| 1315 | return 0; | 
|---|
| 1316 | } | 
|---|
| 1317 | STATS_CreateRoundRectRgn(hrgn, left, top, right, bottom, nWidthEllipse, nHeightEllipse); | 
|---|
| 1318 |  | 
|---|
| 1319 | dprintf(("CreateRoundRectRegion (%d,%d)(%d,%d) (%d,%d) returned %x", left, top, right, bottom, nWidthEllipse, nHeightEllipse, hrgn)); | 
|---|
| 1320 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1321 | return hrgn; | 
|---|
| 1322 | } | 
|---|
| 1323 | //****************************************************************************** | 
|---|
| 1324 | //****************************************************************************** | 
|---|
| 1325 | HRGN WIN32API ExtCreateRegion(const XFORM_W * pXform, DWORD count, | 
|---|
| 1326 | const RGNDATA * pData) | 
|---|
| 1327 | { | 
|---|
| 1328 | HRGN hrgn; | 
|---|
| 1329 |  | 
|---|
| 1330 | if(!pData || count < (sizeof(RGNDATAHEADER) +  pData->rdh.nCount * sizeof(RECT))) { | 
|---|
| 1331 | dprintf(("WARNING: ExtCreateRegion %x %d %x; invalid parameter", pXform, count, pData)); | 
|---|
| 1332 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1333 | return 0; | 
|---|
| 1334 | } | 
|---|
| 1335 |  | 
|---|
| 1336 | PRECTL  pRectl     = new RECTL[pData->rdh.nCount]; | 
|---|
| 1337 | PRECT pDataRects = (PRECT)pData->Buffer; | 
|---|
| 1338 | for(int i=0; i < pData->rdh.nCount; i++) { | 
|---|
| 1339 | MapWin32ToOS2Rect(pDataRects[i], pRectl[i]); | 
|---|
| 1340 | } | 
|---|
| 1341 |  | 
|---|
| 1342 | BOOL doShear = pXform && (pXform->eM12 || pXform->eM21); | 
|---|
| 1343 | HPS  hpsTemp = NULLHANDLE; | 
|---|
| 1344 |  | 
|---|
| 1345 | dprintf(("ExtCreateRegion %x %d %x", pXform, count, pData)); | 
|---|
| 1346 | if(doShear) { | 
|---|
| 1347 | hpsTemp = WinGetPS(HWND_DESKTOP); | 
|---|
| 1348 | GpiBeginPath(hpsTemp, 1); | 
|---|
| 1349 |  | 
|---|
| 1350 | MATRIXLF  matrixlf; | 
|---|
| 1351 | matrixlf.fxM11  = pXform->eM11 * (float)0x10000; | 
|---|
| 1352 | matrixlf.fxM12  = pXform->eM12 * (float)0x10000; | 
|---|
| 1353 | matrixlf.lM13   = 0; | 
|---|
| 1354 | matrixlf.fxM21  = pXform->eM21 * (float)0x10000; | 
|---|
| 1355 | matrixlf.fxM22  = pXform->eM22 * (float)0x10000; | 
|---|
| 1356 | matrixlf.lM23   = 0; | 
|---|
| 1357 | matrixlf.lM31   = pXform->eDx; | 
|---|
| 1358 | matrixlf.lM32   = pXform->eDy; | 
|---|
| 1359 | matrixlf.lM33   = 1; | 
|---|
| 1360 |  | 
|---|
| 1361 | GpiSetModelTransformMatrix(hpsTemp, 9, &matrixlf, TRANSFORM_REPLACE); | 
|---|
| 1362 | } | 
|---|
| 1363 |  | 
|---|
| 1364 | for(i=0; i < pData->rdh.nCount; i++) | 
|---|
| 1365 | { | 
|---|
| 1366 | LONG temp         = pRectl[i].yTop; | 
|---|
| 1367 | pRectl[i].yTop    = pRectl[i].yBottom; | 
|---|
| 1368 | pRectl[i].yBottom = temp; | 
|---|
| 1369 |  | 
|---|
| 1370 | if(pXform) | 
|---|
| 1371 | { | 
|---|
| 1372 | PPOINTL pPointl = ((PPOINTL)&pRectl[i]); | 
|---|
| 1373 |  | 
|---|
| 1374 | if (doShear) { | 
|---|
| 1375 | GpiMove(hpsTemp, pPointl); | 
|---|
| 1376 | GpiBox(hpsTemp, DRO_OUTLINE, pPointl+1, 0, 0); | 
|---|
| 1377 | } | 
|---|
| 1378 | else | 
|---|
| 1379 | { | 
|---|
| 1380 | for(int j=0; j < 2; j++) { | 
|---|
| 1381 | pPointl[j].x = (pXform->eM11 * (float)pPointl[j].x) + (pXform->eM12 * (float)pPointl[j].y) + pXform->eDx; | 
|---|
| 1382 | pPointl[j].y = (pXform->eM21 * (float)pPointl[j].x) + (pXform->eM22 * (float)pPointl[j].y) + pXform->eDy; | 
|---|
| 1383 | } | 
|---|
| 1384 |  | 
|---|
| 1385 | PRECTL pRectlT = (PRECTL)pPointl; | 
|---|
| 1386 | if (pRectlT->xLeft > pRectlT->xRight) { | 
|---|
| 1387 | LONG temp       = pRectlT->xLeft; | 
|---|
| 1388 | pRectlT->xLeft  = pRectlT->xRight; | 
|---|
| 1389 | pRectlT->xRight = temp; | 
|---|
| 1390 | } | 
|---|
| 1391 | if (pRectlT->yBottom > pRectlT->yTop) { | 
|---|
| 1392 | LONG temp         = pRectlT->yBottom; | 
|---|
| 1393 | pRectlT->yBottom  = pRectlT->yTop; | 
|---|
| 1394 | pRectlT->yTop     = temp; | 
|---|
| 1395 | } | 
|---|
| 1396 | } | 
|---|
| 1397 | } | 
|---|
| 1398 | } | 
|---|
| 1399 |  | 
|---|
| 1400 | if(doShear) { | 
|---|
| 1401 | GpiEndPath(hpsTemp); | 
|---|
| 1402 | hrgn = GpiPathToRegion(hpsTemp, 1, FPATH_WINDING); | 
|---|
| 1403 |  | 
|---|
| 1404 | if(pRectl) | 
|---|
| 1405 | delete[] pRectl; | 
|---|
| 1406 |  | 
|---|
| 1407 | if(hrgn == 0) { | 
|---|
| 1408 | dprintf(("WARNING: ExtCreateRegion GpiCreateRegion failed! (%x)", WinGetLastError(0))); | 
|---|
| 1409 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1410 | return 0; | 
|---|
| 1411 | } | 
|---|
| 1412 | WinReleasePS(hpsTemp); | 
|---|
| 1413 | } | 
|---|
| 1414 | else { | 
|---|
| 1415 | hrgn = GpiCreateRegion(hpsRegion, pData->rdh.nCount, pRectl); | 
|---|
| 1416 | if(pRectl) | 
|---|
| 1417 | delete[] pRectl; | 
|---|
| 1418 |  | 
|---|
| 1419 | if(hrgn == 0) { | 
|---|
| 1420 | dprintf(("WARNING: ExtCreateRegion GpiCreateRegion failed! (%x)", WinGetLastError(0))); | 
|---|
| 1421 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1422 | return 0; | 
|---|
| 1423 | } | 
|---|
| 1424 | } | 
|---|
| 1425 |  | 
|---|
| 1426 | if(ObjAllocateHandle(&hrgn, hrgn, HNDL_REGION) == FALSE) { | 
|---|
| 1427 | GpiDestroyRegion(hpsRegion, hrgn); | 
|---|
| 1428 | SetLastError(ERROR_OUTOFMEMORY_W); | 
|---|
| 1429 | return 0; | 
|---|
| 1430 | } | 
|---|
| 1431 | STATS_ExtCreateRegion(hrgn, (PVOID)pXform, count, pData); | 
|---|
| 1432 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1433 | return hrgn; | 
|---|
| 1434 | } | 
|---|
| 1435 | //****************************************************************************** | 
|---|
| 1436 | //****************************************************************************** | 
|---|
| 1437 | HRGN WIN32API CreateEllipticRgn(int  left, int  top, int  right, int  bottom) | 
|---|
| 1438 | { | 
|---|
| 1439 | HRGN hrgn; | 
|---|
| 1440 |  | 
|---|
| 1441 | RECTL  rectl = { left, | 
|---|
| 1442 | top < bottom ? top : bottom, | 
|---|
| 1443 | right, | 
|---|
| 1444 | top < bottom ? bottom : top }; | 
|---|
| 1445 |  | 
|---|
| 1446 | dprintf(("CreateEllipticRgn (%d,%d)(%d,%d)", left, top, right, bottom)); | 
|---|
| 1447 | hrgn = GpiCreateEllipticRegion(hpsRegion, &rectl); | 
|---|
| 1448 | if(hrgn == RGN_ERROR) { | 
|---|
| 1449 | SetLastError(ERROR_INVALID_PARAMETER_W); //todo: not right | 
|---|
| 1450 | dprintf(("WARNING: CreateEllipticRgn: GpiCreateEllipticRegion failed! %x", WinGetLastError(0))); | 
|---|
| 1451 | return 0; | 
|---|
| 1452 | } | 
|---|
| 1453 |  | 
|---|
| 1454 | if(ObjAllocateHandle(&hrgn, hrgn, HNDL_REGION) == FALSE) { | 
|---|
| 1455 | GpiDestroyRegion(hpsRegion, hrgn); | 
|---|
| 1456 | SetLastError(ERROR_OUTOFMEMORY_W); | 
|---|
| 1457 | return 0; | 
|---|
| 1458 | } | 
|---|
| 1459 | STATS_CreateEllipticRgn(hrgn, left, top, right, bottom); | 
|---|
| 1460 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1461 | return hrgn; | 
|---|
| 1462 | } | 
|---|
| 1463 | //****************************************************************************** | 
|---|
| 1464 | //****************************************************************************** | 
|---|
| 1465 | HRGN WIN32API CreateEllipticRgnIndirect(const RECT *pRect) | 
|---|
| 1466 | { | 
|---|
| 1467 | return CreateEllipticRgn(pRect->left, pRect->top, pRect->right, pRect->bottom); | 
|---|
| 1468 | } | 
|---|
| 1469 | //****************************************************************************** | 
|---|
| 1470 | //****************************************************************************** | 
|---|
| 1471 | HRGN WIN32API CreatePolygonRgn(const POINT * lppt, int  cPoints, int  fnPolyFillMode) | 
|---|
| 1472 | { | 
|---|
| 1473 | HRGN hrgn; | 
|---|
| 1474 | LONG flMode; | 
|---|
| 1475 |  | 
|---|
| 1476 | if(!lppt || cPoints < 2) { | 
|---|
| 1477 | dprintf(("WARNING: CreatePolygonRgn %x %d %d invalid parameter", lppt, cPoints, fnPolyFillMode)); | 
|---|
| 1478 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1479 | return 0; | 
|---|
| 1480 | } | 
|---|
| 1481 |  | 
|---|
| 1482 | switch (fnPolyFillMode) | 
|---|
| 1483 | { | 
|---|
| 1484 | case ALTERNATE_W : | 
|---|
| 1485 | flMode = POLYGON_ALTERNATE; | 
|---|
| 1486 | break; | 
|---|
| 1487 | case WINDING_W   : | 
|---|
| 1488 | flMode = POLYGON_WINDING; | 
|---|
| 1489 | break; | 
|---|
| 1490 | default: | 
|---|
| 1491 | dprintf(("WARNING: CreatePolygonRgn %x %d %d invalid parameter", lppt, cPoints, fnPolyFillMode)); | 
|---|
| 1492 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1493 | return 0; | 
|---|
| 1494 | } | 
|---|
| 1495 | dprintf(("CreatePolygonRgn %x %d %d", lppt, cPoints, fnPolyFillMode)); | 
|---|
| 1496 |  | 
|---|
| 1497 | POLYGON  polygon; | 
|---|
| 1498 | polygon.ulPoints = cPoints - 1; | 
|---|
| 1499 | polygon.aPointl  = (PPOINTL)(lppt + 1); | 
|---|
| 1500 |  | 
|---|
| 1501 | #ifdef DEBUG | 
|---|
| 1502 | for(int i=0;i<cPoints;i++) { | 
|---|
| 1503 | dprintf(("Point %d: (%d,%d)", i, lppt[i].x, lppt[i].y)); | 
|---|
| 1504 | } | 
|---|
| 1505 | #endif | 
|---|
| 1506 | GpiMove(hpsRegion, (PPOINTL)lppt); | 
|---|
| 1507 | hrgn = GpiCreatePolygonRegion(hpsRegion, 1, &polygon, POLYGON_BOUNDARY | flMode); | 
|---|
| 1508 | if(hrgn == RGN_ERROR) { | 
|---|
| 1509 | SetLastError(ERROR_INVALID_PARAMETER_W); //todo: not right | 
|---|
| 1510 | dprintf(("WARNING: CreatePolygonRgn: GpiCreatePolygonRegion failed! %x", WinGetLastError(0))); | 
|---|
| 1511 | return 0; | 
|---|
| 1512 | } | 
|---|
| 1513 |  | 
|---|
| 1514 | if(ObjAllocateHandle(&hrgn, hrgn, HNDL_REGION) == FALSE) { | 
|---|
| 1515 | GpiDestroyRegion(hpsRegion, hrgn); | 
|---|
| 1516 | SetLastError(ERROR_OUTOFMEMORY_W); | 
|---|
| 1517 | return 0; | 
|---|
| 1518 | } | 
|---|
| 1519 | STATS_CreatePolygonRgn(hrgn, lppt, cPoints, fnPolyFillMode); | 
|---|
| 1520 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1521 | return hrgn; | 
|---|
| 1522 | } | 
|---|
| 1523 | //****************************************************************************** | 
|---|
| 1524 | //****************************************************************************** | 
|---|
| 1525 | int WIN32API CombineRgn(HRGN hrgnDest, HRGN hrgnSrc1, HRGN hrgnSrc2, int combineMode) | 
|---|
| 1526 | { | 
|---|
| 1527 | ULONG lComplexity; | 
|---|
| 1528 | LONG  mode; | 
|---|
| 1529 | #ifdef DEBUG_LOGGING | 
|---|
| 1530 | HRGN hrgn1 = hrgnDest; | 
|---|
| 1531 | HRGN hrgn2 = hrgnSrc1; | 
|---|
| 1532 | HRGN hrgn3 = hrgnSrc2; | 
|---|
| 1533 | #endif | 
|---|
| 1534 |  | 
|---|
| 1535 | switch(combineMode) { | 
|---|
| 1536 | case RGN_AND_W: | 
|---|
| 1537 | mode = CRGN_AND; | 
|---|
| 1538 | break; | 
|---|
| 1539 | case RGN_COPY_W: | 
|---|
| 1540 | mode = CRGN_COPY; | 
|---|
| 1541 | break; | 
|---|
| 1542 | case RGN_DIFF_W: | 
|---|
| 1543 | mode = CRGN_DIFF; | 
|---|
| 1544 | break; | 
|---|
| 1545 | case RGN_OR_W: | 
|---|
| 1546 | mode = CRGN_OR; | 
|---|
| 1547 | break; | 
|---|
| 1548 | case RGN_XOR_W: | 
|---|
| 1549 | mode = CRGN_XOR; | 
|---|
| 1550 | break; | 
|---|
| 1551 | default: | 
|---|
| 1552 | dprintf(("WARNING: CombineRgn %x %x %x %d; invalid mode!", hrgnDest, hrgnSrc1, hrgnSrc2, combineMode)); | 
|---|
| 1553 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1554 | return ERROR_W; | 
|---|
| 1555 | } | 
|---|
| 1556 |  | 
|---|
| 1557 | hrgnDest = ObjQueryHandleData(hrgnDest, HNDL_REGION); | 
|---|
| 1558 | hrgnSrc1 = ObjQueryHandleData(hrgnSrc1, HNDL_REGION); | 
|---|
| 1559 | hrgnSrc2 = ObjQueryHandleData(hrgnSrc2, HNDL_REGION); | 
|---|
| 1560 | if(hrgnDest == HANDLE_OBJ_ERROR || hrgnSrc1 == HANDLE_OBJ_ERROR  || (hrgnSrc2 == HANDLE_OBJ_ERROR && combineMode != RGN_COPY_W)) { | 
|---|
| 1561 | dprintf(("WARNING: CombineRgn %x %x %x %d invalid region", hrgn1, hrgn2, hrgn3, combineMode)); | 
|---|
| 1562 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1563 | return ERROR_W; | 
|---|
| 1564 | } | 
|---|
| 1565 |  | 
|---|
| 1566 | lComplexity = GpiCombineRegion(hpsRegion, hrgnDest, hrgnSrc1, hrgnSrc2, mode); | 
|---|
| 1567 | if(lComplexity == RGN_ERROR) { | 
|---|
| 1568 | dprintf(("WARNING: CombineRgn %x %x %x %d GpiCombineRegion failed (%x)", hrgn1, hrgn2, hrgn3, mode, WinGetLastError(0))); | 
|---|
| 1569 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1570 | return ERROR_W; | 
|---|
| 1571 | } | 
|---|
| 1572 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1573 | return lComplexity; | 
|---|
| 1574 | } | 
|---|
| 1575 | //****************************************************************************** | 
|---|
| 1576 | //****************************************************************************** | 
|---|
| 1577 | BOOL WIN32API EqualRgn(HRGN  hrgn1, HRGN  hrgn2) | 
|---|
| 1578 | { | 
|---|
| 1579 | LONG lEquality; | 
|---|
| 1580 | #ifdef DEBUG_LOGGING | 
|---|
| 1581 | HRGN hrgnt1 = hrgn1; | 
|---|
| 1582 | HRGN hrgnt2 = hrgn2; | 
|---|
| 1583 | #endif | 
|---|
| 1584 |  | 
|---|
| 1585 | hrgn1 = ObjQueryHandleData(hrgn1, HNDL_REGION); | 
|---|
| 1586 | hrgn2 = ObjQueryHandleData(hrgn2, HNDL_REGION); | 
|---|
| 1587 | if(hrgn1 == HANDLE_OBJ_ERROR || hrgn2 == HANDLE_OBJ_ERROR) { | 
|---|
| 1588 | dprintf(("WARNING: EqualRgn %x %x invalid region", hrgnt1, hrgnt2)); | 
|---|
| 1589 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1590 | return FALSE; | 
|---|
| 1591 | } | 
|---|
| 1592 | lEquality = GpiEqualRegion(hpsRegion, hrgn1, hrgn2); | 
|---|
| 1593 |  | 
|---|
| 1594 | dprintf(("EqualRgn %x %x = %d", hrgnt1, hrgnt2, lEquality)); | 
|---|
| 1595 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1596 |  | 
|---|
| 1597 | if(lEquality == EQRGN_EQUAL) | 
|---|
| 1598 | return TRUE; | 
|---|
| 1599 | else | 
|---|
| 1600 | if(lEquality == EQRGN_NOTEQUAL) | 
|---|
| 1601 | return FALSE; | 
|---|
| 1602 | else { | 
|---|
| 1603 | return FALSE; | 
|---|
| 1604 | } | 
|---|
| 1605 | } | 
|---|
| 1606 | //****************************************************************************** | 
|---|
| 1607 | //****************************************************************************** | 
|---|
| 1608 | BOOL WIN32API SetRectRgn(HRGN  hrgn, int  left, int  top, int  right, int  bottom) | 
|---|
| 1609 | { | 
|---|
| 1610 | BOOL    result = FALSE; | 
|---|
| 1611 | #ifdef DEBUG_LOGGING | 
|---|
| 1612 | HRGN      hrgn1 = hrgn; | 
|---|
| 1613 | #endif | 
|---|
| 1614 |  | 
|---|
| 1615 | hrgn = ObjQueryHandleData(hrgn, HNDL_REGION); | 
|---|
| 1616 | if(hrgn == HANDLE_OBJ_ERROR) { | 
|---|
| 1617 | dprintf(("WARNING: SetRectRgn %x (%d,%d)(%d,%d) invalid region handle", hrgn1, left, top, right, bottom)); | 
|---|
| 1618 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1619 | return 0; | 
|---|
| 1620 | } | 
|---|
| 1621 | RECTL rectl = { left, top, right, bottom }; //reversed y coordinates | 
|---|
| 1622 | if(GpiSetRegion(hpsRegion, hrgn, 1, &rectl)) { | 
|---|
| 1623 | dprintf(("SetRectRgn %x (%d,%d)(%d,%d)", hrgn1, left, top, right, bottom)); | 
|---|
| 1624 | return TRUE; | 
|---|
| 1625 | } | 
|---|
| 1626 | dprintf(("WARNING: SetRectRgn %x (%d,%d)(%d,%d) GpiSetRegion failed %x", hrgn1, left, top, right, bottom, WinGetLastError(0))); | 
|---|
| 1627 | return FALSE; | 
|---|
| 1628 | } | 
|---|
| 1629 | //****************************************************************************** | 
|---|
| 1630 | //NOTE: depends on hps inversion | 
|---|
| 1631 | //****************************************************************************** | 
|---|
| 1632 | ULONG WIN32API GetRegionData( HRGN  hrgn, ULONG count, PRGNDATA pData) | 
|---|
| 1633 | { | 
|---|
| 1634 | #ifdef DEBUG_LOGGING | 
|---|
| 1635 | HRGN      hrgn1 = hrgn; | 
|---|
| 1636 | #endif | 
|---|
| 1637 |  | 
|---|
| 1638 | if(!count && pData) | 
|---|
| 1639 | { | 
|---|
| 1640 | dprintf(("WARNING: GetRegionData %x %d %x; invalid parameter", hrgn1, count, pData)); | 
|---|
| 1641 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1642 | return 0; | 
|---|
| 1643 | } | 
|---|
| 1644 | hrgn = ObjQueryHandleData(hrgn, HNDL_REGION); | 
|---|
| 1645 | if(hrgn == HANDLE_OBJ_ERROR) { | 
|---|
| 1646 | dprintf(("WARNING: GetRegionData %x %d %x; invalid region handle", hrgn1, count, pData)); | 
|---|
| 1647 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1648 | return 0; | 
|---|
| 1649 | } | 
|---|
| 1650 | RGNRECT rgnRect; | 
|---|
| 1651 | rgnRect.ircStart    = 1; | 
|---|
| 1652 | rgnRect.crc         = 0; | 
|---|
| 1653 | rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT; | 
|---|
| 1654 | if(!GpiQueryRegionRects(hpsRegion, hrgn, NULL, &rgnRect, NULL)) | 
|---|
| 1655 | { | 
|---|
| 1656 | dprintf(("WARNING: GetRegionData %x %d %x: GpiQueryRegionRects failed! (%x)", hrgn1, count, pData, WinGetLastError(0))); | 
|---|
| 1657 | return 0; | 
|---|
| 1658 | } | 
|---|
| 1659 |  | 
|---|
| 1660 | dprintf(("GetRegionData %x %d %x", hrgn1, count, pData)); | 
|---|
| 1661 |  | 
|---|
| 1662 | ULONG bufSizeNeeded = rgnRect.crcReturned * sizeof(RECT) + sizeof (RGNDATAHEADER); | 
|---|
| 1663 |  | 
|---|
| 1664 | if(pData && (count >= (sizeof(RGNDATAHEADER) + rgnRect.crcReturned * sizeof(RECT)))) | 
|---|
| 1665 | { | 
|---|
| 1666 | //we actually need to flip the top & bottom values, but as the layout of the PM RECTL and | 
|---|
| 1667 | //Win32 RECT have exactly those two members reversed, we don't do this for the returned | 
|---|
| 1668 | //rectangles (more efficient) | 
|---|
| 1669 | PRECTL pRectl = (PRECTL)pData->Buffer; | 
|---|
| 1670 | rgnRect.crc   = rgnRect.crcReturned; | 
|---|
| 1671 | if(!GpiQueryRegionRects(hpsRegion, hrgn, NULL, &rgnRect, pRectl)) | 
|---|
| 1672 | { | 
|---|
| 1673 | dprintf(("WARNING: GetRegionData: GpiQueryRegionRects failed! (%x)", WinGetLastError(0))); | 
|---|
| 1674 | return 0; | 
|---|
| 1675 | } | 
|---|
| 1676 |  | 
|---|
| 1677 | RECTL boundRect; | 
|---|
| 1678 | GpiQueryRegionBox(hpsRegion, hrgn, &boundRect);  // no need to check rc | 
|---|
| 1679 |  | 
|---|
| 1680 | pData->rdh.dwSize   = sizeof(pData->rdh); | 
|---|
| 1681 | pData->rdh.iType    = RDH_RECTANGLES_W;    // one and only possible value | 
|---|
| 1682 | pData->rdh.nCount   = rgnRect.crcReturned; | 
|---|
| 1683 | pData->rdh.nRgnSize = rgnRect.crcReturned * sizeof(RECT); | 
|---|
| 1684 |  | 
|---|
| 1685 | //flip top & bottom for bounding rectangle (not really necessary; but cleaner coding) | 
|---|
| 1686 | LONG temp          = boundRect.yTop; | 
|---|
| 1687 | boundRect.yTop     = boundRect.yBottom; | 
|---|
| 1688 | boundRect.yBottom  = temp; | 
|---|
| 1689 | MapOS2ToWin32Rect(boundRect, pData->rdh.rcBound); | 
|---|
| 1690 | } | 
|---|
| 1691 |  | 
|---|
| 1692 | //return size needed | 
|---|
| 1693 | return bufSizeNeeded; | 
|---|
| 1694 | } | 
|---|
| 1695 | //****************************************************************************** | 
|---|
| 1696 | //****************************************************************************** | 
|---|
| 1697 | int WIN32API GetRgnBox( HRGN  hrgn, PRECT pRect) | 
|---|
| 1698 | { | 
|---|
| 1699 | BOOL      success; | 
|---|
| 1700 | LONG      lComplexity; | 
|---|
| 1701 | #ifdef DEBUG_LOGGING | 
|---|
| 1702 | HRGN      hrgn1 = hrgn; | 
|---|
| 1703 | #endif | 
|---|
| 1704 |  | 
|---|
| 1705 | hrgn = ObjQueryHandleData(hrgn, HNDL_REGION); | 
|---|
| 1706 | if(hrgn == HANDLE_OBJ_ERROR) { | 
|---|
| 1707 | dprintf(("WARNING: GetRgnBox %x %x invalid region!", hrgn1, pRect)); | 
|---|
| 1708 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1709 | return ERROR_W; | 
|---|
| 1710 | } | 
|---|
| 1711 |  | 
|---|
| 1712 | RECTL  rectl; | 
|---|
| 1713 | lComplexity = GpiQueryRegionBox(hpsRegion, hrgn, &rectl); | 
|---|
| 1714 | if(lComplexity != RGN_ERROR) | 
|---|
| 1715 | { | 
|---|
| 1716 | //no conversion required, just flip top & bottom | 
|---|
| 1717 | ULONG temp    = rectl.yBottom; | 
|---|
| 1718 | rectl.yBottom = rectl.yTop; | 
|---|
| 1719 | rectl.yTop    = temp; | 
|---|
| 1720 |  | 
|---|
| 1721 | MapOS2ToWin32Rect(rectl, *pRect); | 
|---|
| 1722 | } | 
|---|
| 1723 | else { | 
|---|
| 1724 | lComplexity = ERROR_W; | 
|---|
| 1725 | dprintf(("WARNING: GetRgnBox error in region!")); | 
|---|
| 1726 | } | 
|---|
| 1727 | dprintf(("GetRgnBox %x (%d,%d)(%d,%d)", hrgn1, pRect->left, pRect->top, pRect->right, pRect->bottom)); | 
|---|
| 1728 |  | 
|---|
| 1729 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1730 | return lComplexity; | 
|---|
| 1731 | } | 
|---|
| 1732 | //****************************************************************************** | 
|---|
| 1733 | //****************************************************************************** | 
|---|
| 1734 | BOOL WIN32API InvertRgn( HDC  hdc, HRGN  hrgn) | 
|---|
| 1735 | { | 
|---|
| 1736 | #ifdef DEBUG_LOGGING | 
|---|
| 1737 | HRGN      hrgn1 = hrgn; | 
|---|
| 1738 | #endif | 
|---|
| 1739 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 1740 |  | 
|---|
| 1741 | hrgn = ObjQueryHandleData(hrgn, HNDL_REGION); | 
|---|
| 1742 | if(!pHps || hrgn == HANDLE_OBJ_ERROR) { | 
|---|
| 1743 | dprintf(("WARNING: InvertRgn %x %x invalid handle!", hdc, hrgn)); | 
|---|
| 1744 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1745 | return FALSE; | 
|---|
| 1746 | } | 
|---|
| 1747 | //todo metafile recording | 
|---|
| 1748 |  | 
|---|
| 1749 | dprintf(("InvertRgn %x %x", hdc, hrgn1)); | 
|---|
| 1750 |  | 
|---|
| 1751 | interpretRegionAs(pHps, NULL, hrgn, AS_WORLD); | 
|---|
| 1752 |  | 
|---|
| 1753 | LONG  lHits = GPI_ERROR; | 
|---|
| 1754 | HRGN  hrgnOld; | 
|---|
| 1755 | LONG  lComplexity ; | 
|---|
| 1756 | RECTL boundingRect;      // this gets a rectangle in world cordinates! | 
|---|
| 1757 |  | 
|---|
| 1758 | lComplexity = GpiQueryRegionBox(pHps->hps, pHps->hrgnHDC,  &boundingRect); | 
|---|
| 1759 | if(lComplexity != RGN_ERROR) | 
|---|
| 1760 | { | 
|---|
| 1761 | lComplexity = GpiSetClipRegion(pHps->hps, pHps->hrgnHDC,  &hrgnOld); | 
|---|
| 1762 | if(lComplexity != RGN_ERROR) | 
|---|
| 1763 | { | 
|---|
| 1764 | RECTL rectls[2]; | 
|---|
| 1765 | rectls[0] = boundingRect; | 
|---|
| 1766 | rectls[1] = boundingRect; | 
|---|
| 1767 | lHits = GpiBitBlt(pHps->hps, NULL, 3, (PPOINTL)rectls, | 
|---|
| 1768 | ROP_DSTINVERT, 0); | 
|---|
| 1769 |  | 
|---|
| 1770 | /* Restore the old region */ | 
|---|
| 1771 | GpiSetClipRegion(pHps->hps, hrgnOld, &hrgnOld); | 
|---|
| 1772 | } | 
|---|
| 1773 | } | 
|---|
| 1774 |  | 
|---|
| 1775 | if(lHits == GPI_ERROR || lComplexity == RGN_ERROR) | 
|---|
| 1776 | { | 
|---|
| 1777 | dprintf(("WARNING: InvertRgn error during Gpi operation (%x) (%d,%d)", WinGetLastError(0), lHits, lComplexity)); | 
|---|
| 1778 | return FALSE; | 
|---|
| 1779 | } | 
|---|
| 1780 |  | 
|---|
| 1781 | DIBSECTION_MARK_INVALID(hdc); | 
|---|
| 1782 | return TRUE; | 
|---|
| 1783 | } | 
|---|
| 1784 | //****************************************************************************** | 
|---|
| 1785 | //****************************************************************************** | 
|---|
| 1786 | int WIN32API OffsetRgn( HRGN  hrgn, int  xOffset, int  yOffset) | 
|---|
| 1787 | { | 
|---|
| 1788 | LONG   lComplexity; | 
|---|
| 1789 | #ifdef DEBUG_LOGGING | 
|---|
| 1790 | HRGN      hrgn1 = hrgn; | 
|---|
| 1791 | #endif | 
|---|
| 1792 |  | 
|---|
| 1793 | hrgn = ObjQueryHandleData(hrgn, HNDL_REGION); | 
|---|
| 1794 | if(hrgn == HANDLE_OBJ_ERROR) { | 
|---|
| 1795 | dprintf(("WARNING: OffsetRgn %x %d %d invalid handle!", hrgn, xOffset, yOffset)); | 
|---|
| 1796 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1797 | return ERROR_W; | 
|---|
| 1798 | } | 
|---|
| 1799 | dprintf(("OffsetRgn %x %d %d", hrgn1, xOffset, yOffset)); | 
|---|
| 1800 |  | 
|---|
| 1801 | POINTL   ptlOffset = {xOffset, yOffset}; | 
|---|
| 1802 | GpiOffsetRegion(hpsRegion, hrgn, &ptlOffset); | 
|---|
| 1803 |  | 
|---|
| 1804 | RECTL    rectl[8]; | 
|---|
| 1805 | RGNRECT  rgnRect; | 
|---|
| 1806 | rgnRect.ircStart    = 1; | 
|---|
| 1807 | rgnRect.crc         = 8; | 
|---|
| 1808 | rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT;     // doesn't make a difference | 
|---|
| 1809 | if(GpiQueryRegionRects(hpsRegion, hrgn, NULL, &rgnRect, &rectl[0])) | 
|---|
| 1810 | { | 
|---|
| 1811 | switch (rgnRect.crcReturned) { | 
|---|
| 1812 | case 0: | 
|---|
| 1813 | lComplexity = NULLREGION_W; | 
|---|
| 1814 | break; | 
|---|
| 1815 | case 1: | 
|---|
| 1816 | lComplexity = SIMPLEREGION_W; | 
|---|
| 1817 | break; | 
|---|
| 1818 | default: | 
|---|
| 1819 | lComplexity = COMPLEXREGION_W; | 
|---|
| 1820 | break; | 
|---|
| 1821 | } | 
|---|
| 1822 | } | 
|---|
| 1823 | else { | 
|---|
| 1824 | lComplexity = ERROR_W; | 
|---|
| 1825 | dprintf(("WARNING: OffsetRgn error in region! (%x)", WinGetLastError(0))); | 
|---|
| 1826 | } | 
|---|
| 1827 |  | 
|---|
| 1828 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1829 |  | 
|---|
| 1830 | return lComplexity; | 
|---|
| 1831 | } | 
|---|
| 1832 | //****************************************************************************** | 
|---|
| 1833 | //****************************************************************************** | 
|---|
| 1834 | BOOL WIN32API FrameRgn(HDC hdc, HRGN hrgn, HBRUSH hBrush, int width, int height) | 
|---|
| 1835 | { | 
|---|
| 1836 | HBRUSH hbrushRestore = 0; | 
|---|
| 1837 | #ifdef DEBUG_LOGGING | 
|---|
| 1838 | HRGN   hrgn1 = hrgn; | 
|---|
| 1839 | #endif | 
|---|
| 1840 | pDCData  pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 1841 |  | 
|---|
| 1842 | hrgn = ObjQueryHandleData(hrgn, HNDL_REGION); | 
|---|
| 1843 | if(!pHps || hrgn == HANDLE_OBJ_ERROR) { | 
|---|
| 1844 | dprintf(("WARNING: FrameRgn %x %x %x (%d,%d) invalid handle!", hdc, hrgn, hBrush, width, height)); | 
|---|
| 1845 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1846 | return FALSE; | 
|---|
| 1847 | } | 
|---|
| 1848 |  | 
|---|
| 1849 | width  = abs(width); | 
|---|
| 1850 | height = abs(height); | 
|---|
| 1851 |  | 
|---|
| 1852 | if(pHps->lastBrushKey != (UINT)hBrush) | 
|---|
| 1853 | { | 
|---|
| 1854 | hbrushRestore = SelectObject(hdc, hBrush); | 
|---|
| 1855 | if(!hbrushRestore) | 
|---|
| 1856 | { | 
|---|
| 1857 | dprintf(("WARNING: FrameRgn %x %x %x (%d,%d) invalid brush!", hdc, hrgn, hBrush, width, height)); | 
|---|
| 1858 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1859 | return FALSE; | 
|---|
| 1860 | } | 
|---|
| 1861 | } | 
|---|
| 1862 | dprintf(("FrameRgn %x %x %x (%d,%d)", hdc, hrgn1, hBrush, width, height)); | 
|---|
| 1863 | interpretRegionAs(pHps, NULL, hrgn, AS_WORLD); | 
|---|
| 1864 |  | 
|---|
| 1865 | SIZEL  thickness = { width, height }; | 
|---|
| 1866 | LONG   lHits = GpiFrameRegion(pHps->hps, pHps->hrgnHDC,  &thickness); | 
|---|
| 1867 |  | 
|---|
| 1868 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1869 |  | 
|---|
| 1870 | // Restore the brush if necessary | 
|---|
| 1871 | if(hbrushRestore) | 
|---|
| 1872 | SelectObject(hdc, hbrushRestore); | 
|---|
| 1873 |  | 
|---|
| 1874 | if(lHits != GPI_ERROR) | 
|---|
| 1875 | DIBSECTION_MARK_INVALID(hdc); | 
|---|
| 1876 |  | 
|---|
| 1877 | //todo metafile recording | 
|---|
| 1878 | return (lHits != GPI_ERROR); | 
|---|
| 1879 | } | 
|---|
| 1880 | //****************************************************************************** | 
|---|
| 1881 | //****************************************************************************** | 
|---|
| 1882 | BOOL WIN32API FillRgn(HDC hdc, HRGN hrgn, HBRUSH hBrush) | 
|---|
| 1883 | { | 
|---|
| 1884 | BOOL   success; | 
|---|
| 1885 | HBRUSH hbrushRestore = 0; | 
|---|
| 1886 | #ifdef DEBUG_LOGGING | 
|---|
| 1887 | HRGN   hrgn1 = hrgn; | 
|---|
| 1888 | #endif | 
|---|
| 1889 |  | 
|---|
| 1890 | pDCData  pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 1891 |  | 
|---|
| 1892 | hrgn = ObjQueryHandleData(hrgn, HNDL_REGION); | 
|---|
| 1893 | if(!pHps || hrgn == HANDLE_OBJ_ERROR) { | 
|---|
| 1894 | dprintf(("WARNING: FillRgn %x %x %x invalid handle!", hdc, hrgn1, hBrush)); | 
|---|
| 1895 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1896 | return FALSE; | 
|---|
| 1897 | } | 
|---|
| 1898 |  | 
|---|
| 1899 | if(pHps->lastBrushKey != (UINT)hBrush) | 
|---|
| 1900 | { | 
|---|
| 1901 | hbrushRestore = SelectObject(hdc, hBrush); | 
|---|
| 1902 | if (!hbrushRestore) | 
|---|
| 1903 | { | 
|---|
| 1904 | dprintf(("WARNING: FillRgn %x %x %x invalid brush!", hdc, hrgn1, hBrush)); | 
|---|
| 1905 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1906 | return FALSE; | 
|---|
| 1907 | } | 
|---|
| 1908 | } | 
|---|
| 1909 | dprintf(("FillRgn %x %x %x", hdc, hrgn1, hBrush)); | 
|---|
| 1910 |  | 
|---|
| 1911 | DIBSECTION_CHECK_IF_DIRTY(hdc); | 
|---|
| 1912 | interpretRegionAs(pHps, NULL, hrgn, AS_WORLD); | 
|---|
| 1913 |  | 
|---|
| 1914 | dprintfRegion(pHps->hps, pHps->hrgnHDC); | 
|---|
| 1915 |  | 
|---|
| 1916 | success = GpiPaintRegion(pHps->hps, pHps->hrgnHDC); | 
|---|
| 1917 |  | 
|---|
| 1918 | //todo metafile recording | 
|---|
| 1919 |  | 
|---|
| 1920 | /* Restore the brush if necessary */ | 
|---|
| 1921 | if(hbrushRestore) | 
|---|
| 1922 | SelectObject(hdc, hbrushRestore); | 
|---|
| 1923 |  | 
|---|
| 1924 | if(success) | 
|---|
| 1925 | DIBSECTION_MARK_INVALID(hdc); | 
|---|
| 1926 |  | 
|---|
| 1927 | return(success); | 
|---|
| 1928 | } | 
|---|
| 1929 | //****************************************************************************** | 
|---|
| 1930 | //****************************************************************************** | 
|---|
| 1931 | BOOL WIN32API PaintRgn( HDC  hdc, HRGN  hrgn) | 
|---|
| 1932 | { | 
|---|
| 1933 | return FillRgn(hdc, hrgn, (HBRUSH) GetCurrentObject(hdc, OBJ_BRUSH_W)); | 
|---|
| 1934 | } | 
|---|
| 1935 | //****************************************************************************** | 
|---|
| 1936 | //****************************************************************************** | 
|---|
| 1937 | BOOL WIN32API PtInRegion( HRGN  hrgn, int  x, int  y) | 
|---|
| 1938 | { | 
|---|
| 1939 | BOOL      success; | 
|---|
| 1940 | LONG      lInside; | 
|---|
| 1941 | #ifdef DEBUG_LOGGING | 
|---|
| 1942 | HRGN      hrgn1 = hrgn; | 
|---|
| 1943 | #endif | 
|---|
| 1944 |  | 
|---|
| 1945 | hrgn = ObjQueryHandleData(hrgn, HNDL_REGION); | 
|---|
| 1946 | if(hrgn == HANDLE_OBJ_ERROR) { | 
|---|
| 1947 | dprintf(("WARNING: PtInRgn %x (%d,%d) invalid region!", hrgn1, x, y)); | 
|---|
| 1948 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1949 | return FALSE; | 
|---|
| 1950 | } | 
|---|
| 1951 |  | 
|---|
| 1952 | POINTL pointl = {x,y}; | 
|---|
| 1953 | lInside = GpiPtInRegion(hpsRegion, hrgn, &pointl); | 
|---|
| 1954 | if(lInside == PRGN_ERROR) { | 
|---|
| 1955 | success = FALSE; | 
|---|
| 1956 | } | 
|---|
| 1957 | else success = TRUE; | 
|---|
| 1958 |  | 
|---|
| 1959 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 1960 |  | 
|---|
| 1961 | dprintf(("PtInRgn %x (%d,%d) returned %d", hrgn1, x, y, (success && lInside == PRGN_INSIDE) ? 1 : 0)); | 
|---|
| 1962 |  | 
|---|
| 1963 | if(success && lInside == PRGN_INSIDE) | 
|---|
| 1964 | return TRUE; | 
|---|
| 1965 | else | 
|---|
| 1966 | return FALSE; | 
|---|
| 1967 | } | 
|---|
| 1968 | //****************************************************************************** | 
|---|
| 1969 | //****************************************************************************** | 
|---|
| 1970 | BOOL WIN32API RectInRegion( HRGN  hrgn, const RECT * pRect) | 
|---|
| 1971 | { | 
|---|
| 1972 | BOOL      success; | 
|---|
| 1973 | LONG      lInside; | 
|---|
| 1974 | #ifdef DEBUG_LOGGING | 
|---|
| 1975 | HRGN      hrgn1 = hrgn; | 
|---|
| 1976 | #endif | 
|---|
| 1977 |  | 
|---|
| 1978 | if(!pRect) { | 
|---|
| 1979 | dprintf(("WARNING: RectInRgn %x %x invalid parameter!", hrgn1, pRect)); | 
|---|
| 1980 | SetLastError(ERROR_INVALID_PARAMETER_W); | 
|---|
| 1981 | return FALSE; | 
|---|
| 1982 | } | 
|---|
| 1983 | hrgn = ObjQueryHandleData(hrgn, HNDL_REGION); | 
|---|
| 1984 | if(hrgn == HANDLE_OBJ_ERROR) { | 
|---|
| 1985 | dprintf(("WARNING: RectInRgn %x %x invalid region", hrgn1, pRect)); | 
|---|
| 1986 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 1987 | return FALSE; | 
|---|
| 1988 | } | 
|---|
| 1989 |  | 
|---|
| 1990 | RECTL rectl; | 
|---|
| 1991 | MapWin32ToOS2Rect(*pRect, rectl); | 
|---|
| 1992 | //switch bottom & top | 
|---|
| 1993 | UINT temp     = rectl.yBottom; | 
|---|
| 1994 | rectl.yBottom = rectl.yTop; | 
|---|
| 1995 | rectl.yTop    = temp; | 
|---|
| 1996 |  | 
|---|
| 1997 | lInside = GpiRectInRegion(hpsRegion, hrgn, &rectl); | 
|---|
| 1998 | if(lInside == RRGN_ERROR) { | 
|---|
| 1999 | success = FALSE; | 
|---|
| 2000 | } | 
|---|
| 2001 | else    success = TRUE; | 
|---|
| 2002 |  | 
|---|
| 2003 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 2004 |  | 
|---|
| 2005 | dprintf(("RectInRgn %x %x returned %d", hrgn1, pRect, (success && (lInside == RRGN_INSIDE || lInside == RRGN_PARTIAL)) ? 1 : 0)); | 
|---|
| 2006 |  | 
|---|
| 2007 | if(success && (lInside == RRGN_INSIDE || lInside == RRGN_PARTIAL)) | 
|---|
| 2008 | return TRUE; | 
|---|
| 2009 | else | 
|---|
| 2010 | return FALSE; | 
|---|
| 2011 | } | 
|---|
| 2012 | //****************************************************************************** | 
|---|
| 2013 | //Returned region in device coordinates (undocumented behaviour) | 
|---|
| 2014 | //****************************************************************************** | 
|---|
| 2015 | HRGN WIN32API PathToRegion(HDC hdc) | 
|---|
| 2016 | { | 
|---|
| 2017 | HRGN hrgn = 0, hrgnTemp = 0, hrgnwin = 0; | 
|---|
| 2018 |  | 
|---|
| 2019 | pDCData  pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc); | 
|---|
| 2020 | if(!pHps) | 
|---|
| 2021 | { | 
|---|
| 2022 | dprintf(("WARNING: PathToRegion %x; invalid hdc!", hdc)); | 
|---|
| 2023 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 2024 | return NULLHANDLE; | 
|---|
| 2025 | } | 
|---|
| 2026 | dprintf(("GDI32: PathToRegion %x", hdc)); | 
|---|
| 2027 |  | 
|---|
| 2028 | hrgnTemp = GpiPathToRegion(pHps->hps, 1, (pHps->polyFillMode == ALTERNATE_W) ? FPATH_ALTERNATE : FPATH_WINDING); | 
|---|
| 2029 | if(hrgnTemp == NULLHANDLE) { | 
|---|
| 2030 | dprintf(("GpiPathToRegion failed with %x", WinGetLastError(0))); | 
|---|
| 2031 | goto error; | 
|---|
| 2032 | } | 
|---|
| 2033 |  | 
|---|
| 2034 | hrgnwin = CreateRectRgn(1, 1, 2, 2); | 
|---|
| 2035 | hrgn = ObjQueryHandleData(hrgnwin, HNDL_REGION); | 
|---|
| 2036 | if(hrgn == HANDLE_OBJ_ERROR) { | 
|---|
| 2037 | dprintf(("WARNING: PathToRegion invalid region", hrgnwin)); | 
|---|
| 2038 | SetLastError(ERROR_INVALID_HANDLE_W); | 
|---|
| 2039 | return NULLHANDLE; | 
|---|
| 2040 | } | 
|---|
| 2041 |  | 
|---|
| 2042 | if(!setWinDeviceRegionFromPMDeviceRegion(hrgn, hrgnTemp, pHps, NULL)) | 
|---|
| 2043 | goto error; | 
|---|
| 2044 |  | 
|---|
| 2045 | GpiDestroyRegion(pHps->hps, hrgnTemp); | 
|---|
| 2046 |  | 
|---|
| 2047 | return hrgnwin; | 
|---|
| 2048 |  | 
|---|
| 2049 | error: | 
|---|
| 2050 | if(hrgnwin) | 
|---|
| 2051 | DeleteObject(hrgnwin); | 
|---|
| 2052 |  | 
|---|
| 2053 | if(hrgnTemp) | 
|---|
| 2054 | GpiDestroyRegion(pHps->hps, hrgnTemp); | 
|---|
| 2055 |  | 
|---|
| 2056 | SetLastError(ERROR_INVALID_HANDLE_W);       //todo right error | 
|---|
| 2057 | return NULLHANDLE; | 
|---|
| 2058 | } | 
|---|
| 2059 | //****************************************************************************** | 
|---|
| 2060 | //Selects the current path as a clipping region for a device context, combining | 
|---|
| 2061 | //any existing clipping region by using the specified mode | 
|---|
| 2062 | //****************************************************************************** | 
|---|
| 2063 | BOOL WIN32API SelectClipPath(HDC hdc, int iMode) | 
|---|
| 2064 | { | 
|---|
| 2065 | HRGN hrgn; | 
|---|
| 2066 | BOOL ret = FALSE; | 
|---|
| 2067 |  | 
|---|
| 2068 | hrgn = PathToRegion(hdc); | 
|---|
| 2069 | if(hrgn) | 
|---|
| 2070 | { | 
|---|
| 2071 | ret = ExtSelectClipRgn(hdc, hrgn, iMode) != ERROR_W; | 
|---|
| 2072 | DeleteObject(hrgn); | 
|---|
| 2073 | } | 
|---|
| 2074 |  | 
|---|
| 2075 | if(hrgn == NULLHANDLE || ret == FALSE) { | 
|---|
| 2076 | dprintf(("GDI32: SelectClipPath FAILED %x %d PRETEND success", hrgn, ret)); | 
|---|
| 2077 | ret = TRUE; | 
|---|
| 2078 | } | 
|---|
| 2079 | return ret; | 
|---|
| 2080 | } | 
|---|
| 2081 | //****************************************************************************** | 
|---|
| 2082 | //Needs wrapper as this file includes os2.h!! | 
|---|
| 2083 | //****************************************************************************** | 
|---|
| 2084 | BOOL WIN32API OSLibDeleteRegion(HANDLE hRegion) | 
|---|
| 2085 | { | 
|---|
| 2086 | if(GpiDestroyRegion(hpsRegion, hRegion) == FALSE) { | 
|---|
| 2087 | dprintf(("WARNING: OSLibDeleteRegion %x; GpiDestroyRegion failed (%x)", hRegion, WinGetLastError(0))); | 
|---|
| 2088 | } | 
|---|
| 2089 | return (0); | 
|---|
| 2090 | } | 
|---|
| 2091 | /***************************************************************************** | 
|---|
| 2092 | * Name      : int GetMetaRgn | 
|---|
| 2093 | * Purpose   : The GetMetaRgn function retrieves the current metaregion for | 
|---|
| 2094 | *             the specified device context. | 
|---|
| 2095 | * Parameters: HDC  hdc   handle of device context | 
|---|
| 2096 | *             HRGN hrgn  handle of region | 
|---|
| 2097 | * Variables : | 
|---|
| 2098 | * Result    : 0 / 1 | 
|---|
| 2099 | * Remark    : | 
|---|
| 2100 | * Status    : UNTESTED STUB | 
|---|
| 2101 | * | 
|---|
| 2102 | * Author    : Patrick Haller [Mon, 1998/06/15 08:00] | 
|---|
| 2103 | *****************************************************************************/ | 
|---|
| 2104 |  | 
|---|
| 2105 | int WIN32API GetMetaRgn( HDC   hdc, HRGN  hrgn) | 
|---|
| 2106 | { | 
|---|
| 2107 | dprintf(("GDI32: GetMetaRgn(%08xh, %08xh) not implemented.\n", | 
|---|
| 2108 | hdc, | 
|---|
| 2109 | hrgn)); | 
|---|
| 2110 |  | 
|---|
| 2111 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 2112 | return (0); | 
|---|
| 2113 | } | 
|---|
| 2114 | /***************************************************************************** | 
|---|
| 2115 | * Name      : int SetMetaRgn | 
|---|
| 2116 | * Purpose   : The SetMetaRgn function intersects the current clipping region | 
|---|
| 2117 | *             for the specified device context with the current metaregion | 
|---|
| 2118 | *             and saves the combined region as the new metaregion for the | 
|---|
| 2119 | *             specified device context. The clipping region is reset to a null region. | 
|---|
| 2120 | * Parameters: HDC    hdc   handle of device context | 
|---|
| 2121 | * Variables : | 
|---|
| 2122 | * Result    : TRUE / FALSE | 
|---|
| 2123 | * Remark    : | 
|---|
| 2124 | * Status    : UNTESTED STUB | 
|---|
| 2125 | * | 
|---|
| 2126 | * Author    : Patrick Haller [Mon, 1998/06/15 08:00] | 
|---|
| 2127 | *****************************************************************************/ | 
|---|
| 2128 |  | 
|---|
| 2129 | BOOL WIN32API SetMetaRgn( HDC  hdc) | 
|---|
| 2130 | { | 
|---|
| 2131 | dprintf(("GDI32: SetMetaRgn(%08xh) not implemented.\n", | 
|---|
| 2132 | hdc)); | 
|---|
| 2133 |  | 
|---|
| 2134 | SetLastError(ERROR_SUCCESS_W); | 
|---|
| 2135 | return (NULLREGION_W); | 
|---|
| 2136 | } | 
|---|
| 2137 | //****************************************************************************** | 
|---|
| 2138 | //****************************************************************************** | 
|---|