From a1534b369cd9aabdee18827bb4f43d1db5e8dc82 Mon Sep 17 00:00:00 2001 From: Robin Dunn Date: Fri, 3 Aug 2012 03:56:59 +0000 Subject: [PATCH] Add the ability to trigger a print from JavaScript for the OSX backend of the wxWebView control. Closes #14241 git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72284 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/osx/webview_webkit.mm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/src/osx/webview_webkit.mm b/src/osx/webview_webkit.mm index 0b31750b67..3b869b6f32 100644 --- a/src/osx/webview_webkit.mm +++ b/src/osx/webview_webkit.mm @@ -310,6 +310,15 @@ DEFINE_ONE_SHOT_HANDLER_GETTER( wxWebViewWebKitEventHandler ) @end +@interface WebViewUIDelegate : NSObject +{ + wxWebViewWebKit* webKitWindow; +} + +- initWithWxWindow: (wxWebViewWebKit*)inWindow; + +@end + //We use a hash to map scheme names to wxWebViewHandler WX_DECLARE_STRING_HASH_MAP(wxSharedPtr, wxStringToWebHandlerMap); @@ -381,6 +390,11 @@ bool wxWebViewWebKit::Create(wxWindow *parent, [m_webView setPolicyDelegate:policyDelegate]; + WebViewUIDelegate* uiDelegate = + [[WebViewUIDelegate alloc] initWithWxWindow: this]; + + [m_webView setUIDelegate:uiDelegate]; + //Register our own class for custom scheme handling [NSURLProtocol registerClass:[WebViewCustomProtocol class]]; @@ -392,14 +406,19 @@ wxWebViewWebKit::~wxWebViewWebKit() { WebViewLoadDelegate* loadDelegate = [m_webView frameLoadDelegate]; WebViewPolicyDelegate* policyDelegate = [m_webView policyDelegate]; + WebViewUIDelegate* uiDelegate = [m_webView UIDelegate]; [m_webView setFrameLoadDelegate: nil]; [m_webView setPolicyDelegate: nil]; + [m_webView setUIDelegate: nil]; if (loadDelegate) [loadDelegate release]; if (policyDelegate) [policyDelegate release]; + + if (uiDelegate) + [uiDelegate release]; } // ---------------------------------------------------------------------------- @@ -1310,4 +1329,23 @@ wxString nsErrorToWxHtmlError(NSError* error, wxWebViewNavigationError* out) @end + +@implementation WebViewUIDelegate + +- initWithWxWindow: (wxWebViewWebKit*)inWindow +{ + [super init]; + webKitWindow = inWindow; // non retained + return self; +} + +- (void)webView:(WebView *)sender printFrameView:(WebFrameView *)frameView +{ + wxUnusedVar(sender); + wxUnusedVar(frameView); + + webKitWindow->Print(); +} +@end + #endif //wxUSE_WEBVIEW && wxUSE_WEBVIEW_WEBKIT -- 2.45.2