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 )
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
* accessing cursor and icon resources in files and resource entries.
......
......@@ -148,12 +148,12 @@ static void restore_clipping(HDC hdc, HRGN hrgn)
static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
{
HICON prevIcon;
CURSORICONINFO * info;
SIZE size;
if ((style & SS_TYPEMASK) != SS_ICON) return 0;
info = hicon ? GlobalLock16(HICON_16(hicon)) : NULL;
if (hicon && !info) {
WARN("hicon != 0, but info == 0\n");
if (hicon && !get_icon_size( hicon, &size ))
{
WARN("hicon != 0, but invalid\n");
return 0;
}
prevIcon = (HICON)SetWindowLongPtrW( hwnd, HICON_GWL_OFFSET, (LONG_PTR)hicon );
......@@ -170,11 +170,9 @@ static HICON STATIC_SetIcon( HWND hwnd, HICON hicon, DWORD style )
}
else */
{
SetWindowPos( hwnd, 0, 0, 0, info->nWidth, info->nHeight,
SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
SetWindowPos( hwnd, 0, 0, 0, size.cx, size.cy, SWP_NOACTIVATE | SWP_NOMOVE | SWP_NOZORDER );
}
}
if (info) GlobalUnlock16(HICON_16(hicon));
return prevIcon;
}
......@@ -573,8 +571,10 @@ static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
case STM_GETIMAGE:
return (LRESULT)STATIC_GetImage( hwnd, wParam, full_style );
case STM_GETICON16:
return HICON_16(STATIC_GetImage( hwnd, IMAGE_ICON, full_style ));
case STM_GETICON:
return (LRESULT)STATIC_GetImage( hwnd, IMAGE_ICON, full_style );
......@@ -598,6 +598,8 @@ static LRESULT StaticWndProc_common( HWND hwnd, UINT uMsg, WPARAM wParam,
break;
case STM_SETICON16:
wParam = (WPARAM)HICON_32( (HICON16)wParam );
/* fall through */
case STM_SETICON:
lResult = (LRESULT)STATIC_SetIcon( hwnd, (HICON)wParam, full_style );
STATIC_TryPaintFcn( hwnd, full_style );
......@@ -800,13 +802,12 @@ static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
RECT rc, iconRect;
HBRUSH hbrush;
HICON hIcon;
CURSORICONINFO * info;
SIZE size;
GetClientRect( hwnd, &rc );
hbrush = STATIC_SendWmCtlColorStatic(hwnd, hdc);
hIcon = (HICON)GetWindowLongPtrW( hwnd, HICON_GWL_OFFSET );
info = hIcon ? GlobalLock16(HICON_16(hIcon)) : NULL;
if (!hIcon || !info)
if (!hIcon || !get_icon_size( hIcon, &size ))
{
FillRect(hdc, &rc, hbrush);
}
......@@ -814,10 +815,10 @@ static void STATIC_PaintIconfn( HWND hwnd, HDC hdc, DWORD style )
{
if (style & SS_CENTERIMAGE)
{
iconRect.left = (rc.right - rc.left) / 2 - info->nWidth / 2;
iconRect.top = (rc.bottom - rc.top) / 2 - info->nHeight / 2;
iconRect.right = iconRect.left + info->nWidth;
iconRect.bottom = iconRect.top + info->nHeight;
iconRect.left = (rc.right - rc.left) / 2 - size.cx / 2;
iconRect.top = (rc.bottom - rc.top) / 2 - size.cy / 2;
iconRect.right = iconRect.left + size.cx;
iconRect.bottom = iconRect.top + size.cy;
}
else
iconRect = rc;
......@@ -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,
iconRect.bottom - iconRect.top, 0, NULL, DI_NORMAL );
}
if (info) GlobalUnlock16(HICON_16(hIcon));
}
static void STATIC_PaintBitmapfn(HWND hwnd, HDC hdc, DWORD style )
......
......@@ -22,8 +22,8 @@
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wingdi.h"
#include "wine/winuser16.h"
#include "winuser.h"
#include "user_private.h"
#include "wine/unicode.h"
......@@ -1597,7 +1597,6 @@ static BOOL UITOOLS_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp
if(!cx || !cy)
{
SIZE s;
CURSORICONINFO *ici;
BITMAP bm;
switch(opcode)
......@@ -1612,11 +1611,7 @@ static BOOL UITOOLS_DrawState(HDC hdc, HBRUSH hbr, DRAWSTATEPROC func, LPARAM lp
break;
case DST_ICON:
ici = GlobalLock16((HGLOBAL16)lp);
if(!ici) return FALSE;
s.cx = ici->nWidth;
s.cy = ici->nHeight;
GlobalUnlock16((HGLOBAL16)lp);
if (!get_icon_size( (HICON)lp, &s )) return FALSE;
break;
case DST_BITMAP:
......
......@@ -328,6 +328,7 @@ typedef struct
#include "poppack.h"
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 */
#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