added a dialog for wxMessageBox testing

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@55520 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
Vadim Zeitlin
2008-09-08 00:49:06 +00:00
parent 18fc421b1f
commit 44b25eac69
2 changed files with 228 additions and 15 deletions

View File

@@ -118,6 +118,7 @@ END_EVENT_TABLE()
BEGIN_EVENT_TABLE(MyFrame, wxFrame) BEGIN_EVENT_TABLE(MyFrame, wxFrame)
#if wxUSE_MSGDLG #if wxUSE_MSGDLG
EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox) EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox)
EVT_MENU(DIALOGS_MESSAGE_DIALOG, MyFrame::MessageBoxDialog)
EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO, MyFrame::MessageBoxInfo) EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO, MyFrame::MessageBoxInfo)
#endif // wxUSE_MSGDLG #endif // wxUSE_MSGDLG
#if wxUSE_COLOURDLG #if wxUSE_COLOURDLG
@@ -275,6 +276,7 @@ bool MyApp::OnInit()
wxMenu *menuDlg = new wxMenu; wxMenu *menuDlg = new wxMenu;
menuDlg->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M")); menuDlg->Append(DIALOGS_MESSAGE_BOX, _T("&Message box\tCtrl-M"));
menuDlg->Append(DIALOGS_MESSAGE_DIALOG, _T("Message dialog\tShift-Ctrl-M"));
#if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG #if wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
@@ -650,14 +652,16 @@ void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event))
#endif // wxUSE_LOG_DIALOG #endif // wxUSE_LOG_DIALOG
#if wxUSE_MSGDLG #if wxUSE_MSGDLG
void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) ) void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event))
{ {
wxMessageDialog dialog(this, wxMessageDialog dialog(this,
"This is a message box\n" "This is a message box\n"
"A long, long string to test out the message box " "A long, long string to test out the message box "
"layout properly.", "layout properly.",
"Message box text", "Message box text",
wxCENTER | wxNO_DEFAULT | wxYES_NO | wxCANCEL | wxICON_INFORMATION); wxVSCROLL | wxCENTER |
wxNO_DEFAULT | wxYES_NO | wxCANCEL |
wxICON_INFORMATION);
wxString extmsg; wxString extmsg;
if ( dialog.SetYesNoCancelLabels if ( dialog.SetYesNoCancelLabels
@@ -696,6 +700,12 @@ void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
} }
} }
void MyFrame::MessageBoxDialog(wxCommandEvent& WXUNUSED(event))
{
TestMessageBoxDialog dlg(this);
dlg.ShowModal();
}
void MyFrame::MessageBoxInfo(wxCommandEvent& WXUNUSED(event)) void MyFrame::MessageBoxInfo(wxCommandEvent& WXUNUSED(event))
{ {
::wxInfoMessageBox(this); ::wxInfoMessageBox(this);
@@ -2124,4 +2134,164 @@ wxPanel* SettingsDialog::CreateAestheticSettingsPage(wxWindow* parent)
return panel; return panel;
} }
// ----------------------------------------------------------------------------
// TestMessageBoxDialog
// ----------------------------------------------------------------------------
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, "",
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[] = {
"&Information", "&Question", "&Warning", "&Error"
};
m_icons = new wxRadioBox(this, wxID_ANY, "&Icon:",
wxDefaultPosition, wxDefaultSize,
WXSIZEOF(icons), icons);
sizerTop->Add(m_icons, 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);
}
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::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_INFORMATION; break;
case 1: style |= wxICON_QUESTION; break;
case 2: style |= wxICON_WARNING; break;
case 3: style |= wxICON_ERROR; break;
}
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);
}
#endif // USE_SETTINGS_DIALOG #endif // USE_SETTINGS_DIALOG

View File

@@ -142,6 +142,7 @@ private:
#endif // USE_MODAL_PRESENTATION #endif // USE_MODAL_PRESENTATION
// A class demonstrating CreateStdDialogButtonSizer()
class StdButtonSizerDialog : public wxDialog class StdButtonSizerDialog : public wxDialog
{ {
public: public:
@@ -170,6 +171,46 @@ private:
DECLARE_EVENT_TABLE() DECLARE_EVENT_TABLE()
}; };
// Test harness for wxMessageDialog.
class TestMessageBoxDialog : public wxDialog
{
public:
TestMessageBoxDialog(wxWindow *parent);
private:
void OnApply(wxCommandEvent& event);
void OnClose(wxCommandEvent& event);
void OnUpdateLabelUI(wxUpdateUIEvent& event);
enum
{
Btn_Yes,
Btn_No,
Btn_Ok,
Btn_Cancel,
Btn_Max
};
struct BtnInfo
{
int flag;
wxString name;
};
static BtnInfo ms_btnInfo[Btn_Max];
wxTextCtrl *m_textMsg,
*m_textExtMsg;
wxCheckBox *m_buttons[Btn_Max];
wxTextCtrl *m_labels[Btn_Max];
wxRadioBox *m_icons;
DECLARE_EVENT_TABLE()
DECLARE_NO_COPY_CLASS(TestMessageBoxDialog)
};
class TestDefaultActionDialog: public wxDialog class TestDefaultActionDialog: public wxDialog
{ {
public: public:
@@ -227,6 +268,7 @@ public:
#if wxUSE_MSGDLG #if wxUSE_MSGDLG
void MessageBox(wxCommandEvent& event); void MessageBox(wxCommandEvent& event);
void MessageBoxDialog(wxCommandEvent& event);
void MessageBoxInfo(wxCommandEvent& event); void MessageBoxInfo(wxCommandEvent& event);
#endif // wxUSE_MSGDLG #endif // wxUSE_MSGDLG
@@ -382,6 +424,7 @@ enum
DIALOGS_CHOOSE_FONT, DIALOGS_CHOOSE_FONT,
DIALOGS_CHOOSE_FONT_GENERIC, DIALOGS_CHOOSE_FONT_GENERIC,
DIALOGS_MESSAGE_BOX, DIALOGS_MESSAGE_BOX,
DIALOGS_MESSAGE_DIALOG,
DIALOGS_MESSAGE_BOX_WXINFO, DIALOGS_MESSAGE_BOX_WXINFO,
DIALOGS_SINGLE_CHOICE, DIALOGS_SINGLE_CHOICE,
DIALOGS_MULTI_CHOICE, DIALOGS_MULTI_CHOICE,