| 1 | /* $Id: oslibgdi.cpp,v 1.7 1999-07-25 15:51:55 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Window GDI wrapper functions for OS/2
|
|---|
| 4 | *
|
|---|
| 5 | *
|
|---|
| 6 | * Copyright 1999 Sander van Leeuwen (sandervl@xs4all.nl)
|
|---|
| 7 | *
|
|---|
| 8 | *
|
|---|
| 9 | * Project Odin Software License can be found in LICENSE.TXT
|
|---|
| 10 | *
|
|---|
| 11 | */
|
|---|
| 12 | #define INCL_WIN
|
|---|
| 13 | #define INCL_PM
|
|---|
| 14 | #include <os2.h>
|
|---|
| 15 | #include <os2wrap.h>
|
|---|
| 16 | #include <stdlib.h>
|
|---|
| 17 | #include <string.h>
|
|---|
| 18 |
|
|---|
| 19 | #include <misc.h>
|
|---|
| 20 | #include <oslibgdi.h>
|
|---|
| 21 | #include <oslibwin.h>
|
|---|
| 22 |
|
|---|
| 23 | //******************************************************************************
|
|---|
| 24 | //******************************************************************************
|
|---|
| 25 | inline ULONG MAPWIN32POINT(RECTLOS2 *parent, ULONG cy, ULONG y)
|
|---|
| 26 | {
|
|---|
| 27 | return (parent->yTop - parent->yBottom - cy - y);
|
|---|
| 28 | }
|
|---|
| 29 | //******************************************************************************
|
|---|
| 30 | //Map win32 y coordinate (in parent window coordinates) to OS/2 y coord. (in parent window coordinates)
|
|---|
| 31 | //******************************************************************************
|
|---|
| 32 | ULONG MapOS2ToWin32Y(HWND hwndParent, ULONG cy, ULONG y)
|
|---|
| 33 | {
|
|---|
| 34 | RECTLOS2 rectParent = {0};
|
|---|
| 35 |
|
|---|
| 36 | if(hwndParent == OSLIB_HWND_DESKTOP) {
|
|---|
| 37 | hwndParent = HWND_DESKTOP;
|
|---|
| 38 | }
|
|---|
| 39 | WinQueryWindowRect(hwndParent, (PRECTL)&rectParent);
|
|---|
| 40 | return MAPWIN32POINT(&rectParent, cy, y);
|
|---|
| 41 | }
|
|---|
| 42 | //******************************************************************************
|
|---|
| 43 | //******************************************************************************
|
|---|
| 44 | BOOL MapOS2ToWin32Point(HWND hwndParent, HWND hwndChild, OSLIBPOINT *point)
|
|---|
| 45 | {
|
|---|
| 46 | RECTLOS2 rectParent = {0};
|
|---|
| 47 |
|
|---|
| 48 | if(hwndParent == OSLIB_HWND_DESKTOP) {
|
|---|
| 49 | hwndParent = HWND_DESKTOP;
|
|---|
| 50 | }
|
|---|
| 51 | if(WinMapWindowPoints(hwndChild, hwndParent, (POINTL *)point, 1) != TRUE) {
|
|---|
| 52 | dprintf(("MapOS2ToWin32Point:WinMapWindowPoint %x %x returned false", hwndParent, hwndChild));
|
|---|
| 53 | return FALSE;
|
|---|
| 54 | }
|
|---|
| 55 | WinQueryWindowRect(hwndParent, (PRECTL)&rectParent);
|
|---|
| 56 | point->y = rectParent.yTop - point->y - 1;
|
|---|
| 57 | return TRUE;
|
|---|
| 58 | }
|
|---|
| 59 | //******************************************************************************
|
|---|
| 60 | // MapOS2ToWin32Rect
|
|---|
| 61 | // Map os/2 rectangle to screen coordinates and convert to win32 rect
|
|---|
| 62 | //
|
|---|
| 63 | // Parameters:
|
|---|
| 64 | // hwndParent: Parent window handle
|
|---|
| 65 | // hwndChild: Child window handle
|
|---|
| 66 | // rectOS2: OS/2 child window RECTL
|
|---|
| 67 | // rectWin32: Win32 Child window RECT (IN)
|
|---|
| 68 | //
|
|---|
| 69 | // Returns:
|
|---|
| 70 | // TRUE: Success
|
|---|
| 71 | // FALSE: Failures
|
|---|
| 72 | //******************************************************************************
|
|---|
| 73 | BOOL MapOS2ToWin32Rectl(HWND hwndParent, HWND hwndChild, PRECTLOS2 rectOS2, PRECT rectWin32)
|
|---|
| 74 | {
|
|---|
| 75 | RECTLOS2 rectParent = {0};
|
|---|
| 76 |
|
|---|
| 77 | if(hwndParent == OSLIB_HWND_DESKTOP) {
|
|---|
| 78 | hwndParent = HWND_DESKTOP;
|
|---|
| 79 | }
|
|---|
| 80 | if(WinMapWindowPoints(hwndChild, hwndParent, (PPOINTL)rectOS2, 2) != TRUE) {
|
|---|
| 81 | dprintf(("MapOS2ToWin32Rect:WinMapWindowPoint %x %x returned false", hwndParent, hwndChild));
|
|---|
| 82 | return FALSE;
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | ULONG length = rectOS2->yTop - rectOS2->yBottom;
|
|---|
| 86 |
|
|---|
| 87 | rectWin32->bottom = length - rectOS2->yBottom;
|
|---|
| 88 | rectWin32->top = length - rectOS2->yTop;
|
|---|
| 89 | rectWin32->left = rectOS2->xLeft;
|
|---|
| 90 | rectWin32->right = rectOS2->xRight;
|
|---|
| 91 |
|
|---|
| 92 | return TRUE;
|
|---|
| 93 | }
|
|---|
| 94 | //******************************************************************************
|
|---|
| 95 | // MapOS2ToWin32Rectl
|
|---|
| 96 | // Convert OS/2 to Win32 RECTL structure
|
|---|
| 97 | //
|
|---|
| 98 | // Parameters:
|
|---|
| 99 | // rectOS2: OS/2 child window RECTL
|
|---|
| 100 | // rectWin32: Win32 Child window RECT (IN)
|
|---|
| 101 | //
|
|---|
| 102 | // Returns:
|
|---|
| 103 | // TRUE: Success
|
|---|
| 104 | // FALSE: Failures
|
|---|
| 105 | //******************************************************************************
|
|---|
| 106 | BOOL MapOS2ToWin32Rectl(PRECTLOS2 rectOS2, PRECT rectWin32)
|
|---|
| 107 | {
|
|---|
| 108 | ULONG length = rectOS2->yTop - rectOS2->yBottom;
|
|---|
| 109 |
|
|---|
| 110 | rectWin32->bottom = length - rectOS2->yBottom;
|
|---|
| 111 | rectWin32->top = length - rectOS2->yTop;
|
|---|
| 112 | rectWin32->left = rectOS2->xLeft;
|
|---|
| 113 | rectWin32->right = rectOS2->xRight;
|
|---|
| 114 | return TRUE;
|
|---|
| 115 | }
|
|---|
| 116 | //******************************************************************************
|
|---|
| 117 | // MapWin32ToOS2Rectl
|
|---|
| 118 | // Convert Win32 to OS/2 RECTL structure
|
|---|
| 119 | //
|
|---|
| 120 | // Parameters:
|
|---|
| 121 | // rectWin32: Win32 Child window RECT (IN)
|
|---|
| 122 | // rectOS2: OS/2 Child window RECTL (OUT)
|
|---|
| 123 | // Returns:
|
|---|
| 124 | // TRUE: Success
|
|---|
| 125 | // FALSE: Failures
|
|---|
| 126 | //******************************************************************************
|
|---|
| 127 | BOOL MapWin32ToOS2Rectl(PRECT rectWin32, PRECTLOS2 rectOS2)
|
|---|
| 128 | {
|
|---|
| 129 | ULONG length = rectWin32->top - rectWin32->bottom;
|
|---|
| 130 |
|
|---|
| 131 | rectOS2->yBottom = length - rectWin32->bottom;
|
|---|
| 132 | rectOS2->yTop = length - rectWin32->top;
|
|---|
| 133 | rectOS2->xLeft = rectWin32->left;
|
|---|
| 134 | rectOS2->xRight = rectWin32->right;
|
|---|
| 135 | return TRUE;
|
|---|
| 136 | }
|
|---|
| 137 | //******************************************************************************
|
|---|
| 138 | //******************************************************************************
|
|---|
| 139 | HDC OSLibWinBeginPaint(HWND hwnd, RECT *rectWin32)
|
|---|
| 140 | {
|
|---|
| 141 | RECTL rectl;
|
|---|
| 142 |
|
|---|
| 143 | if(WinQueryUpdateRect(hwnd, &rectl) == FALSE)
|
|---|
| 144 | {
|
|---|
| 145 | dprintf(("BeginPaint, NO update rectl"));
|
|---|
| 146 | return 0;
|
|---|
| 147 | }
|
|---|
| 148 | MapOS2ToWin32Rectl((RECTLOS2 *)&rectl, rectWin32);
|
|---|
| 149 | return WinBeginPaint(hwnd, NULLHANDLE, &rectl);
|
|---|
| 150 | }
|
|---|
| 151 | //******************************************************************************
|
|---|
| 152 | //******************************************************************************
|
|---|
| 153 | BOOL OSLibWinEndPaint(HDC hdc)
|
|---|
| 154 | {
|
|---|
| 155 | return WinEndPaint((HPS)hdc);
|
|---|
| 156 | }
|
|---|
| 157 | //******************************************************************************
|
|---|
| 158 | //******************************************************************************
|
|---|
| 159 | HDC OSLibWinGetPS(HWND hwnd)
|
|---|
| 160 | {
|
|---|
| 161 | if(hwnd == OSLIB_HWND_DESKTOP)
|
|---|
| 162 | hwnd = HWND_DESKTOP;
|
|---|
| 163 |
|
|---|
| 164 | return (HDC)WinGetPS(hwnd);
|
|---|
| 165 | }
|
|---|
| 166 | //******************************************************************************
|
|---|
| 167 | //******************************************************************************
|
|---|
| 168 | BOOL OSLibWinReleasePS(HDC hdc)
|
|---|
| 169 | {
|
|---|
| 170 | return WinReleasePS((HPS)hdc);
|
|---|
| 171 | }
|
|---|
| 172 | //******************************************************************************
|
|---|
| 173 | //******************************************************************************
|
|---|
| 174 | BOOL OSLibWinInvalidateRect(HWND hwnd, PRECT pRect, BOOL fIncludeChildren)
|
|---|
| 175 | {
|
|---|
| 176 | RECTLOS2 rectl;
|
|---|
| 177 |
|
|---|
| 178 | if(pRect) {
|
|---|
| 179 | MapWin32ToOS2Rectl(pRect, &rectl);
|
|---|
| 180 | return WinInvalidateRect(hwnd, (PRECTL)&rectl, fIncludeChildren);
|
|---|
| 181 | }
|
|---|
| 182 | return WinInvalidateRect(hwnd, NULL, fIncludeChildren);
|
|---|
| 183 | }
|
|---|
| 184 | //******************************************************************************
|
|---|
| 185 | //Returns rectangle in Win32 window coordinates
|
|---|
| 186 | //******************************************************************************
|
|---|
| 187 | BOOL OSLibWinQueryUpdateRect(HWND hwnd, PRECT pRect)
|
|---|
| 188 | {
|
|---|
| 189 | BOOL rc;
|
|---|
| 190 | RECTLOS2 rectl;
|
|---|
| 191 |
|
|---|
| 192 | rc = WinQueryUpdateRect(hwnd, (PRECTL)&rectl);
|
|---|
| 193 | if(rc) {
|
|---|
| 194 | MapOS2ToWin32Rectl(&rectl, pRect);
|
|---|
| 195 | }
|
|---|
| 196 | else memset(pRect, 0, sizeof(RECT));
|
|---|
| 197 | return rc;
|
|---|
| 198 | }
|
|---|
| 199 | //******************************************************************************
|
|---|
| 200 | //******************************************************************************
|
|---|
| 201 |
|
|---|