Remove EnterHandlingTextCtrl class from the dialogs sample

This code was simplified by 16473d9b19 (Make class used as template
parameter local now that we can, 2022-11-11) but we can simplify it even
more by just getting rid of this class completely and using a small
lambda as the event handler.

No real changes.
This commit is contained in:
Vadim Zeitlin 2022-11-11 13:58:18 +01:00
parent 0f6c54cdb6
commit 699042a272

View file

@ -3089,28 +3089,20 @@ TestDefaultActionDialog::TestDefaultActionDialog( wxWindow *parent ) :
grid_sizer->Add(new wxStaticText(this, wxID_ANY, "wxTextCtrl without wxTE_PROCESS_ENTER"),
wxSizerFlags().CentreVertical());
// 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))
wxTextCtrl* textHandlingEnter =
new wxTextCtrl(this, wxID_ANY, "Enter here is handled by the application",
wxDefaultPosition,
wxSize(50*GetCharWidth(), -1), // big enough
wxTE_PROCESS_ENTER);
textHandlingEnter->Bind(wxEVT_TEXT_ENTER,
[](wxCommandEvent& WXUNUSED(event))
{
wxLogMessage("Enter pressed");
}
};
grid_sizer->Add(new EnterHandlingTextCtrl(this, wxID_ANY, "Enter here is handled by the application"),
// Don't skip the event here, otherwise the dialog would close.
}
);
grid_sizer->Add(textHandlingEnter,
wxSizerFlags().CentreVertical());
grid_sizer->Add(new wxStaticText(this, wxID_ANY, "wxTextCtrl with wxTE_PROCESS_ENTER"),
wxSizerFlags().CentreVertical());