diff --git a/docs/changes.txt b/docs/changes.txt index d467990b48..51b18681d4 100644 --- a/docs/changes.txt +++ b/docs/changes.txt @@ -459,6 +459,7 @@ OSX: - Implement wxFileType::GetOpenCommand(). - wxGetOsVersion() now returns more sensible version numbers, e.g. 10 and 6 for OS X 10.6. +- Added wxApp::MacOpenFiles and deprecated wxApp::MacOpenFile. GTK: diff --git a/include/wx/osx/app.h b/include/wx/osx/app.h index 47315c6b62..011d0dd021 100644 --- a/include/wx/osx/app.h +++ b/include/wx/osx/app.h @@ -122,7 +122,10 @@ public: virtual short MacHandleAEQuit(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ; virtual short MacHandleAERApp(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ; #endif - // in response of an open-document apple event + // in response of an openFiles message with Cocoa and an + // open-document apple event with Carbon + virtual void MacOpenFiles(const wxArrayString &fileNames) ; + // called by MacOpenFiles for each file. virtual void MacOpenFile(const wxString &fileName) ; // in response of a get-url apple event virtual void MacOpenURL(const wxString &url) ; diff --git a/interface/wx/app.h b/interface/wx/app.h index f3530be291..d5badd57d1 100644 --- a/interface/wx/app.h +++ b/interface/wx/app.h @@ -569,7 +569,7 @@ public: Under Windows and Linux/Unix, you should parse the command line arguments and check for files to be opened when starting your - application. Under OS X, you need to override MacOpenFile() + application. Under OS X, you need to override MacOpenFiles() since command line arguments are used differently there. You may use the wxCmdLineParser to parse command line arguments. @@ -802,16 +802,35 @@ public: */ virtual void MacNewFile(); + /** + Called in response of an openFiles message with Cocoa, or an + "open-document" Apple event with Carbon. + + You need to override this method in order to open one or more document + files after the user double clicked on it or if the files and/or + folders were dropped on either the application in the dock or the + application icon in Finder. + + By default this method calls MacOpenFile for each file/folder. + + @onlyfor{wxosx} + + @since 2.9.3 + */ + virtual void MacOpenFiles(const wxArrayString& fileNames); + /** Called in response of an "open-document" Apple event. - You need to override this method in order to open a document file after the - user double clicked on it or if the document file was dropped on either the - running application or the application icon in Finder. + @deprecated + This function is kept mostly for backwards compatibility. Please + override wxApp::MacOpenFiles method instead in any new code. @onlyfor{wxosx} */ - virtual void MacOpenFile(const wxString& fileName); + wxDEPRECATED_BUT_USED_INTERNALLY( + virtual void MacOpenFile(const wxString& fileName) + ); /** Called in response of a "get-url" Apple event. diff --git a/samples/mediaplayer/mediaplayer.cpp b/samples/mediaplayer/mediaplayer.cpp index 1ca1da55f6..1d1698363e 100644 --- a/samples/mediaplayer/mediaplayer.cpp +++ b/samples/mediaplayer/mediaplayer.cpp @@ -143,7 +143,7 @@ class wxMediaPlayerApp : public wxApp { public: #ifdef __WXMAC__ - virtual void MacOpenFile(const wxString & fileName ); + virtual void MacOpenFiles(const wxArrayString & fileNames ); #endif virtual bool OnInit(); @@ -463,10 +463,10 @@ bool wxMediaPlayerApp::OnInit() #ifdef __WXMAC__ -void wxMediaPlayerApp::MacOpenFile(const wxString & fileName ) +void wxMediaPlayerApp::MacOpenFiles(const wxArrayString & fileNames ) { - // Called when a user drags a file over our app - m_frame->DoOpenFile(fileName, true /* new page */); + // Called when a user drags files over our app + m_frame->DoOpenFile(fileNames[0], true /* new page */); } #endif // __WXMAC__ diff --git a/src/osx/carbon/app.cpp b/src/osx/carbon/app.cpp index cf1e53b104..722f9cc2f8 100644 --- a/src/osx/carbon/app.cpp +++ b/src/osx/carbon/app.cpp @@ -130,7 +130,7 @@ pascal OSErr AEHandleGURL( const AppleEvent *event , AppleEvent *reply , SRefCon } -// AEODoc Calls MacOpenFile on each of the files passed +// AEODoc Calls MacOpenFiles with all of the files passed short wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply)) { @@ -158,6 +158,7 @@ short wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply)) wxString fName ; FSRef theRef ; + wxArrayString fileNames; for (i = 1; i <= itemsInList; i++) { AEGetNthPtr( @@ -165,9 +166,11 @@ short wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply)) (Ptr)&theRef, sizeof(theRef), &actualSize); fName = wxMacFSRefToPath( &theRef ) ; - MacOpenFile(fName); + fileNames.Add(fName); } + MacOpenFiles(fileNames); + return noErr; } @@ -274,6 +277,16 @@ short wxApp::MacHandleAERApp(const WXEVENTREF WXUNUSED(event) , WXEVENTREF WXUNU // Support Routines linking the Mac...File Calls to the Document Manager //---------------------------------------------------------------------- +void wxApp::MacOpenFiles(const wxArrayString & fileNames ) +{ + size_t i; + const size_t fileCount = fileNames.GetCount(); + for (i = 0; i < fileCount; i++) + { + MacOpenFile(fileNames[i]); + } +} + void wxApp::MacOpenFile(const wxString & fileName ) { #if wxUSE_DOC_VIEW_ARCHITECTURE diff --git a/src/osx/cocoa/utils.mm b/src/osx/cocoa/utils.mm index c7879d0e6b..cb71db77a3 100644 --- a/src/osx/cocoa/utils.mm +++ b/src/osx/cocoa/utils.mm @@ -55,12 +55,18 @@ void wxBell() wxUnusedVar(application); } -- (BOOL)application:(NSApplication *)sender openFile:(NSString *)filename +- (void)application:(NSApplication *)sender openFiles:(NSArray *)fileNames { wxUnusedVar(sender); - wxCFStringRef cf(wxCFRetain(filename)); - wxTheApp->MacOpenFile(cf.AsString()) ; - return YES; + wxArrayString fileList; + size_t i; + const size_t count = [fileNames count]; + for (i = 0; i < count; i++) + { + fileList.Add( wxCFStringRef::AsString([fileNames objectAtIndex:i]) ); + } + + wxTheApp->MacOpenFiles(fileList); } - (BOOL)applicationShouldOpenUntitledFile:(NSApplication *)sender diff --git a/utils/helpview/src/helpview.cpp b/utils/helpview/src/helpview.cpp index c774b628fa..ecd2a732f0 100644 --- a/utils/helpview/src/helpview.cpp +++ b/utils/helpview/src/helpview.cpp @@ -279,10 +279,10 @@ bool hvApp::OpenBook(wxHtmlHelpController* controller) #ifdef __WXMAC__ /// Respond to Apple Event for opening a document -void hvApp::MacOpenFile(const wxString& filename) +void hvApp::MacOpenFiles(const wxArrayString& fileNames) { wxBusyCursor bcur; - wxFileName fileName(filename); + wxFileName fileName(fileNames[0]); m_helpController->AddBook(fileName); m_helpController->DisplayContents(); } diff --git a/utils/helpview/src/helpview.h b/utils/helpview/src/helpview.h index 2d020e78cb..7b30b795f5 100644 --- a/utils/helpview/src/helpview.h +++ b/utils/helpview/src/helpview.h @@ -36,7 +36,7 @@ public: #ifdef __WXMAC__ /// Respond to Apple Event for opening a document - virtual void MacOpenFile(const wxString& filename); + virtual void MacOpenFiles(const wxArrayString& fileNames); #endif /// Prompt the user for a book to open