From: Vadim Zeitlin Date: Wed, 31 Dec 2008 14:39:38 +0000 (+0000) Subject: customize the rearrange dialog even more X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/e9bef302051cec8d15a62a448e1d4b71e45dd519 customize the rearrange dialog even more git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@57691 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index d0c0c6a8d8..a93d23aa7d 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -867,16 +867,37 @@ public: DoUpdateExtraControls(GetList()->GetSelection()); AddExtraControls(panel); + + + // another customization not directly supported by the dialog: add a + // custom button + wxWindow * const btnOk = FindWindow(wxID_OK); + wxCHECK_RET( btnOk, "no Ok button?" ); + + wxSizer * const sizerBtns = btnOk->GetContainingSizer(); + wxCHECK_RET( sizerBtns, "no buttons sizer?" ); + + sizerBtns->Add(new wxButton(this, wxID_RESET, "&Reset all"), + wxSizerFlags().Border(wxLEFT)); } // call this instead of ShowModal() to update order and labels array in // case the dialog was not cancelled bool Rearrange() { - if ( ShowModal() == wxID_CANCEL ) - return false; + switch ( ShowModal() ) + { + case wxID_CANCEL: + return false; - m_order = GetOrder(); + case wxID_OK: + m_order = GetOrder(); + break; + + case wxID_RESET: + // order already reset + break; + } return true; } @@ -901,6 +922,21 @@ private: GetList()->SetString(m_sel, m_labels[m_sel]); } + void OnReset(wxCommandEvent& WXUNUSED(event)) + { + // in a real program we should probably ask if the user really wants to + // do this but here we just go ahead and reset all columns labels and + // their order without confirmation + const unsigned count = m_order.size(); + for ( unsigned n = 0; n < count; n++ ) + { + m_order[n] = n; + m_labels[n] = m_labelsOrig[n]; + } + + EndModal(wxID_RESET); + } + bool CanRename() const { // only allow renaming if the user modified the currently selected item @@ -940,9 +976,12 @@ private: BEGIN_EVENT_TABLE(MyRearrangeDialog, wxRearrangeDialog) EVT_LISTBOX(wxID_ANY, MyRearrangeDialog::OnSelChange) + EVT_UPDATE_UI(wxID_APPLY, MyRearrangeDialog::OnUpdateUIRename) - EVT_BUTTON(wxID_APPLY, MyRearrangeDialog::OnRename) + EVT_TEXT_ENTER(wxID_ANY, MyRearrangeDialog::OnRename) + EVT_BUTTON(wxID_APPLY, MyRearrangeDialog::OnRename) + EVT_BUTTON(wxID_RESET, MyRearrangeDialog::OnReset) END_EVENT_TABLE() void MyFrame::Rearrange(wxCommandEvent& WXUNUSED(event))