| 1 | /* $Id: oslibgpi.cpp,v 1.2 2001-10-01 07:06:10 sandervl Exp $ */
|
|---|
| 2 |
|
|---|
| 3 | /*
|
|---|
| 4 | * GPI interface code
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1999 Christoph Bratschi (cbratschi@datacomm.ch)
|
|---|
| 7 | *
|
|---|
| 8 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 9 | *
|
|---|
| 10 | */
|
|---|
| 11 |
|
|---|
| 12 | #define INCL_GPI
|
|---|
| 13 | #define INCL_WIN
|
|---|
| 14 | #include <os2wrap.h> //Odin32 OS/2 api wrappers
|
|---|
| 15 | #include <stdlib.h>
|
|---|
| 16 | #include <string.h>
|
|---|
| 17 | #include <math.h>
|
|---|
| 18 | #include "win32type.h"
|
|---|
| 19 | #include <winconst.h>
|
|---|
| 20 | #include <winuser32.h>
|
|---|
| 21 | #include "oslibgpi.h"
|
|---|
| 22 | #include <misc.h>
|
|---|
| 23 |
|
|---|
| 24 | //******************************************************************************
|
|---|
| 25 | //******************************************************************************
|
|---|
| 26 | LPRGNDATA OSLibQueryVisibleRegion(HWND hwnd, DWORD screenHeight)
|
|---|
| 27 | {
|
|---|
| 28 | HRGN hrgnVis = 0;
|
|---|
| 29 | RECTL rcl = {0,0,1,1};
|
|---|
| 30 | LPRGNDATA lpRgnData = 0;
|
|---|
| 31 | HPS hps = 0;
|
|---|
| 32 | LONG temp, i;
|
|---|
| 33 | ULONG bufSizeNeeded;
|
|---|
| 34 | PRECTL pRectl;
|
|---|
| 35 |
|
|---|
| 36 | hps = WinGetPS(Win32ToOS2FrameHandle(hwnd));
|
|---|
| 37 | if(hps == NULL) {
|
|---|
| 38 | dprintf(("OSLibQueryVisibleRegion: WinGetPS %x failed", hwnd));
|
|---|
| 39 | return NULL;
|
|---|
| 40 | }
|
|---|
| 41 | hrgnVis = GreCreateRectRegion(hps, &rcl, 1);
|
|---|
| 42 | GreCopyClipRegion(hps, hrgnVis, 0, COPYCRGN_VISRGN);
|
|---|
| 43 |
|
|---|
| 44 | RGNRECT rgnRect;
|
|---|
| 45 | rgnRect.ircStart = 1;
|
|---|
| 46 | rgnRect.crc = 0;
|
|---|
| 47 | rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT;
|
|---|
| 48 | if(!GpiQueryRegionRects(hps, hrgnVis, NULL, &rgnRect, NULL))
|
|---|
| 49 | {
|
|---|
| 50 | dprintf(("WARNING: GpiQueryRegionRects failed! (%x)", WinGetLastError(0)));
|
|---|
| 51 | goto failure;
|
|---|
| 52 | }
|
|---|
| 53 | bufSizeNeeded = rgnRect.crcReturned * sizeof(RECT) + sizeof (RGNDATAHEADER);
|
|---|
| 54 | lpRgnData = (LPRGNDATA)malloc(bufSizeNeeded);
|
|---|
| 55 |
|
|---|
| 56 | pRectl = (PRECTL)lpRgnData->Buffer;
|
|---|
| 57 | rgnRect.crc = rgnRect.crcReturned;
|
|---|
| 58 | if(!GpiQueryRegionRects(hps, hrgnVis, NULL, &rgnRect, pRectl))
|
|---|
| 59 | {
|
|---|
| 60 | dprintf(("WARNING: GpiQueryRegionRects failed! (%x)", WinGetLastError(0)));
|
|---|
| 61 | goto failure;
|
|---|
| 62 | }
|
|---|
| 63 | for(i=0;i<rgnRect.crcReturned;i++) {
|
|---|
| 64 | temp = pRectl[i].yTop;
|
|---|
| 65 | dprintf(("Region rect %d (%d,%d)(%d,%d)", i, pRectl[i].xLeft, pRectl[i].yBottom, pRectl[i].xRight, pRectl[i].yTop));
|
|---|
| 66 | pRectl[i].yTop = screenHeight - pRectl[i].yBottom;
|
|---|
| 67 | pRectl[i].yBottom = screenHeight - temp;
|
|---|
| 68 | dprintf(("Region rect %d (%d,%d)(%d,%d)", i, pRectl[i].xLeft, pRectl[i].yBottom, pRectl[i].xRight, pRectl[i].yTop));
|
|---|
| 69 | }
|
|---|
| 70 |
|
|---|
| 71 | RECTL boundRect;
|
|---|
| 72 | GpiQueryRegionBox(hps, hrgnVis, &boundRect);
|
|---|
| 73 |
|
|---|
| 74 | lpRgnData->rdh.dwSize = sizeof(lpRgnData->rdh);
|
|---|
| 75 | lpRgnData->rdh.iType = RDH_RECTANGLES_W; // one and only possible value
|
|---|
| 76 | lpRgnData->rdh.nCount = rgnRect.crcReturned;
|
|---|
| 77 | lpRgnData->rdh.nRgnSize = rgnRect.crcReturned * sizeof(RECT);
|
|---|
| 78 |
|
|---|
| 79 | //flip top & bottom for bounding rectangle (not really necessary; but cleaner coding)
|
|---|
| 80 | dprintf(("Boundary (%d,%d)(%d,%d)", boundRect.xLeft, boundRect.yBottom, boundRect.xRight, boundRect.yTop));
|
|---|
| 81 | lpRgnData->rdh.rcBound.left = boundRect.xLeft;
|
|---|
| 82 | lpRgnData->rdh.rcBound.right = boundRect.xRight;
|
|---|
| 83 | lpRgnData->rdh.rcBound.top = screenHeight - boundRect.yBottom;
|
|---|
| 84 | lpRgnData->rdh.rcBound.bottom = screenHeight - boundRect.yTop;
|
|---|
| 85 | dprintf(("Boundary (%d,%d)(%d,%d)", boundRect.xLeft, boundRect.yBottom, boundRect.xRight, boundRect.yTop));
|
|---|
| 86 |
|
|---|
| 87 | // Destroy the region now we have finished with it.
|
|---|
| 88 | GreDestroyRegion(hps, hrgnVis);
|
|---|
| 89 | WinReleasePS(hps);
|
|---|
| 90 | return lpRgnData;
|
|---|
| 91 |
|
|---|
| 92 | failure:
|
|---|
| 93 | if(lpRgnData) free(lpRgnData);
|
|---|
| 94 | if(hrgnVis) GreDestroyRegion(hps, hrgnVis);
|
|---|
| 95 | if(hps) WinReleasePS(hps);
|
|---|
| 96 | return 0;
|
|---|
| 97 | }
|
|---|
| 98 | //******************************************************************************
|
|---|
| 99 | //******************************************************************************
|
|---|