| 1 | /* $Id: oslibgpi.cpp,v 1.3 2001-10-18 07:49:37 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 | if(screenHeight == 0) {
|
|---|
| 37 | RECTL desktopRectl;
|
|---|
| 38 | WinQueryWindowRect(HWND_DESKTOP, &desktopRectl);
|
|---|
| 39 | screenHeight = desktopRectl.xRight;
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | hps = WinGetPS(Win32ToOS2FrameHandle(hwnd));
|
|---|
| 43 | if(hps == NULL) {
|
|---|
| 44 | dprintf(("OSLibQueryVisibleRegion: WinGetPS %x failed", hwnd));
|
|---|
| 45 | return NULL;
|
|---|
| 46 | }
|
|---|
| 47 | hrgnVis = GreCreateRectRegion(hps, &rcl, 1);
|
|---|
| 48 | GreCopyClipRegion(hps, hrgnVis, 0, COPYCRGN_VISRGN);
|
|---|
| 49 |
|
|---|
| 50 | RGNRECT rgnRect;
|
|---|
| 51 | rgnRect.ircStart = 1;
|
|---|
| 52 | rgnRect.crc = 0;
|
|---|
| 53 | rgnRect.ulDirection = RECTDIR_LFRT_TOPBOT;
|
|---|
| 54 | if(!GpiQueryRegionRects(hps, hrgnVis, NULL, &rgnRect, NULL))
|
|---|
| 55 | {
|
|---|
| 56 | dprintf(("WARNING: GpiQueryRegionRects failed! (%x)", WinGetLastError(0)));
|
|---|
| 57 | goto failure;
|
|---|
| 58 | }
|
|---|
| 59 | bufSizeNeeded = rgnRect.crcReturned * sizeof(RECT) + sizeof (RGNDATAHEADER);
|
|---|
| 60 | lpRgnData = (LPRGNDATA)malloc(bufSizeNeeded);
|
|---|
| 61 |
|
|---|
| 62 | pRectl = (PRECTL)lpRgnData->Buffer;
|
|---|
| 63 | rgnRect.crc = rgnRect.crcReturned;
|
|---|
| 64 | if(!GpiQueryRegionRects(hps, hrgnVis, NULL, &rgnRect, pRectl))
|
|---|
| 65 | {
|
|---|
| 66 | dprintf(("WARNING: GpiQueryRegionRects failed! (%x)", WinGetLastError(0)));
|
|---|
| 67 | goto failure;
|
|---|
| 68 | }
|
|---|
| 69 | for(i=0;i<rgnRect.crcReturned;i++) {
|
|---|
| 70 | temp = pRectl[i].yTop;
|
|---|
| 71 | dprintf(("Region rect %d (%d,%d)(%d,%d)", i, pRectl[i].xLeft, pRectl[i].yBottom, pRectl[i].xRight, pRectl[i].yTop));
|
|---|
| 72 | pRectl[i].yTop = screenHeight - pRectl[i].yBottom;
|
|---|
| 73 | pRectl[i].yBottom = screenHeight - temp;
|
|---|
| 74 | dprintf(("Region rect %d (%d,%d)(%d,%d)", i, pRectl[i].xLeft, pRectl[i].yBottom, pRectl[i].xRight, pRectl[i].yTop));
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | RECTL boundRect;
|
|---|
| 78 | GpiQueryRegionBox(hps, hrgnVis, &boundRect);
|
|---|
| 79 |
|
|---|
| 80 | lpRgnData->rdh.dwSize = sizeof(lpRgnData->rdh);
|
|---|
| 81 | lpRgnData->rdh.iType = RDH_RECTANGLES_W; // one and only possible value
|
|---|
| 82 | lpRgnData->rdh.nCount = rgnRect.crcReturned;
|
|---|
| 83 | lpRgnData->rdh.nRgnSize = rgnRect.crcReturned * sizeof(RECT);
|
|---|
| 84 |
|
|---|
| 85 | //flip top & bottom for bounding rectangle (not really necessary; but cleaner coding)
|
|---|
| 86 | dprintf(("Boundary (%d,%d)(%d,%d)", boundRect.xLeft, boundRect.yBottom, boundRect.xRight, boundRect.yTop));
|
|---|
| 87 | lpRgnData->rdh.rcBound.left = boundRect.xLeft;
|
|---|
| 88 | lpRgnData->rdh.rcBound.right = boundRect.xRight;
|
|---|
| 89 | lpRgnData->rdh.rcBound.top = screenHeight - boundRect.yBottom;
|
|---|
| 90 | lpRgnData->rdh.rcBound.bottom = screenHeight - boundRect.yTop;
|
|---|
| 91 | dprintf(("Boundary (%d,%d)(%d,%d)", boundRect.xLeft, boundRect.yBottom, boundRect.xRight, boundRect.yTop));
|
|---|
| 92 |
|
|---|
| 93 | // Destroy the region now we have finished with it.
|
|---|
| 94 | GreDestroyRegion(hps, hrgnVis);
|
|---|
| 95 | WinReleasePS(hps);
|
|---|
| 96 | return lpRgnData;
|
|---|
| 97 |
|
|---|
| 98 | failure:
|
|---|
| 99 | if(lpRgnData) free(lpRgnData);
|
|---|
| 100 | if(hrgnVis) GreDestroyRegion(hps, hrgnVis);
|
|---|
| 101 | if(hps) WinReleasePS(hps);
|
|---|
| 102 | return 0;
|
|---|
| 103 | }
|
|---|
| 104 | //******************************************************************************
|
|---|
| 105 | //******************************************************************************
|
|---|
| 106 |
|
|---|