Add wxBitmapBundle::GetIcon()

This is just a convenient wrapper for GetBitmap() that will be useful in
the classes using wxIcon in their public API to preserve compatibility
after switching to using wxBitmapBundle instead of wxIcon internally.
This commit is contained in:
Vadim Zeitlin 2022-01-20 23:12:12 +00:00
parent 99445aa64c
commit fe2aba3b99
3 changed files with 23 additions and 0 deletions

View File

@ -111,6 +111,10 @@ public:
// If size == wxDefaultSize, GetDefaultSize() is used for it instead.
wxBitmap GetBitmap(const wxSize& size) const;
// Get icon of the specified size, this is just a convenient wrapper for
// GetBitmap() converting the returned bitmap to the icon.
wxIcon GetIcon(const wxSize& size) const;
// Helper combining GetBitmap() and GetPreferredSizeFor(): returns the
// bitmap of the size appropriate for the current DPI scaling of the given
// window.

View File

@ -333,6 +333,14 @@ public:
@param window Non-null and fully created window.
*/
wxBitmap GetBitmapFor(const wxWindow* window) const;
/**
Get icon of the specified size.
This is just a convenient wrapper for GetBitmap() and simply converts
the returned bitmap to wxIcon.
*/
wxIcon GetIcon(const wxSize& size) const;
};
/**

View File

@ -461,6 +461,17 @@ wxBitmap wxBitmapBundle::GetBitmap(const wxSize& size) const
return bmp;
}
wxIcon wxBitmapBundle::GetIcon(const wxSize& size) const
{
wxIcon icon;
const wxBitmap bmp = GetBitmap(size);
if ( bmp.IsOk() )
icon.CopyFromBitmap(bmp);
return icon;
}
wxBitmap wxBitmapBundle::GetBitmapFor(const wxWindow* window) const
{
return GetBitmap(GetPreferredSizeFor(window));