X-Git-Url: https://git.saurik.com/wxWidgets.git/blobdiff_plain/3de9120b030f0d1d9067fe8913828cca68589ae8..53a118d6fe4ecbeda81c0eb2bef65e204b3588ad:/samples/dialogs/dialogs.cpp diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 6e583373d6..486c82e4e7 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(); @@ -585,8 +593,19 @@ void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event)) void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) ) { - wxMessageDialog dialog( NULL, _T("This is a message box\nA long, long string to test out the message box properly"), - _T("Message box text"), wxNO_DEFAULT|wxYES_NO|wxCANCEL|wxICON_INFORMATION); + wxMessageDialog dialog(NULL, + _T("This is a message box\nA long, long string to test out the message box properly"), + _T("Message box text"), + wxNO_DEFAULT | wxYES_NO | wxCANCEL | wxICON_INFORMATION); + + if ( dialog.SetYesNoLabels(_T("Answer &Yes"),_T("Answer &No")) ) + { + dialog.SetExtendedMessage(_T("This platform supports custom button labels")); + } + else + { + dialog.SetExtendedMessage(_T("Custom button labels are not supported.")); + } switch ( dialog.ShowModal() ) { @@ -774,7 +793,7 @@ void MyFrame::FileOpen2(wxCommandEvent& WXUNUSED(event) ) s_extDef = path.AfterLast(_T('.')); wxLogMessage(_T("You selected the file '%s', remembered extension '%s'"), - (const wxChar*) path, (const wxChar*) s_extDef); + path, s_extDef); } void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) ) @@ -1064,6 +1083,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 +1539,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