1 | /* $Id: oslibres.cpp,v 1.21 2001-10-02 17:14:09 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 | //NOTE: Depends on origin of bitmap data!!!
|
---|
236 | // Assumes 1 bpp bitmaps have a top left origin and all others have a bottom left origin
|
---|
237 | //******************************************************************************
|
---|
238 | HANDLE OSLibWinCreatePointer(CURSORICONINFO *pInfo, char *pAndBits, BITMAP_W *pAndBmp, char *pXorBits,
|
---|
239 | BITMAP_W *pXorBmp, BOOL fCursor)
|
---|
240 | {
|
---|
241 | POINTERINFO pointerInfo = {0};
|
---|
242 | HANDLE hPointer;
|
---|
243 | HBITMAP hbmColor = 0, hbmMask = 0;
|
---|
244 | BITMAPINFO2 *pBmpColor, *pBmpMask;
|
---|
245 | int masksize, colorsize, rgbsize, i;
|
---|
246 | HPS hps;
|
---|
247 | char *dest, *src;
|
---|
248 |
|
---|
249 | hps = WinGetScreenPS(HWND_DESKTOP);
|
---|
250 | //SvL: 2*sizeof(RGB2) is enough, but GpiCreateBitmap seems to touch more
|
---|
251 | // memory. (Adobe Photoshop 6 running in the debugger)
|
---|
252 | masksize = sizeof(BITMAPINFO2) + (pAndBmp->bmHeight * 2 * pAndBmp->bmWidthBytes) + 16*sizeof(RGB2);
|
---|
253 | pBmpMask = (BITMAPINFO2 *)malloc(masksize);
|
---|
254 | if(pBmpMask == NULL) {
|
---|
255 | DebugInt3();
|
---|
256 | return 0;
|
---|
257 | }
|
---|
258 | memset(pBmpMask, 0, masksize);
|
---|
259 | pBmpMask->cbFix = sizeof(BITMAPINFOHEADER2);
|
---|
260 | pBmpMask->cx = (USHORT)pAndBmp->bmWidth;
|
---|
261 | pBmpMask->cy = (USHORT)pAndBmp->bmHeight*2;
|
---|
262 | pBmpMask->cPlanes = pAndBmp->bmPlanes;
|
---|
263 | pBmpMask->cBitCount = 1;
|
---|
264 | pBmpMask->ulCompression = BCA_UNCOMP;
|
---|
265 | pBmpMask->ulColorEncoding = BCE_RGB;
|
---|
266 | memset(&pBmpMask->argbColor[0], 0, sizeof(RGB2));
|
---|
267 | memset(&pBmpMask->argbColor[1], 0xff, sizeof(RGB)); //not the reserved byte
|
---|
268 | //Xor bits are already 0
|
---|
269 | //copy And bits (must reverse scanlines because origin is top left instead of bottom left)
|
---|
270 | src = pAndBits;
|
---|
271 | dest = ((char *)&pBmpMask->argbColor[2]) + (pAndBmp->bmHeight * 2 - 1) * (pAndBmp->bmWidthBytes);
|
---|
272 | for(i=0;i<pAndBmp->bmHeight;i++) {
|
---|
273 | memcpy(dest, src, pAndBmp->bmWidthBytes);
|
---|
274 | dest -= pAndBmp->bmWidthBytes;
|
---|
275 | src += pAndBmp->bmWidthBytes;
|
---|
276 | }
|
---|
277 | hbmMask = GpiCreateBitmap(hps, (BITMAPINFOHEADER2 *)pBmpMask, CBM_INIT,
|
---|
278 | (PBYTE)&pBmpMask->argbColor[2], pBmpMask);
|
---|
279 |
|
---|
280 | if(hbmMask == GPI_ERROR) {
|
---|
281 | dprintf(("OSLibWinCreatePointer: GpiCreateBitmap failed!"));
|
---|
282 | WinReleasePS(hps);
|
---|
283 | free(pBmpMask);
|
---|
284 | return 0;
|
---|
285 | }
|
---|
286 | if(pXorBits)
|
---|
287 | {//color bitmap present
|
---|
288 | RGBQUAD *rgb;
|
---|
289 | RGB2 *os2rgb;
|
---|
290 |
|
---|
291 | if(pXorBmp->bmBitsPixel <= 8)
|
---|
292 | rgbsize = (1<<pXorBmp->bmBitsPixel)*sizeof(RGB2);
|
---|
293 | else rgbsize = 0;
|
---|
294 |
|
---|
295 | colorsize = sizeof(BITMAPINFO2) + (pXorBmp->bmHeight * pXorBmp->bmWidthBytes) + rgbsize;
|
---|
296 | pBmpColor = (BITMAPINFO2 *)malloc(colorsize);
|
---|
297 | if(pBmpColor == NULL) {
|
---|
298 | DebugInt3();
|
---|
299 | return 0;
|
---|
300 | }
|
---|
301 | memset(pBmpColor, 0, colorsize);
|
---|
302 | pBmpColor->cbFix = sizeof(BITMAPINFOHEADER2);
|
---|
303 | pBmpColor->cx = (USHORT)pXorBmp->bmWidth;
|
---|
304 | pBmpColor->cy = (USHORT)pXorBmp->bmHeight;
|
---|
305 | pBmpColor->cPlanes = pXorBmp->bmPlanes;
|
---|
306 | pBmpColor->cBitCount = pXorBmp->bmBitsPixel;
|
---|
307 | pBmpColor->ulCompression = BCA_UNCOMP;
|
---|
308 | pBmpColor->ulColorEncoding = BCE_RGB;
|
---|
309 |
|
---|
310 | os2rgb = &pBmpColor->argbColor[0];
|
---|
311 | rgb = (RGBQUAD *)(pXorBits);
|
---|
312 |
|
---|
313 | if(pXorBmp->bmBitsPixel <= 8) {
|
---|
314 | for(i=0;i<(1<<pXorBmp->bmBitsPixel);i++) {
|
---|
315 | os2rgb->bRed = rgb->rgbRed;
|
---|
316 | os2rgb->bBlue = rgb->rgbBlue;
|
---|
317 | os2rgb->bGreen = rgb->rgbGreen;
|
---|
318 | os2rgb++;
|
---|
319 | rgb++;
|
---|
320 | }
|
---|
321 | }
|
---|
322 |
|
---|
323 | if(pXorBmp->bmBitsPixel == 1) {
|
---|
324 | //copy Xor bits (must reverse scanlines because origin is top left instead of bottom left)
|
---|
325 | src = (char *)rgb;
|
---|
326 | dest = ((char *)os2rgb) + (pXorBmp->bmHeight - 1) * pXorBmp->bmWidthBytes;
|
---|
327 | for(i=0;i<pXorBmp->bmHeight;i++) {
|
---|
328 | memcpy(dest, src, pXorBmp->bmWidthBytes);
|
---|
329 | dest -= pXorBmp->bmWidthBytes;
|
---|
330 | src += pXorBmp->bmWidthBytes;
|
---|
331 | }
|
---|
332 | }
|
---|
333 | else
|
---|
334 | if(pXorBmp->bmBitsPixel == 16) {
|
---|
335 | ConvertRGB555to565(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes);
|
---|
336 | }
|
---|
337 | else memcpy(os2rgb, rgb, pXorBmp->bmHeight * pXorBmp->bmWidthBytes);
|
---|
338 |
|
---|
339 | hbmColor = GpiCreateBitmap(hps, (BITMAPINFOHEADER2 *)pBmpColor, CBM_INIT,
|
---|
340 | (PBYTE)os2rgb, pBmpColor);
|
---|
341 |
|
---|
342 | if(hbmColor == GPI_ERROR) {
|
---|
343 | dprintf(("OSLibWinCreateIcon: GpiCreateBitmap failed!"));
|
---|
344 | GpiDeleteBitmap(hbmMask);
|
---|
345 | WinReleasePS(hps);
|
---|
346 | free(pBmpMask);
|
---|
347 | return 0;
|
---|
348 | }
|
---|
349 | }
|
---|
350 |
|
---|
351 | pointerInfo.fPointer = fCursor; //FALSE = icon
|
---|
352 | pointerInfo.xHotspot = pInfo->ptHotSpot.x;
|
---|
353 | pointerInfo.yHotspot = mapY(pInfo->nHeight, pInfo->ptHotSpot.y);
|
---|
354 | pointerInfo.hbmColor = hbmColor;
|
---|
355 | pointerInfo.hbmPointer = hbmMask;
|
---|
356 | hPointer = WinCreatePointerIndirect(HWND_DESKTOP, &pointerInfo);
|
---|
357 |
|
---|
358 | if(hPointer == NULL) {
|
---|
359 | dprintf(("OSLibWinCreateCursor: WinCreatePointerIndirect failed! (lasterr=%x)", WinGetLastError(GetThreadHAB())));
|
---|
360 | }
|
---|
361 | GpiDeleteBitmap(hbmMask);
|
---|
362 | if(hbmColor) GpiDeleteBitmap(hbmColor);
|
---|
363 | WinReleasePS(hps);
|
---|
364 |
|
---|
365 | free(pBmpMask);
|
---|
366 | free(pBmpColor);
|
---|
367 | return hPointer;
|
---|
368 | }
|
---|
369 | //******************************************************************************
|
---|
370 | //******************************************************************************
|
---|
371 | HANDLE OSLibWinQuerySysIcon(ULONG type,INT w,INT h)
|
---|
372 | {
|
---|
373 | ULONG os2type = 0;
|
---|
374 | HPOINTER hPointer;
|
---|
375 |
|
---|
376 | switch(type) {
|
---|
377 | case IDI_APPLICATION_W:
|
---|
378 | os2type = SPTR_PROGRAM;
|
---|
379 | break;
|
---|
380 | case IDI_HAND_W:
|
---|
381 | os2type = SPTR_ICONWARNING;
|
---|
382 | break;
|
---|
383 | case IDI_QUESTION_W:
|
---|
384 | os2type = SPTR_ICONQUESTION;
|
---|
385 | break;
|
---|
386 | case IDI_EXCLAMATION_W:
|
---|
387 | os2type = SPTR_ICONWARNING;
|
---|
388 | break;
|
---|
389 | case IDI_ASTERISK_W:
|
---|
390 | os2type = SPTR_ICONINFORMATION;
|
---|
391 | break;
|
---|
392 | default:
|
---|
393 | return 0;
|
---|
394 | }
|
---|
395 |
|
---|
396 | hPointer = WinQuerySysPointer(HWND_DESKTOP, os2type, TRUE);
|
---|
397 |
|
---|
398 | if (hPointer)
|
---|
399 | {
|
---|
400 | INT sysW = WinQuerySysValue(HWND_DESKTOP,SV_CXICON),sysH = WinQuerySysValue(HWND_DESKTOP,SV_CYICON);
|
---|
401 |
|
---|
402 | if (sysW != w || sysH != h)
|
---|
403 | {
|
---|
404 | POINTERINFO pi;
|
---|
405 |
|
---|
406 | WinQueryPointerInfo(hPointer,&pi);
|
---|
407 | //CB: todo: change icon size
|
---|
408 |
|
---|
409 | }
|
---|
410 | }
|
---|
411 |
|
---|
412 | return hPointer;
|
---|
413 | }
|
---|
414 | //******************************************************************************
|
---|
415 | //******************************************************************************
|
---|
416 | HANDLE OSLibWinQuerySysPointer(ULONG type,INT w,INT h)
|
---|
417 | {
|
---|
418 | ULONG os2type = 0;
|
---|
419 |
|
---|
420 | switch(type) {
|
---|
421 | case IDC_ARROW_W:
|
---|
422 | os2type = SPTR_ARROW;
|
---|
423 | break;
|
---|
424 | case IDC_UPARROW_W:
|
---|
425 | os2type = SPTR_ARROW;
|
---|
426 | break;
|
---|
427 | case IDC_IBEAM_W:
|
---|
428 | os2type = SPTR_TEXT;
|
---|
429 | break;
|
---|
430 | case IDC_ICON_W:
|
---|
431 | os2type = SPTR_PROGRAM;
|
---|
432 | break;
|
---|
433 | case IDC_NO_W:
|
---|
434 | os2type = SPTR_ILLEGAL;
|
---|
435 | break;
|
---|
436 | case IDC_CROSS_W:
|
---|
437 | os2type = SPTR_MOVE;
|
---|
438 | break;
|
---|
439 | case IDC_SIZE_W:
|
---|
440 | os2type = SPTR_MOVE;
|
---|
441 | break;
|
---|
442 | case IDC_SIZEALL_W:
|
---|
443 | os2type = SPTR_MOVE;
|
---|
444 | break;
|
---|
445 | case IDC_SIZENESW_W:
|
---|
446 | os2type = SPTR_SIZENESW;
|
---|
447 | break;
|
---|
448 | case IDC_SIZENS_W:
|
---|
449 | os2type = SPTR_SIZENS;
|
---|
450 | break;
|
---|
451 | case IDC_SIZENWSE_W:
|
---|
452 | os2type = SPTR_SIZENWSE;
|
---|
453 | break;
|
---|
454 | case IDC_SIZEWE_W:
|
---|
455 | os2type = SPTR_SIZEWE;
|
---|
456 | break;
|
---|
457 | case IDC_WAIT_W:
|
---|
458 | os2type = SPTR_WAIT;
|
---|
459 | break;
|
---|
460 | case IDC_APPSTARTING_W:
|
---|
461 | os2type = SPTR_WAIT;
|
---|
462 | break;
|
---|
463 | case IDC_HELP_W: //TODO: Create a cursor for this one
|
---|
464 | os2type = SPTR_WAIT;
|
---|
465 | break;
|
---|
466 | default:
|
---|
467 | return 0;
|
---|
468 | }
|
---|
469 | //Note: Does not create a copy
|
---|
470 | return WinQuerySysPointer(HWND_DESKTOP, os2type, FALSE);
|
---|
471 | }
|
---|
472 | //******************************************************************************
|
---|
473 | //******************************************************************************
|
---|
474 | VOID OSLibWinDestroyPointer(HANDLE hPointer)
|
---|
475 | {
|
---|
476 | WinDestroyPointer(hPointer);
|
---|
477 | }
|
---|
478 | //******************************************************************************
|
---|
479 | //******************************************************************************
|
---|
480 | BOOL OSLibWinSetPointer(HANDLE hPointer)
|
---|
481 | {
|
---|
482 | return WinSetPointer(HWND_DESKTOP, hPointer);
|
---|
483 | }
|
---|
484 | //******************************************************************************
|
---|
485 | //******************************************************************************
|
---|
486 | HANDLE OSLibWinQueryPointer()
|
---|
487 | {
|
---|
488 | return WinQueryPointer(HWND_DESKTOP);
|
---|
489 | }
|
---|
490 | //******************************************************************************
|
---|
491 | //******************************************************************************
|
---|
492 | BOOL OSLibWinClipCursor(const RECT * pRect)
|
---|
493 | {
|
---|
494 | RECTL rectl;
|
---|
495 | PRECTL ptr = NULL;
|
---|
496 |
|
---|
497 | if (pRect != NULL)
|
---|
498 | {
|
---|
499 | rectl.xLeft = max(pRect->left, 0);
|
---|
500 | rectl.xRight = min(pRect->right, ScreenWidth-1);
|
---|
501 | rectl.yBottom = max(ScreenHeight - pRect->bottom, 0);
|
---|
502 | rectl.yTop = min(ScreenHeight - pRect->top, ScreenHeight-1);
|
---|
503 | ptr = &rectl;
|
---|
504 | }
|
---|
505 | return WinSetPointerClipRect (HWND_DESKTOP, ptr);
|
---|
506 | }
|
---|
507 | //******************************************************************************
|
---|
508 | //******************************************************************************
|
---|
509 | BOOL OSLibWinGetClipCursor(LPRECT pRect)
|
---|
510 | {
|
---|
511 | RECTL rectl;
|
---|
512 |
|
---|
513 | if (WinQueryPointerClipRect(HWND_DESKTOP, &rectl))
|
---|
514 | {
|
---|
515 | pRect->left = rectl.xLeft;
|
---|
516 | pRect->right = rectl.xRight;
|
---|
517 | pRect->bottom = ScreenHeight - rectl.yBottom;
|
---|
518 | pRect->top = ScreenHeight - rectl.yTop;
|
---|
519 | return TRUE;
|
---|
520 | }
|
---|
521 | return FALSE;
|
---|
522 | }
|
---|
523 | //******************************************************************************
|
---|
524 | //******************************************************************************
|
---|
525 | static char *OSLibStripPath(char *path)
|
---|
526 | {
|
---|
527 | char *pszFilename;
|
---|
528 | char *pszFilename1;
|
---|
529 |
|
---|
530 | pszFilename = strrchr(path, '\\'); /* find rightmost backslash */
|
---|
531 | pszFilename1 = strrchr(path, '/'); /* find rightmost slash */
|
---|
532 | if(pszFilename > pszFilename1 && pszFilename != NULL)
|
---|
533 | return (++pszFilename); /* return pointer to next character */
|
---|
534 |
|
---|
535 | if (pszFilename1 != NULL)
|
---|
536 | return (++pszFilename1); /* return pointer to next character */
|
---|
537 |
|
---|
538 | return (path); /* default return value */
|
---|
539 | }
|
---|
540 | //******************************************************************************
|
---|
541 | //******************************************************************************
|
---|
542 | void OSLibStripFile(char *path)
|
---|
543 | {
|
---|
544 | char *pszFilename;
|
---|
545 | char *pszFilename1;
|
---|
546 |
|
---|
547 | pszFilename = strrchr(path, '\\'); /* find rightmost backslash */
|
---|
548 | pszFilename1 = strrchr(path, '/'); /* find rightmost slash */
|
---|
549 | if(pszFilename > pszFilename1 && pszFilename != NULL)
|
---|
550 | *pszFilename = 0;
|
---|
551 | else
|
---|
552 | if (pszFilename1 != NULL)
|
---|
553 | *pszFilename1 = 0;
|
---|
554 | }
|
---|
555 | //******************************************************************************
|
---|
556 | //******************************************************************************
|
---|
557 | BOOL WIN32API OSLibWinCreateObject(LPSTR pszPath, LPSTR pszArgs,
|
---|
558 | LPSTR pszWorkDir, LPSTR pszLink,
|
---|
559 | LPSTR pszDescription, LPSTR pszIcoPath,
|
---|
560 | INT iIcoNdx, BOOL fDesktop)
|
---|
561 | {
|
---|
562 | HOBJECT hObject = 0;
|
---|
563 | LPSTR pszName;
|
---|
564 | LPSTR pszSetupString;
|
---|
565 | LPSTR pszFolder;
|
---|
566 | char szSystemDir[256];
|
---|
567 | char temp[128];
|
---|
568 | char szWorkDir[256];
|
---|
569 |
|
---|
570 | if(pszName) {
|
---|
571 | char *tmp;
|
---|
572 | pszName = OSLibStripPath(pszLink);
|
---|
573 | tmp = pszName;
|
---|
574 | while(*tmp) {
|
---|
575 | if(*tmp == '.') {
|
---|
576 | *tmp = 0;
|
---|
577 | break;
|
---|
578 | }
|
---|
579 | tmp++;
|
---|
580 | }
|
---|
581 | }
|
---|
582 | dprintf(("OSLibWinCreateObject %s %s %s\n %s %s %s %d %d", pszPath, pszArgs,
|
---|
583 | pszWorkDir, pszName, pszDescription, pszIcoPath, iIcoNdx, fDesktop));
|
---|
584 | dprintf(("Link path %s", pszLink));
|
---|
585 |
|
---|
586 | GetSystemDirectoryA(szSystemDir, sizeof(szSystemDir));
|
---|
587 | if(pszWorkDir && *pszWorkDir) {
|
---|
588 | strcpy(szWorkDir, pszWorkDir);
|
---|
589 | }
|
---|
590 | else {
|
---|
591 | strcpy(szWorkDir, pszPath);
|
---|
592 | OSLibStripFile(szWorkDir);
|
---|
593 | }
|
---|
594 |
|
---|
595 | pszSetupString = (LPSTR)malloc(128 + strlen(pszPath) + strlen(pszName) +
|
---|
596 | strlen(pszLink) + 2*strlen(szSystemDir) +
|
---|
597 | strlen(szWorkDir) + strlen(pszIcoPath) +
|
---|
598 | ((pszArgs) ? strlen(pszArgs) : 0) +
|
---|
599 | ((pszWorkDir) ? strlen(pszWorkDir) : 0));
|
---|
600 |
|
---|
601 | 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);
|
---|
602 | if(pszArgs && *pszArgs) {
|
---|
603 | strcat(pszSetupString, " ");
|
---|
604 | strcat(pszSetupString, pszArgs);
|
---|
605 | }
|
---|
606 | strcat(pszSetupString, ";");
|
---|
607 |
|
---|
608 | if(fDesktop) {
|
---|
609 | dprintf(("Name = %s", pszName));
|
---|
610 | dprintf(("Setup string = %s", pszSetupString));
|
---|
611 | hObject = WinCreateObject("WPProgram", pszName, pszSetupString,
|
---|
612 | "<WP_DESKTOP>", CO_REPLACEIFEXISTS);
|
---|
613 | }
|
---|
614 | else {
|
---|
615 | //e.g.: Link path k:\source\odin32\bin\win\Start Menu\Programs\Winamp\Winamp
|
---|
616 | OSLibStripFile(pszLink);
|
---|
617 | pszFolder = OSLibStripPath(pszLink);
|
---|
618 | sprintf(temp, "<FOLDER_%s>", pszFolder);
|
---|
619 | sprintf(szWorkDir, "OBJECTID=%s;", temp);
|
---|
620 | hObject = WinCreateObject("WPFolder", pszFolder, szWorkDir,
|
---|
621 | "<ODINFOLDER>", CO_UPDATEIFEXISTS);
|
---|
622 | hObject = WinCreateObject("WPProgram", pszName, pszSetupString,
|
---|
623 | temp, CO_REPLACEIFEXISTS);
|
---|
624 | }
|
---|
625 | // If SysCreateObject("WPProgram", "WarpMix", "<ICHAUDIO>",,
|
---|
626 | // "PROGTYPE=PM;OBJECTID=<WARPMIX>;ICONFILE=WARPMIX.ICO;EXENAME="||bootDrive||"\MMOS2\WARPMIX.EXE")
|
---|
627 |
|
---|
628 | free(pszSetupString);
|
---|
629 | if(!hObject) {
|
---|
630 | dprintf(("ERROR: WinCreateObject failed!!"));
|
---|
631 | }
|
---|
632 | return hObject != 0;
|
---|
633 | }
|
---|
634 | //******************************************************************************
|
---|
635 | //******************************************************************************
|
---|
636 |
|
---|