X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/e4db172a3b318df9aff178eb6c5da149d56e0859..c0badae10089ea785072d739df817b1f5f05c088:/src/msw/menuitem.cpp?ds=sidebyside diff --git a/src/msw/menuitem.cpp b/src/msw/menuitem.cpp index 085dc6e47f..79c03953b8 100644 --- a/src/msw/menuitem.cpp +++ b/src/msw/menuitem.cpp @@ -26,21 +26,20 @@ #if wxUSE_MENUS -#include "wx/menu.h" +#include "wx/menuitem.h" +#include "wx/stockitem.h" #ifndef WX_PRECOMP #include "wx/font.h" #include "wx/bitmap.h" #include "wx/settings.h" - #include "wx/font.h" #include "wx/window.h" #include "wx/accel.h" #include "wx/string.h" #include "wx/log.h" + #include "wx/menu.h" #endif -#include "wx/menuitem.h" - #if wxUSE_ACCEL #include "wx/accel.h" #endif // wxUSE_ACCEL @@ -79,7 +78,7 @@ UINT GetMenuState(HMENU hMenu, UINT id, UINT flags) ; bool wxMenuItemStreamingCallback( const wxObject *object, wxWriter * , wxPersister * , wxxVariantArray & ) { const wxMenuItem * mitem = dynamic_cast(object) ; - if ( mitem->GetMenu() && !mitem->GetMenu()->GetTitle().IsEmpty() ) + if ( mitem->GetMenu() && !mitem->GetMenu()->GetTitle().empty() ) { // we don't stream out the first two items for menus with a title, they will be reconstructed if ( mitem->GetMenu()->FindItemByPosition(0) == mitem || mitem->GetMenu()->FindItemByPosition(1) == mitem ) @@ -338,17 +337,24 @@ void wxMenuItem::Check(bool check) wxMenuItemBase::Check(check); } -void wxMenuItem::SetText(const wxString& text) +void wxMenuItem::SetText(const wxString& txt) { + wxString text = txt; + // don't do anything if label didn't change - if ( m_text == text ) + if ( m_text == txt ) return; + // wxMenuItemBase will do stock ID checks wxMenuItemBase::SetText(text); - OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) ); + + // m_text could now be different from 'text' if we are a stock menu item, + // so use only m_text below + + OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(m_text) ); #if wxUSE_OWNER_DRAWN // tell the owner drawing code to to show the accel string as well - SetAccelString(text.AfterFirst(_T('\t'))); + SetAccelString(m_text.AfterFirst(_T('\t'))); #endif HMENU hMenu = GetHMenuOf(m_parentMenu); @@ -386,7 +392,7 @@ void wxMenuItem::SetText(const wxString& text) #endif //owner drawn { flagsOld |= MF_STRING; - data = (wxChar*) text.c_str(); + data = (wxChar*) m_text.c_str(); } #ifdef __WXWINCE__ @@ -400,7 +406,7 @@ void wxMenuItem::SetText(const wxString& text) info.cbSize = sizeof(info); info.fMask = MIIM_TYPE; info.fType = MFT_STRING; - info.cch = text.length(); + info.cch = m_text.length(); info.dwTypeData = (LPTSTR) data ; if ( !::SetMenuItemInfo(hMenu, id, FALSE, & info) ) {