X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/90527a50d74bed6ed6b4d163e8170ae8c3f5d869..c6a6bbbf637a5a580b7ab182483d27522f5e3189:/src/common/menucmn.cpp diff --git a/src/common/menucmn.cpp b/src/common/menucmn.cpp index 896c9e1e03..87969e0411 100644 --- a/src/common/menucmn.cpp +++ b/src/common/menucmn.cpp @@ -34,6 +34,8 @@ #include "wx/menu.h" #endif +#include "wx/stockitem.h" + // ---------------------------------------------------------------------------- // template lists // ---------------------------------------------------------------------------- @@ -174,13 +176,16 @@ static int bool wxAcceleratorEntry::ParseAccel(const wxString& text, int *flagsOut, int *keyOut) { - // the parser won't like leading/trailing spaces - wxString label = text.Strip(wxString::both); + // the parser won't like trailing spaces + wxString label = text; + label.Trim(true); // the initial \t must be preserved so don't strip leading whitespaces // check for accelerators: they are given after '\t' int posTab = label.Find(wxT('\t')); if ( posTab == wxNOT_FOUND ) + { return false; + } // parse the accelerator string int accelFlags = wxACCEL_NORMAL; @@ -314,9 +319,7 @@ wxString wxAcceleratorEntry::ToString() const const int code = GetKeyCode(); - if ( wxIsalnum(code) ) - text << (wxChar)code; - else if ( code >= WXK_F1 && code <= WXK_F12 ) + if ( code >= WXK_F1 && code <= WXK_F12 ) text << _("F") << code - WXK_F1 + 1; else if ( code >= WXK_NUMPAD0 && code <= WXK_NUMPAD9 ) text << _("KP_") << code - WXK_NUMPAD0; @@ -335,8 +338,22 @@ wxString wxAcceleratorEntry::ToString() const } } - wxASSERT_MSG( n != WXSIZEOF(wxKeyNames), - wxT("unknown keyboard accelerator code") ); + if ( n == WXSIZEOF(wxKeyNames) ) + { + // must be a simple key + if ( +#if !wxUSE_UNICODE + isascii(code) && +#endif // ANSI + wxIsalnum(code) ) + { + text << (wxChar)code; + } + else + { + wxFAIL_MSG( wxT("unknown keyboard accelerator code") ); + } + } } return text; @@ -360,8 +377,6 @@ wxMenuItemBase::wxMenuItemBase(wxMenu *parentMenu, const wxString& help, wxItemKind kind, wxMenu *subMenu) - : m_text(text), - m_help(help) { wxASSERT_MSG( parentMenu != NULL, wxT("menuitem should have a menu") ); @@ -375,6 +390,9 @@ wxMenuItemBase::wxMenuItemBase(wxMenu *parentMenu, m_id = wxNewId(); if (m_id == wxID_SEPARATOR) m_kind = wxITEM_SEPARATOR; + + SetText(text); + SetHelp(help); } wxMenuItemBase::~wxMenuItemBase() @@ -403,6 +421,30 @@ void wxMenuItemBase::SetAccel(wxAcceleratorEntry *accel) #endif // wxUSE_ACCEL +void wxMenuItemBase::SetText(const wxString& str) +{ + m_text = str; + + if ( m_text.empty() && !IsSeparator() ) + { + wxASSERT_MSG( wxIsStockID(GetId()), + wxT("A non-stock menu item with an empty label?") ); + m_text = wxGetStockLabel(GetId(), wxSTOCK_WITH_ACCELERATOR | + wxSTOCK_WITH_MNEMONIC); + } +} + +void wxMenuItemBase::SetHelp(const wxString& str) +{ + m_help = str; + + if ( m_help.empty() && !IsSeparator() && wxIsStockID(GetId()) ) + { + // get a stock help string + m_help = wxGetStockHelpString(GetId()); + } +} + bool wxMenuBase::ms_locked = true; // ----------------------------------------------------------------------------