From: Vadim Zeitlin Date: Mon, 5 Oct 2009 22:57:24 +0000 (+0000) Subject: Return smaller images for wxART_MENU/BUTTON under OS X. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/1d3dfc57e77c64a4691fae47b566bcfb99eceb48?ds=inline Return smaller images for wxART_MENU/BUTTON under OS X. Requesting images with client id of wxART_MENU/BUTTON used to return the large 32*32 icons because GetNativeSizeHint() wasn't implemented for these client ids. Moreover, under Mac some icons (notably message box ones) are created from the corresponding icon bundle and the code in wxArtProvider::GetBitmap() didn't resize them correctly in this case, fix this. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@62299 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/common/artprov.cpp b/src/common/artprov.cpp index 79c9470e01..3a4f56b04c 100644 --- a/src/common/artprov.cpp +++ b/src/common/artprov.cpp @@ -238,6 +238,7 @@ wxArtProvider::~wxArtProvider() break; } + wxSize sizeNeeded = size; if ( !bmp.Ok() ) { // no bitmap created -- as a fallback, try if we can find desired @@ -245,28 +246,31 @@ wxArtProvider::~wxArtProvider() wxIconBundle iconBundle = DoGetIconBundle(id, client); if ( iconBundle.IsOk() ) { - wxSize sz(size != wxDefaultSize - ? size - : GetNativeSizeHint(client)); - wxIcon icon(iconBundle.GetIcon(sz)); + if ( sizeNeeded == wxDefaultSize ) + sizeNeeded = GetNativeSizeHint(client); + + wxIcon icon(iconBundle.GetIcon(sizeNeeded)); if ( icon.IsOk() ) + { + // this icon may be not of the correct size, it will be + // rescaled below in such case bmp.CopyFromIcon(icon); + } } } - if ( bmp.IsOk() ) - { - // if we didn't get the correct size, resize the bitmap + // if we didn't get the correct size, resize the bitmap #if wxUSE_IMAGE && (!defined(__WXMSW__) || wxUSE_WXDIB) - if ( size != wxDefaultSize && - (bmp.GetWidth() != size.x || bmp.GetHeight() != size.y) ) + if ( bmp.IsOk() && sizeNeeded != wxDefaultSize ) + { + if ( bmp.GetSize() != sizeNeeded ) { wxImage img = bmp.ConvertToImage(); - img.Rescale(size.x, size.y); + img.Rescale(sizeNeeded.x, sizeNeeded.y); bmp = wxBitmap(img); } -#endif } +#endif // wxUSE_IMAGE sm_cache->PutBitmap(hashId, bmp); } diff --git a/src/osx/artmac.cpp b/src/osx/artmac.cpp index 6b49934787..04acf5caf4 100644 --- a/src/osx/artmac.cpp +++ b/src/osx/artmac.cpp @@ -117,6 +117,14 @@ wxSize wxArtProvider::GetNativeSizeHint(const wxArtClient& client) // "32 x 32 pixels is the recommended size" return wxSize(32, 32); } + else if ( client == wxART_BUTTON || client == wxART_MENU ) + { + // Mac UI doesn't use any images in neither buttons nor menus in + // general but the code using wxArtProvider can use wxART_BUTTON to + // find the icons of a roughly appropriate size for the buttons and + // 16x16 seems to be the best choice for this kind of use + return wxSize(16, 16); + } return wxDefaultSize; }