Small layout improvements.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@10954 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Fred Kiefer 2001-09-23 22:08:49 +00:00
parent 596d793519
commit 2f8b4e7389

View file

@ -36,6 +36,7 @@
#include <AppKit/NSBox.h> #include <AppKit/NSBox.h>
#include <AppKit/NSButton.h> #include <AppKit/NSButton.h>
#include <AppKit/NSComboBox.h> #include <AppKit/NSComboBox.h>
#include <AppKit/NSPopUpButton.h>
#include <AppKit/NSMatrix.h> #include <AppKit/NSMatrix.h>
#include <AppKit/NSForm.h> #include <AppKit/NSForm.h>
#include <AppKit/NSFormCell.h> #include <AppKit/NSFormCell.h>
@ -46,7 +47,10 @@ NSPageLayout *shared_instance;
@interface NSPageLayout (Private) @interface NSPageLayout (Private)
- (id) _initWithoutGModel; - (id) _initWithoutGModel;
- (NSArray*) _units;
- (float) factorForIndex: (int)sel;
- (NSArray*) _paperSizes;
- (NSArray*) _layouts;
@end @end
@implementation NSPageLayout @implementation NSPageLayout
@ -94,7 +98,6 @@ NSPageLayout *shared_instance;
{ {
// use points as the default // use points as the default
_old = 1.0; _old = 1.0;
_new = 1.0;
[super _initDefaults]; [super _initDefaults];
} }
@ -108,16 +111,39 @@ NSPageLayout *shared_instance;
- (int)runModalWithPrintInfo:(NSPrintInfo *)pInfo - (int)runModalWithPrintInfo:(NSPrintInfo *)pInfo
{ {
int result;
// store the print Info // store the print Info
_printInfo = pInfo; _printInfo = pInfo;
// read the values of the print info // read the values of the print info
[self readPrintInfo]; [self readPrintInfo];
[NSApp runModalForWindow: self]; result = [NSApp runModalForWindow: self];
[self orderOut: self]; [self orderOut: self];
return _result; return result;
}
- (void)beginSheetWithPrintInfo:(NSPrintInfo *)printInfo
modalForWindow:(NSWindow *)docWindow
delegate:(id)delegate
didEndSelector:(SEL)didEndSelector
contextInfo:(void *)contextInfo
{
// store the print Info
_printInfo = printInfo;
// read the values of the print info
[self readPrintInfo];
[NSApp beginSheet: self
modalForWindow: docWindow
modalDelegate: delegate
didEndSelector: didEndSelector
contextInfo: contextInfo];
[self orderOut: self];
} }
// //
@ -138,10 +164,22 @@ NSPageLayout *shared_instance;
- (void)convertOldFactor:(float *)old - (void)convertOldFactor:(float *)old
newFactor:(float *)new newFactor:(float *)new
{ {
NSPopUpButton *pop;
int sel;
if (old) if (old)
*old = _old; *old = _old;
pop = [[self contentView] viewWithTag: NSPLUnitsButton];
if (pop != nil)
{
sel = [pop indexOfSelectedItem];
if (new) if (new)
*new = _new; *new = [self factorForIndex: sel];
}
else if (new)
*new = _old;
} }
- (void)pickedButton:(id)sender - (void)pickedButton:(id)sender
@ -168,14 +206,12 @@ NSPageLayout *shared_instance;
// store the values in the print info // store the values in the print info
[self writePrintInfo]; [self writePrintInfo];
_result = NSOKButton; [NSApp stopModalWithCode: NSOKButton];
} }
if ([sender tag] == NSPLCancelButton) if ([sender tag] == NSPLCancelButton)
{ {
_result = NSOKButton; [NSApp stopModalWithCode: NSCancelButton];
} }
[NSApp stopModal];
} }
- (void)pickedOrientation:(id)sender - (void)pickedOrientation:(id)sender
@ -188,6 +224,11 @@ NSPageLayout *shared_instance;
NSLog(@"pickedPaperSize %@", sender); NSLog(@"pickedPaperSize %@", sender);
} }
- (void)pickedLayout:(id)sender
{
NSLog(@"pickedLayout %@", sender);
}
- (void)pickedUnits:(id)sender - (void)pickedUnits:(id)sender
{ {
NSTextField *field; NSTextField *field;
@ -211,7 +252,7 @@ NSPageLayout *shared_instance;
} }
// Set the selected units. // Set the selected units.
_old = _new; _old = new;
} }
// //
@ -224,7 +265,29 @@ NSPageLayout *shared_instance;
- (void)readPrintInfo - (void)readPrintInfo
{ {
NSTextField *field;
NSSize size = [_printInfo paperSize];
float new, old;
// Both values should be the same
[self convertOldFactor: &old newFactor: &new];
field = [[self contentView] viewWithTag: NSPLWidthForm];
if (field != nil)
{
// Update field based on the conversion factors.
[field setFloatValue:(size.width/old)];
}
field = [[self contentView] viewWithTag: NSPLHeightForm];
if (field != nil)
{
// Update field based on the conversion factors.
[field setFloatValue:(size.height/old)];
}
//[_printInfo paperName];
//[_printInfo orientation];
} }
- (void)writePrintInfo - (void)writePrintInfo
@ -264,7 +327,6 @@ NSPageLayout *shared_instance;
{ {
NSImageView *imageView; NSImageView *imageView;
NSImage *paper; NSImage *paper;
NSComboBox *combo;
NSBox *box; NSBox *box;
NSForm *f; NSForm *f;
NSFormCell *fc; NSFormCell *fc;
@ -272,33 +334,58 @@ NSPageLayout *shared_instance;
NSButtonCell *oc; NSButtonCell *oc;
NSButton *okButton; NSButton *okButton;
NSButton *cancelButton; NSButton *cancelButton;
NSRect pi = {{60,170}, {100,100}}; NSRect uv = {{0,50}, {300,250}};
NSRect wf = {{5,120}, {75,30}}; NSRect lv = {{0,0}, {300,50}};
NSRect hf = {{90,120}, {75,30}}; NSRect ulv = {{0,0}, {190,250}};
NSRect pb = {{190,240}, {95,30}}; NSRect urv = {{190,0}, {110,250}};
NSRect pi = {{60,120}, {100,100}};
NSRect wf = {{5,70}, {75,30}};
NSRect hf = {{90,70}, {75,30}};
NSRect pb = {{0,190}, {95,30}};
NSRect pc = {{5,5}, {85,20}}; NSRect pc = {{5,5}, {85,20}};
NSRect lb = {{190,180}, {95,30}}; NSRect lb = {{0,130}, {95,30}};
NSRect lc = {{5,5}, {85,20}}; NSRect lc = {{5,5}, {85,20}};
NSRect ub = {{190,120}, {95,30}}; NSRect ub = {{0,70}, {95,30}};
NSRect uc = {{5,5}, {85,20}}; NSRect uc = {{5,5}, {85,20}};
NSRect sb = {{190,60}, {95,35}}; NSRect sb = {{0,10}, {95,35}};
NSRect mo = {{60,60}, {90,40}}; NSRect tf = {{5,5}, {75,20}};
NSRect mo = {{60,10}, {90,40}};
NSRect rb = {{126,8}, {72,24}}; NSRect rb = {{126,8}, {72,24}};
NSRect db = {{217,8}, {72,24}}; NSRect db = {{217,8}, {72,24}};
NSView *content; NSView *content;
NSView *upper;
NSView *lower;
NSView *left;
NSView *right;
NSPopUpButton *pop;
NSTextField *text;
[self setTitle: @"Page Layout"]; [self setTitle: @"Page Layout"];
content = [self contentView]; content = [self contentView];
// Spilt up in upper and lower
upper = [[NSView alloc] initWithFrame: uv];
[content addSubview: upper];
RELEASE(upper);
lower = [[NSView alloc] initWithFrame: lv];
[content addSubview: lower];
RELEASE(lower);
// Solit upper in left and right
left = [[NSView alloc] initWithFrame: ulv];
[upper addSubview: left];
RELEASE(left);
right = [[NSView alloc] initWithFrame: urv];
[upper addSubview: right];
RELEASE(right);
// image of the paper size // FIXME: image of the paper size
paper = nil; paper = nil;
imageView = [[NSImageView alloc] initWithFrame: pi]; imageView = [[NSImageView alloc] initWithFrame: pi];
[imageView setImage: paper]; [imageView setImage: paper];
[imageView setImageScaling: NSScaleNone]; [imageView setImageScaling: NSScaleNone];
[imageView setEditable: NO]; [imageView setEditable: NO];
[imageView setTag: NSPLImageButton]; [imageView setTag: NSPLImageButton];
[content addSubview: imageView]; [left addSubview: imageView];
RELEASE(imageView); RELEASE(imageView);
// Width // Width
@ -314,7 +401,7 @@ NSPageLayout *shared_instance;
[f sizeToFit]; [f sizeToFit];
[f setEntryWidth: 80.0]; [f setEntryWidth: 80.0];
[f setTag: NSPLWidthForm]; [f setTag: NSPLWidthForm];
[content addSubview: f]; [left addSubview: f];
RELEASE(f); RELEASE(f);
// Height // Height
@ -330,7 +417,7 @@ NSPageLayout *shared_instance;
[f sizeToFit]; [f sizeToFit];
[f setEntryWidth: 80.0]; [f setEntryWidth: 80.0];
[f setTag: NSPLHeightForm]; [f setTag: NSPLHeightForm];
[content addSubview: f]; [left addSubview: f];
RELEASE(f); RELEASE(f);
// Paper Size // Paper Size
@ -340,29 +427,17 @@ NSPageLayout *shared_instance;
[box setBorderType: NSGrooveBorder]; [box setBorderType: NSGrooveBorder];
[box setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; [box setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
combo = [[NSComboBox alloc] initWithFrame: pc]; pop = [[NSPopUpButton alloc] initWithFrame: pc pullsDown: NO];
[combo setEditable: NO]; [pop setAction: @selector(pickedPaperSize:)];
[combo setSelectable: NO]; [pop setTarget: self];
[combo setBordered: NO]; [pop addItemsWithTitles: [self _paperSizes]];
[combo setBezeled: YES]; [pop selectItemAtIndex: 0];
[combo setDrawsBackground: NO]; [pop setTag: NSPLPaperNameButton];
[combo setAlignment: NSLeftTextAlignment]; [box addSubview: pop];
[combo addItemWithObjectValue: @"A2"]; RELEASE(pop);
[combo addItemWithObjectValue: @"A3"];
[combo addItemWithObjectValue: @"A4"];
[combo addItemWithObjectValue: @"A5"];
[combo addItemWithObjectValue: @"A6"];
[combo setNumberOfVisibleItems: 5];
[combo selectItemAtIndex: 0];
[combo setObjectValue:[combo objectValueOfSelectedItem]];
[combo setAction: @selector(pickedPaperSize:)];
[combo setTarget: self];
[combo setTag: NSPLPaperNameButton];
[box addSubview: combo];
RELEASE(combo);
[box sizeToFit]; [box sizeToFit];
[content addSubview: box]; [right addSubview: box];
RELEASE(box); RELEASE(box);
// Layout // Layout
@ -372,22 +447,17 @@ NSPageLayout *shared_instance;
[box setBorderType: NSGrooveBorder]; [box setBorderType: NSGrooveBorder];
[box setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; [box setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
combo = [[NSComboBox alloc] initWithFrame: lc]; pop = [[NSPopUpButton alloc] initWithFrame: lc pullsDown: NO];
[combo setEditable: NO]; [pop setAction: @selector(pickedLayout:)];
[combo setSelectable: NO]; [pop setTarget: self];
[combo setBordered: NO]; [pop addItemsWithTitles: [self _layouts]];
[combo setBezeled: YES]; [pop selectItemAtIndex: 0];
[combo setDrawsBackground: NO]; //[pop setTag: NSPLPaperNameButton];
[combo setAlignment: NSLeftTextAlignment]; [box addSubview: pop];
[combo addItemWithObjectValue: @"1 Up"]; RELEASE(pop);
[combo setNumberOfVisibleItems: 5];
[combo selectItemAtIndex: 0];
[combo setObjectValue:[combo objectValueOfSelectedItem]];
[box addSubview: combo];
RELEASE(combo);
[box sizeToFit]; [box sizeToFit];
[content addSubview: box]; [right addSubview: box];
RELEASE(box); RELEASE(box);
// Units // Units
@ -397,39 +467,34 @@ NSPageLayout *shared_instance;
[box setBorderType: NSGrooveBorder]; [box setBorderType: NSGrooveBorder];
[box setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; [box setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
combo = [[NSComboBox alloc] initWithFrame: uc]; pop = [[NSPopUpButton alloc] initWithFrame: uc pullsDown: NO];
[combo setEditable: NO]; [pop setAction: @selector(pickedUnits:)];
[combo setSelectable: NO]; [pop setTarget: self];
[combo setBordered: NO]; [pop addItemsWithTitles: [self _units]];
[combo setBezeled: YES]; [pop selectItemAtIndex: 0];
[combo setDrawsBackground: NO]; [pop setTag: NSPLUnitsButton];
[combo setAlignment: NSLeftTextAlignment]; [box addSubview: pop];
[combo addItemWithObjectValue: @"Points"]; RELEASE(pop);
[combo addItemWithObjectValue: @"Millimeter"];
[combo addItemWithObjectValue: @"Centimeter"];
[combo addItemWithObjectValue: @"Inches"];
[combo setNumberOfVisibleItems: 5];
[combo selectItemAtIndex: 2];
[combo setObjectValue:[combo objectValueOfSelectedItem]];
[combo setAction: @selector(pickedUnits:)];
[combo setTarget: self];
[combo setTag: NSPLUnitsButton];
[box addSubview: combo];
RELEASE(combo);
[box sizeToFit]; [box sizeToFit];
[content addSubview: box]; [right addSubview: box];
RELEASE(box); RELEASE(box);
// Sacle // Scale
box = [[NSBox alloc] initWithFrame: sb]; box = [[NSBox alloc] initWithFrame: sb];
[box setTitle: @"Scale"]; [box setTitle: @"Scale"];
[box setTitlePosition: NSAtTop]; [box setTitlePosition: NSAtTop];
[box setBorderType: NSGrooveBorder]; [box setBorderType: NSGrooveBorder];
[box setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)]; [box setAutoresizingMask: (NSViewWidthSizable | NSViewHeightSizable)];
text = [[NSTextField alloc] initWithFrame: tf];
[box addSubview: text];
RELEASE(text);
[content addSubview: box]; [box sizeToFit];
[right addSubview: box];
RELEASE(box); RELEASE(box);
// orientation // orientation
@ -457,7 +522,7 @@ NSPageLayout *shared_instance;
[o setTag: NSPLOrientationMatrix]; [o setTag: NSPLOrientationMatrix];
[o setAction: @selector(pickedOrientation:)]; [o setAction: @selector(pickedOrientation:)];
[o setTarget: self]; [o setTarget: self];
[content addSubview: o]; [left addSubview: o];
RELEASE(o); RELEASE(o);
// cancle button // cancle button
@ -466,7 +531,7 @@ NSPageLayout *shared_instance;
[cancelButton setAction: @selector(pickedButton:)]; [cancelButton setAction: @selector(pickedButton:)];
[cancelButton setTarget: self]; [cancelButton setTarget: self];
[cancelButton setTag: NSPLCancelButton]; [cancelButton setTag: NSPLCancelButton];
[content addSubview: cancelButton]; [lower addSubview: cancelButton];
RELEASE(cancelButton); RELEASE(cancelButton);
// OK button // OK button
@ -475,7 +540,7 @@ NSPageLayout *shared_instance;
[okButton setAction: @selector(pickedButton:)]; [okButton setAction: @selector(pickedButton:)];
[okButton setTarget: self]; [okButton setTarget: self];
[okButton setTag: NSPLOKButton]; [okButton setTag: NSPLOKButton];
[content addSubview: okButton]; [lower addSubview: okButton];
// make it the default button // make it the default button
[self setDefaultButtonCell: [okButton cell]]; [self setDefaultButtonCell: [okButton cell]];
RELEASE(okButton); RELEASE(okButton);
@ -484,5 +549,33 @@ NSPageLayout *shared_instance;
return self; return self;
} }
@end - (NSArray*) _units
{
return [NSArray arrayWithObjects: @"Points", @"Millimeter",
@"Centimeter", @"Inches", nil];
}
- (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;
}
}
- (NSArray*) _paperSizes
{
return [NSArray arrayWithObjects: @"A2", @"A3", @"A4",
@"A5", @"A6", nil];
}
- (NSArray*) _layouts
{
return [NSArray arrayWithObjects: @"1 Up", nil];
}
@end