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