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