]> git.saurik.com Git - wxWidgets.git/commitdiff
Don't generate wxEVT_CHAR_HOOK events while the mouse is captured.
authorVadim Zeitlin <vadim@wxwidgets.org>
Mon, 14 Mar 2011 11:55:01 +0000 (11:55 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Mon, 14 Mar 2011 11:55:01 +0000 (11:55 +0000)
This prevents the parent TLW from interfering with the keyboard handling of
the window that captured the mouse which very often needs Escape for itself to
cancel the capture.

In particular, this fixes the problems with Escape closing the entire dialog
containing the controls instead of closing just the combobox drop down or a
popup menu in wxMSW.

Also modify wxGTK for consistency and update the documentation.

Closes #12952.

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

docs/changes.txt
interface/wx/event.h
src/gtk/window.cpp
src/msw/window.cpp

index 91e69c97c0755243783df8f920619d97d5ae8095..407b501d3b8d0e7ddeed73c243922b81bd921824 100644 (file)
@@ -195,6 +195,10 @@ Changes in behaviour not resulting in compilation errors, please read this!
   release so you are strongly encouraged to upgrade your code to stop relying
   on this behaviour.
 
   release so you are strongly encouraged to upgrade your code to stop relying
   on this behaviour.
 
+- wxEVT_CHAR_HOOK events are not generated any more if the mouse is captured to
+  prevent the parent wxTopLevelWindow from interfering with the keyboard
+  handling of the window that captured the mouse.
+
 
 Changes in behaviour which may result in compilation errors
 -----------------------------------------------------------
 
 Changes in behaviour which may result in compilation errors
 -----------------------------------------------------------
index 863ee56c239fec34ac919ba251469742095878f7..3a8043001bea4670e6d7db9f3a8f901f696f5d48 100644 (file)
@@ -1310,8 +1310,11 @@ enum wxKeyCategoryFlags
         keyboard events are generated giving the parent window the opportunity
         to intercept all the keyboard entry. If the event is handled, i.e. the
         handler doesn't call wxEvent::Skip(), no further keyboard events are
         keyboard events are generated giving the parent window the opportunity
         to intercept all the keyboard entry. If the event is handled, i.e. the
         handler doesn't call wxEvent::Skip(), no further keyboard events are
-        generated. Notice that this event is currently not generated by
-        wxOSX/Cocoa port.
+        generated. Notice that this event is not generated when the mouse is
+        captured as it is considered that the window which has the capture
+        should receive all the keyboard events too without allowing its parent
+        wxTopLevelWindow to interfere with their processing. Also please note
+        that currently this event is not generated by wxOSX/Cocoa port.
     @endEventTable
 
     @see wxKeyboardState
     @endEventTable
 
     @see wxKeyboardState
index 3c32e7dfa62307e9b07f86d03f536d7e152f9e11..0c05229765a7edbdc1f6dccff3aaaca4c3938e83 100644 (file)
@@ -884,17 +884,21 @@ bool
 SendCharHookAndCharEvents(const wxKeyEvent& event, wxWindow *win)
 {
     // wxEVT_CHAR_HOOK must be sent to the top level parent window to allow it
 SendCharHookAndCharEvents(const wxKeyEvent& event, wxWindow *win)
 {
     // wxEVT_CHAR_HOOK must be sent to the top level parent window to allow it
-    // to handle key events in all of its children.
-    wxWindow * const parent = wxGetTopLevelParent(win);
-    if ( parent )
-    {
-        // We need to make a copy of the event object because it is
-        // modified while it's handled, notably its WasProcessed() flag
-        // is set after it had been processed once.
-        wxKeyEvent eventCharHook(event);
-        eventCharHook.SetEventType(wxEVT_CHAR_HOOK);
-        if ( parent->HandleWindowEvent(eventCharHook) )
-            return true;
+    // to handle key events in all of its children unless the mouse is captured
+    // in which case we consider that the keyboard should be "captured" too.
+    if ( !g_captureWindow )
+    {
+        wxWindow * const parent = wxGetTopLevelParent(win);
+        if ( parent )
+        {
+            // We need to make a copy of the event object because it is
+            // modified while it's handled, notably its WasProcessed() flag
+            // is set after it had been processed once.
+            wxKeyEvent eventCharHook(event);
+            eventCharHook.SetEventType(wxEVT_CHAR_HOOK);
+            if ( parent->HandleWindowEvent(eventCharHook) )
+                return true;
+        }
     }
 
     // As above, make a copy of the event first.
     }
 
     // As above, make a copy of the event first.
index e1d2af0ad754e2c1cdf682b5a85e3371632d4c2e..a310475417b7de62d15bbcd49d0a80f2230287d8 100644 (file)
@@ -6521,7 +6521,13 @@ wxKeyboardHook(int nCode, WORD wParam, DWORD lParam)
         // Don't intercept keyboard entry (notably Escape) if a modal window
         // (not managed by wx, e.g. IME one) is currently opened as more often
         // than not it needs all the keys for itself.
         // Don't intercept keyboard entry (notably Escape) if a modal window
         // (not managed by wx, e.g. IME one) is currently opened as more often
         // than not it needs all the keys for itself.
-        if ( !gs_modalEntryWindowCount )
+        //
+        // Also don't catch it if a window currently captures the mouse as
+        // Escape is normally used to release the mouse capture and if you
+        // really need to catch all the keys in the window that has mouse
+        // capture it can be easily done in its own EVT_CHAR handler as it is
+        // certain to have focus while it has the capture.
+        if ( !gs_modalEntryWindowCount && !::GetCapture() )
         {
             if ( id != WXK_NONE
 #if wxUSE_UNICODE
         {
             if ( id != WXK_NONE
 #if wxUSE_UNICODE