mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-23 15:11:37 +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
c6cf00fc56
commit
cce683f608
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>
|
||||
|
||||
* Source/NSTextField.m: ([-dealloc]) morph self to be an NSTextView
|
||||
|
|
|
@ -34,17 +34,23 @@
|
|||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSThread.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 <AppKit/AppKitExceptions.h>
|
||||
#include <AppKit/NSAffineTransform.h>
|
||||
#include <AppKit/NSApplication.h>
|
||||
#include <AppKit/NSGraphicsContext.h>
|
||||
#include <AppKit/NSView.h>
|
||||
#include <AppKit/NSPrinter.h>
|
||||
#include <AppKit/NSPrintPanel.h>
|
||||
#include <AppKit/NSPrintInfo.h>
|
||||
#include <AppKit/NSPrintOperation.h>
|
||||
#include <AppKit/NSWorkspace.h>
|
||||
#include <AppKit/PSOperators.h>
|
||||
|
||||
#include <gnustep/base/GSLocale.h>
|
||||
|
@ -82,6 +88,11 @@ typedef struct _page_info_t {
|
|||
|
||||
@end
|
||||
|
||||
@interface NSPrintPanel (Private)
|
||||
- (void) _setStatusStringValue: (NSString *)string;
|
||||
@end
|
||||
|
||||
|
||||
@interface NSView (NSPrintOperation)
|
||||
- (void) _displayPageInRect: (NSRect)pageRect
|
||||
atPlacement: (NSPoint)location
|
||||
|
@ -435,11 +446,12 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
|||
//
|
||||
// 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.
|
||||
*/
|
||||
- (void)cleanUpOperation
|
||||
{
|
||||
[[self printPanel] orderOut: self];
|
||||
_currentPage = 0;
|
||||
[NSPrintOperation setCurrentOperation: nil];
|
||||
}
|
||||
|
@ -454,10 +466,13 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
|||
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 result;
|
||||
CREATE_AUTORELEASE_POOL(pool);
|
||||
NSGraphicsContext *oldContext = [NSGraphicsContext currentContext];
|
||||
|
||||
[self createContext];
|
||||
|
@ -490,6 +505,7 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
|||
}
|
||||
NS_ENDHANDLER
|
||||
[self destroyContext];
|
||||
RELEASE(pool);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -651,7 +667,11 @@ static NSString *NSPrintOperationThreadKey = @"NSPrintOperationThreadKey";
|
|||
_showPanels = NO;
|
||||
[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;
|
||||
_currentPage = 0;
|
||||
|
||||
|
@ -948,8 +968,9 @@ scaleRect(NSRect rect, double scale)
|
|||
last: _currentPage
|
||||
info: &info];
|
||||
}
|
||||
NSDebugLLog(@"NSPrinting", @" current page %d, rect %@",
|
||||
_currentPage, NSStringFromRect(pageRect));
|
||||
|
||||
NSDebugLLog(@"NSPrinting", @" current page %d, rect %@",
|
||||
_currentPage, NSStringFromRect(pageRect));
|
||||
if (NSIsEmptyRect(pageRect))
|
||||
break;
|
||||
|
||||
|
@ -1028,7 +1049,6 @@ scaleRect(NSRect rect, double scale)
|
|||
label: label
|
||||
bBox: info.sheetBounds
|
||||
fonts: nil];
|
||||
DPSPrintf(ctxt, "/__GSsheetsaveobject save def\n");
|
||||
if (info.orient == NSLandscapeOrientation)
|
||||
{
|
||||
DPSrotate(ctxt, 90);
|
||||
|
@ -1095,7 +1115,6 @@ scaleRect(NSRect rect, double scale)
|
|||
NSPrintOperation *printOp = [NSPrintOperation currentOperation];
|
||||
if ([printOp isEPSOperation] == NO)
|
||||
DPSPrintf(ctxt, "showpage\n");
|
||||
DPSPrintf(ctxt, "__GSsheetsaveobject restore\n");
|
||||
DPSPrintf(ctxt, "%%%%PageTrailer\n");
|
||||
DPSPrintf(ctxt, "\n");
|
||||
}
|
||||
|
@ -1143,16 +1162,88 @@ scaleRect(NSRect rect, double scale)
|
|||
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)
|
||||
[[NSFileManager defaultManager] removeFileAtPath: _path
|
||||
handler: nil];
|
||||
*/
|
||||
return YES;
|
||||
*/
|
||||
return success;
|
||||
}
|
||||
|
||||
@end
|
||||
|
@ -1232,7 +1323,6 @@ scaleRect(NSRect rect, double scale)
|
|||
- (NSGraphicsContext*)createContext
|
||||
{
|
||||
NSMutableDictionary *info;
|
||||
NSAutoreleasePool *pool;
|
||||
|
||||
if (_context)
|
||||
return _context;
|
||||
|
@ -1242,12 +1332,7 @@ scaleRect(NSRect rect, double scale)
|
|||
[info setObject: _path forKey: @"NSOutputFile"];
|
||||
[info setObject: NSGraphicsContextPSFormat
|
||||
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]);
|
||||
[pool release];
|
||||
|
||||
return _context;
|
||||
}
|
||||
|
||||
|
|
|
@ -179,14 +179,16 @@ static NSPrintPanel *shared_instance;
|
|||
/** Display the Print panel in a modal loop. Saves any aquired
|
||||
information in the NSPrintInfo object for the current NSPrintOperation.
|
||||
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
|
||||
{
|
||||
_picked = NSOKButton;
|
||||
[NSApp runModalForWindow: self];
|
||||
[_optionPanel orderOut: self];
|
||||
[self orderOut: self];
|
||||
/* Don't order ourselves out, let the NSPrintOperation do that */
|
||||
return (_picked == NSCancelButton) ? NSCancelButton : NSOKButton;
|
||||
}
|
||||
|
||||
|
@ -240,10 +242,6 @@ static NSPrintPanel *shared_instance;
|
|||
else if (tag == 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 )
|
||||
{
|
||||
|
@ -623,4 +621,9 @@ static NSPrintPanel *shared_instance;
|
|||
|
||||
}
|
||||
|
||||
/* Private method for NSPrintOperation */
|
||||
- (void) _setStatusStringValue: (NSString *)string
|
||||
{
|
||||
[CONTROL(self, NSPPStatusField) setStringValue: string ];
|
||||
}
|
||||
@end
|
||||
|
|
|
@ -268,14 +268,18 @@ static NSMutableArray *screenArray = nil;
|
|||
{
|
||||
NSRect visFrame = _frame;
|
||||
|
||||
switch ([NSApp interfaceStyle])
|
||||
switch (NSInterfaceStyleForKey(@"NSIntefaceStyle", nil))
|
||||
{
|
||||
case NSMacintoshInterfaceStyle:
|
||||
// What is the size of the Mac menubar?
|
||||
visFrame.size.height -= 25;
|
||||
return visFrame;
|
||||
case NSWindows95InterfaceStyle:
|
||||
case GSWindowMakerInterfaceStyle:
|
||||
case NSNextStepInterfaceStyle:
|
||||
visFrame.size.width -= 64;
|
||||
return visFrame;
|
||||
|
||||
case NSWindows95InterfaceStyle:
|
||||
case NSNoInterfaceStyle:
|
||||
default:
|
||||
return _frame;
|
||||
|
|
Loading…
Reference in a new issue