diff --git a/samples/dialogs/dialogs.cpp b/samples/dialogs/dialogs.cpp index d4c8081b01..818a84b8e4 100644 --- a/samples/dialogs/dialogs.cpp +++ b/samples/dialogs/dialogs.cpp @@ -194,6 +194,7 @@ wxBEGIN_EVENT_TABLE(MyFrame, wxFrame) EVT_MENU(DIALOGS_FILE_OPEN, MyFrame::FileOpen) EVT_MENU(DIALOGS_FILE_OPEN2, MyFrame::FileOpen2) EVT_MENU(DIALOGS_FILES_OPEN, MyFrame::FilesOpen) + EVT_MENU(DIALOGS_FILES_OPEN_WINDOW_MODAL, MyFrame::FilesOpenWindowModal) EVT_MENU(DIALOGS_FILE_SAVE, MyFrame::FileSave) #endif // wxUSE_FILEDLG @@ -479,6 +480,7 @@ bool MyApp::OnInit() filedlg_menu->Append(DIALOGS_FILE_OPEN, "&Open file\tCtrl-O"); filedlg_menu->Append(DIALOGS_FILE_OPEN2, "&Second open file\tCtrl-2"); filedlg_menu->Append(DIALOGS_FILES_OPEN, "Open &files\tShift-Ctrl-O"); + filedlg_menu->Append(DIALOGS_FILES_OPEN_WINDOW_MODAL, "Window Modal Open files"); filedlg_menu->Append(DIALOGS_FILE_SAVE, "Sa&ve file\tCtrl-S"); #if USE_FILEDLG_GENERIC @@ -1699,6 +1701,63 @@ void MyFrame::FilesOpen(wxCommandEvent& WXUNUSED(event) ) } } +void MyFrame::FilesOpenWindowModal(wxCommandEvent& WXUNUSED(event) ) +{ + wxString wildcards = +#ifdef __WXMOTIF__ + "C++ files (*.cpp)|*.cpp"; +#else + wxString::Format + ( + "All files (%s)|%s|C++ files (*.cpp;*.h)|*.cpp;*.h", + wxFileSelectorDefaultWildcardStr, + wxFileSelectorDefaultWildcardStr + ); +#endif + wxFileDialog* dialog = new wxFileDialog(this, "Testing open multiple file dialog", + wxEmptyString, wxEmptyString, wildcards, + wxFD_OPEN|wxFD_MULTIPLE); + + dialog->Bind(wxEVT_WINDOW_MODAL_DIALOG_CLOSED, + &MyFrame::FilesOpenWindowModalClosed, this); + + dialog->ShowWindowModal(); +} + +void MyFrame::FilesOpenWindowModalClosed(wxWindowModalDialogEvent& event) +{ + wxFileDialog* dialog = dynamic_cast(event.GetDialog()); + if ( dialog->GetReturnCode() == 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("File %d: %s (%s)\n", + (int)n, paths[n], filenames[n]); + + msg += s; + } + s.Printf("Filter index: %d", dialog->GetFilterIndex()); + msg += s; + + wxMessageDialog dialog2(this, msg, "Selected files"); + dialog2.ShowModal(); + } + else + { + wxLogError("Unexpected window modal wxFileDialog return code!"); + } + delete dialog; +} + + + void MyFrame::FileSave(wxCommandEvent& WXUNUSED(event) ) { wxFileDialog dialog(this, diff --git a/samples/dialogs/dialogs.h b/samples/dialogs/dialogs.h index 3b058c1cca..02767526b2 100644 --- a/samples/dialogs/dialogs.h +++ b/samples/dialogs/dialogs.h @@ -422,6 +422,8 @@ public: void FileOpen(wxCommandEvent& event); void FileOpen2(wxCommandEvent& event); void FilesOpen(wxCommandEvent& event); + void FilesOpenWindowModal(wxCommandEvent& event); + void FilesOpenWindowModalClosed(wxWindowModalDialogEvent& event); void FileSave(wxCommandEvent& event); #endif // wxUSE_FILEDLG @@ -596,6 +598,7 @@ enum DIALOGS_FILE_OPEN, DIALOGS_FILE_OPEN2, DIALOGS_FILES_OPEN, + DIALOGS_FILES_OPEN_WINDOW_MODAL, DIALOGS_FILE_SAVE, DIALOGS_FILE_OPEN_GENERIC, DIALOGS_FILES_OPEN_GENERIC,