From fe2aba3b99db287636a220e612934158a059d32b Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 20 Jan 2022 23:12:12 +0000 Subject: [PATCH] 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. --- include/wx/bmpbndl.h | 4 ++++ interface/wx/bmpbndl.h | 8 ++++++++ src/common/bmpbndl.cpp | 11 +++++++++++ 3 files changed, 23 insertions(+) diff --git a/include/wx/bmpbndl.h b/include/wx/bmpbndl.h index f903ae5b4e..5b045f2113 100644 --- a/include/wx/bmpbndl.h +++ b/include/wx/bmpbndl.h @@ -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. diff --git a/interface/wx/bmpbndl.h b/interface/wx/bmpbndl.h index e0f1caa558..873fcd0b94 100644 --- a/interface/wx/bmpbndl.h +++ b/interface/wx/bmpbndl.h @@ -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; }; /** diff --git a/src/common/bmpbndl.cpp b/src/common/bmpbndl.cpp index 4a5f45b153..fa73b9c178 100644 --- a/src/common/bmpbndl.cpp +++ b/src/common/bmpbndl.cpp @@ -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));