diff --git a/ChangeLog b/ChangeLog index 88d2d5062..64e338a57 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2001-10-08 Adam Fedor + + * Source/NSPrintOperation (_runOperation): New internal method. + (runOperation): Use it. + (-runOperationModalForWindow:delegate:didRunSelector:contextInfo:): + Implement. + (-createContext): Use our context if already created. Set the + path from the NSPrintInfo object if available. + + * Source/NSPrintPanel.m + (beginSheetWithPrintInfo:modalForWindow:delegate:didEndSelector: + contextInfo:): Implement. + Remove coding methods. + Mon Oct 8 14:50:44 2001 Nicola Pero * Tools/wgetopt.h: New file copied from base/Testing/wgetopt.h. diff --git a/Headers/gnustep/gui/NSPrintOperation.h b/Headers/gnustep/gui/NSPrintOperation.h index 4aa161a6c..4ad986c1f 100644 --- a/Headers/gnustep/gui/NSPrintOperation.h +++ b/Headers/gnustep/gui/NSPrintOperation.h @@ -155,6 +155,12 @@ typedef enum _NSPrintingPageOrder { - (void)cleanUpOperation; - (BOOL)deliverResult; - (BOOL)runOperation; +#ifndef STRICT_OPENSTEP +- (void)runOperationModalForWindow: (NSWindow *)docWindow + delegate: (id)delegate + didRunSelector: (SEL)didRunSelector + contextInfo:(void *)contextInfo; +#endif // // Getting the NSPrintInfo Object diff --git a/Headers/gnustep/gui/NSPrintPanel.h b/Headers/gnustep/gui/NSPrintPanel.h index 7ebedeec7..ca0acf92c 100644 --- a/Headers/gnustep/gui/NSPrintPanel.h +++ b/Headers/gnustep/gui/NSPrintPanel.h @@ -32,6 +32,7 @@ #include @class NSView; +@class NSPrintInfo; enum { NSPPSaveButton = 4, @@ -55,7 +56,7 @@ enum { NSPPLayoutButton }; -@interface NSPrintPanel : NSPanel +@interface NSPrintPanel : NSPanel { id _cancelButton; id _copiesField; @@ -91,12 +92,19 @@ enum { // // Running the Panel // -- (int)runModal; -- (void)pickedButton:(id)sender; +- (int) runModal; +#ifndef STRICT_OPENSTEP +- (void) beginSheetWithPrintInfo: (NSPrintInfo *)printInfo + modalForWindow: (NSWindow *)docWindow + delegate: (id)delegate + didEndSelector: (SEL)didEndSelector + contextInfo: (void *)contextInfo; +#endif // // Updating the Panel's Display // +- (void)pickedButton:(id)sender; - (void)pickedAllPages:(id)sender; - (void)pickedLayoutList:(id)sender; @@ -106,12 +114,6 @@ enum { - (void)updateFromPrintInfo; - (void)finalWritePrintInfo; -// -// NSCoding protocol -// -- (void)encodeWithCoder:aCoder; -- initWithCoder:aDecoder; - @end #endif // _GNUstep_H_NSPrintPanel diff --git a/Source/NSPrintOperation.m b/Source/NSPrintOperation.m index 45688d9f4..e86b20eb9 100644 --- a/Source/NSPrintOperation.m +++ b/Source/NSPrintOperation.m @@ -35,6 +35,7 @@ #include #include #include +#include #include #include #include @@ -307,7 +308,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; // - (NSGraphicsContext*)createContext { - // FIXME + [self subclassResponsibility: _cmd]; return nil; } @@ -355,62 +356,116 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; return YES; } +- (BOOL) _runOperation +{ + BOOL result; + NSGraphicsContext *oldContext = [NSGraphicsContext currentContext]; + + [self createContext]; + if (_context == nil) + return NO; + + result = NO; + [NSGraphicsContext setCurrentContext: _context]; + NS_DURING + { + [self _print]; + result = YES; + } + NS_HANDLER + { + NSRunAlertPanel(@"Error", @"Printing error: %@", + @"OK", NULL, NULL, localException); + } + NS_ENDHANDLER + [NSGraphicsContext setCurrentContext: oldContext]; + [self destroyContext]; + return result; +} + - (BOOL)runOperation { BOOL result; - NSString *clocale; if (_showPanels) { - NSPrintPanel *panel = [self printPanel]; - int button; + NSPrintPanel *panel = [self printPanel]; + int button; + + [panel setAccessoryView: _accessoryView]; + [panel updateFromPrintInfo]; + button = [panel runModal]; + [panel setAccessoryView: nil]; - [panel setAccessoryView: _accessoryView]; - [panel updateFromPrintInfo]; - button = [panel runModal]; - [panel setAccessoryView: nil]; -/* - if (button != NSOKButton) + if (button != NSOKButton) { [self cleanUpOperation]; return NO; } -*/ - [panel finalWritePrintInfo]; + [panel finalWritePrintInfo]; } - ASSIGN(_context, [self createContext]); - - if (_context != nil) - { - NSGraphicsContext *oldContext = [NSGraphicsContext currentContext]; - - /* Reset the current locale to a generic C locale so numbers - get printed correctly for PostScript (maybe we should only - set the numeric locale?). Save the current locale for later */ - clocale = GSSetLocale(nil); - GSSetLocale(@"C"); - [NSGraphicsContext setCurrentContext: _context]; - NS_DURING - { - [self _print]; - } - NS_HANDLER - { - NSLog(@"Error while printing: %@\n", localException); - } - NS_ENDHANDLER - GSSetLocale(clocale); - [NSGraphicsContext setCurrentContext: oldContext]; - [self destroyContext]; - } - - result = [self deliverResult]; + result = NO; + if ([self _runOperation]) + result = [self deliverResult]; [self cleanUpOperation]; return result; } +- (void)_printOperationDidRun:(NSPrintOperation *)printOperation + success:(BOOL)success + contextInfo:(void *)contextInfo +{ + id delegate; + SEL *didRunSelector; + NSMutableDictionary *dict; + if (success == YES) + { + NSPrintPanel *panel = [self printPanel]; + [panel finalWritePrintInfo]; + success = NO; + if ([self _runOperation]) + success = [self deliverResult]; + } + [self cleanUpOperation]; + dict = [_printInfo dictionary]; + didRunSelector = [[dict objectForKey: @"GSModalRunSelector"] pointerValue]; + delegate = [dict objectForKey: @"GSModalRunDelegate"]; + [delegate performSelector: *didRunSelector + withObject: success + withObject: contextInfo]; +} + +- (void)runOperationModalForWindow: (NSWindow *)docWindow + delegate: (id)delegate + didRunSelector: (SEL)didRunSelector + contextInfo:(void *)contextInfo +{ + NSMutableDictionary *dict; + NSPrintPanel *panel = [self printPanel]; + + /* Save the selector so we can use it later */ + dict = [_printInfo dictionary]; + [dict setObject: [NSValue value: &didRunSelector withObjCType: @encode(SEL)] + forKey: @"GSModalRunSelector"]; + [dict setObject: delegate + forKey: @"GSModalRunDelegate"]; + + /* Assume we want to show the panel regardless of the value + of _showPanels + */ + [panel setAccessoryView: _accessoryView]; + [panel updateFromPrintInfo]; + [panel beginSheetWithPrintInfo: _printInfo + modalForWindow: docWindow + delegate: delegate + didEndSelector: + @selector(_printOperationDidRun:sucess:contextInfo:) + contextInfo: contextInfo]; + [panel setAccessoryView: nil]; +} + // // Getting the NSPrintInfo Object // @@ -453,7 +508,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; _rect = rect; ASSIGN(_data, data); _pageOrder = NSUnknownPageOrder; - _showPanels = YES; + _showPanels = NO; [self setPrintInfo: aPrintInfo]; ASSIGN(_path, @"/tmp/NSTempPrintFile"); @@ -465,8 +520,16 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; - (void) _print { - // This is the actual printing + NSString *clocale; + /* Reset the current locale to a generic C locale so numbers + get printed correctly for PostScript (maybe we should only + set the numeric locale?). Save the current locale for later. */ + clocale = GSSetLocale(nil); + GSSetLocale(@"C"); + [_view displayRectIgnoringOpacity: _rect]; + + GSSetLocale(clocale); } @end @@ -490,13 +553,25 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey"; - (NSGraphicsContext*)createContext { - NSMutableDictionary *info = [_printInfo dictionary]; - NSGraphicsContext *psContext; + NSMutableDictionary *info; + if (_context) + return _context; + + info = [_printInfo dictionary]; + if (_pathSet == NO) + { + NSString *output = [info objectForKey: NSPrintSavePath]; + if (output) + { + ASSIGN(_path, output); + _pathSet = YES; + } + } [info setObject: _path forKey: @"NSOutputFile"]; - psContext = [NSGraphicsContext postscriptContextWithInfo: info]; + _context = RETAIN([NSGraphicsContext postscriptContextWithInfo: info]); - return psContext; + return _context; } - (BOOL)deliverResult diff --git a/Source/NSPrintPanel.m b/Source/NSPrintPanel.m index 8e05fe744..d2800d914 100644 --- a/Source/NSPrintPanel.m +++ b/Source/NSPrintPanel.m @@ -159,6 +159,23 @@ return (_picked == NSCancelButton) ? NSCancelButton : NSOKButton; } +- (void) beginSheetWithPrintInfo: (NSPrintInfo *)printInfo + modalForWindow: (NSWindow *)docWindow + delegate: (id)delegate + didEndSelector: (SEL)didEndSelector + contextInfo: (void *)contextInfo +{ + _picked = NSCancelButton; + // FIXME: We should probably arrange to call endSheet instead of stopModal + [NSApp beginSheet: self + modalForWindow: docWindow + modalDelegate: delegate + didEndSelector: didEndSelector + contextInfo: contextInfo]; + [self orderOut: self]; +} + + - (BOOL) _getSavePath { int result; @@ -502,19 +519,4 @@ } -// -// NSCoding protocol -// -- (void) encodeWithCoder: (NSCoder*)aCoder -{ - [super encodeWithCoder: aCoder]; -} - -- (id) initWithCoder: (NSCoder*)aDecoder -{ - [super initWithCoder: aDecoder]; - - return self; -} - @end