Remove event table from static page in the widgets sample

The code was confusing as it used Bind() for some handlers, event table
for some others and, for the 3 buttons in the middle column, it actually
managed to use both.

Get rid of the event table completely to make this more clear.
This commit is contained in:
Vadim Zeitlin
2019-06-19 19:49:43 +02:00
parent 672847772d
commit 8fcedbed7b

View File

@@ -49,15 +49,6 @@
// constants // constants
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// control ids
enum
{
StaticPage_Reset = wxID_HIGHEST,
StaticPage_BoxText,
StaticPage_LabelText,
StaticPage_LabelTextWithMarkup
};
// alignment radiobox values // alignment radiobox values
enum enum
{ {
@@ -114,7 +105,7 @@ public:
protected: protected:
// event handlers // event handlers
void OnCheckOrRadioBox(wxCommandEvent& event); void OnCheckEllipsize(wxCommandEvent& event);
#ifdef wxHAS_WINDOW_LABEL_IN_STATIC_BOX #ifdef wxHAS_WINDOW_LABEL_IN_STATIC_BOX
void OnBoxCheckBox(wxCommandEvent& event); void OnBoxCheckBox(wxCommandEvent& event);
#endif // wxHAS_WINDOW_LABEL_IN_STATIC_BOX #endif // wxHAS_WINDOW_LABEL_IN_STATIC_BOX
@@ -176,26 +167,9 @@ protected:
#endif // wxUSE_MARKUP #endif // wxUSE_MARKUP
private: private:
wxDECLARE_EVENT_TABLE();
DECLARE_WIDGETS_PAGE(StaticWidgetsPage) DECLARE_WIDGETS_PAGE(StaticWidgetsPage)
}; };
// ----------------------------------------------------------------------------
// event tables
// ----------------------------------------------------------------------------
wxBEGIN_EVENT_TABLE(StaticWidgetsPage, WidgetsPage)
EVT_BUTTON(StaticPage_Reset, StaticWidgetsPage::OnButtonReset)
EVT_BUTTON(StaticPage_LabelText, StaticWidgetsPage::OnButtonLabelText)
#if wxUSE_MARKUP
EVT_BUTTON(StaticPage_LabelTextWithMarkup, StaticWidgetsPage::OnButtonLabelWithMarkupText)
#endif // wxUSE_MARKUP
EVT_BUTTON(StaticPage_BoxText, StaticWidgetsPage::OnButtonBoxText)
EVT_CHECKBOX(wxID_ANY, StaticWidgetsPage::OnCheckOrRadioBox)
EVT_RADIOBOX(wxID_ANY, StaticWidgetsPage::OnCheckOrRadioBox)
wxEND_EVENT_TABLE()
// ============================================================================ // ============================================================================
// implementation // implementation
// ============================================================================ // ============================================================================
@@ -286,6 +260,8 @@ void StaticWidgetsPage::CreateContent()
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
m_chkEllipsize = CreateCheckBoxAndAddToSizer(sizerLeft, "&Ellipsize"); m_chkEllipsize = CreateCheckBoxAndAddToSizer(sizerLeft, "&Ellipsize");
m_chkEllipsize->Bind(wxEVT_CHECKBOX,
&StaticWidgetsPage::OnCheckEllipsize, this);
static const wxString ellipsizeMode[] = static const wxString ellipsizeMode[] =
{ {
@@ -301,8 +277,9 @@ void StaticWidgetsPage::CreateContent()
sizerLeft->Add(m_radioEllipsize, 0, wxGROW | wxALL, 5); sizerLeft->Add(m_radioEllipsize, 0, wxGROW | wxALL, 5);
wxButton *btn = new wxButton(this, StaticPage_Reset, "&Reset"); wxButton *b0 = new wxButton(this, wxID_ANY, "&Reset");
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15); b0->Bind(wxEVT_BUTTON, &StaticWidgetsPage::OnButtonReset, this);
sizerLeft->Add(b0, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
// middle pane // middle pane
wxSizer *sizerMiddle = new wxStaticBoxSizer(wxVERTICAL, this, wxSizer *sizerMiddle = new wxStaticBoxSizer(wxVERTICAL, this,
@@ -573,12 +550,9 @@ void StaticWidgetsPage::OnButtonReset(wxCommandEvent& WXUNUSED(event))
CreateStatic(); CreateStatic();
} }
void StaticWidgetsPage::OnCheckOrRadioBox(wxCommandEvent& event) void StaticWidgetsPage::OnCheckEllipsize(wxCommandEvent& event)
{ {
if (event.GetEventObject() == static_cast<wxObject*>(m_chkEllipsize))
{
m_radioEllipsize->Enable(event.IsChecked()); m_radioEllipsize->Enable(event.IsChecked());
}
CreateStatic(); CreateStatic();
} }