1996-05-30 20:03:15 +00:00
|
|
|
/*
|
|
|
|
NSPageLayout.m
|
|
|
|
|
2000-10-16 22:52:59 +00:00
|
|
|
Page setup panel
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
Copyright (C) 1996 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Author: Scott Christley <scottc@net-community.com>
|
|
|
|
Date: 1996
|
2000-10-16 22:52:59 +00:00
|
|
|
Author: Fred Kiefer <fredkiefer@gmx.de>
|
|
|
|
Date: 2000
|
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.
|
1996-05-30 20:03:15 +00:00
|
|
|
*/
|
|
|
|
|
2000-10-16 22:52:59 +00:00
|
|
|
#include <AppKit/NSApplication.h>
|
|
|
|
#include <AppKit/NSTextField.h>
|
|
|
|
#include <AppKit/NSButton.h>
|
|
|
|
#include <AppKit/NSPrintInfo.h>
|
1997-02-18 00:29:25 +00:00
|
|
|
#include <AppKit/NSPageLayout.h>
|
1996-05-30 20:03:15 +00:00
|
|
|
|
2000-10-16 22:52:59 +00:00
|
|
|
NSPageLayout *shared_instance;
|
|
|
|
|
|
|
|
@interface NSPageLayout (Private)
|
|
|
|
- (id) _initWithoutGModel;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
1996-05-30 20:03:15 +00:00
|
|
|
@implementation NSPageLayout
|
|
|
|
|
|
|
|
//
|
|
|
|
// Class methods
|
|
|
|
//
|
|
|
|
+ (void)initialize
|
|
|
|
{
|
|
|
|
if (self == [NSPageLayout class])
|
|
|
|
{
|
|
|
|
// Initial version
|
|
|
|
[self setVersion:1];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Creating an NSPageLayout Instance
|
|
|
|
//
|
|
|
|
+ (NSPageLayout *)pageLayout
|
|
|
|
{
|
2000-10-16 22:52:59 +00:00
|
|
|
if (shared_instance == nil)
|
|
|
|
{
|
|
|
|
shared_instance = [[NSPageLayout alloc] init];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[shared_instance _initDefaults];
|
|
|
|
}
|
|
|
|
return shared_instance;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Instance methods
|
|
|
|
//
|
2000-10-16 22:52:59 +00:00
|
|
|
- (id) init
|
|
|
|
{
|
|
|
|
self = [self _initWithoutGModel];
|
|
|
|
[self _initDefaults];
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) _initDefaults
|
|
|
|
{
|
|
|
|
// use points as the default
|
|
|
|
_old = 1.0;
|
|
|
|
_new = 1.0;
|
|
|
|
[super _initDefaults];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Running the Panel
|
|
|
|
//
|
|
|
|
- (int)runModal
|
|
|
|
{
|
2000-10-16 22:52:59 +00:00
|
|
|
return [self runModalWithPrintInfo: [NSPrintInfo sharedPrintInfo]];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (int)runModalWithPrintInfo:(NSPrintInfo *)pInfo
|
|
|
|
{
|
2000-10-16 22:52:59 +00:00
|
|
|
/*
|
|
|
|
NSRunAlertPanel (NULL, @"Page Layout Panel not implemented yet",
|
|
|
|
@"OK", NULL, NULL);
|
|
|
|
*/
|
|
|
|
// store the print Info
|
|
|
|
_printInfo = pInfo;
|
|
|
|
|
|
|
|
// read the values of the print info
|
|
|
|
[self readPrintInfo];
|
|
|
|
|
|
|
|
[NSApp runModalForWindow: self];
|
|
|
|
[self orderOut: self];
|
|
|
|
|
|
|
|
return _result;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Customizing the Panel
|
|
|
|
//
|
|
|
|
- (NSView *)accessoryView
|
|
|
|
{
|
|
|
|
return nil;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void)setAccessoryView:(NSView *)aView
|
|
|
|
{}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Updating the Panel's Display
|
|
|
|
//
|
|
|
|
- (void)convertOldFactor:(float *)old
|
|
|
|
newFactor:(float *)new
|
2000-10-16 22:52:59 +00:00
|
|
|
{
|
|
|
|
if (old)
|
|
|
|
*old = _old;
|
|
|
|
if (new)
|
|
|
|
*new = _new;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)pickedButton:(id)sender
|
2000-10-16 22:52:59 +00:00
|
|
|
{
|
|
|
|
if ([sender tag] == NSPLOKButton)
|
|
|
|
{
|
|
|
|
// check the items if the values are positive,
|
|
|
|
// if not select that item and keep on running.
|
|
|
|
NSTextField *field;
|
|
|
|
|
|
|
|
field = [[self contentView] viewWithTag: NSPLWidthForm];
|
|
|
|
if ((field != nil) && ([field floatValue] <= 0.0))
|
|
|
|
{
|
|
|
|
[field selectText: sender];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
field = [[self contentView] viewWithTag: NSPLHeightForm];
|
|
|
|
if ((field != nil) && ([field floatValue] <= 0.0))
|
|
|
|
{
|
|
|
|
[field selectText: sender];
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
_result = NSOKButton;
|
|
|
|
}
|
|
|
|
if ([sender tag] == NSPLCancelButton)
|
|
|
|
{
|
|
|
|
_result = NSOKButton;
|
|
|
|
}
|
|
|
|
|
|
|
|
[NSApp stopModal];
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)pickedOrientation:(id)sender
|
2000-10-16 22:52:59 +00:00
|
|
|
{
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)pickedPaperSize:(id)sender
|
2000-10-16 22:52:59 +00:00
|
|
|
{
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
- (void)pickedUnits:(id)sender
|
2000-10-16 22:52:59 +00:00
|
|
|
{
|
|
|
|
NSTextField *field;
|
|
|
|
float new, old;
|
|
|
|
|
|
|
|
// At this point the units have been selected but not set.
|
|
|
|
[self convertOldFactor:&old newFactor:&new];
|
|
|
|
|
|
|
|
field = [[self contentView] viewWithTag: NSPLWidthForm];
|
|
|
|
if (field != nil)
|
|
|
|
{
|
|
|
|
// Update field based on the conversion factors.
|
|
|
|
[field setFloatValue:([field floatValue]*new/old)];
|
|
|
|
}
|
|
|
|
|
|
|
|
field = [[self contentView] viewWithTag: NSPLHeightForm];
|
|
|
|
if (field != nil)
|
|
|
|
{
|
|
|
|
// Update field based on the conversion factors.
|
|
|
|
[field setFloatValue:([field floatValue]*new/old)];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the selected units.
|
|
|
|
_old = _new;
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// Communicating with the NSPrintInfo Object
|
|
|
|
//
|
|
|
|
- (NSPrintInfo *)printInfo
|
|
|
|
{
|
2000-10-16 22:52:59 +00:00
|
|
|
return _printInfo;
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void)readPrintInfo
|
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
|
|
|
{
|
|
|
|
}
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// NSCoding protocol
|
|
|
|
//
|
1999-03-02 08:58:30 +00:00
|
|
|
- (void) encodeWithCoder: (NSCoder*)aCoder
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
[super encodeWithCoder: aCoder];
|
1996-05-30 20:03:15 +00:00
|
|
|
}
|
|
|
|
|
1999-03-02 08:58:30 +00:00
|
|
|
- (id) initWithCoder: (NSCoder*)aDecoder
|
1996-05-30 20:03:15 +00:00
|
|
|
{
|
1999-03-02 08:58:30 +00:00
|
|
|
[super initWithCoder: aDecoder];
|
1996-05-30 20:03:15 +00:00
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
2000-10-16 22:52:59 +00:00
|
|
|
|
|
|
|
@implementation NSPageLayout (Private)
|
|
|
|
|
|
|
|
- (id) _initWithoutGModel
|
|
|
|
{
|
|
|
|
NSRect rect = {{100,100}, {300,300}};
|
|
|
|
unsigned int style = NSTitledWindowMask | NSClosableWindowMask;
|
|
|
|
|
|
|
|
self = [super initWithContentRect: rect
|
|
|
|
styleMask: style
|
|
|
|
backing: NSBackingStoreRetained
|
|
|
|
defer: NO
|
|
|
|
screen: nil];
|
|
|
|
if (self != nil)
|
|
|
|
{
|
|
|
|
NSButton *okButton;
|
|
|
|
NSButton *cancelButton;
|
|
|
|
NSRect rb = {{56,8}, {72,24}};
|
|
|
|
NSRect db = {{217,8}, {72,24}};
|
|
|
|
NSView *content = [self contentView];
|
|
|
|
|
|
|
|
[self setTitle: @"Page Layout"];
|
|
|
|
|
|
|
|
// cancle button
|
|
|
|
cancelButton = [[NSButton alloc] initWithFrame: rb];
|
|
|
|
[cancelButton setStringValue: @"Cancel"];
|
|
|
|
[cancelButton setAction: @selector(pickedButton:)];
|
|
|
|
[cancelButton setTarget: self];
|
|
|
|
[cancelButton setTag: NSPLCancelButton];
|
|
|
|
[content addSubview: cancelButton];
|
|
|
|
RELEASE(cancelButton);
|
|
|
|
|
|
|
|
// OK button
|
|
|
|
okButton = [[NSButton alloc] initWithFrame: db];
|
|
|
|
[okButton setStringValue: @"OK"];
|
|
|
|
[okButton setAction: @selector(pickedButton:)];
|
|
|
|
[okButton setTarget: self];
|
|
|
|
[okButton setTag: NSPLOKButton];
|
|
|
|
[content addSubview: okButton];
|
|
|
|
// make it the default button
|
|
|
|
[self setDefaultButtonCell: [okButton cell]];
|
|
|
|
RELEASE(okButton);
|
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
@end
|
|
|
|
|