Handle non-DIB wxBitmaps correctly in wxMenuItem

Such bitmaps can come from wxImageList but also be created directly, so
we need to handle them -- do it by converting them to DIB, if they are
not in this format yet.

This fixes black background for transparent areas in the menu bitmaps
shown for some of them.

See #22669.

Co-Authored-By: Vadim Zeitlin <vadim@wxwidgets.org>
This commit is contained in:
Artur Wieczorek 2022-08-01 17:41:50 +01:00 committed by Vadim Zeitlin
parent a12a2f1282
commit a3fd6cf4e6

View file

@ -692,12 +692,21 @@ wxBitmap wxMenuItem::GetBitmap(bool bChecked) const
{
wxBitmap bmp = GetBitmapFromBundle(bChecked ? m_bitmap : m_bmpUnchecked);
#if wxUSE_IMAGE
if ( bmp.IsOk() && !bmp.HasAlpha() && wxGetWinVersion() >= wxWinVersion_Vista)
if ( bmp.IsOk() && wxGetWinVersion() >= wxWinVersion_Vista)
{
// we must use PARGB DIB for the menu bitmaps so ensure that we do
wxImage img(bmp.ConvertToImage());
img.InitAlpha();
bmp = wxBitmap(img);
if ( !bmp.HasAlpha() )
{
wxImage img(bmp.ConvertToImage());
img.InitAlpha();
bmp = wxBitmap(img);
}
else
{
// even if the bitmap already has alpha, it might be a DDB, while
// the menu code only handles alpha correctly for DIBs
bmp.ConvertToDIB();
}
}
#endif // wxUSE_IMAGE
return bmp;