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

Last change on this file since 21916 was 21916, checked in by dmik, 14 years ago

Merge branch gcc-kmk to trunk.

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