]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/dialogs/dialogs.cpp
Scripts to make a installer package in a disk image for wxPython and
[wxWidgets.git] / samples / dialogs / dialogs.cpp
index 18d11c22490430c366318208af1f18ce9045cc97..e8df89afe6d535e1d2e87c045ee71b0e85bd2633 100644 (file)
@@ -239,19 +239,25 @@ void MyFrame::ChooseColour(wxCommandEvent& WXUNUSED(event) )
 
 void MyFrame::ChooseFont(wxCommandEvent& WXUNUSED(event) )
 {
-      wxFontData data;
-      data.SetInitialFont(wxGetApp().m_canvasFont);
-      data.SetColour(wxGetApp().m_canvasTextColour);
+    wxFontData data;
+    data.SetInitialFont(wxGetApp().m_canvasFont);
+    data.SetColour(wxGetApp().m_canvasTextColour);
 
-      wxFontDialog *dialog = new wxFontDialog(this, &data);
-      if (dialog->ShowModal() == wxID_OK)
-      {
-        wxFontData retData = dialog->GetFontData();
+    // you might also do this:
+    //
+    //  wxFontDialog dialog;
+    //  if ( !dialog.Create(this, data) { ... error ... }
+    //
+    wxFontDialog dialog(this, data);
+
+    if (dialog.ShowModal() == wxID_OK)
+    {
+        wxFontData retData = dialog.GetFontData();
         wxGetApp().m_canvasFont = retData.GetChosenFont();
         wxGetApp().m_canvasTextColour = retData.GetColour();
         myCanvas->Refresh();
-      }
-      dialog->Destroy();
+    }
+    //else: cancelled by the user, don't change the font
 }
 
 #if defined(__WXMSW__) && wxTEST_GENERIC_DIALOGS_IN_MSW
@@ -321,9 +327,25 @@ void MyFrame::LogDialog(wxCommandEvent& event)
 void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
 {
   wxMessageDialog dialog( NULL, "This is a message box\nA long, long string to test out the message box properly",
-      "Message box text", wxYES_NO|wxCANCEL|wxICON_INFORMATION);
+      "Message box text", wxNO_DEFAULT|wxYES_NO|wxCANCEL|wxICON_INFORMATION);
+
+  switch ( dialog.ShowModal() )
+  {
+      case wxID_YES:
+          wxLogStatus(wxT("You pressed \"Yes\""));
+          break;
+
+      case wxID_NO:
+          wxLogStatus(wxT("You pressed \"No\""));
+          break;
 
-  dialog.ShowModal();
+      case wxID_CANCEL:
+          wxLogStatus(wxT("You pressed \"Cancel\""));
+          break;
+
+      default:
+          wxLogError(wxT("Unexpected wxMessageDialog return code!"));
+  }
 }
 
 void MyFrame::NumericEntry(wxCommandEvent& WXUNUSED(event) )