Make wxMSW owner drawn menu item code more clear and correct.
The user-visible effect of this change is that removing the item from the menu and adding it back doesn't lose its icon any more. At the code level, wxMenuItem::SetBitmaps() and related methods are implemented outside of "#if wxUSE_OWNER_DRAWN" which allows to use them even in minimalistic library builds. And IsOwnerDrawn() is not used any more to determine whether the item has bitmaps, just only if it's really owner drawn, making the code more clear and fixing at least the bug above and possible more. Closes #13878. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76202 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -738,8 +738,6 @@ void wxMenuItem::SetItemLabel(const wxString& txt)
|
||||
}
|
||||
}
|
||||
|
||||
#if wxUSE_OWNER_DRAWN
|
||||
|
||||
void wxMenuItem::DoSetBitmap(const wxBitmap& bmp, bool bChecked)
|
||||
{
|
||||
if ( bChecked )
|
||||
@@ -757,16 +755,30 @@ void wxMenuItem::DoSetBitmap(const wxBitmap& bmp, bool bChecked)
|
||||
m_bmpUnchecked = bmp;
|
||||
}
|
||||
|
||||
#if wxUSE_OWNER_DRAWN
|
||||
// already marked as owner-drawn, cannot be reverted
|
||||
if ( IsOwnerDrawn() )
|
||||
return;
|
||||
|
||||
// assume owner-drawn state, will be reset if we can use Windows bitmap
|
||||
// support instead of making the item owner-drawn
|
||||
SetOwnerDrawn(true);
|
||||
|
||||
if ( MSWMustUseOwnerDrawn() )
|
||||
{
|
||||
SetOwnerDrawn(true);
|
||||
|
||||
// Parent menu has to be rearranged/recalculated in this case
|
||||
// (all other menu items have to be also set to owner-drawn mode).
|
||||
if ( m_parentMenu )
|
||||
{
|
||||
wxMenu *menu = m_parentMenu;
|
||||
size_t pos;
|
||||
wxMenuItem *item = menu->FindChildItem(GetMSWId(), &pos);
|
||||
wxCHECK_RET( item == this, wxS("Non unique menu item ID?") );
|
||||
|
||||
menu->Remove(this);
|
||||
menu->Insert(pos, this);
|
||||
}
|
||||
return;
|
||||
}
|
||||
#endif // wxUSE_OWNER_DRAWN
|
||||
|
||||
// the item can be not attached to any menu yet and SetBitmap() is still
|
||||
// valid to call in this case and should do nothing else
|
||||
@@ -802,14 +814,11 @@ void wxMenuItem::DoSetBitmap(const wxBitmap& bmp, bool bChecked)
|
||||
if ( !::SetMenuItemInfo(hMenu, id, FALSE, &mii) )
|
||||
{
|
||||
wxLogLastError(wxT("SetMenuItemInfo"));
|
||||
return;
|
||||
}
|
||||
|
||||
// No need to really make the item owner drawn, Windows will draw its
|
||||
// bitmap(s) for us.
|
||||
SetOwnerDrawn(false);
|
||||
}
|
||||
|
||||
#if wxUSE_OWNER_DRAWN
|
||||
|
||||
int wxMenuItem::MeasureAccelWidth() const
|
||||
{
|
||||
wxString accel = GetItemLabel().AfterFirst(wxT('\t'));
|
||||
@@ -1358,6 +1367,8 @@ bool wxMenuItem::MSWMustUseOwnerDrawn()
|
||||
return mustUseOwnerDrawn;
|
||||
}
|
||||
|
||||
#endif // wxUSE_OWNER_DRAWN
|
||||
|
||||
// returns the HBITMAP to use in MENUITEMINFO
|
||||
HBITMAP wxMenuItem::GetHBitmapForMenu(bool checked)
|
||||
{
|
||||
@@ -1377,7 +1388,6 @@ HBITMAP wxMenuItem::GetHBitmapForMenu(bool checked)
|
||||
#if wxUSE_IMAGE
|
||||
if ( wxGetWinVersion() >= wxWinVersion_Vista )
|
||||
{
|
||||
#if wxUSE_OWNER_DRAWN
|
||||
wxBitmap bmp = GetBitmap(checked);
|
||||
if ( bmp.IsOk() )
|
||||
{
|
||||
@@ -1391,9 +1401,7 @@ HBITMAP wxMenuItem::GetHBitmapForMenu(bool checked)
|
||||
|
||||
return GetHbitmapOf(GetBitmap(checked));
|
||||
}
|
||||
#endif // wxUSE_OWNER_DRAWN
|
||||
//else: bitmap is not set
|
||||
|
||||
return NULL;
|
||||
}
|
||||
#endif // wxUSE_IMAGE
|
||||
@@ -1401,8 +1409,6 @@ HBITMAP wxMenuItem::GetHBitmapForMenu(bool checked)
|
||||
return HBMMENU_CALLBACK;
|
||||
}
|
||||
|
||||
#endif // wxUSE_OWNER_DRAWN
|
||||
|
||||
// ----------------------------------------------------------------------------
|
||||
// wxMenuItemBase
|
||||
// ----------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user