+// ----------------------------------------------------------------------------
+// TestMessageBoxDialog
+// ----------------------------------------------------------------------------
+
+/* static */
+const TestMessageBoxDialog::BtnInfo TestMessageBoxDialog::ms_btnInfo[] =
+{
+ { wxYES, "&Yes" },
+ { wxNO, "&No" },
+ { wxOK, "&Ok" },
+ { wxCANCEL, "&Cancel" },
+};
+
+BEGIN_EVENT_TABLE(TestMessageBoxDialog, wxDialog)
+ EVT_BUTTON(wxID_APPLY, TestMessageBoxDialog::OnApply)
+ EVT_BUTTON(wxID_CLOSE, TestMessageBoxDialog::OnClose)
+END_EVENT_TABLE()
+
+TestMessageBoxDialog::TestMessageBoxDialog(wxWindow *parent)
+ : wxDialog(parent, wxID_ANY, "Message Box Test Dialog",
+ wxDefaultPosition, wxDefaultSize,
+ wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER)
+{
+ wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL);
+
+ // this sizer allows to configure the messages shown in the message box
+ wxSizer * const
+ sizerMsgs = new wxStaticBoxSizer(wxVERTICAL, this, "&Messages");
+ sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Main message:"));
+ m_textMsg = new wxTextCtrl(this, wxID_ANY, "Hello from a box!",
+ wxDefaultPosition, wxDefaultSize,
+ wxTE_MULTILINE);
+ sizerMsgs->Add(m_textMsg, wxSizerFlags(1).Expand().Border(wxBOTTOM));
+
+ sizerMsgs->Add(new wxStaticText(this, wxID_ANY, "&Extended message:"));
+ m_textExtMsg = new wxTextCtrl(this, wxID_ANY, "",
+ wxDefaultPosition, wxDefaultSize,
+ wxTE_MULTILINE);
+ sizerMsgs->Add(m_textExtMsg, wxSizerFlags(1).Expand());
+
+ sizerTop->Add(sizerMsgs, wxSizerFlags(1).Expand().Border());
+
+
+ // this one is for configuring the buttons
+ wxFlexGridSizer * const sizerBtns = new wxFlexGridSizer(2, 5, 5);
+ sizerBtns->AddGrowableCol(1);
+
+ sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Button(s)"));
+ sizerBtns->Add(new wxStaticText(this, wxID_ANY, "Custom label"));
+
+ for ( int n = 0; n < Btn_Max; n++ )
+ {
+ m_buttons[n] = new wxCheckBox(this, wxID_ANY, ms_btnInfo[n].name);
+ sizerBtns->Add(m_buttons[n], wxSizerFlags().Centre().Left());
+
+ m_labels[n] = new wxTextCtrl(this, wxID_ANY);
+ sizerBtns->Add(m_labels[n], wxSizerFlags(1).Centre().Expand());
+
+ m_labels[n]->Connect(wxEVT_UPDATE_UI,
+ wxUpdateUIEventHandler(
+ TestMessageBoxDialog::OnUpdateLabelUI),
+ NULL,
+ this);
+ }
+
+ wxSizer * const
+ sizerBtnsBox = new wxStaticBoxSizer(wxVERTICAL, this, "&Buttons");
+ sizerBtnsBox->Add(sizerBtns, wxSizerFlags(1).Expand());
+ sizerTop->Add(sizerBtnsBox, wxSizerFlags().Expand().Border());
+
+
+ // icon choice
+ const wxString icons[] = {
+ "&None", "&Information", "&Question", "&Warning", "&Error"
+ };
+
+ m_icons = new wxRadioBox(this, wxID_ANY, "&Icons",
+ wxDefaultPosition, wxDefaultSize,
+ WXSIZEOF(icons), icons);
+ // Make the 'Information' icon the default one:
+ m_icons->SetSelection(1);
+ sizerTop->Add(m_icons, wxSizerFlags().Expand().Border());
+
+
+ // miscellaneous other stuff
+ wxSizer * const
+ sizerFlags = new wxStaticBoxSizer(wxHORIZONTAL, this, "&Other flags");
+
+ m_chkNoDefault = new wxCheckBox(this, wxID_ANY, "Make \"No\" &default");
+ m_chkNoDefault->Connect(wxEVT_UPDATE_UI,
+ wxUpdateUIEventHandler(
+ TestMessageBoxDialog::OnUpdateNoDefaultUI),
+ NULL,
+ this);
+ sizerFlags->Add(m_chkNoDefault, wxSizerFlags(1).Border());
+
+ m_chkCentre = new wxCheckBox(this, wxID_ANY, "Centre on &parent");
+ sizerFlags->Add(m_chkCentre, wxSizerFlags(1).Border());
+
+ sizerTop->Add(sizerFlags, wxSizerFlags().Expand().Border());
+
+ // finally buttons to show the resulting message box and close this dialog
+ sizerTop->Add(CreateStdDialogButtonSizer(wxAPPLY | wxCLOSE),
+ wxSizerFlags().Right().Border());
+
+ SetSizerAndFit(sizerTop);
+
+ m_buttons[Btn_Ok]->SetValue(true);
+}
+
+void TestMessageBoxDialog::OnUpdateLabelUI(wxUpdateUIEvent& event)
+{
+ for ( int n = 0; n < Btn_Max; n++ )
+ {
+ if ( event.GetEventObject() == m_labels[n] )
+ {
+ event.Enable( m_buttons[n]->IsChecked() );
+ return;
+ }
+ }
+
+ wxFAIL_MSG( "called for unknown label" );
+}
+
+void TestMessageBoxDialog::OnUpdateNoDefaultUI(wxUpdateUIEvent& event)
+{
+ event.Enable( m_buttons[Btn_No]->IsChecked() );
+}
+
+void TestMessageBoxDialog::OnApply(wxCommandEvent& WXUNUSED(event))
+{
+ long style = 0;
+
+ for ( int n = 0; n < Btn_Max; n++ )
+ {
+ if ( m_buttons[n]->IsChecked() )
+ style |= ms_btnInfo[n].flag;
+ }
+
+ switch ( m_icons->GetSelection() )
+ {
+ case 0: style |= wxICON_NONE; break;
+ case 1: style |= wxICON_INFORMATION; break;
+ case 2: style |= wxICON_QUESTION; break;
+ case 3: style |= wxICON_WARNING; break;
+ case 4: style |= wxICON_ERROR; break;
+ }
+
+ if ( m_chkCentre->IsChecked() )
+ style |= wxCENTRE;
+
+ if ( m_chkNoDefault->IsEnabled() && m_chkNoDefault->IsChecked() )
+ style |= wxNO_DEFAULT;
+
+
+ wxMessageDialog dlg(this, m_textMsg->GetValue(), "Test Message Box",
+ style);
+ if ( !m_textExtMsg->IsEmpty() )
+ dlg.SetExtendedMessage(m_textExtMsg->GetValue());
+
+ if ( style & wxYES_NO )
+ {
+ if ( style & wxCANCEL )
+ {
+ dlg.SetYesNoCancelLabels(m_labels[Btn_Yes]->GetValue(),
+ m_labels[Btn_No]->GetValue(),
+ m_labels[Btn_Cancel]->GetValue());
+ }
+ else
+ {
+ dlg.SetYesNoLabels(m_labels[Btn_Yes]->GetValue(),
+ m_labels[Btn_No]->GetValue());
+ }
+ }
+ else
+ {
+ if ( style & wxCANCEL )
+ {
+ dlg.SetOKCancelLabels(m_labels[Btn_Ok]->GetValue(),
+ m_labels[Btn_Cancel]->GetValue());
+ }
+ else
+ {
+ dlg.SetOKLabel(m_labels[Btn_Ok]->GetValue());
+ }
+ }
+
+ dlg.ShowModal();
+}
+
+void TestMessageBoxDialog::OnClose(wxCommandEvent& WXUNUSED(event))
+{
+ EndModal(wxID_CANCEL);
+}
+