Fix "Enter" behaviour when wxEVT_TEXT_ENTER is skipped in wxGTK
Bring wxGTK in sync with wxMSW and wxMac by activating the default button manually if wxEVT_TEXT_ENTER handler skips the event.
This commit is contained in:
@@ -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
|
||||
|
@@ -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;
|
||||
}
|
||||
|
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -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
|
||||
|
Reference in New Issue
Block a user