diff --git a/Source/NSPageLayout.m b/Source/NSPageLayout.m index 992ddb904..eddb437ee 100644 --- a/Source/NSPageLayout.m +++ b/Source/NSPageLayout.m @@ -1,12 +1,14 @@ /* NSPageLayout.m - Description... + Page setup panel Copyright (C) 1996 Free Software Foundation, Inc. Author: Scott Christley Date: 1996 + Author: Fred Kiefer + Date: 2000 This file is part of the GNUstep GUI Library. @@ -26,9 +28,19 @@ 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ -#include +#include +#include +#include +#include #include +NSPageLayout *shared_instance; + +@interface NSPageLayout (Private) +- (id) _initWithoutGModel; + +@end + @implementation NSPageLayout // @@ -48,24 +60,60 @@ // + (NSPageLayout *)pageLayout { - return nil; + if (shared_instance == nil) + { + shared_instance = [[NSPageLayout alloc] init]; + } + else + { + [shared_instance _initDefaults]; + } + return shared_instance; } // // Instance methods // +- (id) init +{ + self = [self _initWithoutGModel]; + [self _initDefaults]; + + return self; +} + +- (void) _initDefaults +{ + // use points as the default + _old = 1.0; + _new = 1.0; + [super _initDefaults]; +} // // Running the Panel // - (int)runModal { - return 0; + return [self runModalWithPrintInfo: [NSPrintInfo sharedPrintInfo]]; } - (int)runModalWithPrintInfo:(NSPrintInfo *)pInfo { - return 0; +/* + 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; } // @@ -84,33 +132,94 @@ // - (void)convertOldFactor:(float *)old newFactor:(float *)new -{} +{ + if (old) + *old = _old; + if (new) + *new = _new; +} - (void)pickedButton:(id)sender -{} +{ + 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]; +} - (void)pickedOrientation:(id)sender -{} +{ +} - (void)pickedPaperSize:(id)sender -{} +{ +} - (void)pickedUnits:(id)sender -{} +{ + 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; +} // // Communicating with the NSPrintInfo Object // - (NSPrintInfo *)printInfo { - return nil; + return _printInfo; } - (void)readPrintInfo -{} +{ + +} - (void)writePrintInfo -{} +{ +} // // NSCoding protocol @@ -128,3 +237,52 @@ } @end + +@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 +