Revision: 7009
http://skim-app.svn.sourceforge.net/skim-app/?rev=7009&view=rev
Author: hofman
Date: 2010-12-23 12:54:17 +0000 (Thu, 23 Dec 2010)
Log Message:
-----------
reorganize code for printing, especially for callback preparation and invocation
Modified Paths:
--------------
trunk/SKMainDocument.m
Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m 2010-12-22 19:05:39 UTC (rev 7008)
+++ trunk/SKMainDocument.m 2010-12-23 12:54:17 UTC (rev 7009)
@@ -867,20 +867,27 @@
#pragma mark Printing
+static inline void invokePrintCallback(NSInvocation *callback, BOOL didPrint) {
+ [callback setArgument:&didPrint atIndex:3];
+ [callback performSelector:@selector(invoke) withObject:nil afterDelay:0.0];
+}
+
- (void)handleWindowDidEndPrintSheetNotification:(NSNotification
*)notification {
- if (notification)
- [[NSNotificationCenter defaultCenter] removeObserver:self
name:NSWindowDidEndSheetNotification object:[notification object]];
- if (printCallback) {
- BOOL didPrint = YES;
- [printCallback setArgument:&didPrint atIndex:3];
- [printCallback performSelector:@selector(invoke) withObject:nil
afterDelay:0.0];
- SKDESTROY(printCallback);
- }
+ [[NSNotificationCenter defaultCenter] removeObserver:self
name:NSWindowDidEndSheetNotification object:[notification object]];
+ invokePrintCallback(printCallback, YES);
+ SKDESTROY(printCallback);
}
- (void)printDocumentWithSettings:(NSDictionary *)printSettings
showPrintPanel:(BOOL)showPrintPanel delegate:(id)delegate
didPrintSelector:(SEL)didPrintSelector contextInfo:(void *)contextInfo {
NSWindow *printWindow = [[self pdfView] window];
- if ([[self pdfDocument] allowsPrinting] && (showPrintPanel == NO ||
[printWindow attachedSheet] == nil)) {
+ NSInvocation *callback = nil;
+ if (delegate && didPrintSelector) {
+ callback = [NSInvocation invocationWithTarget:delegate
selector:didPrintSelector argument:&self];
+ [callback setArgument:&contextInfo atIndex:4];
+ }
+ if ([[self pdfDocument] allowsPrinting] == NO || (showPrintPanel &&
[printWindow attachedSheet])) {
+ invokePrintCallback(callback, NO);
+ } else if (callback) {
NSPrintInfo *printInfo = [[[self printInfo] copy] autorelease];
NSMutableDictionary *infoDict = [printInfo dictionary];
@@ -890,23 +897,14 @@
[[self pdfView] printWithInfo:printInfo autoRotate:YES
pageScaling:kPDFPrintPageScaleNone];
- if (delegate && didPrintSelector) {
- printCallback = [[NSInvocation invocationWithTarget:delegate
selector:didPrintSelector] retain];
- [printCallback setArgument:&self atIndex:2];
- [printCallback setArgument:&contextInfo atIndex:4];
- NSWindow *printWindow = [[self pdfView] window];
- if (showPrintPanel && [printWindow attachedSheet])
+ if (callback) {
+ if (showPrintPanel && [printWindow attachedSheet]) {
+ printCallback = [callback retain];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(handleWindowDidEndPrintSheetNotification:)
name:NSWindowDidEndSheetNotification object:printWindow];
- else
- [self handleWindowDidEndPrintSheetNotification:nil];
+ } else {
+ invokePrintCallback(callback, YES);
+ }
}
- } else if (delegate && didPrintSelector) {
- BOOL didPrint = NO;
- NSInvocation *callback = [NSInvocation invocationWithTarget:delegate
selector:didPrintSelector];
- [callback setArgument:&self atIndex:2];
- [callback setArgument:&didPrint atIndex:3];
- [callback setArgument:&contextInfo atIndex:4];
- [callback invoke];
}
}
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Learn how Oracle Real Application Clusters (RAC) One Node allows customers
to consolidate database storage, standardize their database environment, and,
should the need arise, upgrade to a full multi-node Oracle RAC database
without downtime or disruption
http://p.sf.net/sfu/oracle-sfdevnl
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit