From 947848a1dd47b81092bebe435ec60e7c771c55a0 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 7 Apr 2007 16:05:11 +0000 Subject: [PATCH] added MacOpenURL() (patch 1235957) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@45306 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/mac/carbon/app.h | 3 +++ src/mac/carbon/app.cpp | 41 +++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/include/wx/mac/carbon/app.h b/include/wx/mac/carbon/app.h index 492a713004..8d294d803d 100644 --- a/include/wx/mac/carbon/app.h +++ b/include/wx/mac/carbon/app.h @@ -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 diff --git a/src/mac/carbon/app.cpp b/src/mac/carbon/app.cpp index ec3b13491d..e04d27946c 100644 --- a/src/mac/carbon/app.cpp +++ b/src/mac/carbon/app.cpp @@ -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 ) ; -- 2.45.2