diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 1f9f8b37c0..e511f8db65 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -2581,6 +2581,34 @@ wxBEGIN_EVENT_TABLE(TestDefaultActionDialog, wxDialog) EVT_TEXT_ENTER(wxID_ANY, TestDefaultActionDialog::OnTextEnter) wxEND_EVENT_TABLE() +// TODO-C++11: We can't declare this class inside TestDefaultActionDialog +// itself when using C++98, so we have to do it here instead. +namespace +{ + +// We have to define a new class in order to actually handle pressing +// Enter, if we didn't do it, pressing it would still close the dialog. +class EnterHandlingTextCtrl : public wxTextCtrl +{ +public: + EnterHandlingTextCtrl(wxWindow* parent, int id, const wxString& value) + : wxTextCtrl(parent, id, value, + wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER) + { + Bind(wxEVT_TEXT_ENTER, &EnterHandlingTextCtrl::OnEnter, this); + + SetInitialSize(GetSizeFromTextSize(GetTextExtent(value).x)); + } + +private: + void OnEnter(wxCommandEvent& WXUNUSED(event)) + { + wxLogMessage("Enter pressed"); + } +}; + +} // anonymous namespace + TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) : wxDialog( parent, -1, "Test default action" ) { @@ -2603,12 +2631,12 @@ TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) : grid_sizer->Add(new wxCheckBox(this, ID_CATCH_LISTBOX_DCLICK, "Catch DoubleClick from wxListBox"), wxSizerFlags().CentreVertical()); - grid_sizer->Add(new wxTextCtrl(this, wxID_ANY, ""), - wxSizerFlags().CentreVertical()); + grid_sizer->Add(new wxTextCtrl(this, wxID_ANY, "Enter here closes the dialog"), + wxSizerFlags().Expand().CentreVertical()); grid_sizer->Add(new wxStaticText(this, wxID_ANY, "wxTextCtrl without wxTE_PROCESS_ENTER"), wxSizerFlags().CentreVertical()); - grid_sizer->Add(new wxTextCtrl(this, wxID_ANY, "", wxDefaultPosition, wxDefaultSize, wxTE_PROCESS_ENTER), + grid_sizer->Add(new EnterHandlingTextCtrl(this, wxID_ANY, "Enter here is handled by the application"), wxSizerFlags().CentreVertical()); grid_sizer->Add(new wxStaticText(this, wxID_ANY, "wxTextCtrl with wxTE_PROCESS_ENTER"), wxSizerFlags().CentreVertical());