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

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

convert color cursors that use only two colors to monochrome

File size: 27.5 KB
Line 
1/* $Id: oslibres.cpp,v 1.22 2001-10-14 20:15:15 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 {
311 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));
312 for(int i=pBmpDest->cy-1;i>=0;i--) {
313 for(int j=0;j<pBmpDest->cx;j++) {
314 if(j<8) {
315 if((*(bmpbuffer+i*4)) & (1<<(7-j))) {
316 WriteLogNoEOL("X");
317 }
318 else WriteLogNoEOL(".");
319 }
320 else
321 if(j<16) {
322 if((*(bmpbuffer+1+i*4)) & (1<<(15-j))) {
323 WriteLogNoEOL("X");
324 }
325 else WriteLogNoEOL(".");
326 }
327 else
328 if(j<24) {
329 if((*(bmpbuffer+2+i*4)) & (1<<(23-j))) {
330 WriteLogNoEOL("X");
331 }
332 else WriteLogNoEOL(".");
333 }
334 else {
335 if((*(bmpbuffer+3+i*4)) & (1<<(31-j))) {
336 WriteLogNoEOL("X");
337 }
338 else WriteLogNoEOL(".");
339 }
340 }
341 WriteLogNoEOL("\n");
342 }
343}
344
345 GpiSetBitmap(hpsDest, NULL);
346
347 GpiAssociate(hpsDest, NULLHANDLE); /* disassociate device context */
348 GpiDestroyPS(hpsDest); /* destroys presentation space */
349 DevCloseDC(hdcDest); /* closes device context */
350 free(bmpinfo);
351
352 return bmpbuffer;
353
354fail:
355 if(bmpinfo) free(bmpinfo);
356 if(bmpbuffer) free(bmpbuffer);
357
358 if(hpsDest) {
359 GpiSetBitmap(hpsDest, NULL);
360 GpiAssociate(hpsDest, NULLHANDLE); /* disassociate device context */
361 GpiDestroyPS(hpsDest); /* destroys presentation space */
362 }
363 if(hdcDest) DevCloseDC(hdcDest); /* closes device context */
364 return 0;
365}
366//******************************************************************************
367//******************************************************************************
368//NOTE: Depends on origin of bitmap data!!!
369// Assumes 1 bpp bitmaps have a top left origin and all others have a bottom left origin
370//******************************************************************************
371HANDLE OSLibWinCreatePointer(CURSORICONINFO *pInfo, char *pAndBits, BITMAP_W *pAndBmp, char *pXorBits,
372 BITMAP_W *pXorBmp, BOOL fCursor)
373{
374 POINTERINFO pointerInfo = {0};
375 HANDLE hPointer;
376 HBITMAP hbmColor = 0, hbmMask = 0;
377 BITMAPINFO2 *pBmpColor = 0, *pBmpMask = 0;
378 int masksize, colorsize, rgbsize, i;
379 HPS hps;
380 char *dest, *src, *pOS2XorBits = 0;
381
382 hps = WinGetScreenPS(HWND_DESKTOP);
383
384 if(pXorBits)
385 {//color bitmap present
386 RGBQUAD *rgb;
387 RGB2 *os2rgb;
388
389 if(pXorBmp->bmBitsPixel <= 8)
390 rgbsize = (1<<pXorBmp->bmBitsPixel)*sizeof(RGB2);
391 else rgbsize = 0;
392
393 colorsize = sizeof(BITMAPINFO2) + (pXorBmp->bmHeight * pXorBmp->bmWidthBytes) + rgbsize;
394 pBmpColor = (BITMAPINFO2 *)malloc(colorsize);
395 if(pBmpColor == NULL) {
396 DebugInt3();
397 return 0;
398 }
399 memset(pBmpColor, 0, colorsize);
400 pBmpColor->cbFix = sizeof(BITMAPINFOHEADER2);
401 pBmpColor->cx = (USHORT)pXorBmp->bmWidth;
402 pBmpColor->cy = (USHORT)pXorBmp->bmHeight;
403 pBmpColor->cPlanes = pXorBmp->bmPlanes;
404 pBmpColor->cBitCount = pXorBmp->bmBitsPixel;
405 pBmpColor->ulCompression = BCA_UNCOMP;
406 pBmpColor->ulColorEncoding = BCE_RGB;
407
408 os2rgb = &pBmpColor->argbColor[0];
409 rgb = (RGBQUAD *)(pXorBits);
410
411 if(pXorBmp->bmBitsPixel <= 8) {
412 for(i=0;i<(1<<pXorBmp->bmBitsPixel);i++) {
413 os2rgb->bRed = rgb->rgbRed;
414 os2rgb->bBlue = rgb->rgbBlue;
415 os2rgb->bGreen = rgb->rgbGreen;
416 os2rgb++;
417 rgb++;
418 }
419 }
420
421 if(pXorBmp->bmBitsPixel == 1) {
422 //copy Xor bits (must reverse scanlines because origin is top left instead of bottom left)
423 src = (char *)rgb;
424 dest = ((char *)os2rgb) + (pXorBmp->bmHeight - 1) * pXorBmp->bmWidthBytes;
425 for(i=0;i<pXorBmp->bmHeight;i++) {
426 memcpy(dest, src, pXorBmp->bmWidthBytes);
427 dest -= pXorBmp->bmWidthBytes;
428 src += pXorBmp->bmWidthBytes;
429 }
430 }
431 else
432 if(pXorBmp->bmBitsPixel == 16) {
433 ConvertRGB555to565(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes);
434 }
435 else memcpy(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes);
436
437 hbmColor = GpiCreateBitmap(hps, (BITMAPINFOHEADER2 *)pBmpColor, CBM_INIT,
438 (PBYTE)os2rgb, pBmpColor);
439
440 if(hbmColor == GPI_ERROR) {
441 dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
442 goto fail;
443 }
444 if(pXorBmp->bmBitsPixel >= 8)
445 {
446 if(isMonoBitmap(pXorBmp, (PBYTE)os2rgb) == TRUE)
447 {
448 pOS2XorBits = colorToMonoBitmap(hbmColor, pBmpColor);
449 if(pOS2XorBits) {
450 GpiDeleteBitmap(hbmColor);
451 hbmColor = 0;
452 }
453 }
454 }
455 //testestest
456 }
457
458 //SvL: 2*sizeof(RGB2) is enough, but GpiCreateBitmap seems to touch more
459 // memory. (Adobe Photoshop 6 running in the debugger)
460 masksize = sizeof(BITMAPINFO2) + (pAndBmp->bmHeight * 2 * pAndBmp->bmWidthBytes) + 16*sizeof(RGB2);
461 pBmpMask = (BITMAPINFO2 *)malloc(masksize);
462 if(pBmpMask == NULL) {
463 DebugInt3();
464 return 0;
465 }
466 memset(pBmpMask, 0, masksize);
467 pBmpMask->cbFix = sizeof(BITMAPINFOHEADER2);
468 pBmpMask->cx = (USHORT)pAndBmp->bmWidth;
469 pBmpMask->cy = (USHORT)pAndBmp->bmHeight*2;
470 pBmpMask->cPlanes = pAndBmp->bmPlanes;
471 pBmpMask->cBitCount = 1;
472 pBmpMask->ulCompression = BCA_UNCOMP;
473 pBmpMask->ulColorEncoding = BCE_RGB;
474 memset(&pBmpMask->argbColor[0], 0, sizeof(RGB2));
475 memset(&pBmpMask->argbColor[1], 0xff, sizeof(RGB)); //not the reserved byte
476 if(pOS2XorBits) {
477 dest = ((char *)&pBmpMask->argbColor[2]);
478 memcpy(dest, pOS2XorBits, pAndBmp->bmWidthBytes*pAndBmp->bmHeight);
479 free(pOS2XorBits);
480 pOS2XorBits = NULL;
481 }
482 // else Xor bits are already 0
483
484 //copy And bits (must reverse scanlines because origin is top left instead of bottom left)
485 src = pAndBits;
486 dest = ((char *)&pBmpMask->argbColor[2]) + (pAndBmp->bmHeight * 2 - 1) * (pAndBmp->bmWidthBytes);
487 for(i=0;i<pAndBmp->bmHeight;i++) {
488 memcpy(dest, src, pAndBmp->bmWidthBytes);
489 dest -= pAndBmp->bmWidthBytes;
490 src += pAndBmp->bmWidthBytes;
491 }
492 hbmMask = GpiCreateBitmap(hps, (BITMAPINFOHEADER2 *)pBmpMask, CBM_INIT,
493 (PBYTE)&pBmpMask->argbColor[2], pBmpMask);
494
495 if(hbmMask == GPI_ERROR) {
496 dprintf(("OSLibWinCreatePointer: GpiCreateBitmap failed!"));
497 goto fail;
498 }
499
500 pointerInfo.fPointer = fCursor; //FALSE = icon
501 pointerInfo.xHotspot = pInfo->ptHotSpot.x;
502 pointerInfo.yHotspot = mapY(pInfo->nHeight, pInfo->ptHotSpot.y);
503 pointerInfo.hbmColor = hbmColor;
504 pointerInfo.hbmPointer = hbmMask;
505 hPointer = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
506
507 if(hPointer == NULL) {
508 dprintf(("OSLibWinCreateCursor: WinCreatePointerIndirect failed! (lasterr=%x)", WinGetLastError(GetThreadHAB())));
509 }
510 GpiDeleteBitmap(hbmMask);
511 if(hbmColor) GpiDeleteBitmap(hbmColor);
512 WinReleasePS(hps);
513
514 free(pBmpMask);
515 free(pBmpColor);
516 return hPointer;
517
518fail:
519 if(hbmMask) GpiDeleteBitmap(hbmMask);
520 if(hbmColor) GpiDeleteBitmap(hbmColor);
521 WinReleasePS(hps);
522 if(pBmpMask) free(pBmpMask);
523 if(pBmpColor) free(pBmpColor);
524 return 0;
525}
526//******************************************************************************
527//******************************************************************************
528HANDLE OSLibWinQuerySysIcon(ULONG type,INT w,INT h)
529{
530 ULONG os2type = 0;
531 HPOINTER hPointer;
532
533 switch(type) {
534 case IDI_APPLICATION_W:
535 os2type = SPTR_PROGRAM;
536 break;
537 case IDI_HAND_W:
538 os2type = SPTR_ICONWARNING;
539 break;
540 case IDI_QUESTION_W:
541 os2type = SPTR_ICONQUESTION;
542 break;
543 case IDI_EXCLAMATION_W:
544 os2type = SPTR_ICONWARNING;
545 break;
546 case IDI_ASTERISK_W:
547 os2type = SPTR_ICONINFORMATION;
548 break;
549 default:
550 return 0;
551 }
552
553 hPointer = WinQuerySysPointer(HWND_DESKTOP, os2type, TRUE);
554
555 if (hPointer)
556 {
557 INT sysW = WinQuerySysValue(HWND_DESKTOP,SV_CXICON),sysH = WinQuerySysValue(HWND_DESKTOP,SV_CYICON);
558
559 if (sysW != w || sysH != h)
560 {
561 POINTERINFO pi;
562
563 WinQueryPointerInfo(hPointer,&pi);
564 //CB: todo: change icon size
565
566 }
567 }
568
569 return hPointer;
570}
571//******************************************************************************
572//******************************************************************************
573HANDLE OSLibWinQuerySysPointer(ULONG type,INT w,INT h)
574{
575 ULONG os2type = 0;
576
577 switch(type) {
578 case IDC_ARROW_W:
579 os2type = SPTR_ARROW;
580 break;
581 case IDC_UPARROW_W:
582 os2type = SPTR_ARROW;
583 break;
584 case IDC_IBEAM_W:
585 os2type = SPTR_TEXT;
586 break;
587 case IDC_ICON_W:
588 os2type = SPTR_PROGRAM;
589 break;
590 case IDC_NO_W:
591 os2type = SPTR_ILLEGAL;
592 break;
593 case IDC_CROSS_W:
594 os2type = SPTR_MOVE;
595 break;
596 case IDC_SIZE_W:
597 os2type = SPTR_MOVE;
598 break;
599 case IDC_SIZEALL_W:
600 os2type = SPTR_MOVE;
601 break;
602 case IDC_SIZENESW_W:
603 os2type = SPTR_SIZENESW;
604 break;
605 case IDC_SIZENS_W:
606 os2type = SPTR_SIZENS;
607 break;
608 case IDC_SIZENWSE_W:
609 os2type = SPTR_SIZENWSE;
610 break;
611 case IDC_SIZEWE_W:
612 os2type = SPTR_SIZEWE;
613 break;
614 case IDC_WAIT_W:
615 os2type = SPTR_WAIT;
616 break;
617 case IDC_APPSTARTING_W:
618 os2type = SPTR_WAIT;
619 break;
620 case IDC_HELP_W: //TODO: Create a cursor for this one
621 os2type = SPTR_WAIT;
622 break;
623 default:
624 return 0;
625 }
626 //Note: Does not create a copy
627 return WinQuerySysPointer(HWND_DESKTOP, os2type, FALSE);
628}
629//******************************************************************************
630//******************************************************************************
631VOID OSLibWinDestroyPointer(HANDLE hPointer)
632{
633 WinDestroyPointer(hPointer);
634}
635//******************************************************************************
636//******************************************************************************
637BOOL OSLibWinSetPointer(HANDLE hPointer)
638{
639 return WinSetPointer(HWND_DESKTOP, hPointer);
640}
641//******************************************************************************
642//******************************************************************************
643HANDLE OSLibWinQueryPointer()
644{
645 return WinQueryPointer(HWND_DESKTOP);
646}
647//******************************************************************************
648//******************************************************************************
649BOOL OSLibWinClipCursor(const RECT * pRect)
650{
651 RECTL rectl;
652 PRECTL ptr = NULL;
653
654 if (pRect != NULL)
655 {
656 rectl.xLeft = max(pRect->left, 0);
657 rectl.xRight = min(pRect->right, ScreenWidth-1);
658 rectl.yBottom = max(ScreenHeight - pRect->bottom, 0);
659 rectl.yTop = min(ScreenHeight - pRect->top, ScreenHeight-1);
660 ptr = &rectl;
661 }
662 return WinSetPointerClipRect (HWND_DESKTOP, ptr);
663}
664//******************************************************************************
665//******************************************************************************
666BOOL OSLibWinGetClipCursor(LPRECT pRect)
667{
668 RECTL rectl;
669
670 if (WinQueryPointerClipRect(HWND_DESKTOP, &rectl))
671 {
672 pRect->left = rectl.xLeft;
673 pRect->right = rectl.xRight;
674 pRect->bottom = ScreenHeight - rectl.yBottom;
675 pRect->top = ScreenHeight - rectl.yTop;
676 return TRUE;
677 }
678 return FALSE;
679}
680//******************************************************************************
681//******************************************************************************
682static char *OSLibStripPath(char *path)
683{
684 char *pszFilename;
685 char *pszFilename1;
686
687 pszFilename = strrchr(path, '\\'); /* find rightmost backslash */
688 pszFilename1 = strrchr(path, '/'); /* find rightmost slash */
689 if(pszFilename > pszFilename1 && pszFilename != NULL)
690 return (++pszFilename); /* return pointer to next character */
691
692 if (pszFilename1 != NULL)
693 return (++pszFilename1); /* return pointer to next character */
694
695 return (path); /* default return value */
696}
697//******************************************************************************
698//******************************************************************************
699void OSLibStripFile(char *path)
700{
701 char *pszFilename;
702 char *pszFilename1;
703
704 pszFilename = strrchr(path, '\\'); /* find rightmost backslash */
705 pszFilename1 = strrchr(path, '/'); /* find rightmost slash */
706 if(pszFilename > pszFilename1 && pszFilename != NULL)
707 *pszFilename = 0;
708 else
709 if (pszFilename1 != NULL)
710 *pszFilename1 = 0;
711}
712//******************************************************************************
713//******************************************************************************
714BOOL WIN32API OSLibWinCreateObject(LPSTR pszPath, LPSTR pszArgs,
715 LPSTR pszWorkDir, LPSTR pszLink,
716 LPSTR pszDescription, LPSTR pszIcoPath,
717 INT iIcoNdx, BOOL fDesktop)
718{
719 HOBJECT hObject = 0;
720 LPSTR pszName;
721 LPSTR pszSetupString;
722 LPSTR pszFolder;
723 char szSystemDir[256];
724 char temp[128];
725 char szWorkDir[256];
726
727 if(pszName) {
728 char *tmp;
729 pszName = OSLibStripPath(pszLink);
730 tmp = pszName;
731 while(*tmp) {
732 if(*tmp == '.') {
733 *tmp = 0;
734 break;
735 }
736 tmp++;
737 }
738 }
739 dprintf(("OSLibWinCreateObject %s %s %s\n %s %s %s %d %d", pszPath, pszArgs,
740 pszWorkDir, pszName, pszDescription, pszIcoPath, iIcoNdx, fDesktop));
741 dprintf(("Link path %s", pszLink));
742
743 GetSystemDirectoryA(szSystemDir, sizeof(szSystemDir));
744 if(pszWorkDir && *pszWorkDir) {
745 strcpy(szWorkDir, pszWorkDir);
746 }
747 else {
748 strcpy(szWorkDir, pszPath);
749 OSLibStripFile(szWorkDir);
750 }
751
752 pszSetupString = (LPSTR)malloc(128 + strlen(pszPath) + strlen(pszName) +
753 strlen(pszLink) + 2*strlen(szSystemDir) +
754 strlen(szWorkDir) + strlen(pszIcoPath) +
755 ((pszArgs) ? strlen(pszArgs) : 0) +
756 ((pszWorkDir) ? strlen(pszWorkDir) : 0));
757
758 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);
759 if(pszArgs && *pszArgs) {
760 strcat(pszSetupString, " ");
761 strcat(pszSetupString, pszArgs);
762 }
763 strcat(pszSetupString, ";");
764
765 if(fDesktop) {
766 dprintf(("Name = %s", pszName));
767 dprintf(("Setup string = %s", pszSetupString));
768 hObject = WinCreateObject("WPProgram", pszName, pszSetupString,
769 "<WP_DESKTOP>", CO_REPLACEIFEXISTS);
770 }
771 else {
772 //e.g.: Link path k:\source\odin32\bin\win\Start Menu\Programs\Winamp\Winamp
773 OSLibStripFile(pszLink);
774 pszFolder = OSLibStripPath(pszLink);
775 sprintf(temp, "<FOLDER_%s>", pszFolder);
776 sprintf(szWorkDir, "OBJECTID=%s;", temp);
777 hObject = WinCreateObject("WPFolder", pszFolder, szWorkDir,
778 "<ODINFOLDER>", CO_UPDATEIFEXISTS);
779 hObject = WinCreateObject("WPProgram", pszName, pszSetupString,
780 temp, CO_REPLACEIFEXISTS);
781 }
782// If SysCreateObject("WPProgram", "WarpMix", "<ICHAUDIO>",,
783// "PROGTYPE=PM;OBJECTID=<WARPMIX>;ICONFILE=WARPMIX.ICO;EXENAME="||bootDrive||"\MMOS2\WARPMIX.EXE")
784
785 free(pszSetupString);
786 if(!hObject) {
787 dprintf(("ERROR: WinCreateObject failed!!"));
788 }
789 return hObject != 0;
790}
791//******************************************************************************
792//******************************************************************************
793
Note: See TracBrowser for help on using the repository browser.