| 1 | /* $Id: oslibgdi.cpp,v 1.2 1999-07-18 14:39:35 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 |
|
|---|
| 22 | //******************************************************************************
|
|---|
| 23 | //******************************************************************************
|
|---|
| 24 | inline PRECTL Win32ToOS2Rect(PVOID pRectl)
|
|---|
| 25 | {
|
|---|
| 26 | PRECTL pWinRect = (PRECTL)pRectl;
|
|---|
| 27 | ULONG tmp;
|
|---|
| 28 |
|
|---|
| 29 | tmp = pWinRect->yBottom;
|
|---|
| 30 | pWinRect->yBottom = pWinRect->yTop;
|
|---|
| 31 | pWinRect->yTop = tmp;
|
|---|
| 32 | return pWinRect;
|
|---|
| 33 | }
|
|---|
| 34 | //******************************************************************************
|
|---|
| 35 | //******************************************************************************
|
|---|
| 36 | inline ULONG MAPWIN32POINT(RECTLOS2 *parent, RECTLOS2 *child, ULONG y)
|
|---|
| 37 | {
|
|---|
| 38 | return (parent->yTop - parent->yBottom - (child->yTop - child->yBottom) - y - 1);
|
|---|
| 39 | }
|
|---|
| 40 | //******************************************************************************
|
|---|
| 41 | //******************************************************************************
|
|---|
| 42 | inline ULONG MAPWIN32POINT(RECTLOS2 *parent, ULONG cy, ULONG y)
|
|---|
| 43 | {
|
|---|
| 44 | return (parent->yTop - parent->yBottom - cy - y - 1);
|
|---|
| 45 | }
|
|---|
| 46 | //******************************************************************************
|
|---|
| 47 | //******************************************************************************
|
|---|
| 48 | ULONG MapOS2ToWin32Y(HWND hwndChild)
|
|---|
| 49 | {
|
|---|
| 50 | HWND hwndParent;
|
|---|
| 51 | RECTLOS2 rectParent = {0}, rectChild = {0};
|
|---|
| 52 |
|
|---|
| 53 | WinQueryWindowRect(hwndChild, (PRECTL)&rectChild);
|
|---|
| 54 | hwndParent = WinQueryWindow(hwndChild, QW_PARENT);
|
|---|
| 55 | WinQueryWindowRect(hwndParent, (PRECTL)&rectParent);
|
|---|
| 56 | return MAPWIN32POINT(&rectParent, &rectChild, rectChild.yBottom);
|
|---|
| 57 | }
|
|---|
| 58 | //******************************************************************************
|
|---|
| 59 | //******************************************************************************
|
|---|
| 60 | ULONG MapOS2ToWin32Y(HWND hwndChild, ULONG y)
|
|---|
| 61 | {
|
|---|
| 62 | HWND hwndParent;
|
|---|
| 63 | RECTLOS2 rectParent = {0}, rectChild = {0};
|
|---|
| 64 |
|
|---|
| 65 | WinQueryWindowRect(hwndChild, (PRECTL)&rectChild);
|
|---|
| 66 | hwndParent = WinQueryWindow(hwndChild, QW_PARENT);
|
|---|
| 67 | WinQueryWindowRect(hwndParent, (PRECTL)&rectParent);
|
|---|
| 68 | return MAPWIN32POINT(&rectParent, &rectChild, y);
|
|---|
| 69 | }
|
|---|
| 70 | //******************************************************************************
|
|---|
| 71 | //******************************************************************************
|
|---|
| 72 | ULONG MapOS2ToWin32Y(HWND hwndChild, ULONG cy, ULONG y)
|
|---|
| 73 | {
|
|---|
| 74 | HWND hwndParent;
|
|---|
| 75 | RECTLOS2 rectParent = {0};
|
|---|
| 76 |
|
|---|
| 77 | hwndParent = WinQueryWindow(hwndChild, QW_PARENT);
|
|---|
| 78 | WinQueryWindowRect(hwndParent, (PRECTL)&rectParent);
|
|---|
| 79 | return MAPWIN32POINT(&rectParent, cy, y);
|
|---|
| 80 | }
|
|---|
| 81 | //******************************************************************************
|
|---|
| 82 | //******************************************************************************
|
|---|
| 83 | ULONG MapOS2ToWin32Y(PRECTLOS2 rectParent, PRECTLOS2 rectChild, ULONG y)
|
|---|
| 84 | {
|
|---|
| 85 | return MAPWIN32POINT(rectParent, rectChild, y);
|
|---|
| 86 | }
|
|---|
| 87 | //******************************************************************************
|
|---|
| 88 | //******************************************************************************
|
|---|
| 89 | ULONG MapOS2ToWin32Y(PRECTLOS2 rectParent, HWND hwndChild, ULONG y)
|
|---|
| 90 | {
|
|---|
| 91 | RECTLOS2 rectChild = {0};
|
|---|
| 92 |
|
|---|
| 93 | WinQueryWindowRect(hwndChild, (PRECTL)&rectChild);
|
|---|
| 94 | return MAPWIN32POINT(rectParent, &rectChild, y);
|
|---|
| 95 | }
|
|---|
| 96 | //******************************************************************************
|
|---|
| 97 | //******************************************************************************
|
|---|
| 98 | ULONG MapOS2ToWin32Y(HWND hwndChild, PRECTLOS2 rectChild, ULONG y)
|
|---|
| 99 | {
|
|---|
| 100 | HWND hwndParent;
|
|---|
| 101 | RECTLOS2 rectParent = {0};
|
|---|
| 102 |
|
|---|
| 103 | hwndParent = WinQueryWindow(hwndChild, QW_PARENT);
|
|---|
| 104 | WinQueryWindowRect(hwndParent, (PRECTL)&rectParent);
|
|---|
| 105 | return MAPWIN32POINT(&rectParent, rectChild, y);
|
|---|
| 106 | }
|
|---|
| 107 | //******************************************************************************
|
|---|
| 108 | // MapOS2ToWin32Rectl
|
|---|
| 109 | // Convert OS/2 to Win32 RECTL structure
|
|---|
| 110 | //
|
|---|
| 111 | // Parameters:
|
|---|
| 112 | // hwndChild: Child window handle
|
|---|
| 113 | // rectChild: OS/2 child window RECTL
|
|---|
| 114 | //
|
|---|
| 115 | // Returns:
|
|---|
| 116 | // rectChild: Converted OS/2 rectange stored in Win32 RECTL (yTop & yBottom reversed)
|
|---|
| 117 | // TRUE: Success
|
|---|
| 118 | // FALSE: Failures
|
|---|
| 119 | //******************************************************************************
|
|---|
| 120 | BOOL MapOS2ToWin32Rectl(HWND hwndChild, PRECTLOS2 rectChild, PRECT rectWin32)
|
|---|
| 121 | {
|
|---|
| 122 | HWND hwndParent;
|
|---|
| 123 | RECTLOS2 rectParent = {0};
|
|---|
| 124 |
|
|---|
| 125 | hwndParent = WinQueryWindow(hwndChild, QW_PARENT);
|
|---|
| 126 | WinQueryWindowRect(hwndParent, (PRECTL)&rectParent);
|
|---|
| 127 |
|
|---|
| 128 | rectWin32->yTop = MAPWIN32POINT(&rectParent, rectChild->yTop - rectChild->yBottom, rectChild->yBottom);
|
|---|
| 129 | rectWin32->yBottom = MAPWIN32POINT(&rectParent, rectChild->yTop - rectChild->yBottom, rectChild->yTop);
|
|---|
| 130 | rectWin32->xLeft = rectChild->xLeft;
|
|---|
| 131 | rectWin32->xRight = rectChild->xRight;
|
|---|
| 132 | return TRUE;
|
|---|
| 133 | }
|
|---|
| 134 | //******************************************************************************
|
|---|
| 135 | // MapOS2ToWin32Rectl
|
|---|
| 136 | // Convert OS/2 to Win32 RECTL structure
|
|---|
| 137 | //
|
|---|
| 138 | // Parameters:
|
|---|
| 139 | // rectParent: OS/2 Parent window RECTL
|
|---|
| 140 | // rectChild: OS/2 Child window RECTL
|
|---|
| 141 | //
|
|---|
| 142 | // Returns:
|
|---|
| 143 | // rectChild: Converted OS/2 rectange stored in Win32 RECTL (yTop & yBottom reversed)
|
|---|
| 144 | // TRUE: Success
|
|---|
| 145 | // FALSE: Failures
|
|---|
| 146 | //******************************************************************************
|
|---|
| 147 | BOOL MapOS2ToWin32Rectl(PRECTLOS2 rectParent, PRECTLOS2 rectChild, PRECT rectWin32)
|
|---|
| 148 | {
|
|---|
| 149 | rectWin32->yTop = MAPWIN32POINT(rectParent, rectChild->yTop - rectChild->yBottom, rectChild->yBottom);
|
|---|
| 150 | rectWin32->yBottom = MAPWIN32POINT(rectParent, rectChild->yTop - rectChild->yBottom, rectChild->yTop);
|
|---|
| 151 | rectWin32->xLeft = rectChild->xLeft;
|
|---|
| 152 | rectWin32->xRight = rectChild->xRight;
|
|---|
| 153 | return TRUE;
|
|---|
| 154 | }
|
|---|
| 155 | //******************************************************************************
|
|---|
| 156 | // MapWin32ToOS2Rectl
|
|---|
| 157 | // Convert Win32 to OS/2 RECTL structure
|
|---|
| 158 | //
|
|---|
| 159 | // Parameters:
|
|---|
| 160 | // hwndChild: OS/2 Child window handle (IN)
|
|---|
| 161 | // rectWin32: Win32 Child window RECT (IN)
|
|---|
| 162 | // rectChild: OS/2 Child window RECTL (OUT)
|
|---|
| 163 | // Returns:
|
|---|
| 164 | // TRUE: Success
|
|---|
| 165 | // FALSE: Failures
|
|---|
| 166 | //******************************************************************************
|
|---|
| 167 | BOOL MapWin32ToOS2Rectl(HWND hwndChild, PRECT rectWin32, PRECTLOS2 rectChild)
|
|---|
| 168 | {
|
|---|
| 169 | HWND hwndParent;
|
|---|
| 170 | RECTLOS2 rectParent = {0};
|
|---|
| 171 |
|
|---|
| 172 | hwndParent = WinQueryWindow(hwndChild, QW_PARENT);
|
|---|
| 173 | WinQueryWindowRect(hwndParent, (PRECTL)&rectParent);
|
|---|
| 174 |
|
|---|
| 175 | rectChild->yTop = MAPWIN32POINT(&rectParent, rectWin32->yBottom - rectWin32->yTop, rectWin32->yBottom);
|
|---|
| 176 | rectChild->yBottom = MAPWIN32POINT(&rectParent, rectWin32->yBottom - rectWin32->yTop, rectWin32->yTop);
|
|---|
| 177 | rectChild->xLeft = rectWin32->xLeft;
|
|---|
| 178 | rectChild->xRight = rectWin32->xRight;
|
|---|
| 179 | return TRUE;
|
|---|
| 180 | }
|
|---|
| 181 | //******************************************************************************
|
|---|
| 182 | // MapWin32ToOS2Rectl
|
|---|
| 183 | // Convert Win32 to OS/2 RECTL structure
|
|---|
| 184 | //
|
|---|
| 185 | // Parameters:
|
|---|
| 186 | // rectParent: OS/2 Parent window RECTL (IN)
|
|---|
| 187 | // rectWin32: Win32 Child window RECT (IN)
|
|---|
| 188 | // rectChild: OS/2 Child window RECTL (OUT)
|
|---|
| 189 | // Returns:
|
|---|
| 190 | // TRUE: Success
|
|---|
| 191 | // FALSE: Failures
|
|---|
| 192 | //******************************************************************************
|
|---|
| 193 | BOOL MapWin32ToOS2Rectl(PRECTLOS2 rectParent, PRECT rectWin32, PRECTLOS2 rectChild)
|
|---|
| 194 | {
|
|---|
| 195 | rectChild->yTop = MAPWIN32POINT(rectParent, rectWin32->yBottom - rectWin32->yTop, rectWin32->yBottom);
|
|---|
| 196 | rectChild->yBottom = MAPWIN32POINT(rectParent, rectWin32->yBottom - rectWin32->yTop, rectWin32->yTop);
|
|---|
| 197 | rectChild->xLeft = rectWin32->xLeft;
|
|---|
| 198 | rectChild->xRight = rectWin32->xRight;
|
|---|
| 199 | return TRUE;
|
|---|
| 200 | }
|
|---|
| 201 | //******************************************************************************
|
|---|
| 202 | //******************************************************************************
|
|---|
| 203 | HDC OSLibWinBeginPaint(HWND hwnd, PVOID pRectl)
|
|---|
| 204 | {
|
|---|
| 205 | RECTLOS2 rectlOS2;
|
|---|
| 206 |
|
|---|
| 207 | MapWin32ToOS2Rectl(hwnd, (PRECT)pRectl, &rectlOS2);
|
|---|
| 208 | return WinBeginPaint(hwnd, NULLHANDLE, (PRECTL)&rectlOS2);
|
|---|
| 209 | }
|
|---|
| 210 | //******************************************************************************
|
|---|
| 211 | //******************************************************************************
|
|---|
| 212 | BOOL OSLibWinEndPaint(HDC hdc)
|
|---|
| 213 | {
|
|---|
| 214 | return WinEndPaint((HPS)hdc);
|
|---|
| 215 | }
|
|---|
| 216 | //******************************************************************************
|
|---|
| 217 | //******************************************************************************
|
|---|
| 218 | HDC OSLibWinGetPS(HWND hwnd)
|
|---|
| 219 | {
|
|---|
| 220 | return (HDC)WinGetPS(hwnd);
|
|---|
| 221 | }
|
|---|
| 222 | //******************************************************************************
|
|---|
| 223 | //******************************************************************************
|
|---|
| 224 | BOOL OSLibWinReleasePS(HDC hdc)
|
|---|
| 225 | {
|
|---|
| 226 | return WinReleasePS((HPS)hdc);
|
|---|
| 227 | }
|
|---|
| 228 | //******************************************************************************
|
|---|
| 229 | //******************************************************************************
|
|---|