]> git.saurik.com Git - wxWidgets.git/commitdiff
Remove asserts in wxMSW::wxTLW::SetIcons() and always set some icon.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 24 Jul 2010 17:43:47 +0000 (17:43 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 24 Jul 2010 17:43:47 +0000 (17:43 +0000)
In practice having the icons of the exact size for all versions of Windows is
not always possible, there are just too many of them. So set the icon of the
most suitable size if no exact match is found instead of asserting in this
case.

See #11146.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@65084 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/toplevel.cpp

index dfb7b19ef462f9a12f1edc97b516c295cf9c100c..ba45599a81a7112459d0add9482e1c97415c5055 100644 (file)
@@ -1051,14 +1051,24 @@ bool wxTopLevelWindowMSW::DoSelectAndSetIcon(const wxIconBundle& icons,
 {
     const wxSize size(::GetSystemMetrics(smX), ::GetSystemMetrics(smY));
 
-    const wxIcon icon = icons.GetIconOfExactSize(size);
-    if ( icon.Ok() )
+    // Try the exact size first.
+    wxIcon icon = icons.GetIconOfExactSize(size);
+
+    if ( !icon.IsOk() )
     {
-        ::SendMessage(GetHwnd(), WM_SETICON, i, (LPARAM)GetHiconOf(icon));
-        return true;
+        // If we didn't find any, set at least some icon: it will look scaled
+        // and ugly but in practice it's impossible to prevent this because not
+        // everyone can provide the icons in all sizes used by all versions of
+        // Windows in all DPIs (this would include creating them in at least
+        // 14, 16, 22, 32, 48, 64 and 128 pixel sizes).
+        icon = icons.GetIcon(size);
     }
 
-    return false;
+    if ( !icon.IsOk() )
+        return false;
+
+    ::SendMessage(GetHwnd(), WM_SETICON, i, (LPARAM)GetHiconOf(icon));
+    return true;
 }
 
 void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons)
@@ -1073,15 +1083,8 @@ void wxTopLevelWindowMSW::SetIcons(const wxIconBundle& icons)
         return;
     }
 
-    bool anySet =
-        DoSelectAndSetIcon(icons, SM_CXSMICON, SM_CYSMICON, ICON_SMALL);
-    if ( DoSelectAndSetIcon(icons, SM_CXICON, SM_CYICON, ICON_BIG) )
-        anySet = true;
-
-    if ( !anySet )
-    {
-        wxFAIL_MSG( "icon bundle doesn't contain any suitable icon" );
-    }
+    DoSelectAndSetIcon(icons, SM_CXSMICON, SM_CYSMICON, ICON_SMALL);
+    DoSelectAndSetIcon(icons, SM_CXICON, SM_CYICON, ICON_BIG);
 }
 
 bool wxTopLevelWindowMSW::EnableCloseButton(bool enable)