Windows printing backend, first cut for panels.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@38083 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Gregory John Casamento 2014-09-16 16:31:32 +00:00
parent 0934169b8f
commit 71cad95ae1
16 changed files with 1204 additions and 0 deletions

View file

@ -42,5 +42,9 @@ ifeq ($(BUILD_GSCUPS), YES)
SUBPROJECTS += GSCUPS
endif
ifeq ($(GNUSTEP_TARGET_OS),mingw32)
SUBPROJECTS += GSWIN32
endif
include $(GNUSTEP_MAKEFILES)/aggregate.make

View file

@ -0,0 +1,102 @@
#
# GSWIN32 Printing Backend Bundle makefile for GNUstep GUI Library
#
# Copyright (C) 2004 Free Software Foundation, Inc.
#
# Author: Chad Hardin <cehardin@mac.com
#
# Date: June 2004
#
# This file is part of the GNUstep GUI Library.
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2 of the License, or (at your option) any later version.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; see the file COPYING.LIB.
# If not, see <http://www.gnu.org/licenses/> or write to the
# Free Software Foundation, 51 Franklin Street, Fifth Floor,
# Boston, MA 02110-1301, USA.
PACKAGE_NAME = gnustep-gui
GNUSTEP_LOCAL_ADDITIONAL_MAKEFILES=../../gui.make
include $(GNUSTEP_MAKEFILES)/common.make
include ../../config.make
include ../../Version
BUNDLE_NAME=GSWIN32
BUNDLE_INSTALL_DIR= $(GNUSTEP_BUNDLES)/GSPrinting
GSWIN32_PRINCIPAL_CLASS=GSWIN32PrincipalClass
ifeq ($(GNUSTEP_TARGET_OS),mingw32)
GSWIN32_BUNDLE_LIBS += -lgnustep-gui $(FND_LIBS) $(OBJC_LIBS)
endif
ifeq ($(GNUSTEP_TARGET_OS),cygwin)
GSWIN32_BUNDLE_LIBS += -lgnustep-gui $(FND_LIBS) $(OBJC_LIBS)
endif
#
# Libraries
#
#GSWIN32_LIBRARIES_DEPEND_UPON +=
#
# Resource files
#
#GSWIN32_RESOURCE_FILES =
#
# Header files
#
GSWIN32_HEADERS= \
GSWIN32PrincipalClass.m \
GSWIN32PageLayout.m \
GSWIN32PrintInfo.m \
GSWIN32PrintOperation \
GSWIN32PrintPanel.m \
GSWIN32Printer.m
#
# Class files
#
GSWIN32_OBJC_FILES= \
GSWIN32PrincipalClass.m \
GSWIN32PageLayout.m \
GSWIN32PrintInfo.m \
GSWIN32PrintOperation.m \
GSWIN32PrintPanel.m \
GSWIN32Printer.m
#
# C files
#
#GSWIN32_C_FILES =
#
# Languages
#
#GSWIN32_LANGUAGES= \
# English
#
# Localized Resource Files
#
#GSWIN32_LOCALIZED_RESOURCE_FILES= \
# GSWIN32PrintPanel.gorm \
# GSWIN32PageLayout.gorm
#
# Makefiles
#
-include GNUmakefile.preamble
#include $(GNUSTEP_MAKEFILES)/aggregate.make
include $(GNUSTEP_MAKEFILES)/bundle.make
-include GNUmakefile.postamble

View file

@ -0,0 +1,42 @@
#
# GNUmakefile.postamble
#
# Copyright (C) 2004 Free Software Foundation, Inc.
#
# Things to do before compiling
# before-all::
# Things to do after compiling
# after-all::
# Things to do before installing
# before-install::
# Things to do after installing
# after-install::
# Things to do before uninstalling
# before-uninstall::
# Things to do after uninstalling
# after-uninstall::
# Things to do before cleaning
# before-clean::
# Things to do after cleaning
# after-clean::
# Things to do before distcleaning
# before-distclean::
# Things to do after distcleaning
# after-distclean::
# Things to do before checking
# before-check::
# Things to do after checking
# after-check::

View file

@ -0,0 +1,43 @@
#
# GNUmakefile.postamble
#
# Copyright (C) 2004 Free Software Foundation, Inc.
#
# Additional flags to pass to the preprocessor
ADDITIONAL_CPPFLAGS +=
# Additional flags to pass to the Objective-C compiler
ADDITIONAL_OBJCFLAGS += -Wall
# Additional flags to pass to the C compiler
ADDITIONAL_CFLAGS +=
# Additional include directories the compiler should search
ADDITIONAL_INCLUDE_DIRS += -I../../Headers/Additions -I../../Headers \
-I../../Source/$(GNUSTEP_TARGET_DIR)
# Additional LDFLAGS to pass to the linker
ADDITIONAL_LDFLAGS += -lwinspool
# Additional library directories the linker should search
ADDITIONAL_LIB_DIRS += -L../../Source/$(GNUSTEP_OBJ_DIR)
# Additional libraries
# GNUstepWeb
ADDITIONAL_GSW_LIBS +=
# GUI apps
ADDITIONAL_GUI_LIBS +=
# Libraries
ADDITIONAL_LIBRARY_LIBS +=
# ObjC stuff
ADDITIONAL_OBJC_LIBS +=
#-lgnustep-gui $(SYSTEM_LIBS)
# Tools
ADDITIONAL_TOOL_LIBS +=
# WebObjects
ADDITIONAL_WO_LIBS +=
# Additional directories to be created during installation
#ADDITIONAL_INSTALL_DIRS +=

View file

@ -0,0 +1,46 @@
/** <title>GSWIN32PageLayout</title>
<abstract>Standard panel for querying user about page layout.</abstract>
Copyright (C) 2001,2004 Free Software Foundation, Inc.
Written By: Adam Fedor <fedor@gnu.org>
Date: Oct 2001
Modified for Printing Backend Support
Author: Chad Hardin <cehardin@mac.com>
Date: June 2004
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_GSWIN32PageLayout
#define _GNUstep_H_GSWIN32PageLayout
#import "AppKit/NSPageLayout.h"
@class NSPrintInfo;
@class NSView;
@interface GSWIN32PageLayout: NSPageLayout
{
}
@end
#endif // _GNUstep_H_GSWIN32PageLayout

View file

@ -0,0 +1,103 @@
/** <title>GSWIN32PageLayout</title>
<abstract></abstract>
Copyright (C) 2004 Free Software Foundation, Inc.
Author: Chad Hardin <cehardin@mac.com>
Date: June 2004
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#import <Foundation/NSDebug.h>
#import <Foundation/NSValue.h>
#import <AppKit/NSPrintInfo.h>
#import <AppKit/NSPrinter.h>
#import <AppKit/NSApplication.h>
#import "GSWIN32Printer.h"
#import "GSWIN32PageLayout.h"
#define PTS2INCHES(n) ((n / 72.0f) * 1000.0f)
#define INCHES2PTS(n) ((n / 1000.0f) * 72.0f)
@implementation GSWIN32PageLayout
//
// Class methods
//
+ (void)initialize
{
if (self == [GSWIN32PageLayout class])
{
// Initial version
[self setVersion:1];
}
}
+ (id) allocWithZone: (NSZone*)zone
{
return NSAllocateObject(self, 0, zone);
}
- (NSInteger)runModalWithPrintInfo:(NSPrintInfo *)printInfo
{
PAGESETUPDLG pgSetup;
int windowNumber =
[[[NSApplication sharedApplication] mainWindow] windowNumber];
pgSetup.lStructSize = sizeof(PAGESETUPDLG);
pgSetup.Flags = PSD_INTHOUSANDTHSOFINCHES;
pgSetup.hwndOwner = (HWND)windowNumber;
pgSetup.hDevNames = NULL;
pgSetup.hDevMode = NULL;
pgSetup.rtMargin.top = PTS2INCHES([printInfo topMargin]);
pgSetup.rtMargin.bottom = PTS2INCHES([printInfo bottomMargin]);
pgSetup.rtMargin.right = PTS2INCHES([printInfo rightMargin]);
pgSetup.rtMargin.left = PTS2INCHES([printInfo leftMargin]);
pgSetup.ptPaperSize.x = PTS2INCHES([printInfo paperSize].width);
pgSetup.ptPaperSize.y = PTS2INCHES([printInfo paperSize].height);
int retVal = PageSetupDlg(&pgSetup);
if (retVal == 0)
{
return NSCancelButton;
}
else
{
NSSize size = NSMakeSize(INCHES2PTS(pgSetup.ptPaperSize.x),
INCHES2PTS(pgSetup.ptPaperSize.y));
[printInfo setPaperSize: size];
[printInfo setTopMargin: INCHES2PTS(pgSetup.rtMargin.top)];
[printInfo setBottomMargin: INCHES2PTS(pgSetup.rtMargin.bottom)];
[printInfo setRightMargin: INCHES2PTS(pgSetup.rtMargin.right)];
[printInfo setLeftMargin: INCHES2PTS(pgSetup.rtMargin.left)];
}
return NSOKButton;
}
- (void) beginSheetWithPrintInfo: (NSPrintInfo *)printInfo
modalForWindow: (NSWindow *)docWindow
delegate: (id)delegate
didEndSelector: (SEL)didEndSelector
contextInfo: (void *)contextInfo
{
[self runModalWithPrintInfo: printInfo];
}
@end

View file

@ -0,0 +1,41 @@
/** <title>GSWIN32PrincipalClass</title>
<abstract>Principal class for the GSWIN32 Bundle.</abstract>
Copyright (C) 2004 Free Software Foundation, Inc.
Author: Chad Hardin <cehardin@mac.com>
Date: June 2004
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_GSWIN32PrincipalClass
#define _GNUstep_H_GSWIN32PrincipalClass
#import "GNUstepGUI/GSPrinting.h"
@interface GSWIN32PrincipalClass : GSPrintingPrincipalClass
{
}
@end
#endif // _GNUstep_H_GSWIN32PrincipalClass

View file

@ -0,0 +1,76 @@
/*
GSWIN32PrincipalClass.m
Principal class for the GSWIN32 Bundle
Copyright (C) 2004 Free Software Foundation, Inc.
Author: Chad Hardin <cehardin@mac.com>
Date: June 2004
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#import <Foundation/NSDebug.h>
#import "GSWIN32PrincipalClass.h"
#import "GSWIN32PageLayout.h"
#import "GSWIN32PrintInfo.h"
#import "GSWIN32PrintOperation.h"
#import "GSWIN32PrintPanel.h"
#import "GSWIN32Printer.h"
@implementation GSWIN32PrincipalClass
//
// Class methods
//
+(Class) pageLayoutClass
{
return [GSWIN32PageLayout class];
}
+(Class) printInfoClass
{
return [GSWIN32PrintInfo class];
}
+(Class) printOperationClass
{
return [GSWIN32PrintOperation class];
}
+(Class) printPanelClass
{
return [GSWIN32PrintPanel class];
}
+(Class) printerClass
{
return [GSWIN32Printer class];
}
+(Class) gsPrintOperationClass
{
return [GSWIN32PrintOperation class];
}
@end

View file

@ -0,0 +1,45 @@
/** <title>GSWIN32PrintInfo</title>
<abstract>Stores information used in printing.</abstract>
Copyright (C) 1996,1997,2004 Free Software Foundation, Inc.
Author: Simon Frankau <sgf@frankau.demon.co.uk>
Date: July 1997
Author: Adam Fedor <fedor@gnu.org>
Date: Oct 2001
Modified for Printing Backend Support
Author: Chad Hardin <cehardin@mac.com>
Date: June 2004
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_GSWIN32PrintInfo
#define _GNUstep_H_GSWIN32PrintInfo
#import <Foundation/NSCoder.h>
#import "AppKit/NSPrintInfo.h"
@interface GSWIN32PrintInfo: NSPrintInfo
{
}
@end
#endif // _GNUstep_H_GSWIN32PrintInfo

View file

@ -0,0 +1,114 @@
/*
GSWIN32PrintInfo.m
Stores information used in printing
Copyright (C) 1996,1997,2004 Free Software Foundation, Inc.
Author: Simon Frankau <sgf@frankau.demon.co.uk>
Date: July 1997
Modified for Printing Backend Support
Author: Chad Hardin <cehardin@mac.com>
Date: June 2004
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#import <Foundation/NSArray.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSValue.h>
#import "AppKit/NSPrinter.h"
#import "GSWIN32PrintInfo.h"
@implementation GSWIN32PrintInfo
//
// Class methods
//
+ (void)initialize
{
if (self == [GSWIN32PrintInfo class])
{
// Initial version
[self setVersion:1];
}
}
+ (id) allocWithZone: (NSZone*)zone
{
return NSAllocateObject(self, 0, zone);
}
+(NSPrinter*) defaultPrinter
{
NSUserDefaults *defaults;
NSString *name;
NSDebugMLLog(@"GSPrinting", @"defaultPrinter");
defaults = [NSUserDefaults standardUserDefaults];
name = [defaults objectForKey: @"GSWIN32DefaultPrinter"];
if (name == nil)
{
name = [[NSPrinter printerNames] objectAtIndex: 0];
}
else
{
if ([NSPrinter printerWithName: name] == nil)
{
name = [[NSPrinter printerNames] objectAtIndex: 0];
}
}
return [NSPrinter printerWithName: name];
}
+ (void)setDefaultPrinter:(NSPrinter *)printer
{
NSUserDefaults *defaults;
NSMutableDictionary *globalDomain;
NSDebugMLLog(@"GSPrinting", @"setDefaultPrinter");
defaults = [NSUserDefaults standardUserDefaults];
globalDomain = (NSMutableDictionary*)[defaults persistentDomainForName: NSGlobalDomain];
if (globalDomain)
{
globalDomain = [globalDomain mutableCopy];
[globalDomain setObject: [printer name]
forKey: @"GSWIN32DefaultPrinter"];
[defaults setPersistentDomain: globalDomain
forName: NSGlobalDomain];
RELEASE(globalDomain);
}
else
{
NSDebugMLLog(@"GSPrinting", @"(GSWIN32) Could not save default printer named %@ to NSUserDefaults GSWIN32DefaultPrinter in NSGlobalDomain.", [printer name]);
}
}
@end

View file

@ -0,0 +1,56 @@
/** <title>GSWIN32PrintOperation</title>
<abstract>Controls generation of EPS, PDF or PS print jobs.</abstract>
Copyright (C) 1996,2004 Free Software Foundation, Inc.
Author: Gregory Casamento <greg.casamento@gmail.com>
Date: 2014
Author: Scott Christley <scottc@net-community.com>
Date: 1996
Author: Fred Kiefer <FredKiefer@gmx.de>
Date: November 2000
Updated to new specification
Author: Adam Fedor <fedor@gnu.org>
Date: Oct 2001
Modified for Printing Backend Support
Author: Chad Hardin <cehardin@mac.com>
Date: June 2004
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_GSWIN32PrintOperation
#define _GNUstep_H_GSWIN32PrintOperation
#import "GNUstepGUI/GSPrintOperation.h"
//GSPrintOperation is subclasses of GSPrintOperation, NOT NSPrintOperation.
//NSPrintOperation does a lot of work that is pretty generic.
//GSPrintOperation contains the method that does the actual
//spooling. A future Win32 printing printing bundle
//will likely have to implement much more
@interface GSWIN32PrintOperation : GSPrintOperation
{
}
@end
#endif // _GNUstep_H_GSWIN32PrintOperation

View file

@ -0,0 +1,161 @@
/*
GWIN32SPrintOperation.m
Controls operations generating EPS, PDF or PS print jobs.
Copyright (C) 2014 Free Software Foundation, Inc.
Author: Gregory John Casamento <greg.casamento@gmail.com>
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 library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#include <config.h>
#import <Foundation/NSDebug.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSPathUtilities.h>
#import <Foundation/NSString.h>
#import <Foundation/NSTask.h>
#import <Foundation/NSValue.h>
#import "AppKit/NSGraphicsContext.h"
#import "AppKit/NSView.h"
#import "AppKit/NSPrinter.h"
#import "AppKit/NSPrintPanel.h"
#import "AppKit/NSPrintInfo.h"
#import "AppKit/NSPrintOperation.h"
#import "GSGuiPrivate.h"
#import "GSWIN32PrintOperation.h"
//A subclass of GSPrintOperation, NOT NSPrintOperation.
@implementation GSWIN32PrintOperation
//
// Class methods
//
+ (id) allocWithZone: (NSZone*)zone
{
return NSAllocateObject(self, 0, zone);
}
- (id)initWithView:(NSView *)aView
printInfo:(NSPrintInfo *)aPrintInfo
{
self = [super initWithView: aView
printInfo: aPrintInfo];
if (self == nil)
return nil;
_path = [NSTemporaryDirectory()
stringByAppendingPathComponent: @"GSWIN32PrintJob-"];
_path = [_path stringByAppendingString:
[[NSProcessInfo processInfo] globallyUniqueString]];
_path = [_path stringByAppendingPathExtension: @"ps"];
RETAIN(_path);
return self;
}
- (BOOL) _deliverSpooledResult
{
int copies;
NSDictionary *dict;
NSTask *task;
NSString *name, *status;
NSMutableArray *args;
name = [[[self printInfo] printer] name];
status = [NSString stringWithFormat: _(@"Spooling to printer %@."), name];
[[self printPanel] _setStatusStringValue: status];
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"];
[args addObject: name];
}
[args addObject: _path];
task = [NSTask new];
[task setLaunchPath: @"lpr"];
[task setArguments: args];
[task launch];
[task waitUntilExit];
AUTORELEASE(task);
return YES;
}
- (NSGraphicsContext*)createContext
{
NSMutableDictionary *info;
NSString *output;
if (_context)
{
NSDebugMLLog(@"GSPrinting", @"Already had context, returning it.");
return _context;
}
NSDebugMLLog(@"GSPrinting", @"Creating context.");
info = [[self printInfo] dictionary];
output = [info objectForKey: NSPrintSavePath];
if (output)
{
ASSIGN(_path, output);
}
NSDebugMLLog(@"GSPrinting", @"_path is %@", _path);
[info setObject: _path
forKey: @"NSOutputFile"];
if ([[[_path pathExtension] lowercaseString] isEqualToString: @"pdf"])
{
[info setObject: NSGraphicsContextPDFFormat
forKey: NSGraphicsContextRepresentationFormatAttributeName];
}
else
{
[info setObject: NSGraphicsContextPSFormat
forKey: NSGraphicsContextRepresentationFormatAttributeName];
}
_context = RETAIN([NSGraphicsContext graphicsContextWithAttributes: info]);
return _context;
}
@end

View file

@ -0,0 +1,44 @@
/*
GSWIN32PrintPanel.h
Standard panel to query users for info on a print job
Copyright (C) 1996,2004 Free Software Foundation, Inc.
Author: Scott Christley <scottc@net-community.com>
Date: 1996
Modified for Printing Backend Support
Author: Chad Hardin <cehardin@mac.com>
Date: June 2004
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_GSWIN32PrintPanel
#define _GNUstep_H_GSWIN32PrintPanel
#import "AppKit/NSPrintPanel.h"
@interface GSWIN32PrintPanel : NSPrintPanel
{
}
@end
#endif // _GNUstep_H_GSWIN32PrintPanel

View file

@ -0,0 +1,114 @@
/** <title>GSWIN32PrintPanel</title>
<abstract>Standard panel for querying user about printing.</abstract>
Copyright (C) 2001,2004 Free Software Foundation, Inc.
Written By: Adam Fedor <fedor@gnu.org>
Date: Oct 2001
Modified for Printing Backend Support
Author: Chad Hardin <cehardin@mac.com>
Date: June 2004
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#import <Foundation/NSDebug.h>
#import <Foundation/NSValue.h>
#import <AppKit/NSPrintInfo.h>
#import <AppKit/NSPrinter.h>
#import <AppKit/NSApplication.h>
#import "GSWIN32PrintPanel.h"
#import "GSWIN32Printer.h"
@implementation GSWIN32PrintPanel
//
// Class methods
//
+ (id) allocWithZone: (NSZone*)zone
{
return NSAllocateObject(self, 0, zone);
}
- (NSInteger) runModalWithPrintInfo: (NSPrintInfo *)printInfo
{
int retVal;
// NSMutableDictionary *info = [printInfo dictionary];
PRINTDLG printDlg;
// GSWIN32Printer *printer = [info objectForKey:@"NSPrinter"];
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.hwndOwner = (HWND)windowNumber;
printDlg.hDevMode = NULL;
printDlg.hDevNames = NULL;
printDlg.hDC = NULL;
printDlg.lCustData = 0;
printDlg.lpfnPrintHook = NULL;
printDlg.lpfnSetupHook = NULL;
printDlg.lpPrintTemplateName = NULL;
printDlg.lpSetupTemplateName = NULL;
printDlg.hPrintTemplate = NULL;
printDlg.hSetupTemplate = NULL;
printDlg.Flags = PD_RETURNDC | PD_COLLATE; // | PD_ENABLEPRINTHOOK;
printDlg.nFromPage = 1;
printDlg.nToPage = 1;
printDlg.nMinPage = 1;
printDlg.nMaxPage = 1;
printDlg.nCopies = 1;
printDlg.hInstance = NULL;
retVal = PrintDlg(&printDlg);
if(retVal==0)
{
return NSCancelButton;
}
else
{
// Get specifics from the data returned
DEVMODE *devMode = printDlg.hDevMode;
NSString *printerName = [NSString stringWithCString:(const char *)(devMode->dmDeviceName)];
NSLog(@"Printer Name = %@",printerName);
}
return NSOKButton;
}
- (void) beginSheetWithPrintInfo: (NSPrintInfo *)printInfo
modalForWindow: (NSWindow *)docWindow
delegate: (id)delegate
didEndSelector: (SEL)didEndSelector
contextInfo: (void *)contextInfo
{
[self runModalWithPrintInfo: printInfo];
}
@end

View file

@ -0,0 +1,46 @@
/*
GSWIN32Printer.h
Class representing a printer's or printer model's capabilities.
Copyright (C) 1996, 1997,2004 Free Software Foundation, Inc.
Authors: Simon Frankau <sgf@frankau.demon.co.uk>
Date: June 1997
Modified for Printing Backend Support
Author: Chad Hardin <cehardin@mac.com>
Date: June 2004
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
#ifndef _GNUstep_H_GSWIN32Printer
#define _GNUstep_H_GSWIN32Printer
#import "AppKit/NSPrinter.h"
@interface GSWIN32Printer : NSPrinter
{
}
+(NSDictionary*) printersDictionary;
@end
#endif // _GNUstep_H_GSWIN32Printer

View file

@ -0,0 +1,167 @@
/** <title>GSWIN32Printer</title>
<abstract>Class representing a printer's or printer model's capabilities.</abstract>
Copyright (C) 1996, 1997, 2004 Free Software Foundation, Inc.
Authors: Simon Frankau <sgf@frankau.demon.co.uk>
Date: June 1997
Modified for Printing Backend Support
Author: Chad Hardin <cehardin@mac.com>
Date: June 2004
This file is part of the GNUstep GUI Library.
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; see the file COPYING.LIB.
If not, see <http://www.gnu.org/licenses/> or write to the
Free Software Foundation, 51 Franklin Street, Fifth Floor,
Boston, MA 02110-1301, USA.
*/
/* NB:
* There are a few FIXMEs in the functionality left.
* Parsing of the PPDs is somewhat suboptimal.
* (I think it's best to leave optimisation until more of GNUstep is done).
* The *OpenUI, *CloseUI, *OpenGroup and *CloseGroup are not processed.
* (This is not required in the OpenStep standard, but could be useful).
*/
#include "config.h"
#import <Foundation/NSDebug.h>
#import <Foundation/NSBundle.h>
#import <Foundation/NSDictionary.h>
#import <Foundation/NSException.h>
#import <Foundation/NSString.h>
#import <Foundation/NSUserDefaults.h>
#import <Foundation/NSValue.h>
#import "GSWIN32Printer.h"
#import "GNUstepGUI/GSPrinting.h"
@implementation GSWIN32Printer
//
// Class methods
//
+(void) initialize
{
if (self == [GSWIN32Printer class])
{
// Initial version
[self setVersion:1];
}
}
+(id) allocWithZone: (NSZone*) zone
{
return NSAllocateObject(self, 0, zone);
}
//
// Finding an NSPrinter
//
+ (NSPrinter*) printerWithName: (NSString*) name
{
NSDictionary* printersDict;
NSDictionary* printerEntry;
NSPrinter* printer;
printersDict = [self printersDictionary];
printerEntry = [printersDict objectForKey: name];
if( printerEntry == nil)
{
[NSException raise: NSGenericException
format: @"(GSWIN32) Could not find printer named %@", name];
return nil;
}
NSDebugMLLog(@"GSPrinting", @"Creating NSPrinter with Printer Entry: %@",
[printerEntry description]);
printer = [(GSWIN32Printer*)[self alloc]
initWithName: name
withType: [printerEntry objectForKey: @"Type"]
withHost: [printerEntry objectForKey: @"Host"]
withNote: [printerEntry objectForKey: @"Note"]];
[printer parsePPDAtPath: [printerEntry objectForKey: @"PPDPath"]];
return AUTORELEASE(printer);
}
+ (NSArray *)printerNames
{
return [[self printersDictionary] allKeys];
}
//
// Load the printer setup from NSUserDefaults
//
+ (NSDictionary*) printersDictionary
{
static BOOL didWarn;
NSUserDefaults* defaults;
NSDictionary *printers;
defaults = [NSUserDefaults standardUserDefaults];
printers = [defaults dictionaryForKey: @"GSWIN32Printers"];
if (!printers) //Not set, make a default printer because we are nice.
{
NSString *ppdPath;
NSMutableDictionary *printerEntry;
printers = [NSMutableDictionary dictionary];
printerEntry = [NSMutableDictionary dictionary];
ppdPath = [NSBundle
pathForLibraryResource: @"Generic-PostScript_Printer-Postscript"
ofType: @"ppd"
inDirectory: @"PostScript/PPD"];
NSAssert(ppdPath,
@"Couldn't find the PPD file for the fallback printer.");
[printerEntry setObject: ppdPath
forKey: @"PPDPath"];
[printerEntry setObject: @"localhost"
forKey: @"Host"];
[printerEntry setObject: @"Automatically Generated"
forKey: @"Note"];
[printerEntry setObject: @"Unknown"
forKey: @"Type"];
[(NSMutableDictionary*)printers setObject: printerEntry
forKey: @"Unnamed"];
[defaults setObject: printers forKey: @"GSWIN32Printers"];
[defaults synchronize];
if (!didWarn)
{
NSLog(@"Creating a default printer since no printer has been set "
@"in the user defaults (under the GSWIN32Printers key).");
didWarn = YES;
}
}
return printers;
}
@end