mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 02:50:48 +00:00
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:
parent
ed5c7ed452
commit
734669301f
5 changed files with 168 additions and 69 deletions
14
ChangeLog
14
ChangeLog
|
@ -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>
|
Mon Oct 8 14:50:44 2001 Nicola Pero <nicola@brainstorm.co.uk>
|
||||||
|
|
||||||
* Tools/wgetopt.h: New file copied from base/Testing/wgetopt.h.
|
* Tools/wgetopt.h: New file copied from base/Testing/wgetopt.h.
|
||||||
|
|
|
@ -155,6 +155,12 @@ typedef enum _NSPrintingPageOrder {
|
||||||
- (void)cleanUpOperation;
|
- (void)cleanUpOperation;
|
||||||
- (BOOL)deliverResult;
|
- (BOOL)deliverResult;
|
||||||
- (BOOL)runOperation;
|
- (BOOL)runOperation;
|
||||||
|
#ifndef STRICT_OPENSTEP
|
||||||
|
- (void)runOperationModalForWindow: (NSWindow *)docWindow
|
||||||
|
delegate: (id)delegate
|
||||||
|
didRunSelector: (SEL)didRunSelector
|
||||||
|
contextInfo:(void *)contextInfo;
|
||||||
|
#endif
|
||||||
|
|
||||||
//
|
//
|
||||||
// Getting the NSPrintInfo Object
|
// Getting the NSPrintInfo Object
|
||||||
|
|
|
@ -32,6 +32,7 @@
|
||||||
#include <AppKit/NSPanel.h>
|
#include <AppKit/NSPanel.h>
|
||||||
|
|
||||||
@class NSView;
|
@class NSView;
|
||||||
|
@class NSPrintInfo;
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
NSPPSaveButton = 4,
|
NSPPSaveButton = 4,
|
||||||
|
@ -55,7 +56,7 @@ enum {
|
||||||
NSPPLayoutButton
|
NSPPLayoutButton
|
||||||
};
|
};
|
||||||
|
|
||||||
@interface NSPrintPanel : NSPanel <NSCoding>
|
@interface NSPrintPanel : NSPanel
|
||||||
{
|
{
|
||||||
id _cancelButton;
|
id _cancelButton;
|
||||||
id _copiesField;
|
id _copiesField;
|
||||||
|
@ -91,12 +92,19 @@ enum {
|
||||||
//
|
//
|
||||||
// Running the Panel
|
// Running the Panel
|
||||||
//
|
//
|
||||||
- (int)runModal;
|
- (int) runModal;
|
||||||
- (void)pickedButton:(id)sender;
|
#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
|
// Updating the Panel's Display
|
||||||
//
|
//
|
||||||
|
- (void)pickedButton:(id)sender;
|
||||||
- (void)pickedAllPages:(id)sender;
|
- (void)pickedAllPages:(id)sender;
|
||||||
- (void)pickedLayoutList:(id)sender;
|
- (void)pickedLayoutList:(id)sender;
|
||||||
|
|
||||||
|
@ -106,12 +114,6 @@ enum {
|
||||||
- (void)updateFromPrintInfo;
|
- (void)updateFromPrintInfo;
|
||||||
- (void)finalWritePrintInfo;
|
- (void)finalWritePrintInfo;
|
||||||
|
|
||||||
//
|
|
||||||
// NSCoding protocol
|
|
||||||
//
|
|
||||||
- (void)encodeWithCoder:aCoder;
|
|
||||||
- initWithCoder:aDecoder;
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
#endif // _GNUstep_H_NSPrintPanel
|
#endif // _GNUstep_H_NSPrintPanel
|
||||||
|
|
|
@ -35,6 +35,7 @@
|
||||||
#include <Foundation/NSException.h>
|
#include <Foundation/NSException.h>
|
||||||
#include <Foundation/NSThread.h>
|
#include <Foundation/NSThread.h>
|
||||||
#include <Foundation/NSFileManager.h>
|
#include <Foundation/NSFileManager.h>
|
||||||
|
#include <Foundation/NSValue.h>
|
||||||
#include <AppKit/AppKitExceptions.h>
|
#include <AppKit/AppKitExceptions.h>
|
||||||
#include <AppKit/NSGraphicsContext.h>
|
#include <AppKit/NSGraphicsContext.h>
|
||||||
#include <AppKit/NSView.h>
|
#include <AppKit/NSView.h>
|
||||||
|
@ -307,7 +308,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
//
|
//
|
||||||
- (NSGraphicsContext*)createContext
|
- (NSGraphicsContext*)createContext
|
||||||
{
|
{
|
||||||
// FIXME
|
[self subclassResponsibility: _cmd];
|
||||||
return nil;
|
return nil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -355,62 +356,116 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
return YES;
|
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)runOperation
|
||||||
{
|
{
|
||||||
BOOL result;
|
BOOL result;
|
||||||
NSString *clocale;
|
|
||||||
|
|
||||||
if (_showPanels)
|
if (_showPanels)
|
||||||
{
|
{
|
||||||
NSPrintPanel *panel = [self printPanel];
|
NSPrintPanel *panel = [self printPanel];
|
||||||
int button;
|
int button;
|
||||||
|
|
||||||
|
[panel setAccessoryView: _accessoryView];
|
||||||
|
[panel updateFromPrintInfo];
|
||||||
|
button = [panel runModal];
|
||||||
|
[panel setAccessoryView: nil];
|
||||||
|
|
||||||
[panel setAccessoryView: _accessoryView];
|
if (button != NSOKButton)
|
||||||
[panel updateFromPrintInfo];
|
|
||||||
button = [panel runModal];
|
|
||||||
[panel setAccessoryView: nil];
|
|
||||||
/*
|
|
||||||
if (button != NSOKButton)
|
|
||||||
{
|
{
|
||||||
[self cleanUpOperation];
|
[self cleanUpOperation];
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
*/
|
[panel finalWritePrintInfo];
|
||||||
[panel finalWritePrintInfo];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSIGN(_context, [self createContext]);
|
result = NO;
|
||||||
|
if ([self _runOperation])
|
||||||
if (_context != nil)
|
result = [self deliverResult];
|
||||||
{
|
|
||||||
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];
|
|
||||||
[self cleanUpOperation];
|
[self cleanUpOperation];
|
||||||
|
|
||||||
return result;
|
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
|
// Getting the NSPrintInfo Object
|
||||||
//
|
//
|
||||||
|
@ -453,7 +508,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
_rect = rect;
|
_rect = rect;
|
||||||
ASSIGN(_data, data);
|
ASSIGN(_data, data);
|
||||||
_pageOrder = NSUnknownPageOrder;
|
_pageOrder = NSUnknownPageOrder;
|
||||||
_showPanels = YES;
|
_showPanels = NO;
|
||||||
[self setPrintInfo: aPrintInfo];
|
[self setPrintInfo: aPrintInfo];
|
||||||
|
|
||||||
ASSIGN(_path, @"/tmp/NSTempPrintFile");
|
ASSIGN(_path, @"/tmp/NSTempPrintFile");
|
||||||
|
@ -465,8 +520,16 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
|
|
||||||
- (void) _print
|
- (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];
|
[_view displayRectIgnoringOpacity: _rect];
|
||||||
|
|
||||||
|
GSSetLocale(clocale);
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -490,13 +553,25 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
|
|
||||||
- (NSGraphicsContext*)createContext
|
- (NSGraphicsContext*)createContext
|
||||||
{
|
{
|
||||||
NSMutableDictionary *info = [_printInfo dictionary];
|
NSMutableDictionary *info;
|
||||||
NSGraphicsContext *psContext;
|
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"];
|
[info setObject: _path forKey: @"NSOutputFile"];
|
||||||
psContext = [NSGraphicsContext postscriptContextWithInfo: info];
|
_context = RETAIN([NSGraphicsContext postscriptContextWithInfo: info]);
|
||||||
|
|
||||||
return psContext;
|
return _context;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)deliverResult
|
- (BOOL)deliverResult
|
||||||
|
|
|
@ -159,6 +159,23 @@
|
||||||
return (_picked == NSCancelButton) ? NSCancelButton : NSOKButton;
|
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
|
- (BOOL) _getSavePath
|
||||||
{
|
{
|
||||||
int result;
|
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
|
@end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue