| 1 | /* $Id: region.cpp,v 1.14 2000-10-02 17:43:32 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 | *
|
|---|
| 9 | * TODO: Metafile recording
|
|---|
| 10 | * TODO: Do we need to translate & set the last error for Gpi operations?
|
|---|
| 11 | *
|
|---|
| 12 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 13 | *
|
|---|
| 14 | */
|
|---|
| 15 | #define INCL_GPI
|
|---|
| 16 | #define INCL_WIN
|
|---|
| 17 | #include <os2wrap.h> //need odin wrappers
|
|---|
| 18 |
|
|---|
| 19 | #include <win32type.h>
|
|---|
| 20 | #include <win32api.h>
|
|---|
| 21 | #include <winconst.h>
|
|---|
| 22 | #include <stdlib.h>
|
|---|
| 23 | #include <stdarg.h>
|
|---|
| 24 | #include <string.h>
|
|---|
| 25 | #include <misc.h>
|
|---|
| 26 | #include <odinwrap.h>
|
|---|
| 27 | #include <objhandle.h>
|
|---|
| 28 | #include <dcdata.h>
|
|---|
| 29 | #include <winuser32.h>
|
|---|
| 30 | #include <win32wnd.h>
|
|---|
| 31 | #include "oslibgpi.h"
|
|---|
| 32 |
|
|---|
| 33 | #define DBG_LOCALLOG DBG_region
|
|---|
| 34 | #include "dbglocal.h"
|
|---|
| 35 |
|
|---|
| 36 | typedef enum
|
|---|
| 37 | {
|
|---|
| 38 | AS_DEVICE,
|
|---|
| 39 | AS_WORLD
|
|---|
| 40 | } InterpMode;
|
|---|
| 41 |
|
|---|
| 42 | #define MEM_HPS_MAX 768
|
|---|
| 43 |
|
|---|
| 44 | static void convertDeviceRect(HWND hwnd, pDCData pHps, PRECTL pRectl, ULONG count);
|
|---|
| 45 |
|
|---|
| 46 | #define convertWinDeviceRectToPMDeviceRect(arg1, arg2, arg3) convertDeviceRect(arg1, arg2, arg3)
|
|---|
| 47 | #define convertPMDeviceRectToWinDeviceRect(arg1, arg2, arg3) convertDeviceRect(arg1, arg2, arg3)
|
|---|
| 48 |
|
|---|
| 49 | inline void convertDeviceRect(pDCData pHps, PRECTL pRectl, ULONG count)
|
|---|
| 50 | {
|
|---|
| 51 | convertDeviceRect(0, pHps, pRectl, count);
|
|---|
| 52 | }
|
|---|
| 53 | inline void convertDeviceRect(HWND hwnd, PRECTL pRectl, ULONG count)
|
|---|
| 54 | {
|
|---|
| 55 | convertDeviceRect(hwnd, 0, pRectl, count);
|
|---|
| 56 | }
|
|---|
| 57 |
|
|---|
| 58 | HPS hpsRegion = 0;
|
|---|
| 59 |
|
|---|
| 60 | //******************************************************************************
|
|---|
| 61 | //******************************************************************************
|
|---|
| 62 | BOOL InitRegionSpace()
|
|---|
| 63 | {
|
|---|
| 64 | hpsRegion = WinGetScreenPS(HWND_DESKTOP);
|
|---|
| 65 | return hpsRegion != 0;
|
|---|
| 66 | }
|
|---|
| 67 | //******************************************************************************
|
|---|
| 68 | //******************************************************************************
|
|---|
| 69 | static LONG clientHeight(HWND hwnd, pDCData pHps)
|
|---|
| 70 | {
|
|---|
| 71 | if(hwnd == 0 && pHps != 0)
|
|---|
| 72 | hwnd = pHps->hwnd;
|
|---|
| 73 |
|
|---|
| 74 | if(hwnd != 0 || pHps == 0)
|
|---|
| 75 | {
|
|---|
| 76 | RECT rect;
|
|---|
| 77 | RECTL rectl;
|
|---|
| 78 | LONG y = 0;
|
|---|
| 79 |
|
|---|
| 80 | if(pHps == 0 || pHps->isClient) //client area
|
|---|
| 81 | {
|
|---|
| 82 | if(GetClientRect(OS2ToWin32Handle(hwnd), &rect) == TRUE) {
|
|---|
| 83 | y = rect.bottom - rect.top;
|
|---|
| 84 | }
|
|---|
| 85 | }
|
|---|
| 86 | else
|
|---|
| 87 | if(WinQueryWindowRect(hwnd, &rectl)) //whole window
|
|---|
| 88 | y = rectl.yTop;
|
|---|
| 89 |
|
|---|
| 90 | return y;
|
|---|
| 91 | }
|
|---|
| 92 | else
|
|---|
| 93 | if(pHps->bitmapHandle)
|
|---|
| 94 | {
|
|---|
| 95 | return pHps->bitmapHeight;
|
|---|
| 96 | }
|
|---|
| 97 | else
|
|---|
| 98 | if(pHps->isMetaPS)
|
|---|
| 99 | {
|
|---|
| 100 | return 0;
|
|---|
| 101 | }
|
|---|
| 102 | else
|
|---|
| 103 | if(pHps->isPrinter)
|
|---|
| 104 | {
|
|---|
| 105 | return pHps->printPageHeight;
|
|---|
| 106 | }
|
|---|
| 107 | else
|
|---|
| 108 | {
|
|---|
| 109 | return MEM_HPS_MAX;
|
|---|
| 110 | }
|
|---|
| 111 | }
|
|---|
| 112 | //******************************************************************************
|
|---|
| 113 | //******************************************************************************
|
|---|
| 114 | static LONG clientWidth(HWND hwnd, pDCData pHps)
|
|---|
| 115 | {
|
|---|
| 116 | if(hwnd == 0 && pHps != 0)
|
|---|
| 117 | hwnd = pHps->hwnd;
|
|---|
| 118 |
|
|---|
| 119 | if(hwnd != 0 || pHps == 0)
|
|---|
| 120 | {
|
|---|
| 121 | RECT rect;
|
|---|
| 122 | RECTL rectl;
|
|---|
| 123 | LONG x = 0;
|
|---|
| 124 |
|
|---|
| 125 | if(pHps == 0 || pHps->isClient) //client area
|
|---|
| 126 | {
|
|---|
| 127 | if(GetClientRect(OS2ToWin32Handle(hwnd), &rect) == TRUE) {
|
|---|
| 128 | x = rect.right - rect.left;
|
|---|
| 129 | }
|
|---|
| 130 | }
|
|---|
| 131 | else
|
|---|
| 132 | if(WinQueryWindowRect(hwnd, &rectl)) //whole window
|
|---|
| 133 | x = rectl.xRight;
|
|---|
| 134 |
|
|---|
| 135 | return x;
|
|---|
| 136 | }
|
|---|
| 137 | // else
|
|---|
| 138 | // DebugInt3();
|
|---|
| 139 | return 0;
|
|---|
| 140 | }
|
|---|
| 141 | //******************************************************************************
|
|---|
| 142 | //******************************************************************************
|
|---|
| 143 | static void convertWinWorldRectToPMDeviceRect(pDCData pHps_Hdc, PRECTL pRects, UINT count = 1)
|
|---|
| 144 | {
|
|---|
| 145 | PRECTL pRectl;
|
|---|
| 146 | for (int x=0; x < count; x++)
|
|---|
| 147 | {
|
|---|
| 148 | pRectl = &pRects[x];
|
|---|
| 149 |
|
|---|
| 150 | if(pRectl->yTop < pRectl->yBottom) {
|
|---|
| 151 | ULONG temp = pRectl->yBottom;
|
|---|
| 152 | pRectl->yBottom = pRectl->yTop;
|
|---|
| 153 | pRectl->yTop = temp;
|
|---|
| 154 | }
|
|---|
| 155 | BOOL success = GpiConvert( pHps_Hdc->hps, CVTC_WORLD, CVTC_DEVICE, 2, (PPOINTL)pRectl);
|
|---|
| 156 | if(!success)
|
|---|
| 157 | {
|
|---|
| 158 | break;
|
|---|
| 159 | }
|
|---|
| 160 | if(pRectl->yTop < pRectl->yBottom) {
|
|---|
| 161 | ULONG temp = pRectl->yBottom;
|
|---|
| 162 | pRectl->yBottom = pRectl->yTop;
|
|---|
| 163 | pRectl->yTop = temp;
|
|---|
| 164 | }
|
|---|
| 165 | }
|
|---|
| 166 | }
|
|---|
| 167 | //******************************************************************************
|
|---|
| 168 | //******************************************************************************
|
|---|
| 169 | static void convertDeviceRect(HWND hwnd, pDCData pHps, PRECTL pRectl, ULONG count)
|
|---|
| 170 | {
|
|---|
| 171 | long wHeight, wWidth;
|
|---|
| 172 |
|
|---|
| 173 | if(hwnd == HWND_DESKTOP) {
|
|---|
| 174 | wHeight = OSLibGetScreenHeight();
|
|---|
| 175 | wWidth = OSLibGetScreenWidth();
|
|---|
| 176 | }
|
|---|
| 177 | else {
|
|---|
| 178 | wHeight = clientHeight(hwnd, pHps);
|
|---|
| 179 | wWidth = clientWidth(hwnd, pHps);
|
|---|
| 180 | }
|
|---|
| 181 |
|
|---|
| 182 | if(pHps)
|
|---|
| 183 | {
|
|---|
| 184 | wHeight += pHps->HPStoHDCInversionHeight;
|
|---|
| 185 | }
|
|---|
| 186 |
|
|---|
| 187 | if(hwnd || (pHps && pHps->hwnd)) {
|
|---|
| 188 | for(int x=0; x < count; x++)
|
|---|
| 189 | {
|
|---|
| 190 | if(pRectl[x].xRight > wWidth) {
|
|---|
| 191 | pRectl[x].xRight = wWidth;
|
|---|
| 192 | }
|
|---|
| 193 | if(pRectl[x].yTop > wHeight) {
|
|---|
| 194 | pRectl[x].yTop = 0;
|
|---|
| 195 | }
|
|---|
| 196 | else pRectl[x].yTop = wHeight - pRectl[x].yTop;
|
|---|
| 197 |
|
|---|
| 198 | pRectl[x].yBottom = wHeight - pRectl[x].yBottom;
|
|---|
| 199 | }
|
|---|
| 200 | }
|
|---|
| 201 | else {
|
|---|
| 202 | for(int x=0; x < count; x++)
|
|---|
| 203 | {
|
|---|
| 204 | pRectl[x].yTop = wHeight - pRectl[x].yTop;
|
|---|
| 205 | pRectl[x].yBottom = wHeight - pRectl[x].yBottom;
|
|---|
| 206 | }
|
|---|
| 207 | }
|
|---|
| 208 | }
|
|---|
| 209 | //******************************************************************************
|
|---|
| 210 | //******************************************************************************
|
|---|
| 211 | static void convertPMDeviceRectToWinWorldRect(pDCData pHps_Hdc, PRECTL pRectl)
|
|---|
| 212 | {
|
|---|
| 213 | GpiConvert(pHps_Hdc->hps, CVTC_DEVICE, CVTC_WORLD, 2, (PPOINTL)pRectl );
|
|---|
| 214 | }
|
|---|
| 215 | //******************************************************************************
|
|---|
| 216 | //******************************************************************************
|
|---|
| 217 | BOOL interpretRegionAs(pDCData pHps, HRGN hrgnDest, HRGN hrgnSrc, InterpMode mode)
|
|---|
| 218 | {
|
|---|
| 219 | BOOL success = FALSE;
|
|---|
| 220 | int x, i;
|
|---|
| 221 | HPS hpsDest;
|
|---|
| 222 |
|
|---|
| 223 | if(pHps)
|
|---|
| 224 | {
|
|---|
| 225 | if(!hrgnDest) {
|
|---|
| 226 | hrgnDest = pHps->hrgnHDC;
|
|---|
| 227 | #ifdef DEBUG
|
|---|
| 228 | if(hrgnDest == 0) {
|
|---|
| 229 | DebugInt3();
|
|---|
| 230 | }
|
|---|
| 231 | #endif
|
|---|
| 232 | }
|
|---|
| 233 | hpsDest = pHps->hps;
|
|---|
| 234 | }
|
|---|
| 235 | else {
|
|---|
| 236 | DebugInt3();
|
|---|
| 237 | return FALSE;
|
|---|
| 238 | }
|
|---|
| 239 |
|
|---|
| 240 | RGNRECT rgnRect;
|
|---|
| 241 | rgnRect.ircStart = 1;
|
|---|
| 242 | rgnRect.crc = 0;
|
|---|
| 243 | rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT;
|
|---|
| 244 | success = GpiQueryRegionRects(hpsRegion, hrgnSrc, NULL, &rgnRect, NULL);
|
|---|
| 245 | if(success)
|
|---|
| 246 | {
|
|---|
| 247 | if(rgnRect.crcReturned > 0)
|
|---|
| 248 | {
|
|---|
| 249 | rgnRect.crc = rgnRect.crcReturned;
|
|---|
| 250 | PRECTL pRectl = new RECTL[rgnRect.crcReturned];
|
|---|
| 251 | success = GpiQueryRegionRects(hpsRegion, hrgnSrc, NULL, &rgnRect, pRectl);
|
|---|
| 252 | if(success)
|
|---|
| 253 | {
|
|---|
| 254 | if(mode == AS_DEVICE)
|
|---|
| 255 | {
|
|---|
| 256 | ULONG temp;
|
|---|
| 257 | for(x=0; x < rgnRect.crcReturned; x++)
|
|---|
| 258 | {
|
|---|
| 259 | temp = pRectl[x].yBottom;
|
|---|
| 260 | pRectl[x].yBottom = pRectl[x].yTop;
|
|---|
| 261 | pRectl[x].yTop = temp;
|
|---|
| 262 | }
|
|---|
| 263 | convertWinDeviceRectToPMDeviceRect(pHps, pRectl, rgnRect.crcReturned);
|
|---|
| 264 | }
|
|---|
| 265 | else
|
|---|
| 266 | {
|
|---|
| 267 | GpiConvert(pHps->hps, CVTC_WORLD, CVTC_DEVICE, rgnRect.crcReturned<<1, (PPOINTL)pRectl);
|
|---|
| 268 |
|
|---|
| 269 | ULONG temp;
|
|---|
| 270 | for(i=0; i < rgnRect.crcReturned; i++)
|
|---|
| 271 | {
|
|---|
| 272 | if(pRectl[i].yTop < pRectl[i].yBottom)
|
|---|
| 273 | {
|
|---|
| 274 | temp = pRectl[i].yBottom + 1;
|
|---|
| 275 | pRectl[i].yBottom = pRectl[i].yTop + 1;
|
|---|
| 276 | pRectl[i].yTop = temp;
|
|---|
| 277 | }
|
|---|
| 278 | else
|
|---|
| 279 | {
|
|---|
| 280 | pRectl[i].yTop++;
|
|---|
| 281 | pRectl[i].yBottom++;
|
|---|
| 282 | }
|
|---|
| 283 | }
|
|---|
| 284 | }
|
|---|
| 285 | success = GpiSetRegion(hpsDest, hrgnDest, rgnRect.crcReturned, pRectl);
|
|---|
| 286 | }
|
|---|
| 287 | delete[] pRectl;
|
|---|
| 288 | }
|
|---|
| 289 | else
|
|---|
| 290 | {
|
|---|
| 291 | success = GpiSetRegion(hpsDest, hrgnDest, 0, NULL);
|
|---|
| 292 | }
|
|---|
| 293 | }
|
|---|
| 294 | return success;
|
|---|
| 295 | }
|
|---|
| 296 | //******************************************************************************
|
|---|
| 297 | //exported (used by user32)
|
|---|
| 298 | //******************************************************************************
|
|---|
| 299 | BOOL WIN32API setWinDeviceRegionFromPMDeviceRegion(HRGN winHrgn, HRGN pmHrgn, pDCData pHpsPmHrgn, HWND hwndPmHrgn)
|
|---|
| 300 | {
|
|---|
| 301 | BOOL success;
|
|---|
| 302 | int x;
|
|---|
| 303 | BOOL mustReleaseScreenPS = FALSE;
|
|---|
| 304 | HPS hps;
|
|---|
| 305 |
|
|---|
| 306 | if(pHpsPmHrgn || hwndPmHrgn)
|
|---|
| 307 | {
|
|---|
| 308 | if(pHpsPmHrgn)
|
|---|
| 309 | hps = pHpsPmHrgn->hps;
|
|---|
| 310 | else
|
|---|
| 311 | {
|
|---|
| 312 | hps = WinGetScreenPS(HWND_DESKTOP);
|
|---|
| 313 | mustReleaseScreenPS = TRUE;
|
|---|
| 314 | }
|
|---|
| 315 |
|
|---|
| 316 | RGNRECT rgnRect;
|
|---|
| 317 | rgnRect.ircStart = 1;
|
|---|
| 318 | rgnRect.crc = 0;
|
|---|
| 319 | rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT;
|
|---|
| 320 | success = GpiQueryRegionRects(hps, pmHrgn, NULL, &rgnRect, NULL);
|
|---|
| 321 | if(success )
|
|---|
| 322 | {
|
|---|
| 323 | if(rgnRect.crcReturned > 0)
|
|---|
| 324 | {
|
|---|
| 325 | rgnRect.crc = rgnRect.crcReturned;
|
|---|
| 326 | PRECTL pRectl = new RECTL[rgnRect.crcReturned];
|
|---|
| 327 | success = GpiQueryRegionRects(hps, pmHrgn, NULL, &rgnRect, pRectl);
|
|---|
| 328 | if(success)
|
|---|
| 329 | {
|
|---|
| 330 | if(pHpsPmHrgn)
|
|---|
| 331 | convertPMDeviceRectToWinDeviceRect(pHpsPmHrgn, pRectl, rgnRect.crcReturned);
|
|---|
| 332 | else
|
|---|
| 333 | convertPMDeviceRectToWinDeviceRect(hwndPmHrgn, pRectl, rgnRect.crcReturned);
|
|---|
| 334 |
|
|---|
| 335 | for(x=0; x < rgnRect.crcReturned; x++)
|
|---|
| 336 | {
|
|---|
| 337 | ULONG temp = pRectl[x].yBottom;
|
|---|
| 338 | pRectl[x].yBottom = pRectl[x].yTop;
|
|---|
| 339 | pRectl[x].yTop = temp;
|
|---|
| 340 | }
|
|---|
| 341 |
|
|---|
| 342 | success = GpiSetRegion(hpsRegion, winHrgn, rgnRect.crcReturned, pRectl);
|
|---|
| 343 | }
|
|---|
| 344 | delete[] pRectl;
|
|---|
| 345 | }
|
|---|
| 346 | else
|
|---|
| 347 | {
|
|---|
| 348 | success = GpiSetRegion(hpsRegion, winHrgn, 0, NULL);
|
|---|
| 349 | }
|
|---|
| 350 | }
|
|---|
| 351 | }
|
|---|
| 352 | else
|
|---|
| 353 | success = FALSE;
|
|---|
| 354 |
|
|---|
| 355 | if(mustReleaseScreenPS)
|
|---|
| 356 | WinReleasePS(hps);
|
|---|
| 357 |
|
|---|
| 358 | return success;
|
|---|
| 359 | }
|
|---|
| 360 | //******************************************************************************
|
|---|
| 361 | //******************************************************************************
|
|---|
| 362 | ODINFUNCTIONNODBG2(int, SelectClipRgn, HDC, hdc, HRGN, hrgn)
|
|---|
| 363 | {
|
|---|
| 364 | LONG lComplexity = RGN_NULL;
|
|---|
| 365 | HRGN hrgnNewClip;
|
|---|
| 366 | HRGN hrgnOldClip;
|
|---|
| 367 |
|
|---|
| 368 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
|
|---|
| 369 | if(!pHps)
|
|---|
| 370 | {
|
|---|
| 371 | dprintf(("WARNING: SelectClipRgn: invalid hdc!", hdc, hrgn));
|
|---|
| 372 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 373 | return ERROR_W;
|
|---|
| 374 | }
|
|---|
| 375 |
|
|---|
| 376 | if(hrgn)
|
|---|
| 377 | {
|
|---|
| 378 | hrgn = ObjGetHandleData(hrgn);
|
|---|
| 379 | if(hrgn == HANDLE_OBJ_ERROR) {
|
|---|
| 380 | dprintf(("WARNING: SelectClipRgn: invalid region!", hdc, hrgn));
|
|---|
| 381 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 382 | return ERROR_W;
|
|---|
| 383 | }
|
|---|
| 384 | }
|
|---|
| 385 |
|
|---|
| 386 | if(hrgn)
|
|---|
| 387 | {
|
|---|
| 388 | RECTL rectl = {0,0,1,1};
|
|---|
| 389 | hrgnNewClip = GpiCreateRegion(pHps->hps, 1, &rectl);
|
|---|
| 390 | if(interpretRegionAs(pHps, hrgnNewClip, hrgn, AS_DEVICE) == 0)
|
|---|
| 391 | {
|
|---|
| 392 | lComplexity = RGN_ERROR;
|
|---|
| 393 | }
|
|---|
| 394 | }
|
|---|
| 395 | else
|
|---|
| 396 | hrgnNewClip = 0;
|
|---|
| 397 |
|
|---|
| 398 | if(lComplexity != RGN_ERROR)
|
|---|
| 399 | {
|
|---|
| 400 | if(hrgnNewClip == 0) {
|
|---|
| 401 | GpiSetClipPath(pHps->hps, 0, SCP_RESET);
|
|---|
| 402 | }
|
|---|
| 403 | lComplexity = GpiSetClipRegion(pHps->hps, hrgnNewClip, &hrgnOldClip);
|
|---|
| 404 | if (lComplexity != RGN_ERROR )
|
|---|
| 405 | {
|
|---|
| 406 | dprintf(("SelectClipRgn: %x %x", hdc, hrgn));
|
|---|
| 407 | if(hrgnOldClip)
|
|---|
| 408 | GpiDestroyRegion(pHps->hps, hrgnOldClip);
|
|---|
| 409 |
|
|---|
| 410 | //todo: metafile recording
|
|---|
| 411 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 412 | return lComplexity;
|
|---|
| 413 | }
|
|---|
| 414 | }
|
|---|
| 415 |
|
|---|
| 416 | dprintf(("WARNING: SelectClipRgn: RGN_ERROR!", hdc, hrgn));
|
|---|
| 417 | if(hrgnNewClip)
|
|---|
| 418 | GpiDestroyRegion(pHps->hps, hrgnNewClip);
|
|---|
| 419 |
|
|---|
| 420 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 421 | return lComplexity;
|
|---|
| 422 | }
|
|---|
| 423 | //******************************************************************************
|
|---|
| 424 | //******************************************************************************
|
|---|
| 425 | ODINFUNCTIONNODBG3(int, ExtSelectClipRgn, HDC, hdc, HRGN, hrgn, int, mode)
|
|---|
| 426 | {
|
|---|
| 427 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
|
|---|
| 428 | if (!pHps)
|
|---|
| 429 | {
|
|---|
| 430 | dprintf(("WARNING: ExtSelectRgn %x %x %d invalid hdc", hdc, hrgn, mode));
|
|---|
| 431 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 432 | return ERROR_W;
|
|---|
| 433 | }
|
|---|
| 434 |
|
|---|
| 435 | LONG lComplexity;
|
|---|
| 436 | HRGN hrgnCurrent = NULLHANDLE;
|
|---|
| 437 |
|
|---|
| 438 | if(!hrgn && mode != RGN_COPY_W)
|
|---|
| 439 | {
|
|---|
| 440 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
|---|
| 441 | dprintf(("WARNING: ExtSelectRgn %x %x %d invalid parameter", hdc, hrgn, mode));
|
|---|
| 442 | return ERROR_W;
|
|---|
| 443 | }
|
|---|
| 444 |
|
|---|
| 445 | LONG lMode;
|
|---|
| 446 | switch (mode)
|
|---|
| 447 | {
|
|---|
| 448 | case RGN_AND_W : lMode = CRGN_AND ; break;
|
|---|
| 449 | case RGN_COPY_W : lMode = CRGN_COPY; break;
|
|---|
| 450 | case RGN_DIFF_W : lMode = CRGN_DIFF; break;
|
|---|
| 451 | case RGN_OR_W : lMode = CRGN_OR ; break;
|
|---|
| 452 | case RGN_XOR_W : lMode = CRGN_XOR ; break;
|
|---|
| 453 | default:
|
|---|
| 454 | {
|
|---|
| 455 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
|---|
| 456 | dprintf(("WARNING: ExtSelectRgn %x %x %d invalid parameter", hdc, hrgn, mode));
|
|---|
| 457 | return ERROR_W;
|
|---|
| 458 | }
|
|---|
| 459 | }
|
|---|
| 460 |
|
|---|
| 461 | if(hrgn)
|
|---|
| 462 | {
|
|---|
| 463 | hrgn = ObjGetHandleData(hrgn);
|
|---|
| 464 | if(hrgn == HANDLE_OBJ_ERROR) {
|
|---|
| 465 | dprintf(("WARNING: ExtSelectRgn %x %x %d invalid region handle", hdc, hrgn, mode));
|
|---|
| 466 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 467 | return 0;
|
|---|
| 468 | }
|
|---|
| 469 | }
|
|---|
| 470 |
|
|---|
| 471 | dprintf(("WARNING: ExtSelectRgn %x %x %d", hdc, hrgn, mode));
|
|---|
| 472 | //TODO: metafile recording
|
|---|
| 473 | if(hrgn)
|
|---|
| 474 | {
|
|---|
| 475 | if(!interpretRegionAs(pHps, 0, hrgn, AS_DEVICE) )
|
|---|
| 476 | {
|
|---|
| 477 | return ERROR_W;
|
|---|
| 478 | }
|
|---|
| 479 | }
|
|---|
| 480 | else
|
|---|
| 481 | {
|
|---|
| 482 | //remove clip region
|
|---|
| 483 | GpiSetClipPath(pHps->hps, 0, SCP_RESET);
|
|---|
| 484 | GpiSetClipRegion(pHps->hps, NULLHANDLE, &hrgnCurrent);
|
|---|
| 485 |
|
|---|
| 486 | if(hrgnCurrent)
|
|---|
| 487 | GpiDestroyRegion(pHps->hps, hrgnCurrent);
|
|---|
| 488 |
|
|---|
| 489 | return NULLREGION_W;
|
|---|
| 490 | }
|
|---|
| 491 |
|
|---|
| 492 | GpiSetClipRegion(pHps->hps, NULLHANDLE, &hrgnCurrent);
|
|---|
| 493 |
|
|---|
| 494 | if(hrgnCurrent == NULLHANDLE)
|
|---|
| 495 | {
|
|---|
| 496 | lMode = CRGN_COPY;
|
|---|
| 497 | RECTL rectl = {0, 0, 1, 1};
|
|---|
| 498 | hrgnCurrent = GpiCreateRegion(pHps->hps, 1, &rectl);
|
|---|
| 499 | }
|
|---|
| 500 |
|
|---|
| 501 | HRGN hrgnSrc1;
|
|---|
| 502 | HRGN hrgnSrc2;
|
|---|
| 503 | if(lMode != CRGN_COPY)
|
|---|
| 504 | {
|
|---|
| 505 | hrgnSrc1 = hrgnCurrent;
|
|---|
| 506 | hrgnSrc2 = pHps->hrgnHDC;
|
|---|
| 507 | }
|
|---|
| 508 | else
|
|---|
| 509 | {
|
|---|
| 510 | hrgnSrc1 = pHps->hrgnHDC;
|
|---|
| 511 | hrgnSrc2 = NULLHANDLE;
|
|---|
| 512 | }
|
|---|
| 513 |
|
|---|
| 514 | lComplexity = GpiCombineRegion(pHps->hps, hrgnCurrent, hrgnSrc1, hrgnSrc2, lMode);
|
|---|
| 515 | if (lComplexity != RGN_ERROR)
|
|---|
| 516 | {
|
|---|
| 517 | HRGN hrgnOld;
|
|---|
| 518 | lComplexity = GpiSetClipRegion(pHps->hps, hrgnCurrent, &hrgnOld);
|
|---|
| 519 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 520 | if (lComplexity != RGN_ERROR)
|
|---|
| 521 | return lComplexity;
|
|---|
| 522 | }
|
|---|
| 523 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 524 | return ERROR_W;
|
|---|
| 525 | }
|
|---|
| 526 | //******************************************************************************
|
|---|
| 527 | //******************************************************************************
|
|---|
| 528 | ODINFUNCTIONNODBG2(int, GetClipBox, HDC, hdc, PRECT, lpRect)
|
|---|
| 529 | {
|
|---|
| 530 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
|
|---|
| 531 | RECTL rectl;
|
|---|
| 532 | LONG lComplexity;
|
|---|
| 533 | int rc;
|
|---|
| 534 |
|
|---|
| 535 | if(!hdc || !lpRect || !pHps) {
|
|---|
| 536 | dprintf(("GDI32: GetClipBox %x %x ERROR_INVALID_PARAMETER", hdc, lpRect));
|
|---|
| 537 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
|---|
| 538 | return ERROR_W;
|
|---|
| 539 | }
|
|---|
| 540 | if(pHps->isPrinter)
|
|---|
| 541 | {
|
|---|
| 542 | lpRect->left = 0;
|
|---|
| 543 | lpRect->top = 0;
|
|---|
| 544 | lpRect->right = GetDeviceCaps( hdc, HORZRES_W);
|
|---|
| 545 | lpRect->bottom = GetDeviceCaps( hdc, VERTRES_W);
|
|---|
| 546 | includeBottomRightPoint(pHps, (PPOINTLOS2)&rectl);
|
|---|
| 547 | convertPMDeviceRectToWinWorldRect(pHps, &rectl);
|
|---|
| 548 |
|
|---|
| 549 | rc = SIMPLEREGION_W;
|
|---|
| 550 | }
|
|---|
| 551 | else {
|
|---|
| 552 | lComplexity = GpiQueryClipBox(pHps->hps, &rectl);
|
|---|
| 553 | if(lComplexity == RGN_ERROR)
|
|---|
| 554 | {
|
|---|
| 555 | rc = ERROR_W;
|
|---|
| 556 | }
|
|---|
| 557 | else
|
|---|
| 558 | if(lComplexity == RGN_NULL)
|
|---|
| 559 | {
|
|---|
| 560 | memset(lpRect, 0, sizeof(*lpRect));
|
|---|
| 561 | rc = NULLREGION_W;
|
|---|
| 562 | }
|
|---|
| 563 | else {
|
|---|
| 564 | //Convert including/including to including/excluding
|
|---|
| 565 | includeBottomRightPoint(pHps, (PPOINTLOS2)&rectl);
|
|---|
| 566 |
|
|---|
| 567 | lpRect->left = rectl.xLeft;
|
|---|
| 568 | lpRect->right = rectl.xRight;
|
|---|
| 569 | //No conversion required as GpiQueryClipBox is affected by
|
|---|
| 570 | //the y-inversion of the window
|
|---|
| 571 | //NOTE: YINVERSION dependancy
|
|---|
| 572 | if(rectl.yBottom > rectl.yTop) {
|
|---|
| 573 | lpRect->top = rectl.yTop;
|
|---|
| 574 | lpRect->bottom = rectl.yBottom;
|
|---|
| 575 | }
|
|---|
| 576 | else {
|
|---|
| 577 | lpRect->top = rectl.yBottom;
|
|---|
| 578 | lpRect->bottom = rectl.yTop;
|
|---|
| 579 | }
|
|---|
| 580 |
|
|---|
| 581 | rc = (lComplexity == RGN_RECT) ? SIMPLEREGION_W : COMPLEXREGION_W;
|
|---|
| 582 | }
|
|---|
| 583 | }
|
|---|
| 584 | dprintf(("GDI32: GetClipBox of %X returned %d; (%d,%d)(%d,%d)", hdc, rc, lpRect->left, lpRect->top, lpRect->right, lpRect->bottom));
|
|---|
| 585 | return rc;
|
|---|
| 586 | }
|
|---|
| 587 | //******************************************************************************
|
|---|
| 588 | //******************************************************************************
|
|---|
| 589 | ODINFUNCTIONNODBG2(int, GetClipRgn, HDC, hdc, HRGN, hrgn)
|
|---|
| 590 | {
|
|---|
| 591 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
|
|---|
| 592 | BOOL success;
|
|---|
| 593 | LONG lComplexity = RGN_RECT;
|
|---|
| 594 | HRGN hrgnClip = NULL, hrgnTemp;
|
|---|
| 595 |
|
|---|
| 596 | hrgn = ObjGetHandleData(hrgn);
|
|---|
| 597 | if(hrgn == HANDLE_OBJ_ERROR || !pHps) {
|
|---|
| 598 | dprintf(("WARNING: GetClipRgn %x %x invalid handle", hdc, hrgn));
|
|---|
| 599 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 600 | return 0;
|
|---|
| 601 | }
|
|---|
| 602 |
|
|---|
| 603 | if(GpiSetClipRegion(pHps->hps, NULL, &hrgnClip) == RGN_ERROR) {
|
|---|
| 604 | dprintf(("WARNING: GetClipRgn GpiSetClipRegion failed! (%x)", WinGetLastError(0)));
|
|---|
| 605 | SetLastError(ERROR_INVALID_PARAMETER_W); //todo right errror
|
|---|
| 606 | return 0;
|
|---|
| 607 | }
|
|---|
| 608 | if(hrgnClip) {
|
|---|
| 609 | if(!setWinDeviceRegionFromPMDeviceRegion(hrgn, hrgnClip, pHps, NULL)) {
|
|---|
| 610 | dprintf(("WARNING: GetClipRgn setWinDeviceRegionFromPMDeviceRegion failed!"));
|
|---|
| 611 | GpiSetClipRegion(pHps->hps, hrgnClip, &hrgnTemp);
|
|---|
| 612 | SetLastError(ERROR_INVALID_PARAMETER_W); //todo right errror
|
|---|
| 613 | return 0;
|
|---|
| 614 | }
|
|---|
| 615 | if(GpiSetClipRegion(pHps->hps, hrgnClip, &hrgnTemp) == RGN_ERROR )
|
|---|
| 616 | {
|
|---|
| 617 | dprintf(("WARNING: GetClipRgn GpiSetClipRegion failed %x!", WinGetLastError(0)));
|
|---|
| 618 | SetLastError(ERROR_INVALID_PARAMETER_W); //todo right errror
|
|---|
| 619 | return 0;
|
|---|
| 620 | }
|
|---|
| 621 | }
|
|---|
| 622 | else lComplexity = RGN_NULL;
|
|---|
| 623 |
|
|---|
| 624 | dprintf(("GetClipRgn %x %x returned %d", hdc, hrgn, lComplexity != RGN_NULL));
|
|---|
| 625 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 626 | if(lComplexity == RGN_NULL)
|
|---|
| 627 | return 0;
|
|---|
| 628 | else return 1;
|
|---|
| 629 | }
|
|---|
| 630 | //******************************************************************************
|
|---|
| 631 | //******************************************************************************
|
|---|
| 632 | ODINFUNCTIONNODBG5(int, ExcludeClipRect, HDC, hdc, int, left, int, top, int, right, int, bottom)
|
|---|
| 633 | {
|
|---|
| 634 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
|
|---|
| 635 | if(!pHps)
|
|---|
| 636 | {
|
|---|
| 637 | dprintf(("WARNING: ExcludeClipRgn %x (%d,%d)(%d,%d) invalid hdc", hdc, left, top, right, bottom));
|
|---|
| 638 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 639 | return ERROR_W;
|
|---|
| 640 | }
|
|---|
| 641 |
|
|---|
| 642 | LONG lComplexity;
|
|---|
| 643 | RECTL rectl = { left, bottom, right, top };
|
|---|
| 644 |
|
|---|
| 645 | excludeBottomRightPoint(pHps, (PPOINTLOS2)&rectl);
|
|---|
| 646 | if(rectl.yTop < rectl.yBottom) {
|
|---|
| 647 | ULONG temp = rectl.yBottom;
|
|---|
| 648 | rectl.yBottom = rectl.yTop;
|
|---|
| 649 | rectl.yTop = temp;
|
|---|
| 650 | }
|
|---|
| 651 |
|
|---|
| 652 | dprintf(("ExcludeClipRgn %x (%d,%d)(%d,%d)", hdc, left, top, right, bottom));
|
|---|
| 653 | lComplexity = GpiExcludeClipRectangle(pHps->hps, &rectl);
|
|---|
| 654 | if (lComplexity == RGN_ERROR) {
|
|---|
| 655 | SetLastError(ERROR_INVALID_PARAMETER_W); //TODO: wrong error
|
|---|
| 656 | return ERROR_W;
|
|---|
| 657 | }
|
|---|
| 658 |
|
|---|
| 659 | //todo metafile recording
|
|---|
| 660 |
|
|---|
| 661 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 662 | return lComplexity;
|
|---|
| 663 | }
|
|---|
| 664 | //******************************************************************************
|
|---|
| 665 | //******************************************************************************
|
|---|
| 666 | ODINFUNCTIONNODBG5(int, IntersectClipRect, HDC, hdc, int, left, int, top, int, right, int, bottom)
|
|---|
| 667 | {
|
|---|
| 668 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
|
|---|
| 669 | LONG lComplexity;
|
|---|
| 670 | BOOL success;
|
|---|
| 671 |
|
|---|
| 672 | if(!pHps) {
|
|---|
| 673 | dprintf(("WARNING: IntersectClipRgn %x (%d,%d)(%d,%d) invalid hdc", hdc, left, top, right, bottom));
|
|---|
| 674 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 675 | return ERROR_W;
|
|---|
| 676 | }
|
|---|
| 677 | RECTL rectl = { left, bottom, right, top };
|
|---|
| 678 |
|
|---|
| 679 | excludeBottomRightPoint(pHps, (PPOINTLOS2)&rectl);
|
|---|
| 680 | if(rectl.yTop < rectl.yBottom) {
|
|---|
| 681 | ULONG temp = rectl.yBottom;
|
|---|
| 682 | rectl.yBottom = rectl.yTop;
|
|---|
| 683 | rectl.yTop = temp;
|
|---|
| 684 | }
|
|---|
| 685 |
|
|---|
| 686 | dprintf(("IntersectClipRgn %x (%d,%d)(%d,%d)", hdc, left, top, right, bottom));
|
|---|
| 687 | lComplexity = GpiIntersectClipRectangle(pHps->hps, &rectl);
|
|---|
| 688 |
|
|---|
| 689 | //todo metafile recording
|
|---|
| 690 |
|
|---|
| 691 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 692 | return lComplexity;
|
|---|
| 693 | }
|
|---|
| 694 | //******************************************************************************
|
|---|
| 695 | //******************************************************************************
|
|---|
| 696 | ODINFUNCTIONNODBG3(int, OffsetClipRgn, HDC, hdc, int, nXOffset, int, nYOffset )
|
|---|
| 697 | {
|
|---|
| 698 | BOOL success;
|
|---|
| 699 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
|
|---|
| 700 | LONG lComplexity;
|
|---|
| 701 |
|
|---|
| 702 | if(!pHps) {
|
|---|
| 703 | dprintf(("OffsetClipRgn %x (%d,%d) invalid hdc", hdc, nXOffset, nYOffset));
|
|---|
| 704 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 705 | return ERROR_W;
|
|---|
| 706 | }
|
|---|
| 707 |
|
|---|
| 708 | dprintf(("OffsetClipRgn %x (%d,%d)", hdc, nXOffset, nYOffset));
|
|---|
| 709 | POINTL pointl = { nXOffset, nYOffset };
|
|---|
| 710 | lComplexity = GpiOffsetClipRegion(pHps->hps, &pointl);
|
|---|
| 711 |
|
|---|
| 712 | //todo metafile recording
|
|---|
| 713 |
|
|---|
| 714 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 715 | return lComplexity;
|
|---|
| 716 | }
|
|---|
| 717 | //******************************************************************************
|
|---|
| 718 | //******************************************************************************
|
|---|
| 719 | ODINFUNCTIONNODBG4(HRGN, CreatePolyPolygonRgn, const POINT * , lppt, const int *, pPolyCount, int, nCount, int, fnPolyFillMode)
|
|---|
| 720 | {
|
|---|
| 721 | LONG flMode;
|
|---|
| 722 |
|
|---|
| 723 | switch(fnPolyFillMode)
|
|---|
| 724 | {
|
|---|
| 725 | case ALTERNATE_W:
|
|---|
| 726 | flMode = POLYGON_ALTERNATE;
|
|---|
| 727 | break;
|
|---|
| 728 | case WINDING_W:
|
|---|
| 729 | flMode = POLYGON_WINDING;
|
|---|
| 730 | break;
|
|---|
| 731 | default:
|
|---|
| 732 | dprintf(("WARNING: CreatePolyPolygonRgn %x %x %d %d invalid parameter", lppt, pPolyCount, nCount, fnPolyFillMode));
|
|---|
| 733 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
|---|
| 734 | return 0;
|
|---|
| 735 | }
|
|---|
| 736 |
|
|---|
| 737 | if(nCount < 1)
|
|---|
| 738 | {
|
|---|
| 739 | dprintf(("WARNING: CreatePolyPolygonRgn %x %x %d %d invalid parameter", lppt, pPolyCount, nCount, fnPolyFillMode));
|
|---|
| 740 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
|---|
| 741 | return 0;
|
|---|
| 742 | }
|
|---|
| 743 |
|
|---|
| 744 | PPOLYGON pPolygon = new POLYGON[nCount];
|
|---|
| 745 | if(!pPolygon) {
|
|---|
| 746 | dprintf(("ERROR: CreatePolyPolygonRgn: out of memory!!"));
|
|---|
| 747 | SetLastError(ERROR_OUTOFMEMORY_W);
|
|---|
| 748 | return 0;
|
|---|
| 749 | }
|
|---|
| 750 | dprintf(("CreatePolyPolygonRgn %x %x %d %d", lppt, pPolyCount, nCount, fnPolyFillMode));
|
|---|
| 751 |
|
|---|
| 752 | PPOINTL pPointl = (PPOINTL)lppt+1; // skip first point
|
|---|
| 753 | for (int x=0; x < nCount; x++) {
|
|---|
| 754 | pPolygon[x].ulPoints = (x == 0) ? pPolyCount[x] - 1 : pPolyCount[x];
|
|---|
| 755 | pPolygon[x].aPointl = pPointl;
|
|---|
| 756 | pPointl += pPolygon[x].ulPoints;
|
|---|
| 757 | }
|
|---|
| 758 | GpiMove(hpsRegion, (PPOINTL)lppt);
|
|---|
| 759 | HRGN hrgn = GpiCreatePolygonRegion(hpsRegion, nCount, pPolygon, POLYGON_BOUNDARY | flMode);
|
|---|
| 760 |
|
|---|
| 761 | delete[] pPolygon;
|
|---|
| 762 |
|
|---|
| 763 | if(!hrgn) {
|
|---|
| 764 | SetLastError(ERROR_INVALID_PARAMETER_W); //todo: not right
|
|---|
| 765 | return 0;
|
|---|
| 766 | }
|
|---|
| 767 |
|
|---|
| 768 | if(ObjAllocateHandle(&hrgn, hrgn, GDIOBJ_REGION) == FALSE) {
|
|---|
| 769 | SetLastError(ERROR_OUTOFMEMORY_W);
|
|---|
| 770 | return 0;
|
|---|
| 771 | }
|
|---|
| 772 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 773 | return hrgn;
|
|---|
| 774 | }
|
|---|
| 775 | //******************************************************************************
|
|---|
| 776 | //******************************************************************************
|
|---|
| 777 | ODINFUNCTIONNODBG4(HRGN, CreateRectRgn, int, left, int, top, int, right, int, bottom)
|
|---|
| 778 | {
|
|---|
| 779 | HRGN hrgn;
|
|---|
| 780 | RECTL rectl = { left, top < bottom ? top : bottom, right, top < bottom ? bottom : top };
|
|---|
| 781 |
|
|---|
| 782 | hrgn = GpiCreateRegion(hpsRegion, 1, &rectl);
|
|---|
| 783 | if(!hrgn) {
|
|---|
| 784 | dprintf(("WARNING: CreateRectRgn: GpiCreateRectRegion failed! %x", WinGetLastError(0)));
|
|---|
| 785 | SetLastError(ERROR_INVALID_PARAMETER_W); //todo: not right
|
|---|
| 786 | return 0;
|
|---|
| 787 | }
|
|---|
| 788 |
|
|---|
| 789 | if(ObjAllocateHandle(&hrgn, hrgn, GDIOBJ_REGION) == FALSE) {
|
|---|
| 790 | SetLastError(ERROR_OUTOFMEMORY_W);
|
|---|
| 791 | return 0;
|
|---|
| 792 | }
|
|---|
| 793 | dprintf(("CreateRectRegion (%d,%d)(%d,%d) returned %x", left, top, right, bottom, hrgn));
|
|---|
| 794 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 795 | return hrgn;
|
|---|
| 796 | }
|
|---|
| 797 | //******************************************************************************
|
|---|
| 798 | //******************************************************************************
|
|---|
| 799 | ODINFUNCTIONNODBG1(HRGN, CreateRectRgnIndirect, const RECT *, lprc)
|
|---|
| 800 | {
|
|---|
| 801 | return CreateRectRgn(lprc->left, lprc->top, lprc->right, lprc->bottom);
|
|---|
| 802 | }
|
|---|
| 803 | //******************************************************************************
|
|---|
| 804 | //******************************************************************************
|
|---|
| 805 | ODINFUNCTIONNODBG6(HRGN, CreateRoundRectRgn, int, left, int, top, int, right, int, bottom, int, nWidthEllipse, int, nHeightEllipse)
|
|---|
| 806 | {
|
|---|
| 807 | HRGN hrgn;
|
|---|
| 808 | RECTL rectl = { left, top < bottom ? top : bottom, right, top < bottom ? bottom : top };
|
|---|
| 809 |
|
|---|
| 810 | PPOINTL pPointl = (PPOINTL)&rectl;
|
|---|
| 811 |
|
|---|
| 812 | GpiMove(hpsRegion, &pPointl[0]);
|
|---|
| 813 | hrgn = GpiCreateRoundRectRegion(hpsRegion, &pPointl[1], labs(nWidthEllipse), labs(nHeightEllipse));
|
|---|
| 814 |
|
|---|
| 815 | if(!hrgn) {
|
|---|
| 816 | SetLastError(ERROR_INVALID_PARAMETER_W); //todo: not right
|
|---|
| 817 | dprintf(("WARNING: CreateRoundRectRgn: GpiCreateRoundRectRegion failed! %x", WinGetLastError(0)));
|
|---|
| 818 | return 0;
|
|---|
| 819 | }
|
|---|
| 820 |
|
|---|
| 821 | if(ObjAllocateHandle(&hrgn, hrgn, GDIOBJ_REGION) == FALSE) {
|
|---|
| 822 | SetLastError(ERROR_OUTOFMEMORY_W);
|
|---|
| 823 | return 0;
|
|---|
| 824 | }
|
|---|
| 825 | dprintf(("CreateRoundRectRegion (%d,%d)(%d,%d) (%d,%d) returned %x", left, top, right, bottom, nWidthEllipse, nHeightEllipse, hrgn));
|
|---|
| 826 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 827 | return hrgn;
|
|---|
| 828 | }
|
|---|
| 829 | //******************************************************************************
|
|---|
| 830 | //******************************************************************************
|
|---|
| 831 | ODINFUNCTIONNODBG3(HRGN, ExtCreateRegion, const XFORM_W *, pXform, DWORD, count, const RGNDATA *, pData)
|
|---|
| 832 | {
|
|---|
| 833 | HRGN hrgn;
|
|---|
| 834 |
|
|---|
| 835 | if(!pData || count < (sizeof(RGNDATAHEADER) + pData->rdh.nCount * sizeof(RECT))) {
|
|---|
| 836 | dprintf(("WARNING: ExtCreateRegion %x %d %x; invalid parameter", pXform, count, pData));
|
|---|
| 837 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
|---|
| 838 | return 0;
|
|---|
| 839 | }
|
|---|
| 840 |
|
|---|
| 841 | PRECTL pRectl = new RECTL[pData->rdh.nCount];
|
|---|
| 842 | PRECT pDataRects = (PRECT)pData->Buffer;
|
|---|
| 843 | for(int i=0; i < pData->rdh.nCount; i++) {
|
|---|
| 844 | MapWin32ToOS2Rect(pDataRects[i], pRectl[i]);
|
|---|
| 845 | }
|
|---|
| 846 |
|
|---|
| 847 | BOOL doShear = pXform && (pXform->eM12 || pXform->eM21);
|
|---|
| 848 | HPS hpsTemp = NULLHANDLE;
|
|---|
| 849 |
|
|---|
| 850 | dprintf(("ExtCreateRegion %x %d %x", pXform, count, pData));
|
|---|
| 851 | if(doShear) {
|
|---|
| 852 | hpsTemp = WinGetPS(HWND_DESKTOP);
|
|---|
| 853 | GpiBeginPath(hpsTemp, 1);
|
|---|
| 854 |
|
|---|
| 855 | MATRIXLF matrixlf;
|
|---|
| 856 | matrixlf.fxM11 = pXform->eM11 * (float)0x10000;
|
|---|
| 857 | matrixlf.fxM12 = pXform->eM12 * (float)0x10000;
|
|---|
| 858 | matrixlf.lM13 = 0;
|
|---|
| 859 | matrixlf.fxM21 = pXform->eM21 * (float)0x10000;
|
|---|
| 860 | matrixlf.fxM22 = pXform->eM22 * (float)0x10000;
|
|---|
| 861 | matrixlf.lM23 = 0;
|
|---|
| 862 | matrixlf.lM31 = pXform->eDx;
|
|---|
| 863 | matrixlf.lM32 = pXform->eDy;
|
|---|
| 864 | matrixlf.lM33 = 1;
|
|---|
| 865 |
|
|---|
| 866 | GpiSetModelTransformMatrix(hpsTemp, 9, &matrixlf, TRANSFORM_REPLACE);
|
|---|
| 867 | }
|
|---|
| 868 |
|
|---|
| 869 | for(i=0; i < pData->rdh.nCount; i++)
|
|---|
| 870 | {
|
|---|
| 871 | LONG temp = pRectl[i].yTop;
|
|---|
| 872 | pRectl[i].yTop = pRectl[i].yBottom;
|
|---|
| 873 | pRectl[i].yBottom = temp;
|
|---|
| 874 |
|
|---|
| 875 | if(pXform)
|
|---|
| 876 | {
|
|---|
| 877 | PPOINTL pPointl = ((PPOINTL)&pRectl[i]);
|
|---|
| 878 |
|
|---|
| 879 | if (doShear) {
|
|---|
| 880 | GpiMove(hpsTemp, pPointl);
|
|---|
| 881 | GpiBox(hpsTemp, DRO_OUTLINE, pPointl+1, 0, 0);
|
|---|
| 882 | }
|
|---|
| 883 | else
|
|---|
| 884 | {
|
|---|
| 885 | for(int j=0; j < 2; j++) {
|
|---|
| 886 | pPointl[j].x = (pXform->eM11 * (float)pPointl[j].x) + (pXform->eM12 * (float)pPointl[j].y) + pXform->eDx;
|
|---|
| 887 | pPointl[j].y = (pXform->eM21 * (float)pPointl[j].x) + (pXform->eM22 * (float)pPointl[j].y) + pXform->eDy;
|
|---|
| 888 | }
|
|---|
| 889 |
|
|---|
| 890 | PRECTL pRectlT = (PRECTL)pPointl;
|
|---|
| 891 | if (pRectlT->xLeft > pRectlT->xRight) {
|
|---|
| 892 | LONG temp = pRectlT->xLeft;
|
|---|
| 893 | pRectlT->xLeft = pRectlT->xRight;
|
|---|
| 894 | pRectlT->xRight = temp;
|
|---|
| 895 | }
|
|---|
| 896 | if (pRectlT->yBottom > pRectlT->yTop) {
|
|---|
| 897 | LONG temp = pRectlT->yBottom;
|
|---|
| 898 | pRectlT->yBottom = pRectlT->yTop;
|
|---|
| 899 | pRectlT->yTop = temp;
|
|---|
| 900 | }
|
|---|
| 901 | }
|
|---|
| 902 | }
|
|---|
| 903 | }
|
|---|
| 904 |
|
|---|
| 905 | if(doShear) {
|
|---|
| 906 | GpiEndPath(hpsTemp);
|
|---|
| 907 | hrgn = GpiPathToRegion(hpsTemp, 1, FPATH_WINDING);
|
|---|
| 908 |
|
|---|
| 909 | if(pRectl)
|
|---|
| 910 | delete[] pRectl;
|
|---|
| 911 |
|
|---|
| 912 | if(hrgn == 0) {
|
|---|
| 913 | dprintf(("WARNING: ExtCreateRegion GpiCreateRegion failed! (%x)", WinGetLastError(0)));
|
|---|
| 914 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
|---|
| 915 | return 0;
|
|---|
| 916 | }
|
|---|
| 917 | WinReleasePS(hpsTemp);
|
|---|
| 918 | }
|
|---|
| 919 | else {
|
|---|
| 920 | hrgn = GpiCreateRegion(hpsRegion, pData->rdh.nCount, pRectl);
|
|---|
| 921 | if(pRectl)
|
|---|
| 922 | delete[] pRectl;
|
|---|
| 923 |
|
|---|
| 924 | if(hrgn == 0) {
|
|---|
| 925 | dprintf(("WARNING: ExtCreateRegion GpiCreateRegion failed! (%x)", WinGetLastError(0)));
|
|---|
| 926 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
|---|
| 927 | return 0;
|
|---|
| 928 | }
|
|---|
| 929 | }
|
|---|
| 930 |
|
|---|
| 931 | if(ObjAllocateHandle(&hrgn, hrgn, GDIOBJ_REGION) == FALSE) {
|
|---|
| 932 | SetLastError(ERROR_OUTOFMEMORY_W);
|
|---|
| 933 | return 0;
|
|---|
| 934 | }
|
|---|
| 935 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 936 | return hrgn;
|
|---|
| 937 | }
|
|---|
| 938 | //******************************************************************************
|
|---|
| 939 | //******************************************************************************
|
|---|
| 940 | ODINFUNCTIONNODBG4(HRGN, CreateEllipticRgn, int, left, int, top, int, right, int, bottom)
|
|---|
| 941 | {
|
|---|
| 942 | HRGN hrgn;
|
|---|
| 943 |
|
|---|
| 944 | RECTL rectl = { left,
|
|---|
| 945 | top < bottom ? top : bottom,
|
|---|
| 946 | right,
|
|---|
| 947 | top < bottom ? bottom : top };
|
|---|
| 948 |
|
|---|
| 949 | dprintf(("CreateEllipticRgn (%d,%d)(%d,%d)", left, top, right, bottom));
|
|---|
| 950 | hrgn = GpiCreateEllipticRegion(hpsRegion, &rectl);
|
|---|
| 951 |
|
|---|
| 952 | if(ObjAllocateHandle(&hrgn, hrgn, GDIOBJ_REGION) == FALSE) {
|
|---|
| 953 | SetLastError(ERROR_OUTOFMEMORY_W);
|
|---|
| 954 | return 0;
|
|---|
| 955 | }
|
|---|
| 956 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 957 | return hrgn;
|
|---|
| 958 | }
|
|---|
| 959 | //******************************************************************************
|
|---|
| 960 | //******************************************************************************
|
|---|
| 961 | ODINFUNCTIONNODBG1(HRGN, CreateEllipticRgnIndirect, const RECT *, pRect)
|
|---|
| 962 | {
|
|---|
| 963 | return CreateEllipticRgn(pRect->left, pRect->top, pRect->right, pRect->bottom);
|
|---|
| 964 | }
|
|---|
| 965 | //******************************************************************************
|
|---|
| 966 | //******************************************************************************
|
|---|
| 967 | ODINFUNCTIONNODBG3(HRGN, CreatePolygonRgn, const POINT *, lppt, int, cPoints, int, fnPolyFillMode)
|
|---|
| 968 | {
|
|---|
| 969 | HRGN hrgn;
|
|---|
| 970 | LONG flMode;
|
|---|
| 971 |
|
|---|
| 972 | if(!lppt || cPoints < 2) {
|
|---|
| 973 | dprintf(("WARNING: CreatePolygonRgn %x %d %d invalid parameter", lppt, cPoints, fnPolyFillMode));
|
|---|
| 974 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
|---|
| 975 | return 0;
|
|---|
| 976 | }
|
|---|
| 977 |
|
|---|
| 978 | switch (fnPolyFillMode)
|
|---|
| 979 | {
|
|---|
| 980 | case ALTERNATE_W :
|
|---|
| 981 | flMode = POLYGON_ALTERNATE;
|
|---|
| 982 | break;
|
|---|
| 983 | case WINDING_W :
|
|---|
| 984 | flMode = POLYGON_WINDING;
|
|---|
| 985 | break;
|
|---|
| 986 | default:
|
|---|
| 987 | dprintf(("WARNING: CreatePolygonRgn %x %d %d invalid parameter", lppt, cPoints, fnPolyFillMode));
|
|---|
| 988 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
|---|
| 989 | return 0;
|
|---|
| 990 | }
|
|---|
| 991 |
|
|---|
| 992 | dprintf(("CreatePolygonRgn %x %d %d", lppt, cPoints, fnPolyFillMode));
|
|---|
| 993 |
|
|---|
| 994 |
|
|---|
| 995 | POLYGON polygon;
|
|---|
| 996 | polygon.ulPoints = cPoints - 1;
|
|---|
| 997 | polygon.aPointl = (PPOINTL)(lppt + 1);
|
|---|
| 998 |
|
|---|
| 999 | GpiMove(hpsRegion, (PPOINTL)lppt);
|
|---|
| 1000 | hrgn = GpiCreatePolygonRegion(hpsRegion, 1, &polygon, POLYGON_BOUNDARY | flMode);
|
|---|
| 1001 |
|
|---|
| 1002 | if(ObjAllocateHandle(&hrgn, hrgn, GDIOBJ_REGION) == FALSE) {
|
|---|
| 1003 | SetLastError(ERROR_OUTOFMEMORY_W);
|
|---|
| 1004 | return 0;
|
|---|
| 1005 | }
|
|---|
| 1006 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 1007 | return hrgn;
|
|---|
| 1008 | }
|
|---|
| 1009 | //******************************************************************************
|
|---|
| 1010 | //******************************************************************************
|
|---|
| 1011 | ODINFUNCTIONNODBG4(int, CombineRgn, HRGN, hrgnDest, HRGN, hrgnSrc1, HRGN, hrgnSrc2, int, combineMode)
|
|---|
| 1012 | {
|
|---|
| 1013 | ULONG lComplexity;
|
|---|
| 1014 | LONG mode;
|
|---|
| 1015 |
|
|---|
| 1016 | switch(combineMode) {
|
|---|
| 1017 | case RGN_AND_W:
|
|---|
| 1018 | mode = CRGN_AND;
|
|---|
| 1019 | break;
|
|---|
| 1020 | case RGN_COPY_W:
|
|---|
| 1021 | mode = CRGN_COPY;
|
|---|
| 1022 | break;
|
|---|
| 1023 | case RGN_DIFF_W:
|
|---|
| 1024 | mode = CRGN_DIFF;
|
|---|
| 1025 | break;
|
|---|
| 1026 | case RGN_OR_W:
|
|---|
| 1027 | mode = CRGN_OR;
|
|---|
| 1028 | break;
|
|---|
| 1029 | case RGN_XOR_W:
|
|---|
| 1030 | mode = CRGN_XOR;
|
|---|
| 1031 | break;
|
|---|
| 1032 | default:
|
|---|
| 1033 | dprintf(("WARNING: CombineRgn %x %x %x %d; invalid mode!", hrgnDest, hrgnSrc1, hrgnSrc2, combineMode));
|
|---|
| 1034 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
|---|
| 1035 | return ERROR_W;
|
|---|
| 1036 | }
|
|---|
| 1037 |
|
|---|
| 1038 | hrgnDest = ObjGetHandleData(hrgnDest);
|
|---|
| 1039 | hrgnSrc1 = ObjGetHandleData(hrgnSrc1);
|
|---|
| 1040 | hrgnSrc2 = ObjGetHandleData(hrgnSrc2);
|
|---|
| 1041 | if(hrgnDest == HANDLE_OBJ_ERROR || hrgnSrc1 == HANDLE_OBJ_ERROR || (hrgnSrc2 == HANDLE_OBJ_ERROR && combineMode != RGN_COPY_W)) {
|
|---|
| 1042 | dprintf(("WARNING: CombineRgn %x %x %x %d invalid region", hrgnDest, hrgnSrc1, hrgnSrc2, combineMode));
|
|---|
| 1043 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1044 | return ERROR_W;
|
|---|
| 1045 | }
|
|---|
| 1046 |
|
|---|
| 1047 | lComplexity = GpiCombineRegion(hpsRegion, hrgnDest, hrgnSrc1, hrgnSrc2, mode);
|
|---|
| 1048 | if(lComplexity == RGN_ERROR) {
|
|---|
| 1049 | dprintf(("WARNING: CombineRgn %x %x %x %d GpiCombineRegion failed (%x)", hrgnDest, hrgnSrc1, hrgnSrc2, mode, WinGetLastError(0)));
|
|---|
| 1050 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1051 | return ERROR_W;
|
|---|
| 1052 | }
|
|---|
| 1053 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 1054 | return lComplexity;
|
|---|
| 1055 | }
|
|---|
| 1056 | //******************************************************************************
|
|---|
| 1057 | //******************************************************************************
|
|---|
| 1058 | ODINFUNCTIONNODBG2(BOOL, EqualRgn, HRGN, hrgn1, HRGN, hrgn2)
|
|---|
| 1059 | {
|
|---|
| 1060 | LONG lEquality;
|
|---|
| 1061 |
|
|---|
| 1062 | hrgn1 = ObjGetHandleData(hrgn1);
|
|---|
| 1063 | hrgn2 = ObjGetHandleData(hrgn2);
|
|---|
| 1064 | if(hrgn1 == HANDLE_OBJ_ERROR || hrgn2 == HANDLE_OBJ_ERROR) {
|
|---|
| 1065 | dprintf(("WARNING: EqualRgn %x %x invalid region", hrgn1, hrgn2));
|
|---|
| 1066 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1067 | return FALSE;
|
|---|
| 1068 | }
|
|---|
| 1069 | lEquality = GpiEqualRegion(hpsRegion, hrgn1, hrgn2);
|
|---|
| 1070 |
|
|---|
| 1071 | dprintf(("EqualRgn %x %x = %d", hrgn1, hrgn2, lEquality));
|
|---|
| 1072 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 1073 |
|
|---|
| 1074 | if(lEquality == EQRGN_EQUAL)
|
|---|
| 1075 | return TRUE;
|
|---|
| 1076 | else
|
|---|
| 1077 | if(lEquality == EQRGN_NOTEQUAL)
|
|---|
| 1078 | return FALSE;
|
|---|
| 1079 | else {
|
|---|
| 1080 | return FALSE;
|
|---|
| 1081 | }
|
|---|
| 1082 | }
|
|---|
| 1083 | //******************************************************************************
|
|---|
| 1084 | //******************************************************************************
|
|---|
| 1085 | ODINFUNCTIONNODBG5(BOOL, SetRectRgn, HRGN, hrgn, int, left, int, top, int, right, int, bottom)
|
|---|
| 1086 | {
|
|---|
| 1087 | BOOL result = FALSE;
|
|---|
| 1088 |
|
|---|
| 1089 | hrgn = ObjGetHandleData(hrgn);
|
|---|
| 1090 | if(hrgn == HANDLE_OBJ_ERROR) {
|
|---|
| 1091 | dprintf(("WARNING: SetRectRgn %x (%d,%d)(%d,%d) invalid region handle", hrgn, left, top, right, bottom));
|
|---|
| 1092 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1093 | return 0;
|
|---|
| 1094 | }
|
|---|
| 1095 | RECTL rectl = { left, top, right, bottom }; //reversed y coordinates
|
|---|
| 1096 | if(GpiSetRegion(hpsRegion, hrgn, 1, &rectl)) {
|
|---|
| 1097 | dprintf(("SetRectRgn %x (%d,%d)(%d,%d)", hrgn, left, top, right, bottom));
|
|---|
| 1098 | return TRUE;
|
|---|
| 1099 | }
|
|---|
| 1100 | dprintf(("WARNING: SetRectRgn %x (%d,%d)(%d,%d) GpiSetRegion failed %x", hrgn, left, top, right, bottom, WinGetLastError(0)));
|
|---|
| 1101 | return FALSE;
|
|---|
| 1102 | }
|
|---|
| 1103 | //******************************************************************************
|
|---|
| 1104 | //******************************************************************************
|
|---|
| 1105 | ODINFUNCTIONNODBG3(ULONG, GetRegionData, HRGN, hrgn, ULONG, count, PRGNDATA, pData)
|
|---|
| 1106 | {
|
|---|
| 1107 | if(!count && pData)
|
|---|
| 1108 | {
|
|---|
| 1109 | dprintf(("WARNING: GetRegionData %x %d %x; invalid parameter", hrgn, count, pData));
|
|---|
| 1110 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
|---|
| 1111 | return 0;
|
|---|
| 1112 | }
|
|---|
| 1113 | hrgn = ObjGetHandleData(hrgn);
|
|---|
| 1114 | if(hrgn == HANDLE_OBJ_ERROR) {
|
|---|
| 1115 | dprintf(("WARNING: GetRegionData %x %d %x; invalid region handle", hrgn, count, pData));
|
|---|
| 1116 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1117 | return 0;
|
|---|
| 1118 | }
|
|---|
| 1119 | RGNRECT rgnRect;
|
|---|
| 1120 | rgnRect.ircStart = 1;
|
|---|
| 1121 | rgnRect.crc = 0;
|
|---|
| 1122 | rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT;
|
|---|
| 1123 | if(!GpiQueryRegionRects(hpsRegion, hrgn, NULL, &rgnRect, NULL))
|
|---|
| 1124 | {
|
|---|
| 1125 | dprintf(("WARNING: GetRegionData %x %d %x: GpiQueryRegionRects failed! (%x)", hrgn, count, pData, WinGetLastError(0)));
|
|---|
| 1126 | return 0;
|
|---|
| 1127 | }
|
|---|
| 1128 |
|
|---|
| 1129 | dprintf(("GetRegionData %x %d %x", hrgn, count, pData));
|
|---|
| 1130 |
|
|---|
| 1131 | ULONG bufSizeNeeded = rgnRect.crcReturned * sizeof(RECT) + sizeof (RGNDATAHEADER);
|
|---|
| 1132 |
|
|---|
| 1133 | if(pData && (count >= (sizeof(RGNDATAHEADER) + rgnRect.crcReturned * sizeof(RECT))))
|
|---|
| 1134 | {
|
|---|
| 1135 | //we actually need to flip the top & bottom values, but as the layout of the PM RECTL and
|
|---|
| 1136 | //Win32 RECT have exactly those two members reversed, we don't do this for the returned
|
|---|
| 1137 | //rectangles (more efficient)
|
|---|
| 1138 | PRECTL pRectl = (PRECTL)pData->Buffer;
|
|---|
| 1139 | rgnRect.crc = rgnRect.crcReturned;
|
|---|
| 1140 | if(!GpiQueryRegionRects(hpsRegion, hrgn, NULL, &rgnRect, pRectl))
|
|---|
| 1141 | {
|
|---|
| 1142 | dprintf(("WARNING: GetRegionData: GpiQueryRegionRects failed! (%x)", WinGetLastError(0)));
|
|---|
| 1143 | return 0;
|
|---|
| 1144 | }
|
|---|
| 1145 |
|
|---|
| 1146 | RECTL boundRect;
|
|---|
| 1147 | GpiQueryRegionBox(hpsRegion, hrgn, &boundRect); // no need to check rc
|
|---|
| 1148 |
|
|---|
| 1149 | pData->rdh.dwSize = sizeof(pData->rdh);
|
|---|
| 1150 | pData->rdh.iType = RDH_RECTANGLES_W; // one and only possible value
|
|---|
| 1151 | pData->rdh.nCount = rgnRect.crcReturned;
|
|---|
| 1152 | pData->rdh.nRgnSize = rgnRect.crcReturned * sizeof(RECTL);
|
|---|
| 1153 |
|
|---|
| 1154 | //flip top & bottom for bounding rectangle (not really necessary; but cleaner coding)
|
|---|
| 1155 | LONG temp = boundRect.yTop;
|
|---|
| 1156 | boundRect.yTop = boundRect.yBottom;
|
|---|
| 1157 | boundRect.yBottom = temp;
|
|---|
| 1158 | MapOS2ToWin32Rect(boundRect, pData->rdh.rcBound);
|
|---|
| 1159 | }
|
|---|
| 1160 |
|
|---|
| 1161 | //return size needed
|
|---|
| 1162 | return bufSizeNeeded;
|
|---|
| 1163 | }
|
|---|
| 1164 | //******************************************************************************
|
|---|
| 1165 | //******************************************************************************
|
|---|
| 1166 | ODINFUNCTIONNODBG2(int, GetRgnBox, HRGN, hrgn, PRECT, pRect)
|
|---|
| 1167 | {
|
|---|
| 1168 | BOOL success;
|
|---|
| 1169 | LONG lComplexity;
|
|---|
| 1170 |
|
|---|
| 1171 | hrgn = ObjGetHandleData(hrgn);
|
|---|
| 1172 | if(hrgn == HANDLE_OBJ_ERROR) {
|
|---|
| 1173 | dprintf(("WARNING: GetRgnBox %x %x invalid region!", hrgn, pRect));
|
|---|
| 1174 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1175 | return FALSE;
|
|---|
| 1176 | }
|
|---|
| 1177 |
|
|---|
| 1178 | dprintf(("GetRgnBox %x %x", hrgn, pRect));
|
|---|
| 1179 |
|
|---|
| 1180 | RECTL rectl;
|
|---|
| 1181 | lComplexity = GpiQueryRegionBox(hpsRegion, hrgn, &rectl);
|
|---|
| 1182 | if(lComplexity != RGN_ERROR)
|
|---|
| 1183 | {
|
|---|
| 1184 | //no conversion required, just flip top & bottom
|
|---|
| 1185 | ULONG temp = rectl.yBottom;
|
|---|
| 1186 | rectl.yBottom = rectl.yTop;
|
|---|
| 1187 | rectl.yTop = temp;
|
|---|
| 1188 |
|
|---|
| 1189 | MapOS2ToWin32Rect(rectl, *pRect);
|
|---|
| 1190 | }
|
|---|
| 1191 | else {
|
|---|
| 1192 | lComplexity = ERROR_W;
|
|---|
| 1193 | dprintf(("WARNING: GetRgnBox error in region!"));
|
|---|
| 1194 | }
|
|---|
| 1195 |
|
|---|
| 1196 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 1197 | return lComplexity;
|
|---|
| 1198 | }
|
|---|
| 1199 | //******************************************************************************
|
|---|
| 1200 | //******************************************************************************
|
|---|
| 1201 | ODINFUNCTIONNODBG2(BOOL, InvertRgn, HDC, hdc, HRGN, hrgn)
|
|---|
| 1202 | {
|
|---|
| 1203 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
|
|---|
| 1204 |
|
|---|
| 1205 | hrgn = ObjGetHandleData(hrgn);
|
|---|
| 1206 | if(!pHps || hrgn == HANDLE_OBJ_ERROR) {
|
|---|
| 1207 | dprintf(("WARNING: InvertRgn %x %x invalid handle!", hdc, hrgn));
|
|---|
| 1208 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1209 | return FALSE;
|
|---|
| 1210 | }
|
|---|
| 1211 | //todo metafile recording
|
|---|
| 1212 |
|
|---|
| 1213 | dprintf(("InvertRgn %x %x", hdc, hrgn));
|
|---|
| 1214 |
|
|---|
| 1215 | interpretRegionAs(pHps, NULL, hrgn, AS_WORLD);
|
|---|
| 1216 |
|
|---|
| 1217 | LONG lHits = GPI_ERROR;
|
|---|
| 1218 | HRGN hrgnOld;
|
|---|
| 1219 | LONG lComplexity ;
|
|---|
| 1220 | RECTL boundingRect; // this gets a rectangle in world cordinates!
|
|---|
| 1221 |
|
|---|
| 1222 | lComplexity = GpiQueryRegionBox(pHps->hps, pHps->hrgnHDC, &boundingRect);
|
|---|
| 1223 | if(lComplexity != RGN_ERROR)
|
|---|
| 1224 | {
|
|---|
| 1225 | lComplexity = GpiSetClipRegion(pHps->hps, pHps->hrgnHDC, &hrgnOld);
|
|---|
| 1226 | if(lComplexity != RGN_ERROR)
|
|---|
| 1227 | {
|
|---|
| 1228 | RECTL rectls[2];
|
|---|
| 1229 | rectls[0] = boundingRect;
|
|---|
| 1230 | rectls[1] = boundingRect;
|
|---|
| 1231 | lHits = GpiBitBlt(pHps->hps, NULL, 3, (PPOINTL)rectls,
|
|---|
| 1232 | ROP_DSTINVERT, 0);
|
|---|
| 1233 |
|
|---|
| 1234 | /* Restore the old region */
|
|---|
| 1235 | GpiSetClipRegion(pHps->hps, hrgnOld, &hrgnOld);
|
|---|
| 1236 | }
|
|---|
| 1237 | }
|
|---|
| 1238 |
|
|---|
| 1239 | if(lHits == GPI_ERROR || lComplexity == RGN_ERROR)
|
|---|
| 1240 | {
|
|---|
| 1241 | dprintf(("WARNING: InvertRgn error during Gpi operation (%x) (%d,%d)", WinGetLastError(0), lHits, lComplexity));
|
|---|
| 1242 | return FALSE;
|
|---|
| 1243 | }
|
|---|
| 1244 |
|
|---|
| 1245 | return TRUE;
|
|---|
| 1246 | }
|
|---|
| 1247 | //******************************************************************************
|
|---|
| 1248 | //******************************************************************************
|
|---|
| 1249 | ODINFUNCTIONNODBG3(int, OffsetRgn, HRGN, hrgn, int, xOffset, int, yOffset)
|
|---|
| 1250 | {
|
|---|
| 1251 | LONG lComplexity;
|
|---|
| 1252 |
|
|---|
| 1253 | hrgn = ObjGetHandleData(hrgn);
|
|---|
| 1254 | if(hrgn == HANDLE_OBJ_ERROR) {
|
|---|
| 1255 | dprintf(("WARNING: OffsetRgn %x %d %d invalid handle!", hrgn, xOffset, yOffset));
|
|---|
| 1256 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1257 | return ERROR_W;
|
|---|
| 1258 | }
|
|---|
| 1259 | dprintf(("OffsetRgn %x %d %d", hrgn, xOffset, yOffset));
|
|---|
| 1260 |
|
|---|
| 1261 | POINTL ptlOffset = {xOffset, yOffset};
|
|---|
| 1262 | GpiOffsetRegion(hpsRegion, hrgn, &ptlOffset);
|
|---|
| 1263 |
|
|---|
| 1264 | RGNRECT rgnRect;
|
|---|
| 1265 | rgnRect.ircStart = 1;
|
|---|
| 1266 | rgnRect.crc = 0;
|
|---|
| 1267 | rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT; // doesn't make a difference
|
|---|
| 1268 | if(GpiQueryRegionRects(hpsRegion, hrgn, NULL, &rgnRect, NULL))
|
|---|
| 1269 | {
|
|---|
| 1270 | switch (rgnRect.crcReturned) {
|
|---|
| 1271 | case 0:
|
|---|
| 1272 | lComplexity = NULLREGION_W;
|
|---|
| 1273 | break;
|
|---|
| 1274 | case 1:
|
|---|
| 1275 | lComplexity = SIMPLEREGION_W;
|
|---|
| 1276 | break;
|
|---|
| 1277 | default:
|
|---|
| 1278 | lComplexity = COMPLEXREGION_W;
|
|---|
| 1279 | break;
|
|---|
| 1280 | }
|
|---|
| 1281 | }
|
|---|
| 1282 | else {
|
|---|
| 1283 | lComplexity = ERROR_W;
|
|---|
| 1284 | dprintf(("WARNING: OffsetRgn error in region! (%x)", WinGetLastError(0)));
|
|---|
| 1285 | }
|
|---|
| 1286 |
|
|---|
| 1287 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 1288 |
|
|---|
| 1289 | return lComplexity;
|
|---|
| 1290 | }
|
|---|
| 1291 | //******************************************************************************
|
|---|
| 1292 | //******************************************************************************
|
|---|
| 1293 | ODINFUNCTIONNODBG5(BOOL, FrameRgn, HDC, hdc, HRGN, hrgn, HBRUSH, hBrush, int, width, int, height)
|
|---|
| 1294 | {
|
|---|
| 1295 | HBRUSH hbrushRestore = 0;
|
|---|
| 1296 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
|
|---|
| 1297 |
|
|---|
| 1298 | hrgn = ObjGetHandleData(hrgn);
|
|---|
| 1299 | if(!pHps || hrgn == HANDLE_OBJ_ERROR) {
|
|---|
| 1300 | dprintf(("WARNING: FrameRgn %x %x %x (%d,%d) invalid handle!", hdc, hrgn, hBrush, width, height));
|
|---|
| 1301 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1302 | return FALSE;
|
|---|
| 1303 | }
|
|---|
| 1304 |
|
|---|
| 1305 | width = abs(width);
|
|---|
| 1306 | height = abs(height);
|
|---|
| 1307 |
|
|---|
| 1308 | if(pHps->lastBrushHandle != (UINT)hBrush)
|
|---|
| 1309 | {
|
|---|
| 1310 | hbrushRestore = SelectObject(hdc, hBrush);
|
|---|
| 1311 | if(!hbrushRestore)
|
|---|
| 1312 | {
|
|---|
| 1313 | dprintf(("WARNING: FrameRgn %x %x %x (%d,%d) invalid brush!", hdc, hrgn, hBrush, width, height));
|
|---|
| 1314 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1315 | return FALSE;
|
|---|
| 1316 | }
|
|---|
| 1317 | }
|
|---|
| 1318 | dprintf(("FrameRgn %x %x %x (%d,%d)", hdc, hrgn, hBrush, width, height));
|
|---|
| 1319 | interpretRegionAs(pHps, NULL, hrgn, AS_WORLD);
|
|---|
| 1320 |
|
|---|
| 1321 | SIZEL thickness = { width, height };
|
|---|
| 1322 | LONG lHits = GpiFrameRegion(pHps->hps, pHps->hrgnHDC, &thickness);
|
|---|
| 1323 |
|
|---|
| 1324 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 1325 |
|
|---|
| 1326 | // Restore the brush if necessary
|
|---|
| 1327 | if(hbrushRestore)
|
|---|
| 1328 | SelectObject(hdc, hbrushRestore);
|
|---|
| 1329 |
|
|---|
| 1330 | //todo metafile recording
|
|---|
| 1331 | return (lHits != GPI_ERROR);
|
|---|
| 1332 | }
|
|---|
| 1333 | //******************************************************************************
|
|---|
| 1334 | //******************************************************************************
|
|---|
| 1335 | ODINFUNCTIONNODBG3(BOOL, FillRgn, HDC, hdc, HRGN, hrgn, HBRUSH, hBrush)
|
|---|
| 1336 | {
|
|---|
| 1337 | BOOL success;
|
|---|
| 1338 | HBRUSH hbrushRestore = 0;
|
|---|
| 1339 |
|
|---|
| 1340 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
|
|---|
| 1341 |
|
|---|
| 1342 | hrgn = ObjGetHandleData(hrgn);
|
|---|
| 1343 | if(!pHps || hrgn == HANDLE_OBJ_ERROR) {
|
|---|
| 1344 | dprintf(("WARNING: FillRgn %x %x %x invalid handle!", hdc, hrgn, hBrush));
|
|---|
| 1345 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1346 | return FALSE;
|
|---|
| 1347 | }
|
|---|
| 1348 |
|
|---|
| 1349 | if(pHps->lastBrushHandle != (UINT)hBrush)
|
|---|
| 1350 | {
|
|---|
| 1351 | hbrushRestore = SelectObject(hdc, hBrush);
|
|---|
| 1352 | if (!hbrushRestore)
|
|---|
| 1353 | {
|
|---|
| 1354 | dprintf(("WARNING: FillRgn %x %x %x invalid brush!", hdc, hrgn, hBrush));
|
|---|
| 1355 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1356 | return FALSE;
|
|---|
| 1357 | }
|
|---|
| 1358 | }
|
|---|
| 1359 | dprintf(("FillRgn %x %x %x", hdc, hrgn, hBrush));
|
|---|
| 1360 |
|
|---|
| 1361 | interpretRegionAs(pHps, NULL, hrgn, AS_WORLD);
|
|---|
| 1362 |
|
|---|
| 1363 | success = GpiPaintRegion(pHps->hps, pHps->hrgnHDC);
|
|---|
| 1364 |
|
|---|
| 1365 | //todo metafile recording
|
|---|
| 1366 |
|
|---|
| 1367 | /* Restore the brush if necessary */
|
|---|
| 1368 | if(hbrushRestore)
|
|---|
| 1369 | SelectObject(hdc, hbrushRestore);
|
|---|
| 1370 |
|
|---|
| 1371 | return(success);
|
|---|
| 1372 | }
|
|---|
| 1373 | //******************************************************************************
|
|---|
| 1374 | //******************************************************************************
|
|---|
| 1375 | ODINFUNCTIONNODBG2(BOOL, PaintRgn, HDC, hdc, HRGN, hrgn)
|
|---|
| 1376 | {
|
|---|
| 1377 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
|
|---|
| 1378 | if(!pHps)
|
|---|
| 1379 | {
|
|---|
| 1380 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1381 | return FALSE;
|
|---|
| 1382 | }
|
|---|
| 1383 |
|
|---|
| 1384 | return FillRgn(hdc, hrgn, (HBRUSH) pHps->lastBrushHandle);
|
|---|
| 1385 | }
|
|---|
| 1386 | //******************************************************************************
|
|---|
| 1387 | //******************************************************************************
|
|---|
| 1388 | ODINFUNCTIONNODBG3(BOOL, PtInRegion, HRGN, hrgn, int, x, int, y)
|
|---|
| 1389 | {
|
|---|
| 1390 | BOOL success;
|
|---|
| 1391 | LONG lInside;
|
|---|
| 1392 |
|
|---|
| 1393 | hrgn = ObjGetHandleData(hrgn);
|
|---|
| 1394 | if(hrgn == HANDLE_OBJ_ERROR) {
|
|---|
| 1395 | dprintf(("WARNING: PtInRgn %x (%d,%d) invalid region!", hrgn, x, y));
|
|---|
| 1396 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1397 | return FALSE;
|
|---|
| 1398 | }
|
|---|
| 1399 |
|
|---|
| 1400 | POINTL pointl = {x,y};
|
|---|
| 1401 | lInside = GpiPtInRegion(hpsRegion, hrgn, &pointl);
|
|---|
| 1402 | if(lInside == PRGN_ERROR) {
|
|---|
| 1403 | success = FALSE;
|
|---|
| 1404 | }
|
|---|
| 1405 | else success = TRUE;
|
|---|
| 1406 |
|
|---|
| 1407 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 1408 |
|
|---|
| 1409 | dprintf(("WARNING: PtInRgn %x (%d,%d) returned %d", hrgn, x, y, (success && lInside == PRGN_INSIDE) ? 1 : 0));
|
|---|
| 1410 |
|
|---|
| 1411 | if(success && lInside == PRGN_INSIDE)
|
|---|
| 1412 | return TRUE;
|
|---|
| 1413 | else
|
|---|
| 1414 | return FALSE;
|
|---|
| 1415 | }
|
|---|
| 1416 | //******************************************************************************
|
|---|
| 1417 | //******************************************************************************
|
|---|
| 1418 | ODINFUNCTIONNODBG2(BOOL, RectInRegion, HRGN, hrgn, const RECT *, pRect)
|
|---|
| 1419 | {
|
|---|
| 1420 | BOOL success;
|
|---|
| 1421 | LONG lInside;
|
|---|
| 1422 |
|
|---|
| 1423 | if(!pRect) {
|
|---|
| 1424 | dprintf(("WARNING: RectInRgn %x %x invalid parameter!", hrgn, pRect));
|
|---|
| 1425 | SetLastError(ERROR_INVALID_PARAMETER_W);
|
|---|
| 1426 | return FALSE;
|
|---|
| 1427 | }
|
|---|
| 1428 | hrgn = ObjGetHandleData(hrgn);
|
|---|
| 1429 | if(hrgn == HANDLE_OBJ_ERROR) {
|
|---|
| 1430 | dprintf(("WARNING: RectInRgn %x %x invalid region", hrgn, pRect));
|
|---|
| 1431 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1432 | return FALSE;
|
|---|
| 1433 | }
|
|---|
| 1434 |
|
|---|
| 1435 | RECTL rectl;
|
|---|
| 1436 | MapWin32ToOS2Rect(*pRect, rectl);
|
|---|
| 1437 | //switch bottom & top
|
|---|
| 1438 | UINT temp = rectl.yBottom;
|
|---|
| 1439 | rectl.yBottom = rectl.yTop;
|
|---|
| 1440 | rectl.yTop = temp;
|
|---|
| 1441 |
|
|---|
| 1442 | lInside = GpiRectInRegion(hpsRegion, hrgn, &rectl);
|
|---|
| 1443 | if(lInside == RRGN_ERROR) {
|
|---|
| 1444 | success = FALSE;
|
|---|
| 1445 | }
|
|---|
| 1446 | else success = TRUE;
|
|---|
| 1447 |
|
|---|
| 1448 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 1449 |
|
|---|
| 1450 | dprintf(("WARNING: RectInRgn %x %x returned %d", hrgn, pRect, (success && (lInside == RRGN_INSIDE || lInside == RRGN_PARTIAL)) ? 1 : 0));
|
|---|
| 1451 |
|
|---|
| 1452 | if(success && (lInside == RRGN_INSIDE || lInside == RRGN_PARTIAL))
|
|---|
| 1453 | return TRUE;
|
|---|
| 1454 | else
|
|---|
| 1455 | return FALSE;
|
|---|
| 1456 | }
|
|---|
| 1457 | //******************************************************************************
|
|---|
| 1458 | //Returned region in device coordinates (undocumented behaviour)
|
|---|
| 1459 | //******************************************************************************
|
|---|
| 1460 | ODINFUNCTIONNODBG1(HRGN, PathToRegion, HDC, hdc)
|
|---|
| 1461 | {
|
|---|
| 1462 | pDCData pHps = (pDCData)OSLibGpiQueryDCData((HPS)hdc);
|
|---|
| 1463 | if(!pHps)
|
|---|
| 1464 | {
|
|---|
| 1465 | dprintf(("WARNING: PathToRegion %x; invalid hdc!", hdc));
|
|---|
| 1466 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1467 | return NULLHANDLE;
|
|---|
| 1468 | }
|
|---|
| 1469 |
|
|---|
| 1470 | HRGN hrgn, hrgnTemp, hrgnwin;
|
|---|
| 1471 |
|
|---|
| 1472 | dprintf(("GDI32: PathToRegion %x", hdc));
|
|---|
| 1473 |
|
|---|
| 1474 | hrgnTemp = GpiPathToRegion(pHps->hps, 1, (pHps->polyFillMode == ALTERNATE_W) ? FPATH_ALTERNATE : FPATH_WINDING);
|
|---|
| 1475 | if(hrgnTemp == NULLHANDLE)
|
|---|
| 1476 | goto error;
|
|---|
| 1477 |
|
|---|
| 1478 | hrgnwin = CreateRectRgn(1, 1, 2, 2);
|
|---|
| 1479 | hrgn = ObjGetHandleData(hrgnwin);
|
|---|
| 1480 | if(hrgn == HANDLE_OBJ_ERROR) {
|
|---|
| 1481 | dprintf(("WARNING: PathToRegion invalid region", hrgnwin));
|
|---|
| 1482 | SetLastError(ERROR_INVALID_HANDLE_W);
|
|---|
| 1483 | return NULLHANDLE;
|
|---|
| 1484 | }
|
|---|
| 1485 |
|
|---|
| 1486 | if(!setWinDeviceRegionFromPMDeviceRegion(hrgn, hrgnTemp, pHps, NULL))
|
|---|
| 1487 | goto error;
|
|---|
| 1488 |
|
|---|
| 1489 | GpiDestroyRegion(pHps->hps, hrgnTemp);
|
|---|
| 1490 |
|
|---|
| 1491 | return hrgnwin;
|
|---|
| 1492 |
|
|---|
| 1493 | error:
|
|---|
| 1494 | if(hrgnwin)
|
|---|
| 1495 | DeleteObject(hrgnwin);
|
|---|
| 1496 |
|
|---|
| 1497 | SetLastError(ERROR_INVALID_HANDLE_W); //todo right error
|
|---|
| 1498 | return NULLHANDLE;
|
|---|
| 1499 | }
|
|---|
| 1500 | //******************************************************************************
|
|---|
| 1501 | //Needs wrapper as this file includes os2.h!!
|
|---|
| 1502 | //******************************************************************************
|
|---|
| 1503 | ODINFUNCTIONNODBG1(BOOL, OSLibDeleteRegion, HANDLE, hRegion)
|
|---|
| 1504 | {
|
|---|
| 1505 | if(GpiDestroyRegion(hpsRegion, hRegion) == FALSE) {
|
|---|
| 1506 | dprintf(("WARNING: OSLibDeleteRegion %x; GpiDestroyRegion failed (%x)", hRegion, WinGetLastError(0)));
|
|---|
| 1507 | }
|
|---|
| 1508 | return (0);
|
|---|
| 1509 | }
|
|---|
| 1510 | /*****************************************************************************
|
|---|
| 1511 | * Name : int GetMetaRgn
|
|---|
| 1512 | * Purpose : The GetMetaRgn function retrieves the current metaregion for
|
|---|
| 1513 | * the specified device context.
|
|---|
| 1514 | * Parameters: HDC hdc handle of device context
|
|---|
| 1515 | * HRGN hrgn handle of region
|
|---|
| 1516 | * Variables :
|
|---|
| 1517 | * Result : 0 / 1
|
|---|
| 1518 | * Remark :
|
|---|
| 1519 | * Status : UNTESTED STUB
|
|---|
| 1520 | *
|
|---|
| 1521 | * Author : Patrick Haller [Mon, 1998/06/15 08:00]
|
|---|
| 1522 | *****************************************************************************/
|
|---|
| 1523 |
|
|---|
| 1524 | ODINFUNCTIONNODBG2(int, GetMetaRgn, HDC, hdc, HRGN, hrgn)
|
|---|
| 1525 | {
|
|---|
| 1526 | dprintf(("GDI32: GetMetaRgn(%08xh, %08xh) not implemented.\n",
|
|---|
| 1527 | hdc,
|
|---|
| 1528 | hrgn));
|
|---|
| 1529 |
|
|---|
| 1530 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 1531 | return (0);
|
|---|
| 1532 | }
|
|---|
| 1533 | /*****************************************************************************
|
|---|
| 1534 | * Name : int SetMetaRgn
|
|---|
| 1535 | * Purpose : The SetMetaRgn function intersects the current clipping region
|
|---|
| 1536 | * for the specified device context with the current metaregion
|
|---|
| 1537 | * and saves the combined region as the new metaregion for the
|
|---|
| 1538 | * specified device context. The clipping region is reset to a null region.
|
|---|
| 1539 | * Parameters: HDC hdc handle of device context
|
|---|
| 1540 | * Variables :
|
|---|
| 1541 | * Result : TRUE / FALSE
|
|---|
| 1542 | * Remark :
|
|---|
| 1543 | * Status : UNTESTED STUB
|
|---|
| 1544 | *
|
|---|
| 1545 | * Author : Patrick Haller [Mon, 1998/06/15 08:00]
|
|---|
| 1546 | *****************************************************************************/
|
|---|
| 1547 |
|
|---|
| 1548 | ODINFUNCTIONNODBG1(BOOL, SetMetaRgn, HDC, hdc)
|
|---|
| 1549 | {
|
|---|
| 1550 | dprintf(("GDI32: SetMetaRgn(%08xh) not implemented.\n",
|
|---|
| 1551 | hdc));
|
|---|
| 1552 |
|
|---|
| 1553 | SetLastError(ERROR_SUCCESS_W);
|
|---|
| 1554 | return (NULLREGION_W);
|
|---|
| 1555 | }
|
|---|
| 1556 | //******************************************************************************
|
|---|
| 1557 | //******************************************************************************
|
|---|