]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't post process events twice but return correct value from ProcessEvent().
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 6 Jun 2010 12:41:51 +0000 (12:41 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 6 Jun 2010 12:41:51 +0000 (12:41 +0000)
This is a further complication to the event handling code which aims to handle
correctly the case of wxScrollHelperEvtHandler which doesn't respect the
request to process events only in it but always passes it to the next handler
in the chain itself while still returning the correct value from
ProcessEvent() itself to avoid breaking code that relies on it, like the
background painting code in wxHtmlWindow.

This replaces the change of r64495 and does return true from DoTryChain() in
wxScrollHelperEvtHandler case but sets the "skipped" flag in the event itself
to indicate that it wasn't really processed and ProcessEvent() now checks it
after calling ProcessEventLocally() and returns the correct value
appropriately.

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

src/common/event.cpp

index 1cc349614dbc51bc3b2ce94a687eed17377ccd32..18972841f982b0532ca2a1567981660a1ad5d7d6 100644 (file)
@@ -1385,7 +1385,15 @@ bool wxEvtHandler::ProcessEvent(wxEvent& event)
 
     // Try to process the event in this handler itself.
     if ( ProcessEventLocally(event) )
-        return true;
+    {
+        // It is possible that DoTryChain() called from ProcessEventLocally()
+        // returned true but the event was not really processed: this happens
+        // if a custom handler ignores the request to process the event in this
+        // handler only and in this case we should skip the post processing
+        // done in TryAfter() but still return the correct value ourselves to
+        // indicate whether we did or did not find a handler for this event.
+        return !event.GetSkipped();
+    }
 
     // If we still didn't find a handler, propagate the event upwards the
     // window chain and/or to the application object.
@@ -1448,10 +1456,24 @@ bool wxEvtHandler::DoTryChain(wxEvent& event)
         // done by that rogue event handler.
         wxEventProcessInHandlerOnly processInHandlerOnly(event, h);
         if ( h->ProcessEvent(event) )
+        {
+            // Make sure "skipped" flag is not set as the event was really
+            // processed in this case. Normally it shouldn't be set anyhow but
+            // make sure just in case the user code does something strange.
+            event.Skip(false);
+
             return true;
+        }
 
         if ( !event.ShouldProcessOnlyIn(h) )
-            break;
+        {
+            // Still return true to indicate that no further processing should
+            // be undertaken but ensure that "skipped" flag is set so that the
+            // caller knows that the event was not really processed.
+            event.Skip();
+
+            return true;
+        }
     }
 
     return false;