mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 20:00:48 +00:00
Printing impl.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@14862 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
c7efda6fab
commit
3766e95ce1
4 changed files with 135 additions and 28 deletions
15
ChangeLog
15
ChangeLog
|
@ -1,3 +1,18 @@
|
||||||
|
2002-10-28 Adam Fedor <fedor@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSScreen.m (-visibleFrame): Don't include dock
|
||||||
|
with NexT/WindowMaker styles (patch from Stefan <urbanek@host.sk>).
|
||||||
|
|
||||||
|
2002-10-28 Adam Fedor <fedor@gnu.org>
|
||||||
|
|
||||||
|
* Source/NSPrintOperation.m (-cleanUpOperation): Order out print
|
||||||
|
panel.
|
||||||
|
(-_runOperation): Use autorelease pool around operation.
|
||||||
|
(-init): Create a proper, unique temp print file.
|
||||||
|
(-deliverResult): Implement for previewing, spooling.
|
||||||
|
* Source/NSPrintPanel.m (-runModel): Don't order self out.
|
||||||
|
(-_setStatusStringValue:) New private method.
|
||||||
|
|
||||||
2002-10-28 Richard Frith-Macdonald <rfm@gnu.org>
|
2002-10-28 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/NSTextField.m: ([-dealloc]) morph self to be an NSTextView
|
* Source/NSTextField.m: ([-dealloc]) morph self to be an NSTextView
|
||||||
|
|
|
@ -34,17 +34,23 @@
|
||||||
#include <Foundation/NSString.h>
|
#include <Foundation/NSString.h>
|
||||||
#include <Foundation/NSDebug.h>
|
#include <Foundation/NSDebug.h>
|
||||||
#include <Foundation/NSData.h>
|
#include <Foundation/NSData.h>
|
||||||
#include <Foundation/NSException.h>
|
|
||||||
#include <Foundation/NSThread.h>
|
|
||||||
#include <Foundation/NSFileManager.h>
|
#include <Foundation/NSFileManager.h>
|
||||||
|
#include <Foundation/NSException.h>
|
||||||
|
#include <Foundation/NSPathUtilities.h>
|
||||||
|
#include <Foundation/NSTask.h>
|
||||||
|
#include <Foundation/NSThread.h>
|
||||||
|
#include <Foundation/NSUserDefaults.h>
|
||||||
#include <Foundation/NSValue.h>
|
#include <Foundation/NSValue.h>
|
||||||
#include <AppKit/AppKitExceptions.h>
|
#include <AppKit/AppKitExceptions.h>
|
||||||
#include <AppKit/NSAffineTransform.h>
|
#include <AppKit/NSAffineTransform.h>
|
||||||
|
#include <AppKit/NSApplication.h>
|
||||||
#include <AppKit/NSGraphicsContext.h>
|
#include <AppKit/NSGraphicsContext.h>
|
||||||
#include <AppKit/NSView.h>
|
#include <AppKit/NSView.h>
|
||||||
|
#include <AppKit/NSPrinter.h>
|
||||||
#include <AppKit/NSPrintPanel.h>
|
#include <AppKit/NSPrintPanel.h>
|
||||||
#include <AppKit/NSPrintInfo.h>
|
#include <AppKit/NSPrintInfo.h>
|
||||||
#include <AppKit/NSPrintOperation.h>
|
#include <AppKit/NSPrintOperation.h>
|
||||||
|
#include <AppKit/NSWorkspace.h>
|
||||||
#include <AppKit/PSOperators.h>
|
#include <AppKit/PSOperators.h>
|
||||||
|
|
||||||
#include <gnustep/base/GSLocale.h>
|
#include <gnustep/base/GSLocale.h>
|
||||||
|
@ -82,6 +88,11 @@ typedef struct _page_info_t {
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@interface NSPrintPanel (Private)
|
||||||
|
- (void) _setStatusStringValue: (NSString *)string;
|
||||||
|
@end
|
||||||
|
|
||||||
|
|
||||||
@interface NSView (NSPrintOperation)
|
@interface NSView (NSPrintOperation)
|
||||||
- (void) _displayPageInRect: (NSRect)pageRect
|
- (void) _displayPageInRect: (NSRect)pageRect
|
||||||
atPlacement: (NSPoint)location
|
atPlacement: (NSPoint)location
|
||||||
|
@ -435,11 +446,12 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
//
|
//
|
||||||
// Running a Print Operation
|
// Running a Print Operation
|
||||||
//
|
//
|
||||||
/** Called by the print operation and it has finished running a printing
|
/** Called by the print operation after it has finished running a printing
|
||||||
operation.
|
operation.
|
||||||
*/
|
*/
|
||||||
- (void)cleanUpOperation
|
- (void)cleanUpOperation
|
||||||
{
|
{
|
||||||
|
[[self printPanel] orderOut: self];
|
||||||
_currentPage = 0;
|
_currentPage = 0;
|
||||||
[NSPrintOperation setCurrentOperation: nil];
|
[NSPrintOperation setCurrentOperation: nil];
|
||||||
}
|
}
|
||||||
|
@ -454,10 +466,13 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Private method to run the printing operation */
|
/* Private method to run the printing operation. Needs to create an
|
||||||
|
autoreleaes pool to make sure the print context is destroyed before
|
||||||
|
returning (which closes the print file.) */
|
||||||
- (BOOL) _runOperation
|
- (BOOL) _runOperation
|
||||||
{
|
{
|
||||||
BOOL result;
|
BOOL result;
|
||||||
|
CREATE_AUTORELEASE_POOL(pool);
|
||||||
NSGraphicsContext *oldContext = [NSGraphicsContext currentContext];
|
NSGraphicsContext *oldContext = [NSGraphicsContext currentContext];
|
||||||
|
|
||||||
[self createContext];
|
[self createContext];
|
||||||
|
@ -490,6 +505,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
}
|
}
|
||||||
NS_ENDHANDLER
|
NS_ENDHANDLER
|
||||||
[self destroyContext];
|
[self destroyContext];
|
||||||
|
RELEASE(pool);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -651,7 +667,11 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
||||||
_showPanels = NO;
|
_showPanels = NO;
|
||||||
[self setPrintInfo: aPrintInfo];
|
[self setPrintInfo: aPrintInfo];
|
||||||
|
|
||||||
ASSIGN(_path, @"/tmp/NSTempPrintFile");
|
_path = [NSTemporaryDirectory() stringByAppendingPathComponent: @"GSPrint-"];
|
||||||
|
_path = [_path stringByAppendingString:
|
||||||
|
[[NSProcessInfo processInfo] globallyUniqueString]];
|
||||||
|
_path = [_path stringByAppendingPathExtension: @"ps"];
|
||||||
|
RETAIN(_path);
|
||||||
_pathSet = NO;
|
_pathSet = NO;
|
||||||
_currentPage = 0;
|
_currentPage = 0;
|
||||||
|
|
||||||
|
@ -948,8 +968,9 @@ scaleRect(NSRect rect, double scale)
|
||||||
last: _currentPage
|
last: _currentPage
|
||||||
info: &info];
|
info: &info];
|
||||||
}
|
}
|
||||||
NSDebugLLog(@"NSPrinting", @" current page %d, rect %@",
|
|
||||||
_currentPage, NSStringFromRect(pageRect));
|
NSDebugLLog(@"NSPrinting", @" current page %d, rect %@",
|
||||||
|
_currentPage, NSStringFromRect(pageRect));
|
||||||
if (NSIsEmptyRect(pageRect))
|
if (NSIsEmptyRect(pageRect))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -1028,7 +1049,6 @@ scaleRect(NSRect rect, double scale)
|
||||||
label: label
|
label: label
|
||||||
bBox: info.sheetBounds
|
bBox: info.sheetBounds
|
||||||
fonts: nil];
|
fonts: nil];
|
||||||
DPSPrintf(ctxt, "/__GSsheetsaveobject save def\n");
|
|
||||||
if (info.orient == NSLandscapeOrientation)
|
if (info.orient == NSLandscapeOrientation)
|
||||||
{
|
{
|
||||||
DPSrotate(ctxt, 90);
|
DPSrotate(ctxt, 90);
|
||||||
|
@ -1095,7 +1115,6 @@ scaleRect(NSRect rect, double scale)
|
||||||
NSPrintOperation *printOp = [NSPrintOperation currentOperation];
|
NSPrintOperation *printOp = [NSPrintOperation currentOperation];
|
||||||
if ([printOp isEPSOperation] == NO)
|
if ([printOp isEPSOperation] == NO)
|
||||||
DPSPrintf(ctxt, "showpage\n");
|
DPSPrintf(ctxt, "showpage\n");
|
||||||
DPSPrintf(ctxt, "__GSsheetsaveobject restore\n");
|
|
||||||
DPSPrintf(ctxt, "%%%%PageTrailer\n");
|
DPSPrintf(ctxt, "%%%%PageTrailer\n");
|
||||||
DPSPrintf(ctxt, "\n");
|
DPSPrintf(ctxt, "\n");
|
||||||
}
|
}
|
||||||
|
@ -1143,16 +1162,88 @@ scaleRect(NSRect rect, double scale)
|
||||||
return _context;
|
return _context;
|
||||||
}
|
}
|
||||||
|
|
||||||
- (BOOL)deliverResult
|
- (BOOL) _deliverSpooledResult
|
||||||
{
|
{
|
||||||
// FIXME
|
int copies;
|
||||||
|
NSDictionary *dict;
|
||||||
|
NSTask *task;
|
||||||
|
NSString *name, *status;
|
||||||
|
NSMutableArray *args;
|
||||||
|
name = [[_printInfo printer] name];
|
||||||
|
status = [NSString stringWithFormat: @"Spooling to printer %@.", name];
|
||||||
|
[_printPanel _setStatusStringValue: status];
|
||||||
|
|
||||||
/*
|
dict = [_printInfo dictionary];
|
||||||
|
args = [NSMutableArray array];
|
||||||
|
copies = [[dict objectForKey: NSPrintCopies] intValue];
|
||||||
|
if (copies > 1)
|
||||||
|
[args addObject: [NSString stringWithFormat: @"-#%0d", copies]];
|
||||||
|
if ([name isEqual: @"Unknown"] == NO)
|
||||||
|
{
|
||||||
|
[args addObject: @"-P"];
|
||||||
|
[args addObject: name];
|
||||||
|
}
|
||||||
|
[args addObject: _path];
|
||||||
|
|
||||||
|
task = [NSTask new];
|
||||||
|
[task setLaunchPath: @"lpr"];
|
||||||
|
[task setArguments: args];
|
||||||
|
[task launch];
|
||||||
|
[task waitUntilExit];
|
||||||
|
AUTORELEASE(task);
|
||||||
|
return YES;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL) deliverResult
|
||||||
|
{
|
||||||
|
BOOL success;
|
||||||
|
NSString *job;
|
||||||
|
|
||||||
|
success = YES;
|
||||||
|
job = [_printInfo jobDisposition];
|
||||||
|
if ([job isEqual: NSPrintPreviewJob])
|
||||||
|
{
|
||||||
|
/* Check to see if there is a GNUstep app that can preview PS files.
|
||||||
|
It's not likely at this point, so also check for a standards
|
||||||
|
previewer, like gv.
|
||||||
|
*/
|
||||||
|
NSTask *task;
|
||||||
|
NSString *preview;
|
||||||
|
NSWorkspace *ws = [NSWorkspace sharedWorkspace];
|
||||||
|
[_printPanel _setStatusStringValue: @"Opening in previewer..."];
|
||||||
|
preview = [ws getBestAppInRole: @"Viewer" forExtension: @"ps"];
|
||||||
|
if (preview)
|
||||||
|
{
|
||||||
|
[ws openFile: _path withApplication: preview];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
|
||||||
|
preview = [def objectForKey: @"NSPreviewApp"];
|
||||||
|
if (preview == nil || [preview length] == 0)
|
||||||
|
preview = @"gv";
|
||||||
|
task = [NSTask new];
|
||||||
|
[task setLaunchPath: preview];
|
||||||
|
[task setArguments: [NSArray arrayWithObject: _path]];
|
||||||
|
[task launch];
|
||||||
|
AUTORELEASE(task);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if ([job isEqual: NSPrintSpoolJob])
|
||||||
|
{
|
||||||
|
sucess = [self _deliverSpooledResult];
|
||||||
|
}
|
||||||
|
else if ([job isEqual: NSPrintFaxJob])
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
/* We can't remove the temp file because the previewer might still be
|
||||||
|
using it, perhaps the printer is also?
|
||||||
if (!_pathSet)
|
if (!_pathSet)
|
||||||
[[NSFileManager defaultManager] removeFileAtPath: _path
|
[[NSFileManager defaultManager] removeFileAtPath: _path
|
||||||
handler: nil];
|
handler: nil];
|
||||||
*/
|
*/
|
||||||
return YES;
|
return success;
|
||||||
}
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -1232,7 +1323,6 @@ scaleRect(NSRect rect, double scale)
|
||||||
- (NSGraphicsContext*)createContext
|
- (NSGraphicsContext*)createContext
|
||||||
{
|
{
|
||||||
NSMutableDictionary *info;
|
NSMutableDictionary *info;
|
||||||
NSAutoreleasePool *pool;
|
|
||||||
|
|
||||||
if (_context)
|
if (_context)
|
||||||
return _context;
|
return _context;
|
||||||
|
@ -1242,12 +1332,7 @@ scaleRect(NSRect rect, double scale)
|
||||||
[info setObject: _path forKey: @"NSOutputFile"];
|
[info setObject: _path forKey: @"NSOutputFile"];
|
||||||
[info setObject: NSGraphicsContextPSFormat
|
[info setObject: NSGraphicsContextPSFormat
|
||||||
forKey: NSGraphicsContextRepresentationFormatAttributeName];
|
forKey: NSGraphicsContextRepresentationFormatAttributeName];
|
||||||
/* We have to remove the autorelease from the context, because we need the
|
|
||||||
contents of the file before the next return to the run loop */
|
|
||||||
pool = [NSAutoreleasePool new];
|
|
||||||
_context = RETAIN([NSGraphicsContext graphicsContextWithAttributes: info]);
|
_context = RETAIN([NSGraphicsContext graphicsContextWithAttributes: info]);
|
||||||
[pool release];
|
|
||||||
|
|
||||||
return _context;
|
return _context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -179,14 +179,16 @@ static NSPrintPanel *shared_instance;
|
||||||
/** Display the Print panel in a modal loop. Saves any aquired
|
/** Display the Print panel in a modal loop. Saves any aquired
|
||||||
information in the NSPrintInfo object for the current NSPrintOperation.
|
information in the NSPrintInfo object for the current NSPrintOperation.
|
||||||
Returns NSCancelButton if the user clicks the Cancel button or
|
Returns NSCancelButton if the user clicks the Cancel button or
|
||||||
NSOKButton otherwise.
|
NSOKButton otherwise. Unlike other panels, this one does not order
|
||||||
|
itself out after the modal session is finished. You must do that
|
||||||
|
yourself.
|
||||||
*/
|
*/
|
||||||
- (int)runModal
|
- (int)runModal
|
||||||
{
|
{
|
||||||
_picked = NSOKButton;
|
_picked = NSOKButton;
|
||||||
[NSApp runModalForWindow: self];
|
[NSApp runModalForWindow: self];
|
||||||
[_optionPanel orderOut: self];
|
[_optionPanel orderOut: self];
|
||||||
[self orderOut: self];
|
/* Don't order ourselves out, let the NSPrintOperation do that */
|
||||||
return (_picked == NSCancelButton) ? NSCancelButton : NSOKButton;
|
return (_picked == NSCancelButton) ? NSCancelButton : NSOKButton;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -240,10 +242,6 @@ static NSPrintPanel *shared_instance;
|
||||||
else if (tag == NSPPPreviewButton)
|
else if (tag == NSPPPreviewButton)
|
||||||
{
|
{
|
||||||
_picked = NSPPPreviewButton;
|
_picked = NSPPPreviewButton;
|
||||||
NSRunAlertPanel(@"Sorry", @"Previewing of print file not implemented",
|
|
||||||
@"OK", NULL, NULL);
|
|
||||||
/* Don't stop the modal session */
|
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
else if (tag ==NSFaxButton )
|
else if (tag ==NSFaxButton )
|
||||||
{
|
{
|
||||||
|
@ -623,4 +621,9 @@ static NSPrintPanel *shared_instance;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Private method for NSPrintOperation */
|
||||||
|
- (void) _setStatusStringValue: (NSString *)string
|
||||||
|
{
|
||||||
|
[CONTROL(self, NSPPStatusField) setStringValue: string ];
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
|
@ -268,14 +268,18 @@ static NSMutableArray *screenArray = nil;
|
||||||
{
|
{
|
||||||
NSRect visFrame = _frame;
|
NSRect visFrame = _frame;
|
||||||
|
|
||||||
switch ([NSApp interfaceStyle])
|
switch (NSInterfaceStyleForKey(@"NSIntefaceStyle", nil))
|
||||||
{
|
{
|
||||||
case NSMacintoshInterfaceStyle:
|
case NSMacintoshInterfaceStyle:
|
||||||
// What is the size of the Mac menubar?
|
// What is the size of the Mac menubar?
|
||||||
visFrame.size.height -= 25;
|
visFrame.size.height -= 25;
|
||||||
return visFrame;
|
return visFrame;
|
||||||
case NSWindows95InterfaceStyle:
|
case GSWindowMakerInterfaceStyle:
|
||||||
case NSNextStepInterfaceStyle:
|
case NSNextStepInterfaceStyle:
|
||||||
|
visFrame.size.width -= 64;
|
||||||
|
return visFrame;
|
||||||
|
|
||||||
|
case NSWindows95InterfaceStyle:
|
||||||
case NSNoInterfaceStyle:
|
case NSNoInterfaceStyle:
|
||||||
default:
|
default:
|
||||||
return _frame;
|
return _frame;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue