source: trunk/src/user32/oslibres.cpp

Last change on this file was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

File size: 24.6 KB
Line 
1/* $Id: oslibres.cpp,v 1.39 2004-03-18 11:14:02 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 <stdio.h>
17#include <string.h>
18
19#include <misc.h>
20#include <winconst.h>
21#include "oslibwin.h"
22#include "oslibutil.h"
23#include "oslibmsg.h"
24#include "oslibgdi.h"
25#include "oslibres.h"
26#include "pmwindow.h"
27#include <wingdi32.h>
28#include <custombuild.h>
29
30#define DBG_LOCALLOG DBG_oslibres
31#include "dbglocal.h"
32
33//******************************************************************************
34//******************************************************************************
35HANDLE OSLibWinSetAccelTable(HWND hwnd, HANDLE hAccel, PVOID acceltemplate)
36{
37 HAB hab = WinQueryAnchorBlock(hwnd);
38
39 if(hAccel == 0) {
40 hAccel = WinCreateAccelTable(hab, (PACCELTABLE)acceltemplate);
41 if(hAccel == 0) {
42 dprintf(("OSLibWinSetAccelTable: WinCreateAccelTable returned 0"));
43 return FALSE;
44 }
45 }
46 if(WinSetAccelTable(hab, hAccel, hwnd) == TRUE) {
47 return hAccel;
48 }
49 else return 0;
50}
51#if 0
52//******************************************************************************
53//TODO: change search method for icon array (cxDesired, cyDesired)
54//TODO: PM rescales the icon internally!!! ($W(#*&$(*%&)
55//******************************************************************************
56HANDLE OSLibWinCreateIcon(PVOID iconbitmap, ULONG cxDesired, ULONG cyDesired)
57{
58 POINTERINFO pointerInfo = {0};
59 HBITMAP hbmColor, hbmMask;
60 BITMAPARRAYFILEHEADER2 *bafh = (BITMAPARRAYFILEHEADER2 *)iconbitmap;
61 BITMAPFILEHEADER2 *bfhBW;
62 BITMAPFILEHEADER2 *bfhColor;
63 HPS hps;
64 HANDLE hIcon;
65
66 if(iconbitmap == NULL) {
67 dprintf(("OSLibWinCreateIcon iconbitmap == NULL!!"));
68 return 0;
69 }
70 if(bafh->usType == BFT_BITMAPARRAY && bafh->cbSize == sizeof(BITMAPARRAYFILEHEADER2)) {
71 // search best icon for the current screen,
72 // TODO: maybe compare icon size with screen size.
73 // Some bugs with black/white Icons ?
74 BITMAPARRAYFILEHEADER2 *next, *found;
75 LONG bitcountScreen, bitcountIcon=-1, cxIcon=-1, cyIcon=-1;
76
77 HPS hps = WinGetPS(HWND_DESKTOP);
78 HDC hdc = GpiQueryDevice(hps);
79 DevQueryCaps(hdc, CAPS_COLOR_BITCOUNT, 1, &bitcountScreen);
80 WinReleasePS(hps);
81
82 next = found = bafh;
83 while(TRUE)
84 {
85 bfhColor = (BITMAPFILEHEADER2 *)((char *)&next->bfh2 + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
86 if(bfhColor->bmp2.cBitCount <= bitcountScreen &&
87 bfhColor->bmp2.cBitCount > bitcountIcon ||
88 (bfhColor->bmp2.cBitCount == bitcountIcon &&
89 (cxIcon < bfhColor->bmp2.cx || cyIcon < bfhColor->bmp2.cy)))
90 {
91 found = next;
92 bitcountIcon = bfhColor->bmp2.cBitCount;
93 cxIcon = bfhColor->bmp2.cx;
94 cyIcon = bfhColor->bmp2.cy;
95 }
96 if(next->offNext != 0)
97 next = (BITMAPARRAYFILEHEADER2 *) ((char *)bafh + next->offNext);
98 else
99 break;
100 }
101 bfhBW = &found->bfh2;
102 bfhColor = (BITMAPFILEHEADER2 *)((char *)bfhBW + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
103 }
104 else {//single icon
105 bfhBW = (BITMAPFILEHEADER2 *)iconbitmap;
106 bfhColor = (BITMAPFILEHEADER2 *)((char *)bfhBW + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
107 bafh = (BITMAPARRAYFILEHEADER2 *)bfhBW; //for calculation bitmap offset
108 }
109 hps = WinGetScreenPS(HWND_DESKTOP);
110
111 //Resize icon bitmap if requested size is different
112 if(cxDesired != bfhColor->bmp2.cx|| cyDesired != bfhColor->bmp2.cy)
113 {
114 BITMAPINFOHEADER2 infohdr = bfhColor->bmp2;
115
116 infohdr.cx = cxDesired;
117 infohdr.cy = cyDesired;
118 hbmColor = GpiCreateBitmap(hps, &infohdr, CBM_INIT,
119 (char *)bafh + bfhColor->offBits,
120 (BITMAPINFO2 *)&bfhColor->bmp2);
121 }
122 else {
123 hbmColor = GpiCreateBitmap(hps, &bfhColor->bmp2, CBM_INIT,
124 (char *)bafh + bfhColor->offBits,
125 (BITMAPINFO2 *)&bfhColor->bmp2);
126 }
127 if(hbmColor == GPI_ERROR) {
128 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
129 WinReleasePS(hps);
130 return 0;
131 }
132 //Resize icon mask if requested size is different
133 if(cxDesired != bfhBW->bmp2.cx|| cyDesired*2 != bfhBW->bmp2.cy)
134 {
135 BITMAPINFOHEADER2 infohdr = bfhBW->bmp2;
136
137 infohdr.cx = cxDesired;
138 infohdr.cy = cyDesired;
139 hbmMask = GpiCreateBitmap(hps, &infohdr, CBM_INIT,
140 (char *)bafh + bfhBW->offBits,
141 (BITMAPINFO2 *)&bfhBW->bmp2);
142 }
143 else {
144 hbmMask = GpiCreateBitmap(hps, &bfhBW->bmp2, CBM_INIT,
145 (char *)bafh + bfhBW->offBits,
146 (BITMAPINFO2 *)&bfhBW->bmp2);
147 }
148 if(hbmMask == GPI_ERROR) {
149 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap hbmMask failed!"));
150 GpiDeleteBitmap(hbmColor);
151 WinReleasePS(hps);
152 return 0;
153 }
154
155 pointerInfo.fPointer = FALSE; //icon
156 pointerInfo.xHotspot = bfhBW->xHotspot;
157 pointerInfo.yHotspot = bfhBW->yHotspot;
158 pointerInfo.hbmColor = hbmColor;
159 pointerInfo.hbmPointer = hbmMask;
160 hIcon = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
161 if(hIcon == NULL) {
162 dprintf(("OSLibWinCreateIcon: WinCreatePointerIndirect failed!"));
163 }
164 GpiDeleteBitmap(hbmMask);
165 GpiDeleteBitmap(hbmColor);
166 WinReleasePS(hps);
167
168 return hIcon;
169}
170//******************************************************************************
171//TODO: change cursor size if required!! (cxDesired, cyDesired)
172//******************************************************************************
173HANDLE OSLibWinCreatePointer(PVOID cursorbitmap, ULONG cxDesired, ULONG cyDesired)
174{
175 POINTERINFO pointerInfo = {0};
176 HBITMAP hbmColor = 0, hbmMask = 0;
177 BITMAPARRAYFILEHEADER2 *bafh = (BITMAPARRAYFILEHEADER2 *)cursorbitmap;
178 BITMAPFILEHEADER2 *bfh = (BITMAPFILEHEADER2 *)cursorbitmap, *bfhColor = 0;
179 HPS hps;
180 HANDLE hPointer;
181
182 if(cursorbitmap == NULL) {
183 dprintf(("OSLibWinCreatePointer cursorbitmap == NULL!!"));
184 return 0;
185 }
186 if(bafh->usType == BFT_BITMAPARRAY && bafh->cbSize == sizeof(BITMAPARRAYFILEHEADER2)) {
187 bfh = &bafh->bfh2;
188 bfhColor = (BITMAPFILEHEADER2 *)((char *)bfh + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
189 }
190 else {//single cursor
191 bfh = (BITMAPFILEHEADER2 *)cursorbitmap;
192 bfhColor = (BITMAPFILEHEADER2 *)((char *)bfh + sizeof(RGB2)*2 + sizeof(BITMAPFILEHEADER2));
193 bafh = (BITMAPARRAYFILEHEADER2 *)bfh; //for calculation bitmap offset
194 }
195 //skip xor/and mask
196 hps = WinGetScreenPS(HWND_DESKTOP);
197 hbmMask = GpiCreateBitmap(hps, &bfh->bmp2, CBM_INIT,
198 (char *)bafh + bfh->offBits,
199 (BITMAPINFO2 *)&bfh->bmp2);
200 if(hbmMask == GPI_ERROR) {
201 dprintf(("OSLibWinCreatePointer: GpiCreateBitmap failed!"));
202 WinReleasePS(hps);
203 return 0;
204 }
205
206 if((ULONG)((char *)bafh+bfh->offBits) != (ULONG)bfhColor)
207 {//color bitmap present
208 hbmColor = GpiCreateBitmap(hps, &bfhColor->bmp2, CBM_INIT,
209 (char *)bafh + bfhColor->offBits,
210 (BITMAPINFO2 *)&bfhColor->bmp2);
211 if(hbmColor == GPI_ERROR) {
212 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
213 GpiDeleteBitmap(hbmMask);
214 WinReleasePS(hps);
215 return 0;
216 }
217 }
218
219 pointerInfo.fPointer = TRUE;
220 pointerInfo.xHotspot = bfh->xHotspot;
221 pointerInfo.yHotspot = bfh->yHotspot;
222 pointerInfo.hbmColor = hbmColor;
223 pointerInfo.hbmPointer = hbmMask;
224 hPointer = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
225
226 if(hPointer == NULL) {
227 dprintf(("OSLibWinCreatePointer: WinCreatePointerIndirect failed!"));
228 }
229 GpiDeleteBitmap(hbmMask);
230 if(hbmColor) GpiDeleteBitmap(hbmColor);
231 WinReleasePS(hps);
232 return hPointer;
233}
234#endif
235//******************************************************************************
236//******************************************************************************
237BOOL isMonoBitmap(BITMAP_W *pXorBmp, PBYTE os2rgb)
238{
239 ULONG pixel, color[2];
240 char *bmpdata;
241 int i, j, nrcolors = 0, increment;
242
243 increment = pXorBmp->bmBitsPixel/8;
244
245 for(i=0;i<pXorBmp->bmHeight;i++) {
246 bmpdata = (char *)os2rgb;
247 for(j=0;j<pXorBmp->bmWidth;j++) {
248 pixel = 0;
249 memcpy(&pixel, os2rgb, increment);
250 if(nrcolors == 0) {
251 color[0] = pixel;
252 nrcolors = 1;
253 }
254 else
255 if(nrcolors == 1 && color[0] != pixel) {
256 color[1] = pixel;
257 nrcolors = 2;
258 }
259 else {
260 if(color[0] != pixel && color[1] != pixel)
261 {
262 return FALSE;
263 }
264 }
265 os2rgb += increment;
266 }
267 os2rgb = bmpdata + pXorBmp->bmWidthBytes;
268 }
269 return TRUE;
270}
271//******************************************************************************
272//******************************************************************************
273char *colorToMonoBitmap(HBITMAP bmpsrc, BITMAPINFO2 *pBmpDest)
274{
275 HDC hdcDest = 0; /* device context handle */
276 HPS hpsDest = 0;
277 SIZEL sizl = { 0, 0 }; /* use same page size as device */
278 DEVOPENSTRUC dop = {0L, (PSZ)"DISPLAY", NULL, 0L, 0L, 0L, 0L, 0L, 0L};
279 LONG lHits;
280 char *bmpbuffer = 0;
281 BITMAPINFO2 *bmpinfo = NULL;
282 HAB hab;
283
284 dprintf2(("Convert color bitmap to mono (%d,%d) %d", pBmpDest->cx, pBmpDest->cy, pBmpDest->cBitCount));
285
286 hab = GetThreadHAB();
287
288 /* create memory device context */
289 hdcDest = DevOpenDC(hab, OD_MEMORY, "*", 5L, (PDEVOPENDATA)&dop, NULLHANDLE);
290
291 /* Create the presentation and associate the memory device
292 context. */
293 hpsDest = GpiCreatePS(hab, hdcDest, &sizl, PU_PELS |
294 GPIT_MICRO | GPIA_ASSOC);
295 if(!hpsDest) goto fail;
296
297 GpiSetBitmap(hpsDest, bmpsrc);
298
299 bmpinfo = (BITMAPINFO2 *)malloc(2*sizeof(BITMAPINFOHEADER2) + sizeof(RGB2));
300 bmpbuffer = (char *)malloc(pBmpDest->cy*pBmpDest->cx);
301 memset(bmpinfo, 0, sizeof(BITMAPINFOHEADER2) + sizeof(RGB2));
302 bmpinfo->cbFix = sizeof(BITMAPINFOHEADER2);
303 bmpinfo->cx = pBmpDest->cx;
304 bmpinfo->cy = pBmpDest->cy;
305 bmpinfo->cPlanes = 1;
306 bmpinfo->cBitCount = 1;
307 bmpinfo->ulCompression = BCA_UNCOMP;
308 bmpinfo->ulColorEncoding = BCE_RGB;
309
310 lHits = GpiQueryBitmapBits(hpsDest, 0, pBmpDest->cy, bmpbuffer, bmpinfo);
311 if(lHits == GPI_ERROR) goto fail;
312
313//#define DEBUG_CURSOR
314#ifdef DEBUG_CURSOR
315 {
316 dprintf(("colorToMonoBitmap %d %d (%x,%x,%x)(%x,%x,%x)", pBmpDest->cx, pBmpDest->cy, bmpinfo->argbColor[0].bRed, bmpinfo->argbColor[0].bGreen, bmpinfo->argbColor[0].bBlue, bmpinfo->argbColor[1].bRed, bmpinfo->argbColor[1].bGreen, bmpinfo->argbColor[1].bBlue));
317 for(int i=pBmpDest->cy-1;i>=0;i--) {
318 for(int j=0;j<pBmpDest->cx;j++) {
319 if(j<8) {
320 if((*(bmpbuffer+i*4)) & (1<<(7-j))) {
321 WriteLogNoEOL("X");
322 }
323 else WriteLogNoEOL(".");
324 }
325 else
326 if(j<16) {
327 if((*(bmpbuffer+1+i*4)) & (1<<(15-j))) {
328 WriteLogNoEOL("X");
329 }
330 else WriteLogNoEOL(".");
331 }
332 else
333 if(j<24) {
334 if((*(bmpbuffer+2+i*4)) & (1<<(23-j))) {
335 WriteLogNoEOL("X");
336 }
337 else WriteLogNoEOL(".");
338 }
339 else {
340 if((*(bmpbuffer+3+i*4)) & (1<<(31-j))) {
341 WriteLogNoEOL("X");
342 }
343 else WriteLogNoEOL(".");
344 }
345 }
346 WriteLogNoEOL("\n");
347 }
348}
349#endif
350
351 GpiSetBitmap(hpsDest, NULL);
352
353 GpiAssociate(hpsDest, NULLHANDLE); /* disassociate device context */
354 GpiDestroyPS(hpsDest); /* destroys presentation space */
355 DevCloseDC(hdcDest); /* closes device context */
356 free(bmpinfo);
357
358 return bmpbuffer;
359
360fail:
361 if(bmpinfo) free(bmpinfo);
362 if(bmpbuffer) free(bmpbuffer);
363
364 if(hpsDest) {
365 GpiSetBitmap(hpsDest, NULL);
366 GpiAssociate(hpsDest, NULLHANDLE); /* disassociate device context */
367 GpiDestroyPS(hpsDest); /* destroys presentation space */
368 }
369 if(hdcDest) DevCloseDC(hdcDest); /* closes device context */
370 return 0;
371}
372//******************************************************************************
373//******************************************************************************
374//NOTE: Depends on origin of bitmap data!!!
375// Assumes 1 bpp bitmaps have a top left origin and all others have a bottom left origin
376//******************************************************************************
377HANDLE OSLibWinCreatePointer(CURSORICONINFO *pInfo, char *pAndBits, BITMAP_W *pAndBmp, char *pXorBits,
378 BITMAP_W *pXorBmp, BOOL fCursor)
379{
380 POINTERINFO pointerInfo = {0};
381 HANDLE hPointer;
382 HBITMAP hbmColor = 0, hbmMask = 0;
383 BITMAPINFO2 *pBmpColor = 0, *pBmpMask = 0;
384 int masksize, colorsize, rgbsize, i;
385 HPS hps;
386 char *dest, *src, *pOS2XorBits = 0;
387
388 hps = WinGetScreenPS(HWND_DESKTOP);
389
390 if(pXorBits && pXorBmp->bmBitsPixel > 1)
391 {//color bitmap present
392 RGBQUAD *rgb;
393 RGB2 *os2rgb;
394
395 if(pXorBmp->bmBitsPixel <= 8)
396 rgbsize = (1<<pXorBmp->bmBitsPixel)*sizeof(RGB2);
397 else rgbsize = 0;
398
399 colorsize = sizeof(BITMAPINFO2) + (pXorBmp->bmHeight * pXorBmp->bmWidthBytes) + rgbsize;
400 pBmpColor = (BITMAPINFO2 *)calloc(colorsize, 1);
401 if(pBmpColor == NULL) {
402 DebugInt3();
403 return 0;
404 }
405 pBmpColor->cbFix = sizeof(BITMAPINFOHEADER2);
406 pBmpColor->cx = (USHORT)pXorBmp->bmWidth;
407 pBmpColor->cy = (USHORT)pXorBmp->bmHeight;
408 pBmpColor->cPlanes = pXorBmp->bmPlanes;
409 pBmpColor->cBitCount = pXorBmp->bmBitsPixel;
410 pBmpColor->ulCompression = BCA_UNCOMP;
411 pBmpColor->ulColorEncoding = BCE_RGB;
412
413 os2rgb = &pBmpColor->argbColor[0];
414 rgb = (RGBQUAD *)(pXorBits);
415
416 if(pXorBmp->bmBitsPixel <= 8) {
417 for(i=0;i<(1<<pXorBmp->bmBitsPixel);i++) {
418 os2rgb->bRed = rgb->rgbRed;
419 os2rgb->bBlue = rgb->rgbBlue;
420 os2rgb->bGreen = rgb->rgbGreen;
421 os2rgb++;
422 rgb++;
423 }
424 }
425
426 if(pXorBmp->bmBitsPixel == 16) {
427 ConvertRGB555to565(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes);
428 }
429 else memcpy(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes);
430
431 hbmColor = GpiCreateBitmap(hps, (BITMAPINFOHEADER2 *)pBmpColor, CBM_INIT,
432 (PBYTE)os2rgb, pBmpColor);
433
434 if(hbmColor == GPI_ERROR) {
435 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
436 goto fail;
437 }
438 if(fCursor && pXorBmp->bmBitsPixel >= 8)
439 {
440 if(fForceMonoCursor || isMonoBitmap(pXorBmp, (PBYTE)os2rgb) == TRUE)
441 {
442 pOS2XorBits = colorToMonoBitmap(hbmColor, pBmpColor);
443 if(pOS2XorBits) {
444 GpiDeleteBitmap(hbmColor);
445 hbmColor = 0;
446 }
447 }
448 }
449 if(hbmColor) {
450 dprintf2(("OSLibWinCreatePointer: using real color cursor/icon (fCursor %d)", fCursor));
451 }
452 else dprintf2(("OSLibWinCreatePointer: converted color cursor/icon to mono (fCursor %d)", fCursor));
453 }
454
455 //SvL: 2*sizeof(RGB2) is enough, but GpiCreateBitmap seems to touch more
456 // memory. (Adobe Photoshop 6 running in the debugger)
457 //bird: We should reserve the amount required anythingelse is stupid.
458 // Looks like it's reading 3 bytes too much... Hopefully that's due to the
459 // &pBmpMask->argbColor[2] which it assumes is 16 colors long. But no proofs.
460 //bird: Acroabat 5.1 + Printer dialog -> caused 1 byte reading too much from this buffer.
461 // At loss for the reason so I'm adding a safety catch of 256 extra bytes, I'm tired of this.
462 // (Prolem occured for bitmap: cPlanes=1 bmWidth=76 bmHeight=24 bmWidthBytes=10)
463 masksize = sizeof(BITMAPINFO2) + (pAndBmp->bmHeight * 2 * pAndBmp->bmWidthBytes) + (16 + 2) * sizeof(RGB2) + 256;
464 pBmpMask = (BITMAPINFO2 *)calloc(masksize, 1);
465 if(pBmpMask == NULL) {
466 DebugInt3();
467 return 0;
468 }
469 pBmpMask->cbFix = sizeof(BITMAPINFOHEADER2);
470 pBmpMask->cx = (USHORT)pAndBmp->bmWidth;
471 pBmpMask->cy = (USHORT)pAndBmp->bmHeight*2;
472 pBmpMask->cPlanes = pAndBmp->bmPlanes;
473 pBmpMask->cBitCount = 1;
474 pBmpMask->ulCompression = BCA_UNCOMP;
475 pBmpMask->ulColorEncoding = BCE_RGB;
476 memset(&pBmpMask->argbColor[0], 0x00, sizeof(RGB)); //not the reserved byte
477 memset(&pBmpMask->argbColor[1], 0xff, sizeof(RGB)); //not the reserved byte
478
479 // The mono XOR bitmap must be first in the pointer bitmap
480 if(pOS2XorBits || pXorBmp->bmBitsPixel == 1)
481 {
482 if(pXorBmp->bmBitsPixel == 1)
483 {
484 pOS2XorBits = (char *)calloc(pXorBmp->bmHeight, pXorBmp->bmWidthBytes);
485
486 //copy Xor bits (must reverse scanlines because origin is top left instead of bottom left)
487 src = (char *)pXorBits;
488 dest = ((char *)pOS2XorBits) + (pXorBmp->bmHeight - 1) * pXorBmp->bmWidthBytes;
489 for(i=0;i<pXorBmp->bmHeight;i++) {
490 memcpy(dest, src, pXorBmp->bmWidthBytes);
491 dest -= pXorBmp->bmWidthBytes;
492 src += pXorBmp->bmWidthBytes;
493 }
494 }
495 //else converted bitmap (created by colorToMonoBitmap)
496
497 dest = ((char *)&pBmpMask->argbColor[2]);
498 memcpy(dest, pOS2XorBits, pAndBmp->bmWidthBytes*pAndBmp->bmHeight);
499 free(pOS2XorBits);
500 pOS2XorBits = NULL;
501 }
502 // else Xor bits are already 0
503
504 //copy And bits (must reverse scanlines because origin is top left instead of bottom left)
505 src = pAndBits;
506 dest = ((char *)&pBmpMask->argbColor[2]) + (pAndBmp->bmHeight * 2 - 1) * (pAndBmp->bmWidthBytes);
507 for(i=0;i<pAndBmp->bmHeight;i++) {
508 memcpy(dest, src, pAndBmp->bmWidthBytes);
509 dest -= pAndBmp->bmWidthBytes;
510 src += pAndBmp->bmWidthBytes;
511 }
512 hbmMask = GpiCreateBitmap(hps, (BITMAPINFOHEADER2 *)pBmpMask, CBM_INIT,
513 (PBYTE)&pBmpMask->argbColor[2], pBmpMask);
514
515 if(hbmMask == GPI_ERROR) {
516 dprintf(("OSLibWinCreatePointer: GpiCreateBitmap failed!"));
517 goto fail;
518 }
519
520 pointerInfo.fPointer = fCursor; //FALSE = icon
521 pointerInfo.xHotspot = pInfo->ptHotSpot.x;
522 pointerInfo.yHotspot = mapY(pInfo->nHeight, pInfo->ptHotSpot.y);
523 pointerInfo.hbmColor = hbmColor;
524 pointerInfo.hbmPointer = hbmMask;
525 dprintf2(("WinCreatePointerIndirect %d (%d,%d) (org %d,%d)", pointerInfo.fPointer, pointerInfo.xHotspot, pointerInfo.yHotspot, pInfo->ptHotSpot.x, pInfo->ptHotSpot.y));
526 hPointer = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
527
528 if(hPointer == NULL) {
529 dprintf(("OSLibWinCreateCursor: WinCreatePointerIndirect failed! (lasterr=%x)", WinGetLastError(GetThreadHAB())));
530 }
531 GpiDeleteBitmap(hbmMask);
532 if(hbmColor) GpiDeleteBitmap(hbmColor);
533 WinReleasePS(hps);
534
535 free(pBmpMask);
536 free(pBmpColor);
537
538 dprintf2(("OSLibWinCreatePointer: PM pointer %x", hPointer));
539 return hPointer;
540
541fail:
542 if(hbmMask) GpiDeleteBitmap(hbmMask);
543 if(hbmColor) GpiDeleteBitmap(hbmColor);
544 WinReleasePS(hps);
545 if(pBmpMask) free(pBmpMask);
546 if(pBmpColor) free(pBmpColor);
547 return 0;
548}
549//******************************************************************************
550//******************************************************************************
551HANDLE OSLibWinQuerySysIcon(ULONG type,INT w,INT h)
552{
553 ULONG os2type = 0;
554 HPOINTER hPointer;
555
556 switch(type) {
557 case IDI_APPLICATION_W:
558 os2type = SPTR_PROGRAM;
559 break;
560 case IDI_HAND_W:
561 os2type = SPTR_ICONWARNING;
562 break;
563 case IDI_QUESTION_W:
564 os2type = SPTR_ICONQUESTION;
565 break;
566 case IDI_EXCLAMATION_W:
567 os2type = SPTR_ICONWARNING;
568 break;
569 case IDI_ASTERISK_W:
570 os2type = SPTR_ICONINFORMATION;
571 break;
572 default:
573 return 0;
574 }
575
576 hPointer = WinQuerySysPointer(HWND_DESKTOP, os2type, TRUE);
577
578 if (hPointer)
579 {
580 INT sysW = WinQuerySysValue(HWND_DESKTOP,SV_CXICON),sysH = WinQuerySysValue(HWND_DESKTOP,SV_CYICON);
581
582 if (sysW != w || sysH != h)
583 {
584 POINTERINFO pi;
585
586 WinQueryPointerInfo(hPointer,&pi);
587 //CB: todo: change icon size
588
589 }
590 }
591
592 return hPointer;
593}
594//******************************************************************************
595//******************************************************************************
596HANDLE OSLibWinQuerySysPointer(ULONG type,INT w,INT h)
597{
598 ULONG os2type = 0;
599
600 switch(type) {
601 case IDC_ARROW_W:
602 os2type = SPTR_ARROW;
603 break;
604 case IDC_UPARROW_W:
605 os2type = SPTR_ARROW;
606 break;
607 case IDC_IBEAM_W:
608 os2type = SPTR_TEXT;
609 break;
610 case IDC_ICON_W:
611 os2type = SPTR_PROGRAM;
612 break;
613 case IDC_NO_W:
614 os2type = SPTR_ILLEGAL;
615 break;
616 case IDC_CROSS_W:
617 os2type = SPTR_MOVE;
618 break;
619 case IDC_SIZE_W:
620 os2type = SPTR_MOVE;
621 break;
622 case IDC_SIZEALL_W:
623 os2type = SPTR_MOVE;
624 break;
625 case IDC_SIZENESW_W:
626 os2type = SPTR_SIZENESW;
627 break;
628 case IDC_SIZENS_W:
629 os2type = SPTR_SIZENS;
630 break;
631 case IDC_SIZENWSE_W:
632 os2type = SPTR_SIZENWSE;
633 break;
634 case IDC_SIZEWE_W:
635 os2type = SPTR_SIZEWE;
636 break;
637 case IDC_WAIT_W:
638 os2type = SPTR_WAIT;
639 break;
640 case IDC_APPSTARTING_W:
641 os2type = SPTR_WAIT;
642 break;
643 case IDC_HELP_W: //TODO: Create a cursor for this one
644 os2type = SPTR_WAIT;
645 break;
646 default:
647 return 0;
648 }
649 //Note: Does not create a copy
650 return WinQuerySysPointer(HWND_DESKTOP, os2type, FALSE);
651}
652//******************************************************************************
653//******************************************************************************
654VOID OSLibWinDestroyPointer(HANDLE hPointer)
655{
656 WinDestroyPointer(hPointer);
657}
658//******************************************************************************
659//******************************************************************************
660BOOL OSLibWinSetPointer(HANDLE hPointer)
661{
662 return WinSetPointer(HWND_DESKTOP, hPointer);
663}
664//******************************************************************************
665//******************************************************************************
666HANDLE OSLibWinQueryPointer()
667{
668 return WinQueryPointer(HWND_DESKTOP);
669}
670//******************************************************************************
671//******************************************************************************
672BOOL OSLibWinClipCursor(const RECT * pRect)
673{
674 RECTL rectl;
675 PRECTL ptr = NULL;
676
677 if (pRect != NULL)
678 {
679 rectl.xLeft = max(pRect->left, 0);
680 rectl.xRight = min(pRect->right, ScreenWidth-1);
681 rectl.yBottom = max(ScreenHeight - pRect->bottom, 0);
682 rectl.yTop = min(ScreenHeight - pRect->top, ScreenHeight-1);
683 ptr = &rectl;
684 }
685 return WinSetPointerClipRect (HWND_DESKTOP, ptr);
686}
687//******************************************************************************
688//******************************************************************************
689BOOL OSLibWinGetClipCursor(LPRECT pRect)
690{
691 RECTL rectl;
692
693 if (WinQueryPointerClipRect(HWND_DESKTOP, &rectl))
694 {
695 pRect->left = rectl.xLeft;
696 pRect->right = rectl.xRight;
697 pRect->bottom = ScreenHeight - rectl.yBottom;
698 pRect->top = ScreenHeight - rectl.yTop;
699 return TRUE;
700 }
701 return FALSE;
702}
703//******************************************************************************
704//******************************************************************************
Note: See TracBrowser for help on using the repository browser.