Update radio page in widgets sample
Make the reset button work by binding to OnUpdateUIReset. Use wxSizerFlags based API. Remove minimum size of right panel so the minimum size of wxRadioBox can be verified. Use wxArrayString instead of manually creating and deleting an array of wxString pointers. Reapply disabling and hiding the test button, and check if test button is available. Layout the entire page instead of only the sizer, see #18100.
This commit is contained in:
@@ -146,6 +146,7 @@ wxBEGIN_EVENT_TABLE(RadioWidgetsPage, WidgetsPage)
|
|||||||
EVT_BUTTON(RadioPage_Selection, RadioWidgetsPage::OnButtonSelection)
|
EVT_BUTTON(RadioPage_Selection, RadioWidgetsPage::OnButtonSelection)
|
||||||
EVT_BUTTON(RadioPage_Label, RadioWidgetsPage::OnButtonSetLabel)
|
EVT_BUTTON(RadioPage_Label, RadioWidgetsPage::OnButtonSetLabel)
|
||||||
|
|
||||||
|
EVT_UPDATE_UI(RadioPage_Reset, RadioWidgetsPage::OnUpdateUIReset)
|
||||||
EVT_UPDATE_UI(RadioPage_Update, RadioWidgetsPage::OnUpdateUIUpdate)
|
EVT_UPDATE_UI(RadioPage_Update, RadioWidgetsPage::OnUpdateUIUpdate)
|
||||||
EVT_UPDATE_UI(RadioPage_Selection, RadioWidgetsPage::OnUpdateUISelection)
|
EVT_UPDATE_UI(RadioPage_Selection, RadioWidgetsPage::OnUpdateUISelection)
|
||||||
|
|
||||||
@@ -211,21 +212,21 @@ void RadioWidgetsPage::CreateContent()
|
|||||||
sizerRow = CreateSizerWithTextAndLabel("&Major dimension:",
|
sizerRow = CreateSizerWithTextAndLabel("&Major dimension:",
|
||||||
wxID_ANY,
|
wxID_ANY,
|
||||||
&m_textMajorDim);
|
&m_textMajorDim);
|
||||||
sizerLeft->Add(sizerRow, 0, wxGROW | wxALL, 5);
|
sizerLeft->Add(sizerRow, wxSizerFlags().Expand().Border());
|
||||||
|
|
||||||
sizerRow = CreateSizerWithTextAndLabel("&Number of buttons:",
|
sizerRow = CreateSizerWithTextAndLabel("&Number of buttons:",
|
||||||
wxID_ANY,
|
wxID_ANY,
|
||||||
&m_textNumBtns);
|
&m_textNumBtns);
|
||||||
sizerLeft->Add(sizerRow, 0, wxGROW | wxALL, 5);
|
sizerLeft->Add(sizerRow, wxSizerFlags().Expand().Border());
|
||||||
|
|
||||||
wxButton *btn;
|
wxButton *btn;
|
||||||
btn = new wxButton(this, RadioPage_Update, "&Update");
|
btn = new wxButton(this, RadioPage_Update, "&Update");
|
||||||
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 5);
|
sizerLeft->Add(btn, wxSizerFlags().CentreHorizontal().Border());
|
||||||
|
|
||||||
sizerLeft->Add(5, 5, 0, wxGROW | wxALL, 5); // spacer
|
sizerLeft->AddSpacer(5);
|
||||||
|
|
||||||
btn = new wxButton(this, RadioPage_Reset, "&Reset");
|
btn = new wxButton(this, RadioPage_Reset, "&Reset");
|
||||||
sizerLeft->Add(btn, 0, wxALIGN_CENTRE_HORIZONTAL | wxALL, 15);
|
sizerLeft->Add(btn, wxSizerFlags().CentreHorizontal().Border(wxALL, 15));
|
||||||
|
|
||||||
// middle pane
|
// middle pane
|
||||||
wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, "&Change parameters");
|
wxStaticBox *box2 = new wxStaticBox(this, wxID_ANY, "&Change parameters");
|
||||||
@@ -234,25 +235,25 @@ void RadioWidgetsPage::CreateContent()
|
|||||||
sizerRow = CreateSizerWithTextAndLabel("Current selection:",
|
sizerRow = CreateSizerWithTextAndLabel("Current selection:",
|
||||||
wxID_ANY,
|
wxID_ANY,
|
||||||
&m_textCurSel);
|
&m_textCurSel);
|
||||||
sizerMiddle->Add(sizerRow, 0, wxGROW | wxALL, 5);
|
sizerMiddle->Add(sizerRow, wxSizerFlags().Expand().Border());
|
||||||
|
|
||||||
sizerRow = CreateSizerWithTextAndButton(RadioPage_Selection,
|
sizerRow = CreateSizerWithTextAndButton(RadioPage_Selection,
|
||||||
"&Change selection:",
|
"&Change selection:",
|
||||||
wxID_ANY,
|
wxID_ANY,
|
||||||
&m_textSel);
|
&m_textSel);
|
||||||
sizerMiddle->Add(sizerRow, 0, wxGROW | wxALL, 5);
|
sizerMiddle->Add(sizerRow, wxSizerFlags().Expand().Border());
|
||||||
|
|
||||||
sizerRow = CreateSizerWithTextAndButton(RadioPage_Label,
|
sizerRow = CreateSizerWithTextAndButton(RadioPage_Label,
|
||||||
"&Label for box:",
|
"&Label for box:",
|
||||||
wxID_ANY,
|
wxID_ANY,
|
||||||
&m_textLabel);
|
&m_textLabel);
|
||||||
sizerMiddle->Add(sizerRow, 0, wxGROW | wxALL, 5);
|
sizerMiddle->Add(sizerRow, wxSizerFlags().Expand().Border());
|
||||||
|
|
||||||
sizerRow = CreateSizerWithTextAndButton(RadioPage_LabelBtn,
|
sizerRow = CreateSizerWithTextAndButton(RadioPage_LabelBtn,
|
||||||
"&Label for buttons:",
|
"&Label for buttons:",
|
||||||
wxID_ANY,
|
wxID_ANY,
|
||||||
&m_textLabelBtns);
|
&m_textLabelBtns);
|
||||||
sizerMiddle->Add(sizerRow, 0, wxGROW | wxALL, 5);
|
sizerMiddle->Add(sizerRow, wxSizerFlags().Expand().Border());
|
||||||
|
|
||||||
m_chkEnableItem = CreateCheckBoxAndAddToSizer(sizerMiddle,
|
m_chkEnableItem = CreateCheckBoxAndAddToSizer(sizerMiddle,
|
||||||
"Disable &2nd item",
|
"Disable &2nd item",
|
||||||
@@ -263,16 +264,18 @@ void RadioWidgetsPage::CreateContent()
|
|||||||
|
|
||||||
// right pane
|
// right pane
|
||||||
wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
|
wxSizer *sizerRight = new wxBoxSizer(wxHORIZONTAL);
|
||||||
sizerRight->SetMinSize(150, 0);
|
|
||||||
m_sizerRadio = sizerRight; // save it to modify it later
|
m_sizerRadio = sizerRight; // save it to modify it later
|
||||||
|
|
||||||
Reset();
|
Reset();
|
||||||
CreateRadio();
|
CreateRadio();
|
||||||
|
|
||||||
// the 3 panes panes compose the window
|
// the 3 panes panes compose the window
|
||||||
sizerTop->Add(sizerLeft, 0, wxGROW | (wxALL & ~wxLEFT), 10);
|
sizerTop->Add(sizerLeft,
|
||||||
sizerTop->Add(sizerMiddle, 1, wxGROW | wxALL, 10);
|
wxSizerFlags(0).Expand().Border((wxALL & ~wxLEFT), 10));
|
||||||
sizerTop->Add(sizerRight, 0, wxGROW | (wxALL & ~wxRIGHT), 10);
|
sizerTop->Add(sizerMiddle,
|
||||||
|
wxSizerFlags(1).Expand().Border(wxALL, 10));
|
||||||
|
sizerTop->Add(sizerRight,
|
||||||
|
wxSizerFlags(0).Expand().Border((wxALL & ~wxRIGHT), 10));
|
||||||
|
|
||||||
// final initializations
|
// final initializations
|
||||||
SetSizer(sizerTop);
|
SetSizer(sizerTop);
|
||||||
@@ -328,13 +331,13 @@ void RadioWidgetsPage::CreateRadio()
|
|||||||
majorDim = DEFAULT_MAJOR_DIM;
|
majorDim = DEFAULT_MAJOR_DIM;
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString *items = new wxString[count];
|
wxArrayString items;
|
||||||
|
|
||||||
wxString labelBtn = m_textLabelBtns->GetValue();
|
wxString labelBtn = m_textLabelBtns->GetValue();
|
||||||
for ( size_t n = 0; n < count; n++ )
|
for ( size_t n = 0; n < count; n++ )
|
||||||
{
|
{
|
||||||
items[n] = wxString::Format("%s %lu",
|
items.push_back(wxString::Format("%s %lu",
|
||||||
labelBtn, (unsigned long)n + 1);
|
labelBtn, (unsigned long)n + 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
int flags = m_chkSpecifyRows->GetValue() ? wxRA_SPECIFY_ROWS
|
int flags = m_chkSpecifyRows->GetValue() ? wxRA_SPECIFY_ROWS
|
||||||
@@ -345,22 +348,26 @@ void RadioWidgetsPage::CreateRadio()
|
|||||||
m_radio = new wxRadioBox(this, RadioPage_Radio,
|
m_radio = new wxRadioBox(this, RadioPage_Radio,
|
||||||
m_textLabel->GetValue(),
|
m_textLabel->GetValue(),
|
||||||
wxDefaultPosition, wxDefaultSize,
|
wxDefaultPosition, wxDefaultSize,
|
||||||
count, items,
|
items,
|
||||||
majorDim,
|
majorDim,
|
||||||
flags);
|
flags);
|
||||||
|
|
||||||
delete [] items;
|
|
||||||
|
|
||||||
if ( sel >= 0 && (size_t)sel < count )
|
if ( sel >= 0 && (size_t)sel < count )
|
||||||
{
|
{
|
||||||
m_radio->SetSelection(sel);
|
m_radio->SetSelection(sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_sizerRadio->Add(m_radio, 1, wxGROW);
|
if ( count > TEST_BUTTON )
|
||||||
m_sizerRadio->Layout();
|
{
|
||||||
|
m_radio->Enable(TEST_BUTTON, m_chkEnableItem->IsChecked());
|
||||||
|
m_radio->Show(TEST_BUTTON, m_chkShowItem->IsChecked());
|
||||||
|
}
|
||||||
|
|
||||||
m_chkEnableItem->SetValue(true);
|
m_sizerRadio->Add(m_radio, wxSizerFlags(1).Expand());
|
||||||
m_chkEnableItem->SetValue(true);
|
Layout();
|
||||||
|
|
||||||
|
m_chkEnableItem->Enable(count > TEST_BUTTON);
|
||||||
|
m_chkShowItem->Enable(count > TEST_BUTTON);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ----------------------------------------------------------------------------
|
// ----------------------------------------------------------------------------
|
||||||
@@ -467,12 +474,18 @@ void RadioWidgetsPage::OnUpdateUIReset(wxUpdateUIEvent& event)
|
|||||||
|
|
||||||
void RadioWidgetsPage::OnUpdateUIEnableItem(wxUpdateUIEvent& event)
|
void RadioWidgetsPage::OnUpdateUIEnableItem(wxUpdateUIEvent& event)
|
||||||
{
|
{
|
||||||
|
if ( m_radio->GetCount() <= TEST_BUTTON )
|
||||||
|
return;
|
||||||
|
|
||||||
event.SetText(m_radio->IsItemEnabled(TEST_BUTTON) ? "Disable &2nd item"
|
event.SetText(m_radio->IsItemEnabled(TEST_BUTTON) ? "Disable &2nd item"
|
||||||
: "Enable &2nd item");
|
: "Enable &2nd item");
|
||||||
}
|
}
|
||||||
|
|
||||||
void RadioWidgetsPage::OnUpdateUIShowItem(wxUpdateUIEvent& event)
|
void RadioWidgetsPage::OnUpdateUIShowItem(wxUpdateUIEvent& event)
|
||||||
{
|
{
|
||||||
|
if ( m_radio->GetCount() <= TEST_BUTTON )
|
||||||
|
return;
|
||||||
|
|
||||||
event.SetText(m_radio->IsItemShown(TEST_BUTTON) ? "Hide 2nd &item"
|
event.SetText(m_radio->IsItemShown(TEST_BUTTON) ? "Hide 2nd &item"
|
||||||
: "Show 2nd &item");
|
: "Show 2nd &item");
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user