X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/944f641cf9e822770d667be45926e58deb339482..7198c3368055d88249a338eb33b21f051f674806:/src/common/accelcmn.cpp diff --git a/src/common/accelcmn.cpp b/src/common/accelcmn.cpp index 718275e160..f52fc05de3 100644 --- a/src/common/accelcmn.cpp +++ b/src/common/accelcmn.cpp @@ -26,13 +26,15 @@ #if wxUSE_ACCEL #ifndef WX_PRECOMP + #include "wx/accel.h" #include "wx/string.h" #include "wx/intl.h" #include "wx/log.h" - #include "wx/accel.h" #include "wx/crt.h" #endif //WX_PRECOMP +wxAcceleratorTable wxNullAcceleratorTable; + // ============================================================================ // wxAcceleratorEntry implementation // ============================================================================ @@ -158,11 +160,13 @@ wxAcceleratorEntry::ParseAccel(const wxString& text, int *flagsOut, int *keyOut) { // 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 + label.Trim(true); - // If we're passed the entire menu item label instead of just the - // accelerator, skip the label part and only look after the TAB. - // check for accelerators: they are given after '\t' + // For compatibility with the old wx versions which accepted (and actually + // even required) a TAB character in the string passed to this function we + // ignore anything up to the first TAB. Notice however that the correct + // input consists of just the accelerator itself and nothing else, this is + // done for compatibility and compatibility only. int posTab = label.Find(wxT('\t')); if ( posTab == wxNOT_FOUND ) posTab = 0; @@ -274,9 +278,18 @@ wxAcceleratorEntry::ParseAccel(const wxString& text, int *flagsOut, int *keyOut) /* static */ wxAcceleratorEntry *wxAcceleratorEntry::Create(const wxString& str) { + const wxString accelStr = str.AfterFirst('\t'); + if ( accelStr.empty() ) + { + // It's ok to pass strings not containing any accelerators at all to + // this function, wxMenuItem code does it and we should just return + // NULL in this case. + return NULL; + } + int flags, keyCode; - if ( !ParseAccel(str, &flags, &keyCode) ) + if ( !ParseAccel(accelStr, &flags, &keyCode) ) return NULL; return new wxAcceleratorEntry(flags, keyCode); @@ -294,7 +307,7 @@ wxString wxAcceleratorEntry::ToString() const int flags = GetFlags(); if ( flags & wxACCEL_ALT ) text += _("Alt+"); - if ( flags & wxACCEL_CTRL ) + if ( flags & (wxACCEL_CTRL | wxACCEL_CMD) ) text += _("Ctrl+"); if ( flags & wxACCEL_SHIFT ) text += _("Shift+");