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