From 3d45718de50d193798dee93ce2fe8758f0f0acd6 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 31 Jan 2009 17:51:02 +0000 Subject: [PATCH] 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 --- src/msw/menuitem.cpp | 81 +++++++++++++++++--------------------------- 1 file changed, 31 insertions(+), 50 deletions(-) diff --git a/src/msw/menuitem.cpp b/src/msw/menuitem.cpp index cc55d41996..38088dba4b 100644 --- a/src/msw/menuitem.cpp +++ b/src/msw/menuitem.cpp @@ -365,62 +365,43 @@ void wxMenuItem::SetItemLabel(const wxString& txt) m_parentMenu->UpdateAccel(this); #endif // wxUSE_ACCEL - UINT id = GetMSWId(); - UINT flagsOld = ::GetMenuState(hMenu, id, MF_BYCOMMAND); - if ( flagsOld == 0xFFFFFFFF ) +#if wxUSE_OWNER_DRAWN + if ( IsOwnerDrawn() ) { - // It's not an error, it means that the menu item doesn't exist - //wxLogLastError(wxT("GetMenuState")); + // we don't need to do anything for owner drawn items, they will redraw + // themselves using the new text the next time they're displayed + return; } - else - { - if ( IsSubMenu() ) - { - // high byte contains the number of items in a submenu for submenus - flagsOld &= 0xFF; - flagsOld |= MF_POPUP; - } +#endif // owner drawn - LPCTSTR data; + // update the text of the native menu item + const UINT id = GetMSWId(); -#if wxUSE_OWNER_DRAWN - if ( IsOwnerDrawn() ) - { - flagsOld |= MF_OWNERDRAW; - data = (LPCTSTR)this; - } - else -#endif //owner drawn - { - flagsOld |= MF_STRING; - data = (wxChar*) m_text.wx_str(); - } + WinStruct info; -#ifdef __WXWINCE__ - // FIXME: complete this, applying the old - // flags. - // However, the WinCE doc for SetMenuItemInfo - // says that you can't use it to set the menu - // item state; only data, id and type. - MENUITEMINFO info; - wxZeroMemory(info); - info.cbSize = sizeof(info); + // surprisingly, calling SetMenuItemInfo() with just MIIM_STRING doesn't + // work as it resets the menu bitmap, so we need to first get the old item + // state and then modify it + 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.fType = MFT_STRING; - info.cch = m_text.length(); - info.dwTypeData = (LPTSTR) data ; - if ( !::SetMenuItemInfo(hMenu, id, FALSE, & info) ) - { - wxLogLastError(wxT("SetMenuItemInfo")); - } -#else - if ( ::ModifyMenu(hMenu, id, - MF_BYCOMMAND | flagsOld, - id, data) == (int)0xFFFFFFFF ) - { - wxLogLastError(wxT("ModifyMenu")); - } -#endif + if ( !::GetMenuItemInfo(hMenu, id, FALSE, &info) ) + { + wxLogLastError(wxT("GetMenuItemInfo")); + return; + } + + if ( isLaterThanWin95 ) + info.fMask |= MIIM_STRING; + //else: MIIM_TYPE already specified + info.dwTypeData = (LPTSTR)m_text.wx_str(); + info.cch = m_text.length(); + if ( !::SetMenuItemInfo(hMenu, id, FALSE, &info) ) + { + wxLogLastError(wxT("SetMenuItemInfo")); } } -- 2.47.2