source: trunk/src/user32/winicon.cpp@ 7788

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

CreateIconIndirect bugfix

File size: 61.4 KB
Line 
1/* $Id: winicon.cpp,v 1.33 2001-10-27 10:30:11 sandervl Exp $ */
2/*
3 * Win32 Icon Code for OS/2
4 *
5 *
6 * Copyright 1998 Sander van Leeuwen (sandervl@xs4all.nl) (OS/2 Port)
7 *
8 * Based on Wine code (objects\bitmap.c, loader\resource.c, objects\cursoricon.c):
9 *
10 * Copyright 1993 Alexandre Julliard
11 * 1993 Robert J. Amstadt
12 * 1996 Martin Von Loewis
13 * 1997 Alex Korobka
14 * 1998 Turchanov Sergey
15 * 1998 Huw D M Davies
16 * Theory:
17 *
18 * http://www.microsoft.com/win32dev/ui/icons.htm
19 *
20 * Cursors and icons are stored in a global heap block, with the
21 * following layout:
22 *
23 * CURSORICONINFO info;
24 * BYTE[] ANDbits;
25 * BYTE[] XORbits;
26 *
27 * The bits structures are in the format of a device-dependent bitmap.
28 *
29 * This layout is very sub-optimal, as the bitmap bits are stored in
30 * the X client instead of in the server like other bitmaps; however,
31 * some programs (notably Paint Brush) expect to be able to manipulate
32 * the bits directly :-(
33 *
34 * FIXME: what are we going to do with animation and color (bpp > 1) cursors ?!
35 *
36 **************************************************************************************************
37 *
38 * TODO: Scaling of system cursors (store them as resources in user32 instead of using PM pointers)
39 * TODO: We use the hColorBmp member of the CURSORICONINFO structure to store the PM cursor handle
40 * Might mess up PaintBrush (see above)
41 *
42 * Project Odin Software License can be found in LICENSE.TXT
43 *
44 */
45#include <os2win.h>
46#include <stdio.h>
47#include <string.h>
48#include <winicon.h>
49#include <win\cursoricon.h>
50#include <objhandle.h>
51#include "dib.h"
52#include <heapstring.h>
53#include <win\virtual.h>
54#include "initterm.h"
55#include "oslibres.h"
56#include "oslibwin.h"
57#include "dc.h"
58
59#define DBG_LOCALLOG DBG_winicon
60#include "dbglocal.h"
61
62
63/**********************************************************************
64 * ICONCACHE for cursors/icons loaded with LR_SHARED.
65 *
66 * FIXME: This should not be allocated on the system heap, but on a
67 * subsystem-global heap (i.e. one for all Win16 processes,
68 * and one for each Win32 process).
69 */
70typedef struct tagICONCACHE
71{
72 struct tagICONCACHE *next;
73
74 HMODULE hModule;
75 HRSRC hRsrc;
76 HRSRC hGroupRsrc;
77 HANDLE handle;
78 INT count;
79} ICONCACHE;
80
81static ICONCACHE *IconAnchor = NULL;
82static CRITICAL_SECTION IconCrst = CRITICAL_SECTION_INIT;
83static WORD ICON_HOTSPOT = 0x4242;
84static HCURSOR hActiveCursor = 0;
85static HCURSOR hActiveCursorPM = 0;
86
87
88static HGLOBAL CURSORICON_CreateFromResource( HINSTANCE hInstance, DWORD dwResGroupId, HGLOBAL hObj, LPBYTE bits,
89 UINT cbSize, BOOL bIcon, DWORD dwVersion, INT width, INT height, UINT loadflags );
90static HGLOBAL CURSORICON_Copy( HGLOBAL handle );
91static CURSORICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width,
92 int height, int colors );
93static CURSORICONDIRENTRY *CURSORICON_FindBestCursor( CURSORICONDIR *dir,
94 int width, int height, int color);
95BOOL CURSORICON_SimulateLoadingFromResourceW( LPWSTR filename, BOOL fCursor,
96 CURSORICONDIR **res, LPBYTE **ptr);
97
98static INT CURSORICON_DelSharedIcon( HANDLE handle );
99static void CURSORICON_AddSharedIcon( HMODULE hModule, HRSRC hRsrc, HRSRC hGroupRsrc, HANDLE handle );
100static HANDLE CURSORICON_FindSharedIcon( HMODULE hModule, HRSRC hRsrc );
101static ICONCACHE* CURSORICON_FindCache(HANDLE handle);
102
103static HGLOBAL CreateCursorIconIndirect( HINSTANCE hInstance,
104 CURSORICONINFO *info,
105 LPCVOID lpANDbits,
106 LPCVOID lpXORbits, BOOL fIcon);
107
108/***********************************************************************
109 * CreateIcon (USER32.75)
110 */
111HICON WIN32API CreateIcon(HINSTANCE hInstance, INT nWidth,
112 INT nHeight, BYTE bPlanes, BYTE bBitsPixel,
113 LPCVOID lpANDbits, LPCVOID lpXORbits )
114{
115 CURSORICONINFO info;
116
117 dprintf(("USER32: CreateIcon (%d,%d), %d, %x, %x", nWidth, nHeight, bPlanes * bBitsPixel, lpXORbits, lpANDbits));
118
119 info.ptHotSpot.x = ICON_HOTSPOT;
120 info.ptHotSpot.y = ICON_HOTSPOT;
121 info.nWidth = nWidth;
122 info.nHeight = nHeight;
123 info.nWidthBytes = 0;
124 info.bPlanes = bPlanes;
125 info.bBitsPerPixel = bBitsPixel;
126 info.hInstance = hInstance;
127 info.dwResGroupId = -1;
128 info.hColorBmp = 0;
129 return CreateCursorIconIndirect(0, &info, lpANDbits, lpXORbits, TRUE);
130}
131/**********************************************************************
132 * CreateIconFromResource (USER32.76)
133 */
134HICON WIN32API CreateIconFromResource(LPBYTE bits, UINT cbSize,
135 BOOL bIcon, DWORD dwVersion)
136{
137 return CreateIconFromResourceEx( bits, cbSize, bIcon, dwVersion, 0,0,0);
138}
139//******************************************************************************
140//******************************************************************************
141HICON WIN32API CreateIconFromResourceEx(LPBYTE bits, UINT cbSize,
142 BOOL bIcon, DWORD dwVersion,
143 INT width, INT height,
144 UINT cFlag )
145{
146 dprintf(("USER32: CreateIconFromResourceEx %X %d %d %X %d %d %X,", bits, cbSize, bIcon, dwVersion, width, height, cFlag));
147 return CURSORICON_CreateFromResource(0, -1, 0, bits, cbSize, bIcon, dwVersion, width, height, cFlag );
148}
149/**********************************************************************
150 * CreateIconIndirect (USER32.78)
151 */
152HICON WINAPI CreateIconIndirect(ICONINFO *iconinfo)
153{
154 BITMAP bmpXor,bmpAnd;
155 HICON hObj;
156 int sizeXor,sizeAnd,colortablesize;
157
158 dprintf(("USER32: CreateIconIndirect %x %x %x %s", iconinfo, iconinfo->hbmMask, iconinfo->hbmColor, (iconinfo->fIcon) ? "icon" : "cursor"));
159
160 GetObjectA( iconinfo->hbmColor, sizeof(bmpXor), &bmpXor );
161 GetObjectA( iconinfo->hbmMask, sizeof(bmpAnd), &bmpAnd );
162
163 colortablesize = 0;
164
165 if(bmpXor.bmBitsPixel <= 8) {
166 colortablesize = sizeof(RGBQUAD)*(1<<bmpXor.bmBitsPixel);
167 sizeXor = bmpXor.bmHeight * bmpXor.bmWidthBytes + colortablesize;
168 }
169 else sizeXor = bmpXor.bmHeight * bmpXor.bmWidthBytes;
170
171 sizeAnd = bmpAnd.bmHeight * bmpAnd.bmWidthBytes;
172
173 hObj = GlobalAlloc( GMEM_MOVEABLE, sizeof(CURSORICONINFO) + sizeXor + sizeAnd );
174 if (hObj)
175 {
176 CURSORICONINFO *info;
177
178 info = (CURSORICONINFO *)GlobalLock( hObj );
179
180 /* If we are creating an icon, the hotspot is unused */
181 if (iconinfo->fIcon)
182 {
183 info->ptHotSpot.x = ICON_HOTSPOT;
184 info->ptHotSpot.y = ICON_HOTSPOT;
185 }
186 else
187 {
188 info->ptHotSpot.x = iconinfo->xHotspot;
189 info->ptHotSpot.y = iconinfo->yHotspot;
190 }
191
192 info->nWidth = bmpXor.bmWidth;
193 info->nHeight = bmpXor.bmHeight;
194 info->nWidthBytes = bmpXor.bmWidthBytes;
195 info->bPlanes = bmpXor.bmPlanes;
196 info->bBitsPerPixel = bmpXor.bmBitsPixel;
197 info->hInstance = -1;
198 info->dwResGroupId = -1;
199 info->hColorBmp = 0;
200
201 /* Transfer the bitmap bits to the CURSORICONINFO structure */
202 GetBitmapBits( iconinfo->hbmMask ,sizeAnd,(char*)(info + 1) );
203 if(bmpXor.bmBitsPixel > 1)
204 {
205 BITMAPINFO* pInfo = (BITMAPINFO *)malloc(sizeof(BITMAPINFO)+colortablesize+3*sizeof(DWORD)); //+ extra space for > 8bpp images
206 HBITMAP oldbmp;
207 HDC hdc;
208
209 hdc = CreateCompatibleDC(0);
210
211 memset(pInfo, 0, sizeof(BITMAPINFO)+colortablesize+3*sizeof(DWORD));
212 pInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
213 pInfo->bmiHeader.biPlanes = info->bPlanes;
214 pInfo->bmiHeader.biBitCount = info->bBitsPerPixel;
215
216 GetDIBits(hdc, iconinfo->hbmColor, 0, bmpXor.bmHeight, (char *)(info + 1) + sizeAnd + colortablesize, pInfo, DIB_RGB_COLORS);
217 if(colortablesize) {
218 memcpy((char *)(info + 1) + sizeAnd, (char *)&pInfo->bmiHeader + pInfo->bmiHeader.biSize, colortablesize);
219 }
220
221 DeleteDC(hdc);
222 free(pInfo);
223 }
224 else {
225 GetBitmapBits( iconinfo->hbmColor,sizeXor,(char*)(info + 1) +sizeAnd);
226 }
227
228#ifdef __WIN32OS2__
229 info->hColorBmp = OSLibWinCreatePointer(info, (char*)(info + 1), (LPBITMAP_W)&bmpAnd, (char*)(info + 1) + sizeAnd, (LPBITMAP_W)&bmpXor, iconinfo->fIcon == FALSE);
230#endif
231 GlobalUnlock(hObj);
232
233#ifdef __WIN32OS2__
234 HICON hIcon;
235 if(ObjAllocateHandle(&hIcon, (DWORD)hObj, USEROBJ_CURSORICON) == FALSE) {
236 GlobalFree(hObj);
237 dprintf(("ERROR: CreateIconIndirect ObjAllocateHandle failed!!"));
238 return 0;
239 }
240#endif
241 dprintf(("USER32: CreateIconIndirect %x returned %x", iconinfo, hIcon));
242 return hIcon;
243 }
244 else {
245 dprintf(("ERROR: CreateIconIndirect GlobalAlloc failed!!"));
246 return 0;
247 }
248}
249//******************************************************************************
250//******************************************************************************
251BOOL WIN32API DestroyIcon( HICON hIcon)
252{
253 dprintf(("USER32: DestroyIcon %x", hIcon));
254 return CURSORICON_Destroy( hIcon, 0 );
255}
256//******************************************************************************
257//******************************************************************************
258HICON WIN32API CopyIcon( HICON hIcon)
259{
260 dprintf(("USER32: CopyIcon %x", hIcon));
261 return CURSORICON_Copy( hIcon );
262}
263//******************************************************************************
264//******************************************************************************
265HICON WIN32API GetOS2Icon(HICON hIcon)
266{
267 CURSORICONINFO *ciconinfo;
268
269 hIcon = ObjGetHandleData(hIcon, USEROBJ_CURSORICON);
270 if(hIcon == -1) {
271 dprintf(("ERROR: Invalid cursor/icon!"));
272 return 0;
273 }
274 ciconinfo = (CURSORICONINFO *)GlobalLock((HGLOBAL)hIcon);
275 if (!ciconinfo)
276 return 0;
277 HICON hOS2Icon = ciconinfo->hColorBmp;
278 GlobalUnlock(hIcon);
279 return hOS2Icon;
280}
281/**********************************************************************
282 * GetIconInfo (USER32.242)
283 */
284BOOL WINAPI GetIconInfo(HICON hIcon, ICONINFO *iconinfo)
285{
286 CURSORICONINFO *ciconinfo;
287
288 dprintf(("GetIconInfo %x %x", hIcon, iconinfo));
289
290#ifdef __WIN32OS2__
291 hIcon = ObjGetHandleData(hIcon, USEROBJ_CURSORICON);
292 if(hIcon == -1) {
293 dprintf(("ERROR: Invalid cursor/icon!"));
294 return 0;
295 }
296#endif
297 ciconinfo = (CURSORICONINFO *)GlobalLock((HGLOBAL)hIcon);
298 if (!ciconinfo)
299 return FALSE;
300
301 if((ciconinfo->ptHotSpot.x == ICON_HOTSPOT) &&
302 (ciconinfo->ptHotSpot.y == ICON_HOTSPOT))
303 {
304 iconinfo->fIcon = TRUE;
305 iconinfo->xHotspot = ciconinfo->nWidth / 2;
306 iconinfo->yHotspot = ciconinfo->nHeight / 2;
307 }
308 else
309 {
310 iconinfo->fIcon = FALSE;
311 iconinfo->xHotspot = ciconinfo->ptHotSpot.x;
312 iconinfo->yHotspot = ciconinfo->ptHotSpot.y;
313 }
314
315 //Create new bitmaps for the color and mask data; application is responsible
316 //for deleteing them (according to docs & verified in NT4)
317 if(ciconinfo->bBitsPerPixel > 1)
318 {
319 BITMAPINFO* pInfo;
320 int colorsize = 0;
321 int coloroff;
322
323 HDC hdc = CreateCompatibleDC(0);
324
325 if(ciconinfo->bBitsPerPixel <= 8) {
326 colorsize = (1<<ciconinfo->bBitsPerPixel)*sizeof(RGBQUAD);
327 }
328 else {
329 colorsize = 3*sizeof(DWORD); //color masks
330 }
331 pInfo = (BITMAPINFO *)malloc(ciconinfo->nHeight * ciconinfo->nWidthBytes + colorsize + sizeof(BITMAPINFO));
332 memset(pInfo, 0, sizeof(BITMAPINFO)+colorsize);
333
334 pInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
335 pInfo->bmiHeader.biWidth = ciconinfo->nWidth;
336 pInfo->bmiHeader.biHeight = ciconinfo->nHeight,
337 pInfo->bmiHeader.biPlanes = ciconinfo->bPlanes;
338 pInfo->bmiHeader.biBitCount = ciconinfo->bBitsPerPixel;
339 pInfo->bmiHeader.biSizeImage= ciconinfo->nHeight * ciconinfo->nWidthBytes;
340
341 //offset in cursorinfo memory
342 coloroff = ciconinfo->nHeight * BITMAP_GetWidthBytes (ciconinfo->nWidth, 1);
343
344 char *src = (char *)(ciconinfo + 1) + coloroff;
345 if(ciconinfo->bBitsPerPixel <= 8) {
346 src += colorsize; //no color masks in cursorinfo data for bpp > 8
347 }
348 if(ciconinfo->bBitsPerPixel <= 8) {
349 memcpy(&pInfo->bmiColors[0], (char *)(ciconinfo + 1) + coloroff, colorsize);
350 }
351 //else TODO: color masks (currently unused in CreateDIBitmap)
352
353 iconinfo->hbmColor = CreateDIBitmap(hdc, &pInfo->bmiHeader, CBM_INIT, src, pInfo, DIB_RGB_COLORS);
354
355 free(pInfo);
356 DeleteDC(hdc);
357 }
358 else {
359 iconinfo->hbmColor = CreateBitmap ( ciconinfo->nWidth, ciconinfo->nHeight,
360 ciconinfo->bPlanes, ciconinfo->bBitsPerPixel,
361 (char *)(ciconinfo + 1)
362 + ciconinfo->nHeight *
363 BITMAP_GetWidthBytes (ciconinfo->nWidth, 1) );
364 }
365
366 iconinfo->hbmMask = CreateBitmap ( ciconinfo->nWidth, ciconinfo->nHeight,
367 1, 1, (char *)(ciconinfo + 1));
368
369 GlobalUnlock(hIcon);
370
371 return TRUE;
372}
373//******************************************************************************
374//******************************************************************************
375HCURSOR WIN32API CreateCursor(HINSTANCE hInst, int xHotSpot, int yHotSpot, int nWidth, int nHeight,
376 const VOID *lpANDbits, const VOID *lpXORbits)
377{
378 CURSORICONINFO info;
379
380 dprintf(("CreateCursor %dx%d spot=%d,%d xor=%p and=%p\n",
381 nWidth, nHeight, xHotSpot, yHotSpot, lpXORbits, lpANDbits));
382
383 info.ptHotSpot.x = xHotSpot;
384 info.ptHotSpot.y = yHotSpot;
385 info.nWidth = nWidth;
386 info.nHeight = nHeight;
387 info.nWidthBytes = 0;
388 info.bPlanes = 1;
389 info.bBitsPerPixel = 1;
390 info.hInstance = hInst;
391 info.dwResGroupId = -1;
392 info.hColorBmp = 0;
393
394 return CreateCursorIconIndirect( 0, &info, lpANDbits, lpXORbits, FALSE);
395}
396//******************************************************************************
397//******************************************************************************
398BOOL WIN32API DestroyCursor( HCURSOR hCursor)
399{
400 dprintf(("USER32: DestroyCursor %x", hCursor));
401 return CURSORICON_Destroy( hCursor, CID_WIN32 );
402}
403//******************************************************************************
404//******************************************************************************
405HCURSOR WIN32API GetCursor(void)
406{
407 dprintf2(("USER32: GetCursor"));
408 if(hActiveCursorPM && hActiveCursorPM != OSLibWinQueryPointer()) {
409 dprintf(("Another app changed mouse cursor"));
410 hActiveCursorPM = hActiveCursor = 0;
411 }
412 return hActiveCursor;
413}
414//******************************************************************************
415//******************************************************************************
416HCURSOR WIN32API SetCursor( HCURSOR hCursor)
417{
418 HCURSOR hOldCursor;
419
420 dprintf(("USER32: SetCursor %x (prev %x)", hCursor, hActiveCursor));
421 GetCursor();
422 if (hCursor == hActiveCursor) return hActiveCursor; /* No change */
423
424 hOldCursor = hActiveCursor;
425 hActiveCursor = hCursor;
426
427#ifdef __WIN32OS2__
428 hCursor = ObjGetHandleData(hCursor, USEROBJ_CURSORICON);
429 if(hCursor == -1) {
430 dprintf(("ERROR: Invalid cursor/icon!"));
431 return 0;
432 }
433#endif
434
435 CURSORICONINFO *iconinfo = (CURSORICONINFO *)GlobalLock((HGLOBAL)hCursor);
436 if (!iconinfo) {
437 dprintf(("ERROR: Invalid cursor!"));
438 return 0;
439 }
440 if(!iconinfo->hColorBmp) {
441 dprintf(("SetCursor: invalid os/2 pointer handle!!"));
442 }
443
444 dprintf2(("OSLibWinSetPointer %x", iconinfo->hColorBmp));
445 if(OSLibWinSetPointer(iconinfo->hColorBmp) == FALSE) {
446 dprintf(("OSLibWinSetPointer %x returned FALSE!!", iconinfo->hColorBmp));
447 }
448 hActiveCursorPM = iconinfo->hColorBmp;
449 GlobalUnlock(hCursor);
450
451 return hOldCursor;
452}
453//******************************************************************************
454//******************************************************************************
455BOOL WIN32API GetCursorPos( PPOINT lpPoint)
456{
457 dprintf2(("USER32: GetCursorPos %x", lpPoint));
458
459 if (!lpPoint) return FALSE;
460
461 if (OSLibWinQueryPointerPos(lpPoint)) //POINT == POINTL
462 {
463 mapScreenPoint((OSLIBPOINT*)lpPoint);
464 return TRUE;
465 }
466 else return FALSE;
467}
468//******************************************************************************
469//******************************************************************************
470BOOL WIN32API SetCursorPos( int X, int Y)
471{
472 dprintf(("USER32: SetCursorPos %d %d", X,Y));
473 return OSLibWinSetPointerPos(X, mapScreenY(Y));
474}
475//******************************************************************************
476//******************************************************************************
477BOOL WIN32API ClipCursor(const RECT * lpRect)
478{
479 if(lpRect) {
480 dprintf(("USER32: ClipCursor (%d,%d)(%d,%d)", lpRect->left, lpRect->top, lpRect->right, lpRect->bottom));
481 }
482 else dprintf(("USER32: ClipCursor NULL"));
483 return OSLibWinClipCursor(lpRect);
484}
485//******************************************************************************
486//******************************************************************************
487BOOL WIN32API GetClipCursor( LPRECT lpRect)
488{
489 dprintf(("USER32: GetClipCursor %x", lpRect));
490 return OSLibWinGetClipCursor(lpRect);
491}
492//******************************************************************************
493//******************************************************************************
494/*****************************************************************************
495 * Name : BOOL WIN32API SetSystemCursor
496 * Purpose : The SetSystemCursor function replaces the contents of the system
497 * cursor specified by dwCursorId with the contents of the cursor
498 * specified by hCursor, and then destroys hCursor. This function
499 * lets an application customize the system cursors.
500 * Parameters: HCURSOR hCursor set specified system cursor to this cursor's
501 * contents, then destroy this
502 * DWORD dwCursorID system cursor specified by its identifier
503 * Variables :
504 * Result : If the function succeeds, the return value is TRUE.
505 * If the function fails, the return value is FALSE. To get extended
506 * error information, call GetLastError.
507 * Remark :
508 * Status : UNTESTED STUB
509 *
510 * Author : Patrick Haller [Thu, 1998/02/26 11:55]
511 *****************************************************************************/
512BOOL WIN32API SetSystemCursor(HCURSOR hCursor, DWORD dwCursorId)
513{
514 dprintf(("USER32:SetSystemCursor (%08xh,%08x) not supported.\n",
515 hCursor,
516 dwCursorId));
517
518 return DestroyCursor(hCursor);
519}
520//******************************************************************************
521//******************************************************************************
522INT OPEN32API __ShowCursor(BOOL bShow);
523
524inline INT _ShowCursor (BOOL bShow)
525{
526 INT yyrc;
527 USHORT sel = RestoreOS2FS();
528
529 yyrc = __ShowCursor(bShow);
530 SetFS(sel);
531
532 return yyrc;
533}
534//******************************************************************************
535static int cursorshowcnt = 0;
536//******************************************************************************
537void RestoreCursor()
538{
539 dprintf2(("USER32: RestoreCursor %d", cursorshowcnt));
540 while(cursorshowcnt != 0)
541 {
542 if(cursorshowcnt > 0 )
543 {
544 ShowCursor(FALSE);
545 }
546 else
547 {
548 ShowCursor(TRUE);
549 }
550 }
551}
552//******************************************************************************
553//******************************************************************************
554int WIN32API ShowCursor(BOOL bShow)
555{
556 dprintf2(("USER32: ShowCursor %d", bShow));
557 cursorshowcnt = cursorshowcnt + ((bShow) ? 1 : -1);
558 return _ShowCursor(bShow);
559}
560/***********************************************************************
561 * CreateCursorIconIndirect
562 */
563static HGLOBAL CreateCursorIconIndirect( HINSTANCE hInstance,
564 CURSORICONINFO *info,
565 LPCVOID lpANDbits,
566 LPCVOID lpXORbits, BOOL fIcon)
567{
568 HGLOBAL handle;
569 char *ptr;
570 int sizeAnd, sizeXor;
571#ifdef __WIN32OS2__
572 BITMAP bmpXor, bmpAnd;
573#endif
574
575 if (!lpXORbits || !lpANDbits || info->bPlanes != 1) return 0;
576 info->nWidthBytes = BITMAP_GetWidthBytes(info->nWidth,info->bBitsPerPixel);
577 sizeXor = info->nHeight * info->nWidthBytes;
578 sizeAnd = info->nHeight * BITMAP_GetWidthBytes( info->nWidth, 1 );
579 if (!(handle = GlobalAlloc( GMEM_MOVEABLE,
580 sizeof(CURSORICONINFO) + sizeXor + sizeAnd)))
581 return 0;
582 ptr = (char *)GlobalLock( handle );
583 memcpy( ptr, info, sizeof(*info) );
584 memcpy( ptr + sizeof(CURSORICONINFO), lpANDbits, sizeAnd );
585 memcpy( ptr + sizeof(CURSORICONINFO) + sizeAnd, lpXORbits, sizeXor );
586#ifdef __WIN32OS2__
587 bmpAnd.bmType = 0;
588 bmpAnd.bmWidth = info->nWidth;
589 bmpAnd.bmHeight = info->nHeight;
590 bmpAnd.bmWidthBytes = BITMAP_GetWidthBytes(info->nWidth, 1);
591 bmpAnd.bmPlanes = info->bPlanes;
592 bmpAnd.bmBitsPixel = 1;
593 bmpAnd.bmBits = NULL;
594
595 bmpXor.bmType = 0;
596 bmpXor.bmWidth = info->nWidth;
597 bmpXor.bmHeight = info->nHeight;
598 bmpXor.bmWidthBytes = info->nWidthBytes;
599 bmpXor.bmPlanes = info->bPlanes;
600 bmpXor.bmBitsPixel = info->bBitsPerPixel;
601 bmpXor.bmBits = NULL;
602 ((CURSORICONINFO *)ptr)->hColorBmp =
603 OSLibWinCreatePointer(info, (char *)lpANDbits, (LPBITMAP_W)&bmpAnd, (char *)lpXORbits, (LPBITMAP_W)&bmpXor, fIcon == FALSE);
604#endif
605 GlobalUnlock( handle );
606
607#ifdef __WIN32OS2__
608 HICON hIcon;
609 if(ObjAllocateHandle(&hIcon, (DWORD)handle, USEROBJ_CURSORICON) == FALSE) {
610 GlobalFree(handle);
611 dprintf(("ERROR: CreateCursorIconIndirect ObjAllocateHandle failed!!"));
612 return 0;
613 }
614 dprintf(("USER32: CreateCursorIconIndirect returned %x", hIcon));
615 return hIcon;
616#else
617 return handle;
618#endif
619}
620/**********************************************************************
621 * CURSORICON_Load
622 *
623 * Load a cursor or icon from resource or file.
624 */
625HGLOBAL CURSORICON_Load( HINSTANCE hInstance, LPCWSTR name,
626 INT width, INT height, INT colors,
627 BOOL fCursor, UINT loadflags )
628{
629 HANDLE handle = 0, h = 0;
630 HANDLE hRsrc;
631 CURSORICONDIR *dir;
632 CURSORICONDIRENTRY *dirEntry;
633 LPBYTE bits;
634
635#ifdef __WIN32OS2__
636 //TODO: Can system cursors be loaded by name??? (#xxx)
637 if (fCursor && hInstance == NULL && !HIWORD(name))
638 {
639 HCURSOR hCursor = OSLibWinQuerySysPointer((ULONG)name, width, height);
640 if(hCursor)
641 {
642 /* If shared icon, check whether it was already loaded */
643 if ((loadflags & LR_SHARED)
644 && (h = CURSORICON_FindSharedIcon( -1, hCursor ) ) != 0 )
645 {
646 dprintf(("Found icon/cursor in cache; returned old handle %x", h));
647 return h;
648 }
649
650 HANDLE hObj = GlobalAlloc( GMEM_MOVEABLE, sizeof(CURSORICONINFO));
651 if (!hObj)
652 {
653 DebugInt3();
654 return 0;
655 }
656 CURSORICONINFO *info;
657
658 info = (CURSORICONINFO *)GlobalLock( hObj );
659 info->ptHotSpot.x = 0;
660 info->ptHotSpot.y = 0;
661 info->nWidth = width;
662 info->nHeight = height;
663 info->nWidthBytes = width*height/8;
664 info->bPlanes = 1;
665 info->bBitsPerPixel = 1;
666 info->hColorBmp = hCursor;
667 info->hInstance = -1;
668 info->dwResGroupId = -1;
669
670 HICON hIcon;
671 if(ObjAllocateHandle(&hIcon, (DWORD)hObj, USEROBJ_CURSORICON) == FALSE) {
672 GlobalUnlock( hObj );
673 GlobalFree(hObj);
674 dprintf(("ERROR: CURSORICON_Load ObjAllocateHandle failed!!"));
675 return 0;
676 }
677
678 if (loadflags & LR_SHARED )
679 CURSORICON_AddSharedIcon( -1, hCursor, -1, hIcon );
680
681 GlobalUnlock( hObj );
682
683 return hIcon;
684 }
685 }
686#endif
687 if ( loadflags & LR_LOADFROMFILE ) /* Load from file */
688 {
689 LPBYTE *ptr;
690
691 if (!CURSORICON_SimulateLoadingFromResourceW((LPWSTR)name, fCursor, &dir, &ptr))
692 return 0;
693 if (fCursor)
694 dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestCursor(dir, width, height, 1);
695 else
696 dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon(dir, width, height, colors);
697 bits = ptr[dirEntry->wResId-1];
698 h = CURSORICON_CreateFromResource( 0, -1, 0, bits, dirEntry->dwBytesInRes,
699 !fCursor, 0x00030000, width, height, loadflags);
700
701 HeapFree( GetProcessHeap(), 0, dir );
702 HeapFree( GetProcessHeap(), 0, ptr );
703 }
704 else /* Load from resource */
705 {
706 HANDLE hGroupRsrc;
707 WORD wResId;
708 DWORD dwBytesInRes;
709 BOOL bIsGroup = TRUE;
710
711 /* Get directory resource ID */
712 if (!hInstance)
713 {
714 hRsrc = FindResourceW(hInstanceUser32, name, fCursor ? RT_CURSORW : RT_ICONW);
715 if(!hRsrc) {
716 hRsrc = FindResourceW(hInstanceUser32, name, fCursor ? RT_GROUP_CURSORW : RT_GROUP_ICONW);
717 }
718 else bIsGroup = FALSE;
719
720 if(!hRsrc) return 0;
721
722 hInstance = hInstanceUser32;
723 }
724 else {
725 hRsrc = FindResourceW(hInstance, name, fCursor ? RT_GROUP_CURSORW : RT_GROUP_ICONW);
726 if(!hRsrc) return 0;
727 }
728 hGroupRsrc = hRsrc;
729
730 if(bIsGroup) {
731 /* Find the best entry in the directory */
732
733 if (!(handle = LoadResource( hInstance, hRsrc ))) return 0;
734 if (!(dir = (CURSORICONDIR*)LockResource( handle ))) return 0;
735
736 if (fCursor)
737 dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestCursor( dir,
738 width, height, 1);
739 else
740 dirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon( dir,
741 width, height, colors );
742 if (!dirEntry) return 0;
743 wResId = dirEntry->wResId;
744 dwBytesInRes = dirEntry->dwBytesInRes;
745 FreeResource( handle );
746
747 /* Load the resource */
748 if (!(hRsrc = FindResourceW(hInstance,MAKEINTRESOURCEW(wResId),
749 fCursor ? RT_CURSORW : RT_ICONW ))) return 0;
750 }
751
752 /* If shared icon, check whether it was already loaded */
753 if ((loadflags & LR_SHARED)
754 && (h = CURSORICON_FindSharedIcon( hInstance, hRsrc ) ) != 0 )
755 {
756 dprintf(("Found icon/cursor in cache; returned old handle %x", h));
757 return h;
758 }
759
760 if (!(handle = LoadResource( hInstance, hRsrc ))) return 0;
761 bits = (LPBYTE)LockResource( handle );
762 h = CURSORICON_CreateFromResource( hInstance, (DWORD)name, 0, bits, dwBytesInRes,
763 !fCursor, 0x00030000, width, height, loadflags);
764 FreeResource( handle );
765
766 /* If shared icon, add to icon cache */
767
768 if ( h && (loadflags & LR_SHARED) )
769 CURSORICON_AddSharedIcon( hInstance, hRsrc, hGroupRsrc, h );
770
771 }
772
773 return h;
774}
775
776/*********************************************************************
777 * The main purpose of this function is to create fake resource directory
778 * and fake resource entries. There are several reasons for this:
779 * - CURSORICONDIR and CURSORICONFILEDIR differ in sizes and their
780 * fields
781 * There are some "bad" cursor files which do not have
782 * bColorCount initialized but instead one must read this info
783 * directly from corresponding DIB sections
784 * Note: wResId is index to array of pointer returned in ptrs (origin is 1)
785 */
786BOOL CURSORICON_SimulateLoadingFromResourceW( LPWSTR filename, BOOL fCursor,
787 CURSORICONDIR **res, LPBYTE **ptr)
788{
789 LPBYTE _free;
790 CURSORICONFILEDIR *bits;
791 int entries, size, i;
792 HANDLE hMapping = 0;
793
794 *res = NULL;
795 *ptr = NULL;
796
797 hMapping = VIRTUAL_MapFileW( filename, (LPVOID *)&bits, TRUE);
798 if(hMapping == INVALID_HANDLE_VALUE)
799 return FALSE;
800
801 /* FIXME: test for inimated icons
802 * hack to load the first icon from the *.ani file
803 */
804 if ( *(LPDWORD)bits==0x46464952 ) /* "RIFF" */
805 {
806 LPBYTE pos = (LPBYTE) bits;
807 dprintf(("Animated icons not correctly implemented! %p \n", bits));
808
809 for (;;)
810 {
811 if (*(LPDWORD)pos==0x6e6f6369) /* "icon" */
812 {
813 dprintf(("icon entry found! %p\n", bits));
814 pos+=4;
815 if ( !*(LPWORD) pos==0x2fe) /* iconsize */
816 {
817 goto fail;
818 }
819 bits=(CURSORICONFILEDIR*)(pos+4);
820 dprintf(("icon size ok. offset=%p \n", bits));
821 break;
822 }
823 pos+=2;
824 if (pos>=(LPBYTE)bits+766) goto fail;
825 }
826 }
827 if (!(entries = bits->idCount)) goto fail;
828 size = sizeof(CURSORICONDIR) + sizeof(CURSORICONDIRENTRY) * (entries - 1);
829 _free = (LPBYTE) size;
830
831 for (i=0; i < entries; i++)
832 size += bits->idEntries[i].dwDIBSize + (fCursor ? sizeof(POINT16): 0);
833
834 if (!(*ptr = (LPBYTE *)HeapAlloc( GetProcessHeap(), 0,
835 entries * sizeof (CURSORICONDIRENTRY*)))) goto fail;
836 if (!(*res = (CURSORICONDIR *)HeapAlloc( GetProcessHeap(), 0, size))) goto fail;
837
838 _free = (LPBYTE)(*res) + (int)_free;
839 memcpy((*res), bits, 6);
840 for (i=0; i<entries; i++)
841 {
842 ((LPBYTE*)(*ptr))[i] = _free;
843 if (fCursor) {
844 (*res)->idEntries[i].ResInfo.cursor.wWidth=bits->idEntries[i].bWidth;
845 (*res)->idEntries[i].ResInfo.cursor.wHeight=bits->idEntries[i].bHeight;
846 ((LPPOINT16)_free)->x=bits->idEntries[i].xHotspot;
847 ((LPPOINT16)_free)->y=bits->idEntries[i].yHotspot;
848 _free+=sizeof(POINT16);
849 }
850 else {
851 (*res)->idEntries[i].ResInfo.icon.bWidth=bits->idEntries[i].bWidth;
852 (*res)->idEntries[i].ResInfo.icon.bHeight=bits->idEntries[i].bHeight;
853 (*res)->idEntries[i].ResInfo.icon.bColorCount = bits->idEntries[i].bColorCount;
854 }
855 (*res)->idEntries[i].wPlanes=1;
856 (*res)->idEntries[i].wBitCount = ((LPBITMAPINFOHEADER)((LPBYTE)bits +
857 bits->idEntries[i].dwDIBOffset))->biBitCount;
858 (*res)->idEntries[i].dwBytesInRes = bits->idEntries[i].dwDIBSize;
859 (*res)->idEntries[i].wResId=i+1;
860
861 memcpy(_free,(LPBYTE)bits +bits->idEntries[i].dwDIBOffset,
862 (*res)->idEntries[i].dwBytesInRes);
863 _free += (*res)->idEntries[i].dwBytesInRes;
864 }
865 UnmapViewOfFile( bits );
866 CloseHandle(hMapping);
867 return TRUE;
868
869fail:
870 if (*res) HeapFree( GetProcessHeap(), 0, *res );
871 if (*ptr) HeapFree( GetProcessHeap(), 0, *ptr );
872
873 UnmapViewOfFile( bits );
874 CloseHandle(hMapping);
875 return FALSE;
876}
877
878/**********************************************************************
879 * CURSORICON_CreateFromResource
880 *
881 * Create a cursor or icon from in-memory resource template.
882 *
883 * FIXME: Convert to mono when cFlag is LR_MONOCHROME. Do something
884 * with cbSize parameter as well.
885 */
886static HGLOBAL CURSORICON_CreateFromResource( HINSTANCE hInstance, DWORD dwResGroupId, HGLOBAL hObj, LPBYTE bits,
887 UINT cbSize, BOOL bIcon, DWORD dwVersion,
888 INT width, INT height, UINT loadflags )
889{
890 int sizeAnd, sizeXor;
891 HBITMAP hAndBits = 0, hXorBits = 0; /* error condition for later */
892 BITMAP bmpXor, bmpAnd;
893 POINT16 hotspot;
894 BITMAPINFO *bmi;
895 HDC hdc = 0;
896 BOOL DoStretch;
897 INT size, colortablesize, bwsize, colorsize;
898
899 hotspot.x = ICON_HOTSPOT;
900 hotspot.y = ICON_HOTSPOT;
901
902 dprintf2(("CURSORICON_CreateFromResource %x %x %x %x %d", hInstance, dwResGroupId, hObj, bits, cbSize));
903
904 if (dwVersion == 0x00020000)
905 {
906 dprintf(("CURSORICON_CreateFromResource 2.xx resources are not supported"));
907 return 0;
908 }
909
910 if (bIcon) {
911 bmi = (BITMAPINFO *)bits;
912 }
913 else /* get the hotspot */
914 {
915 POINT16 *pt = (POINT16 *)bits;
916 hotspot = *pt;
917 bmi = (BITMAPINFO *)(pt + 1);
918 }
919 size = DIB_BitmapInfoSize(bmi, DIB_RGB_COLORS);
920
921 if (!width) width = bmi->bmiHeader.biWidth;
922 if (!height) height = bmi->bmiHeader.biHeight/2;
923
924 DoStretch = (bmi->bmiHeader.biHeight/2 != height) || (bmi->bmiHeader.biWidth != width);
925
926 colorsize = DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight/2, bmi->bmiHeader.biBitCount);
927 bwsize = (bmi->bmiHeader.biWidth * bmi->bmiHeader.biHeight/2)/8;
928
929 /* Check bitmap header */
930 if((bmi->bmiHeader.biSize != sizeof(BITMAPCOREHEADER)) &&
931 (bmi->bmiHeader.biSize != sizeof(BITMAPINFOHEADER) ||
932 bmi->bmiHeader.biCompression != BI_RGB) )
933 {
934 return 0;
935 }
936
937#ifdef __WIN32OS2__
938 if( (hdc = CreateCompatibleDC( 0 )) )
939#else
940 if( (hdc = GetDC( 0 )) )
941#endif
942 {
943 BITMAPINFO* pInfo;
944
945 /* Make sure we have room for the monochrome bitmap later on.
946 * Note that BITMAPINFOINFO and BITMAPCOREHEADER are the same
947 * up to and including the biBitCount. In-memory icon resource
948 * format is as follows:
949 *
950 * BITMAPINFOHEADER icHeader // DIB header
951 * RGBQUAD icColors[] // Color table
952 * BYTE icXOR[] // DIB bits for XOR mask
953 * BYTE icAND[] // DIB bits for AND mask
954 */
955
956 if ((pInfo = (BITMAPINFO *)HeapAlloc( GetProcessHeap(), 0,
957 max(size, sizeof(BITMAPINFOHEADER) + 2*sizeof(RGBQUAD)))))
958 {
959 memcpy( pInfo, bmi, size );
960 pInfo->bmiHeader.biHeight /= 2;
961
962 /* Create the XOR bitmap */
963 if (DoStretch)
964 {
965 if(bIcon)
966 {
967 hXorBits = CreateCompatibleBitmap(hdc, width, height);
968 }
969 else
970 {
971 hXorBits = CreateBitmap(width, height, 1, 1, NULL);
972 }
973 if(hXorBits)
974 {
975 HBITMAP hOld;
976 HDC hMem = CreateCompatibleDC(hdc);
977 BOOL res;
978
979 if (hMem) {
980 hOld = SelectObject(hMem, hXorBits);
981 res = StretchDIBits(hMem, 0, 0, width, height, 0, 0,
982 bmi->bmiHeader.biWidth, bmi->bmiHeader.biHeight/2,
983 (char*)bmi + size, pInfo, DIB_RGB_COLORS, SRCCOPY);
984 SelectObject(hMem, hOld);
985 DeleteDC(hMem);
986 }
987 else res = FALSE;
988 if (!res) {
989 DeleteObject(hXorBits);
990 hXorBits = 0;
991 }
992 }
993 }
994 else
995 {
996 hXorBits = CreateDIBitmap(hdc, &pInfo->bmiHeader,
997 CBM_INIT, (char*)bmi + size, pInfo, DIB_RGB_COLORS );
998 }
999 if( hXorBits )
1000 {
1001 char* xbits = (char *)bmi + size + DIB_GetDIBImageBytes(bmi->bmiHeader.biWidth,
1002 bmi->bmiHeader.biHeight,
1003 bmi->bmiHeader.biBitCount) / 2;
1004
1005 pInfo->bmiHeader.biBitCount = 1;
1006 if (pInfo->bmiHeader.biSize == sizeof(BITMAPINFOHEADER))
1007 {
1008 RGBQUAD *rgb = pInfo->bmiColors;
1009
1010 pInfo->bmiHeader.biClrUsed = pInfo->bmiHeader.biClrImportant = 2;
1011 rgb[0].rgbBlue = rgb[0].rgbGreen = rgb[0].rgbRed = 0x00;
1012 rgb[1].rgbBlue = rgb[1].rgbGreen = rgb[1].rgbRed = 0xff;
1013 rgb[0].rgbReserved = rgb[1].rgbReserved = 0;
1014 }
1015 else
1016 {
1017 RGBTRIPLE *rgb = (RGBTRIPLE *)(((BITMAPCOREHEADER *)pInfo) + 1);
1018
1019 rgb[0].rgbtBlue = rgb[0].rgbtGreen = rgb[0].rgbtRed = 0x00;
1020 rgb[1].rgbtBlue = rgb[1].rgbtGreen = rgb[1].rgbtRed = 0xff;
1021 }
1022
1023 /* Create the AND bitmap */
1024 if (DoStretch)
1025 {
1026 if ((hAndBits = CreateBitmap(width, height, 1, 1, NULL)))
1027 {
1028 HBITMAP hOld;
1029 HDC hMem = CreateCompatibleDC(hdc);
1030 BOOL res;
1031
1032 if (hMem) {
1033 hOld = SelectObject(hMem, hAndBits);
1034//SvL: This also doesn't work as StretchDIBits doesn't handle 1bpp bitmaps correctly
1035//--------->>> hack alert!
1036#if 1
1037 HBITMAP hBmp, hOld1;
1038 HDC hMem1;
1039
1040 hMem1 = CreateCompatibleDC(hdc);
1041
1042 int linewidth = BITMAP_GetWidthBytes(pInfo->bmiHeader.biWidth, 1);
1043
1044 char *newpix = (char *)malloc(linewidth*pInfo->bmiHeader.biHeight);
1045
1046 newpix += ((pInfo->bmiHeader.biHeight-1)*linewidth);
1047
1048 if(cbSize - size - colorsize - bwsize == bwsize)
1049 {//this means an AND and XOR mask is present (interleaved; and/xor)
1050 for(int i=0;i<pInfo->bmiHeader.biHeight;i++) {
1051 memcpy(newpix, xbits, linewidth);
1052 newpix -= linewidth;
1053 xbits += linewidth*2;
1054 }
1055 }
1056 else {
1057 for(int i=0;i<pInfo->bmiHeader.biHeight;i++) {
1058 memcpy(newpix, xbits, linewidth);
1059 newpix -= linewidth;
1060 xbits += linewidth;
1061 }
1062 }
1063 newpix += linewidth;
1064 hBmp = CreateBitmap(pInfo->bmiHeader.biWidth, pInfo->bmiHeader.biHeight, 1, 1, newpix);
1065 free(newpix);
1066
1067 hOld1 = SelectObject(hMem1, hBmp);
1068
1069 res = StretchBlt(hMem, 0, 0, width, height, hMem1, 0, 0, pInfo->bmiHeader.biWidth, pInfo->bmiHeader.biHeight, SRCCOPY);
1070
1071 SelectObject(hMem1, hOld1);
1072 DeleteObject(hBmp);
1073 DeleteDC(hMem1);
1074
1075
1076#else
1077 res = StretchDIBits(hMem, 0, 0, width, height, 0, 0,
1078 pInfo->bmiHeader.biWidth, pInfo->bmiHeader.biHeight,
1079 xbits, pInfo, DIB_RGB_COLORS, SRCCOPY);
1080#endif
1081 SelectObject(hMem, hOld);
1082 DeleteDC(hMem);
1083 }
1084 else res = FALSE;
1085 if (!res) {
1086 DeleteObject(hAndBits);
1087 hAndBits = 0;
1088 }
1089 }
1090 }
1091 else {
1092//SvL: Must use CreateBitmap here as CreateDIBitmap converts data to 8bpp (GetObjectA info -> 8 bpp)
1093#if 1
1094 int linewidth = BITMAP_GetWidthBytes(width, 1);
1095
1096 char *newpix = (char *)malloc(linewidth*height);
1097
1098 newpix += ((height-1)*linewidth);
1099
1100 if(cbSize - size - colorsize - bwsize == bwsize)
1101 {//this means an AND and XOR mask is present (interleaved; and/xor)
1102 for(int i=0;i<height;i++) {
1103 memcpy(newpix, xbits, linewidth);
1104 newpix -= linewidth;
1105 xbits += linewidth*2;
1106 }
1107 }
1108 else {
1109 for(int i=0;i<height;i++) {
1110 memcpy(newpix, xbits, linewidth);
1111 newpix -= linewidth;
1112 xbits += linewidth;
1113 }
1114 }
1115 newpix += linewidth;
1116 hAndBits = CreateBitmap(width, height, 1, 1, newpix);
1117
1118 free(newpix);
1119
1120#else
1121 hAndBits = CreateDIBitmap(hdc, &pInfo->bmiHeader,
1122 CBM_INIT, xbits, pInfo, DIB_RGB_COLORS );
1123#endif
1124 }
1125 if( !hAndBits )
1126 DeleteObject( hXorBits );
1127 }
1128 HeapFree( GetProcessHeap(), 0, pInfo );
1129 }
1130#ifdef __WIN32OS2__
1131 DeleteDC(hdc );
1132#else
1133 ReleaseDC( 0, hdc );
1134#endif
1135 }
1136
1137 if( !hXorBits || !hAndBits )
1138 {
1139 dprintf(("\tunable to create an icon bitmap."));
1140 return 0;
1141 }
1142
1143 /* Now create the CURSORICONINFO structure */
1144 GetObjectA( hXorBits, sizeof(bmpXor), &bmpXor );
1145 GetObjectA( hAndBits, sizeof(bmpAnd), &bmpAnd );
1146 colortablesize = 0;
1147
1148 if(bmpXor.bmBitsPixel <= 8) {
1149 colortablesize = sizeof(RGBQUAD)*(1<<bmpXor.bmBitsPixel);
1150 sizeXor = bmpXor.bmHeight * bmpXor.bmWidthBytes + colortablesize;
1151 }
1152 else sizeXor = bmpXor.bmHeight * bmpXor.bmWidthBytes;
1153
1154 sizeAnd = bmpAnd.bmHeight * bmpAnd.bmWidthBytes;
1155
1156 if (hObj) hObj = GlobalReAlloc( hObj,
1157 sizeof(CURSORICONINFO) + sizeXor + sizeAnd, GMEM_MOVEABLE );
1158 if (!hObj) hObj = GlobalAlloc( GMEM_MOVEABLE,
1159 sizeof(CURSORICONINFO) + sizeXor + sizeAnd );
1160 if (hObj)
1161 {
1162 CURSORICONINFO *info;
1163
1164 info = (CURSORICONINFO *)GlobalLock( hObj );
1165 info->ptHotSpot.x = hotspot.x;
1166 info->ptHotSpot.y = hotspot.y;
1167 info->nWidth = bmpXor.bmWidth;
1168 info->nHeight = bmpXor.bmHeight;
1169 info->nWidthBytes = bmpXor.bmWidthBytes;
1170 info->bPlanes = bmpXor.bmPlanes;
1171 info->bBitsPerPixel = bmpXor.bmBitsPixel;
1172 info->hInstance = hInstance;
1173 info->dwResGroupId = dwResGroupId;
1174 info->hColorBmp = 0;
1175
1176 /* Transfer the bitmap bits to the CURSORICONINFO structure */
1177 GetBitmapBits( hAndBits, sizeAnd, (char *)(info + 1));
1178
1179 if(bmpXor.bmBitsPixel > 1)
1180 {
1181 BITMAPINFO* pInfo = (BITMAPINFO *)malloc(sizeof(BITMAPINFO)+colortablesize+3*sizeof(DWORD)); //+ extra space for > 8bpp images
1182 HBITMAP oldbmp;
1183
1184 hdc = CreateCompatibleDC(0);
1185
1186 memset(pInfo, 0, sizeof(BITMAPINFO)+colortablesize+3*sizeof(DWORD));
1187 pInfo->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
1188 pInfo->bmiHeader.biPlanes = info->bPlanes;
1189 pInfo->bmiHeader.biBitCount = info->bBitsPerPixel;
1190
1191 GetDIBits(hdc, hXorBits, 0, bmpXor.bmHeight, (char *)(info + 1) + sizeAnd + colortablesize, pInfo, DIB_RGB_COLORS);
1192 if(colortablesize) {
1193 memcpy((char *)(info + 1) + sizeAnd, (char *)&pInfo->bmiHeader + pInfo->bmiHeader.biSize, colortablesize);
1194 }
1195
1196 DeleteDC(hdc);
1197 free(pInfo);
1198 }
1199 else {
1200 GetBitmapBits( hXorBits, sizeXor, (char *)(info + 1) + sizeAnd);
1201 }
1202 info->hColorBmp = OSLibWinCreatePointer(info, (char*)(info + 1), (LPBITMAP_W)&bmpAnd, (char*)(info + 1) + sizeAnd, (LPBITMAP_W)&bmpXor, bIcon == FALSE);
1203
1204 dprintf(("Create cursor/icon %x with OS/2 pointer handle %x", hObj, info->hColorBmp));
1205 GlobalUnlock( hObj );
1206 }
1207
1208 DeleteObject( hAndBits );
1209 DeleteObject( hXorBits );
1210
1211#ifdef __WIN32OS2__
1212 if(hObj) {
1213 HICON hIcon;
1214 if(ObjAllocateHandle(&hIcon, (DWORD)hObj, USEROBJ_CURSORICON) == FALSE) {
1215 GlobalFree(hObj);
1216 dprintf(("ERROR: CURSORICON_Load ObjAllocateHandle failed!!"));
1217 return 0;
1218 }
1219 return hIcon;
1220 }
1221#endif
1222 return hObj;
1223}
1224
1225/**********************************************************************
1226 * CURSORICON_Destroy (USER.610)
1227 *
1228 * This routine is actually exported from Win95 USER under the name
1229 * DestroyIcon32 ... The behaviour implemented here should mimic
1230 * the Win95 one exactly, especially the return values, which
1231 * depend on the setting of various flags.
1232 */
1233WORD WIN32API CURSORICON_Destroy( HGLOBAL handle, UINT flags )
1234{
1235 WORD retv;
1236
1237 /* Check whether destroying active cursor */
1238
1239 if ( hActiveCursor == handle )
1240 {
1241 dprintf(("WARNING: Destroying active cursor!" ));
1242 SetCursor( 0 );
1243 }
1244
1245#ifdef __WIN32OS2__
1246 HICON hIcon = ObjGetHandleData(handle, USEROBJ_CURSORICON);
1247 if(hIcon == -1) {
1248 dprintf(("ERROR: Invalid cursor/icon!"));
1249 return 0;
1250 }
1251#endif
1252
1253 /* Try shared cursor/icon first */
1254 if ( !(flags & CID_NONSHARED) )
1255 {
1256 INT count = CURSORICON_DelSharedIcon( handle );
1257
1258 if ( count != -1 )
1259 return (flags & CID_WIN32)? TRUE : (count == 0);
1260
1261 /* FIXME: OEM cursors/icons should be recognized */
1262 }
1263 /* Now assume non-shared cursor/icon */
1264
1265#ifdef __WIN32OS2__
1266 CURSORICONINFO *iconinfo = (CURSORICONINFO *)GlobalLock((HGLOBAL)hIcon);
1267 if (!iconinfo) {
1268 dprintf(("ERROR: Invalid cursor!"));
1269 return 0;
1270 }
1271
1272 if(iconinfo->hColorBmp) {
1273 OSLibWinDestroyPointer(iconinfo->hColorBmp);
1274 }
1275 GlobalUnlock(hIcon);
1276 retv = GlobalFree( hIcon );
1277 ObjFreeHandle(handle);
1278
1279 return (flags & CID_RESOURCE)? retv : TRUE;
1280#else
1281 retv = GlobalFree( handle );
1282 return (flags & CID_RESOURCE)? retv : TRUE;
1283#endif
1284}
1285
1286/***********************************************************************
1287 * CURSORICON_Copy
1288 *
1289 * Make a copy of a cursor or icon.
1290 */
1291static HGLOBAL CURSORICON_Copy(HGLOBAL handle)
1292{
1293 char *ptrOld, *ptrNew;
1294 int size;
1295 HGLOBAL hNew;
1296
1297 handle = ObjGetHandleData(handle, USEROBJ_CURSORICON);
1298 if(handle == -1) {
1299 dprintf(("ERROR: Invalid cursor/icon!"));
1300 return 0;
1301 }
1302
1303 if (!(ptrOld = (char *)GlobalLock( handle ))) return 0;
1304
1305 size = GlobalSize( handle );
1306 hNew = GlobalAlloc( GMEM_MOVEABLE, size );
1307#ifdef __WIN32OS2__
1308 if(hNew == NULL) {
1309 dprintf(("ERROR: CURSORICON_Copy GlobalAlloc failed!!"));
1310 return NULL;
1311 }
1312#endif
1313 ptrNew = (char *)GlobalLock( hNew );
1314 memcpy( ptrNew, ptrOld, size );
1315 GlobalUnlock( handle );
1316 GlobalUnlock( hNew );
1317
1318#ifdef __WIN32OS2__
1319 HICON hIcon;
1320 if(ObjAllocateHandle(&hIcon, (DWORD)hNew, USEROBJ_CURSORICON) == FALSE) {
1321 GlobalFree(hNew);
1322 dprintf(("ERROR: CURSORICON_Copy ObjAllocateHandle failed!!"));
1323 return 0;
1324 }
1325 return hIcon;
1326#else
1327 return hNew;
1328#endif
1329}
1330
1331/*************************************************************************
1332 * CURSORICON_ExtCopy
1333 *
1334 * Copies an Image from the Cache if LR_COPYFROMRESOURCE is specified
1335 *
1336 * PARAMS
1337 * Handle [I] handle to an Image
1338 * nType [I] Type of Handle (IMAGE_CURSOR | IMAGE_ICON)
1339 * iDesiredCX [I] The Desired width of the Image
1340 * iDesiredCY [I] The desired height of the Image
1341 * nFlags [I] The flags from CopyImage
1342 *
1343 * RETURNS
1344 * Success: The new handle of the Image
1345 *
1346 * NOTES
1347 * LR_COPYDELETEORG and LR_MONOCHROME are currently not implemented.
1348 * LR_MONOCHROME should be implemented by CURSORICON_CreateFromResource.
1349 * LR_COPYFROMRESOURCE will only work if the Image is in the Cache.
1350 *
1351 *
1352 */
1353HGLOBAL CURSORICON_ExtCopy(HGLOBAL Handle, UINT nType,
1354 INT iDesiredCX, INT iDesiredCY,
1355 UINT nFlags)
1356{
1357 HGLOBAL hNew=0;
1358
1359#ifdef __WIN32OS2__
1360 HICON hIcon = ObjGetHandleData(Handle, USEROBJ_CURSORICON);
1361 if(hIcon == -1) {
1362 dprintf(("ERROR: Invalid cursor/icon!"));
1363 return 0;
1364 }
1365
1366#else
1367 if(Handle == 0)
1368 {
1369 return 0;
1370 }
1371#endif
1372 /* Best Fit or Monochrome */
1373 if( (nFlags & LR_COPYFROMRESOURCE
1374 && (iDesiredCX > 0 || iDesiredCY > 0))
1375 || nFlags & LR_MONOCHROME)
1376 {
1377#ifdef __WIN32OS2__
1378 ICONCACHE* pIconCache = CURSORICON_FindCache(hIcon);
1379#else
1380 ICONCACHE* pIconCache = CURSORICON_FindCache(Handle);
1381#endif
1382
1383 /* Not Found in Cache, then do a straight copy
1384 */
1385 if(pIconCache == NULL)
1386 {
1387#ifdef __WIN32OS2__
1388 hNew = CURSORICON_Copy(Handle);
1389#else
1390 hNew = CURSORICON_Copy(0, Handle);
1391#endif
1392 if(nFlags & LR_COPYFROMRESOURCE)
1393 {
1394 dprintf(("WARNING: LR_COPYFROMRESOURCE: Failed to load from cache\n"));
1395 }
1396 }
1397 else
1398 {
1399 int iTargetCY = iDesiredCY, iTargetCX = iDesiredCX;
1400 LPBYTE pBits;
1401 HANDLE hMem;
1402 HRSRC hRsrc;
1403 DWORD dwBytesInRes;
1404 WORD wResId;
1405 DWORD dwResGroupId;
1406 HINSTANCE hInstance;
1407 CURSORICONINFO *iconinfo;
1408 CURSORICONDIR *pDir;
1409 CURSORICONDIRENTRY *pDirEntry;
1410 BOOL bIsIcon = (nType == IMAGE_ICON);
1411
1412#ifdef __WIN32OS2__
1413 iconinfo = (CURSORICONINFO *)GlobalLock( hIcon );
1414#else
1415 iconinfo = (CURSORICONINFO *)GlobalLock( Handle );
1416#endif
1417 if(iconinfo == NULL) {
1418 dprintf(("ERROR: CURSORICON_ExtCopy invalid icon!"));
1419 }
1420 hInstance = iconinfo->hInstance;
1421 dwResGroupId = iconinfo->dwResGroupId;
1422 GlobalUnlock( Handle );
1423 if(dwResGroupId == -1) {
1424 //todo: if scaling is necessary..
1425 dprintf(("WARNING: no resource associated with icon/cursor -> copy without scaling!"));
1426 hNew = CURSORICON_Copy(Handle);
1427 return hNew;
1428 }
1429
1430 /* Completing iDesiredCX CY for Monochrome Bitmaps if needed
1431 */
1432 if(((nFlags & LR_MONOCHROME) && !(nFlags & LR_COPYFROMRESOURCE))
1433 || (iDesiredCX == 0 && iDesiredCY == 0))
1434 {
1435 iDesiredCY = GetSystemMetrics(bIsIcon ? SM_CYICON : SM_CYCURSOR);
1436 iDesiredCX = GetSystemMetrics(bIsIcon ? SM_CXICON : SM_CXCURSOR);
1437 }
1438
1439 /* Retreive the CURSORICONDIRENTRY
1440 */
1441 hRsrc = FindResourceW(hInstance, (LPWSTR)dwResGroupId, bIsIcon ? RT_GROUP_ICONW : RT_GROUP_CURSORW);
1442 if(!hRsrc) {
1443 goto notfound;
1444 }
1445
1446 if (!(hMem = LoadResource( hInstance, hRsrc)))
1447 {
1448 goto notfound;
1449 }
1450 if (!(pDir = (CURSORICONDIR*)LockResource( hMem )))
1451 {
1452 goto notfound;
1453 }
1454
1455 /* Find Best Fit
1456 */
1457 if(bIsIcon)
1458 {
1459 pDirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestIcon(
1460 pDir, iDesiredCX, iDesiredCY, 256);
1461 }
1462 else
1463 {
1464 pDirEntry = (CURSORICONDIRENTRY *)CURSORICON_FindBestCursor(
1465 pDir, iDesiredCX, iDesiredCY, 1);
1466 }
1467
1468 wResId = pDirEntry->wResId;
1469 dwBytesInRes = pDirEntry->dwBytesInRes;
1470 FreeResource(hMem);
1471
1472 /* Get the Best Fit
1473 */
1474 if (!(hRsrc = FindResourceW(hInstance ,
1475 MAKEINTRESOURCEW(wResId), bIsIcon ? RT_ICONW : RT_CURSORW)))
1476 {
1477 goto notfound;
1478 }
1479 if (!(hMem = LoadResource( hInstance, hRsrc )))
1480 {
1481 goto notfound;
1482 }
1483
1484 pBits = (LPBYTE)LockResource( hMem );
1485
1486 if(nFlags & LR_DEFAULTSIZE)
1487 {
1488 iTargetCY = GetSystemMetrics(SM_CYICON);
1489 iTargetCX = GetSystemMetrics(SM_CXICON);
1490 }
1491
1492 /* Create a New Icon with the proper dimension
1493 */
1494 hNew = CURSORICON_CreateFromResource( hInstance, dwResGroupId, 0, pBits, dwBytesInRes,
1495 bIsIcon, 0x00030000, iTargetCX, iTargetCY, nFlags);
1496 FreeResource(hMem);
1497 }
1498 }
1499 else
1500 {
1501 hNew = CURSORICON_Copy(Handle);
1502 }
1503 return hNew;
1504
1505notfound:
1506 dprintf(("WARNING: unable to find resource associated with icon/cursor -> copy without scaling!"));
1507 hNew = CURSORICON_Copy(Handle);
1508 return hNew;
1509}
1510
1511/**********************************************************************
1512 * CURSORICON_FindBestIcon
1513 *
1514 * Find the icon closest to the requested size and number of colors.
1515 */
1516static CURSORICONDIRENTRY *CURSORICON_FindBestIcon( CURSORICONDIR *dir, int width,
1517 int height, int colors )
1518{
1519 int i;
1520 CURSORICONDIRENTRY *entry, *bestEntry = NULL;
1521 UINT iTotalDiff, iXDiff=0, iYDiff=0, iColorDiff;
1522 UINT iTempXDiff, iTempYDiff, iTempColorDiff;
1523
1524 if (dir->idCount < 1)
1525 {
1526 dprintf(("Empty directory!\n" ));
1527 return NULL;
1528 }
1529 if (dir->idCount == 1) return &dir->idEntries[0]; /* No choice... */
1530
1531 /* Find Best Fit */
1532 iTotalDiff = 0xFFFFFFFF;
1533 iColorDiff = 0xFFFFFFFF;
1534 for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
1535 {
1536 iTempXDiff = abs(width - entry->ResInfo.icon.bWidth);
1537 iTempYDiff = abs(height - entry->ResInfo.icon.bHeight);
1538
1539 if(iTotalDiff > (iTempXDiff + iTempYDiff))
1540 {
1541 iXDiff = iTempXDiff;
1542 iYDiff = iTempYDiff;
1543 iTotalDiff = iXDiff + iYDiff;
1544 }
1545 }
1546
1547 /* Find Best Colors for Best Fit */
1548 for (i = 0, entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
1549 {
1550 if(abs(width - entry->ResInfo.icon.bWidth) == iXDiff &&
1551 abs(height - entry->ResInfo.icon.bHeight) == iYDiff)
1552 {
1553#ifdef __WIN32OS2__
1554 iTempColorDiff = abs(colors - (1 << entry->wBitCount));
1555#else
1556 iTempColorDiff = abs(colors - entry->ResInfo.icon.bColorCount);
1557#endif
1558 if(iColorDiff > iTempColorDiff)
1559 {
1560 bestEntry = entry;
1561 iColorDiff = iTempColorDiff;
1562 }
1563 }
1564 }
1565////testestest
1566 dprintf(("CURSORICON_FindBestIcon (%d,%d) %d -> %d", width, height, colors, (bestEntry) ? bestEntry->wResId : 0));
1567 return bestEntry;
1568}
1569
1570
1571/**********************************************************************
1572 * CURSORICON_FindBestCursor
1573 *
1574 * Find the cursor closest to the requested size.
1575 * FIXME: parameter 'color' ignored and entries with more than 1 bpp
1576 * ignored too
1577 */
1578static CURSORICONDIRENTRY *CURSORICON_FindBestCursor( CURSORICONDIR *dir,
1579 int width, int height, int color)
1580{
1581 int i, maxwidth, maxheight;
1582 CURSORICONDIRENTRY *entry, *bestEntry = NULL;
1583
1584 if (dir->idCount < 1)
1585 {
1586 dprintf(("Empty directory!\n" ));
1587 return NULL;
1588 }
1589 if (dir->idCount == 1) return &dir->idEntries[0]; /* No choice... */
1590
1591 /* Double height to account for AND and XOR masks */
1592
1593 height *= 2;
1594
1595 /* First find the largest one smaller than or equal to the requested size*/
1596
1597 maxwidth = maxheight = 0;
1598 for(i = 0,entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
1599 if ((entry->ResInfo.cursor.wWidth <= width) && (entry->ResInfo.cursor.wHeight <= height) &&
1600 (entry->ResInfo.cursor.wWidth > maxwidth) && (entry->ResInfo.cursor.wHeight > maxheight) &&
1601 (entry->wBitCount == 1))
1602 {
1603 bestEntry = entry;
1604 maxwidth = entry->ResInfo.cursor.wWidth;
1605 maxheight = entry->ResInfo.cursor.wHeight;
1606 }
1607 if (bestEntry) return bestEntry;
1608
1609 /* Now find the smallest one larger than the requested size */
1610
1611 maxwidth = maxheight = 255;
1612 for(i = 0,entry = &dir->idEntries[0]; i < dir->idCount; i++,entry++)
1613 if ((entry->ResInfo.cursor.wWidth < maxwidth) && (entry->ResInfo.cursor.wHeight < maxheight) &&
1614 (entry->wBitCount == 1))
1615 {
1616 bestEntry = entry;
1617 maxwidth = entry->ResInfo.cursor.wWidth;
1618 maxheight = entry->ResInfo.cursor.wHeight;
1619 }
1620
1621 return bestEntry;
1622}
1623/**********************************************************************
1624 * LookupIconIdFromDirectoryEx (USER.364)
1625 *
1626 * FIXME: exact parameter sizes
1627 */
1628INT WIN32API LookupIconIdFromDirectoryEx(LPBYTE xdir, BOOL bIcon,
1629 INT width, INT height, UINT cFlag )
1630{
1631 CURSORICONDIR *dir = (CURSORICONDIR*)xdir;
1632 UINT retVal = 0;
1633
1634 dprintf(("LookupIconIdFromDirectoryEx %x %d (%d,%d)", xdir, bIcon, width, height));
1635 if( dir && !dir->idReserved && (dir->idType & 3) )
1636 {
1637 CURSORICONDIRENTRY* entry;
1638 HDC hdc;
1639 UINT palEnts;
1640 int colors;
1641 hdc = GetDC(0);
1642 palEnts = GetSystemPaletteEntries(hdc, 0, 0, NULL);
1643 if (palEnts == 0)
1644 palEnts = 256;
1645 colors = (cFlag & LR_MONOCHROME) ? 2 : palEnts;
1646
1647 ReleaseDC(0, hdc);
1648
1649 if( bIcon )
1650 entry = CURSORICON_FindBestIcon( dir, width, height, colors );
1651 else
1652 entry = CURSORICON_FindBestCursor( dir, width, height, 1);
1653
1654 if( entry ) retVal = entry->wResId;
1655 }
1656 else dprintf(("invalid resource directory\n"));
1657 return retVal;
1658}
1659/**********************************************************************
1660 * LookupIconIdFromDirectory (USER32.379)
1661 */
1662INT WIN32API LookupIconIdFromDirectory( LPBYTE dir, BOOL bIcon )
1663{
1664 return LookupIconIdFromDirectoryEx( dir, bIcon,
1665 bIcon ? GetSystemMetrics(SM_CXICON) : GetSystemMetrics(SM_CXCURSOR),
1666 bIcon ? GetSystemMetrics(SM_CYICON) : GetSystemMetrics(SM_CYCURSOR), bIcon ? 0 : LR_MONOCHROME );
1667}
1668//******************************************************************************
1669//******************************************************************************
1670
1671//ICON cache implementation (Wine code)
1672
1673/**********************************************************************
1674 * CURSORICON_FindSharedIcon
1675 */
1676static HANDLE CURSORICON_FindSharedIcon( HMODULE hModule, HRSRC hRsrc )
1677{
1678 HANDLE handle = 0;
1679 ICONCACHE *ptr;
1680
1681 EnterCriticalSection( &IconCrst );
1682
1683 for ( ptr = IconAnchor; ptr; ptr = ptr->next )
1684 if ( ptr->hModule == hModule && ptr->hRsrc == hRsrc )
1685 {
1686 ptr->count++;
1687 handle = ptr->handle;
1688 break;
1689 }
1690
1691 LeaveCriticalSection( &IconCrst );
1692
1693 return handle;
1694}
1695
1696/*************************************************************************
1697 * CURSORICON_FindCache
1698 *
1699 * Given a handle, find the corresponding cache element
1700 *
1701 * PARAMS
1702 * Handle [I] handle to an Image
1703 *
1704 * RETURNS
1705 * Success: The cache entry
1706 * Failure: NULL
1707 *
1708 */
1709static ICONCACHE* CURSORICON_FindCache(HANDLE handle)
1710{
1711 ICONCACHE *ptr;
1712 ICONCACHE *pRet=NULL;
1713 BOOL IsFound = FALSE;
1714 int count;
1715
1716 EnterCriticalSection( &IconCrst );
1717
1718 for (count = 0, ptr = IconAnchor; ptr != NULL && !IsFound; ptr = ptr->next, count++ )
1719 {
1720 if ( handle == ptr->handle )
1721 {
1722 IsFound = TRUE;
1723 pRet = ptr;
1724 }
1725 }
1726
1727 LeaveCriticalSection( &IconCrst );
1728
1729 return pRet;
1730}
1731
1732/**********************************************************************
1733 * CURSORICON_AddSharedIcon
1734 */
1735static void CURSORICON_AddSharedIcon( HMODULE hModule, HRSRC hRsrc, HRSRC hGroupRsrc, HANDLE handle )
1736{
1737 ICONCACHE *ptr = (ICONCACHE *)HeapAlloc( GetProcessHeap(), 0, sizeof(ICONCACHE) );
1738 if ( !ptr ) return;
1739
1740 ptr->hModule = hModule;
1741 ptr->hRsrc = hRsrc;
1742 ptr->handle = handle;
1743 ptr->hGroupRsrc = hGroupRsrc;
1744 ptr->count = 1;
1745
1746 EnterCriticalSection( &IconCrst );
1747 ptr->next = IconAnchor;
1748 IconAnchor = ptr;
1749 LeaveCriticalSection( &IconCrst );
1750}
1751
1752/**********************************************************************
1753 * CURSORICON_DelSharedIcon
1754 */
1755static INT CURSORICON_DelSharedIcon( HANDLE handle )
1756{
1757 INT count = -1;
1758 ICONCACHE *ptr;
1759
1760 EnterCriticalSection( &IconCrst );
1761
1762 for ( ptr = IconAnchor; ptr; ptr = ptr->next )
1763 if ( ptr->handle == handle )
1764 {
1765 if ( ptr->count > 0 ) ptr->count--;
1766 count = ptr->count;
1767 break;
1768 }
1769
1770 LeaveCriticalSection( &IconCrst );
1771
1772 return count;
1773}
1774
1775/**********************************************************************
1776 * CURSORICON_FreeModuleIcons
1777 */
1778void CURSORICON_FreeModuleIcons( HMODULE hModule )
1779{
1780 ICONCACHE **ptr = &IconAnchor;
1781
1782 EnterCriticalSection( &IconCrst );
1783
1784 while ( *ptr )
1785 {
1786 if ( (*ptr)->hModule == hModule )
1787 {
1788 ICONCACHE *freePtr = *ptr;
1789 *ptr = freePtr->next;
1790
1791#ifdef __WIN32OS2__
1792 CURSORICON_Destroy(freePtr->handle, CID_NONSHARED);
1793#else
1794 GlobalFree( freePtr->handle );
1795#endif
1796 HeapFree( GetProcessHeap(), 0, freePtr );
1797 continue;
1798 }
1799 ptr = &(*ptr)->next;
1800 }
1801
1802 LeaveCriticalSection( &IconCrst );
1803}
1804
Note: See TracBrowser for help on using the repository browser.