X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/514b0e137e34529eb845ac26aa269f720cfa123c..b54a0e3913d919ed1ed2b51acb0ebbe5e4c0bb11:/src/gtk/window.cpp diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 01c966f2c4..9e62caac35 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -830,34 +830,22 @@ struct wxGtkIMData namespace { -// Send wxEVT_CHAR_HOOK event to the parent of the window and if it wasn't -// processed, send wxEVT_CHAR to the window itself. Return true if either of -// them was handled. -bool -SendCharHookAndCharEvents(const wxKeyEvent& event, wxWindow *win) +// Send wxEVT_CHAR_HOOK event to the parent of the window and return true only +// if it was processed (and not skipped). +bool SendCharHookEvent(const wxKeyEvent& event, wxWindow *win) { - // wxEVT_CHAR_HOOK must be sent to the top level parent window to allow it + // wxEVT_CHAR_HOOK must be sent to allow the parent windows (e.g. a dialog + // which typically closes when Esc key is pressed in any of its controls) // 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; - } + wxKeyEvent eventCharHook(wxEVT_CHAR_HOOK, event); + if ( win->HandleWindowEvent(eventCharHook) ) + return true; } - // As above, make a copy of the event first. - wxKeyEvent eventChar(event); - eventChar.SetEventType(wxEVT_CHAR); - return win->HandleWindowEvent(eventChar); + return false; } } // anonymous namespace @@ -879,6 +867,13 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget), if( wxTranslateGTKKeyEventToWx(event, win, gdk_event) ) { + // Send the CHAR_HOOK event first + if ( SendCharHookEvent(event, win) ) + { + // Don't do anything at all with this event any more. + return TRUE; + } + // Emit KEY_DOWN event ret = win->HandleWindowEvent( event ); } @@ -962,25 +957,27 @@ gtk_window_key_press_callback( GtkWidget *WXUNUSED(widget), if ( key_code ) { + wxKeyEvent eventChar(wxEVT_CHAR, event); + wxLogTrace(TRACE_KEYS, wxT("Char event: %ld"), key_code); - event.m_keyCode = key_code; + eventChar.m_keyCode = key_code; // To conform to the docs we need to translate Ctrl-alpha // characters to values in the range 1-26. - if ( event.ControlDown() && + if ( eventChar.ControlDown() && ( wxIsLowerChar(key_code) || wxIsUpperChar(key_code) )) { if ( wxIsLowerChar(key_code) ) - event.m_keyCode = key_code - 'a' + 1; + eventChar.m_keyCode = key_code - 'a' + 1; if ( wxIsUpperChar(key_code) ) - event.m_keyCode = key_code - 'A' + 1; + eventChar.m_keyCode = key_code - 'A' + 1; #if wxUSE_UNICODE - event.m_uniChar = event.m_keyCode; + eventChar.m_uniChar = event.m_keyCode; #endif } - ret = SendCharHookAndCharEvents(event, win); + ret = win->HandleWindowEvent(eventChar); } } @@ -994,7 +991,7 @@ gtk_wxwindow_commit_cb (GtkIMContext * WXUNUSED(context), const gchar *str, wxWindow *window) { - wxKeyEvent event( wxEVT_KEY_DOWN ); + wxKeyEvent event( wxEVT_CHAR ); // take modifiers, cursor position, timestamp etc. from the last // key_press_event that was fed into Input Method: @@ -1039,7 +1036,7 @@ gtk_wxwindow_commit_cb (GtkIMContext * WXUNUSED(context), #endif } - SendCharHookAndCharEvents(event, window); + window->HandleWindowEvent(event); } } }