source: trunk/src/user32/oslibres.cpp@ 9523

Last change on this file since 9523 was 9523, checked in by sandervl, 23 years ago

removed obsolete files

File size: 28.4 KB
Line 
1/* $Id: oslibres.cpp,v 1.33 2002-12-18 12:28:05 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, "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)
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 *)malloc(colorsize);
401 if(pBmpColor == NULL) {
402 DebugInt3();
403 return 0;
404 }
405 memset(pBmpColor, 0, colorsize);
406 pBmpColor->cbFix = sizeof(BITMAPINFOHEADER2);
407 pBmpColor->cx = (USHORT)pXorBmp->bmWidth;
408 pBmpColor->cy = (USHORT)pXorBmp->bmHeight;
409 pBmpColor->cPlanes = pXorBmp->bmPlanes;
410 pBmpColor->cBitCount = pXorBmp->bmBitsPixel;
411 pBmpColor->ulCompression = BCA_UNCOMP;
412 pBmpColor->ulColorEncoding = BCE_RGB;
413
414 os2rgb = &pBmpColor->argbColor[0];
415 rgb = (RGBQUAD *)(pXorBits);
416
417 if(pXorBmp->bmBitsPixel <= 8) {
418 for(i=0;i<(1<<pXorBmp->bmBitsPixel);i++) {
419 os2rgb->bRed = rgb->rgbRed;
420 os2rgb->bBlue = rgb->rgbBlue;
421 os2rgb->bGreen = rgb->rgbGreen;
422 os2rgb++;
423 rgb++;
424 }
425 }
426
427 if(pXorBmp->bmBitsPixel == 1) {
428 //copy Xor bits (must reverse scanlines because origin is top left instead of bottom left)
429 src = (char *)rgb;
430 dest = ((char *)os2rgb) + (pXorBmp->bmHeight - 1) * pXorBmp->bmWidthBytes;
431 for(i=0;i<pXorBmp->bmHeight;i++) {
432 memcpy(dest, src, pXorBmp->bmWidthBytes);
433 dest -= pXorBmp->bmWidthBytes;
434 src += pXorBmp->bmWidthBytes;
435 }
436 }
437 else
438 if(pXorBmp->bmBitsPixel == 16) {
439 ConvertRGB555to565(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes);
440 }
441 else memcpy(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes);
442
443 hbmColor = GpiCreateBitmap(hps, (BITMAPINFOHEADER2 *)pBmpColor, CBM_INIT,
444 (PBYTE)os2rgb, pBmpColor);
445
446 if(hbmColor == GPI_ERROR) {
447 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
448 goto fail;
449 }
450 if(fCursor && pXorBmp->bmBitsPixel >= 8)
451 {
452 if(fForceMonoCursor || isMonoBitmap(pXorBmp, (PBYTE)os2rgb) == TRUE)
453 {
454 pOS2XorBits = colorToMonoBitmap(hbmColor, pBmpColor);
455 if(pOS2XorBits) {
456 GpiDeleteBitmap(hbmColor);
457 hbmColor = 0;
458 }
459 }
460 }
461 if(hbmColor) {
462 dprintf2(("OSLibWinCreatePointer: using real color cursor/icon (fCursor %d)", fCursor));
463 }
464 else dprintf2(("OSLibWinCreatePointer: converted color cursor/icon to mono (fCursor %d)", fCursor));
465 }
466
467 //SvL: 2*sizeof(RGB2) is enough, but GpiCreateBitmap seems to touch more
468 // memory. (Adobe Photoshop 6 running in the debugger)
469 //bird: We should reserve the amount required anythingelse is stupid.
470 // Looks like it's reading 3 bytes too much... Hopefully that's due to the
471 // &pBmpMask->argbColor[2] which it assumes is 16 colors long. But no proofs.
472 masksize = sizeof(BITMAPINFO2) + (pAndBmp->bmHeight * 2 * pAndBmp->bmWidthBytes) + (16+2)*sizeof(RGB2);
473 pBmpMask = (BITMAPINFO2 *)malloc(masksize);
474 if(pBmpMask == NULL) {
475 DebugInt3();
476 return 0;
477 }
478 memset(pBmpMask, 0, masksize);
479 pBmpMask->cbFix = sizeof(BITMAPINFOHEADER2);
480 pBmpMask->cx = (USHORT)pAndBmp->bmWidth;
481 pBmpMask->cy = (USHORT)pAndBmp->bmHeight*2;
482 pBmpMask->cPlanes = pAndBmp->bmPlanes;
483 pBmpMask->cBitCount = 1;
484 pBmpMask->ulCompression = BCA_UNCOMP;
485 pBmpMask->ulColorEncoding = BCE_RGB;
486 memset(&pBmpMask->argbColor[0], 0, sizeof(RGB2));
487 memset(&pBmpMask->argbColor[1], 0xff, sizeof(RGB)); //not the reserved byte
488 if(pOS2XorBits) {
489 dest = ((char *)&pBmpMask->argbColor[2]);
490 memcpy(dest, pOS2XorBits, pAndBmp->bmWidthBytes*pAndBmp->bmHeight);
491 free(pOS2XorBits);
492 pOS2XorBits = NULL;
493 }
494 // else Xor bits are already 0
495
496 //copy And bits (must reverse scanlines because origin is top left instead of bottom left)
497 src = pAndBits;
498 dest = ((char *)&pBmpMask->argbColor[2]) + (pAndBmp->bmHeight * 2 - 1) * (pAndBmp->bmWidthBytes);
499 for(i=0;i<pAndBmp->bmHeight;i++) {
500 memcpy(dest, src, pAndBmp->bmWidthBytes);
501 dest -= pAndBmp->bmWidthBytes;
502 src += pAndBmp->bmWidthBytes;
503 }
504 hbmMask = GpiCreateBitmap(hps, (BITMAPINFOHEADER2 *)pBmpMask, CBM_INIT,
505 (PBYTE)&pBmpMask->argbColor[2], pBmpMask);
506
507 if(hbmMask == GPI_ERROR) {
508 dprintf(("OSLibWinCreatePointer: GpiCreateBitmap failed!"));
509 goto fail;
510 }
511
512 pointerInfo.fPointer = fCursor; //FALSE = icon
513 pointerInfo.xHotspot = pInfo->ptHotSpot.x;
514 pointerInfo.yHotspot = mapY(pInfo->nHeight, pInfo->ptHotSpot.y);
515 pointerInfo.hbmColor = hbmColor;
516 pointerInfo.hbmPointer = hbmMask;
517 dprintf2(("WinCreatePointerIndirect %d (%d,%d) (org %d,%d)", pointerInfo.fPointer, pointerInfo.xHotspot, pointerInfo.yHotspot, pInfo->ptHotSpot.x, pInfo->ptHotSpot.y));
518 hPointer = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
519
520 if(hPointer == NULL) {
521 dprintf(("OSLibWinCreateCursor: WinCreatePointerIndirect failed! (lasterr=%x)", WinGetLastError(GetThreadHAB())));
522 }
523 GpiDeleteBitmap(hbmMask);
524 if(hbmColor) GpiDeleteBitmap(hbmColor);
525 WinReleasePS(hps);
526
527 free(pBmpMask);
528 free(pBmpColor);
529
530 dprintf2(("OSLibWinCreatePointer: PM pointer %x", hPointer));
531 return hPointer;
532
533fail:
534 if(hbmMask) GpiDeleteBitmap(hbmMask);
535 if(hbmColor) GpiDeleteBitmap(hbmColor);
536 WinReleasePS(hps);
537 if(pBmpMask) free(pBmpMask);
538 if(pBmpColor) free(pBmpColor);
539 return 0;
540}
541//******************************************************************************
542//******************************************************************************
543HANDLE OSLibWinQuerySysIcon(ULONG type,INT w,INT h)
544{
545 ULONG os2type = 0;
546 HPOINTER hPointer;
547
548 switch(type) {
549 case IDI_APPLICATION_W:
550 os2type = SPTR_PROGRAM;
551 break;
552 case IDI_HAND_W:
553 os2type = SPTR_ICONWARNING;
554 break;
555 case IDI_QUESTION_W:
556 os2type = SPTR_ICONQUESTION;
557 break;
558 case IDI_EXCLAMATION_W:
559 os2type = SPTR_ICONWARNING;
560 break;
561 case IDI_ASTERISK_W:
562 os2type = SPTR_ICONINFORMATION;
563 break;
564 default:
565 return 0;
566 }
567
568 hPointer = WinQuerySysPointer(HWND_DESKTOP, os2type, TRUE);
569
570 if (hPointer)
571 {
572 INT sysW = WinQuerySysValue(HWND_DESKTOP,SV_CXICON),sysH = WinQuerySysValue(HWND_DESKTOP,SV_CYICON);
573
574 if (sysW != w || sysH != h)
575 {
576 POINTERINFO pi;
577
578 WinQueryPointerInfo(hPointer,&pi);
579 //CB: todo: change icon size
580
581 }
582 }
583
584 return hPointer;
585}
586//******************************************************************************
587//******************************************************************************
588HANDLE OSLibWinQuerySysPointer(ULONG type,INT w,INT h)
589{
590 ULONG os2type = 0;
591
592 switch(type) {
593 case IDC_ARROW_W:
594 os2type = SPTR_ARROW;
595 break;
596 case IDC_UPARROW_W:
597 os2type = SPTR_ARROW;
598 break;
599 case IDC_IBEAM_W:
600 os2type = SPTR_TEXT;
601 break;
602 case IDC_ICON_W:
603 os2type = SPTR_PROGRAM;
604 break;
605 case IDC_NO_W:
606 os2type = SPTR_ILLEGAL;
607 break;
608 case IDC_CROSS_W:
609 os2type = SPTR_MOVE;
610 break;
611 case IDC_SIZE_W:
612 os2type = SPTR_MOVE;
613 break;
614 case IDC_SIZEALL_W:
615 os2type = SPTR_MOVE;
616 break;
617 case IDC_SIZENESW_W:
618 os2type = SPTR_SIZENESW;
619 break;
620 case IDC_SIZENS_W:
621 os2type = SPTR_SIZENS;
622 break;
623 case IDC_SIZENWSE_W:
624 os2type = SPTR_SIZENWSE;
625 break;
626 case IDC_SIZEWE_W:
627 os2type = SPTR_SIZEWE;
628 break;
629 case IDC_WAIT_W:
630 os2type = SPTR_WAIT;
631 break;
632 case IDC_APPSTARTING_W:
633 os2type = SPTR_WAIT;
634 break;
635 case IDC_HELP_W: //TODO: Create a cursor for this one
636 os2type = SPTR_WAIT;
637 break;
638 default:
639 return 0;
640 }
641 //Note: Does not create a copy
642 return WinQuerySysPointer(HWND_DESKTOP, os2type, FALSE);
643}
644//******************************************************************************
645//******************************************************************************
646VOID OSLibWinDestroyPointer(HANDLE hPointer)
647{
648 WinDestroyPointer(hPointer);
649}
650//******************************************************************************
651//******************************************************************************
652BOOL OSLibWinSetPointer(HANDLE hPointer)
653{
654 return WinSetPointer(HWND_DESKTOP, hPointer);
655}
656//******************************************************************************
657//******************************************************************************
658HANDLE OSLibWinQueryPointer()
659{
660 return WinQueryPointer(HWND_DESKTOP);
661}
662//******************************************************************************
663//******************************************************************************
664BOOL OSLibWinClipCursor(const RECT * pRect)
665{
666 RECTL rectl;
667 PRECTL ptr = NULL;
668
669 if (pRect != NULL)
670 {
671 rectl.xLeft = max(pRect->left, 0);
672 rectl.xRight = min(pRect->right, ScreenWidth-1);
673 rectl.yBottom = max(ScreenHeight - pRect->bottom, 0);
674 rectl.yTop = min(ScreenHeight - pRect->top, ScreenHeight-1);
675 ptr = &rectl;
676 }
677 return WinSetPointerClipRect (HWND_DESKTOP, ptr);
678}
679//******************************************************************************
680//******************************************************************************
681BOOL OSLibWinGetClipCursor(LPRECT pRect)
682{
683 RECTL rectl;
684
685 if (WinQueryPointerClipRect(HWND_DESKTOP, &rectl))
686 {
687 pRect->left = rectl.xLeft;
688 pRect->right = rectl.xRight;
689 pRect->bottom = ScreenHeight - rectl.yBottom;
690 pRect->top = ScreenHeight - rectl.yTop;
691 return TRUE;
692 }
693 return FALSE;
694}
695//******************************************************************************
696//******************************************************************************
697static char *OSLibStripPath(char *path)
698{
699 char *pszFilename;
700 char *pszFilename1;
701
702 pszFilename = strrchr(path, '\\'); /* find rightmost backslash */
703 pszFilename1 = strrchr(path, '/'); /* find rightmost slash */
704 if(pszFilename > pszFilename1 && pszFilename != NULL)
705 return (++pszFilename); /* return pointer to next character */
706
707 if (pszFilename1 != NULL)
708 return (++pszFilename1); /* return pointer to next character */
709
710 return (path); /* default return value */
711}
712//******************************************************************************
713//******************************************************************************
714void OSLibStripFile(char *path)
715{
716 char *pszFilename;
717 char *pszFilename1;
718
719 pszFilename = strrchr(path, '\\'); /* find rightmost backslash */
720 pszFilename1 = strrchr(path, '/'); /* find rightmost slash */
721 if(pszFilename > pszFilename1 && pszFilename != NULL)
722 *pszFilename = 0;
723 else
724 if (pszFilename1 != NULL)
725 *pszFilename1 = 0;
726}
727//******************************************************************************
728//******************************************************************************
729BOOL WIN32API OSLibWinCreateObject(LPSTR pszPath, LPSTR pszArgs,
730 LPSTR pszWorkDir, LPSTR pszLink,
731 LPSTR pszDescription, LPSTR pszIcoPath,
732 INT iIcoNdx, BOOL fDesktop)
733{
734 HOBJECT hObject = 0;
735 LPSTR pszName;
736 LPSTR pszSetupString;
737 LPSTR pszFolder;
738 char szSystemDir[256];
739 char temp[128];
740 char szWorkDir[256];
741 char szPEGUILoaderPath[256];
742
743 if(pszName) {
744 char *tmp;
745 pszName = OSLibStripPath(pszLink);
746 tmp = pszName;
747 while(*tmp) {
748 if(*tmp == '.') {
749 *tmp = 0;
750 break;
751 }
752 tmp++;
753 }
754 }
755 dprintf(("OSLibWinCreateObject %s %s %s\n %s %s %s %d %d", pszPath, pszArgs,
756 pszWorkDir, pszName, pszDescription, pszIcoPath, iIcoNdx, fDesktop));
757 dprintf(("Link path %s", pszLink));
758
759 GetSystemDirectoryA(szSystemDir, sizeof(szSystemDir));
760 if(pszWorkDir && *pszWorkDir) {
761 strcpy(szWorkDir, pszWorkDir);
762 }
763 else {
764 strcpy(szWorkDir, pszPath);
765 OSLibStripFile(szWorkDir);
766 }
767
768 ODIN_QueryLoaders(NULL, 0, szPEGUILoaderPath, sizeof(szPEGUILoaderPath), NULL, 0);
769
770 pszSetupString = (LPSTR)malloc(128 + strlen(pszPath) + strlen(pszName) +
771 strlen(pszLink) + strlen(szSystemDir) +
772 strlen(szWorkDir) + strlen(pszIcoPath) +
773 strlen(szPEGUILoaderPath) +
774 ((pszArgs) ? strlen(pszArgs) : 0) +
775 ((pszWorkDir) ? strlen(pszWorkDir) : 0));
776
777 sprintf(pszSetupString, "PROGTYPE=PM;OBJECTID=<%s>;EXENAME=%s;SET BEGINLIBPATH=%s;STARTUPDIR=%s;ICONFILE=%s;PARAMETERS=\"%s\"", pszName, szPEGUILoaderPath, szSystemDir, szWorkDir, pszIcoPath, pszPath);
778 if(pszArgs && *pszArgs) {
779 strcat(pszSetupString, " ");
780 strcat(pszSetupString, pszArgs);
781 }
782 strcat(pszSetupString, ";");
783
784 if(fDesktop) {
785 dprintf(("Name = %s", pszName));
786 dprintf(("Setup string = %s", pszSetupString));
787 hObject = WinCreateObject("WPProgram", pszName, pszSetupString,
788 "<WP_DESKTOP>", CO_REPLACEIFEXISTS);
789 }
790 else {
791 //e.g.: Link path k:\source\odin32\bin\win\Start Menu\Programs\Winamp\Winamp
792 OSLibStripFile(pszLink);
793 pszFolder = OSLibStripPath(pszLink);
794 sprintf(temp, "<FOLDER_%s>", pszFolder);
795 sprintf(szWorkDir, "OBJECTID=%s;", temp);
796 hObject = WinCreateObject("WPFolder", pszFolder, szWorkDir,
797 "<ODINFOLDER>", CO_UPDATEIFEXISTS);
798 hObject = WinCreateObject("WPProgram", pszName, pszSetupString,
799 temp, CO_REPLACEIFEXISTS);
800 }
801
802 free(pszSetupString);
803 if(!hObject) {
804 dprintf(("ERROR: WinCreateObject failed!!"));
805 }
806 return hObject != 0;
807}
808//******************************************************************************
809//******************************************************************************
810
Note: See TracBrowser for help on using the repository browser.