Actually make wxTE_PROCESS_ENTER example in dialogs sample work

This didn't work any more since the changes done in the branch merged by
fb2c17c193 as using wxTE_PROCESS_ENTER
without actually handling the resulting event doesn't prevent Enter from
activating the default button any longer.
This commit is contained in:
Vadim Zeitlin 2019-09-06 17:44:56 +02:00
parent 5f635db3bf
commit ba2ea837de

View File

@ -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());