X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/efb27c04d3045a6db679ec14c6a88b1d2276665d..9d5507f7a2701395e1d5c121bd877bb9066ee6ea:/src/msw/menuitem.cpp diff --git a/src/msw/menuitem.cpp b/src/msw/menuitem.cpp index d2d737ae34..964e64892f 100644 --- a/src/msw/menuitem.cpp +++ b/src/msw/menuitem.cpp @@ -154,12 +154,6 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu, void wxMenuItem::Init() { - if (m_text.IsEmpty()) - { - wxASSERT_MSG(wxIsStockID(GetId()), wxT("A non-stock menu item with an empty label?")); - m_text = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR|wxSTOCK_WITH_MNEMONIC); - } - m_radioGroup.start = -1; m_isRadioGroupStart = false; @@ -192,9 +186,14 @@ wxMenuItem::~wxMenuItem() // ---- // return the id for calling Win32 API functions -int wxMenuItem::GetRealId() const +unsigned wxMenuItem::GetMSWId() const { - return m_subMenu ? (int)m_subMenu->GetHMenu() : GetId(); + // we must use ids in unsigned short range with Windows functions, if we + // pass ids > USHRT_MAX to them they get very confused (e.g. start + // generating WM_COMMAND messages with negative high word of wParam), so + // use the cast to ensure the id is in range + return m_subMenu ? wx_reinterpret_cast(unsigned, m_subMenu->GetHMenu()) + : wx_static_cast(unsigned short, GetId()); } // get item state @@ -207,13 +206,13 @@ bool wxMenuItem::IsChecked() const if ( GetId() == wxID_SEPARATOR ) return false ; - int flag = ::GetMenuState(GetHMenuOf(m_parentMenu), GetId(), MF_BYCOMMAND); + int flag = ::GetMenuState(GetHMenuOf(m_parentMenu), GetMSWId(), MF_BYCOMMAND); return (flag & MF_CHECKED) != 0; } /* static */ -wxString wxMenuItemBase::GetLabelFromText(const wxString& text) +wxString wxMenuItemBase::GetLabelText(const wxString& text) { return wxStripMenuCodes(text); } @@ -251,7 +250,7 @@ void wxMenuItem::Enable(bool enable) return; long rc = EnableMenuItem(GetHMenuOf(m_parentMenu), - GetRealId(), + GetMSWId(), MF_BYCOMMAND | (enable ? MF_ENABLED : MF_GRAYED)); @@ -333,7 +332,7 @@ void wxMenuItem::Check(bool check) else // check item { if ( ::CheckMenuItem(hmenu, - GetRealId(), + GetMSWId(), MF_BYCOMMAND | flags) == (DWORD)-1 ) { wxFAIL_MSG( _T("CheckMenuItem() failed, item not in the menu?") ); @@ -343,7 +342,7 @@ void wxMenuItem::Check(bool check) wxMenuItemBase::Check(check); } -void wxMenuItem::SetText(const wxString& txt) +void wxMenuItem::SetItemLabel(const wxString& txt) { wxString text = txt; @@ -351,17 +350,16 @@ void wxMenuItem::SetText(const wxString& txt) if ( m_text == txt ) return; - if (text.IsEmpty()) - { - wxASSERT_MSG(wxIsStockID(GetId()), wxT("A non-stock menu item with an empty label?")); - text = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR|wxSTOCK_WITH_MNEMONIC); - } + // wxMenuItemBase will do stock ID checks + wxMenuItemBase::SetItemLabel(text); + + // m_text could now be different from 'text' if we are a stock menu item, + // so use only m_text below - wxMenuItemBase::SetText(text); - OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) ); + 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); @@ -371,7 +369,7 @@ void wxMenuItem::SetText(const wxString& txt) m_parentMenu->UpdateAccel(this); #endif // wxUSE_ACCEL - UINT id = GetRealId(); + UINT id = GetMSWId(); UINT flagsOld = ::GetMenuState(hMenu, id, MF_BYCOMMAND); if ( flagsOld == 0xFFFFFFFF ) { @@ -399,7 +397,7 @@ void wxMenuItem::SetText(const wxString& txt) #endif //owner drawn { flagsOld |= MF_STRING; - data = (wxChar*) text.c_str(); + data = (wxChar*) m_text.wx_str(); } #ifdef __WXWINCE__ @@ -413,7 +411,7 @@ void wxMenuItem::SetText(const wxString& txt) 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) ) {