| 1 | /* $Id: oslibres.cpp,v 1.15 2001-07-04 09:55:17 sandervl Exp $ */
|
|---|
| 2 | /*
|
|---|
| 3 | * Window API wrappers 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 <os2wrap.h>
|
|---|
| 15 | #include <stdlib.h>
|
|---|
| 16 | #include <string.h>
|
|---|
| 17 |
|
|---|
| 18 | #include <misc.h>
|
|---|
| 19 | #include <winconst.h>
|
|---|
| 20 | #include "oslibwin.h"
|
|---|
| 21 | #include "oslibutil.h"
|
|---|
| 22 | #include "oslibmsg.h"
|
|---|
| 23 | #include "oslibgdi.h"
|
|---|
| 24 | #include "oslibres.h"
|
|---|
| 25 | #include "pmwindow.h"
|
|---|
| 26 |
|
|---|
| 27 | #define DBG_LOCALLOG DBG_oslibres
|
|---|
| 28 | #include "dbglocal.h"
|
|---|
| 29 |
|
|---|
| 30 | //******************************************************************************
|
|---|
| 31 | //******************************************************************************
|
|---|
| 32 | HANDLE OSLibWinSetAccelTable(HWND hwnd, HANDLE hAccel, PVOID acceltemplate)
|
|---|
| 33 | {
|
|---|
| 34 | HAB hab = WinQueryAnchorBlock(hwnd);
|
|---|
| 35 |
|
|---|
| 36 | if(hAccel == 0) {
|
|---|
| 37 | hAccel = WinCreateAccelTable(hab, (PACCELTABLE)acceltemplate);
|
|---|
| 38 | if(hAccel == 0) {
|
|---|
| 39 | dprintf(("OSLibWinSetAccelTable: WinCreateAccelTable returned 0"));
|
|---|
| 40 | return FALSE;
|
|---|
| 41 | }
|
|---|
| 42 | }
|
|---|
| 43 | if(WinSetAccelTable(hab, hAccel, hwnd) == TRUE) {
|
|---|
| 44 | return hAccel;
|
|---|
| 45 | }
|
|---|
| 46 | else return 0;
|
|---|
| 47 | }
|
|---|
| 48 | #if 0
|
|---|
| 49 | //******************************************************************************
|
|---|
| 50 | //TODO: change search method for icon array (cxDesired, cyDesired)
|
|---|
| 51 | //TODO: PM rescales the icon internally!!! ($W(#*&$(*%&)
|
|---|
| 52 | //******************************************************************************
|
|---|
| 53 | HANDLE OSLibWinCreateIcon(PVOID iconbitmap, ULONG cxDesired, ULONG cyDesired)
|
|---|
| 54 | {
|
|---|
| 55 | POINTERINFO pointerInfo = {0};
|
|---|
| 56 | HBITMAP hbmColor, hbmMask;
|
|---|
| 57 | BITMAPARRAYFILEHEADER2 *bafh = (BITMAPARRAYFILEHEADER2 *)iconbitmap;
|
|---|
| 58 | BITMAPFILEHEADER2 *bfhBW;
|
|---|
| 59 | BITMAPFILEHEADER2 *bfhColor;
|
|---|
| 60 | HPS hps;
|
|---|
| 61 | HANDLE hIcon;
|
|---|
| 62 |
|
|---|
| 63 | if(iconbitmap == NULL) {
|
|---|
| 64 | dprintf(("OSLibWinCreateIcon iconbitmap == NULL!!"));
|
|---|
| 65 | return 0;
|
|---|
| 66 | }
|
|---|
| 67 | if(bafh->usType == BFT_BITMAPARRAY && bafh->cbSize == sizeof(BITMAPARRAYFILEHEADER2)) {
|
|---|
| 68 | // search best icon for the current screen,
|
|---|
| 69 | // TODO: maybe compare icon size with screen size.
|
|---|
| 70 | // Some bugs with black/white Icons ?
|
|---|
| 71 | BITMAPARRAYFILEHEADER2 *next, *found;
|
|---|
| 72 | LONG bitcountScreen, bitcountIcon=-1, cxIcon=-1, cyIcon=-1;
|
|---|
| 73 |
|
|---|
| 74 | HPS hps = WinGetPS(HWND_DESKTOP);
|
|---|
| 75 | HDC hdc = GpiQueryDevice(hps);
|
|---|
| 76 | DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, &bitcountScreen);
|
|---|
| 77 | WinReleasePS(hps);
|
|---|
| 78 |
|
|---|
| 79 | next = found = bafh;
|
|---|
| 80 | while(TRUE)
|
|---|
| 81 | {
|
|---|
| 82 | bfhColor = (BITMAPFILEHEADER2 *)((char *)&next->bfh2 + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
|
|---|
| 83 | if(bfhColor->bmp2.cBitCount <= bitcountScreen &&
|
|---|
| 84 | bfhColor->bmp2.cBitCount > bitcountIcon ||
|
|---|
| 85 | (bfhColor->bmp2.cBitCount == bitcountIcon &&
|
|---|
| 86 | (cxIcon < bfhColor->bmp2.cx || cyIcon < bfhColor->bmp2.cy)))
|
|---|
| 87 | {
|
|---|
| 88 | found = next;
|
|---|
| 89 | bitcountIcon = bfhColor->bmp2.cBitCount;
|
|---|
| 90 | cxIcon = bfhColor->bmp2.cx;
|
|---|
| 91 | cyIcon = bfhColor->bmp2.cy;
|
|---|
| 92 | }
|
|---|
| 93 | if(next->offNext != 0)
|
|---|
| 94 | next = (BITMAPARRAYFILEHEADER2 *) ((char *)bafh + next->offNext);
|
|---|
| 95 | else
|
|---|
| 96 | break;
|
|---|
| 97 | }
|
|---|
| 98 | bfhBW = &found->bfh2;
|
|---|
| 99 | bfhColor = (BITMAPFILEHEADER2 *)((char *)bfhBW + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
|
|---|
| 100 | }
|
|---|
| 101 | else {//single icon
|
|---|
| 102 | bfhBW = (BITMAPFILEHEADER2 *)iconbitmap;
|
|---|
| 103 | bfhColor = (BITMAPFILEHEADER2 *)((char *)bfhBW + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
|
|---|
| 104 | bafh = (BITMAPARRAYFILEHEADER2 *)bfhBW; //for calculation bitmap offset
|
|---|
| 105 | }
|
|---|
| 106 | hps = WinGetScreenPS(HWND_DESKTOP);
|
|---|
| 107 |
|
|---|
| 108 | //Resize icon bitmap if requested size is different
|
|---|
| 109 | if(cxDesired != bfhColor->bmp2.cx|| cyDesired != bfhColor->bmp2.cy)
|
|---|
| 110 | {
|
|---|
| 111 | BITMAPINFOHEADER2 infohdr = bfhColor->bmp2;
|
|---|
| 112 |
|
|---|
| 113 | infohdr.cx = cxDesired;
|
|---|
| 114 | infohdr.cy = cyDesired;
|
|---|
| 115 | hbmColor = GpiCreateBitmap(hps, &infohdr, CBM_INIT,
|
|---|
| 116 | (char *)bafh + bfhColor->offBits,
|
|---|
| 117 | (BITMAPINFO2 *)&bfhColor->bmp2);
|
|---|
| 118 | }
|
|---|
| 119 | else {
|
|---|
| 120 | hbmColor = GpiCreateBitmap(hps, &bfhColor->bmp2, CBM_INIT,
|
|---|
| 121 | (char *)bafh + bfhColor->offBits,
|
|---|
| 122 | (BITMAPINFO2 *)&bfhColor->bmp2);
|
|---|
| 123 | }
|
|---|
| 124 | if(hbmColor == GPI_ERROR) {
|
|---|
| 125 | dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
|
|---|
| 126 | WinReleasePS(hps);
|
|---|
| 127 | return 0;
|
|---|
| 128 | }
|
|---|
| 129 | //Resize icon mask if requested size is different
|
|---|
| 130 | if(cxDesired != bfhBW->bmp2.cx|| cyDesired*2 != bfhBW->bmp2.cy)
|
|---|
| 131 | {
|
|---|
| 132 | BITMAPINFOHEADER2 infohdr = bfhBW->bmp2;
|
|---|
| 133 |
|
|---|
| 134 | infohdr.cx = cxDesired;
|
|---|
| 135 | infohdr.cy = cyDesired;
|
|---|
| 136 | hbmMask = GpiCreateBitmap(hps, &infohdr, CBM_INIT,
|
|---|
| 137 | (char *)bafh + bfhBW->offBits,
|
|---|
| 138 | (BITMAPINFO2 *)&bfhBW->bmp2);
|
|---|
| 139 | }
|
|---|
| 140 | else {
|
|---|
| 141 | hbmMask = GpiCreateBitmap(hps, &bfhBW->bmp2, CBM_INIT,
|
|---|
| 142 | (char *)bafh + bfhBW->offBits,
|
|---|
| 143 | (BITMAPINFO2 *)&bfhBW->bmp2);
|
|---|
| 144 | }
|
|---|
| 145 | if(hbmMask == GPI_ERROR) {
|
|---|
| 146 | dprintf(("OSLibWinCreateIcon: GpiCreateBitmap hbmMask failed!"));
|
|---|
| 147 | GpiDeleteBitmap(hbmColor);
|
|---|
| 148 | WinReleasePS(hps);
|
|---|
| 149 | return 0;
|
|---|
| 150 | }
|
|---|
| 151 |
|
|---|
| 152 | pointerInfo.fPointer = FALSE; //icon
|
|---|
| 153 | pointerInfo.xHotspot = bfhBW->xHotspot;
|
|---|
| 154 | pointerInfo.yHotspot = bfhBW->yHotspot;
|
|---|
| 155 | pointerInfo.hbmColor = hbmColor;
|
|---|
| 156 | pointerInfo.hbmPointer = hbmMask;
|
|---|
| 157 | hIcon = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
|
|---|
| 158 | if(hIcon == NULL) {
|
|---|
| 159 | dprintf(("OSLibWinCreateIcon: WinCreatePointerIndirect failed!"));
|
|---|
| 160 | }
|
|---|
| 161 | GpiDeleteBitmap(hbmMask);
|
|---|
| 162 | GpiDeleteBitmap(hbmColor);
|
|---|
| 163 | WinReleasePS(hps);
|
|---|
| 164 |
|
|---|
| 165 | return hIcon;
|
|---|
| 166 | }
|
|---|
| 167 | //******************************************************************************
|
|---|
| 168 | //TODO: change cursor size if required!! (cxDesired, cyDesired)
|
|---|
| 169 | //******************************************************************************
|
|---|
| 170 | HANDLE OSLibWinCreatePointer(PVOID cursorbitmap, ULONG cxDesired, ULONG cyDesired)
|
|---|
| 171 | {
|
|---|
| 172 | POINTERINFO pointerInfo = {0};
|
|---|
| 173 | HBITMAP hbmColor = 0, hbmMask = 0;
|
|---|
| 174 | BITMAPARRAYFILEHEADER2 *bafh = (BITMAPARRAYFILEHEADER2 *)cursorbitmap;
|
|---|
| 175 | BITMAPFILEHEADER2 *bfh = (BITMAPFILEHEADER2 *)cursorbitmap, *bfhColor = 0;
|
|---|
| 176 | HPS hps;
|
|---|
| 177 | HANDLE hPointer;
|
|---|
| 178 |
|
|---|
| 179 | if(cursorbitmap == NULL) {
|
|---|
| 180 | dprintf(("OSLibWinCreatePointer cursorbitmap == NULL!!"));
|
|---|
| 181 | return 0;
|
|---|
| 182 | }
|
|---|
| 183 | if(bafh->usType == BFT_BITMAPARRAY && bafh->cbSize == sizeof(BITMAPARRAYFILEHEADER2)) {
|
|---|
| 184 | bfh = &bafh->bfh2;
|
|---|
| 185 | bfhColor = (BITMAPFILEHEADER2 *)((char *)bfh + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
|
|---|
| 186 | }
|
|---|
| 187 | else {//single cursor
|
|---|
| 188 | bfh = (BITMAPFILEHEADER2 *)cursorbitmap;
|
|---|
| 189 | bfhColor = (BITMAPFILEHEADER2 *)((char *)bfh + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
|
|---|
| 190 | bafh = (BITMAPARRAYFILEHEADER2 *)bfh; //for calculation bitmap offset
|
|---|
| 191 | }
|
|---|
| 192 | //skip xor/and mask
|
|---|
| 193 | hps = WinGetScreenPS(HWND_DESKTOP);
|
|---|
| 194 | hbmMask = GpiCreateBitmap(hps, &bfh->bmp2, CBM_INIT,
|
|---|
| 195 | (char *)bafh + bfh->offBits,
|
|---|
| 196 | (BITMAPINFO2 *)&bfh->bmp2);
|
|---|
| 197 | if(hbmMask == GPI_ERROR) {
|
|---|
| 198 | dprintf(("OSLibWinCreatePointer: GpiCreateBitmap failed!"));
|
|---|
| 199 | WinReleasePS(hps);
|
|---|
| 200 | return 0;
|
|---|
| 201 | }
|
|---|
| 202 |
|
|---|
| 203 | if((ULONG)((char *)bafh+bfh->offBits) != (ULONG)bfhColor)
|
|---|
| 204 | {//color bitmap present
|
|---|
| 205 | hbmColor = GpiCreateBitmap(hps, &bfhColor->bmp2, CBM_INIT,
|
|---|
| 206 | (char *)bafh + bfhColor->offBits,
|
|---|
| 207 | (BITMAPINFO2 *)&bfhColor->bmp2);
|
|---|
| 208 | if(hbmColor == GPI_ERROR) {
|
|---|
| 209 | dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
|
|---|
| 210 | GpiDeleteBitmap(hbmMask);
|
|---|
| 211 | WinReleasePS(hps);
|
|---|
| 212 | return 0;
|
|---|
| 213 | }
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | pointerInfo.fPointer = TRUE;
|
|---|
| 217 | pointerInfo.xHotspot = bfh->xHotspot;
|
|---|
| 218 | pointerInfo.yHotspot = bfh->yHotspot;
|
|---|
| 219 | pointerInfo.hbmColor = hbmColor;
|
|---|
| 220 | pointerInfo.hbmPointer = hbmMask;
|
|---|
| 221 | hPointer = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
|
|---|
| 222 |
|
|---|
| 223 | if(hPointer == NULL) {
|
|---|
| 224 | dprintf(("OSLibWinCreatePointer: WinCreatePointerIndirect failed!"));
|
|---|
| 225 | }
|
|---|
| 226 | GpiDeleteBitmap(hbmMask);
|
|---|
| 227 | if(hbmColor) GpiDeleteBitmap(hbmColor);
|
|---|
| 228 | WinReleasePS(hps);
|
|---|
| 229 | return hPointer;
|
|---|
| 230 | }
|
|---|
| 231 | #endif
|
|---|
| 232 | //******************************************************************************
|
|---|
| 233 | //NOTE: Depends on origin of bitmap data!!!
|
|---|
| 234 | // Assumes 1 bpp bitmaps have a top left origin and all others have a bottom left origin
|
|---|
| 235 | //******************************************************************************
|
|---|
| 236 | HANDLE OSLibWinCreatePointer(CURSORICONINFO *pInfo, char *pAndBits, BITMAP_W *pAndBmp, char *pXorBits,
|
|---|
| 237 | BITMAP_W *pXorBmp, BOOL fCursor)
|
|---|
| 238 | {
|
|---|
| 239 | POINTERINFO pointerInfo = {0};
|
|---|
| 240 | HANDLE hPointer;
|
|---|
| 241 | HBITMAP hbmColor = 0, hbmMask = 0;
|
|---|
| 242 | BITMAPINFO2 *pBmpColor, *pBmpMask;
|
|---|
| 243 | int masksize, colorsize, rgbsize, i;
|
|---|
| 244 | HPS hps;
|
|---|
| 245 | char *dest, *src;
|
|---|
| 246 |
|
|---|
| 247 | hps = WinGetScreenPS(HWND_DESKTOP);
|
|---|
| 248 | masksize = sizeof(BITMAPINFO2) + (pAndBmp->bmHeight * 2 * pAndBmp->bmWidthBytes) + 2*sizeof(RGB2);
|
|---|
| 249 | pBmpMask = (BITMAPINFO2 *)malloc(masksize);
|
|---|
| 250 | if(pBmpMask == NULL) {
|
|---|
| 251 | DebugInt3();
|
|---|
| 252 | return 0;
|
|---|
| 253 | }
|
|---|
| 254 | memset(pBmpMask, 0, masksize);
|
|---|
| 255 | pBmpMask->cbFix = sizeof(BITMAPINFOHEADER2);
|
|---|
| 256 | pBmpMask->cx = (USHORT)pAndBmp->bmWidth;
|
|---|
| 257 | pBmpMask->cy = (USHORT)pAndBmp->bmHeight*2;
|
|---|
| 258 | pBmpMask->cPlanes = pAndBmp->bmPlanes;
|
|---|
| 259 | pBmpMask->cBitCount = 1;
|
|---|
| 260 | pBmpMask->ulCompression = BCA_UNCOMP;
|
|---|
| 261 | pBmpMask->ulColorEncoding = BCE_RGB;
|
|---|
| 262 | memset(&pBmpMask->argbColor[0], 0, sizeof(RGB2));
|
|---|
| 263 | memset(&pBmpMask->argbColor[1], 0xff, sizeof(RGB)); //not the reserved byte
|
|---|
| 264 | //Xor bits are already 0
|
|---|
| 265 | //copy And bits (must reverse scanlines because origin is top left instead of bottom left)
|
|---|
| 266 | src = pAndBits;
|
|---|
| 267 | dest = ((char *)&pBmpMask->argbColor[2]) + (pAndBmp->bmHeight * 2 - 1) * (pAndBmp->bmWidthBytes);
|
|---|
| 268 | for(i=0;i<pAndBmp->bmHeight;i++) {
|
|---|
| 269 | memcpy(dest, src, pAndBmp->bmWidthBytes);
|
|---|
| 270 | dest -= pAndBmp->bmWidthBytes;
|
|---|
| 271 | src += pAndBmp->bmWidthBytes;
|
|---|
| 272 | }
|
|---|
| 273 | hbmMask = GpiCreateBitmap(hps, (BITMAPINFOHEADER2 *)pBmpMask, CBM_INIT,
|
|---|
| 274 | (PBYTE)&pBmpMask->argbColor[2], pBmpMask);
|
|---|
| 275 |
|
|---|
| 276 | if(hbmMask == GPI_ERROR) {
|
|---|
| 277 | dprintf(("OSLibWinCreatePointer: GpiCreateBitmap failed!"));
|
|---|
| 278 | WinReleasePS(hps);
|
|---|
| 279 | free(pBmpMask);
|
|---|
| 280 | return 0;
|
|---|
| 281 | }
|
|---|
| 282 | if(pXorBits)
|
|---|
| 283 | {//color bitmap present
|
|---|
| 284 | RGBQUAD *rgb;
|
|---|
| 285 | RGB2 *os2rgb;
|
|---|
| 286 |
|
|---|
| 287 | if(pXorBmp->bmBitsPixel <= 8)
|
|---|
| 288 | rgbsize = (1<<pXorBmp->bmBitsPixel)*sizeof(RGB2);
|
|---|
| 289 | else rgbsize = 0;
|
|---|
| 290 |
|
|---|
| 291 | colorsize = sizeof(BITMAPINFO2) + (pXorBmp->bmHeight * pXorBmp->bmWidthBytes) + rgbsize;
|
|---|
| 292 | pBmpColor = (BITMAPINFO2 *)malloc(colorsize);
|
|---|
| 293 | if(pBmpColor == NULL) {
|
|---|
| 294 | DebugInt3();
|
|---|
| 295 | return 0;
|
|---|
| 296 | }
|
|---|
| 297 | memset(pBmpColor, 0, colorsize);
|
|---|
| 298 | pBmpColor->cbFix = sizeof(BITMAPINFOHEADER2);
|
|---|
| 299 | pBmpColor->cx = (USHORT)pXorBmp->bmWidth;
|
|---|
| 300 | pBmpColor->cy = (USHORT)pXorBmp->bmHeight;
|
|---|
| 301 | pBmpColor->cPlanes = pXorBmp->bmPlanes;
|
|---|
| 302 | pBmpColor->cBitCount = pXorBmp->bmBitsPixel;
|
|---|
| 303 | pBmpColor->ulCompression = BCA_UNCOMP;
|
|---|
| 304 | pBmpColor->ulColorEncoding = BCE_RGB;
|
|---|
| 305 |
|
|---|
| 306 | os2rgb = &pBmpColor->argbColor[0];
|
|---|
| 307 | rgb = (RGBQUAD *)(pXorBits);
|
|---|
| 308 |
|
|---|
| 309 | if(pXorBmp->bmBitsPixel <= 8) {
|
|---|
| 310 | for(i=0;i<(1<<pXorBmp->bmBitsPixel);i++) {
|
|---|
| 311 | os2rgb->bRed = rgb->rgbRed;
|
|---|
| 312 | os2rgb->bBlue = rgb->rgbBlue;
|
|---|
| 313 | os2rgb->bGreen = rgb->rgbGreen;
|
|---|
| 314 | os2rgb++;
|
|---|
| 315 | rgb++;
|
|---|
| 316 | }
|
|---|
| 317 | }
|
|---|
| 318 |
|
|---|
| 319 | if(pXorBmp->bmBitsPixel == 1) {
|
|---|
| 320 | //copy Xor bits (must reverse scanlines because origin is top left instead of bottom left)
|
|---|
| 321 | src = (char *)rgb;
|
|---|
| 322 | dest = ((char *)os2rgb) + (pXorBmp->bmHeight - 1) * pXorBmp->bmWidthBytes;
|
|---|
| 323 | for(i=0;i<pXorBmp->bmHeight;i++) {
|
|---|
| 324 | memcpy(dest, src, pXorBmp->bmWidthBytes);
|
|---|
| 325 | dest -= pXorBmp->bmWidthBytes;
|
|---|
| 326 | src += pXorBmp->bmWidthBytes;
|
|---|
| 327 | }
|
|---|
| 328 | }
|
|---|
| 329 | else memcpy(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes);
|
|---|
| 330 |
|
|---|
| 331 | hbmColor = GpiCreateBitmap(hps, (BITMAPINFOHEADER2 *)pBmpColor, CBM_INIT,
|
|---|
| 332 | (PBYTE)os2rgb, pBmpColor);
|
|---|
| 333 |
|
|---|
| 334 | if(hbmColor == GPI_ERROR) {
|
|---|
| 335 | dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
|
|---|
| 336 | GpiDeleteBitmap(hbmMask);
|
|---|
| 337 | WinReleasePS(hps);
|
|---|
| 338 | free(pBmpMask);
|
|---|
| 339 | return 0;
|
|---|
| 340 | }
|
|---|
| 341 | }
|
|---|
| 342 |
|
|---|
| 343 | pointerInfo.fPointer = fCursor; //FALSE = icon
|
|---|
| 344 | pointerInfo.xHotspot = pInfo->ptHotSpot.x;
|
|---|
| 345 | pointerInfo.yHotspot = mapY(pInfo->nHeight, pInfo->ptHotSpot.y);
|
|---|
| 346 | pointerInfo.hbmColor = hbmColor;
|
|---|
| 347 | pointerInfo.hbmPointer = hbmMask;
|
|---|
| 348 | hPointer = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
|
|---|
| 349 |
|
|---|
| 350 | if(hPointer == NULL) {
|
|---|
| 351 | dprintf(("OSLibWinCreateCursor: WinCreatePointerIndirect failed! (lasterr=%x)", WinGetLastError(GetThreadHAB())));
|
|---|
| 352 | }
|
|---|
| 353 | GpiDeleteBitmap(hbmMask);
|
|---|
| 354 | if(hbmColor) GpiDeleteBitmap(hbmColor);
|
|---|
| 355 | WinReleasePS(hps);
|
|---|
| 356 |
|
|---|
| 357 | free(pBmpMask);
|
|---|
| 358 | free(pBmpColor);
|
|---|
| 359 | return hPointer;
|
|---|
| 360 | }
|
|---|
| 361 | //******************************************************************************
|
|---|
| 362 | //******************************************************************************
|
|---|
| 363 | HANDLE OSLibWinQuerySysIcon(ULONG type,INT w,INT h)
|
|---|
| 364 | {
|
|---|
| 365 | ULONG os2type = 0;
|
|---|
| 366 | HPOINTER hPointer;
|
|---|
| 367 |
|
|---|
| 368 | switch(type) {
|
|---|
| 369 | case IDI_APPLICATION_W:
|
|---|
| 370 | os2type = SPTR_PROGRAM;
|
|---|
| 371 | break;
|
|---|
| 372 | case IDI_HAND_W:
|
|---|
| 373 | os2type = SPTR_ICONWARNING;
|
|---|
| 374 | break;
|
|---|
| 375 | case IDI_QUESTION_W:
|
|---|
| 376 | os2type = SPTR_ICONQUESTION;
|
|---|
| 377 | break;
|
|---|
| 378 | case IDI_EXCLAMATION_W:
|
|---|
| 379 | os2type = SPTR_ICONWARNING;
|
|---|
| 380 | break;
|
|---|
| 381 | case IDI_ASTERISK_W:
|
|---|
| 382 | os2type = SPTR_ICONINFORMATION;
|
|---|
| 383 | break;
|
|---|
| 384 | default:
|
|---|
| 385 | return 0;
|
|---|
| 386 | }
|
|---|
| 387 |
|
|---|
| 388 | hPointer = WinQuerySysPointer(HWND_DESKTOP, os2type, TRUE);
|
|---|
| 389 |
|
|---|
| 390 | if (hPointer)
|
|---|
| 391 | {
|
|---|
| 392 | INT sysW = WinQuerySysValue(HWND_DESKTOP,SV_CXICON),sysH = WinQuerySysValue(HWND_DESKTOP,SV_CYICON);
|
|---|
| 393 |
|
|---|
| 394 | if (sysW != w || sysH != h)
|
|---|
| 395 | {
|
|---|
| 396 | POINTERINFO pi;
|
|---|
| 397 |
|
|---|
| 398 | WinQueryPointerInfo(hPointer,&pi);
|
|---|
| 399 | //CB: todo: change icon size
|
|---|
| 400 |
|
|---|
| 401 | }
|
|---|
| 402 | }
|
|---|
| 403 |
|
|---|
| 404 | return hPointer;
|
|---|
| 405 | }
|
|---|
| 406 | //******************************************************************************
|
|---|
| 407 | //******************************************************************************
|
|---|
| 408 | HANDLE OSLibWinQuerySysPointer(ULONG type,INT w,INT h)
|
|---|
| 409 | {
|
|---|
| 410 | ULONG os2type = 0;
|
|---|
| 411 |
|
|---|
| 412 | switch(type) {
|
|---|
| 413 | case IDC_ARROW_W:
|
|---|
| 414 | os2type = SPTR_ARROW;
|
|---|
| 415 | break;
|
|---|
| 416 | case IDC_UPARROW_W:
|
|---|
| 417 | os2type = SPTR_ARROW;
|
|---|
| 418 | break;
|
|---|
| 419 | case IDC_IBEAM_W:
|
|---|
| 420 | os2type = SPTR_TEXT;
|
|---|
| 421 | break;
|
|---|
| 422 | case IDC_ICON_W:
|
|---|
| 423 | os2type = SPTR_PROGRAM;
|
|---|
| 424 | break;
|
|---|
| 425 | case IDC_NO_W:
|
|---|
| 426 | os2type = SPTR_ILLEGAL;
|
|---|
| 427 | break;
|
|---|
| 428 | case IDC_CROSS_W:
|
|---|
| 429 | os2type = SPTR_MOVE;
|
|---|
| 430 | break;
|
|---|
| 431 | case IDC_SIZE_W:
|
|---|
| 432 | os2type = SPTR_MOVE;
|
|---|
| 433 | break;
|
|---|
| 434 | case IDC_SIZEALL_W:
|
|---|
| 435 | os2type = SPTR_MOVE;
|
|---|
| 436 | break;
|
|---|
| 437 | case IDC_SIZENESW_W:
|
|---|
| 438 | os2type = SPTR_SIZENESW;
|
|---|
| 439 | break;
|
|---|
| 440 | case IDC_SIZENS_W:
|
|---|
| 441 | os2type = SPTR_SIZENS;
|
|---|
| 442 | break;
|
|---|
| 443 | case IDC_SIZENWSE_W:
|
|---|
| 444 | os2type = SPTR_SIZENWSE;
|
|---|
| 445 | break;
|
|---|
| 446 | case IDC_SIZEWE_W:
|
|---|
| 447 | os2type = SPTR_SIZEWE;
|
|---|
| 448 | break;
|
|---|
| 449 | case IDC_WAIT_W:
|
|---|
| 450 | os2type = SPTR_WAIT;
|
|---|
| 451 | break;
|
|---|
| 452 | case IDC_APPSTARTING_W:
|
|---|
| 453 | os2type = SPTR_WAIT;
|
|---|
| 454 | break;
|
|---|
| 455 | case IDC_HELP_W: //TODO: Create a cursor for this one
|
|---|
| 456 | os2type = SPTR_WAIT;
|
|---|
| 457 | break;
|
|---|
| 458 | default:
|
|---|
| 459 | return 0;
|
|---|
| 460 | }
|
|---|
| 461 | //Note: Does not create a copy
|
|---|
| 462 | return WinQuerySysPointer(HWND_DESKTOP, os2type, FALSE);
|
|---|
| 463 | }
|
|---|
| 464 | //******************************************************************************
|
|---|
| 465 | //******************************************************************************
|
|---|
| 466 | VOID OSLibWinDestroyPointer(HANDLE hPointer)
|
|---|
| 467 | {
|
|---|
| 468 | WinDestroyPointer(hPointer);
|
|---|
| 469 | }
|
|---|
| 470 | //******************************************************************************
|
|---|
| 471 | //******************************************************************************
|
|---|
| 472 | BOOL OSLibWinSetPointer(HANDLE hPointer)
|
|---|
| 473 | {
|
|---|
| 474 | return WinSetPointer(HWND_DESKTOP, hPointer);
|
|---|
| 475 | }
|
|---|
| 476 | //******************************************************************************
|
|---|
| 477 | //******************************************************************************
|
|---|
| 478 | HANDLE OSLibWinQueryPointer()
|
|---|
| 479 | {
|
|---|
| 480 | return WinQueryPointer(HWND_DESKTOP);
|
|---|
| 481 | }
|
|---|
| 482 | //******************************************************************************
|
|---|
| 483 | //******************************************************************************
|
|---|
| 484 | BOOL OSLibWinClipCursor(const RECT * pRect)
|
|---|
| 485 | {
|
|---|
| 486 | RECTL rectl;
|
|---|
| 487 | PRECTL ptr = NULL;
|
|---|
| 488 |
|
|---|
| 489 | if (pRect != NULL)
|
|---|
| 490 | {
|
|---|
| 491 | rectl.xLeft = max(pRect->left, 0);
|
|---|
| 492 | rectl.xRight = min(pRect->right, ScreenWidth-1);
|
|---|
| 493 | rectl.yBottom = max(ScreenHeight - pRect->bottom, 0);
|
|---|
| 494 | rectl.yTop = min(ScreenHeight - pRect->top, ScreenHeight-1);
|
|---|
| 495 | ptr = &rectl;
|
|---|
| 496 | }
|
|---|
| 497 | return WinSetPointerClipRect (HWND_DESKTOP, ptr);
|
|---|
| 498 | }
|
|---|
| 499 | //******************************************************************************
|
|---|
| 500 | //******************************************************************************
|
|---|
| 501 | BOOL OSLibWinGetClipCursor(LPRECT pRect)
|
|---|
| 502 | {
|
|---|
| 503 | RECTL rectl;
|
|---|
| 504 |
|
|---|
| 505 | if (WinQueryPointerClipRect(HWND_DESKTOP, &rectl))
|
|---|
| 506 | {
|
|---|
| 507 | pRect->left = rectl.xLeft;
|
|---|
| 508 | pRect->right = rectl.xRight;
|
|---|
| 509 | pRect->bottom = ScreenHeight - rectl.yBottom;
|
|---|
| 510 | pRect->top = ScreenHeight - rectl.yTop;
|
|---|
| 511 | return TRUE;
|
|---|
| 512 | }
|
|---|
| 513 | return FALSE;
|
|---|
| 514 | }
|
|---|
| 515 | //******************************************************************************
|
|---|
| 516 | //******************************************************************************
|
|---|