| 1 | /* $Id: oslibgdi.cpp,v 1.6 1999-12-28 17:04:23 cbratschi 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 | #include <misc.h>
|
|---|
| 19 | #include <oslibgdi.h>
|
|---|
| 20 | #include <oslibwin.h>
|
|---|
| 21 | #include "win32wbase.h"
|
|---|
| 22 |
|
|---|
| 23 | //CB: new mapping infrastructure to avoid transformation bugs -> available soon
|
|---|
| 24 |
|
|---|
| 25 | /*
|
|---|
| 26 | All mapScreen/Window can be used to transform from Win32 to OS/2 and vice versa
|
|---|
| 27 | First letter is lower case to avoid conflicts with Win32 API names
|
|---|
| 28 |
|
|---|
| 29 | Single y mapping:
|
|---|
| 30 | mapScreenY()
|
|---|
| 31 | mapClientY()
|
|---|
| 32 | mapChildY()
|
|---|
| 33 |
|
|---|
| 34 | Single point mapping:
|
|---|
| 35 | mapScreenPoint()
|
|---|
| 36 | mapClientPoint()
|
|---|
| 37 | mapChildPoint()
|
|---|
| 38 |
|
|---|
| 39 | Single rect mapping:
|
|---|
| 40 | mapScreenRect()
|
|---|
| 41 | mapClientRect()
|
|---|
| 42 |
|
|---|
| 43 | Rect transformation:
|
|---|
| 44 | copyOS2Rect()
|
|---|
| 45 | copyWin32Rect()
|
|---|
| 46 | */
|
|---|
| 47 |
|
|---|
| 48 | INT mapScreenY(INT screenPosY)
|
|---|
| 49 | {
|
|---|
| 50 | return WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN)-1-screenPosY;
|
|---|
| 51 | }
|
|---|
| 52 | //******************************************************************************
|
|---|
| 53 | //******************************************************************************
|
|---|
| 54 | INT mapScreenY(INT screenH,INT screenPosY)
|
|---|
| 55 | {
|
|---|
| 56 | return screenH-1-screenPosY;
|
|---|
| 57 | }
|
|---|
| 58 | //******************************************************************************
|
|---|
| 59 | //******************************************************************************
|
|---|
| 60 | INT mapClientY(INT clientH,INT clientPosY)
|
|---|
| 61 | {
|
|---|
| 62 | return clientH-1-clientPosY;
|
|---|
| 63 | }
|
|---|
| 64 | //******************************************************************************
|
|---|
| 65 | //******************************************************************************
|
|---|
| 66 | INT mapClientY(HWND os2Client,INT clientPosY)
|
|---|
| 67 | {
|
|---|
| 68 | RECTL rect;
|
|---|
| 69 |
|
|---|
| 70 | if (os2Client == OSLIB_HWND_DESKTOP) os2Client = HWND_DESKTOP; //client shouldn't be desktop
|
|---|
| 71 | if (!WinQueryWindowRect(os2Client,&rect)) return 0;
|
|---|
| 72 | return rect.yTop-1-clientPosY;
|
|---|
| 73 | }
|
|---|
| 74 | //******************************************************************************
|
|---|
| 75 | //******************************************************************************
|
|---|
| 76 | INT mapClientY(Win32BaseWindow *win32wnd,INT clientPosY)
|
|---|
| 77 | {
|
|---|
| 78 | return win32wnd->getWindowHeight()-1-clientPosY;
|
|---|
| 79 | }
|
|---|
| 80 | //******************************************************************************
|
|---|
| 81 | //******************************************************************************
|
|---|
| 82 | INT mapChildY(INT parentH,INT childY,INT childPosY)
|
|---|
| 83 | {
|
|---|
| 84 | return parentH-1-childY-childPosY;
|
|---|
| 85 | }
|
|---|
| 86 | //******************************************************************************
|
|---|
| 87 | //******************************************************************************
|
|---|
| 88 | INT mapChildY(HWND os2Parent,INT childY,INT childPosY)
|
|---|
| 89 | {
|
|---|
| 90 | RECTL rect;
|
|---|
| 91 |
|
|---|
| 92 | if (os2Parent == OSLIB_HWND_DESKTOP) os2Parent = HWND_DESKTOP;
|
|---|
| 93 | if (!WinQueryWindowRect(os2Parent,&rect)) return 0;
|
|---|
| 94 | return rect.yTop-1-childY-childPosY;
|
|---|
| 95 | }
|
|---|
| 96 | //******************************************************************************
|
|---|
| 97 | //******************************************************************************
|
|---|
| 98 | INT mapChildY(HWND os2Parent,HWND os2Child,INT childPosY)
|
|---|
| 99 | {
|
|---|
| 100 | RECTL rect;
|
|---|
| 101 | SWP swp;
|
|---|
| 102 |
|
|---|
| 103 | if (os2Parent == OSLIB_HWND_DESKTOP) os2Parent = HWND_DESKTOP;
|
|---|
| 104 | if (!WinQueryWindowRect(os2Parent,&rect)) return 0;
|
|---|
| 105 | if (!WinQueryWindowPos(os2Child,&swp)) return 0;
|
|---|
| 106 | return rect.yTop-1-swp.y-childPosY;
|
|---|
| 107 | }
|
|---|
| 108 | //******************************************************************************
|
|---|
| 109 | //******************************************************************************
|
|---|
| 110 | BOOL mapScreenPoint(OSLIBPOINT *screenPt)
|
|---|
| 111 | {
|
|---|
| 112 | if(!screenPt) return FALSE;
|
|---|
| 113 | screenPt->y = WinQuerySysValue(HWND_DESKTOP,SV_CYSCREEN)-1-screenPt->y;
|
|---|
| 114 | return TRUE;
|
|---|
| 115 | }
|
|---|
| 116 | //******************************************************************************
|
|---|
| 117 | //******************************************************************************
|
|---|
| 118 | INT mapScreenY(INT screenH,OSLIBPOINT *screenPt)
|
|---|
| 119 | {
|
|---|
| 120 | if (!screenPt) return FALSE;
|
|---|
| 121 | screenPt->y = screenH-1-screenPt->y;
|
|---|
| 122 | return TRUE;
|
|---|
| 123 | }
|
|---|
| 124 |
|
|---|
| 125 | //old mapping functions
|
|---|
| 126 |
|
|---|
| 127 | //******************************************************************************
|
|---|
| 128 | //******************************************************************************
|
|---|
| 129 | inline ULONG MAPWIN32POINT(RECTLOS2 *parent, ULONG cy, ULONG y)
|
|---|
| 130 | {
|
|---|
| 131 | return (parent->yTop - parent->yBottom - cy - y);
|
|---|
| 132 | }
|
|---|
| 133 | //******************************************************************************
|
|---|
| 134 | //Map win32 y coordinate (in parent window coordinates) to OS/2 y coord. (in parent window coordinates)
|
|---|
| 135 | //******************************************************************************
|
|---|
| 136 | ULONG MapOS2ToWin32Y(HWND hwndParent, ULONG cy, ULONG y)
|
|---|
| 137 | {
|
|---|
| 138 | RECTLOS2 rectParent = {0};
|
|---|
| 139 |
|
|---|
| 140 | if(hwndParent == OSLIB_HWND_DESKTOP) {
|
|---|
| 141 | hwndParent = HWND_DESKTOP;
|
|---|
| 142 | }
|
|---|
| 143 | WinQueryWindowRect(hwndParent, (PRECTL)&rectParent);
|
|---|
| 144 | return MAPWIN32POINT(&rectParent, cy, y);
|
|---|
| 145 | }
|
|---|
| 146 | //******************************************************************************
|
|---|
| 147 | //******************************************************************************
|
|---|
| 148 | BOOL MapOS2ToWin32Point(HWND hwndParent, HWND hwndChild, OSLIBPOINT *point)
|
|---|
| 149 | {
|
|---|
| 150 | RECTLOS2 rectParent = {0};
|
|---|
| 151 |
|
|---|
| 152 | if(hwndParent == OSLIB_HWND_DESKTOP) {
|
|---|
| 153 | hwndParent = HWND_DESKTOP;
|
|---|
| 154 | }
|
|---|
| 155 | if(WinMapWindowPoints(hwndChild, hwndParent, (POINTL *)point, 1) != TRUE) {
|
|---|
| 156 | dprintf(("MapOS2ToWin32Point:WinMapWindowPoint %x %x returned false", hwndParent, hwndChild));
|
|---|
| 157 | return FALSE;
|
|---|
| 158 | }
|
|---|
| 159 | WinQueryWindowRect(hwndParent, (PRECTL)&rectParent);
|
|---|
| 160 | point->y = rectParent.yTop - point->y - 1;
|
|---|
| 161 | return TRUE;
|
|---|
| 162 | }
|
|---|
| 163 | //******************************************************************************
|
|---|
| 164 | // MapOS2ToWin32Rect
|
|---|
| 165 | // Map os/2 rectangle to screen coordinates and convert to win32 rect
|
|---|
| 166 | //
|
|---|
| 167 | // Parameters:
|
|---|
| 168 | // hwndParent: Parent window handle
|
|---|
| 169 | // hwndChild: Child window handle
|
|---|
| 170 | // rectOS2: OS/2 child window RECTL
|
|---|
| 171 | // rectWin32: Win32 Child window RECT (IN)
|
|---|
| 172 | //
|
|---|
| 173 | // Returns:
|
|---|
| 174 | // TRUE: Success
|
|---|
| 175 | // FALSE: Failures
|
|---|
| 176 | //******************************************************************************
|
|---|
| 177 | BOOL MapOS2ToWin32Rectl(HWND hwndParent, HWND hwndChild, PRECTLOS2 rectOS2, PRECT rectWin32)
|
|---|
| 178 | {
|
|---|
| 179 | RECTLOS2 rectParent = {0};
|
|---|
| 180 | Win32BaseWindow *window;
|
|---|
| 181 | LONG height;
|
|---|
| 182 |
|
|---|
| 183 | if(hwndParent == OSLIB_HWND_DESKTOP) {
|
|---|
| 184 | hwndParent = HWND_DESKTOP;
|
|---|
| 185 | }
|
|---|
| 186 | if(WinMapWindowPoints(hwndChild, hwndParent, (PPOINTL)rectOS2, 2) != TRUE) {
|
|---|
| 187 | dprintf(("MapOS2ToWin32Rect:WinMapWindowPoint %x %x returned false", hwndParent, hwndChild));
|
|---|
| 188 | return FALSE;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | if(hwndParent != HWND_DESKTOP)
|
|---|
| 192 | {
|
|---|
| 193 | window = Win32BaseWindow::GetWindowFromOS2FrameHandle(hwndParent);
|
|---|
| 194 | if(window == NULL)
|
|---|
| 195 | return FALSE;
|
|---|
| 196 | height = window->getWindowHeight();
|
|---|
| 197 | }
|
|---|
| 198 | else height = OSLibQueryScreenHeight();
|
|---|
| 199 |
|
|---|
| 200 | rectWin32->bottom = height - rectOS2->yBottom;
|
|---|
| 201 | rectWin32->top = height - rectOS2->yTop;
|
|---|
| 202 | rectWin32->left = rectOS2->xLeft;
|
|---|
| 203 | rectWin32->right = rectOS2->xRight;
|
|---|
| 204 |
|
|---|
| 205 | return TRUE;
|
|---|
| 206 | }
|
|---|
| 207 | //******************************************************************************
|
|---|
| 208 | // MapOS2ToWin32Rectl
|
|---|
| 209 | // Convert OS/2 to Win32 RECTL structure
|
|---|
| 210 | //
|
|---|
| 211 | // Parameters:
|
|---|
| 212 | // hwnd: OS/2 window handle
|
|---|
| 213 | // rectOS2: OS/2 child window RECTL
|
|---|
| 214 | // rectWin32: Win32 Child window RECT (IN)
|
|---|
| 215 | //
|
|---|
| 216 | // Returns:
|
|---|
| 217 | // TRUE: Success
|
|---|
| 218 | // FALSE: Failures
|
|---|
| 219 | //******************************************************************************
|
|---|
| 220 | BOOL MapOS2ToWin32Rectl(HWND hwnd,PRECTLOS2 rectOS2, PRECT rectWin32)
|
|---|
| 221 | {
|
|---|
| 222 | RECTL rect;
|
|---|
| 223 |
|
|---|
| 224 | if (!WinQueryWindowRect(hwnd,&rect)) return FALSE;
|
|---|
| 225 |
|
|---|
| 226 | rectWin32->bottom = rect.yTop-rectOS2->yBottom;
|
|---|
| 227 | rectWin32->top = rect.yTop-rectOS2->yTop;
|
|---|
| 228 | rectWin32->left = rectOS2->xLeft;
|
|---|
| 229 | rectWin32->right = rectOS2->xRight;
|
|---|
| 230 |
|
|---|
| 231 | return TRUE;
|
|---|
| 232 | }
|
|---|
| 233 | //******************************************************************************
|
|---|
| 234 | // MapWin32ToOS2Rectl
|
|---|
| 235 | // Convert Win32 to OS/2 RECTL structure
|
|---|
| 236 | //
|
|---|
| 237 | // Parameters:
|
|---|
| 238 | // hwnd: OS/2 window handle
|
|---|
| 239 | // rectWin32: Win32 Child window RECT (IN)
|
|---|
| 240 | // rectOS2: OS/2 Child window RECTL (OUT)
|
|---|
| 241 | // Returns:
|
|---|
| 242 | // TRUE: Success
|
|---|
| 243 | // FALSE: Failures
|
|---|
| 244 | //******************************************************************************
|
|---|
| 245 | BOOL MapWin32ToOS2Rectl(HWND hwnd,PRECT rectWin32, PRECTLOS2 rectOS2)
|
|---|
| 246 | {
|
|---|
| 247 | RECTL rect;
|
|---|
| 248 |
|
|---|
| 249 | if (!WinQueryWindowRect(hwnd,&rect)) return FALSE;
|
|---|
| 250 |
|
|---|
| 251 | rectOS2->yBottom = rect.yTop-rectWin32->bottom;
|
|---|
| 252 | rectOS2->yTop = rect.yTop-rectWin32->top;
|
|---|
| 253 | rectOS2->xLeft = rectWin32->left;
|
|---|
| 254 | rectOS2->xRight = rectWin32->right;
|
|---|
| 255 |
|
|---|
| 256 | return TRUE;
|
|---|
| 257 | }
|
|---|
| 258 | //******************************************************************************
|
|---|
| 259 | //******************************************************************************
|
|---|
| 260 | BOOL MapOS2ToWin32WindowRect(PRECTLOS2 rectOS2,PRECT rectWin32)
|
|---|
| 261 | {
|
|---|
| 262 | rectWin32->bottom = rectOS2->yTop;
|
|---|
| 263 | rectWin32->top = rectOS2->yBottom;
|
|---|
| 264 | rectWin32->left = rectOS2->xLeft;
|
|---|
| 265 | rectWin32->right = rectOS2->xRight;
|
|---|
| 266 |
|
|---|
| 267 | return TRUE;
|
|---|
| 268 | }
|
|---|
| 269 | //******************************************************************************
|
|---|
| 270 | //******************************************************************************
|
|---|
| 271 | BOOL MapWin32ToOS2WindowRect(PRECT rectWin32,PRECTLOS2 rectOS2)
|
|---|
| 272 | {
|
|---|
| 273 | rectOS2->yBottom = rectWin32->top;
|
|---|
| 274 | rectOS2->yTop = rectWin32->bottom;
|
|---|
| 275 | rectOS2->xLeft = rectWin32->left;
|
|---|
| 276 | rectOS2->xRight = rectWin32->right;
|
|---|
| 277 |
|
|---|
| 278 | return TRUE;
|
|---|
| 279 | }
|
|---|
| 280 | //******************************************************************************
|
|---|
| 281 | //******************************************************************************
|
|---|
| 282 | HDC OSLibWinBeginPaint(HWND hwnd, RECT *rectWin32)
|
|---|
| 283 | {
|
|---|
| 284 | RECTL rectl;
|
|---|
| 285 |
|
|---|
| 286 | if(WinQueryUpdateRect(hwnd, &rectl) == FALSE)
|
|---|
| 287 | {
|
|---|
| 288 | dprintf(("BeginPaint, NO update rectl"));
|
|---|
| 289 | return 0;
|
|---|
| 290 | }
|
|---|
| 291 | MapOS2ToWin32Rectl(hwnd,(RECTLOS2 *)&rectl, rectWin32);
|
|---|
| 292 | return WinBeginPaint(hwnd, NULLHANDLE, &rectl);
|
|---|
| 293 | }
|
|---|
| 294 | //******************************************************************************
|
|---|
| 295 | //******************************************************************************
|
|---|
| 296 | BOOL OSLibWinEndPaint(HDC hdc)
|
|---|
| 297 | {
|
|---|
| 298 | return WinEndPaint((HPS)hdc);
|
|---|
| 299 | }
|
|---|
| 300 | //******************************************************************************
|
|---|
| 301 | //******************************************************************************
|
|---|
| 302 | HDC OSLibWinGetPS(HWND hwnd)
|
|---|
| 303 | {
|
|---|
| 304 | if(hwnd == OSLIB_HWND_DESKTOP)
|
|---|
| 305 | hwnd = HWND_DESKTOP;
|
|---|
| 306 |
|
|---|
| 307 | return (HDC)WinGetPS(hwnd);
|
|---|
| 308 | }
|
|---|
| 309 | //******************************************************************************
|
|---|
| 310 | //******************************************************************************
|
|---|
| 311 | BOOL OSLibWinReleasePS(HDC hdc)
|
|---|
| 312 | {
|
|---|
| 313 | return WinReleasePS((HPS)hdc);
|
|---|
| 314 | }
|
|---|
| 315 | //******************************************************************************
|
|---|
| 316 | //******************************************************************************
|
|---|
| 317 | BOOL OSLibWinInvalidateRect(HWND hwnd, PRECT pRect, BOOL fIncludeChildren)
|
|---|
| 318 | {
|
|---|
| 319 | RECTLOS2 rectl;
|
|---|
| 320 |
|
|---|
| 321 | if(pRect) {
|
|---|
| 322 | MapWin32ToOS2Rectl(hwnd,pRect, &rectl);
|
|---|
| 323 | return WinInvalidateRect(hwnd, (PRECTL)&rectl, fIncludeChildren);
|
|---|
| 324 | }
|
|---|
| 325 | return WinInvalidateRect(hwnd, NULL, fIncludeChildren);
|
|---|
| 326 | }
|
|---|
| 327 | //******************************************************************************
|
|---|
| 328 | //Returns rectangle in Win32 window coordinates
|
|---|
| 329 | //******************************************************************************
|
|---|
| 330 | BOOL OSLibWinQueryUpdateRect(HWND hwnd, PRECT pRect)
|
|---|
| 331 | {
|
|---|
| 332 | BOOL rc;
|
|---|
| 333 | RECTLOS2 rectl;
|
|---|
| 334 |
|
|---|
| 335 | rc = WinQueryUpdateRect(hwnd, (PRECTL)&rectl);
|
|---|
| 336 | if(rc) {
|
|---|
| 337 | MapOS2ToWin32Rectl(hwnd,&rectl, pRect);
|
|---|
| 338 | }
|
|---|
| 339 | else memset(pRect, 0, sizeof(RECT));
|
|---|
| 340 | return rc;
|
|---|
| 341 | }
|
|---|
| 342 | //******************************************************************************
|
|---|
| 343 | //******************************************************************************
|
|---|
| 344 |
|
|---|