Move WebView related print support to OakHTMLOutputView

This commit is contained in:
Allan Odgaard
2014-09-10 14:02:08 +02:00
parent 707da020bb
commit 73b21bd836
2 changed files with 20 additions and 39 deletions

View File

@@ -471,10 +471,6 @@ BOOL HasDocumentWindow (NSArray* windows)
[item updateTitle:[NSString stringWithCxxString:name_with_selection(bundleItem, [textView hasSelection])]];
}
}
else if([item action] == @selector(printDocument:))
{
enabled = [self findPrintableView:[NSApp keyWindow]] != nil;
}
return enabled;
}
@@ -502,39 +498,4 @@ BOOL HasDocumentWindow (NSArray* windows)
{
[[NSPageLayout pageLayout] runModal];
}
- (NSView*)findPrintableView:(NSWindow*)aWindow
{
NSRect rect = [aWindow.contentView frame];
for(NSView* view = [aWindow.contentView hitTest:NSMakePoint(NSMidX(rect), NSMidY(rect))]; view; view = [view superview])
{
if([view acceptsFirstResponder] && [view respondsToSelector:@selector(printDocument:)] || [view conformsToProtocol:@protocol(WebDocumentView)])
return view;
}
return nil;
}
- (void)printDocument:(id)sender
{
id view = [self findPrintableView:[NSApp keyWindow]];
if([view respondsToSelector:@selector(printDocument:)])
{
[view printDocument:sender];
}
else if([view conformsToProtocol:@protocol(WebDocumentView)])
{
NSPrintOperation* printer = [NSPrintOperation printOperationWithView:view];
[[printer printPanel] setOptions:[[printer printPanel] options] | NSPrintPanelShowsPaperSize | NSPrintPanelShowsOrientation];
NSPrintInfo* info = [printer printInfo];
NSRect display = NSIntersectionRect(info.imageablePageBounds, (NSRect){ NSZeroPoint, info.paperSize });
info.leftMargin = NSMinX(display);
info.rightMargin = info.paperSize.width - NSMaxX(display);
info.topMargin = info.paperSize.height - NSMaxY(display);
info.bottomMargin = NSMinY(display);
[printer runOperationModalForWindow:[view window] delegate:nil didRunSelector:NULL contextInfo:nil];
}
}
@end

View File

@@ -138,4 +138,24 @@ extern NSString* const kCommandRunnerURLScheme; // from HTMLOutput.h
}
}
}
// ====================
// = Printing Support =
// ====================
- (IBAction)printDocument:(id)sender
{
NSPrintOperation* printer = [NSPrintOperation printOperationWithView:self.webView.mainFrame.frameView.documentView];
[[printer printPanel] setOptions:[[printer printPanel] options] | NSPrintPanelShowsPaperSize | NSPrintPanelShowsOrientation];
NSPrintInfo* info = [printer printInfo];
NSRect display = NSIntersectionRect(info.imageablePageBounds, (NSRect){ NSZeroPoint, info.paperSize });
info.leftMargin = NSMinX(display);
info.rightMargin = info.paperSize.width - NSMaxX(display);
info.topMargin = info.paperSize.height - NSMaxY(display);
info.bottomMargin = NSMinY(display);
[printer runOperationModalForWindow:self.window delegate:nil didRunSelector:NULL contextInfo:nil];
}
@end