Fix saving print file to path.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@11122 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Adam Fedor 2001-10-09 04:22:13 +00:00
parent ed5c7ed452
commit 734669301f
5 changed files with 168 additions and 69 deletions

View file

@ -1,3 +1,17 @@
2001-10-08 Adam Fedor <fedor@gnu.org>
* 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 <nicola@brainstorm.co.uk>
* Tools/wgetopt.h: New file copied from base/Testing/wgetopt.h.

View file

@ -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

View file

@ -32,6 +32,7 @@
#include <AppKit/NSPanel.h>
@class NSView;
@class NSPrintInfo;
enum {
NSPPSaveButton = 4,
@ -55,7 +56,7 @@ enum {
NSPPLayoutButton
};
@interface NSPrintPanel : NSPanel <NSCoding>
@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

View file

@ -35,6 +35,7 @@
#include <Foundation/NSException.h>
#include <Foundation/NSThread.h>
#include <Foundation/NSFileManager.h>
#include <Foundation/NSValue.h>
#include <AppKit/AppKitExceptions.h>
#include <AppKit/NSGraphicsContext.h>
#include <AppKit/NSView.h>
@ -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

View file

@ -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