]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't pass strings not containing accelerators to ParseAccel().
authorVadim Zeitlin <vadim@wxwidgets.org>
Wed, 15 Dec 2010 11:18:42 +0000 (11:18 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Wed, 15 Dec 2010 11:18:42 +0000 (11:18 +0000)
Check for the presence of accelerator part in the string passed to
wxAcceleratorEntry::Create() and don't call ParseAccel() at all if it's not
there. This avoids the spurious warnings about unrecognized accelerators when
creating menu items that don't have any accelerators at all.

Also update wxAcceleratorEntry::FromString() documentation to mention that
the new code should pass just the accelerator to this function and that it
only accepts full menu item labels for compatibility.

Closes #12770.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66379 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

interface/wx/accel.h
src/common/accelcmn.cpp

index e60430af7611a6d7f04644448727623d781213ae..974731fab6e55c314bdcf5d5aeaf6f4359de923f 100644 (file)
@@ -119,7 +119,10 @@ public:
             ToString(), i.e. contain the accelerator itself only, or have the
             format of a full menu item text with i.e. <code>Label TAB
             Accelerator</code>. In the latter case, the part of the string
-            before the TAB is ignored.
+            before the TAB is ignored. Notice that the latter format is only
+            supported for the compatibility with the previous wxWidgets
+            versions and the new code should pass only the accelerator string
+            itself to this function.
 
         @return @true if the given string correctly initialized this object
                 (i.e. if IsOk() returns true after this call)
index 718275e160520564ffbdb7ca9330b28f5c4ead28..5df35dc39f3122043117d111d12298c48bb12b3a 100644 (file)
@@ -158,11 +158,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 +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);