From: Robert Roebling Date: Tue, 19 Feb 2002 21:48:03 +0000 (+0000) Subject: Added test for default action (button normally) X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/2b328fc942acc9bdab7588c7b33eaaa945ec539d Added test for default action (button normally) to combo box when hittinh return. In a normal Find&Replace dialog, hitting enter in one of the two fields will usually mean "OK". Corrected the same test in wxTextCtrl. Removed some debug code. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@14311 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/src/gtk/combobox.cpp b/src/gtk/combobox.cpp index 326381bcb4..de35777f0b 100644 --- a/src/gtk/combobox.cpp +++ b/src/gtk/combobox.cpp @@ -615,7 +615,26 @@ void wxComboBox::OnChar( wxKeyEvent &event ) event.SetEventObject( this ); GetEventHandler()->ProcessEvent( event ); } - //else: do nothing, this will open the listbox + else + { + // 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; + } + } + } } } diff --git a/src/gtk/textctrl.cpp b/src/gtk/textctrl.cpp index 6c37c6636a..48cb8c1e77 100644 --- a/src/gtk/textctrl.cpp +++ b/src/gtk/textctrl.cpp @@ -964,15 +964,22 @@ void wxTextCtrl::OnChar( wxKeyEvent &key_event ) if ((key_event.KeyCode() == WXK_RETURN) && !(m_windowStyle & wxTE_MULTILINE)) { + // 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(); - GtkWindow *window = GTK_WINDOW(top_frame->m_widget); - - if (window->default_widget) + + if (top_frame && GTK_IS_WINDOW(top_frame->m_widget)) { - gtk_widget_activate (window->default_widget); - return; + GtkWindow *window = GTK_WINDOW(top_frame->m_widget); + + if (window->default_widget) + { + gtk_widget_activate (window->default_widget); + return; + } } } diff --git a/src/gtk/window.cpp b/src/gtk/window.cpp index 30fae11783..b2941feb0a 100644 --- a/src/gtk/window.cpp +++ b/src/gtk/window.cpp @@ -1640,7 +1640,7 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, g_focusWindowLast = g_focusWindow = win; -#if 1 +#if 0 wxPrintf( "OnSetFocus from " ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) wxPrintf( win->GetClassInfo()->GetClassName() ); diff --git a/src/gtk1/combobox.cpp b/src/gtk1/combobox.cpp index 326381bcb4..de35777f0b 100644 --- a/src/gtk1/combobox.cpp +++ b/src/gtk1/combobox.cpp @@ -615,7 +615,26 @@ void wxComboBox::OnChar( wxKeyEvent &event ) event.SetEventObject( this ); GetEventHandler()->ProcessEvent( event ); } - //else: do nothing, this will open the listbox + else + { + // 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; + } + } + } } } diff --git a/src/gtk1/textctrl.cpp b/src/gtk1/textctrl.cpp index 6c37c6636a..48cb8c1e77 100644 --- a/src/gtk1/textctrl.cpp +++ b/src/gtk1/textctrl.cpp @@ -964,15 +964,22 @@ void wxTextCtrl::OnChar( wxKeyEvent &key_event ) if ((key_event.KeyCode() == WXK_RETURN) && !(m_windowStyle & wxTE_MULTILINE)) { + // 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(); - GtkWindow *window = GTK_WINDOW(top_frame->m_widget); - - if (window->default_widget) + + if (top_frame && GTK_IS_WINDOW(top_frame->m_widget)) { - gtk_widget_activate (window->default_widget); - return; + GtkWindow *window = GTK_WINDOW(top_frame->m_widget); + + if (window->default_widget) + { + gtk_widget_activate (window->default_widget); + return; + } } } diff --git a/src/gtk1/window.cpp b/src/gtk1/window.cpp index 30fae11783..b2941feb0a 100644 --- a/src/gtk1/window.cpp +++ b/src/gtk1/window.cpp @@ -1640,7 +1640,7 @@ static gint gtk_window_focus_in_callback( GtkWidget *widget, g_focusWindowLast = g_focusWindow = win; -#if 1 +#if 0 wxPrintf( "OnSetFocus from " ); if (win->GetClassInfo() && win->GetClassInfo()->GetClassName()) wxPrintf( win->GetClassInfo()->GetClassName() );