2 * Cursor and icon support
4 * Copyright 1995 Alexandre Julliard
5 * 1996 Martin Von Loewis
12 * http://www.microsoft.com/win32dev/ui/icons.htm
14 * Cursors and icons are stored in a global heap block, with the
17 * CURSORICONINFO info;
21 * The bits structures are in the format of a device-dependent bitmap.
23 * This layout is very sub-optimal, as the bitmap bits are stored in
24 * the X client instead of in the server like other bitmaps; however,
25 * some programs (notably Paint Brush) expect to be able to manipulate
26 * the bits directly :-(
37 #include "cursoricon.h"
38 #include "sysmetrics.h"
48 Cursor CURSORICON_XCursor
= None
; /* Current X cursor */
49 static HCURSOR32 hActiveCursor
= 0; /* Active cursor */
50 static INT32 CURSOR_ShowCount
= 0; /* Cursor display count */
51 static RECT32 CURSOR_ClipRect
; /* Cursor clipping rect */
53 /**********************************************************************
54 * CURSORICON_FindBestIcon
56 * Find the icon closest to the requested size and number of colors.
58 static ICONDIRENTRY
*CURSORICON_FindBestIcon( CURSORICONDIR
*dir
, int width
,
59 int height
, int colors
)
61 int i
, maxcolors
, maxwidth
, maxheight
;
62 ICONDIRENTRY
*entry
, *bestEntry
= NULL
;
66 WARN(icon
, "Empty directory!\n" );
69 if (dir
->idCount
== 1) return &dir
->idEntries
[0].icon
; /* No choice... */
71 /* First find the exact size with less colors */
74 for (i
= 0, entry
= &dir
->idEntries
[0].icon
; i
< dir
->idCount
; i
++,entry
++)
75 if ((entry
->bWidth
== width
) && (entry
->bHeight
== height
) &&
76 (entry
->bColorCount
<= colors
) && (entry
->bColorCount
> maxcolors
))
79 maxcolors
= entry
->bColorCount
;
81 if (bestEntry
) return bestEntry
;
83 /* First find the exact size with more colors */
86 for (i
= 0, entry
= &dir
->idEntries
[0].icon
; i
< dir
->idCount
; i
++,entry
++)
87 if ((entry
->bWidth
== width
) && (entry
->bHeight
== height
) &&
88 (entry
->bColorCount
> colors
) && (entry
->bColorCount
<= maxcolors
))
91 maxcolors
= entry
->bColorCount
;
93 if (bestEntry
) return bestEntry
;
95 /* Now find a smaller one with less colors */
97 maxcolors
= maxwidth
= maxheight
= 0;
98 for (i
= 0, entry
= &dir
->idEntries
[0].icon
; i
< dir
->idCount
; i
++,entry
++)
99 if ((entry
->bWidth
<= width
) && (entry
->bHeight
<= height
) &&
100 (entry
->bWidth
>= maxwidth
) && (entry
->bHeight
>= maxheight
) &&
101 (entry
->bColorCount
<= colors
) && (entry
->bColorCount
> maxcolors
))
104 maxwidth
= entry
->bWidth
;
105 maxheight
= entry
->bHeight
;
106 maxcolors
= entry
->bColorCount
;
108 if (bestEntry
) return bestEntry
;
110 /* Now find a smaller one with more colors */
113 maxwidth
= maxheight
= 0;
114 for (i
= 0, entry
= &dir
->idEntries
[0].icon
; i
< dir
->idCount
; i
++,entry
++)
115 if ((entry
->bWidth
<= width
) && (entry
->bHeight
<= height
) &&
116 (entry
->bWidth
>= maxwidth
) && (entry
->bHeight
>= maxheight
) &&
117 (entry
->bColorCount
> colors
) && (entry
->bColorCount
<= maxcolors
))
120 maxwidth
= entry
->bWidth
;
121 maxheight
= entry
->bHeight
;
122 maxcolors
= entry
->bColorCount
;
124 if (bestEntry
) return bestEntry
;
126 /* Now find a larger one with less colors */
129 maxwidth
= maxheight
= 255;
130 for (i
= 0, entry
= &dir
->idEntries
[0].icon
; i
< dir
->idCount
; i
++,entry
++)
131 if ((entry
->bWidth
<= maxwidth
) && (entry
->bHeight
<= maxheight
) &&
132 (entry
->bColorCount
<= colors
) && (entry
->bColorCount
> maxcolors
))
135 maxwidth
= entry
->bWidth
;
136 maxheight
= entry
->bHeight
;
137 maxcolors
= entry
->bColorCount
;
139 if (bestEntry
) return bestEntry
;
141 /* Now find a larger one with more colors */
143 maxcolors
= maxwidth
= maxheight
= 255;
144 for (i
= 0, entry
= &dir
->idEntries
[0].icon
; i
< dir
->idCount
; i
++,entry
++)
145 if ((entry
->bWidth
<= maxwidth
) && (entry
->bHeight
<= maxheight
) &&
146 (entry
->bColorCount
> colors
) && (entry
->bColorCount
<= maxcolors
))
149 maxwidth
= entry
->bWidth
;
150 maxheight
= entry
->bHeight
;
151 maxcolors
= entry
->bColorCount
;
158 /**********************************************************************
159 * CURSORICON_FindBestCursor
161 * Find the cursor closest to the requested size.
163 static CURSORDIRENTRY
*CURSORICON_FindBestCursor( CURSORICONDIR
*dir
,
164 int width
, int height
)
166 int i
, maxwidth
, maxheight
;
167 CURSORDIRENTRY
*entry
, *bestEntry
= NULL
;
169 if (dir
->idCount
< 1)
171 WARN(cursor
, "Empty directory!\n" );
174 if (dir
->idCount
== 1) return &dir
->idEntries
[0].cursor
; /* No choice... */
176 /* First find the largest one smaller than or equal to the requested size*/
178 maxwidth
= maxheight
= 0;
179 for(i
= 0,entry
= &dir
->idEntries
[0].cursor
; i
< dir
->idCount
; i
++,entry
++)
180 if ((entry
->wWidth
<= width
) && (entry
->wHeight
<= height
) &&
181 (entry
->wWidth
> maxwidth
) && (entry
->wHeight
> maxheight
))
184 maxwidth
= entry
->wWidth
;
185 maxheight
= entry
->wHeight
;
187 if (bestEntry
) return bestEntry
;
189 /* Now find the smallest one larger than the requested size */
191 maxwidth
= maxheight
= 255;
192 for(i
= 0,entry
= &dir
->idEntries
[0].cursor
; i
< dir
->idCount
; i
++,entry
++)
193 if ((entry
->wWidth
< maxwidth
) && (entry
->wHeight
< maxheight
))
196 maxwidth
= entry
->wWidth
;
197 maxheight
= entry
->wHeight
;
204 /**********************************************************************
205 * CURSORICON_LoadDirEntry16
207 * Load the icon/cursor directory for a given resource name and find the
208 * best matching entry.
210 static BOOL32
CURSORICON_LoadDirEntry16( HINSTANCE32 hInstance
, SEGPTR name
,
211 INT32 width
, INT32 height
, INT32 colors
,
212 BOOL32 fCursor
, CURSORICONDIRENTRY
*dirEntry
)
217 CURSORICONDIRENTRY
*entry
= NULL
;
219 if (!(hRsrc
= FindResource16( hInstance
, name
,
220 fCursor
? RT_GROUP_CURSOR16
: RT_GROUP_ICON16
)))
222 if (!(hMem
= LoadResource16( hInstance
, hRsrc
))) return FALSE
;
223 if ((dir
= (CURSORICONDIR
*)LockResource16( hMem
)))
226 entry
= (CURSORICONDIRENTRY
*)CURSORICON_FindBestCursor( dir
,
229 entry
= (CURSORICONDIRENTRY
*)CURSORICON_FindBestIcon( dir
,
230 width
, height
, colors
);
231 if (entry
) *dirEntry
= *entry
;
233 FreeResource16( hMem
);
234 return (entry
!= NULL
);
238 /**********************************************************************
239 * CURSORICON_LoadDirEntry32
241 * Load the icon/cursor directory for a given resource name and find the
242 * best matching entry.
244 static BOOL32
CURSORICON_LoadDirEntry32( HINSTANCE32 hInstance
, LPCWSTR name
,
245 INT32 width
, INT32 height
, INT32 colors
,
246 BOOL32 fCursor
, CURSORICONDIRENTRY
*dirEntry
)
251 CURSORICONDIRENTRY
*entry
= NULL
;
253 if (!(hRsrc
= FindResource32W( hInstance
, name
,
254 fCursor
? RT_GROUP_CURSOR32W
: RT_GROUP_ICON32W
)))
256 if (!(hMem
= LoadResource32( hInstance
, hRsrc
))) return FALSE
;
257 if ((dir
= (CURSORICONDIR
*)LockResource32( hMem
)))
260 entry
= (CURSORICONDIRENTRY
*)CURSORICON_FindBestCursor( dir
,
263 entry
= (CURSORICONDIRENTRY
*)CURSORICON_FindBestIcon( dir
,
264 width
, height
, colors
);
265 if (entry
) *dirEntry
= *entry
;
267 FreeResource32( hMem
);
268 return (entry
!= NULL
);
272 /**********************************************************************
273 * CURSORICON_CreateFromResource
275 * Create a cursor or icon from in-memory resource template.
277 * FIXME: Adjust icon size when width and height are nonzero (stretchblt).
278 * Convert to mono when cFlag is LR_MONOCHROME. Do something
279 * with cbSize parameter as well.
281 static HGLOBAL16
CURSORICON_CreateFromResource( HINSTANCE16 hInstance
, HGLOBAL16 hObj
, LPBYTE bits
,
282 UINT32 cbSize
, BOOL32 bIcon
, DWORD dwVersion
,
283 INT32 width
, INT32 height
, UINT32 cFlag
)
285 int sizeAnd
, sizeXor
;
286 HBITMAP32 hAndBits
= 0, hXorBits
= 0; /* error condition for later */
287 BITMAPOBJ
*bmpXor
, *bmpAnd
;
288 POINT16 hotspot
= { 0 ,0 };
292 TRACE(cursor
,"%08x (%u bytes), ver %08x, %ix%i %s %s\n",
293 (unsigned)bits
, cbSize
, (unsigned)dwVersion
, width
, height
,
294 bIcon
? "icon" : "cursor", cFlag
? "mono" : "" );
295 if (dwVersion
== 0x00020000)
297 FIXME(cursor
,"\t2.xx resources are not supported\n");
302 bmi
= (BITMAPINFO
*)bits
;
303 else /* get the hotspot */
305 POINT16
*pt
= (POINT16
*)bits
;
307 bmi
= (BITMAPINFO
*)(pt
+ 1);
310 /* Check bitmap header */
312 if ( (bmi
->bmiHeader
.biSize
!= sizeof(BITMAPCOREHEADER
)) &&
313 (bmi
->bmiHeader
.biSize
!= sizeof(BITMAPINFOHEADER
) ||
314 bmi
->bmiHeader
.biCompression
!= BI_RGB
) )
316 WARN(cursor
,"\tinvalid resource bitmap header.\n");
320 if( (hdc
= GetDC32( 0 )) )
323 INT32 size
= DIB_BitmapInfoSize( bmi
, DIB_RGB_COLORS
);
325 /* Make sure we have room for the monochrome bitmap later on.
326 * Note that BITMAPINFOINFO and BITMAPCOREHEADER are the same
327 * up to and including the biBitCount. In-memory icon resource
328 * format is as follows:
330 * BITMAPINFOHEADER icHeader // DIB header
331 * RGBQUAD icColors[] // Color table
332 * BYTE icXOR[] // DIB bits for XOR mask
333 * BYTE icAND[] // DIB bits for AND mask
336 if( (pInfo
= (BITMAPINFO
*)HeapAlloc( GetProcessHeap(), 0,
337 MAX(size
, sizeof(BITMAPINFOHEADER
) + 2*sizeof(RGBQUAD
)))) )
339 memcpy( pInfo
, bmi
, size
);
340 pInfo
->bmiHeader
.biHeight
/= 2;
342 /* Create the XOR bitmap */
344 hXorBits
= CreateDIBitmap32( hdc
, &pInfo
->bmiHeader
, CBM_INIT
,
345 (char*)bmi
+ size
, pInfo
, DIB_RGB_COLORS
);
348 char* bits
= (char *)bmi
+ size
+ bmi
->bmiHeader
.biHeight
*
349 DIB_GetDIBWidthBytes(bmi
->bmiHeader
.biWidth
,
350 bmi
->bmiHeader
.biBitCount
) / 2;
352 pInfo
->bmiHeader
.biBitCount
= 1;
353 if (pInfo
->bmiHeader
.biSize
== sizeof(BITMAPINFOHEADER
))
355 RGBQUAD
*rgb
= pInfo
->bmiColors
;
357 pInfo
->bmiHeader
.biClrUsed
= pInfo
->bmiHeader
.biClrImportant
= 2;
358 rgb
[0].rgbBlue
= rgb
[0].rgbGreen
= rgb
[0].rgbRed
= 0x00;
359 rgb
[1].rgbBlue
= rgb
[1].rgbGreen
= rgb
[1].rgbRed
= 0xff;
360 rgb
[0].rgbReserved
= rgb
[1].rgbReserved
= 0;
364 RGBTRIPLE
*rgb
= (RGBTRIPLE
*)(((BITMAPCOREHEADER
*)pInfo
) + 1);
366 rgb
[0].rgbtBlue
= rgb
[0].rgbtGreen
= rgb
[0].rgbtRed
= 0x00;
367 rgb
[1].rgbtBlue
= rgb
[1].rgbtGreen
= rgb
[1].rgbtRed
= 0xff;
370 /* Create the AND bitmap */
372 hAndBits
= CreateDIBitmap32( hdc
, &pInfo
->bmiHeader
, CBM_INIT
,
373 bits
, pInfo
, DIB_RGB_COLORS
);
374 if( !hAndBits
) DeleteObject32( hXorBits
);
376 HeapFree( GetProcessHeap(), 0, pInfo
);
378 ReleaseDC32( 0, hdc
);
381 if( !hXorBits
|| !hAndBits
)
383 WARN(cursor
,"\tunable to create an icon bitmap.\n");
387 /* Now create the CURSORICONINFO structure */
389 bmpXor
= (BITMAPOBJ
*) GDI_GetObjPtr( hXorBits
, BITMAP_MAGIC
);
390 bmpAnd
= (BITMAPOBJ
*) GDI_GetObjPtr( hAndBits
, BITMAP_MAGIC
);
391 sizeXor
= bmpXor
->bitmap
.bmHeight
* bmpXor
->bitmap
.bmWidthBytes
;
392 sizeAnd
= bmpAnd
->bitmap
.bmHeight
* bmpAnd
->bitmap
.bmWidthBytes
;
394 if (hObj
) hObj
= GlobalReAlloc16( hObj
,
395 sizeof(CURSORICONINFO
) + sizeXor
+ sizeAnd
, GMEM_MOVEABLE
);
396 if (!hObj
) hObj
= GlobalAlloc16( GMEM_MOVEABLE
,
397 sizeof(CURSORICONINFO
) + sizeXor
+ sizeAnd
);
400 CURSORICONINFO
*info
;
402 /* Make it owned by the module */
403 if (hInstance
) FarSetOwner( hObj
, GetExePtr(hInstance
) );
405 info
= (CURSORICONINFO
*)GlobalLock16( hObj
);
406 info
->ptHotSpot
.x
= hotspot
.x
;
407 info
->ptHotSpot
.y
= hotspot
.y
;
408 info
->nWidth
= bmpXor
->bitmap
.bmWidth
;
409 info
->nHeight
= bmpXor
->bitmap
.bmHeight
;
410 info
->nWidthBytes
= bmpXor
->bitmap
.bmWidthBytes
;
411 info
->bPlanes
= bmpXor
->bitmap
.bmPlanes
;
412 info
->bBitsPerPixel
= bmpXor
->bitmap
.bmBitsPixel
;
414 /* Transfer the bitmap bits to the CURSORICONINFO structure */
416 GetBitmapBits32( hAndBits
, sizeAnd
, (char *)(info
+ 1) );
417 GetBitmapBits32( hXorBits
, sizeXor
, (char *)(info
+ 1) + sizeAnd
);
418 GlobalUnlock16( hObj
);
421 DeleteObject32( hXorBits
);
422 DeleteObject32( hAndBits
);
427 /**********************************************************************
428 * CreateIconFromResourceEx16 (USER.450)
430 * FIXME: not sure about exact parameter types
432 HICON16 WINAPI
CreateIconFromResourceEx16( LPBYTE bits
, UINT16 cbSize
, BOOL16 bIcon
,
433 DWORD dwVersion
, INT16 width
, INT16 height
, UINT16 cFlag
)
435 TDB
* pTask
= (TDB
*)GlobalLock16( GetCurrentTask() );
437 return CURSORICON_CreateFromResource( pTask
->hInstance
, 0, bits
, cbSize
, bIcon
, dwVersion
,
438 width
, height
, cFlag
);
443 /**********************************************************************
444 * CreateIconFromResource (USER32.76)
446 * bon@elektron.ikp.physik.tu-darmstadt.de 971130: Test with weditres
447 * showed only blank layout. Couldn't determine if this is a problem
448 * with CreateIconFromResource32 or the application. The application
449 * windows behaves strange (no redraw) before CreateIconFromResource32
451 HICON32 WINAPI
CreateIconFromResource32( LPBYTE bits
, UINT32 cbSize
,
452 BOOL32 bIcon
, DWORD dwVersion
)
455 ret
= CreateIconFromResourceEx16( bits
, cbSize
, bIcon
, dwVersion
, 0,0,0);
456 FIXME(icon
,"probably only a stub\n");
457 TRACE(icon
, "%s at %p size %d winver %d return 0x%04x\n",
458 (bIcon
)?"Icon":"Cursor",bits
,cbSize
,bIcon
,ret
);
463 /**********************************************************************
464 * CreateIconFromResourceEx32 (USER32.77)
466 HICON32 WINAPI
CreateIconFromResourceEx32( LPBYTE bits
, UINT32 cbSize
,
467 BOOL32 bIcon
, DWORD dwVersion
,
468 INT32 width
, INT32 height
,
471 return CreateIconFromResourceEx16( bits
, cbSize
, bIcon
, dwVersion
, width
, height
, cFlag
);
475 /**********************************************************************
478 * Load a cursor or icon from a 16-bit resource.
480 static HGLOBAL16
CURSORICON_Load16( HINSTANCE16 hInstance
, SEGPTR name
,
481 INT32 width
, INT32 height
, INT32 colors
,
486 CURSORICONDIRENTRY dirEntry
;
488 if (!hInstance
) /* OEM cursor/icon */
490 if (HIWORD(name
)) /* Check for '#xxx' name */
492 char *ptr
= PTR_SEG_TO_LIN( name
);
493 if (ptr
[0] != '#') return 0;
494 if (!(name
= (SEGPTR
)atoi( ptr
+ 1 ))) return 0;
496 return OBM_LoadCursorIcon( LOWORD(name
), fCursor
);
499 /* Find the best entry in the directory */
501 if ( !CURSORICON_LoadDirEntry16( hInstance
, name
, width
, height
,
502 colors
, fCursor
, &dirEntry
) ) return 0;
503 /* Load the resource */
505 if ( (hRsrc
= FindResource16( hInstance
,
506 MAKEINTRESOURCE16( dirEntry
.icon
.wResId
),
507 fCursor
? RT_CURSOR16
: RT_ICON16
)) )
509 /* 16-bit icon or cursor resources are processed
510 * transparently by the LoadResource16() via custom
511 * resource handlers set by SetResourceHandler().
514 if ( (handle
= LoadResource16( hInstance
, hRsrc
)) )
520 /**********************************************************************
523 * Load a cursor or icon from a 32-bit resource.
525 static HGLOBAL32
CURSORICON_Load32( HINSTANCE32 hInstance
, LPCWSTR name
,
526 int width
, int height
, int colors
,
531 CURSORICONDIRENTRY dirEntry
;
533 if(!hInstance
) /* OEM cursor/icon */
538 LPSTR ansi
= HEAP_strdupWtoA(GetProcessHeap(),0,name
);
539 if( ansi
[0]=='#') /*Check for '#xxx' name */
541 resid
= atoi(ansi
+1);
542 HeapFree( GetProcessHeap(), 0, ansi
);
546 HeapFree( GetProcessHeap(), 0, ansi
);
550 else resid
= LOWORD(name
);
551 return OBM_LoadCursorIcon(resid
, fCursor
);
554 /* Find the best entry in the directory */
556 if ( !CURSORICON_LoadDirEntry32( hInstance
, name
, width
, height
,
557 colors
, fCursor
, &dirEntry
) ) return 0;
558 /* Load the resource */
560 if ( (hRsrc
= FindResource32W( hInstance
,
561 MAKEINTRESOURCE32W( dirEntry
.icon
.wResId
),
562 fCursor
? RT_CURSOR32W
: RT_ICON32W
)) )
565 if ( (handle
= LoadResource32( hInstance
, hRsrc
)) )
567 /* Hack to keep LoadCursor/Icon32() from spawning multiple
568 * copies of the same object.
570 #define pRsrcEntry ((LPIMAGE_RESOURCE_DATA_ENTRY)hRsrc)
571 if( !pRsrcEntry
->ResourceHandle
)
573 LPBYTE bits
= (LPBYTE
)LockResource32( handle
);
574 h
= CURSORICON_CreateFromResource( 0, 0, bits
, dirEntry
.icon
.dwBytesInRes
,
575 !fCursor
, 0x00030000, width
, height
, LR_DEFAULTCOLOR
);
576 pRsrcEntry
->ResourceHandle
= h
;
578 else h
= pRsrcEntry
->ResourceHandle
;
587 /***********************************************************************
590 * Make a copy of a cursor or icon.
592 static HGLOBAL16
CURSORICON_Copy( HINSTANCE16 hInstance
, HGLOBAL16 handle
)
594 char *ptrOld
, *ptrNew
;
598 if (!(ptrOld
= (char *)GlobalLock16( handle
))) return 0;
599 if (!(hInstance
= GetExePtr( hInstance
))) return 0;
600 size
= GlobalSize16( handle
);
601 hNew
= GlobalAlloc16( GMEM_MOVEABLE
, size
);
602 FarSetOwner( hNew
, hInstance
);
603 ptrNew
= (char *)GlobalLock16( hNew
);
604 memcpy( ptrNew
, ptrOld
, size
);
605 GlobalUnlock16( handle
);
606 GlobalUnlock16( hNew
);
610 /***********************************************************************
611 * CURSORICON_IconToCursor
613 * Converts bitmap to mono and truncates if icon is too large (should
614 * probably do StretchBlt() instead).
616 HCURSOR16
CURSORICON_IconToCursor(HICON16 hIcon
, BOOL32 bSemiTransparent
)
619 CURSORICONINFO
*pIcon
= NULL
;
620 HTASK16 hTask
= GetCurrentTask();
621 TDB
* pTask
= (TDB
*)GlobalLock16(hTask
);
624 if (!(pIcon
= (CURSORICONINFO
*)GlobalLock16( hIcon
))) return FALSE
;
625 if (pIcon
->bPlanes
* pIcon
->bBitsPerPixel
== 1)
626 hRet
= CURSORICON_Copy( pTask
->hInstance
, hIcon
);
631 int maxx
, maxy
, ix
, iy
, bpp
= pIcon
->bBitsPerPixel
;
632 BYTE
* psPtr
, *pxbPtr
= pXorBits
;
633 unsigned xor_width
, and_width
, val_base
= 0xffffffff >> (32 - bpp
);
639 TRACE(icon
, "[%04x] %ix%i %ibpp (bogus %ibps)\n",
640 hIcon
, pIcon
->nWidth
, pIcon
->nHeight
, pIcon
->bBitsPerPixel
, pIcon
->nWidthBytes
);
642 xor_width
= BITMAP_GetBitsWidth( pIcon
->nWidth
, bpp
);
643 and_width
= BITMAP_GetBitsWidth( pIcon
->nWidth
, 1 );
644 psPtr
= (BYTE
*)(pIcon
+ 1) + pIcon
->nHeight
* and_width
;
646 memset(pXorBits
, 0, 128);
647 cI
.bBitsPerPixel
= 1; cI
.bPlanes
= 1;
648 cI
.ptHotSpot
.x
= cI
.ptHotSpot
.y
= 15;
649 cI
.nWidth
= 32; cI
.nHeight
= 32;
650 cI
.nWidthBytes
= 4; /* 32x1bpp */
652 maxx
= (pIcon
->nWidth
> 32) ? 32 : pIcon
->nWidth
;
653 maxy
= (pIcon
->nHeight
> 32) ? 32 : pIcon
->nHeight
;
655 for( iy
= 0; iy
< maxy
; iy
++ )
657 unsigned shift
= iy
% 2;
659 memcpy( pAndBits
+ iy
* 4, (BYTE
*)(pIcon
+ 1) + iy
* and_width
,
660 (and_width
> 4) ? 4 : and_width
);
661 for( ix
= 0; ix
< maxx
; ix
++ )
663 if( bSemiTransparent
&& ((ix
+shift
)%2) )
665 /* set AND bit, XOR bit stays 0 */
667 pbc
= pAndBits
+ iy
* 4 + ix
/8;
668 *pbc
|= 0x80 >> (ix
%8);
672 /* keep AND bit, set XOR bit */
674 unsigned *psc
= (unsigned*)(psPtr
+ (ix
* bpp
)/8);
675 unsigned val
= ((*psc
) >> (ix
* bpp
)%8) & val_base
;
676 col
= COLOR_ToLogical(val
);
677 if( (GetRValue(col
) + GetGValue(col
) + GetBValue(col
)) > 0x180 )
680 *pbc
|= 0x80 >> (ix
%8);
688 hRet
= CreateCursorIconIndirect( pTask
->hInstance
, &cI
, pAndBits
, pXorBits
);
690 if( !hRet
) /* fall back on default drag cursor */
691 hRet
= CURSORICON_Copy( pTask
->hInstance
,
692 CURSORICON_Load16(0,MAKEINTRESOURCE16(OCR_DRAGOBJECT
),
693 SYSMETRICS_CXCURSOR
, SYSMETRICS_CYCURSOR
, 1, TRUE
) );
700 /***********************************************************************
701 * LoadCursor16 (USER.173)
703 HCURSOR16 WINAPI
LoadCursor16( HINSTANCE16 hInstance
, SEGPTR name
)
706 TRACE(cursor
, "%04x '%s'\n",
707 hInstance
, (char *)PTR_SEG_TO_LIN( name
) );
709 TRACE(cursor
, "%04x %04x\n",
710 hInstance
, LOWORD(name
) );
712 return CURSORICON_Load16( hInstance
, name
,
713 SYSMETRICS_CXCURSOR
, SYSMETRICS_CYCURSOR
, 1, TRUE
);
717 /***********************************************************************
718 * LoadIcon16 (USER.174)
720 HICON16 WINAPI
LoadIcon16( HINSTANCE16 hInstance
, SEGPTR name
)
723 TRACE(icon
, "%04x '%s'\n",
724 hInstance
, (char *)PTR_SEG_TO_LIN( name
) );
726 TRACE(icon
, "%04x %04x\n",
727 hInstance
, LOWORD(name
) );
729 return CURSORICON_Load16( hInstance
, name
,
730 SYSMETRICS_CXICON
, SYSMETRICS_CYICON
,
731 MIN( 16, COLOR_GetSystemPaletteSize() ), FALSE
);
735 /***********************************************************************
736 * CreateCursor16 (USER.406)
738 HCURSOR16 WINAPI
CreateCursor16( HINSTANCE16 hInstance
,
739 INT16 xHotSpot
, INT16 yHotSpot
,
740 INT16 nWidth
, INT16 nHeight
,
741 LPCVOID lpANDbits
, LPCVOID lpXORbits
)
743 CURSORICONINFO info
= { { xHotSpot
, yHotSpot
}, nWidth
, nHeight
, 0, 1, 1 };
745 TRACE(cursor
, "%dx%d spot=%d,%d xor=%p and=%p\n",
746 nWidth
, nHeight
, xHotSpot
, yHotSpot
, lpXORbits
, lpANDbits
);
747 return CreateCursorIconIndirect( hInstance
, &info
, lpANDbits
, lpXORbits
);
751 /***********************************************************************
752 * CreateCursor32 (USER32.67)
754 HCURSOR32 WINAPI
CreateCursor32( HINSTANCE32 hInstance
,
755 INT32 xHotSpot
, INT32 yHotSpot
,
756 INT32 nWidth
, INT32 nHeight
,
757 LPCVOID lpANDbits
, LPCVOID lpXORbits
)
759 CURSORICONINFO info
= { { xHotSpot
, yHotSpot
}, nWidth
, nHeight
, 0, 1, 1 };
761 TRACE(cursor
, "%dx%d spot=%d,%d xor=%p and=%p\n",
762 nWidth
, nHeight
, xHotSpot
, yHotSpot
, lpXORbits
, lpANDbits
);
763 return CreateCursorIconIndirect( 0, &info
, lpANDbits
, lpXORbits
);
767 /***********************************************************************
768 * CreateIcon16 (USER.407)
770 HICON16 WINAPI
CreateIcon16( HINSTANCE16 hInstance
, INT16 nWidth
,
771 INT16 nHeight
, BYTE bPlanes
, BYTE bBitsPixel
,
772 LPCVOID lpANDbits
, LPCVOID lpXORbits
)
774 CURSORICONINFO info
= { { 0, 0 }, nWidth
, nHeight
, 0, bPlanes
, bBitsPixel
};
776 TRACE(icon
, "%dx%dx%d, xor=%p, and=%p\n",
777 nWidth
, nHeight
, bPlanes
* bBitsPixel
, lpXORbits
, lpANDbits
);
778 return CreateCursorIconIndirect( hInstance
, &info
, lpANDbits
, lpXORbits
);
782 /***********************************************************************
783 * CreateIcon32 (USER32.75)
785 HICON32 WINAPI
CreateIcon32( HINSTANCE32 hInstance
, INT32 nWidth
,
786 INT32 nHeight
, BYTE bPlanes
, BYTE bBitsPixel
,
787 LPCVOID lpANDbits
, LPCVOID lpXORbits
)
789 CURSORICONINFO info
= { { 0, 0 }, nWidth
, nHeight
, 0, bPlanes
, bBitsPixel
};
791 TRACE(icon
, "%dx%dx%d, xor=%p, and=%p\n",
792 nWidth
, nHeight
, bPlanes
* bBitsPixel
, lpXORbits
, lpANDbits
);
793 return CreateCursorIconIndirect( 0, &info
, lpANDbits
, lpXORbits
);
797 /***********************************************************************
798 * CreateCursorIconIndirect (USER.408)
800 HGLOBAL16 WINAPI
CreateCursorIconIndirect( HINSTANCE16 hInstance
,
801 CURSORICONINFO
*info
,
807 int sizeAnd
, sizeXor
;
809 hInstance
= GetExePtr( hInstance
); /* Make it a module handle */
810 if (!lpXORbits
|| !lpANDbits
|| info
->bPlanes
!= 1) return 0;
811 info
->nWidthBytes
= BITMAP_WIDTH_BYTES(info
->nWidth
,info
->bBitsPerPixel
);
812 sizeXor
= info
->nHeight
* info
->nWidthBytes
;
813 sizeAnd
= info
->nHeight
* BITMAP_WIDTH_BYTES( info
->nWidth
, 1 );
814 if (!(handle
= GlobalAlloc16( GMEM_MOVEABLE
,
815 sizeof(CURSORICONINFO
) + sizeXor
+ sizeAnd
)))
817 if (hInstance
) FarSetOwner( handle
, hInstance
);
818 ptr
= (char *)GlobalLock16( handle
);
819 memcpy( ptr
, info
, sizeof(*info
) );
820 memcpy( ptr
+ sizeof(CURSORICONINFO
), lpANDbits
, sizeAnd
);
821 memcpy( ptr
+ sizeof(CURSORICONINFO
) + sizeAnd
, lpXORbits
, sizeXor
);
822 GlobalUnlock16( handle
);
827 /***********************************************************************
828 * CopyIcon16 (USER.368)
830 HICON16 WINAPI
CopyIcon16( HINSTANCE16 hInstance
, HICON16 hIcon
)
832 TRACE(icon
, "%04x %04x\n", hInstance
, hIcon
);
833 return CURSORICON_Copy( hInstance
, hIcon
);
837 /***********************************************************************
838 * CopyIcon32 (USER32.60)
840 HICON32 WINAPI
CopyIcon32( HICON32 hIcon
)
842 HTASK16 hTask
= GetCurrentTask ();
843 TDB
* pTask
= (TDB
*) GlobalLock16 (hTask
);
844 TRACE(icon
, "%04x\n", hIcon
);
845 return CURSORICON_Copy( pTask
->hInstance
, hIcon
);
849 /***********************************************************************
850 * CopyCursor16 (USER.369)
852 HCURSOR16 WINAPI
CopyCursor16( HINSTANCE16 hInstance
, HCURSOR16 hCursor
)
854 TRACE(cursor
, "%04x %04x\n", hInstance
, hCursor
);
855 return CURSORICON_Copy( hInstance
, hCursor
);
859 /***********************************************************************
860 * DestroyIcon16 (USER.457)
862 BOOL16 WINAPI
DestroyIcon16( HICON16 hIcon
)
864 return DestroyIcon32( hIcon
);
868 /***********************************************************************
869 * DestroyIcon32 (USER32.133)
871 BOOL32 WINAPI
DestroyIcon32( HICON32 hIcon
)
873 TRACE(icon
, "%04x\n", hIcon
);
874 /* FIXME: should check for OEM icon here */
875 return (FreeResource16( hIcon
) == 0);
879 /***********************************************************************
880 * DestroyCursor16 (USER.458)
882 BOOL16 WINAPI
DestroyCursor16( HCURSOR16 hCursor
)
884 return DestroyCursor32( hCursor
);
888 /***********************************************************************
889 * DestroyCursor32 (USER32.132)
891 BOOL32 WINAPI
DestroyCursor32( HCURSOR32 hCursor
)
893 TRACE(cursor
, "%04x\n", hCursor
);
894 /* FIXME: should check for OEM cursor here */
895 return (FreeResource16( hCursor
) == 0);
899 /***********************************************************************
900 * DrawIcon16 (USER.84)
902 BOOL16 WINAPI
DrawIcon16( HDC16 hdc
, INT16 x
, INT16 y
, HICON16 hIcon
)
904 return DrawIcon32( hdc
, x
, y
, hIcon
);
908 /***********************************************************************
909 * DrawIcon32 (USER32.159)
911 BOOL32 WINAPI
DrawIcon32( HDC32 hdc
, INT32 x
, INT32 y
, HICON32 hIcon
)
915 HBITMAP32 hXorBits
, hAndBits
;
916 COLORREF oldFg
, oldBg
;
918 if (!(ptr
= (CURSORICONINFO
*)GlobalLock16( hIcon
))) return FALSE
;
919 if (!(hMemDC
= CreateCompatibleDC32( hdc
))) return FALSE
;
920 hAndBits
= CreateBitmap32( ptr
->nWidth
, ptr
->nHeight
, 1, 1,
922 hXorBits
= CreateBitmap32( ptr
->nWidth
, ptr
->nHeight
, ptr
->bPlanes
,
923 ptr
->bBitsPerPixel
, (char *)(ptr
+ 1)
924 + ptr
->nHeight
* BITMAP_WIDTH_BYTES(ptr
->nWidth
,1) );
925 oldFg
= SetTextColor32( hdc
, RGB(0,0,0) );
926 oldBg
= SetBkColor32( hdc
, RGB(255,255,255) );
928 if (hXorBits
&& hAndBits
)
930 HBITMAP32 hBitTemp
= SelectObject32( hMemDC
, hAndBits
);
931 BitBlt32( hdc
, x
, y
, ptr
->nWidth
, ptr
->nHeight
, hMemDC
, 0, 0, SRCAND
);
932 SelectObject32( hMemDC
, hXorBits
);
933 BitBlt32(hdc
, x
, y
, ptr
->nWidth
, ptr
->nHeight
, hMemDC
, 0, 0,SRCINVERT
);
934 SelectObject32( hMemDC
, hBitTemp
);
936 DeleteDC32( hMemDC
);
937 if (hXorBits
) DeleteObject32( hXorBits
);
938 if (hAndBits
) DeleteObject32( hAndBits
);
939 GlobalUnlock16( hIcon
);
940 SetTextColor32( hdc
, oldFg
);
941 SetBkColor32( hdc
, oldBg
);
946 /***********************************************************************
947 * DumpIcon (USER.459)
949 DWORD WINAPI
DumpIcon( SEGPTR pInfo
, WORD
*lpLen
,
950 SEGPTR
*lpXorBits
, SEGPTR
*lpAndBits
)
952 CURSORICONINFO
*info
= PTR_SEG_TO_LIN( pInfo
);
953 int sizeAnd
, sizeXor
;
956 sizeXor
= info
->nHeight
* info
->nWidthBytes
;
957 sizeAnd
= info
->nHeight
* BITMAP_WIDTH_BYTES( info
->nWidth
, 1 );
958 if (lpAndBits
) *lpAndBits
= pInfo
+ sizeof(CURSORICONINFO
);
959 if (lpXorBits
) *lpXorBits
= pInfo
+ sizeof(CURSORICONINFO
) + sizeAnd
;
960 if (lpLen
) *lpLen
= sizeof(CURSORICONINFO
) + sizeAnd
+ sizeXor
;
961 return MAKELONG( sizeXor
, sizeXor
);
965 /***********************************************************************
966 * CURSORICON_SetCursor
968 * Change the X cursor. Helper function for SetCursor() and ShowCursor().
969 * The Xlib critical section must be entered before calling this function.
971 static BOOL32
CURSORICON_SetCursor( HCURSOR16 hCursor
)
973 Pixmap pixmapBits
, pixmapMask
, pixmapAll
;
975 Cursor cursor
= None
;
977 if (!hCursor
) /* Create an empty cursor */
979 static const char data
[] = { 0 };
981 bg
.red
= bg
.green
= bg
.blue
= 0x0000;
982 pixmapBits
= XCreateBitmapFromData( display
, rootWindow
, data
, 1, 1 );
985 cursor
= XCreatePixmapCursor( display
, pixmapBits
, pixmapBits
,
987 XFreePixmap( display
, pixmapBits
);
990 else /* Create the X cursor from the bits */
995 if (!(ptr
= (CURSORICONINFO
*)GlobalLock16( hCursor
))) return FALSE
;
996 if (ptr
->bPlanes
* ptr
->bBitsPerPixel
!= 1)
998 WARN(cursor
, "Cursor %04x has more than 1 bpp!\n", hCursor
);
1002 /* Create a pixmap and transfer all the bits to it */
1004 /* NOTE: Following hack works, but only because XFree depth
1005 * 1 images really use 1 bit/pixel (and so the same layout
1006 * as the Windows cursor data). Perhaps use a more generic
1009 pixmapAll
= XCreatePixmap( display
, rootWindow
,
1010 ptr
->nWidth
, ptr
->nHeight
* 2, 1 );
1011 image
= XCreateImage( display
, DefaultVisualOfScreen(screen
),
1012 1, ZPixmap
, 0, (char *)(ptr
+ 1), ptr
->nWidth
,
1013 ptr
->nHeight
* 2, 16, ptr
->nWidthBytes
);
1016 image
->byte_order
= MSBFirst
;
1017 image
->bitmap_bit_order
= MSBFirst
;
1018 image
->bitmap_unit
= 16;
1019 _XInitImageFuncPtrs(image
);
1021 XPutImage( display
, pixmapAll
, BITMAP_monoGC
, image
,
1022 0, 0, 0, 0, ptr
->nWidth
, ptr
->nHeight
* 2 );
1024 XDestroyImage( image
);
1027 /* Now create the 2 pixmaps for bits and mask */
1029 pixmapBits
= XCreatePixmap( display
, rootWindow
,
1030 ptr
->nWidth
, ptr
->nHeight
, 1 );
1031 pixmapMask
= XCreatePixmap( display
, rootWindow
,
1032 ptr
->nWidth
, ptr
->nHeight
, 1 );
1034 /* Make sure everything went OK so far */
1036 if (pixmapBits
&& pixmapMask
&& pixmapAll
)
1038 /* We have to do some magic here, as cursors are not fully
1039 * compatible between Windows and X11. Under X11, there
1040 * are only 3 possible color cursor: black, white and
1041 * masked. So we map the 4th Windows color (invert the
1042 * bits on the screen) to black. This require some boolean
1046 * Xor And Result | Bits Mask Result
1047 * 0 0 black | 0 1 background
1048 * 0 1 no change | X 0 no change
1049 * 1 0 white | 1 1 foreground
1050 * 1 1 inverted | 0 1 background
1053 * Bits = 'Xor' and not 'And'
1054 * Mask = 'Xor' or not 'And'
1056 * FIXME: apparently some servers do support 'inverted' color.
1057 * I don't know if it's correct per the X spec, but maybe
1058 * we ought to take advantage of it. -- AJ
1060 XCopyArea( display
, pixmapAll
, pixmapBits
, BITMAP_monoGC
,
1061 0, 0, ptr
->nWidth
, ptr
->nHeight
, 0, 0 );
1062 XCopyArea( display
, pixmapAll
, pixmapMask
, BITMAP_monoGC
,
1063 0, 0, ptr
->nWidth
, ptr
->nHeight
, 0, 0 );
1064 XSetFunction( display
, BITMAP_monoGC
, GXandReverse
);
1065 XCopyArea( display
, pixmapAll
, pixmapBits
, BITMAP_monoGC
,
1066 0, ptr
->nHeight
, ptr
->nWidth
, ptr
->nHeight
, 0, 0 );
1067 XSetFunction( display
, BITMAP_monoGC
, GXorReverse
);
1068 XCopyArea( display
, pixmapAll
, pixmapMask
, BITMAP_monoGC
,
1069 0, ptr
->nHeight
, ptr
->nWidth
, ptr
->nHeight
, 0, 0 );
1070 XSetFunction( display
, BITMAP_monoGC
, GXcopy
);
1071 fg
.red
= fg
.green
= fg
.blue
= 0xffff;
1072 bg
.red
= bg
.green
= bg
.blue
= 0x0000;
1073 cursor
= XCreatePixmapCursor( display
, pixmapBits
, pixmapMask
,
1074 &fg
, &bg
, ptr
->ptHotSpot
.x
, ptr
->ptHotSpot
.y
);
1077 /* Now free everything */
1079 if (pixmapAll
) XFreePixmap( display
, pixmapAll
);
1080 if (pixmapBits
) XFreePixmap( display
, pixmapBits
);
1081 if (pixmapMask
) XFreePixmap( display
, pixmapMask
);
1082 GlobalUnlock16( hCursor
);
1085 if (cursor
== None
) return FALSE
;
1086 if (CURSORICON_XCursor
!= None
) XFreeCursor( display
, CURSORICON_XCursor
);
1087 CURSORICON_XCursor
= cursor
;
1089 if (rootWindow
!= DefaultRootWindow(display
))
1091 /* Set the cursor on the desktop window */
1092 XDefineCursor( display
, rootWindow
, cursor
);
1096 /* Set the same cursor for all top-level windows */
1097 HWND32 hwnd
= GetWindow32( GetDesktopWindow32(), GW_CHILD
);
1100 Window win
= WIN_GetXWindow( hwnd
);
1101 if (win
&& win
!=DefaultRootWindow(display
))
1102 XDefineCursor( display
, win
, cursor
);
1103 hwnd
= GetWindow32( hwnd
, GW_HWNDNEXT
);
1110 /***********************************************************************
1111 * SetCursor16 (USER.69)
1113 HCURSOR16 WINAPI
SetCursor16( HCURSOR16 hCursor
)
1115 return (HCURSOR16
)SetCursor32( hCursor
);
1119 /***********************************************************************
1120 * SetCursor32 (USER32.472)
1122 * A handle to the previous cursor shape.
1124 HCURSOR32 WINAPI
SetCursor32(
1125 HCURSOR32 hCursor
/* Handle of cursor to show */
1127 HCURSOR32 hOldCursor
;
1129 if (hCursor
== hActiveCursor
) return hActiveCursor
; /* No change */
1130 TRACE(cursor
, "%04x\n", hCursor
);
1131 hOldCursor
= hActiveCursor
;
1132 hActiveCursor
= hCursor
;
1133 /* Change the cursor shape only if it is visible */
1134 if (CURSOR_ShowCount
>= 0)
1136 EnterCriticalSection( &X11DRV_CritSection
);
1137 CALL_LARGE_STACK( CURSORICON_SetCursor
, hActiveCursor
);
1138 LeaveCriticalSection( &X11DRV_CritSection
);
1144 /***********************************************************************
1145 * SetCursorPos16 (USER.70)
1147 void WINAPI
SetCursorPos16( INT16 x
, INT16 y
)
1149 SetCursorPos32( x
, y
);
1153 /***********************************************************************
1154 * SetCursorPos32 (USER32.474)
1156 BOOL32 WINAPI
SetCursorPos32( INT32 x
, INT32 y
)
1158 TRACE(cursor
, "x=%d y=%d\n", x
, y
);
1159 TSXWarpPointer( display
, rootWindow
, rootWindow
, 0, 0, 0, 0, x
, y
);
1164 /***********************************************************************
1165 * ShowCursor16 (USER.71)
1167 INT16 WINAPI
ShowCursor16( BOOL16 bShow
)
1169 return ShowCursor32( bShow
);
1173 /***********************************************************************
1174 * ShowCursor32 (USER32.530)
1176 INT32 WINAPI
ShowCursor32( BOOL32 bShow
)
1178 TRACE(cursor
, "%d, count=%d\n",
1179 bShow
, CURSOR_ShowCount
);
1181 EnterCriticalSection( &X11DRV_CritSection
);
1184 if (++CURSOR_ShowCount
== 0) /* Show it */
1185 CALL_LARGE_STACK( CURSORICON_SetCursor
, hActiveCursor
);
1189 if (--CURSOR_ShowCount
== -1) /* Hide it */
1190 CALL_LARGE_STACK( CURSORICON_SetCursor
, 0 );
1192 LeaveCriticalSection( &X11DRV_CritSection
);
1193 return CURSOR_ShowCount
;
1197 /***********************************************************************
1198 * GetCursor16 (USER.247)
1200 HCURSOR16 WINAPI
GetCursor16(void)
1202 return hActiveCursor
;
1206 /***********************************************************************
1207 * GetCursor32 (USER32.227)
1209 HCURSOR32 WINAPI
GetCursor32(void)
1211 return hActiveCursor
;
1215 /***********************************************************************
1216 * ClipCursor16 (USER.16)
1218 BOOL16 WINAPI
ClipCursor16( const RECT16
*rect
)
1220 if (!rect
) SetRectEmpty32( &CURSOR_ClipRect
);
1221 else CONV_RECT16TO32( rect
, &CURSOR_ClipRect
);
1226 /***********************************************************************
1227 * ClipCursor32 (USER32.53)
1229 BOOL32 WINAPI
ClipCursor32( const RECT32
*rect
)
1231 if (!rect
) SetRectEmpty32( &CURSOR_ClipRect
);
1232 else CopyRect32( &CURSOR_ClipRect
, rect
);
1237 /***********************************************************************
1238 * GetCursorPos16 (USER.17)
1240 void WINAPI
GetCursorPos16( POINT16
*pt
)
1243 int rootX
, rootY
, childX
, childY
;
1244 unsigned int mousebut
;
1247 if (!TSXQueryPointer( display
, rootWindow
, &root
, &child
,
1248 &rootX
, &rootY
, &childX
, &childY
, &mousebut
))
1254 if (mousebut
& Button1Mask
)
1255 AsyncMouseButtonsStates
[0] = MouseButtonsStates
[0] = TRUE
;
1257 MouseButtonsStates
[0] = FALSE
;
1258 if (mousebut
& Button2Mask
)
1259 AsyncMouseButtonsStates
[1] = MouseButtonsStates
[1] = TRUE
;
1261 MouseButtonsStates
[1] = FALSE
;
1262 if (mousebut
& Button3Mask
)
1263 AsyncMouseButtonsStates
[2] = MouseButtonsStates
[2] = TRUE
;
1265 MouseButtonsStates
[2] = FALSE
;
1267 TRACE(cursor
, "ret=%d,%d\n", pt
->x
, pt
->y
);
1271 /***********************************************************************
1272 * GetCursorPos32 (USER32.229)
1274 void WINAPI
GetCursorPos32( POINT32
*pt
)
1277 GetCursorPos16( &pt16
);
1278 if (pt
) CONV_POINT16TO32( &pt16
, pt
);
1282 /***********************************************************************
1283 * GetClipCursor16 (USER.309)
1285 void WINAPI
GetClipCursor16( RECT16
*rect
)
1287 if (rect
) CONV_RECT32TO16( &CURSOR_ClipRect
, rect
);
1291 /***********************************************************************
1292 * GetClipCursor32 (USER32.221)
1294 void WINAPI
GetClipCursor32( RECT32
*rect
)
1296 if (rect
) CopyRect32( rect
, &CURSOR_ClipRect
);
1299 /**********************************************************************
1300 * LookupIconIdFromDirectoryEx16 (USER.364)
1302 * FIXME: exact parameter sizes
1304 INT16 WINAPI
LookupIconIdFromDirectoryEx16( LPBYTE xdir
, BOOL16 bIcon
,
1305 INT16 width
, INT16 height
, UINT16 cFlag
)
1307 CURSORICONDIR
*dir
= (CURSORICONDIR
*)xdir
;
1309 if( dir
&& !dir
->idReserved
&& (dir
->idType
& 3) )
1311 int colors
= (cFlag
== LR_MONOCHROME
) ? 2 : COLOR_GetSystemPaletteSize();
1314 ICONDIRENTRY
* entry
;
1315 entry
= CURSORICON_FindBestIcon( dir
, width
, height
, colors
);
1316 if( entry
) retVal
= entry
->wResId
;
1320 CURSORDIRENTRY
* entry
;
1321 entry
= CURSORICON_FindBestCursor( dir
, width
, height
);
1322 if( entry
) retVal
= entry
->wResId
;
1325 else WARN(cursor
, "invalid resource directory\n");
1329 /**********************************************************************
1330 * LookupIconIdFromDirectoryEx32 (USER32.380)
1332 INT32 WINAPI
LookupIconIdFromDirectoryEx32( LPBYTE dir
, BOOL32 bIcon
,
1333 INT32 width
, INT32 height
, UINT32 cFlag
)
1335 return LookupIconIdFromDirectoryEx16( dir
, bIcon
, width
, height
, cFlag
);
1338 /**********************************************************************
1339 * LookupIconIdFromDirectory (USER.???)
1341 INT16 WINAPI
LookupIconIdFromDirectory16( LPBYTE dir
, BOOL16 bIcon
)
1343 return LookupIconIdFromDirectoryEx16( dir
, bIcon
,
1344 bIcon
? SYSMETRICS_CXICON
: SYSMETRICS_CXCURSOR
,
1345 bIcon
? SYSMETRICS_CYICON
: SYSMETRICS_CYCURSOR
, bIcon
? 0 : LR_MONOCHROME
);
1348 /**********************************************************************
1349 * LookupIconIdFromDirectory (USER32.379)
1351 INT32 WINAPI
LookupIconIdFromDirectory32( LPBYTE dir
, BOOL32 bIcon
)
1353 return LookupIconIdFromDirectoryEx32( dir
, bIcon
,
1354 bIcon
? SYSMETRICS_CXICON
: SYSMETRICS_CXCURSOR
,
1355 bIcon
? SYSMETRICS_CYICON
: SYSMETRICS_CYCURSOR
, bIcon
? 0 : LR_MONOCHROME
);
1358 /**********************************************************************
1359 * GetIconID (USER.455)
1361 WORD WINAPI
GetIconID( HGLOBAL16 hResource
, DWORD resType
)
1363 LPBYTE lpDir
= (LPBYTE
)GlobalLock16(hResource
);
1365 TRACE(cursor
, "hRes=%04x, entries=%i\n",
1366 hResource
, lpDir
? ((CURSORICONDIR
*)lpDir
)->idCount
: 0);
1371 return (WORD
)LookupIconIdFromDirectoryEx16( lpDir
, FALSE
,
1372 SYSMETRICS_CXCURSOR
, SYSMETRICS_CYCURSOR
, LR_MONOCHROME
);
1374 return (WORD
)LookupIconIdFromDirectoryEx16( lpDir
, TRUE
,
1375 SYSMETRICS_CXICON
, SYSMETRICS_CYICON
, 0 );
1377 WARN(cursor
, "invalid res type %ld\n", resType
);
1382 /**********************************************************************
1383 * LoadCursorIconHandler (USER.336)
1385 * Supposed to load resources of Windows 2.x applications.
1387 HGLOBAL16 WINAPI
LoadCursorIconHandler( HGLOBAL16 hResource
, HMODULE16 hModule
, HRSRC16 hRsrc
)
1389 FIXME(cursor
,"(%04x,%04x,%04x): old 2.x resources are not supported!\n",
1390 hResource
, hModule
, hRsrc
);
1391 return (HGLOBAL16
)0;
1394 /**********************************************************************
1395 * LoadDIBIconHandler (USER.357)
1397 * RT_ICON resource loader, installed by USER_SignalProc when module
1400 HGLOBAL16 WINAPI
LoadDIBIconHandler( HGLOBAL16 hMemObj
, HMODULE16 hModule
, HRSRC16 hRsrc
)
1402 /* If hResource is zero we must allocate a new memory block, if it's
1403 * non-zero but GlobalLock() returns NULL then it was discarded and
1404 * we have to recommit some memory, otherwise we just need to check
1405 * the block size. See LoadProc() in 16-bit SDK for more.
1408 hMemObj
= USER_CallDefaultRsrcHandler( hMemObj
, hModule
, hRsrc
);
1411 LPBYTE bits
= (LPBYTE
)GlobalLock16( hMemObj
);
1412 hMemObj
= CURSORICON_CreateFromResource( hModule
, hMemObj
, bits
,
1413 SizeofResource16(hModule
, hRsrc
), TRUE
, 0x00030000,
1414 SYSMETRICS_CXICON
, SYSMETRICS_CYICON
, LR_DEFAULTCOLOR
);
1419 /**********************************************************************
1420 * LoadDIBCursorHandler (USER.356)
1422 * RT_CURSOR resource loader. Same as above.
1424 HGLOBAL16 WINAPI
LoadDIBCursorHandler( HGLOBAL16 hMemObj
, HMODULE16 hModule
, HRSRC16 hRsrc
)
1426 hMemObj
= USER_CallDefaultRsrcHandler( hMemObj
, hModule
, hRsrc
);
1429 LPBYTE bits
= (LPBYTE
)GlobalLock16( hMemObj
);
1430 hMemObj
= CURSORICON_CreateFromResource( hModule
, hMemObj
, bits
,
1431 SizeofResource16(hModule
, hRsrc
), FALSE
, 0x00030000,
1432 SYSMETRICS_CXCURSOR
, SYSMETRICS_CYCURSOR
, LR_MONOCHROME
);
1437 /**********************************************************************
1438 * LoadIconHandler (USER.456)
1440 HICON16 WINAPI
LoadIconHandler( HGLOBAL16 hResource
, BOOL16 bNew
)
1442 LPBYTE bits
= (LPBYTE
)LockResource16( hResource
);
1444 TRACE(cursor
,"hRes=%04x\n",hResource
);
1446 return CURSORICON_CreateFromResource( 0, 0, bits
, 0, TRUE
,
1447 bNew
? 0x00030000 : 0x00020000, 0, 0, LR_DEFAULTCOLOR
);
1450 /***********************************************************************
1451 * LoadCursorW (USER32.362)
1453 HCURSOR32 WINAPI
LoadCursor32W(HINSTANCE32 hInstance
, LPCWSTR name
)
1455 return CURSORICON_Load32( hInstance
, name
,
1456 SYSMETRICS_CXCURSOR
, SYSMETRICS_CYCURSOR
, 1, TRUE
);
1459 /***********************************************************************
1460 * LoadCursorA (USER32.359)
1462 HCURSOR32 WINAPI
LoadCursor32A(HINSTANCE32 hInstance
, LPCSTR name
)
1466 return LoadCursor32W(hInstance
,(LPCWSTR
)name
);
1469 LPWSTR uni
= HEAP_strdupAtoW( GetProcessHeap(), 0, name
);
1470 res
= LoadCursor32W(hInstance
, uni
);
1471 HeapFree( GetProcessHeap(), 0, uni
);
1475 /***********************************************************************
1476 * LoadCursorFromFile32W (USER32.361)
1478 HCURSOR32 WINAPI
LoadCursorFromFile32W (LPCWSTR name
)
1479 { FIXME(cursor
, ":stub LoadCursorFromFile32W\n");
1480 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1484 /***********************************************************************
1485 * LoadCursorFromFile32A (USER32.360)
1487 HCURSOR32 WINAPI
LoadCursorFromFile32A (LPCSTR name
)
1488 { FIXME(cursor
, ":stub LoadCursorFromFile32A %s\n", name
);
1489 SetLastError(ERROR_CALL_NOT_IMPLEMENTED
);
1494 /***********************************************************************
1495 * LoadIconW (USER32.364)
1497 HICON32 WINAPI
LoadIcon32W(HINSTANCE32 hInstance
, LPCWSTR name
)
1499 return CURSORICON_Load32( hInstance
, name
,
1500 SYSMETRICS_CXICON
, SYSMETRICS_CYICON
,
1501 MIN( 16, COLOR_GetSystemPaletteSize() ), FALSE
);
1504 /***********************************************************************
1505 * LoadIconA (USER32.363)
1507 HICON32 WINAPI
LoadIcon32A(HINSTANCE32 hInstance
, LPCSTR name
)
1512 return LoadIcon32W(hInstance
, (LPCWSTR
)name
);
1515 LPWSTR uni
= HEAP_strdupAtoW( GetProcessHeap(), 0, name
);
1516 res
= LoadIcon32W( hInstance
, uni
);
1517 HeapFree( GetProcessHeap(), 0, uni
);
1522 /**********************************************************************
1523 * GetIconInfo (USER32.242)
1525 BOOL32 WINAPI
GetIconInfo(HICON32 hIcon
,LPICONINFO iconinfo
) {
1526 CURSORICONINFO
*ciconinfo
;
1528 ciconinfo
= GlobalLock16(hIcon
);
1531 iconinfo
->xHotspot
= ciconinfo
->ptHotSpot
.x
;
1532 iconinfo
->yHotspot
= ciconinfo
->ptHotSpot
.y
;
1533 iconinfo
->fIcon
= TRUE
; /* hmm */
1534 /* FIXME ... add both bitmaps */
1538 /**********************************************************************
1539 * CreateIconIndirect (USER32.78)
1541 HICON32 WINAPI
CreateIconIndirect(LPICONINFO iconinfo
) {
1542 BITMAPOBJ
*bmpXor
,*bmpAnd
;
1544 int sizeXor
,sizeAnd
;
1546 bmpXor
= (BITMAPOBJ
*) GDI_GetObjPtr( iconinfo
->hbmColor
, BITMAP_MAGIC
);
1547 bmpAnd
= (BITMAPOBJ
*) GDI_GetObjPtr( iconinfo
->hbmMask
, BITMAP_MAGIC
);
1549 sizeXor
= bmpXor
->bitmap
.bmHeight
* bmpXor
->bitmap
.bmWidthBytes
;
1550 sizeAnd
= bmpAnd
->bitmap
.bmHeight
* bmpAnd
->bitmap
.bmWidthBytes
;
1552 hObj
= GlobalAlloc16( GMEM_MOVEABLE
,
1553 sizeof(CURSORICONINFO
) + sizeXor
+ sizeAnd
);
1556 CURSORICONINFO
*info
;
1558 info
= (CURSORICONINFO
*)GlobalLock16( hObj
);
1559 info
->ptHotSpot
.x
= iconinfo
->xHotspot
;
1560 info
->ptHotSpot
.y
= iconinfo
->yHotspot
;
1561 info
->nWidth
= bmpXor
->bitmap
.bmWidth
;
1562 info
->nHeight
= bmpXor
->bitmap
.bmHeight
;
1563 info
->nWidthBytes
= bmpXor
->bitmap
.bmWidthBytes
;
1564 info
->bPlanes
= bmpXor
->bitmap
.bmPlanes
;
1565 info
->bBitsPerPixel
= bmpXor
->bitmap
.bmBitsPixel
;
1567 /* Transfer the bitmap bits to the CURSORICONINFO structure */
1569 GetBitmapBits32( iconinfo
->hbmMask
,sizeAnd
,(char*)(info
+ 1) );
1570 GetBitmapBits32( iconinfo
->hbmColor
,sizeXor
,(char*)(info
+ 1) +sizeAnd
);
1571 GlobalUnlock16( hObj
);
1577 /**********************************************************************
1578 * DrawIconEx16 (USER.394)
1580 BOOL16 WINAPI
DrawIconEx16 (HDC16 hdc
, INT16 xLeft
, INT16 yTop
, HICON16 hIcon
,
1581 INT16 cxWidth
, INT16 cyWidth
, UINT16 istep
,
1582 HBRUSH16 hbr
, UINT16 flags
)
1584 return DrawIconEx32(hdc
, xLeft
, yTop
, hIcon
, cxWidth
, cyWidth
,
1589 /******************************************************************************
1590 * DrawIconEx32 [USER32.160] Draws an icon or cursor on device context
1593 * Why is this using SM_CXICON instead of SM_CXCURSOR?
1596 * hdc [I] Handle to device context
1597 * x0 [I] X coordinate of upper left corner
1598 * y0 [I] Y coordinate of upper left corner
1599 * hIcon [I] Handle to icon to draw
1600 * cxWidth [I] Width of icon
1601 * cyWidth [I] Height of icon
1602 * istep [I] Index of frame in animated cursor
1603 * hbr [I] Handle to background brush
1604 * flags [I] Icon-drawing flags
1610 BOOL32 WINAPI
DrawIconEx32( HDC32 hdc
, INT32 x0
, INT32 y0
, HICON32 hIcon
,
1611 INT32 cxWidth
, INT32 cyWidth
, UINT32 istep
,
1612 HBRUSH32 hbr
, UINT32 flags
)
1614 CURSORICONINFO
*ptr
= (CURSORICONINFO
*)GlobalLock16 (hIcon
);
1615 HDC32 hMemDC
= CreateCompatibleDC32 (hdc
);
1616 BOOL32 result
= FALSE
;
1619 FIXME(icon
, "Ignoring istep=%d\n", istep
);
1621 FIXME(icon
, "Ignoring hbr=%x\n", hbr
);
1622 if (flags
& DI_COMPAT
)
1623 FIXME(icon
, "Ignoring flag DI_COMPAT\n");
1627 HBITMAP32 hXorBits
, hAndBits
;
1628 COLORREF oldFg
, oldBg
;
1631 /* Calculate the size of the destination image. */
1633 if (flags
& DI_DEFAULTSIZE
)
1634 cxWidth
= GetSystemMetrics32 (SM_CXICON
);
1636 cxWidth
= ptr
->nWidth
;
1638 if (flags
& DI_DEFAULTSIZE
)
1639 cyWidth
= GetSystemMetrics32 (SM_CYICON
);
1641 cyWidth
= ptr
->nHeight
;
1643 nStretchMode
= SetStretchBltMode32 (hdc
, STRETCH_DELETESCANS
);
1645 hXorBits
= CreateBitmap32 ( ptr
->nWidth
, ptr
->nHeight
,
1646 ptr
->bPlanes
, ptr
->bBitsPerPixel
,
1649 BITMAP_WIDTH_BYTES(ptr
->nWidth
,1) );
1650 hAndBits
= CreateBitmap32 ( cxWidth
, cyWidth
,
1651 1, 1, (char *)(ptr
+1) );
1652 oldFg
= SetTextColor32( hdc
, RGB(0,0,0) );
1653 oldBg
= SetBkColor32( hdc
, RGB(255,255,255) );
1655 if (hXorBits
&& hAndBits
)
1657 HBITMAP32 hBitTemp
= SelectObject32( hMemDC
, hAndBits
);
1658 if (flags
& DI_MASK
)
1659 StretchBlt32 (hdc
, x0
, y0
, cxWidth
, cyWidth
,
1660 hMemDC
, 0, 0, ptr
->nWidth
, ptr
->nHeight
, SRCAND
);
1661 SelectObject32( hMemDC
, hXorBits
);
1662 if (flags
& DI_IMAGE
)
1663 StretchBlt32 (hdc
, x0
, y0
, cxWidth
, cyWidth
,
1664 hMemDC
, 0, 0, ptr
->nWidth
, ptr
->nHeight
, SRCPAINT
);
1665 SelectObject32( hMemDC
, hBitTemp
);
1669 SetTextColor32( hdc
, oldFg
);
1670 SetBkColor32( hdc
, oldBg
);
1671 if (hXorBits
) DeleteObject32( hXorBits
);
1672 if (hAndBits
) DeleteObject32( hAndBits
);
1673 SetStretchBltMode32 (hdc
, nStretchMode
);
1675 if (hMemDC
) DeleteDC32( hMemDC
);
1676 GlobalUnlock16( hIcon
);