Improve fallback logic in wxArtProvider::GetBitmap{,Bundle}()

This improves the changes of f78db92462 (Avoid bitmap scaling in
wxArtProvider::GetBitmapBundle(), 2021-12-17) and still uses a custom
bundle to avoid scaling the bitmap if possible, but does it in
GetBitmapBundle() itself rather than CreateBitmapBundle().

This allows to also use CreateBitmapBundle() from GetBitmap(), as there
is no possibility of infinite recursion due to calling each of these
functions from the other one any more, and so allows defining art
providers overriding only CreateBitmapBundle() instead of having to
always override both it and CreateBitmap().

Also add a unit test, even if just a trivial one, for these functions,
to at least check that they don't crash.
This commit is contained in:
Vadim Zeitlin
2022-01-31 22:44:22 +00:00
parent 1a10199575
commit ae7fa19ae3
3 changed files with 55 additions and 23 deletions

View File

@@ -14,6 +14,8 @@
#include "wx/bmpbndl.h"
#include "wx/artprov.h"
#include "asserthelper.h"
// ----------------------------------------------------------------------------
@@ -144,3 +146,16 @@ TEST_CASE("BitmapBundle::FromSVGFile", "[bmpbundle][svg][file]")
}
#endif // wxHAS_SVG
TEST_CASE("BitmapBundle::ArtProvider", "[bmpbundle][art]")
{
// Check that creating a bogus bundle fails as expected.
wxBitmapBundle b = wxArtProvider::GetBitmapBundle("bloordyblop");
CHECK( !b.IsOk() );
// And that creating a bundle using a standard icon works.
const wxSize size(16, 16);
b = wxArtProvider::GetBitmapBundle(wxART_INFORMATION, wxART_MENU, size);
CHECK( b.IsOk() );
CHECK( b.GetDefaultSize() == size );
}