diff --git a/include/wx/gtk/textentry.h b/include/wx/gtk/textentry.h index aaf777a515..3410ec3924 100644 --- a/include/wx/gtk/textentry.h +++ b/include/wx/gtk/textentry.h @@ -86,6 +86,10 @@ protected: static int GTKGetEntryTextLength(GtkEntry* entry); + // Helper for wxTE_PROCESS_ENTER handling: activates the default button in + // the dialog containing this control if any. + bool ClickDefaultButtonIfPossible(); + private: // implement this to return the associated GtkEntry or another widget // implementing GtkEditable diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 578088c0fd..aa533ec34a 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -241,6 +241,12 @@ void wxComboBox::OnChar( wxKeyEvent &event ) // down list upon RETURN. return; } + + // We disable built-in default button activation when + // wxTE_PROCESS_ENTER is used, but we still should activate it + // if the event wasn't handled, so do it from here. + if ( ClickDefaultButtonIfPossible() ) + return; } break; } diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 54af9c1def..13fa13196c 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -1693,6 +1693,12 @@ void wxTextCtrl::OnChar( wxKeyEvent &key_event ) event.SetString(GetValue()); if ( HandleWindowEvent(event) ) return; + + // We disable built-in default button activation when + // wxTE_PROCESS_ENTER is used, but we still should activate it + // if the event wasn't handled, so do it from here. + if ( ClickDefaultButtonIfPossible() ) + return; } } diff --git a/src/gtk/textentry.cpp b/src/gtk/textentry.cpp index 598d7593a0..eb6e91c0eb 100644 --- a/src/gtk/textentry.cpp +++ b/src/gtk/textentry.cpp @@ -986,4 +986,35 @@ wxString wxTextEntry::GetHint() const } #endif // __WXGTK3__ +bool wxTextEntry::ClickDefaultButtonIfPossible() +{ + GtkWidget* const widget = GTK_WIDGET(GetEntry()); + + // This does the same thing as gtk_entry_real_activate() in GTK itself. + // + // Note: in GTK 4 we should probably just use gtk_widget_activate_default(). + GtkWidget* const toplevel = gtk_widget_get_toplevel(widget); + if ( GTK_IS_WINDOW (toplevel) ) + { + GtkWindow* const window = GTK_WINDOW(toplevel); + + if ( window ) + { + GtkWidget* const default_widget = gtk_window_get_default_widget(window); + GtkWidget* const focus_widget = gtk_window_get_focus(window); + + if ( widget != default_widget && + !(widget == focus_widget && + (!default_widget || + !gtk_widget_get_sensitive(default_widget))) ) + { + if ( gtk_window_activate_default(window) ) + return true; + } + } + } + + return false; +} + #endif // wxUSE_TEXTCTRL || wxUSE_COMBOBOX