From 8e1dac82746a49c2037bffadd0ea495471f4a2dd Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 22 Apr 2007 21:25:24 +0000 Subject: [PATCH] added wxStdDialogButtonSizer test (patch 1705382) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45593 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/dialogs/dialogs.cpp | 173 ++++++++++++++++++++++++++++++++++++ samples/dialogs/dialogs.h | 32 ++++++- 2 files changed, 204 insertions(+), 1 deletion(-) diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 6e583373d6..8ab65908e0 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -215,6 +215,7 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, MyFrame::OnPropertySheet) #endif + EVT_MENU(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, MyFrame::OnStandardButtonsSizerDialog) EVT_MENU(DIALOGS_REQUEST, MyFrame::OnRequestUserAttention) EVT_MENU(wxID_EXIT, MyFrame::OnExit) @@ -233,6 +234,11 @@ END_EVENT_TABLE() #endif // USE_MODAL_PRESENTATION +BEGIN_EVENT_TABLE(StdButtonSizerDialog, wxDialog) + EVT_CHECKBOX(wxID_ANY, StdButtonSizerDialog::OnEvent) + EVT_RADIOBUTTON(wxID_ANY, StdButtonSizerDialog::OnEvent) +END_EVENT_TABLE() + MyCanvas *myCanvas = (MyCanvas *) NULL; // `Main program' equivalent, creating windows and returning main app frame @@ -398,6 +404,8 @@ bool MyApp::OnInit() menuDlg->Append(wxID_ANY, _T("&Property sheets"), sheet_menu); #endif // USE_SETTINGS_DIALOG + menuDlg->Append(DIALOGS_STANDARD_BUTTON_SIZER_DIALOG, _T("&Standard Buttons Sizer Dialog")); + menuDlg->Append(DIALOGS_REQUEST, _T("&Request user attention\tCtrl-R")); menuDlg->AppendSeparator(); @@ -1064,6 +1072,12 @@ void MyFrame::OnRequestUserAttention(wxCommandEvent& WXUNUSED(event)) RequestUserAttention(wxUSER_ATTENTION_ERROR); } +void MyFrame::OnStandardButtonsSizerDialog(wxCommandEvent& WXUNUSED(event)) +{ + StdButtonSizerDialog dialog(this); + dialog.ShowModal(); +} + void MyFrame::OnExit(wxCommandEvent& WXUNUSED(event) ) { Close(true); @@ -1514,6 +1528,165 @@ void MyModalDialog::OnButton(wxCommandEvent& event) #endif // USE_MODAL_PRESENTATION +// ---------------------------------------------------------------------------- +// StdButtonSizerDialog +// ---------------------------------------------------------------------------- + +StdButtonSizerDialog::StdButtonSizerDialog(wxWindow *parent) + : wxDialog(parent, wxID_ANY, wxString(_T("StdButtonSizer dialog")), + wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER), + m_buttonsSizer(NULL) +{ + wxBoxSizer *const sizerTop = new wxBoxSizer(wxVERTICAL); + + wxBoxSizer *const sizer = new wxBoxSizer(wxHORIZONTAL); + wxBoxSizer *const sizerInside1 = new wxBoxSizer(wxVERTICAL); + + m_chkboxAffirmativeButton = new wxCheckBox(this, wxID_ANY, _("Enable Affirmative Button")); + + wxStaticBoxSizer *const sizer1 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Affirmative Button")); + + m_radiobtnOk = new wxRadioButton(this, wxID_ANY, _("Ok"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); + m_radiobtnYes = new wxRadioButton(this, wxID_ANY, _("Yes")); + + wxBoxSizer *const sizerInside2 = new wxBoxSizer(wxVERTICAL); + + m_chkboxDismissButton = new wxCheckBox(this, wxID_ANY, _("Enable Dismiss Button")); + + wxStaticBoxSizer *const sizer2 = new wxStaticBoxSizer(wxVERTICAL, this, wxT("Dismiss Button")); + + m_radiobtnCancel = new wxRadioButton(this, wxID_ANY, _("Cancel"), wxDefaultPosition, wxDefaultSize, wxRB_GROUP); + m_radiobtnClose = new wxRadioButton(this, wxID_ANY, _("Close")); + + wxBoxSizer *const sizer3 = new wxBoxSizer(wxHORIZONTAL); + + m_chkboxNo = new wxCheckBox(this, wxID_ANY, _("No")); + m_chkboxHelp = new wxCheckBox(this, wxID_ANY, _("Help")); + m_chkboxApply = new wxCheckBox(this, wxID_ANY, _("Apply")); + + m_chkboxNoDefault = new wxCheckBox(this, wxID_ANY, wxT("No Default")); + + sizer1->Add(m_radiobtnOk, 0, wxALL, 5); + sizer1->Add(m_radiobtnYes, 0, wxALL, 5); + + sizer->Add(sizerInside1, 0, 0, 0); + sizerInside1->Add(m_chkboxAffirmativeButton, 0, wxALL, 5); + sizerInside1->Add(sizer1, 0, wxALL, 5); + sizerInside1->SetItemMinSize(sizer1, sizer1->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label + + sizer2->Add(m_radiobtnCancel, 0, wxALL, 5); + sizer2->Add(m_radiobtnClose, 0, wxALL, 5); + + sizer->Add(sizerInside2, 0, 0, 0); + sizerInside2->Add(m_chkboxDismissButton, 0, wxALL, 5); + sizerInside2->Add(sizer2, 0, wxALL, 5); + sizerInside2->SetItemMinSize(sizer2, sizer2->GetStaticBox()->GetBestSize()); // to prevent wrapping of static box label + + sizerTop->Add(sizer, 0, wxALL, 5); + + sizer3->Add(m_chkboxNo, 0, wxALL, 5); + sizer3->Add(m_chkboxHelp, 0, wxALL, 5); + sizer3->Add(m_chkboxApply, 0, wxALL, 5); + + sizerTop->Add(sizer3, 0, wxALL, 5); + + sizerTop->Add(m_chkboxNoDefault, 0, wxLEFT|wxRIGHT, 10); + + EnableDisableControls(); + + SetSizer(sizerTop); + + sizerTop->SetSizeHints(this); + wxCommandEvent ev; + OnEvent(ev); +} + +void StdButtonSizerDialog::OnEvent(wxCommandEvent& WXUNUSED(event)) +{ + if (m_buttonsSizer) + { + m_buttonsSizer->DeleteWindows(); + GetSizer()->Remove(m_buttonsSizer); + } + + EnableDisableControls(); + + long flags = 0; + unsigned long numButtons = 0; + + if (m_chkboxAffirmativeButton->IsChecked()) + { + if (m_radiobtnOk->GetValue()) + { + flags |= wxOK; + numButtons ++; + } + else if (m_radiobtnYes->GetValue()) + { + flags |= wxYES; + numButtons ++; + } + } + + if (m_chkboxDismissButton->IsChecked()) + { + if (m_radiobtnCancel->GetValue()) + { + flags |= wxCANCEL; + numButtons ++; + } + + else if (m_radiobtnClose->GetValue()) + { + flags |= wxCLOSE; + numButtons ++; + } + + } + + if (m_chkboxApply->IsChecked()) + { + flags |= wxAPPLY; + numButtons ++; + } + + if (m_chkboxNo->IsChecked()) + { + flags |= wxNO; + numButtons ++; + } + + if (m_chkboxHelp->IsChecked()) + { + flags |= wxHELP; + numButtons ++; + } + + if (m_chkboxNoDefault->IsChecked()) + { + flags |= wxNO_DEFAULT; + } + + m_buttonsSizer = CreateStdDialogButtonSizer(flags); + GetSizer()->Add(m_buttonsSizer, 0, wxGROW|wxALL, 5); + + Layout(); + GetSizer()->SetSizeHints(this); +} + +void StdButtonSizerDialog::EnableDisableControls() +{ + const bool affButtonEnabled = m_chkboxAffirmativeButton->IsChecked(); + + m_radiobtnOk->Enable(affButtonEnabled); + m_radiobtnYes->Enable(affButtonEnabled); + + const bool dismissButtonEnabled = m_chkboxDismissButton->IsChecked(); + + m_radiobtnCancel->Enable(dismissButtonEnabled); + m_radiobtnClose->Enable(dismissButtonEnabled); +} + #if USE_SETTINGS_DIALOG // ---------------------------------------------------------------------------- // SettingsDialog diff --git a/samples/dialogs/dialogs.h b/samples/dialogs/dialogs.h index 12a64d9a63..9aa4d1681b 100644 --- a/samples/dialogs/dialogs.h +++ b/samples/dialogs/dialogs.h @@ -141,6 +141,34 @@ private: #endif // USE_MODAL_PRESENTATION +class StdButtonSizerDialog : public wxDialog +{ +public: + StdButtonSizerDialog(wxWindow *parent); + + void OnEvent(wxCommandEvent& event); + +private: + void EnableDisableControls(); + + wxCheckBox *m_chkboxAffirmativeButton; + wxRadioButton *m_radiobtnOk, + *m_radiobtnYes; + + wxCheckBox *m_chkboxDismissButton; + wxRadioButton *m_radiobtnClose, + *m_radiobtnCancel; + + wxCheckBox *m_chkboxApply, + *m_chkboxNo, + *m_chkboxHelp, + *m_chkboxNoDefault; + + wxSizer *m_buttonsSizer; + + DECLARE_EVENT_TABLE() +}; + #if USE_SETTINGS_DIALOG // Property sheet dialog class SettingsDialog: public wxPropertySheetDialog @@ -271,6 +299,7 @@ public: void OnPropertySheet(wxCommandEvent& event); void OnRequestUserAttention(wxCommandEvent& event); + void OnStandardButtonsSizerDialog(wxCommandEvent& event); void OnExit(wxCommandEvent& event); private: @@ -347,7 +376,8 @@ enum DIALOGS_REQUEST, DIALOGS_PROPERTY_SHEET, DIALOGS_PROPERTY_SHEET_TOOLBOOK, - DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK + DIALOGS_PROPERTY_SHEET_BUTTONTOOLBOOK, + DIALOGS_STANDARD_BUTTON_SIZER_DIALOG }; #endif -- 2.45.2