From 074ca2937d4c5df7acde4e7263f877c3bcee12dc Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 3 Jan 2008 01:13:44 +0000 Subject: [PATCH] don't hardcode 16/32 as sizes for small/normal icons (fixes bug 1862812) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@50999 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- docs/changes.txt | 3 +-- include/wx/msw/toplevel.h | 5 +++++ src/msw/toplevel.cpp | 31 ++++++++++++++++--------------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/docs/changes.txt b/docs/changes.txt index ed565aed01..8d17863fd2 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -118,8 +118,7 @@ All (Unix): wxMSW: - Fix rare bug with messages delivered to wrong wxSocket (Tim Kosse) - -wxGTK: +- Fix setting icons when they have non-default (16*16 and 32*32) sizes diff --git a/include/wx/msw/toplevel.h b/include/wx/msw/toplevel.h index 44c5141a12..43fcbb5863 100644 --- a/include/wx/msw/toplevel.h +++ b/include/wx/msw/toplevel.h @@ -180,6 +180,11 @@ protected: #endif // __SMARTPHONE__ && __WXWINCE__ private: + // helper of SetIcons(): calls gets the icon with the size specified by the + // given system metrics (SM_C{X|Y}[SM]ICON) from the bundle and sets it + // using WM_SETICON with the specified wParam (ICOM_SMALL or ICON_BIG) + void DoSelectAndSetIcon(const wxIconBundle& icons, int smX, int smY, int i); + #if defined(__SMARTPHONE__) || defined(__POCKETPC__) void* m_activateInfo; diff --git a/src/msw/toplevel.cpp b/src/msw/toplevel.cpp index 3c7bfe03c1..2070db8f3a 100644 --- a/src/msw/toplevel.cpp +++ b/src/msw/toplevel.cpp @@ -910,25 +910,26 @@ void wxTopLevelWindowMSW::SetIcon(const wxIcon& icon) SetIcons( wxIconBundle( icon ) ); } +void wxTopLevelWindowMSW::DoSelectAndSetIcon(const wxIconBundle& icons, + int smX, + int smY, + int i) +{ + const wxSize size(::GetSystemMetrics(smX), ::GetSystemMetrics(smY)); + + const wxIcon icon = icons.GetIcon(size); + if ( icon.Ok() && icon.GetWidth() == size.x && icon.GetHeight() == size.y ) + { + ::SendMessage(GetHwnd(), WM_SETICON, i, (LPARAM)GetHiconOf(icon)); + } +} + void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons) { wxTopLevelWindowBase::SetIcons(icons); -#if !defined(__WXMICROWIN__) - const wxIcon& sml = icons.GetIcon( wxSize( 16, 16 ) ); - if( sml.Ok() && sml.GetWidth() == 16 && sml.GetHeight() == 16 ) - { - ::SendMessage( GetHwndOf( this ), WM_SETICON, ICON_SMALL, - (LPARAM)GetHiconOf(sml) ); - } - - const wxIcon& big = icons.GetIcon( wxSize( 32, 32 ) ); - if( big.Ok() && big.GetWidth() == 32 && big.GetHeight() == 32 ) - { - ::SendMessage( GetHwndOf( this ), WM_SETICON, ICON_BIG, - (LPARAM)GetHiconOf(big) ); - } -#endif // !__WXMICROWIN__ + DoSelectAndSetIcon(icons, SM_CXSMICON, SM_CYSMICON, ICON_SMALL); + DoSelectAndSetIcon(icons, SM_CXICON, SM_CYICON, ICON_BIG); } bool wxTopLevelWindowMSW::EnableCloseButton(bool enable)