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
This commit is contained in:
Václav Slavík 2009-03-29 21:23:59 +00:00
parent cee875e329
commit b5c2a33438
3 changed files with 57 additions and 44 deletions

View File

@ -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:

View File

@ -235,28 +235,63 @@ wxArtProvider::~wxArtProvider()
{
bmp = node->GetData()->CreateBitmap(id, client, size);
if ( bmp.Ok() )
{
#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 ( !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);
}
// We could try the IconBundles here and convert what we find
// to a bitmap.
}
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
}
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;

View File

@ -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()