Alexandre Julliard : user32: Add a helper to retrieve the dimensions of an icon.
Alexandre Julliard
julliard at winehq.org
Fri Oct 16 11:26:08 CDT 2009
Module: wine
Branch: master
Commit: 62ac036bc6148dffc53543a0184f6248bfbcc390
URL: http://source.winehq.org/git/wine.git/?a=commit;h=62ac036bc6148dffc53543a0184f6248bfbcc390
Author: Alexandre Julliard <julliard at winehq.org>
Date: Thu Oct 15 19:44:45 2009 +0200
user32: Add a helper to retrieve the dimensions of an icon.
---
dlls/user32/cursoricon.c | 14 ++++++++++++++
dlls/user32/static.c | 32 ++++++++++++++++----------------
dlls/user32/uitools.c | 9 ++-------
dlls/user32/user_private.h | 1 +
4 files changed, 33 insertions(+), 23 deletions(-)
diff --git a/dlls/user32/cursoricon.c b/dlls/user32/cursoricon.c
index 1ae33aa..3872c8a 100644
--- a/dlls/user32/cursoricon.c
+++ b/dlls/user32/cursoricon.c
@@ -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.
diff --git a/dlls/user32/static.c b/dlls/user32/static.c
index 69acbc5..6c61db2 100644
--- a/dlls/user32/static.c
+++ b/dlls/user32/static.c
@@ -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 )
diff --git a/dlls/user32/uitools.c b/dlls/user32/uitools.c
index a401fc3..c8e9580 100644
--- a/dlls/user32/uitools.c
+++ b/dlls/user32/uitools.c
@@ -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:
diff --git a/dlls/user32/user_private.h b/dlls/user32/user_private.h
index 8c49ad3..67fdbb6 100644
--- a/dlls/user32/user_private.h
+++ b/dlls/user32/user_private.h
@@ -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__
More information about the wine-cvs
mailing list