]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/dialogs/dialogs.cpp
added missing include files for compilation with Apple Developer Tools
[wxWidgets.git] / samples / dialogs / dialogs.cpp
index 96f70704d19932c74207f73e664e8025644e0a79..598fe7f515ab55a0796dea92574a0d9b021cfac0 100644 (file)
@@ -2,7 +2,7 @@
 // Name:        dialogs.cpp
 // Purpose:     Common dialogs demo
 // Author:      Julian Smart
-// Modified by: ABX (2004) - adjustementd for conditional building
+// Modified by: ABX (2004) - adjustements for conditional building + new menu
 // Created:     04/01/98
 // RCS-ID:      $Id$
 // Copyright:   (c) Julian Smart
@@ -25,6 +25,7 @@
 #include "wx/wx.h"
 #endif
 
+#include "wx/datetime.h"
 #include "wx/image.h"
 
 #if wxUSE_COLOURDLG
     #include "wx/generic/colrdlgg.h"
 #endif // USE_COLOURDLG_GENERIC
 
-#if USE_FONTDLG_GENERIC
-    #include "wx/generic/fontdlgg.h"
-#endif // USE_FONTDLG_GENERIC
-
 #if USE_DIRDLG_GENERIC
     #include "wx/generic/dirdlgg.h"
 #endif // USE_DIRDLG_GENERIC
 
+#if USE_FILEDLG_GENERIC
+    #include "wx/generic/filedlgg.h"
+#endif // USE_FILEDLG_GENERIC
+
+#if USE_FONTDLG_GENERIC
+    #include "wx/generic/fontdlgg.h"
+#endif // USE_FONTDLG_GENERIC
+
 IMPLEMENT_APP(MyApp)
 
 BEGIN_EVENT_TABLE(MyCanvas, wxScrolledWindow)
@@ -125,6 +130,12 @@ BEGIN_EVENT_TABLE(MyFrame, wxFrame)
     EVT_MENU(DIALOGS_FILE_SAVE,                     MyFrame::FileSave)
 #endif // wxUSE_FILEDLG
 
+#if USE_FILEDLG_GENERIC
+    EVT_MENU(DIALOGS_FILE_OPEN_GENERIC,             MyFrame::FileOpenGeneric)
+    EVT_MENU(DIALOGS_FILES_OPEN_GENERIC,            MyFrame::FilesOpenGeneric)
+    EVT_MENU(DIALOGS_FILE_SAVE_GENERIC,             MyFrame::FileSaveGeneric)
+#endif // USE_FILEDLG_GENERIC
+
 #if wxUSE_DIRDLG
     EVT_MENU(DIALOGS_DIR_CHOOSE,                    MyFrame::DirChoose)
     EVT_MENU(DIALOGS_DIRNEW_CHOOSE,                 MyFrame::DirChooseNew)
@@ -219,23 +230,27 @@ bool MyApp::OnInit()
             choices_menu->Append(DIALOGS_CHOOSE_COLOUR, _T("&Choose colour"));
         #endif // wxUSE_COLOURDLG
 
-        #if USE_COLOURDLG_GENERIC
-            choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("&Choose colour (generic)"));
-        #endif // USE_COLOURDLG_GENERIC
-
         #if wxUSE_FONTDLG
             choices_menu->Append(DIALOGS_CHOOSE_FONT, _T("Choose &font"));
         #endif // wxUSE_FONTDLG
 
-        #if USE_FONTDLG_GENERIC
-            choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose &font (generic)"));
-        #endif // USE_FONTDLG_GENERIC
-
         #if wxUSE_CHOICEDLG
             choices_menu->Append(DIALOGS_SINGLE_CHOICE,  _T("&Single choice\tCtrl-C"));
             choices_menu->Append(DIALOGS_MULTI_CHOICE,  _T("M&ultiple choice\tCtrl-U"));
         #endif // wxUSE_CHOICEDLG
 
+        #if USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
+            choices_menu->AppendSeparator();
+        #endif // USE_COLOURDLG_GENERIC || USE_FONTDLG_GENERIC
+
+        #if USE_COLOURDLG_GENERIC
+            choices_menu->Append(DIALOGS_CHOOSE_COLOUR_GENERIC, _T("&Choose colour (generic)"));
+        #endif // USE_COLOURDLG_GENERIC
+
+        #if USE_FONTDLG_GENERIC
+            choices_menu->Append(DIALOGS_CHOOSE_FONT_GENERIC, _T("Choose &font (generic)"));
+        #endif // USE_FONTDLG_GENERIC
+
         file_menu->Append(wxID_ANY,_T("Choices and selectors"),choices_menu);
 
     #endif // wxUSE_COLOURDLG || wxUSE_FONTDLG || wxUSE_CHOICEDLG
@@ -256,7 +271,7 @@ bool MyApp::OnInit()
 
         file_menu->Append(wxID_ANY,_T("Entry dialogs"),entry_menu);
 
-    #endif
+    #endif // wxUSE_TEXTDLG || wxUSE_NUMBERDLG
 
 
     #if wxUSE_FILEDLG
@@ -266,6 +281,14 @@ bool MyApp::OnInit()
         filedlg_menu->Append(DIALOGS_FILE_OPEN2,  _T("&Second open file\tCtrl-2"));
         filedlg_menu->Append(DIALOGS_FILES_OPEN,  _T("Open &files\tCtrl-Q"));
         filedlg_menu->Append(DIALOGS_FILE_SAVE,  _T("Sa&ve file\tCtrl-S"));
+
+        #if USE_FILEDLG_GENERIC
+            filedlg_menu->AppendSeparator();
+            filedlg_menu->Append(DIALOGS_FILE_OPEN_GENERIC,  _T("&Open file (generic)"));
+            filedlg_menu->Append(DIALOGS_FILES_OPEN_GENERIC,  _T("Open &files (generic)"));
+            filedlg_menu->Append(DIALOGS_FILE_SAVE_GENERIC,  _T("Sa&ve file (generic)"));
+        #endif // USE_FILEDLG_GENERIC
+
         file_menu->Append(wxID_ANY,_T("File operations"),filedlg_menu);
 
     #endif // wxUSE_FILEDLG
@@ -274,14 +297,14 @@ bool MyApp::OnInit()
         wxMenu *dir_menu = new wxMenu;
 
         dir_menu->Append(DIALOGS_DIR_CHOOSE,  _T("&Choose a directory\tCtrl-D"));
+        dir_menu->Append(DIALOGS_DIRNEW_CHOOSE,  _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
+        file_menu->Append(wxID_ANY,_T("Directory operations"),dir_menu);
 
         #if USE_DIRDLG_GENERIC
+            dir_menu->AppendSeparator();
             dir_menu->Append(DIALOGS_GENERIC_DIR_CHOOSE,  _T("&Choose a directory (generic)"));
         #endif // USE_DIRDLG_GENERIC
 
-        dir_menu->Append(DIALOGS_DIRNEW_CHOOSE,  _T("Choose a directory (with \"Ne&w\" button)\tShift-Ctrl-D"));
-        file_menu->Append(wxID_ANY,_T("Directory operations"),dir_menu);
-
     #endif // wxUSE_DIRDLG
 
 
@@ -312,15 +335,15 @@ bool MyApp::OnInit()
 
     #if wxUSE_FINDREPLDLG
         wxMenu *find_menu = new wxMenu;
-        find_menu->Append(DIALOGS_FIND, _T("&Find dialog\tCtrl-F"), wxEmptyString, true);
-        find_menu->Append(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F"), wxEmptyString, true);
+        find_menu->AppendCheckItem(DIALOGS_FIND, _T("&Find dialog\tCtrl-F"));
+        find_menu->AppendCheckItem(DIALOGS_REPLACE, _T("Find and &replace dialog\tShift-Ctrl-F"));
         file_menu->Append(wxID_ANY,_T("Searching"),find_menu);
     #endif // wxUSE_FINDREPLDLG
 
     #if USE_MODAL_PRESENTATION
         wxMenu *modal_menu = new wxMenu;
         modal_menu->Append(DIALOGS_MODAL, _T("Mo&dal dialog\tCtrl-W"));
-        modal_menu->Append(DIALOGS_MODELESS, _T("Modeless &dialog\tCtrl-Z"), wxEmptyString, true);
+        modal_menu->AppendCheckItem(DIALOGS_MODELESS, _T("Modeless &dialog\tCtrl-Z"));
         file_menu->Append(wxID_ANY,_T("Modal/Modeless"),modal_menu);
     #endif // USE_MODAL_PRESENTATION
 
@@ -366,7 +389,9 @@ MyFrame::MyFrame(wxWindow *parent,
     }
 #endif // wxUSE_COLOURDLG
 
+#if wxUSE_STATUSBAR
     CreateStatusBar();
+#endif // wxUSE_STATUSBAR
 }
 
 #if wxUSE_COLOURDLG
@@ -455,6 +480,7 @@ void MyFrame::ChooseFontGeneric(wxCommandEvent& WXUNUSED(event) )
 }
 #endif // USE_FONTDLG_GENERIC
 
+#if wxUSE_LOG_DIALOG
 void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event))
 {
     // calling wxYield() (as ~wxBusyCursor does) shouldn't result in messages
@@ -476,6 +502,7 @@ void MyFrame::LogDialog(wxCommandEvent& WXUNUSED(event))
 
     wxLogMessage(wxT("And this is the same dialog but with only one message."));
 }
+#endif // wxUSE_LOG_DIALOG
 
 void MyFrame::MessageBox(wxCommandEvent& WXUNUSED(event) )
 {
@@ -551,8 +578,7 @@ void MyFrame::TextEntry(wxCommandEvent& WXUNUSED(event))
 
     if (dialog.ShowModal() == wxID_OK)
     {
-        wxMessageDialog dialog2(this, dialog.GetValue(), _T("Got string"));
-        dialog2.ShowModal();
+        wxMessageBox(dialog.GetValue(), _T("Got string"), wxOK | wxICON_INFORMATION, this);
     }
 }
 #endif // wxUSE_TEXTDLG
@@ -621,7 +647,7 @@ void MyFrame::FileOpen(wxCommandEvent& WXUNUSED(event) )
 #ifdef __WXMOTIF__
                     _T("C++ files (*.cpp)|*.cpp")
 #else
-                    _T("C++ files (*.h;*.cpp)|*.h;*.cpp")
+                    _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
 #endif
                  );
 
@@ -672,7 +698,7 @@ void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) )
 #ifdef __WXMOTIF__
                     _T("C++ files (*.cpp)|*.cpp");
 #else
-                    _T("All files (*.*)|*.*|C++ files (*.h;*.cpp)|*.h;*.cpp");
+                    _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
 #endif
     wxFileDialog dialog(this, _T("Testing open multiple file dialog"),
                         wxEmptyString, wxEmptyString, wildcards,
@@ -721,6 +747,84 @@ void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) )
 }
 #endif // wxUSE_FILEDLG
 
+#if USE_FILEDLG_GENERIC
+void MyFrame::FileOpenGeneric(wxCommandEvent& WXUNUSED(event) )
+{
+    wxGenericFileDialog dialog
+                 (
+                    this,
+                    _T("Testing open file dialog"),
+                    wxEmptyString,
+                    wxEmptyString,
+                    _T("C++ files (*.cpp;*.h)|*.cpp;*.h")
+                 );
+
+    dialog.SetDirectory(wxGetHomeDir());
+
+    if (dialog.ShowModal() == wxID_OK)
+    {
+        wxString info;
+        info.Printf(_T("Full file name: %s\n")
+                    _T("Path: %s\n")
+                    _T("Name: %s"),
+                    dialog.GetPath().c_str(),
+                    dialog.GetDirectory().c_str(),
+                    dialog.GetFilename().c_str());
+        wxMessageDialog dialog2(this, info, _T("Selected file"));
+        dialog2.ShowModal();
+    }
+}
+
+void MyFrame::FilesOpenGeneric(wxCommandEvent& WXUNUSED(event) )
+{
+    wxString wildcards = _T("All files (*.*)|*.*|C++ files (*.cpp;*.h)|*.cpp;*.h");
+    wxGenericFileDialog dialog(this, _T("Testing open multiple file dialog"),
+                        wxEmptyString, wxEmptyString, wildcards,
+                        wxMULTIPLE);
+
+    if (dialog.ShowModal() == wxID_OK)
+    {
+        wxArrayString paths, filenames;
+
+        dialog.GetPaths(paths);
+        dialog.GetFilenames(filenames);
+
+        wxString msg, s;
+        size_t count = paths.GetCount();
+        for ( size_t n = 0; n < count; n++ )
+        {
+            s.Printf(_T("File %d: %s (%s)\n"),
+                     (int)n, paths[n].c_str(), filenames[n].c_str());
+
+            msg += s;
+        }
+        s.Printf(_T("Filter index: %d"), dialog.GetFilterIndex());
+        msg += s;
+
+        wxMessageDialog dialog2(this, msg, _T("Selected files"));
+        dialog2.ShowModal();
+    }
+}
+
+void MyFrame::FileSaveGeneric(wxCommandEvent& WXUNUSED(event) )
+{
+    wxGenericFileDialog dialog(this,
+                        _T("Testing save file dialog"),
+                        wxEmptyString,
+                        _T("myletter.doc"),
+                        _T("Text files (*.txt)|*.txt|Document files (*.doc)|*.doc"),
+                        wxSAVE|wxOVERWRITE_PROMPT);
+
+    dialog.SetFilterIndex(1);
+
+    if (dialog.ShowModal() == wxID_OK)
+    {
+        wxLogMessage(_T("%s, filter %d"),
+                     dialog.GetPath().c_str(), dialog.GetFilterIndex());
+    }
+}
+#endif // USE_FILEDLG_GENERIC
+
 #if wxUSE_DIRDLG
 void MyFrame::DoDirChoose(int style)
 {
@@ -1031,9 +1135,16 @@ void MyCanvas::OnPaint(wxPaintEvent& WXUNUSED(event) )
     dc.SetFont(wxGetApp().m_canvasFont);
     dc.SetTextForeground(wxGetApp().m_canvasTextColour);
     dc.SetBackgroundMode(wxTRANSPARENT);
-    dc.DrawText(_T("wxWidgets common dialogs test application"), 10, 10);
+    dc.DrawText(
+                _T("wxWidgets common dialogs")
+#if !defined(__SMARTPHONE__)
+                _T(" test application")
+#endif
+                , 10, 10);
 }
 
+#if USE_MODAL_PRESENTATION
+
 // ----------------------------------------------------------------------------
 // MyModelessDialog
 // ----------------------------------------------------------------------------
@@ -1130,3 +1241,6 @@ void MyModalDialog::OnButton(wxCommandEvent& event)
         event.Skip();
     }
 }
+
+#endif // USE_MODAL_PRESENTATION
+