]> git.saurik.com Git - wxWidgets.git/commitdiff
Add the ability to trigger a print from JavaScript for the OSX backend of the wxWebVi...
authorRobin Dunn <robin@alldunn.com>
Fri, 3 Aug 2012 03:56:59 +0000 (03:56 +0000)
committerRobin Dunn <robin@alldunn.com>
Fri, 3 Aug 2012 03:56:59 +0000 (03:56 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@72284 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

src/osx/webview_webkit.mm

index 0b31750b679510010b2f9454678c2de889bcfaef..3b869b6f32ee9edb1292579843adcc018226a093 100644 (file)
@@ -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<wxWebViewHandler>, 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