From b4ba5ae0b6df0e55a991197a6c0897c0d1fd1306 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Fri, 12 Nov 2021 14:10:22 +0100 Subject: [PATCH] Use icons set with SetImages() in Mac wxNotebook implementation Use GetBitmapBundle(), via a helper GetPageBitmapBundle() function which is going to be useful elsewhere too, rather than GetImageList(), as the latter only works if the images were set using SetImageList(), while the new version does the right thing both in this case and when the images were set using SetImages(). --- include/wx/bookctrl.h | 9 +++++++++ src/osx/cocoa/notebook.mm | 12 +++++------- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/include/wx/bookctrl.h b/include/wx/bookctrl.h index f77f277ca6..9e5bb9fe0b 100644 --- a/include/wx/bookctrl.h +++ b/include/wx/bookctrl.h @@ -229,6 +229,15 @@ public: // returns true if the platform should explicitly apply a theme border virtual bool CanApplyThemeBorder() const wxOVERRIDE { return false; } + + // Implementation only from now on. + + // Returns an empty bundle if no image is specified for this page. + wxBitmapBundle GetPageBitmapBundle(size_t n) const + { + return GetBitmapBundle(GetPageImage(n)); + } + protected: // flags for DoSetSelection() enum diff --git a/src/osx/cocoa/notebook.mm b/src/osx/cocoa/notebook.mm index 766ecd2b1b..45a86b2a13 100644 --- a/src/osx/cocoa/notebook.mm +++ b/src/osx/cocoa/notebook.mm @@ -22,7 +22,7 @@ #endif #include "wx/string.h" -#include "wx/imaglist.h" +#include "wx/private/bmpbndl.h" #include "wx/osx/private.h" // @@ -266,13 +266,11 @@ public: [item setView:page->GetHandle() ]; wxCFStringRef cf( page->GetLabel() , notebook.GetFont().GetEncoding() ); [item setLabel:cf.AsNSString()]; - if ( notebook.GetImageList() && notebook.GetPageImage(i) >= 0 ) + + const wxBitmapBundle bitmap = notebook.GetPageBitmapBundle(i); + if ( bitmap.IsOk() ) { - const wxBitmap bmap = notebook.GetImageList()->GetBitmap( notebook.GetPageImage( i ) ) ; - if ( bmap.IsOk() ) - { - [(WXCTabViewImageItem*) item setImage: bmap.GetNSImage()]; - } + [(WXCTabViewImageItem*) item setImage: wxOSXGetImageFromBundle(bitmap)]; } } }