]> git.saurik.com Git - wxWidgets.git/commitdiff
adding window-modal message box sample
authorStefan Csomor <csomor@advancedconcepts.ch>
Thu, 28 Jan 2010 09:54:51 +0000 (09:54 +0000)
committerStefan Csomor <csomor@advancedconcepts.ch>
Thu, 28 Jan 2010 09:54:51 +0000 (09:54 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@63294 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/dialogs/dialogs.cpp
samples/dialogs/dialogs.h

index 72a1b58ccc63545e13dbd42caa177e7228933616..eb0b735d89f0312946cb95db3846f2fe7a68be45 100644 (file)
@@ -123,6 +123,7 @@ END_EVENT_TABLE()
 BEGIN_EVENT_TABLE(MyFrame, wxFrame)
 #if wxUSE_MSGDLG
     EVT_MENU(DIALOGS_MESSAGE_BOX,                   MyFrame::MessageBox)
 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
     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"));
     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"));
 
 
     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);
                            wxCENTER |
                            wxNO_DEFAULT | wxYES_NO | wxCANCEL |
                            wxICON_INFORMATION);
-
+    
     wxString extmsg;
     if ( dialog.SetYesNoCancelLabels
     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",
                 (
                     "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.";
     }
         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\""));
     {
         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!"));
     }
         default:
             wxLogError(wxT("Unexpected wxMessageDialog return code!"));
     }
+    delete dialog;
 }
 
 void MyFrame::MessageBoxDialog(wxCommandEvent& WXUNUSED(event))
 }
 
 void MyFrame::MessageBoxDialog(wxCommandEvent& WXUNUSED(event))
index fc11ed657a6378371301b1eaa83391e0ace5bc19..66944fc65fe1d4b636ca96db06ee34e8062e210b 100644 (file)
@@ -288,6 +288,8 @@ public:
     void MessageBox(wxCommandEvent& event);
     void MessageBoxDialog(wxCommandEvent& event);
     void MessageBoxInfo(wxCommandEvent& event);
     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
 #endif // wxUSE_MSGDLG
 
 #if wxUSE_COLOURDLG
@@ -464,6 +466,7 @@ enum
     DIALOGS_CHOOSE_FONT,
     DIALOGS_CHOOSE_FONT_GENERIC,
     DIALOGS_MESSAGE_BOX,
     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,
     DIALOGS_MESSAGE_DIALOG,
     DIALOGS_MESSAGE_BOX_WXINFO,
     DIALOGS_SINGLE_CHOICE,