2001-10-16 02:09:09 +00:00
|
|
|
/** <title>NSPageLayout</title>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
<abstract>Standard panel for querying user about page layout.</abstract>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2004-07-10 10:19:34 +00:00
|
|
|
Copyright (C) 2001,2004 Free Software Foundation, Inc.
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2001-12-17 16:51:51 +00:00
|
|
|
Written By: Adam Fedor <fedor@gnu.org>
|
2001-10-16 02:09:09 +00:00
|
|
|
Date: Oct 2001
|
2004-07-10 10:19:34 +00:00
|
|
|
Modified for Printing Backend Support
|
|
|
|
Author: Chad Hardin <cehardin@mac.com>
|
|
|
|
Date: June 2004
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
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 Library 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
|
|
|
|
Library General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Library General Public
|
1996-10-18 17:14:13 +00:00
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
|
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
2001-10-16 02:09:09 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
*/
|
|
|
|
|
2003-06-13 15:01:12 +00:00
|
|
|
#include "AppKit/NSApplication.h"
|
|
|
|
#include "AppKit/NSFont.h"
|
|
|
|
#include "AppKit/NSTextField.h"
|
|
|
|
#include "AppKit/NSImage.h"
|
|
|
|
#include "AppKit/NSImageView.h"
|
2004-07-11 21:31:39 +00:00
|
|
|
#include "AppKit/NSBezierPath.h"
|
2003-06-13 15:01:12 +00:00
|
|
|
#include "AppKit/NSBox.h"
|
|
|
|
#include "AppKit/NSButton.h"
|
2004-07-11 21:31:39 +00:00
|
|
|
#include "AppKit/NSColor.h"
|
2003-06-13 15:01:12 +00:00
|
|
|
#include "AppKit/NSComboBox.h"
|
|
|
|
#include "AppKit/NSPopUpButton.h"
|
|
|
|
#include "AppKit/NSMatrix.h"
|
|
|
|
#include "AppKit/NSNibLoading.h"
|
|
|
|
#include "AppKit/NSForm.h"
|
|
|
|
#include "AppKit/NSFormCell.h"
|
|
|
|
#include "AppKit/NSPrintInfo.h"
|
|
|
|
#include "AppKit/NSPageLayout.h"
|
|
|
|
#include "AppKit/NSPrinter.h"
|
2003-07-31 23:52:10 +00:00
|
|
|
#include "GSGuiPrivate.h"
|
2004-07-10 10:19:34 +00:00
|
|
|
#include "GNUstepGUI/GSPrinting.h"
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2001-10-16 03:20:01 +00:00
|
|
|
static NSPageLayout *shared_instance;
|
2000-10-16 22:52:59 +00:00
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
|
2004-07-11 21:31:39 +00:00
|
|
|
//#define CONTROL(panel, name) [[panel contentView] viewWithTag: name]
|
2001-10-16 02:09:09 +00:00
|
|
|
|
2002-09-06 00:34:26 +00:00
|
|
|
@implementation NSApplication (NSPageLayout)
|
|
|
|
|
|
|
|
- (void) runPageLayout: sender
|
|
|
|
{
|
|
|
|
[[NSPageLayout pageLayout] runModal];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2004-07-11 21:31:39 +00:00
|
|
|
|
|
|
|
@interface GSPageLayoutController : NSObject
|
|
|
|
{
|
|
|
|
NSSize _size;
|
|
|
|
double _scale;
|
|
|
|
id _panel;
|
|
|
|
id _orientationMatrix;
|
|
|
|
id _widthField;
|
|
|
|
id _heightField;
|
|
|
|
id _unitsButton;
|
|
|
|
id _paperNameButton;
|
|
|
|
id _scaleField;
|
|
|
|
id _imageButton;
|
|
|
|
id _miniPageView;
|
|
|
|
NSPrintInfo *_printInfo;
|
|
|
|
NSView *_accessoryView;
|
|
|
|
}
|
|
|
|
-(NSPageLayout*) panel;
|
|
|
|
|
|
|
|
//IBActions
|
|
|
|
-(void) buttonClicked: (id)sender;
|
|
|
|
-(void) paperSelected: (id)sender;
|
|
|
|
-(void) unitsSelected: (id)sender;
|
|
|
|
-(void) scaleSelected: (id)sender;
|
|
|
|
-(void) widthSelected: (id)sender;
|
|
|
|
-(void) heightSelected: (id)sender;
|
|
|
|
-(void) orientationMatrixClicked: (id)sender;
|
|
|
|
|
|
|
|
//internal
|
|
|
|
-(void) setNewPageSize;
|
|
|
|
-(float) factorForIndex: (int)sel;
|
|
|
|
|
|
|
|
//access to ivars
|
|
|
|
-(NSPrintInfo*) printInfo;
|
|
|
|
-(void) setPrintInfo:(NSPrintInfo*)printInfo;
|
|
|
|
-(NSView*) accessoryView;
|
|
|
|
-(void) setAccessoryView:(NSView*)accessoryView;
|
|
|
|
-(NSSize) pageSize;
|
|
|
|
|
|
|
|
|
|
|
|
//Handling of NSPageLayout implementation
|
|
|
|
-(void)convertOldFactor:(float *)old
|
|
|
|
newFactor:(float *)new;
|
|
|
|
-(void)readPrintInfo;
|
|
|
|
-(void)writePrintInfo;
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-10-16 02:11:30 +00:00
|
|
|
/**
|
2001-10-16 02:09:09 +00:00
|
|
|
<unit>
|
|
|
|
<heading>NSPageLayout</heading>
|
|
|
|
<p>
|
|
|
|
NSPageLayout provides a panel that allows the user to specify certain
|
|
|
|
information about the printer and how data is formatted for printing.
|
|
|
|
This includes information about the paper size and orientation.
|
|
|
|
|
|
|
|
Typically you would create a page layout panel with the
|
2002-01-26 04:14:38 +00:00
|
|
|
+pageLayout class method. However, the best
|
2001-10-16 02:09:09 +00:00
|
|
|
way to use the panel is to have the application
|
|
|
|
call the runPageLayout: method in the NSApplication object
|
|
|
|
which would both create a standard NSPageLayout panel and display it
|
|
|
|
in a modal loop. This method would be sent up the responder chain if
|
|
|
|
the user clicked on a Page Layout menu item.
|
|
|
|
</p>
|
|
|
|
</unit>
|
2001-10-16 02:11:30 +00:00
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
@implementation NSPageLayout
|
|
|
|
|
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
2004-07-10 10:19:34 +00:00
|
|
|
/** Load the appropriate bundle for the PageLayout
|
|
|
|
(eg: GSLPRPageLayout, GSCUPSPageLayout).
|
|
|
|
*/
|
|
|
|
+ (id) allocWithZone: (NSZone*) zone
|
|
|
|
{
|
|
|
|
Class principalClass;
|
|
|
|
|
|
|
|
principalClass = [[GSPrinting printingBundle] principalClass];
|
|
|
|
|
|
|
|
if( principalClass == nil )
|
|
|
|
return nil;
|
|
|
|
|
|
|
|
return [[principalClass pageLayoutClass] allocWithZone: zone];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
/** Creates and returns a shared instance of the NSPageLayout panel.
|
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
+ (NSPageLayout *)pageLayout
|
|
|
|
{
|
2000-10-16 22:52:59 +00:00
|
|
|
if (shared_instance == nil)
|
|
|
|
{
|
2004-07-11 21:31:39 +00:00
|
|
|
GSPageLayoutController *controller;
|
|
|
|
controller = [[GSPageLayoutController alloc] init];
|
|
|
|
shared_instance = [controller panel];
|
2000-10-16 22:52:59 +00:00
|
|
|
}
|
|
|
|
return shared_instance;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2003-07-21 10:41:10 +00:00
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// Running the Panel
|
|
|
|
//
|
2001-10-16 02:09:09 +00:00
|
|
|
/** Display the Page Layout panel in a modal loop. Saves any aquired
|
|
|
|
information in the shared NSPrintInfo object. Returns NSCancelButton
|
|
|
|
if the user clicks the Cancel button or NSOKButton otherwise.
|
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
- (int)runModal
|
|
|
|
{
|
2000-10-16 22:52:59 +00:00
|
|
|
return [self runModalWithPrintInfo: [NSPrintInfo sharedPrintInfo]];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
/** Display the Page Layout panel in a modal loop. Saves any aquired
|
|
|
|
information in the indicated NSPrintInfo object. Returns NSCancelButton
|
|
|
|
if the user clicks the Cancel button or NSOKButton otherwise.
|
|
|
|
*/
|
2004-07-11 21:31:39 +00:00
|
|
|
- (int)runModalWithPrintInfo:(NSPrintInfo *)printInfo
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
2001-09-23 22:08:49 +00:00
|
|
|
int result;
|
|
|
|
|
2004-07-11 21:31:39 +00:00
|
|
|
[_controller setPrintInfo: printInfo];
|
2000-10-16 22:52:59 +00:00
|
|
|
[self readPrintInfo];
|
|
|
|
|
2001-09-23 22:08:49 +00:00
|
|
|
result = [NSApp runModalForWindow: self];
|
2000-10-16 22:52:59 +00:00
|
|
|
[self orderOut: self];
|
2001-09-23 22:08:49 +00:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)beginSheetWithPrintInfo:(NSPrintInfo *)printInfo
|
|
|
|
modalForWindow:(NSWindow *)docWindow
|
|
|
|
delegate:(id)delegate
|
|
|
|
didEndSelector:(SEL)didEndSelector
|
|
|
|
contextInfo:(void *)contextInfo
|
|
|
|
{
|
2004-07-11 21:31:39 +00:00
|
|
|
[_controller setPrintInfo: printInfo];
|
2001-09-23 22:08:49 +00:00
|
|
|
[self readPrintInfo];
|
|
|
|
|
|
|
|
[NSApp beginSheet: self
|
2004-07-11 21:31:39 +00:00
|
|
|
modalForWindow: docWindow
|
|
|
|
modalDelegate: delegate
|
|
|
|
didEndSelector: didEndSelector
|
|
|
|
contextInfo: contextInfo];
|
2001-09-23 22:08:49 +00:00
|
|
|
|
|
|
|
[self orderOut: self];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Customizing the Panel
|
|
|
|
//
|
2001-10-16 02:09:09 +00:00
|
|
|
/** Returns the accessory view for the page layout panel
|
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
- (NSView *)accessoryView
|
|
|
|
{
|
2004-07-11 21:31:39 +00:00
|
|
|
return [_controller accessoryView];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
/** Set the accessory view for the page layout panel
|
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
- (void)setAccessoryView:(NSView *)aView
|
2000-11-21 19:22:45 +00:00
|
|
|
{
|
2004-07-11 21:31:39 +00:00
|
|
|
[_controller setAccessoryView: aView];
|
2000-11-21 19:22:45 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2004-07-11 21:31:39 +00:00
|
|
|
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
//
|
|
|
|
// Updating the Panel's Display
|
|
|
|
//
|
2001-10-16 02:09:09 +00:00
|
|
|
/** Convert the old value to a new one based on the current units. This
|
|
|
|
method has been depreciated. It doesn't do anything useful
|
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
- (void)convertOldFactor:(float *)old
|
2004-07-11 21:31:39 +00:00
|
|
|
newFactor:(float *)new
|
2001-10-16 02:09:09 +00:00
|
|
|
{
|
2004-07-11 21:31:39 +00:00
|
|
|
[_controller convertOldFactor: old
|
|
|
|
newFactor: new];
|
2001-10-16 02:09:09 +00:00
|
|
|
}
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
/** This method has been depreciated. It doesn't do anything useful.
|
|
|
|
*/
|
|
|
|
- (void)pickedButton:(id)sender
|
|
|
|
{
|
|
|
|
NSLog(@"[NSPageLayout -pickedButton:] method depreciated");
|
|
|
|
}
|
|
|
|
|
|
|
|
/** This method has been depreciated. It doesn't do anything useful.
|
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
- (void)pickedOrientation:(id)sender
|
2000-10-16 22:52:59 +00:00
|
|
|
{
|
2001-10-16 02:09:09 +00:00
|
|
|
NSLog(@"[NSPageLayout -pickedOrientation:] method depreciated");
|
2000-10-16 22:52:59 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
/** This method has been depreciated. It doesn't do anything useful.
|
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
- (void)pickedPaperSize:(id)sender
|
2000-10-16 22:52:59 +00:00
|
|
|
{
|
2001-10-16 02:09:09 +00:00
|
|
|
NSLog(@"[NSPageLayout -pickedPaperSize:] method depreciated");
|
2001-09-23 22:08:49 +00:00
|
|
|
}
|
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
/** This method has been depreciated. It doesn't do anything useful.
|
|
|
|
*/
|
2001-09-23 22:08:49 +00:00
|
|
|
- (void)pickedLayout:(id)sender
|
|
|
|
{
|
2001-10-16 02:09:09 +00:00
|
|
|
NSLog(@"[NSPageLayout -pickedLayout:] method depreciated");
|
2000-10-16 22:52:59 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
/** This method has been depreciated. It doesn't do anything useful.
|
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
- (void)pickedUnits:(id)sender
|
2000-10-16 22:52:59 +00:00
|
|
|
{
|
2001-10-16 02:09:09 +00:00
|
|
|
NSLog(@"[NSPageLayout -pickedUnits:] method depreciated");
|
2000-10-16 22:52:59 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Communicating with the NSPrintInfo Object
|
|
|
|
//
|
2001-10-16 02:09:09 +00:00
|
|
|
/** Return the NSPrintInfo object that the receiver stores layout information
|
|
|
|
into.
|
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
- (NSPrintInfo *)printInfo
|
|
|
|
{
|
2004-07-11 21:31:39 +00:00
|
|
|
return [_controller printInfo];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
/** Updates the receiver panel with information from its NSPrintInfo object
|
|
|
|
*/
|
1996-05-30 20:03:15 +00:00
|
|
|
- (void)readPrintInfo
|
2000-10-16 22:52:59 +00:00
|
|
|
{
|
2004-07-11 21:31:39 +00:00
|
|
|
[_controller readPrintInfo];
|
|
|
|
}
|
|
|
|
|
|
|
|
/** Writes any layout information set by the user to the receiver's
|
|
|
|
NSPrintInfo object
|
|
|
|
*/
|
|
|
|
- (void)writePrintInfo
|
|
|
|
{
|
|
|
|
[_controller writePrintInfo];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Controller for the PageLayout Panel
|
|
|
|
//
|
|
|
|
@implementation GSPageLayoutController
|
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
NSString *panelPath;
|
|
|
|
NSDictionary *table;
|
|
|
|
NSImage *image;
|
|
|
|
|
|
|
|
self = [super init];
|
|
|
|
panelPath = [GSGuiBundle() pathForResource: @"GSPageLayout"
|
|
|
|
ofType: @"gorm"
|
|
|
|
inDirectory: nil];
|
|
|
|
|
|
|
|
NSLog(@"Panel path=%@",panelPath);
|
|
|
|
table = [NSDictionary dictionaryWithObject: self
|
|
|
|
forKey: @"NSOwner"];
|
|
|
|
|
|
|
|
if ([NSBundle loadNibFile: panelPath
|
|
|
|
externalNameTable: table
|
|
|
|
withZone: [self zone]] == NO)
|
|
|
|
{
|
|
|
|
NSRunAlertPanel(@"Error", @"Could not load page layout panel resource",
|
|
|
|
@"OK", NULL, NULL);
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
image = [[NSApplication sharedApplication] applicationIconImage];
|
|
|
|
[_imageButton setImage: image];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSPageLayout*) panel
|
|
|
|
{
|
|
|
|
return (NSPageLayout*)_panel;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Private communication with our panel objects */
|
|
|
|
- (void) buttonClicked: (id)sender
|
|
|
|
{
|
|
|
|
int picked;
|
|
|
|
int tag = [sender tag];
|
|
|
|
|
|
|
|
NSLog(@"buttonClicked:");
|
|
|
|
if (tag == NSPLOKButton)
|
|
|
|
{
|
|
|
|
picked = NSOKButton;
|
|
|
|
[self writePrintInfo];
|
|
|
|
}
|
|
|
|
else if (tag == NSPLCancelButton)
|
|
|
|
{
|
|
|
|
picked = NSCancelButton;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
NSLog(@"NSPageLayout button press from unknown sender %@ tag %d",
|
|
|
|
sender, tag);
|
|
|
|
picked = NSOKButton;
|
|
|
|
}
|
|
|
|
[NSApp stopModalWithCode: picked];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) setNewPageSize
|
|
|
|
{
|
|
|
|
double factor;
|
|
|
|
|
|
|
|
factor = [self factorForIndex: [_unitsButton indexOfSelectedItem]];
|
|
|
|
[_widthField setDoubleValue: _size.width * factor];
|
|
|
|
[_heightField setDoubleValue: _size.height * factor];
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Converts between points, millimeters, centimeters, and inches, in that order.
|
|
|
|
// Dependent upon the order of which the values appear in the Gorm popup.
|
|
|
|
//
|
|
|
|
- (float) factorForIndex: (int)sel
|
|
|
|
{
|
|
|
|
switch (sel)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case 0: return 1.0;
|
|
|
|
case 1: return 25.4/72;
|
|
|
|
case 2: return 2.54/72;
|
|
|
|
case 3: return 1.0/72;
|
|
|
|
}
|
|
|
|
}
|
2001-10-16 02:09:09 +00:00
|
|
|
|
2004-07-11 21:31:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
- (void) paperSelected: (id)sender
|
|
|
|
{
|
|
|
|
NSPrinter *printer;
|
|
|
|
|
|
|
|
_scale = 100;
|
|
|
|
[_scaleField setDoubleValue: _scale];
|
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
printer = [_printInfo printer];
|
2004-07-11 21:31:39 +00:00
|
|
|
_size = [printer pageSizeForPaper: [sender titleOfSelectedItem]];
|
|
|
|
|
|
|
|
//check if the user selected landscape mode, if so, switch out the
|
|
|
|
//width and height
|
|
|
|
if ([_orientationMatrix selectedColumn] > 0)
|
|
|
|
{
|
|
|
|
double temp = _size.width;
|
|
|
|
_size.width = _size.height;
|
|
|
|
_size.height = temp;
|
|
|
|
}
|
|
|
|
[self setNewPageSize];
|
|
|
|
[_miniPageView setNeedsDisplay: YES];
|
|
|
|
}
|
2001-10-16 02:09:09 +00:00
|
|
|
|
2004-07-11 21:31:39 +00:00
|
|
|
- (void) unitsSelected: (id)sender
|
|
|
|
{
|
|
|
|
[self setNewPageSize];
|
|
|
|
[_miniPageView setNeedsDisplay: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) scaleSelected: (id)sender
|
|
|
|
{
|
|
|
|
float scale;
|
|
|
|
|
|
|
|
scale = [_scaleField doubleValue];
|
|
|
|
|
|
|
|
if( scale == 0.0 )
|
2001-09-23 22:08:49 +00:00
|
|
|
{
|
2004-07-11 21:31:39 +00:00
|
|
|
[_scaleField setDoubleValue: _scale];
|
2001-09-23 22:08:49 +00:00
|
|
|
}
|
2001-10-16 02:09:09 +00:00
|
|
|
else
|
2004-07-11 21:31:39 +00:00
|
|
|
{
|
|
|
|
_scale = scale;
|
|
|
|
_size.width *= (_scale/100);
|
|
|
|
_size.height *= (_scale/100);
|
|
|
|
}
|
|
|
|
|
|
|
|
[self setNewPageSize];
|
|
|
|
[_miniPageView setNeedsDisplay: YES];
|
|
|
|
}
|
2001-09-23 22:08:49 +00:00
|
|
|
|
2004-07-11 21:31:39 +00:00
|
|
|
-(void) widthSelected: (id)sender
|
|
|
|
{
|
|
|
|
double width;
|
|
|
|
|
|
|
|
width = [_widthField doubleValue];
|
|
|
|
|
|
|
|
if( width == 0.0 )
|
2001-09-23 22:08:49 +00:00
|
|
|
{
|
2004-07-11 21:31:39 +00:00
|
|
|
[_widthField setDoubleValue: _size.width];
|
2001-09-23 22:08:49 +00:00
|
|
|
}
|
2001-10-16 02:09:09 +00:00
|
|
|
else
|
|
|
|
{
|
2004-07-11 21:31:39 +00:00
|
|
|
_size.width = width;
|
|
|
|
[_miniPageView setNeedsDisplay: YES];
|
2001-10-16 02:09:09 +00:00
|
|
|
}
|
2004-07-11 21:31:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
-(void) heightSelected: (id)sender
|
|
|
|
{
|
|
|
|
double height;
|
|
|
|
|
|
|
|
height = [_heightField doubleValue];
|
|
|
|
|
|
|
|
if( height == 0.0 )
|
|
|
|
{
|
|
|
|
[_heightField setDoubleValue: _size.height];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_size.height = height;
|
|
|
|
[_miniPageView setNeedsDisplay: YES];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) orientationMatrixClicked: (id)sender
|
|
|
|
{
|
|
|
|
double temp;
|
|
|
|
|
|
|
|
if ([sender selectedColumn] > 0)
|
|
|
|
{
|
|
|
|
temp = MIN(_size.width, _size.height);
|
|
|
|
_size.width = MAX(_size.width, _size.height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
temp = MAX(_size.width, _size.height);
|
|
|
|
_size.width = MIN(_size.width, _size.height);
|
|
|
|
}
|
|
|
|
_size.height = temp;
|
|
|
|
[self setNewPageSize];
|
|
|
|
[_miniPageView setNeedsDisplay: YES];
|
|
|
|
}
|
|
|
|
|
|
|
|
-(NSPrintInfo*) printInfo
|
|
|
|
{
|
|
|
|
return _printInfo;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) setPrintInfo:(NSPrintInfo*)printInfo
|
|
|
|
{
|
|
|
|
ASSIGN( _printInfo, printInfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
-(NSView*) accessoryView
|
|
|
|
{
|
|
|
|
return _accessoryView;
|
|
|
|
}
|
|
|
|
|
|
|
|
-(void) setAccessoryView:(NSView*)accessoryView
|
|
|
|
{
|
|
|
|
ASSIGN( _accessoryView, accessoryView);
|
|
|
|
}
|
|
|
|
|
|
|
|
-(NSSize) pageSize
|
|
|
|
{
|
|
|
|
return _size;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)convertOldFactor:(float *)old
|
|
|
|
newFactor:(float *)new
|
|
|
|
{
|
|
|
|
int sel;
|
|
|
|
|
|
|
|
if (old == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
sel = [_unitsButton indexOfSelectedItem];
|
|
|
|
if (new)
|
|
|
|
*new = [self factorForIndex: sel];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)readPrintInfo
|
|
|
|
{
|
|
|
|
NSString *string;
|
|
|
|
NSPrinter *printer;
|
|
|
|
NSDictionary *dict;
|
|
|
|
|
|
|
|
printer = [_printInfo printer];
|
|
|
|
dict = [_printInfo dictionary];
|
|
|
|
|
|
|
|
/* Setup the paper name popup */
|
|
|
|
{
|
|
|
|
[_paperNameButton removeAllItems];
|
|
|
|
string = [_printInfo paperName];
|
|
|
|
if (string)
|
|
|
|
{
|
|
|
|
NSArray *paperNames;
|
|
|
|
paperNames = [printer stringListForKey:@"PageSize"
|
|
|
|
inTable:@"PPD"];
|
|
|
|
if ([paperNames count])
|
|
|
|
{
|
|
|
|
NSEnumerator *paperNamesEnum;
|
|
|
|
NSString *paperName;
|
|
|
|
paperNamesEnum = [paperNames objectEnumerator];
|
|
|
|
|
|
|
|
while( (paperName = [paperNamesEnum nextObject]) )
|
|
|
|
{
|
|
|
|
[_paperNameButton addItemWithTitle: paperName];
|
|
|
|
}
|
|
|
|
[_paperNameButton selectItemWithTitle: string];
|
|
|
|
}
|
|
|
|
else //PPD was empty!
|
|
|
|
{
|
|
|
|
[_paperNameButton addItemWithTitle: string];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else //this really should not happen man.
|
|
|
|
{
|
|
|
|
[_paperNameButton addItemWithTitle: @"Unknown"];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Set up units */
|
|
|
|
{
|
|
|
|
//The loading of the GORM file should ensure this is ok.
|
|
|
|
[_unitsButton selectItemAtIndex: 0];
|
|
|
|
}
|
2001-10-16 02:09:09 +00:00
|
|
|
|
|
|
|
/* Set up size form */
|
2004-07-11 21:31:39 +00:00
|
|
|
{
|
|
|
|
_size = [_printInfo paperSize];
|
|
|
|
[_widthField setDoubleValue: _size.width];
|
|
|
|
[_heightField setDoubleValue: _size.height];
|
|
|
|
}
|
2001-10-16 02:09:09 +00:00
|
|
|
|
|
|
|
/* Set up the orientation */
|
|
|
|
{
|
|
|
|
NSPrintingOrientation orient = [_printInfo orientation];
|
2004-07-11 21:31:39 +00:00
|
|
|
[_orientationMatrix selectCellAtRow: 0
|
|
|
|
column: (orient - NSPortraitOrientation)];
|
2001-10-16 02:09:09 +00:00
|
|
|
}
|
2004-03-01 03:00:24 +00:00
|
|
|
|
|
|
|
//TODO Scaling
|
|
|
|
{
|
|
|
|
float scale = 100;
|
|
|
|
NSNumber *scaleNumber;
|
2004-03-08 18:22:07 +00:00
|
|
|
if ((scaleNumber = [dict objectForKey:NSPrintScalingFactor]))
|
2004-03-01 03:00:24 +00:00
|
|
|
{
|
2004-07-11 21:31:39 +00:00
|
|
|
scale = [scaleNumber floatValue];
|
2004-03-01 03:00:24 +00:00
|
|
|
}
|
|
|
|
|
2004-07-11 21:31:39 +00:00
|
|
|
[_scaleField setFloatValue: scale];
|
|
|
|
_scale = scale;
|
2004-03-01 03:00:24 +00:00
|
|
|
}
|
|
|
|
|
2000-10-16 22:52:59 +00:00
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)writePrintInfo
|
2000-10-16 22:52:59 +00:00
|
|
|
{
|
2004-07-11 21:31:39 +00:00
|
|
|
NSString *string;
|
2001-10-16 02:09:09 +00:00
|
|
|
NSPrinter *printer;
|
2004-03-01 03:00:24 +00:00
|
|
|
float scale;
|
|
|
|
NSMutableDictionary *dict = [_printInfo dictionary];
|
2000-10-16 22:52:59 +00:00
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
printer = [_printInfo printer];
|
2004-07-11 21:31:39 +00:00
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
/* Write Paper Name */
|
2004-07-11 21:31:39 +00:00
|
|
|
{
|
|
|
|
string = [_paperNameButton titleOfSelectedItem];
|
|
|
|
[_printInfo setPaperName: string];
|
|
|
|
}
|
2001-09-23 22:08:49 +00:00
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
/* Write Orientation */
|
2004-07-11 21:31:39 +00:00
|
|
|
{
|
|
|
|
[_printInfo setOrientation:
|
|
|
|
[_orientationMatrix selectedColumn]+NSPortraitOrientation];
|
|
|
|
}
|
2004-03-01 03:00:24 +00:00
|
|
|
|
2004-07-11 21:31:39 +00:00
|
|
|
/* Write Scaling Factor */
|
|
|
|
{
|
|
|
|
scale = _scale;
|
|
|
|
[dict setObject: [NSNumber numberWithFloat:scale]
|
|
|
|
forKey: NSPrintScalingFactor];
|
|
|
|
}
|
2004-03-01 03:00:24 +00:00
|
|
|
|
|
|
|
|
2001-10-16 02:09:09 +00:00
|
|
|
/* Write Size */
|
2001-11-08 18:26:39 +00:00
|
|
|
/* FIXME: Currently don't allow writing custom size. */
|
2001-09-23 22:08:49 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2004-07-11 21:31:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Show the preview of the page's dimensions
|
|
|
|
//
|
|
|
|
|
|
|
|
@interface GSPageLayoutMiniPageView : NSView
|
|
|
|
{
|
|
|
|
id _pageLayoutController;
|
|
|
|
}
|
|
|
|
@end
|
|
|
|
|
|
|
|
|
|
|
|
//
|
|
|
|
// Show the preview of the page's dimensions
|
|
|
|
//
|
|
|
|
@implementation GSPageLayoutMiniPageView
|
|
|
|
|
|
|
|
-(int) tag
|
|
|
|
{
|
|
|
|
return NSPLMiniPageView;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) drawRect: (NSRect)rect
|
|
|
|
{
|
|
|
|
NSSize pageSize;
|
|
|
|
NSRect paper;
|
|
|
|
NSRect shadow;
|
|
|
|
double ratio;
|
|
|
|
double width, height;
|
|
|
|
NSColor *shadowColor;
|
|
|
|
|
|
|
|
//Draw the background
|
|
|
|
NSRect bounds = [self bounds];
|
|
|
|
//[[NSColor windowBackgroundColor] set];
|
|
|
|
//[NSBezierPath fillRect: bounds];
|
|
|
|
|
|
|
|
pageSize = [_pageLayoutController pageSize];
|
|
|
|
|
|
|
|
if( pageSize.width >= pageSize.height)
|
|
|
|
{
|
|
|
|
ratio = pageSize.height/ pageSize.width;
|
|
|
|
width = bounds.size.width;
|
|
|
|
height = width * ratio;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ratio = pageSize.width / pageSize.height;
|
|
|
|
height = bounds.size.height;
|
|
|
|
width = height * ratio;
|
|
|
|
}
|
|
|
|
|
|
|
|
//make the page a bit smaller
|
|
|
|
width *= 0.75;
|
|
|
|
height *= 0.75;
|
|
|
|
|
|
|
|
paper.origin.x = (bounds.size.width - width) / 2;
|
|
|
|
paper.origin.y = (bounds.size.height - height) / 2;
|
|
|
|
paper.size.width = width;
|
|
|
|
paper.size.height = height;
|
|
|
|
|
|
|
|
shadow = paper;
|
|
|
|
if( [self isFlipped] == NO)
|
|
|
|
shadow.origin.y -= 2;
|
|
|
|
else
|
|
|
|
shadow.origin.y += 2;
|
|
|
|
|
|
|
|
shadow.origin.x += 2;
|
|
|
|
|
|
|
|
|
|
|
|
//first draw the shadow
|
|
|
|
shadowColor = [[NSColor windowBackgroundColor] shadowWithLevel: 0.5];
|
|
|
|
|
|
|
|
[shadowColor set];
|
|
|
|
[NSBezierPath fillRect: shadow];
|
|
|
|
|
|
|
|
//now draw the paper
|
|
|
|
[[NSColor whiteColor] set];
|
|
|
|
[NSBezierPath fillRect: paper];
|
|
|
|
[[NSColor blackColor] set];
|
|
|
|
[NSBezierPath strokeRect: paper];
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|