]> git.saurik.com Git - wxWidgets.git/commitdiff
added MacOpenURL() (patch 1235957)
authorVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Apr 2007 16:05:11 +0000 (16:05 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sat, 7 Apr 2007 16:05:11 +0000 (16:05 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45306 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/mac/carbon/app.h
src/mac/carbon/app.cpp

index 492a71300478060951ca0c10ccd4df30caf7e619..8d294d803da720dad1f0c5b24993d0873b5dc39d 100644 (file)
@@ -112,6 +112,7 @@ public:
     bool    MacSendCharEvent( wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar ) ;
     void    MacCreateKeyEvent( wxKeyEvent& event, wxWindow* focus , long keymessage , long modifiers , long when , short wherex , short wherey , wxChar uniChar ) ;
     virtual short         MacHandleAEODoc(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ;
+    virtual short         MacHandleAEGURL(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ;
     virtual short         MacHandleAEPDoc(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ;
     virtual short         MacHandleAEOApp(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ;
     virtual short         MacHandleAEQuit(const WXAPPLEEVENTREF event , WXAPPLEEVENTREF reply) ;
@@ -119,6 +120,8 @@ public:
 
     // in response of an open-document apple event
     virtual void         MacOpenFile(const wxString &fileName) ;
+    // in response of a get-url apple event
+    virtual void         MacOpenURL(const wxString &url) ;
     // in response of a print-document apple event
     virtual void         MacPrintFile(const wxString &fileName) ;
     // in response of a open-application apple event
index ec3b13491db7072b9617971dc61d5797a4ddece0..e04d27946cc7a21ef06f892782fcb1f8ce409e87 100644 (file)
@@ -133,6 +133,12 @@ pascal OSErr AEHandleRApp( const AppleEvent *event , AppleEvent *reply , SRefCon
     return wxTheApp->MacHandleAERApp( (AppleEvent*) event , reply) ;
 }
 
+pascal OSErr AEHandleGURL( const AppleEvent *event , AppleEvent *reply , long WXUNUSED(refcon) )
+{
+    return wxTheApp->MacHandleAEGURL((WXEVENTREF *)event , reply) ;
+}
+
+
 // AEODoc Calls MacOpenFile on each of the files passed
 
 short wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply))
@@ -174,6 +180,31 @@ short wxApp::MacHandleAEODoc(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply))
     return noErr;
 }
 
+// AEODoc Calls MacOpenURL on the url passed
+
+short wxApp::MacHandleAEGURL(const WXEVENTREF event, WXEVENTREF WXUNUSED(reply))
+{
+    DescType returnedType;
+    Size actualSize;
+    char url[255];
+    OSErr err = AEGetParamPtr((AppleEvent *)event, keyDirectObject, typeChar,
+                              &returnedType, url, sizeof(url)-1,
+                              &actualSize);
+    if (err != noErr)
+        return err;
+
+    url[actualSize] = '\0';    // Terminate the C string 
+
+    ProcessSerialNumber PSN ;
+    PSN.highLongOfPSN = 0 ;
+    PSN.lowLongOfPSN = kCurrentProcess ;
+    SetFrontProcess( &PSN ) ;
+
+    MacOpenURL(wxString(url, wxConvUTF8));
+
+    return noErr;
+}
+
 // AEPDoc Calls MacPrintFile on each of the files passed
 
 short wxApp::MacHandleAEPDoc(const WXEVENTREF event , WXEVENTREF WXUNUSED(reply))
@@ -264,6 +295,9 @@ void wxApp::MacOpenFile(const wxString & fileName )
 #endif
 }
 
+void wxApp::MacOpenURL(const wxString & url )
+{
+}
 
 void wxApp::MacPrintFile(const wxString & fileName )
 {
@@ -860,6 +894,7 @@ bool wxApp::Initialize(int& argc, wxChar **argv)
 }
 
 AEEventHandlerUPP sODocHandler = NULL ;
+AEEventHandlerUPP sGURLHandler = NULL ;
 AEEventHandlerUPP sOAppHandler = NULL ;
 AEEventHandlerUPP sPDocHandler = NULL ;
 AEEventHandlerUPP sRAppHandler = NULL ;
@@ -882,6 +917,7 @@ bool wxApp::OnInitGui()
     if (!sm_isEmbedded)
     {
         sODocHandler = NewAEEventHandlerUPP(AEHandleODoc) ;
+        sGURLHandler = NewAEEventHandlerUPP(AEHandleGURL) ;
         sOAppHandler = NewAEEventHandlerUPP(AEHandleOApp) ;
         sPDocHandler = NewAEEventHandlerUPP(AEHandlePDoc) ;
         sRAppHandler = NewAEEventHandlerUPP(AEHandleRApp) ;
@@ -889,6 +925,8 @@ bool wxApp::OnInitGui()
 
         AEInstallEventHandler( kCoreEventClass , kAEOpenDocuments ,
                                sODocHandler , 0 , FALSE ) ;
+        AEInstallEventHandler( kInternetEventClass, kAEGetURL,
+                               sGURLHandler , 0 , FALSE ) ;
         AEInstallEventHandler( kCoreEventClass , kAEOpenApplication ,
                                sOAppHandler , 0 , FALSE ) ;
         AEInstallEventHandler( kCoreEventClass , kAEPrintDocuments ,
@@ -937,6 +975,8 @@ void wxApp::CleanUp()
     {
         AERemoveEventHandler( kCoreEventClass , kAEOpenDocuments ,
                                sODocHandler , FALSE ) ;
+        AERemoveEventHandler( kInternetEventClass, kAEGetURL,
+                               sGURLHandler , FALSE ) ;
         AERemoveEventHandler( kCoreEventClass , kAEOpenApplication ,
                                sOAppHandler , FALSE ) ;
         AERemoveEventHandler( kCoreEventClass , kAEPrintDocuments ,
@@ -947,6 +987,7 @@ void wxApp::CleanUp()
                                sQuitHandler , FALSE ) ;
 
         DisposeAEEventHandlerUPP( sODocHandler ) ;
+        DisposeAEEventHandlerUPP( sGURLHandler ) ;
         DisposeAEEventHandlerUPP( sOAppHandler ) ;
         DisposeAEEventHandlerUPP( sPDocHandler ) ;
         DisposeAEEventHandlerUPP( sRAppHandler ) ;