[6/10] user: Split the loading of the hotspot and the loading of
the actual cursor / icon data out of CreateIconFromResourceEx
H. Verbeet
hverbeet at gmail.com
Sat Aug 5 16:39:57 CDT 2006
The format of the cursor / icon data is the same for .ico, .cur, .ani
and cursors / icons from a resource, but the location of the hotspot
isn't. This splits the loadig of the data out into its own function,
so it can be reused in the next few of patches.
-------------- next part --------------
diff --git a/dlls/user/cursoricon.c b/dlls/user/cursoricon.c
index edb74cc..5bfbc80 100644
--- a/dlls/user/cursoricon.c
+++ b/dlls/user/cursoricon.c
@@ -1011,48 +1011,28 @@ static CURSORICONFILEDIRENTRY *CURSORICO
return &dir->idEntries[n];
}
-/**********************************************************************
- * CreateIconFromResourceEx (USER32.@)
- *
- * FIXME: Convert to mono when cFlag is LR_MONOCHROME. Do something
- * with cbSize parameter as well.
- */
-HICON WINAPI CreateIconFromResourceEx( LPBYTE bits, UINT cbSize,
- BOOL bIcon, DWORD dwVersion,
- INT width, INT height,
- UINT cFlag )
+static BOOL load_cursor_frame( LPBYTE bits, UINT cbSize, POINT16 hotspot, DWORD dwVersion,
+ INT width, INT height, UINT cFlag, cursor_frame_t *frame )
{
- HCURSOR cursor;
- cursor_frame_t frame = {0};
static HDC hdcMem;
int sizeAnd, sizeXor;
HBITMAP hAndBits = 0, hXorBits = 0; /* error condition for later */
BITMAP bmpXor, bmpAnd;
- POINT16 hotspot;
BITMAPINFO *bmi;
BOOL DoStretch;
INT size;
- hotspot.x = ICON_HOTSPOT;
- hotspot.y = ICON_HOTSPOT;
-
- TRACE_(cursor)("%p (%u bytes), ver %08x, %ix%i %s %s\n",
- bits, cbSize, (unsigned)dwVersion, width, height,
- bIcon ? "icon" : "cursor", (cFlag & LR_MONOCHROME) ? "mono" : "" );
+ TRACE_(cursor)("%p (%u bytes), ver %08x, %ix%i %s\n",
+ bits, cbSize, (unsigned)dwVersion, width, height,
+ (cFlag & LR_MONOCHROME) ? "mono" : "" );
if (dwVersion == 0x00020000)
{
FIXME_(cursor)("\t2.xx resources are not supported\n");
- return 0;
+ return FALSE;
}
- if (bIcon)
- bmi = (BITMAPINFO *)bits;
- else /* get the hotspot */
- {
- POINT16 *pt = (POINT16 *)bits;
- hotspot = *pt;
- bmi = (BITMAPINFO *)(pt + 1);
- }
+ bmi = (BITMAPINFO *)bits;
+
size = bitmap_info_size( bmi, DIB_RGB_COLORS );
if (!width) width = bmi->bmiHeader.biWidth;
@@ -1067,7 +1047,7 @@ HICON WINAPI CreateIconFromResourceEx( L
bmi->bmiHeader.biCompression != BI_RGB) )
{
WARN_(cursor)("\tinvalid resource bitmap header.\n");
- return 0;
+ return FALSE;
}
if (!screen_dc) screen_dc = CreateDCW( DISPLAYW, NULL, NULL, NULL );
@@ -1186,7 +1166,7 @@ HICON WINAPI CreateIconFromResourceEx( L
if( !hXorBits || !hAndBits )
{
WARN_(cursor)("\tunable to create an icon bitmap.\n");
- return 0;
+ return FALSE;
}
/* Setup a cursor frame, send it to the server */
@@ -1195,24 +1175,62 @@ HICON WINAPI CreateIconFromResourceEx( L
sizeXor = bmpXor.bmHeight * bmpXor.bmWidthBytes;
sizeAnd = bmpAnd.bmHeight * bmpAnd.bmWidthBytes;
- cursor = create_cursor( 1, 0 );
- frame.xhot = hotspot.x;
- frame.yhot = hotspot.y;
- frame.width = bmpXor.bmWidth;
- frame.height = bmpXor.bmHeight;
- frame.and_width_bytes = bmpAnd.bmWidthBytes;
- frame.xor_width_bytes = bmpXor.bmWidthBytes;
- frame.planes = bmpXor.bmPlanes;
- frame.bpp = bmpXor.bmBitsPixel;
- frame.bits = HeapAlloc( GetProcessHeap(), 0, sizeAnd + sizeXor );
- GetBitmapBits( hAndBits, sizeAnd, frame.bits );
- GetBitmapBits( hXorBits, sizeXor, frame.bits + sizeAnd );
- set_cursor_frame( cursor, 0, &frame );
- HeapFree( GetProcessHeap(), 0, frame.bits );
+ frame->xhot = hotspot.x;
+ frame->yhot = hotspot.y;
+ frame->width = bmpXor.bmWidth;
+ frame->height = bmpXor.bmHeight;
+ frame->and_width_bytes = bmpAnd.bmWidthBytes;
+ frame->xor_width_bytes = bmpXor.bmWidthBytes;
+ frame->planes = bmpXor.bmPlanes;
+ frame->bpp = bmpXor.bmBitsPixel;
+ frame->bits = HeapAlloc( GetProcessHeap(), 0, sizeAnd + sizeXor );
+ GetBitmapBits( hAndBits, sizeAnd, frame->bits );
+ GetBitmapBits( hXorBits, sizeXor, frame->bits + sizeAnd );
DeleteObject( hAndBits );
DeleteObject( hXorBits );
+ return TRUE;
+}
+
+/**********************************************************************
+ * CreateIconFromResourceEx (USER32.@)
+ *
+ * FIXME: Convert to mono when cFlag is LR_MONOCHROME. Do something
+ * with cbSize parameter as well.
+ */
+HICON WINAPI CreateIconFromResourceEx( LPBYTE bits, UINT cbSize,
+ BOOL bIcon, DWORD dwVersion,
+ INT width, INT height,
+ UINT cFlag )
+{
+ POINT16 hotspot;
+ HCURSOR cursor = create_cursor( 1, 0 );
+ cursor_frame_t frame = {0};
+
+ if (bIcon)
+ {
+ hotspot.x = ICON_HOTSPOT;
+ hotspot.y = ICON_HOTSPOT;
+ }
+ else
+ {
+ hotspot = *(POINT16 *)bits;
+ bits = (LPBYTE)(((POINT16 *)bits) + 1);
+ }
+
+ if (load_cursor_frame( bits, cbSize, hotspot, dwVersion, width, height, cFlag, &frame ))
+ {
+ set_cursor_frame( cursor, 0, &frame );
+ }
+ else
+ {
+ destroy_cursor( cursor );
+ cursor = 0;
+ }
+
+ HeapFree( GetProcessHeap(), 0, frame.bits );
+
return cursor;
}
More information about the wine-patches
mailing list