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

Last change on this file since 7102 was 7079, checked in by sandervl, 24 years ago

custom build updates

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