From: Vadim Zeitlin Date: Sun, 4 Nov 2007 16:34:36 +0000 (+0000) Subject: use gtk_entry_set_activates_default() instead of redoing its work manually ourselves X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/ff805cac748d91edbf55d82a7f1b567d5d4d3cc0 use gtk_entry_set_activates_default() instead of redoing its work manually ourselves git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@49625 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/gtk/textctrl.h b/include/wx/gtk/textctrl.h index 57d52e3b80..28554b1f96 100644 --- a/include/wx/gtk/textctrl.h +++ b/include/wx/gtk/textctrl.h @@ -176,6 +176,7 @@ protected: // set the given characteristic) void GTKSetEditable(); void GTKSetVisibility(); + void GTKSetActivatesDefault(); void GTKSetWrapMode(); void GTKSetJustification(); diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index a1bdfc5414..b44668c172 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -747,6 +747,9 @@ bool wxTextCtrl::Create( wxWindow *parent, if (style & wxTE_READONLY) GTKSetEditable(); + if (style & wxTE_PROCESS_ENTER) + GTKSetActivatesDefault(); + // left justification (alignment) is the default anyhow if ( style & (wxTE_RIGHT | wxTE_CENTRE) ) GTKSetJustification(); @@ -824,9 +827,19 @@ void wxTextCtrl::GTKSetEditable() void wxTextCtrl::GTKSetVisibility() { - // VZ: shouldn't we assert if wxTE_PASSWORD is set for multiline control? - if ( IsSingleLine() ) - gtk_entry_set_visibility(GTK_ENTRY(m_text), !HasFlag(wxTE_PASSWORD)); + wxCHECK_RET( IsSingleLine(), + "wxTE_PASSWORD is for single line text controls only" ); + + gtk_entry_set_visibility(GTK_ENTRY(m_text), !HasFlag(wxTE_PASSWORD)); +} + +void wxTextCtrl::GTKSetActivatesDefault() +{ + wxCHECK_RET( IsSingleLine(), + "wxTE_PROCESS_ENTER is for single line text controls only" ); + + gtk_entry_set_activates_default(GTK_ENTRY(m_text), + !HasFlag(wxTE_PROCESS_ENTER)); } void wxTextCtrl::GTKSetWrapMode() @@ -906,6 +919,9 @@ void wxTextCtrl::SetWindowStyleFlag(long style) if ( (style & wxTE_PASSWORD) != (styleOld & wxTE_PASSWORD) ) GTKSetVisibility(); + if ( (style & wxTE_PROCESS_ENTER) != (styleOld & wxTE_PROCESS_ENTER) ) + GTKSetActivatesDefault(); + static const long flagsWrap = wxTE_WORDWRAP | wxTE_CHARWRAP | wxTE_DONTWRAP; if ( (style & flagsWrap) != (styleOld & flagsWrap) ) GTKSetWrapMode(); @@ -1537,29 +1553,6 @@ void wxTextCtrl::OnChar( wxKeyEvent &key_event ) if ( GetEventHandler()->ProcessEvent(event) ) return; } - - // FIXME: this is not the right place to do it, wxDialog::OnCharHook() - // probably is - if ( IsSingleLine() ) - { - // This will invoke the dialog default action, such - // as the clicking the default button. - - wxWindow *top_frame = m_parent; - while (top_frame->GetParent() && !(top_frame->IsTopLevel())) - top_frame = top_frame->GetParent(); - - if (top_frame && GTK_IS_WINDOW(top_frame->m_widget)) - { - GtkWindow *window = GTK_WINDOW(top_frame->m_widget); - - if (window->default_widget) - { - gtk_widget_activate (window->default_widget); - return; - } - } - } } key_event.Skip();