]> git.saurik.com Git - wxWidgets.git/commitdiff
Added NSApplicationDelegate's openFiles for wxOSX-Cocoa.
authorDimitri Schoolwerth <dimitri.schoolwerth@gmail.com>
Tue, 9 Aug 2011 22:17:12 +0000 (22:17 +0000)
committerDimitri Schoolwerth <dimitri.schoolwerth@gmail.com>
Tue, 9 Aug 2011 22:17:12 +0000 (22:17 +0000)
openFiles (available since OS X 10.3) replaces using the openFile method. It allows for more convenient handling of multiple drops and knowing in advance how much files/folders are dropped instead of openFile with which you only get to respond to a single file/folder drop at a time. By default openFiles calls the newly added MacOpenFiles which calls MacOpenFile multiple times, so ordinarily the behaviour is backwards compatible (both on wxOSX Cocoa and Carbon).

The openFile instance method has been removed because it doesn't seem to be called anymore: neither when dropping a single file on the application in the dock or Finder nor when passed as a command-line argument.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@68617 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/changes.txt
include/wx/osx/app.h
interface/wx/app.h
samples/mediaplayer/mediaplayer.cpp
src/osx/carbon/app.cpp
src/osx/cocoa/utils.mm
utils/helpview/src/helpview.cpp
utils/helpview/src/helpview.h

index d467990b48b34c58d141736e1a581bc16e0e34c1..51b18681d4d1c684e1fc8c825fc8e1dfef37bdf6 100644 (file)
@@ -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:
 
index 47315c6b6277fee9210a6c84dde609fb2373cf30..011d0dd021fcaf4596e849228dfb43d0c6310420 100644 (file)
@@ -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) ;
index f3530be2913045e75f629640ac7cae84d38de238..d5badd57d1b2dd08539b7c57cd32d820cb64ff38 100644 (file)
@@ -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.
index 1ca1da55f633e42ce629afd10f3dfdd72e5a99d7..1d1698363e51394f6b486490f568844d86837860 100644 (file)
@@ -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__
index cf1e53b104bb1fb5b42b7b7d8292aeb4f630f082..722f9cc2f899f7c3bf024da32a3d0521e90765ac 100644 (file)
@@ -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
index c7879d0e6bacc5af3e881aed6017b229b40b01c3..cb71db77a3ddf87f4c6620d97abec03cebb9a968 100644 (file)
@@ -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
index c774b628fac5ccdd546df6f6bc8c98be9c04de50..ecd2a732f0800963c6d72985f5d78f6785998816 100644 (file)
@@ -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();
 }
index 2d020e78cb13d9d9be6ffc3b9f57df53687b3da8..7b30b795f5af323b77eb7dc99db48d622bcb856b 100644 (file)
@@ -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