#if wxUSE_MENUS
#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"
Init();
}
+#if WXWIN_COMPATIBILITY_2_8
wxMenuItem::wxMenuItem(wxMenu *parentMenu,
int id,
const wxString& text,
{
Init();
}
+#endif
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
// ----
// 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())
+ : static_cast<unsigned short>(GetId());
}
// get item state
{
// 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
// -----------------
return;
long rc = EnableMenuItem(GetHMenuOf(m_parentMenu),
- GetRealId(),
+ GetMSWId(),
MF_BYCOMMAND |
(enable ? MF_ENABLED : MF_GRAYED));
else // check item
{
if ( ::CheckMenuItem(hmenu,
- GetRealId(),
+ GetMSWId(),
MF_BYCOMMAND | flags) == (DWORD)-1 )
{
wxFAIL_MSG( _T("CheckMenuItem() failed, item not in the menu?") );
wxMenuItemBase::Check(check);
}
-void wxMenuItem::SetText(const wxString& text)
+void wxMenuItem::SetItemLabel(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::SetText(text);
- OWNER_DRAWN_ONLY( wxOwnerDrawn::SetName(text) );
+ // 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
+
+ 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);
m_parentMenu->UpdateAccel(this);
#endif // wxUSE_ACCEL
- UINT id = GetRealId();
+ UINT id = GetMSWId();
UINT flagsOld = ::GetMenuState(hMenu, id, MF_BYCOMMAND);
if ( flagsOld == 0xFFFFFFFF )
{
#endif //owner drawn
{
flagsOld |= MF_STRING;
- data = (wxChar*) text.c_str();
+ data = (wxChar*) m_text.wx_str();
}
#ifdef __WXWINCE__
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) )
{