X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/345319d60c69cac3f5e9e74ee570d20370fc532f..eecf97a5ee1df46b19ca85a00229cd81d185bd6f:/src/msw/menuitem.cpp diff --git a/src/msw/menuitem.cpp b/src/msw/menuitem.cpp index 79c03953b8..e2d5bcbfbb 100644 --- a/src/msw/menuitem.cpp +++ b/src/msw/menuitem.cpp @@ -137,6 +137,7 @@ wxMenuItem::wxMenuItem(wxMenu *pParentMenu, Init(); } +#if WXWIN_COMPATIBILITY_2_8 wxMenuItem::wxMenuItem(wxMenu *parentMenu, int id, const wxString& text, @@ -151,6 +152,7 @@ wxMenuItem::wxMenuItem(wxMenu *parentMenu, { Init(); } +#endif void wxMenuItem::Init() { @@ -170,7 +172,7 @@ void wxMenuItem::Init() ResetOwnerDrawn(); // switch ownerdraw back on if using a non default margin - if ( GetId() != wxID_SEPARATOR ) + if ( !IsSeparator() ) SetMarginWidth(GetMarginWidth()); // tell the owner drawing code to show the accel string as well @@ -186,9 +188,14 @@ wxMenuItem::~wxMenuItem() // ---- // return the id for calling Win32 API functions -int wxMenuItem::GetRealId() const +WXWPARAM 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 ? wxPtrToUInt(m_subMenu->GetHMenu()) + : wx_static_cast(unsigned short, GetId()); } // get item state @@ -198,20 +205,14 @@ bool wxMenuItem::IsChecked() const { // fix that RTTI is always getting the correct state (separators cannot be checked, but the call below // returns true - if ( GetId() == wxID_SEPARATOR ) + if ( IsSeparator() ) 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) -{ - return wxStripMenuCodes(text); -} - // radio group stuff // ----------------- @@ -245,7 +246,7 @@ void wxMenuItem::Enable(bool enable) return; long rc = EnableMenuItem(GetHMenuOf(m_parentMenu), - GetRealId(), + GetMSWId(), MF_BYCOMMAND | (enable ? MF_ENABLED : MF_GRAYED)); @@ -327,7 +328,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?") ); @@ -337,7 +338,7 @@ void wxMenuItem::Check(bool check) wxMenuItemBase::Check(check); } -void wxMenuItem::SetText(const wxString& txt) +void wxMenuItem::SetItemLabel(const wxString& txt) { wxString text = txt; @@ -346,7 +347,7 @@ void wxMenuItem::SetText(const wxString& txt) return; // wxMenuItemBase will do stock ID checks - wxMenuItemBase::SetText(text); + wxMenuItemBase::SetItemLabel(text); // m_text could now be different from 'text' if we are a stock menu item, // so use only m_text below @@ -364,7 +365,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 ) { @@ -392,7 +393,7 @@ void wxMenuItem::SetText(const wxString& txt) #endif //owner drawn { flagsOld |= MF_STRING; - data = (wxChar*) m_text.c_str(); + data = (wxChar*) m_text.wx_str(); } #ifdef __WXWINCE__