]> git.saurik.com Git - wxWidgets.git/commitdiff
Move wxMacExecute into base
authorRyan Norton <wxprojects@comcast.net>
Fri, 22 Apr 2005 15:19:11 +0000 (15:19 +0000)
committerRyan Norton <wxprojects@comcast.net>
Fri, 22 Apr 2005 15:19:11 +0000 (15:19 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@33836 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/mac/corefoundation/hid.cpp
src/mac/corefoundation/utilsexc_cf.cpp

index d824a0a0f511de6e15e42a67787a2165abdb9dba..b19859b6572396f690269f3a918943492210c466 100644 (file)
@@ -568,4 +568,118 @@ bool wxGetKeyState (wxKeyCode key)
     }
 }
 
+//
+// TODO: Find a better file to put this in
+//
+#include "wx/intl.h"
+
+#ifdef __WXCOCOA__
+#include <CoreFoundation/CoreFoundation.h>
+#include <ApplicationServices/ApplicationServices.h>
+#else
+#include "wx/mac/private.h"
+#include "LaunchServices.h"
+#endif
+
+#include "wx/uri.h"
+#include "wx/mac/corefoundation/cfstring.h"
+
+long wxMacExecute(wxChar **argv,
+               int flags,
+               wxProcess *process)
+{
+    CFIndex cfiCount = 0;
+    //get count
+    for(wxChar** argvcopy = argv; *argvcopy != NULL ; ++argvcopy)
+    {
+        ++cfiCount;
+    }
+
+    if(cfiCount == 0) //no file to launch?
+    {
+        wxLogDebug(wxT("wxMacExecute No file to launch!"));
+        return -1;
+    }
+    
+    CFURLRef cfurlApp = CFURLCreateWithString(
+            kCFAllocatorDefault,
+            wxMacCFStringHolder(*argv++, wxLocale::GetSystemEncoding()),
+            NULL);
+    wxASSERT(cfurlApp);
+
+    CFBundleRef cfbApp = CFBundleCreate(kCFAllocatorDefault, cfurlApp);
+    if(!cfbApp)
+    {
+        wxLogDebug(wxT("wxMacExecute Bad bundle"));
+        CFRelease(cfurlApp);
+        return -1;
+    }
+    
+    
+    UInt32 dwBundleType, dwBundleCreator;
+    CFBundleGetPackageInfo(cfbApp, &dwBundleType, &dwBundleCreator);
+
+    //Only call wxMacExecute for .app bundles - others could be actual unix programs
+    if(dwBundleType != 'APPL')
+    {
+        CFRelease(cfurlApp);
+        return -1;
+    }
+    
+    //
+    // We have a good bundle - so let's launch it!
+    //
+    
+    CFMutableArrayRef cfaFiles = CFArrayCreateMutable(kCFAllocatorDefault, cfiCount - 1, NULL);
+            
+    wxASSERT(cfaFiles);
+    
+    if(--cfiCount)
+    {
+        for( ; *argv != NULL ; ++argv)
+        {
+//            wxLogDebug(*argv);
+            wxString sCurrentFile;
+            
+            if(wxURI(*argv).IsReference())
+                sCurrentFile = wxString(wxT("file://")) + *argv;
+            else
+                sCurrentFile = *argv;
+                
+            CFURLRef cfurlCurrentFile =   CFURLCreateWithString(
+                    kCFAllocatorDefault,
+                    wxMacCFStringHolder(sCurrentFile, wxLocale::GetSystemEncoding()),
+                    NULL);
+            wxASSERT(cfurlCurrentFile);
+
+            CFArrayAppendValue(
+                cfaFiles,
+                cfurlCurrentFile
+                            );
+        }
+    }
+    
+    LSLaunchURLSpec launchspec;
+    launchspec.appURL = cfurlApp;
+    launchspec.itemURLs = cfaFiles;
+    launchspec.passThruParams = NULL; //AEDesc* 
+    launchspec.launchFlags = kLSLaunchDefaults | kLSLaunchDontSwitch;  //TODO:  Possibly be smarter with flags
+    launchspec.asyncRefCon = NULL;
+    
+    OSStatus status = LSOpenFromURLSpec(&launchspec,
+                        NULL); //2nd is CFURLRef* really launched
+
+    //cleanup
+    CFRelease(cfurlApp);
+    CFRelease(cfaFiles);
+    
+    //check for error
+    if(status != noErr)
+    {
+        wxLogDebug(wxString::Format(wxT("wxMacExecute ERROR: %d")), (int)status);
+        return -1;
+    }
+    return 0; //success
+}
+
 #endif //__DARWIN__
index bb6e19d6ed6634495c95295aa8363abe827b6e94..12f26671c083311af375a6eb3a42a9ec875bdc76 100644 (file)
 #include "wx/stdpaths.h"
 #include "wx/apptrait.h"
 
-#ifdef __WXCOCOA__
-#include <CoreFoundation/CoreFoundation.h>
-#include <ApplicationServices/ApplicationServices.h>
-#else
-#include "wx/mac/private.h"
-#include "LaunchServices.h"
-#endif
-
-#include "wx/uri.h"
-#include "wx/mac/corefoundation/cfstring.h"
-
-long wxMacExecute(wxChar **argv,
-               int flags,
-               wxProcess *process)
-{
-    CFIndex cfiCount = 0;
-    //get count
-    for(wxChar** argvcopy = argv; *argvcopy != NULL ; ++argvcopy)
-    {
-        ++cfiCount;
-    }
-
-    if(cfiCount == 0) //no file to launch?
-    {
-        wxLogDebug(wxT("wxMacExecute No file to launch!"));
-        return -1;
-    }
-    
-    CFURLRef cfurlApp = CFURLCreateWithString(
-            kCFAllocatorDefault,
-            wxMacCFStringHolder(*argv++, wxLocale::GetSystemEncoding()),
-            NULL);
-    wxASSERT(cfurlApp);
-
-    CFBundleRef cfbApp = CFBundleCreate(kCFAllocatorDefault, cfurlApp);
-    if(!cfbApp)
-    {
-        wxLogDebug(wxT("wxMacExecute Bad bundle"));
-        CFRelease(cfurlApp);
-        return -1;
-    }
-    
-    
-    UInt32 dwBundleType, dwBundleCreator;
-    CFBundleGetPackageInfo(cfbApp, &dwBundleType, &dwBundleCreator);
-
-    //Only call wxMacExecute for .app bundles - others could be actual unix programs
-    if(dwBundleType != 'APPL')
-    {
-        CFRelease(cfurlApp);
-        return -1;
-    }
-    
-    //
-    // We have a good bundle - so let's launch it!
-    //
-    
-    CFMutableArrayRef cfaFiles = CFArrayCreateMutable(kCFAllocatorDefault, cfiCount - 1, NULL);
-            
-    wxASSERT(cfaFiles);
-    
-    if(--cfiCount)
-    {
-        for( ; *argv != NULL ; ++argv)
-        {
-//            wxLogDebug(*argv);
-            wxString sCurrentFile;
-            
-            if(wxURI(*argv).IsReference())
-                sCurrentFile = wxString(wxT("file://")) + *argv;
-            else
-                sCurrentFile = *argv;
-                
-            CFURLRef cfurlCurrentFile =   CFURLCreateWithString(
-                    kCFAllocatorDefault,
-                    wxMacCFStringHolder(sCurrentFile, wxLocale::GetSystemEncoding()),
-                    NULL);
-            wxASSERT(cfurlCurrentFile);
-
-            CFArrayAppendValue(
-                cfaFiles,
-                cfurlCurrentFile
-                            );
-        }
-    }
-    
-    LSLaunchURLSpec launchspec;
-    launchspec.appURL = cfurlApp;
-    launchspec.itemURLs = cfaFiles;
-    launchspec.passThruParams = NULL; //AEDesc* 
-    launchspec.launchFlags = kLSLaunchDefaults | kLSLaunchDontSwitch;  //TODO:  Possibly be smarter with flags
-    launchspec.asyncRefCon = NULL;
-    
-    OSStatus status = LSOpenFromURLSpec(&launchspec,
-                        NULL); //2nd is CFURLRef* really launched
-
-    //cleanup
-    CFRelease(cfurlApp);
-    CFRelease(cfaFiles);
-    
-    //check for error
-    if(status != noErr)
-    {
-        wxLogDebug(wxString::Format(wxT("wxMacExecute ERROR: %d")), (int)status);
-        return -1;
-    }
-    return 0; //success
-}
 
 
 #include <CoreFoundation/CFMachPort.h>