Commit 62ac036b authored by Alexandre Julliard's avatar Alexandre Julliard

user32: Add a helper to retrieve the dimensions of an icon.

parent 538b2474
...@@ -473,6 +473,20 @@ void CURSORICON_FreeModuleIcons( HMODULE16 hMod16 ) ...@@ -473,6 +473,20 @@ void CURSORICON_FreeModuleIcons( HMODULE16 hMod16 )
LeaveCriticalSection( &IconCrst ); LeaveCriticalSection( &IconCrst );
} }
/**********************************************************************
* get_icon_size
*/
BOOL get_icon_size( HICON handle, SIZE *size )
{
CURSORICONINFO *info;
if (!(info = GlobalLock16( HICON_16(handle) ))) return FALSE;
size->cx = info->nWidth;
size->cy = info->nHeight;
GlobalUnlock16( HICON_16(handle) );
return TRUE;
}
/* /*
* The following macro functions account for the irregularities of * The following macro functions account for the irregularities of
* accessing cursor and icon resources in files and resource entries. * accessing cursor and icon resources in files and resource entries.
......
...@@ -148,12 +148,12 @@ static void restore_clipping(HDC hdc, HRGN hrgn) ...@@ -148,12 +148,12 @@ static void restore_clipping(HDC hdc, HRGN hrgn)
static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style ) static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
{ {
HICON prevIcon; HICON prevIcon;
CURSORICONINFO * info; SIZE size;
if ((style & SS_TYPEMASK) != SS_ICON) return 0; if ((style & SS_TYPEMASK) != SS_ICON) return 0;
info = hicon ? GlobalLock16(HICON_16(hicon)) : NULL; if (hicon && !get_icon_size( hicon, &size ))
if (hicon && !info) { {
WARN("hicon != 0, but info == 0\n"); WARN("hicon != 0, but invalid\n");
return 0; return 0;
} }
prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon ); prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
...@@ -170,11 +170,9 @@ static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style ) ...@@ -170,11 +170,9 @@ static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
} }
else */ else */
{ {
SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight, SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
} }
} }
if (info) GlobalUnlock16(HICON_16(hicon));
return prevIcon; return prevIcon;
} }
...@@ -573,8 +571,10 @@ static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, ...@@ -573,8 +571,10 @@ static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
case STM_GETIMAGE: case STM_GETIMAGE:
return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style ); return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
case STM_GETICON16: case STM_GETICON16:
return HICON_16(STATIC_GetImage( hwnd, IMAGE_ICON, full_style ));
case STM_GETICON: case STM_GETICON:
return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style ); return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
...@@ -598,6 +598,8 @@ static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam, ...@@ -598,6 +598,8 @@ static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
break; break;
case STM_SETICON16: case STM_SETICON16:
wParam = (WPARAM)HICON_32( (HICON16)wParam );
/* fall through */
case STM_SETICON: case STM_SETICON:
lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style ); lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
STATIC_TryPaintFcn( hwnd, full_style ); STATIC_TryPaintFcn( hwnd, full_style );
...@@ -800,13 +802,12 @@ static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style ) ...@@ -800,13 +802,12 @@ static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
RECT rc, iconRect; RECT rc, iconRect;
HBRUSH hbrush; HBRUSH hbrush;
HICON hIcon; HICON hIcon;
CURSORICONINFO * info; SIZE size;
GetClientRect( hwnd, &rc ); GetClientRect( hwnd, &rc );
hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc); hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET ); hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
info = hIcon ? GlobalLock16(HICON_16(hIcon)) : NULL; if (!hIcon || !get_icon_size( hIcon, &size ))
if (!hIcon || !info)
{ {
FillRect(hdc, &rc, hbrush); FillRect(hdc, &rc, hbrush);
} }
...@@ -814,10 +815,10 @@ static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style ) ...@@ -814,10 +815,10 @@ static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
{ {
if (style & SS_CENTERIMAGE) if (style & SS_CENTERIMAGE)
{ {
iconRect.left = (rc.right - rc.left) / 2 - info->nWidth / 2; iconRect.left = (rc.right - rc.left) / 2 - size.cx / 2;
iconRect.top = (rc.bottom - rc.top) / 2 - info->nHeight / 2; iconRect.top = (rc.bottom - rc.top) / 2 - size.cy / 2;
iconRect.right = iconRect.left + info->nWidth; iconRect.right = iconRect.left + size.cx;
iconRect.bottom = iconRect.top + info->nHeight; iconRect.bottom = iconRect.top + size.cy;
} }
else else
iconRect = rc; iconRect = rc;
...@@ -825,7 +826,6 @@ static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style ) ...@@ -825,7 +826,6 @@ static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
DrawIconEx( hdc, iconRect.left, iconRect.top, hIcon, iconRect.right - iconRect.left, DrawIconEx( hdc, iconRect.left, iconRect.top, hIcon, iconRect.right - iconRect.left,
iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL ); iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL );
} }
if (info) GlobalUnlock16(HICON_16(hIcon));
} }
static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style ) static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
......
...@@ -22,8 +22,8 @@ ...@@ -22,8 +22,8 @@
#include <stdarg.h> #include <stdarg.h>
#include "windef.h" #include "windef.h"
#include "winbase.h"
#include "wingdi.h" #include "wingdi.h"
#include "wine/winuser16.h"
#include "winuser.h" #include "winuser.h"
#include "user_private.h" #include "user_private.h"
#include "wine/unicode.h" #include "wine/unicode.h"
...@@ -1597,7 +1597,6 @@ static BOOL UITOOLS_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp ...@@ -1597,7 +1597,6 @@ static BOOL UITOOLS_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp
if(!cx || !cy) if(!cx || !cy)
{ {
SIZE s; SIZE s;
CURSORICONINFO *ici;
BITMAP bm; BITMAP bm;
switch(opcode) switch(opcode)
...@@ -1612,11 +1611,7 @@ static BOOL UITOOLS_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp ...@@ -1612,11 +1611,7 @@ static BOOL UITOOLS_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp
break; break;
case DST_ICON: case DST_ICON:
ici = GlobalLock16((HGLOBAL16)lp); if (!get_icon_size( (HICON)lp, &s )) return FALSE;
if(!ici) return FALSE;
s.cx = ici->nWidth;
s.cy = ici->nHeight;
GlobalUnlock16((HGLOBAL16)lp);
break; break;
case DST_BITMAP: case DST_BITMAP:
......
...@@ -328,6 +328,7 @@ typedef struct ...@@ -328,6 +328,7 @@ typedef struct
#include "poppack.h" #include "poppack.h"
extern void CURSORICON_FreeModuleIcons( HMODULE16 hModule ) DECLSPEC_HIDDEN; extern void CURSORICON_FreeModuleIcons( HMODULE16 hModule ) DECLSPEC_HIDDEN;
extern BOOL get_icon_size( HICON handle, SIZE *size ) DECLSPEC_HIDDEN;
/* Mingw's assert() imports MessageBoxA and gets confused by user32 exporting it */ /* Mingw's assert() imports MessageBoxA and gets confused by user32 exporting it */
#ifdef __MINGW32__ #ifdef __MINGW32__
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment