]> git.saurik.com Git - wxWidgets.git/commitdiff
use SetMenuItemInfo() to update the item label to avoid reseting its bitmap and so...
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 31 Jan 2009 17:51:02 +0000 (17:51 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 31 Jan 2009 17:51:02 +0000 (17:51 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@58556 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/msw/menuitem.cpp

index cc55d4199646b42483ba76e7fa7aaadbe0810f26..38088dba4b33d09b7442a1b3d7bc282d70559fb6 100644 (file)
@@ -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<MENUITEMINFO> 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"));
     }
 }