From 400e16fd894656c257498e97bee89a4884dffd7c Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Wed, 2 Apr 2014 22:39:08 +0000 Subject: [PATCH] Show the result of closing rich message box in the sample. Improve showing the button which closed the message box by doing it inside the dialog used for testing it instead of popping up a separate message box just for this. And do the same thing for rich message boxes as for the normal ones. See #16153. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@76256 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- samples/dialogs/dialogs.cpp | 24 +++++++++++++++++++----- samples/dialogs/dialogs.h | 4 ++++ 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 36f9c6a18a..8da5a08e69 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -3097,6 +3097,13 @@ bool TestMessageBoxDialog::Create() sizerTop->Add(sizerFlags, wxSizerFlags().Expand().Border()); + // add the currently unused zone for displaying the dialog result + m_labelResult = new wxStaticText(this, wxID_ANY, "", + wxDefaultPosition, wxDefaultSize, + wxST_NO_AUTORESIZE | wxALIGN_CENTRE); + m_labelResult->SetForegroundColour(*wxBLUE); + sizerTop->Add(m_labelResult, wxSizerFlags().Expand().DoubleBorder()); + // finally buttons to show the resulting message box and close this dialog sizerTop->Add(CreateStdDialogButtonSizer(wxAPPLY | wxCLOSE), wxSizerFlags().Right().Border()); @@ -3226,16 +3233,21 @@ void TestMessageBoxDialog::OnApply(wxCommandEvent& WXUNUSED(event)) wxMessageDialog dlg(this, GetMessage(), GetBoxTitle(), GetStyle()); PrepareMessageDialog(dlg); + ShowResult(dlg.ShowModal()); +} + +void TestMessageBoxDialog::ShowResult(int res) +{ wxString btnName; - switch ( dlg.ShowModal() ) + switch ( res ) { case wxID_OK: btnName = "OK"; break; case wxID_CANCEL: - // Avoid the extra message box if the dialog was cancelled. - return; + btnName = "Cancel"; + break; case wxID_YES: btnName = "Yes"; @@ -3253,7 +3265,9 @@ void TestMessageBoxDialog::OnApply(wxCommandEvent& WXUNUSED(event)) btnName = "Unknown"; } - wxLogMessage("Dialog was closed with the \"%s\" button.", btnName); + m_labelResult->SetLabel( + wxString::Format("Dialog was closed with the \"%s\" button.", btnName) + ); } void TestMessageBoxDialog::OnClose(wxCommandEvent& WXUNUSED(event)) @@ -3318,7 +3332,7 @@ void TestRichMessageDialog::OnApply(wxCommandEvent& WXUNUSED(event)) m_initialValueCheckBox->GetValue()); dlg.ShowDetailedText(m_textDetailed->GetValue()); - dlg.ShowModal(); + ShowResult(dlg.ShowModal()); } #endif // wxUSE_RICHMSGDLG diff --git a/samples/dialogs/dialogs.h b/samples/dialogs/dialogs.h index 55ab481618..374af2a09a 100644 --- a/samples/dialogs/dialogs.h +++ b/samples/dialogs/dialogs.h @@ -216,6 +216,8 @@ protected: virtual void AddAdditionalTextOptions(wxSizer *WXUNUSED(sizer)) { } virtual void AddAdditionalFlags(wxSizer *WXUNUSED(sizer)) { } + void ShowResult(int res); + void OnApply(wxCommandEvent& event); void OnClose(wxCommandEvent& event); void OnUpdateLabelUI(wxUpdateUIEvent& event); @@ -264,6 +266,8 @@ private: wxCheckBox *m_chkNoDefault, *m_chkCentre; + wxStaticText *m_labelResult; + wxDECLARE_EVENT_TABLE(); wxDECLARE_NO_COPY_CLASS(TestMessageBoxDialog); };