From: Stefan Csomor Date: Thu, 28 Jan 2010 09:54:51 +0000 (+0000) Subject: adding window-modal message box sample X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/86c3808c286007a4e3c15f21204fa9ce2edf3728 adding window-modal message box sample git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63294 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index 72a1b58ccc..eb0b735d89 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -123,6 +123,7 @@ END_EVENT_TABLE() BEGIN_EVENT_TABLE(MyFrame, wxFrame) #if wxUSE_MSGDLG EVT_MENU(DIALOGS_MESSAGE_BOX, MyFrame::MessageBox) + EVT_MENU(DIALOGS_MESSAGE_BOX_WINDOW_MODAL, MyFrame::MessageBoxWindowModal) EVT_MENU(DIALOGS_MESSAGE_DIALOG, MyFrame::MessageBoxDialog) EVT_MENU(DIALOGS_MESSAGE_BOX_WXINFO, MyFrame::MessageBoxInfo) #endif // wxUSE_MSGDLG @@ -286,6 +287,7 @@ bool MyApp::OnInit() wxMenu *menuDlg = new wxMenu; menuDlg->Append(DIALOGS_MESSAGE_BOX, wxT("&Message box\tCtrl-M")); + menuDlg->Append(DIALOGS_MESSAGE_BOX_WINDOW_MODAL, wxT("Window-Modal Message box ")); menuDlg->Append(DIALOGS_MESSAGE_DIALOG, wxT("Message dialog\tShift-Ctrl-M")); @@ -746,9 +748,57 @@ void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event)) wxCENTER | wxNO_DEFAULT | wxYES_NO | wxCANCEL | wxICON_INFORMATION); - + wxString extmsg; if ( dialog.SetYesNoCancelLabels + ( + "Answer &Yes", + "Answer &No", + "Refuse to answer" + ) ) + { + extmsg = "This platform supports custom button labels,\n" + "so you should see the descriptive labels below."; + } + else + { + extmsg = "Custom button labels are not supported on this platform,\n" + "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used."; + } + dialog.SetExtendedMessage(extmsg); + + switch ( dialog.ShowModal() ) + { + case wxID_YES: + wxLogStatus(wxT("You pressed \"Yes\"")); + break; + + case wxID_NO: + wxLogStatus(wxT("You pressed \"No\"")); + break; + + case wxID_CANCEL: + wxLogStatus(wxT("You pressed \"Cancel\"")); + break; + + default: + wxLogError(wxT("Unexpected wxMessageDialog return code!")); + } +} + +void MyFrame::MessageBoxWindowModal(wxCommandEvent& WXUNUSED(event)) +{ + wxMessageDialog* dialog = new wxMessageDialog(this, + "This is a message box\n" + "This is a long, long string to test out if the message box " + "is laid out properly.", + "Message box text", + wxCENTER | + wxNO_DEFAULT | wxYES_NO | wxCANCEL | + wxICON_INFORMATION); + + wxString extmsg; + if ( dialog->SetYesNoCancelLabels ( "Answer &Yes", "Answer &No", @@ -763,9 +813,15 @@ void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event)) extmsg = "Custom button labels are not supported on this platform,\n" "so the default \"Yes\"/\"No\"/\"Cancel\" buttons are used."; } - dialog.SetExtendedMessage(extmsg); + dialog->SetExtendedMessage(extmsg); + dialog->Connect( wxEVT_WINDOW_MODAL_DIALOG_CLOSED, wxWindowModalDialogEventHandler(MyFrame::MessageBoxWindowModalClosed), NULL, this ); + dialog->ShowWindowModal(); +} - switch ( dialog.ShowModal() ) +void MyFrame::MessageBoxWindowModalClosed(wxWindowModalDialogEvent& event) +{ + wxDialog* dialog = event.GetDialog(); + switch ( dialog->GetReturnCode() ) { case wxID_YES: wxLogStatus(wxT("You pressed \"Yes\"")); @@ -782,6 +838,7 @@ void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event)) default: wxLogError(wxT("Unexpected wxMessageDialog return code!")); } + delete dialog; } void MyFrame::MessageBoxDialog(wxCommandEvent& WXUNUSED(event)) diff --git a/samples/dialogs/dialogs.h b/samples/dialogs/dialogs.h index fc11ed657a..66944fc65f 100644 --- a/samples/dialogs/dialogs.h +++ b/samples/dialogs/dialogs.h @@ -288,6 +288,8 @@ public: void MessageBox(wxCommandEvent& event); void MessageBoxDialog(wxCommandEvent& event); void MessageBoxInfo(wxCommandEvent& event); + void MessageBoxWindowModal(wxCommandEvent& event); + void MessageBoxWindowModalClosed(wxWindowModalDialogEvent& event); #endif // wxUSE_MSGDLG #if wxUSE_COLOURDLG @@ -464,6 +466,7 @@ enum DIALOGS_CHOOSE_FONT, DIALOGS_CHOOSE_FONT_GENERIC, DIALOGS_MESSAGE_BOX, + DIALOGS_MESSAGE_BOX_WINDOW_MODAL, DIALOGS_MESSAGE_DIALOG, DIALOGS_MESSAGE_BOX_WXINFO, DIALOGS_SINGLE_CHOICE,