Fix wxMenuItem::SetBitmap infinite recursion differently.
Don't call SetBitmap from GetHBitmapForMenu but instead handle possibly needed bitmap modifications earlier on during SetBitmap. Allows for GetHBitmapForMenu to be const and gets rid of the clumsy re-entry check introduced in r76754. Also check the bitmap for alpha presence instead of needlessly converting the bitmap to an image and checking the latter for alpha. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76781 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -125,7 +125,7 @@ private:
|
|||||||
};
|
};
|
||||||
|
|
||||||
// helper function to get a handle for bitmap associated with item
|
// helper function to get a handle for bitmap associated with item
|
||||||
WXHBITMAP GetHBitmapForMenu(BitmapKind kind);
|
WXHBITMAP GetHBitmapForMenu(BitmapKind kind) const;
|
||||||
|
|
||||||
// helper function to set/change the bitmap
|
// helper function to set/change the bitmap
|
||||||
void DoSetBitmap(const wxBitmap& bmp, bool bChecked);
|
void DoSetBitmap(const wxBitmap& bmp, bool bChecked);
|
||||||
|
@@ -730,37 +730,26 @@ void wxMenuItem::SetItemLabel(const wxString& txt)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void wxMenuItem::DoSetBitmap(const wxBitmap& bmp, bool bChecked)
|
void wxMenuItem::DoSetBitmap(const wxBitmap& bmpNew, bool bChecked)
|
||||||
{
|
{
|
||||||
static bool s_insideSetBitmap = false;
|
wxBitmap& bmp = bChecked ? m_bmpChecked : m_bmpUnchecked;
|
||||||
|
if ( bmp.IsSameAs(bmpNew) )
|
||||||
|
return;
|
||||||
|
|
||||||
if ( bChecked )
|
#if wxUSE_IMAGE
|
||||||
|
if ( !bmpNew.HasAlpha() && wxGetWinVersion() >= wxWinVersion_Vista)
|
||||||
{
|
{
|
||||||
if ( m_bmpChecked.IsSameAs(bmp) )
|
// we must use PARGB DIB for the menu bitmaps so ensure that we do
|
||||||
return;
|
wxImage img(bmpNew.ConvertToImage());
|
||||||
|
img.InitAlpha();
|
||||||
m_bmpChecked = bmp;
|
bmp = wxBitmap(img);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
#endif // wxUSE_IMAGE
|
||||||
{
|
{
|
||||||
if ( m_bmpUnchecked.IsSameAs(bmp) )
|
bmp = bmpNew;
|
||||||
return;
|
|
||||||
|
|
||||||
m_bmpUnchecked = bmp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (s_insideSetBitmap)
|
|
||||||
{
|
|
||||||
// We can arrive here because of calling GetHBitmapForMenu
|
|
||||||
// further down below, which itself can call [Do]SetBitmap
|
|
||||||
// resulting in infinite recursion. After having set the
|
|
||||||
// bitmap just return instead.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
wxON_BLOCK_EXIT_SET(s_insideSetBitmap, false);
|
|
||||||
s_insideSetBitmap = true;
|
|
||||||
|
|
||||||
#if wxUSE_OWNER_DRAWN
|
#if wxUSE_OWNER_DRAWN
|
||||||
// already marked as owner-drawn, cannot be reverted
|
// already marked as owner-drawn, cannot be reverted
|
||||||
if ( IsOwnerDrawn() )
|
if ( IsOwnerDrawn() )
|
||||||
@@ -1377,7 +1366,7 @@ bool wxMenuItem::MSWMustUseOwnerDrawn()
|
|||||||
#endif // wxUSE_OWNER_DRAWN
|
#endif // wxUSE_OWNER_DRAWN
|
||||||
|
|
||||||
// returns the HBITMAP to use in MENUITEMINFO
|
// returns the HBITMAP to use in MENUITEMINFO
|
||||||
HBITMAP wxMenuItem::GetHBitmapForMenu(BitmapKind kind)
|
HBITMAP wxMenuItem::GetHBitmapForMenu(BitmapKind kind) const
|
||||||
{
|
{
|
||||||
// Under versions of Windows older than Vista we can't pass HBITMAP
|
// Under versions of Windows older than Vista we can't pass HBITMAP
|
||||||
// directly as hbmpItem for 2 reasons:
|
// directly as hbmpItem for 2 reasons:
|
||||||
@@ -1401,15 +1390,7 @@ HBITMAP wxMenuItem::GetHBitmapForMenu(BitmapKind kind)
|
|||||||
wxBitmap bmp = GetBitmap(checked);
|
wxBitmap bmp = GetBitmap(checked);
|
||||||
if ( bmp.IsOk() )
|
if ( bmp.IsOk() )
|
||||||
{
|
{
|
||||||
// we must use PARGB DIB for the menu bitmaps so ensure that we do
|
return GetHbitmapOf(bmp);
|
||||||
wxImage img(bmp.ConvertToImage());
|
|
||||||
if ( !img.HasAlpha() )
|
|
||||||
{
|
|
||||||
img.InitAlpha();
|
|
||||||
SetBitmap(img, checked);
|
|
||||||
}
|
|
||||||
|
|
||||||
return GetHbitmapOf(GetBitmap(checked));
|
|
||||||
}
|
}
|
||||||
//else: bitmap is not set
|
//else: bitmap is not set
|
||||||
return NULL;
|
return NULL;
|
||||||
|
Reference in New Issue
Block a user