From b5c2a33438de94c80c55f1f0d4e96224236bf60f Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Sun, 29 Mar 2009 21:23:59 +0000 Subject: [PATCH] wxArtProvider::GetIconBundle() cleanup: * makes GetIcon() and GetBitmap() behave in the same way again (i.e. GetBitmap falls back to CreateIconBundle too) * GetIcon() used to call CreateIconBundle() first, before CreateBitmap() - this doesn't make sense, inverted * GetIconBundle() falls back to GetIcon() if provider's CreateIconBundle() doesn't return anything and vice versa: GetIcon()/GetBitmap() falls back to GetIconBundle() if CreateBitmap() doesn't return anything git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@59930 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/artprov.h | 7 +++- src/common/artprov.cpp | 72 +++++++++++++++++++++++++++++------------- src/osx/artmac.cpp | 20 ------------ 3 files changed, 56 insertions(+), 43 deletions(-) diff --git a/include/wx/artprov.h b/include/wx/artprov.h index 2ece3c33b2..b32e34b375 100644 --- a/include/wx/artprov.h +++ b/include/wx/artprov.h @@ -205,7 +205,10 @@ protected: // only once per instance's lifetime for each requested wxArtID. virtual wxBitmap CreateBitmap(const wxArtID& WXUNUSED(id), const wxArtClient& WXUNUSED(client), - const wxSize& WXUNUSED(size)) { return wxNullBitmap; } + const wxSize& WXUNUSED(size)) + { + return wxNullBitmap; + } virtual wxIconBundle CreateIconBundle(const wxArtID& WXUNUSED(id), const wxArtClient& WXUNUSED(client)) @@ -215,6 +218,8 @@ protected: private: static void CommonAddingProvider(); + static wxIconBundle DoGetIconBundle(const wxArtID& id, + const wxArtClient& client); private: // list of providers: diff --git a/src/common/artprov.cpp b/src/common/artprov.cpp index 299c5a669f..fb19f1ebbf 100644 --- a/src/common/artprov.cpp +++ b/src/common/artprov.cpp @@ -235,28 +235,63 @@ wxArtProvider::~wxArtProvider() { bmp = node->GetData()->CreateBitmap(id, client, size); if ( bmp.Ok() ) + break; + } + + if ( !bmp.Ok() ) + { + // no bitmap created -- as a fallback, try if we can find desired + // icon in a bundle + wxIconBundle iconBundle = DoGetIconBundle(id, client); + if ( iconBundle.IsOk() ) { + wxSize sz(size != wxDefaultSize + ? size + : GetNativeSizeHint(client)); + wxIcon icon(iconBundle.GetIcon(sz)); + if ( icon.IsOk() ) + bmp.CopyFromIcon(icon); + } + } + + if ( bmp.IsOk() ) + { + // 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) ) - { - wxImage img = bmp.ConvertToImage(); - img.Rescale(size.x, size.y); - bmp = wxBitmap(img); - } -#endif - break; + if ( size != wxDefaultSize && + (bmp.GetWidth() != size.x || bmp.GetHeight() != size.y) ) + { + wxImage img = bmp.ConvertToImage(); + img.Rescale(size.x, size.y); + bmp = wxBitmap(img); } - // We could try the IconBundles here and convert what we find - // to a bitmap. +#endif } + sm_cache->PutBitmap(hashId, bmp); - } + } return bmp; } -/*static*/ wxIconBundle wxArtProvider::GetIconBundle(const wxArtID& id, const wxArtClient& client) +/*static*/ +wxIconBundle wxArtProvider::GetIconBundle(const wxArtID& id, const wxArtClient& client) +{ + wxIconBundle iconbundle(DoGetIconBundle(id, client)); + + if ( iconbundle.IsOk() ) + { + return iconbundle; + } + else + { + // fall back to single-icon bundle + return wxIconBundle(GetIcon(id, client)); + } +} + +/*static*/ +wxIconBundle wxArtProvider::DoGetIconBundle(const wxArtID& id, const wxArtClient& client) { // safety-check against writing client,id,size instead of id,client,size: wxASSERT_MSG( client.Last() == _T('C'), _T("invalid 'client' parameter") ); @@ -286,16 +321,9 @@ wxArtProvider::~wxArtProvider() const wxArtClient& client, const wxSize& size) { - wxCHECK_MSG( sm_providers, wxNullIcon, _T("no wxArtProvider exists") ); - - // First look for an appropriate icon bundle - this will give us the best icon - wxIconBundle iconBundle = GetIconBundle(id, client); - if ( iconBundle.IsOk() ) - return iconBundle.GetIcon(size); - - // If there is no icon bundle then look for a bitmap wxBitmap bmp = GetBitmap(id, client, size); - if ( !bmp.Ok() ) + + if ( !bmp.IsOk() ) return wxNullIcon; wxIcon icon; diff --git a/src/osx/artmac.cpp b/src/osx/artmac.cpp index 2777353262..9142c143e8 100644 --- a/src/osx/artmac.cpp +++ b/src/osx/artmac.cpp @@ -34,8 +34,6 @@ class wxMacArtProvider : public wxArtProvider { protected: - virtual wxBitmap CreateBitmap(const wxArtID& id, const wxArtClient& client, - const wxSize& size); virtual wxIconBundle CreateIconBundle(const wxArtID& id, const wxArtClient& client); }; @@ -105,24 +103,6 @@ wxIconBundle wxMacArtProvider::CreateIconBundle(const wxArtID& id, const wxArtCl return wxMacArtProvider_CreateIconBundle(id); } -// ---------------------------------------------------------------------------- -// CreateBitmap -// ---------------------------------------------------------------------------- - -wxBitmap wxMacArtProvider::CreateBitmap(const wxArtID& id, - const wxArtClient& client, - const wxSize& reqSize) -{ - wxIconBundle ic(CreateIconBundle(id, client)); - if (ic.IsOk()) - { - wxIcon theIcon(ic.GetIcon(reqSize)); - return wxBitmap(theIcon); - } - - return wxNullBitmap; -} - // ---------------------------------------------------------------------------- // wxArtProvider::GetNativeSizeHint() -- 2.45.2