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().
This commit is contained in:
Vadim Zeitlin
2021-11-12 14:10:22 +01:00
parent e58612661c
commit b4ba5ae0b6
2 changed files with 14 additions and 7 deletions

View File

@@ -229,6 +229,15 @@ public:
// returns true if the platform should explicitly apply a theme border // returns true if the platform should explicitly apply a theme border
virtual bool CanApplyThemeBorder() const wxOVERRIDE { return false; } 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: protected:
// flags for DoSetSelection() // flags for DoSetSelection()
enum enum

View File

@@ -22,7 +22,7 @@
#endif #endif
#include "wx/string.h" #include "wx/string.h"
#include "wx/imaglist.h" #include "wx/private/bmpbndl.h"
#include "wx/osx/private.h" #include "wx/osx/private.h"
// //
@@ -266,13 +266,11 @@ public:
[item setView:page->GetHandle() ]; [item setView:page->GetHandle() ];
wxCFStringRef cf( page->GetLabel() , notebook.GetFont().GetEncoding() ); wxCFStringRef cf( page->GetLabel() , notebook.GetFont().GetEncoding() );
[item setLabel:cf.AsNSString()]; [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 ) ) ; [(WXCTabViewImageItem*) item setImage: wxOSXGetImageFromBundle(bitmap)];
if ( bmap.IsOk() )
{
[(WXCTabViewImageItem*) item setImage: bmap.GetNSImage()];
}
} }
} }
} }