X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/7a0079d5a4d1fe6e80cc978d84648fa7bf6fde4a..424da8bdb9f05243d8888d78a56ab0cc3f615a6c:/src/common/accelcmn.cpp diff --git a/src/common/accelcmn.cpp b/src/common/accelcmn.cpp index ee99542df2..5df35dc39f 100644 --- a/src/common/accelcmn.cpp +++ b/src/common/accelcmn.cpp @@ -158,19 +158,23 @@ 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); - // 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 ) - { - return false; - } + posTab = 0; + else + posTab++; // parse the accelerator string int accelFlags = wxACCEL_NORMAL; wxString current; - for ( size_t n = (size_t)posTab + 1; n < label.length(); n++ ) + for ( size_t n = (size_t)posTab; n < label.length(); n++ ) { if ( (label[n] == '+') || (label[n] == '-') ) { @@ -272,9 +276,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); @@ -291,11 +304,11 @@ wxString wxAcceleratorEntry::ToString() const int flags = GetFlags(); if ( flags & wxACCEL_ALT ) - text += _("Alt-"); + text += _("Alt+"); if ( flags & wxACCEL_CTRL ) - text += _("Ctrl-"); + text += _("Ctrl+"); if ( flags & wxACCEL_SHIFT ) - text += _("Shift-"); + text += _("Shift+"); const int code = GetKeyCode();