use SetMenuItemInfo() to update the item label to avoid reseting its bitmap and so use the same code for the desktop and CE versions (see #10452)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58556 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
@@ -365,62 +365,43 @@ void wxMenuItem::SetItemLabel(const wxString& txt)
|
|||||||
m_parentMenu->UpdateAccel(this);
|
m_parentMenu->UpdateAccel(this);
|
||||||
#endif // wxUSE_ACCEL
|
#endif // wxUSE_ACCEL
|
||||||
|
|
||||||
UINT id = GetMSWId();
|
|
||||||
UINT flagsOld = ::GetMenuState(hMenu, id, MF_BYCOMMAND);
|
|
||||||
if ( flagsOld == 0xFFFFFFFF )
|
|
||||||
{
|
|
||||||
// It's not an error, it means that the menu item doesn't exist
|
|
||||||
//wxLogLastError(wxT("GetMenuState"));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if ( IsSubMenu() )
|
|
||||||
{
|
|
||||||
// high byte contains the number of items in a submenu for submenus
|
|
||||||
flagsOld &= 0xFF;
|
|
||||||
flagsOld |= MF_POPUP;
|
|
||||||
}
|
|
||||||
|
|
||||||
LPCTSTR data;
|
|
||||||
|
|
||||||
#if wxUSE_OWNER_DRAWN
|
#if wxUSE_OWNER_DRAWN
|
||||||
if ( IsOwnerDrawn() )
|
if ( IsOwnerDrawn() )
|
||||||
{
|
{
|
||||||
flagsOld |= MF_OWNERDRAW;
|
// we don't need to do anything for owner drawn items, they will redraw
|
||||||
data = (LPCTSTR)this;
|
// themselves using the new text the next time they're displayed
|
||||||
}
|
return;
|
||||||
else
|
}
|
||||||
#endif //owner drawn
|
#endif // owner drawn
|
||||||
{
|
|
||||||
flagsOld |= MF_STRING;
|
|
||||||
data = (wxChar*) m_text.wx_str();
|
|
||||||
}
|
|
||||||
|
|
||||||
#ifdef __WXWINCE__
|
// update the text of the native menu item
|
||||||
// FIXME: complete this, applying the old
|
const UINT id = GetMSWId();
|
||||||
// flags.
|
|
||||||
// However, the WinCE doc for SetMenuItemInfo
|
WinStruct<MENUITEMINFO> info;
|
||||||
// says that you can't use it to set the menu
|
|
||||||
// item state; only data, id and type.
|
// surprisingly, calling SetMenuItemInfo() with just MIIM_STRING doesn't
|
||||||
MENUITEMINFO info;
|
// work as it resets the menu bitmap, so we need to first get the old item
|
||||||
wxZeroMemory(info);
|
// state and then modify it
|
||||||
info.cbSize = sizeof(info);
|
const bool isLaterThanWin95 = wxGetWinVersion() > wxWinVersion_95;
|
||||||
|
info.fMask = MIIM_ID | MIIM_SUBMENU | MIIM_CHECKMARKS | MIIM_DATA;
|
||||||
|
if ( isLaterThanWin95 )
|
||||||
|
info.fMask |= MIIM_BITMAP | MIIM_FTYPE;
|
||||||
|
else
|
||||||
info.fMask = MIIM_TYPE;
|
info.fMask = MIIM_TYPE;
|
||||||
info.fType = MFT_STRING;
|
if ( !::GetMenuItemInfo(hMenu, id, FALSE, &info) )
|
||||||
info.cch = m_text.length();
|
{
|
||||||
info.dwTypeData = (LPTSTR) data ;
|
wxLogLastError(wxT("GetMenuItemInfo"));
|
||||||
if ( !::SetMenuItemInfo(hMenu, id, FALSE, & info) )
|
return;
|
||||||
{
|
}
|
||||||
wxLogLastError(wxT("SetMenuItemInfo"));
|
|
||||||
}
|
if ( isLaterThanWin95 )
|
||||||
#else
|
info.fMask |= MIIM_STRING;
|
||||||
if ( ::ModifyMenu(hMenu, id,
|
//else: MIIM_TYPE already specified
|
||||||
MF_BYCOMMAND | flagsOld,
|
info.dwTypeData = (LPTSTR)m_text.wx_str();
|
||||||
id, data) == (int)0xFFFFFFFF )
|
info.cch = m_text.length();
|
||||||
{
|
if ( !::SetMenuItemInfo(hMenu, id, FALSE, &info) )
|
||||||
wxLogLastError(wxT("ModifyMenu"));
|
{
|
||||||
}
|
wxLogLastError(wxT("SetMenuItemInfo"));
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user