mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-06-01 23:50:59 +00:00
Improvements to windows printing.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@38099 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a60e46ed54
commit
2edd41299e
5 changed files with 153 additions and 83 deletions
17
ChangeLog
17
ChangeLog
|
@ -1,11 +1,24 @@
|
||||||
2014-09-27 12:19-EDT Gregory John Casamento <greg.casamento@gmail.com>
|
2014-09-28 04:00-EDT Gregory John Casamento <greg.casamento@gmail.com>
|
||||||
|
|
||||||
|
* Printing/GNUmakefile: On windows only compile the GSWIN32
|
||||||
|
Printing backend
|
||||||
|
* Printing/GSWIN32/GSWIN32PrintPanel.m: Extract printer name
|
||||||
|
from results.
|
||||||
|
* Printing/GSWIN32/GSWIN32PrintOperation.m: Add code to
|
||||||
|
send raw data to the printer. Implement code to send
|
||||||
|
file to printer.
|
||||||
|
* Printing/GSWIN32/GSWIN32Printer.m: Add code to enumerate list of
|
||||||
|
available printers on Windows. Build dictionary for GSWIN32Printer
|
||||||
|
class.
|
||||||
|
|
||||||
|
2014-09-27 21:30-EDT Gregory John Casamento <greg.casamento@gmail.com>
|
||||||
|
|
||||||
* Printing/GSWIN32/GSWIN32PrinterOperation.m: Addition of function
|
* Printing/GSWIN32/GSWIN32PrinterOperation.m: Addition of function
|
||||||
to output to printer directly.
|
to output to printer directly.
|
||||||
* Printing/GSWIN32/GNUmakefile: Change to correct linker issue
|
* Printing/GSWIN32/GNUmakefile: Change to correct linker issue
|
||||||
winspool was not being linked in the proper place so it was
|
winspool was not being linked in the proper place so it was
|
||||||
causing unresolved references.
|
causing unresolved references.
|
||||||
|
|
||||||
2014-09-16 12:19-EDT Gregory John Casamento <greg.casamento@gmail.com>
|
2014-09-16 12:19-EDT Gregory John Casamento <greg.casamento@gmail.com>
|
||||||
|
|
||||||
* Source/GSPrinting.m: Reorder printing backend load order.
|
* Source/GSPrinting.m: Reorder printing backend load order.
|
||||||
|
|
|
@ -43,7 +43,7 @@ SUBPROJECTS += GSCUPS
|
||||||
endif
|
endif
|
||||||
|
|
||||||
ifeq ($(GNUSTEP_TARGET_OS),mingw32)
|
ifeq ($(GNUSTEP_TARGET_OS),mingw32)
|
||||||
SUBPROJECTS += GSWIN32
|
SUBPROJECTS = GSWIN32
|
||||||
endif
|
endif
|
||||||
|
|
||||||
include $(GNUSTEP_MAKEFILES)/aggregate.make
|
include $(GNUSTEP_MAKEFILES)/aggregate.make
|
||||||
|
|
|
@ -1,20 +1,12 @@
|
||||||
/*
|
/*
|
||||||
GWIN32SPrintOperation.m
|
GWIN32PrintOperation.m
|
||||||
|
|
||||||
Controls operations generating EPS, PDF or PS print jobs.
|
Controls operations generating windows print
|
||||||
|
|
||||||
Copyright (C) 2014 Free Software Foundation, Inc.
|
Copyright (C) 2014 Free Software Foundation, Inc.
|
||||||
|
|
||||||
Author: Gregory John Casamento <greg.casamento@gmail.com>
|
Author: Gregory John Casamento <greg.casamento@gmail.com>
|
||||||
Date 2014
|
Date 2014
|
||||||
Author: Scott Christley <scottc@net-community.com>
|
|
||||||
Date: 1996
|
|
||||||
Author: Fred Kiefer <FredKiefer@gmx.de>
|
|
||||||
Date: November 2000
|
|
||||||
Started implementation.
|
|
||||||
Modified for Printing Backend Support
|
|
||||||
Author: Chad Hardin
|
|
||||||
Date: June 2004
|
|
||||||
|
|
||||||
This file is part of the GNUstep GUI Library.
|
This file is part of the GNUstep GUI Library.
|
||||||
|
|
||||||
|
@ -42,6 +34,7 @@
|
||||||
#import <Foundation/NSString.h>
|
#import <Foundation/NSString.h>
|
||||||
#import <Foundation/NSTask.h>
|
#import <Foundation/NSTask.h>
|
||||||
#import <Foundation/NSValue.h>
|
#import <Foundation/NSValue.h>
|
||||||
|
#import <Foundation/NSData.h>
|
||||||
#import "AppKit/NSGraphicsContext.h"
|
#import "AppKit/NSGraphicsContext.h"
|
||||||
#import "AppKit/NSView.h"
|
#import "AppKit/NSView.h"
|
||||||
#import "AppKit/NSPrinter.h"
|
#import "AppKit/NSPrinter.h"
|
||||||
|
@ -154,35 +147,36 @@ BOOL RawDataToPrinter(LPSTR szPrinterName, LPBYTE lpData, DWORD dwCount)
|
||||||
|
|
||||||
- (BOOL) _deliverSpooledResult
|
- (BOOL) _deliverSpooledResult
|
||||||
{
|
{
|
||||||
int copies;
|
NSString *name = nil;
|
||||||
NSDictionary *dict;
|
NSData *fileData = nil;
|
||||||
NSTask *task;
|
LPSTR szPrinterName = NULL;
|
||||||
NSString *name, *status;
|
DWORD dwCount = 0;
|
||||||
NSMutableArray *args;
|
LPBYTE lpData = NULL;
|
||||||
|
BOOL result = FALSE;
|
||||||
|
|
||||||
name = [[[self printInfo] printer] name];
|
name = [[[self printInfo] printer] name];
|
||||||
status = [NSString stringWithFormat: _(@"Spooling to printer %@."), name];
|
|
||||||
[[self printPanel] _setStatusStringValue: status];
|
if(name != nil)
|
||||||
|
|
||||||
dict = [[self 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"];
|
szPrinterName = (LPSTR)[name cString];
|
||||||
[args addObject: name];
|
fileData = [NSData dataWithContentsOfFile:_path];
|
||||||
|
if(fileData != nil)
|
||||||
|
{
|
||||||
|
dwCount = (DWORD)[fileData length];
|
||||||
|
lpData = (LPBYTE)[fileData bytes];
|
||||||
|
result = RawDataToPrinter(szPrinterName, lpData, dwCount);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSLog(@"File is blank");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSLog(@"No printer name supplied");
|
||||||
}
|
}
|
||||||
[args addObject: _path];
|
|
||||||
|
|
||||||
task = [NSTask new];
|
return (result ? YES : NO); // Paranoid conversion to ObjC type...
|
||||||
[task setLaunchPath: @"lpr"];
|
|
||||||
[task setArguments: args];
|
|
||||||
[task launch];
|
|
||||||
[task waitUntilExit];
|
|
||||||
AUTORELEASE(task);
|
|
||||||
return YES;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSGraphicsContext*)createContext
|
- (NSGraphicsContext*)createContext
|
||||||
|
|
|
@ -50,26 +50,14 @@
|
||||||
- (NSInteger) runModalWithPrintInfo: (NSPrintInfo *)printInfo
|
- (NSInteger) runModalWithPrintInfo: (NSPrintInfo *)printInfo
|
||||||
{
|
{
|
||||||
int retVal;
|
int retVal;
|
||||||
// NSMutableDictionary *info = [printInfo dictionary];
|
|
||||||
PRINTDLG printDlg;
|
PRINTDLG printDlg;
|
||||||
// GSWIN32Printer *printer = [info objectForKey:@"NSPrinter"];
|
|
||||||
int windowNumber = [[[NSApplication sharedApplication] mainWindow] windowNumber];
|
int windowNumber = [[[NSApplication sharedApplication] mainWindow] windowNumber];
|
||||||
|
|
||||||
/*
|
|
||||||
NSLog(@"==== Printer info ");
|
|
||||||
NSLog(@"Names: %@",[GSWIN32Printer printerNames]);
|
|
||||||
NSLog(@"Info: %@",info);
|
|
||||||
NSLog(@"Host: %@",[printer host]);
|
|
||||||
NSLog(@"Name: %@",[printer name]);
|
|
||||||
NSLog(@"Note: %@",[printer note]);
|
|
||||||
NSLog(@"Type: %@",[printer type]);
|
|
||||||
NSLog(@"==== End Printer info ");
|
|
||||||
*/
|
|
||||||
|
|
||||||
printDlg.lStructSize = sizeof(PRINTDLG);
|
printDlg.lStructSize = sizeof(PRINTDLG);
|
||||||
printDlg.hwndOwner = (HWND)windowNumber;
|
printDlg.hwndOwner = (HWND)windowNumber;
|
||||||
printDlg.hDevMode = NULL;
|
printDlg.hDevMode = NULL;
|
||||||
printDlg.hDevNames = NULL;
|
printDlg.hDevNames = NULL;
|
||||||
|
printDlg.Flags = PD_RETURNDC | PD_USEDEVMODECOPIESANDCOLLATE;
|
||||||
printDlg.hDC = NULL;
|
printDlg.hDC = NULL;
|
||||||
printDlg.lCustData = 0;
|
printDlg.lCustData = 0;
|
||||||
printDlg.lpfnPrintHook = NULL;
|
printDlg.lpfnPrintHook = NULL;
|
||||||
|
@ -78,12 +66,11 @@
|
||||||
printDlg.lpSetupTemplateName = NULL;
|
printDlg.lpSetupTemplateName = NULL;
|
||||||
printDlg.hPrintTemplate = NULL;
|
printDlg.hPrintTemplate = NULL;
|
||||||
printDlg.hSetupTemplate = NULL;
|
printDlg.hSetupTemplate = NULL;
|
||||||
printDlg.Flags = PD_RETURNDC | PD_COLLATE; // | PD_ENABLEPRINTHOOK;
|
|
||||||
|
|
||||||
printDlg.nFromPage = 1;
|
printDlg.nFromPage = 0; //0xFFFF;
|
||||||
printDlg.nToPage = 1;
|
printDlg.nToPage = 0; //0xFFFF;
|
||||||
printDlg.nMinPage = 1;
|
printDlg.nMinPage = 1;
|
||||||
printDlg.nMaxPage = 1;
|
printDlg.nMaxPage = 0xFFFF;
|
||||||
printDlg.nCopies = 1;
|
printDlg.nCopies = 1;
|
||||||
printDlg.hInstance = NULL;
|
printDlg.hInstance = NULL;
|
||||||
|
|
||||||
|
@ -94,10 +81,20 @@
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Get specifics from the data returned
|
DEVNAMES *pDevNames = (DEVNAMES *)GlobalLock(printDlg.hDevNames);
|
||||||
DEVMODE *devMode = printDlg.hDevMode;
|
LPCTSTR szDevice = NULL;
|
||||||
NSString *printerName = [NSString stringWithCString:(const char *)(devMode->dmDeviceName)];
|
NSString *printerName = nil;
|
||||||
|
NSPrinter *printer = nil;
|
||||||
|
|
||||||
|
szDevice = (LPCTSTR)pDevNames + pDevNames->wDeviceOffset;
|
||||||
|
printerName = [NSString stringWithCString:(const char *)szDevice];
|
||||||
NSLog(@"Printer Name = %@",printerName);
|
NSLog(@"Printer Name = %@",printerName);
|
||||||
|
|
||||||
|
printer = [NSPrinter printerWithName:printerName];
|
||||||
|
if(printer != nil)
|
||||||
|
{
|
||||||
|
[printInfo setPrinter:printer];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return NSOKButton;
|
return NSOKButton;
|
||||||
|
|
|
@ -45,9 +45,81 @@
|
||||||
#import <Foundation/NSString.h>
|
#import <Foundation/NSString.h>
|
||||||
#import <Foundation/NSUserDefaults.h>
|
#import <Foundation/NSUserDefaults.h>
|
||||||
#import <Foundation/NSValue.h>
|
#import <Foundation/NSValue.h>
|
||||||
|
|
||||||
#import "GSWIN32Printer.h"
|
#import "GSWIN32Printer.h"
|
||||||
#import "GNUstepGUI/GSPrinting.h"
|
#import "GNUstepGUI/GSPrinting.h"
|
||||||
|
|
||||||
|
NSMutableDictionary *EnumeratePrinters(DWORD flags)
|
||||||
|
{
|
||||||
|
PRINTER_INFO_2* prninfo=NULL;
|
||||||
|
DWORD needed, returned;
|
||||||
|
NSMutableDictionary *printers = nil;
|
||||||
|
|
||||||
|
//find required size for the buffer
|
||||||
|
EnumPrinters(flags, NULL, 2, NULL, 0, &needed, &returned);
|
||||||
|
|
||||||
|
//allocate array of PRINTER_INFO structures
|
||||||
|
prninfo = (PRINTER_INFO_2*) GlobalAlloc(GPTR,needed);
|
||||||
|
|
||||||
|
//call again
|
||||||
|
if (!EnumPrinters(flags, NULL,
|
||||||
|
2, (LPBYTE) prninfo, needed, &needed, &returned))
|
||||||
|
{
|
||||||
|
NSLog(@"Error: %s\n", GetLastError());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
printers = [NSMutableDictionary dictionary];
|
||||||
|
NSLog(@"Printers found: %d\n\n",returned);
|
||||||
|
for (i = 0; i < returned; i++)
|
||||||
|
{
|
||||||
|
NSMutableDictionary *entry = [NSMutableDictionary dictionary];
|
||||||
|
NSString *printerName =
|
||||||
|
[NSString stringWithCString:prninfo[i].pPrinterName
|
||||||
|
encoding:NSASCIIStringEncoding];
|
||||||
|
|
||||||
|
if (printerName != nil)
|
||||||
|
{
|
||||||
|
NSString *portName =
|
||||||
|
[NSString stringWithCString:prninfo[i].pPortName
|
||||||
|
encoding:NSASCIIStringEncoding];
|
||||||
|
if (portName != nil)
|
||||||
|
{
|
||||||
|
[entry setObject:portName
|
||||||
|
forKey:@"Host"];
|
||||||
|
[entry setObject:[NSString stringWithFormat:@"Current Status: %d",prninfo[i].Status]
|
||||||
|
forKey:@"Note"];
|
||||||
|
[entry setObject:@"Generic Postscript Printer"
|
||||||
|
forKey:@"Type"];
|
||||||
|
|
||||||
|
[printers setObject:entry
|
||||||
|
forKey:printerName];
|
||||||
|
/*
|
||||||
|
NSLog(@"%s on %s, Status = %d, jobs=%d\n",
|
||||||
|
prninfo[i].pPrinterName,
|
||||||
|
prninfo[i].pPortName,
|
||||||
|
prninfo[i].Status,
|
||||||
|
prninfo[i].cJobs);
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSLog(@"Port name is nil for %@",printerName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSLog(@"Printer name is nil");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
GlobalFree(prninfo);
|
||||||
|
|
||||||
|
return printers;
|
||||||
|
}
|
||||||
|
|
||||||
@implementation GSWIN32Printer
|
@implementation GSWIN32Printer
|
||||||
|
|
||||||
|
@ -97,7 +169,7 @@
|
||||||
withHost: [printerEntry objectForKey: @"Host"]
|
withHost: [printerEntry objectForKey: @"Host"]
|
||||||
withNote: [printerEntry objectForKey: @"Note"]];
|
withNote: [printerEntry objectForKey: @"Note"]];
|
||||||
|
|
||||||
[printer parsePPDAtPath: [printerEntry objectForKey: @"PPDPath"]];
|
// [printer parsePPDAtPath: [printerEntry objectForKey: @"PPDPath"]];
|
||||||
|
|
||||||
return AUTORELEASE(printer);
|
return AUTORELEASE(printer);
|
||||||
}
|
}
|
||||||
|
@ -109,58 +181,52 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
// Load the printer setup from NSUserDefaults
|
// Load the printer setup
|
||||||
//
|
//
|
||||||
+ (NSDictionary*) printersDictionary
|
+ (NSDictionary*) printersDictionary
|
||||||
{
|
{
|
||||||
static BOOL didWarn;
|
static BOOL didWarn;
|
||||||
NSUserDefaults* defaults;
|
|
||||||
NSDictionary *printers;
|
NSDictionary *printers;
|
||||||
|
|
||||||
defaults = [NSUserDefaults standardUserDefaults];
|
printers = EnumeratePrinters(PRINTER_ENUM_LOCAL);
|
||||||
printers = [defaults dictionaryForKey: @"GSWIN32Printers"];
|
|
||||||
|
|
||||||
if (!printers) //Not set, make a default printer because we are nice.
|
if (!printers) //Not set, make a default printer because we are nice.
|
||||||
{
|
{
|
||||||
NSString *ppdPath;
|
NSString *ppdPath;
|
||||||
NSMutableDictionary *printerEntry;
|
NSMutableDictionary *printerEntry;
|
||||||
|
|
||||||
printers = [NSMutableDictionary dictionary];
|
printers = [NSMutableDictionary dictionary];
|
||||||
printerEntry = [NSMutableDictionary dictionary];
|
printerEntry = [NSMutableDictionary dictionary];
|
||||||
|
|
||||||
ppdPath = [NSBundle
|
ppdPath = [NSBundle
|
||||||
pathForLibraryResource: @"Generic-PostScript_Printer-Postscript"
|
pathForLibraryResource: @"Generic-PostScript_Printer-Postscript"
|
||||||
ofType: @"ppd"
|
ofType: @"ppd"
|
||||||
inDirectory: @"PostScript/PPD"];
|
inDirectory: @"PostScript/PPD"];
|
||||||
NSAssert(ppdPath,
|
NSAssert(ppdPath,
|
||||||
@"Couldn't find the PPD file for the fallback printer.");
|
@"Couldn't find the PPD file for the fallback printer.");
|
||||||
|
|
||||||
[printerEntry setObject: ppdPath
|
[printerEntry setObject: ppdPath
|
||||||
forKey: @"PPDPath"];
|
forKey: @"PPDPath"];
|
||||||
|
|
||||||
[printerEntry setObject: @"localhost"
|
[printerEntry setObject: @"localhost"
|
||||||
forKey: @"Host"];
|
forKey: @"Host"];
|
||||||
|
|
||||||
[printerEntry setObject: @"Automatically Generated"
|
[printerEntry setObject: @"Automatically Generated"
|
||||||
forKey: @"Note"];
|
forKey: @"Note"];
|
||||||
|
|
||||||
[printerEntry setObject: @"Unknown"
|
[printerEntry setObject: @"Unknown"
|
||||||
forKey: @"Type"];
|
forKey: @"Type"];
|
||||||
|
|
||||||
[(NSMutableDictionary*)printers setObject: printerEntry
|
[(NSMutableDictionary*)printers setObject: printerEntry
|
||||||
forKey: @"Unnamed"];
|
forKey: @"Unnamed"];
|
||||||
|
|
||||||
[defaults setObject: printers forKey: @"GSWIN32Printers"];
|
|
||||||
[defaults synchronize];
|
|
||||||
|
|
||||||
if (!didWarn)
|
if (!didWarn)
|
||||||
{
|
{
|
||||||
NSLog(@"Creating a default printer since no printer has been set "
|
NSLog(@"Creating a default printer since no printer has been set "
|
||||||
@"in the user defaults (under the GSWIN32Printers key).");
|
@"in the user defaults (under the GSWIN32Printers key).");
|
||||||
didWarn = YES;
|
didWarn = YES;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return printers;
|
return printers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue