Fix setting menu item bitmaps after appending them in wxMSW.

Update the bitmap used by Windows when using non-owner-drawn items with
bitmaps.

Closes #9388.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76191 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2014-03-23 15:18:37 +00:00
parent 67b128e186
commit a3da62503f
3 changed files with 77 additions and 8 deletions

View File

@@ -52,6 +52,7 @@ wxMSW:
- Improve wxMimeTypesManager open command detection (Eric Jensen).
- Make wxFILTER_INCLUDE_LIST in wxTextValidator actually usable.
- Fix setting menu item bitmaps after appending them (Artur Wieczorek).
- Fix handling of selected images in wxBitmapButton (Artur Wieczorek).
- Fix loading of bitmap with non-pre-multiplied alpha (Artur Wieczorek).
- Support multiline strings in wxDC::DrawRotatedText() (Artur Wieczorek).

View File

@@ -77,18 +77,13 @@ public:
void SetBitmaps(const wxBitmap& bmpChecked,
const wxBitmap& bmpUnchecked = wxNullBitmap)
{
m_bmpChecked = bmpChecked;
m_bmpUnchecked = bmpUnchecked;
SetOwnerDrawn(true);
DoSetBitmap(bmpChecked, true);
DoSetBitmap(bmpUnchecked, false);
}
void SetBitmap(const wxBitmap& bmp, bool bChecked = true)
{
if ( bChecked )
m_bmpChecked = bmp;
else
m_bmpUnchecked = bmp;
SetOwnerDrawn(true);
DoSetBitmap(bmp, bChecked);
}
void SetDisabledBitmap(const wxBitmap& bmpDisabled)
@@ -124,6 +119,9 @@ private:
// helper function to get a handle of bitmap associated with item
WXHBITMAP GetHBitmapForMenu(bool checked = true);
// helper function to set/change the bitmap
void DoSetBitmap(const wxBitmap& bmp, bool bChecked);
#else // !wxUSE_OWNER_DRAWN
// Provide stubs for the public functions above to ensure that the code
// still compiles without wxUSE_OWNER_DRAWN -- it makes sense to just drop

View File

@@ -740,6 +740,76 @@ void wxMenuItem::SetItemLabel(const wxString& txt)
#if wxUSE_OWNER_DRAWN
void wxMenuItem::DoSetBitmap(const wxBitmap& bmp, bool bChecked)
{
if ( bChecked )
{
if ( m_bmpChecked.IsSameAs(bmp) )
return;
m_bmpChecked = bmp;
}
else
{
if ( m_bmpUnchecked.IsSameAs(bmp) )
return;
m_bmpUnchecked = bmp;
}
// 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 ( MustUseOwnerDrawn() )
return;
// 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
if ( !m_parentMenu )
return;
HMENU hMenu = GetHMenuOf(m_parentMenu);
if ( !hMenu )
return;
const UINT id = GetMSWId();
const UINT state = ::GetMenuState(hMenu, id, MF_BYCOMMAND);
if ( state == (UINT)-1 )
return;
// update the bitmap of the native menu item
// don't set hbmpItem for the checkable items as it would
// be used for both checked and unchecked state
WinStruct<MENUITEMINFO> mii;
if ( IsCheckable() )
{
mii.fMask = MIIM_CHECKMARKS;
mii.hbmpChecked = GetHBitmapForMenu(true);
mii.hbmpUnchecked = GetHBitmapForMenu(false);
}
else
{
mii.fMask = MIIM_BITMAP;
mii.hbmpItem = GetHBitmapForMenu();
}
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);
}
int wxMenuItem::MeasureAccelWidth() const
{
wxString accel = GetItemLabel().AfterFirst(wxT('\t'));