]> git.saurik.com Git - wxWidgets.git/commitdiff
prevent unhandled key events from propagating up parent chain
authorPaul Cornett <paulcor@bullseye.com>
Thu, 12 Jan 2012 18:06:07 +0000 (18:06 +0000)
committerPaul Cornett <paulcor@bullseye.com>
Thu, 12 Jan 2012 18:06:07 +0000 (18:06 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@70324 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/gtk/window.cpp

index 1a3f1065b08be29f2cee5a115802df9c3d02d80b..9d99c4b6b7a042b4b78661170d910b4672eb21ea 100644 (file)
@@ -1068,6 +1068,20 @@ gtk_window_key_release_callback( GtkWidget * WXUNUSED(widget),
 }
 }
 
+//-----------------------------------------------------------------------------
+// "key_press_event"/"key_release_event", after, from m_widget
+//-----------------------------------------------------------------------------
+
+extern "C" {
+static gboolean key_event_after(GtkWidget* widget, GdkEventKey*, wxWindow*)
+{
+    // If a widget does not handle a key event, GTK+ sends it up the parent
+    // chain until it is handled. Key events are not supposed to propagate in
+    // wxWidgets, so prevent it unless widget is in a native container.
+    return WX_IS_PIZZA(gtk_widget_get_parent(widget));
+}
+}
+
 // ============================================================================
 // the mouse events
 // ============================================================================
@@ -2357,6 +2371,10 @@ void wxWindowGTK::PostCreation()
 
     ConnectWidget( connect_widget );
 
+    // connect handler to prevent key events from propagating up parent chain
+    g_signal_connect_after(m_widget, "key_press_event", G_CALLBACK(key_event_after), this);
+    g_signal_connect_after(m_widget, "key_release_event", G_CALLBACK(key_event_after), this);
+
     // We cannot set colours, fonts and cursors before the widget has been
     // realized, so we do this directly after realization -- unless the widget
     // was in fact realized already.