Update the size in the preview and size browser when the size text field changes. Set sane defaults _before_ setting the current font.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@14510 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Alexander Malmberg 2002-09-22 14:33:41 +00:00
parent 61b91e6b57
commit 1cf5f94cab
2 changed files with 49 additions and 13 deletions

View file

@ -1,3 +1,14 @@
2002-09-22 16:26 Alexander Malmberg <alexander@malmberg.org>
* Source/NSFontPanel.m (-init): Set sane defaults _before_ trying
to set values for the current font.
Move code to select a certain size in the size browser to
-_trySelectSize:. Update the size in the preview and the browser
when the size text field changes.
Mark private variables and constants as static.
2002-09-22 01:23 Alexander Malmberg <alexander@malmberg.org> 2002-09-22 01:23 Alexander Malmberg <alexander@malmberg.org>
* Headers/gnustep/gui/NSView.h, Source/NSPanel.m, Source/NSText.m, * Headers/gnustep/gui/NSView.h, Source/NSPanel.m, Source/NSText.m,

View file

@ -66,10 +66,10 @@ static inline void _setFloatValue (NSTextField *field, float size)
} }
NSText *sizeFieldText = nil; static NSText *sizeFieldText = nil;
float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, static float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
14.0, 16.0, 18.0, 24.0, 36.0, 48.0, 64.0}; 14.0, 16.0, 18.0, 24.0, 36.0, 48.0, 64.0};
/* Implemented in NSBrowser */ /* Implemented in NSBrowser */
@interface GSBrowserTitleCell : NSTextFieldCell @interface GSBrowserTitleCell : NSTextFieldCell
@ -80,6 +80,8 @@ float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
@interface NSFontPanel (Private) @interface NSFontPanel (Private)
- (NSFont*) _fontForSelection: (NSFont*) fontObject; - (NSFont*) _fontForSelection: (NSFont*) fontObject;
-(void) _trySelectSize: (float)size;
// Some action methods // Some action methods
- (void) cancel: (id) sender; - (void) cancel: (id) sender;
- (void) _togglePreview: (id) sender; - (void) _togglePreview: (id) sender;
@ -130,10 +132,10 @@ float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
// if (![NSBundle loadNibNamed: @"FontPanel" owner: self]); // if (![NSBundle loadNibNamed: @"FontPanel" owner: self]);
[self _initWithoutGModel]; [self _initWithoutGModel];
[self reloadDefaultFontFamilies];
ASSIGN(_faceList, [NSArray array]); ASSIGN(_faceList, [NSArray array]);
_face = -1; _face = -1;
_family = -1; _family = -1;
[self reloadDefaultFontFamilies];
return self; return self;
} }
@ -211,7 +213,6 @@ float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
NSString *fontName = [fontObject fontName]; NSString *fontName = [fontObject fontName];
float size = [fontObject pointSize]; float size = [fontObject pointSize];
NSTextField *sizeField = [[self contentView] viewWithTag: NSFPSizeField]; NSTextField *sizeField = [[self contentView] viewWithTag: NSFPSizeField];
NSBrowser *sizeBrowser = [[self contentView] viewWithTag: NSFPSizeBrowser];
NSBrowser *familyBrowser = [[self contentView] viewWithTag: NSFPFamilyBrowser]; NSBrowser *familyBrowser = [[self contentView] viewWithTag: NSFPFamilyBrowser];
NSBrowser *faceBrowser = [[self contentView] viewWithTag: NSFPFaceBrowser]; NSBrowser *faceBrowser = [[self contentView] viewWithTag: NSFPFaceBrowser];
NSString *face = @""; NSString *face = @"";
@ -252,13 +253,7 @@ float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
// show point size and select the row if there is one // show point size and select the row if there is one
_setFloatValue (sizeField, size); _setFloatValue (sizeField, size);
for (i = 0; i < sizeof(sizes)/sizeof(float); i++) [self _trySelectSize: size];
{
if (size == sizes[i])
{
[sizeBrowser selectRow: i inColumn: 0];
}
}
// Use in preview // Use in preview
[previewArea setFont: fontObject]; [previewArea setFont: fontObject];
@ -518,6 +513,7 @@ float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
[sizeField setAlignment: NSCenterTextAlignment]; [sizeField setAlignment: NSCenterTextAlignment];
[sizeField setBackgroundColor: [NSColor windowFrameTextColor]]; [sizeField setBackgroundColor: [NSColor windowFrameTextColor]];
[sizeField setAutoresizingMask: NSViewMinXMargin | NSViewMinYMargin]; [sizeField setAutoresizingMask: NSViewMinXMargin | NSViewMinYMargin];
[sizeField setDelegate: self];
[sizeField setTag: NSFPSizeField]; [sizeField setTag: NSFPSizeField];
[bottomSplit addSubview: sizeField]; [bottomSplit addSubview: sizeField];
RELEASE(sizeField); RELEASE(sizeField);
@ -732,7 +728,36 @@ float sizes[] = {4.0, 6.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0,
// FIXME: We should check if the font is correct // FIXME: We should check if the font is correct
return [NSFont fontWithName: fontName size: size]; return [NSFont fontWithName: fontName size: size];
} }
-(void) _trySelectSize: (float)size
{
int i;
NSBrowser *sizeBrowser = [[self contentView] viewWithTag: NSFPSizeBrowser];
for (i = 0; i < sizeof(sizes) / sizeof(float); i++)
{
if (size == sizes[i])
{
[sizeBrowser selectRow: i inColumn: 0];
break;
}
}
if (i == sizeof(sizes) / sizeof(float))
{
/* TODO: No matching size found in the list. We should deselect
everything. */
}
}
- (void) controlTextDidChange: (NSNotification *)n
{
NSTextField *sizeField = [[self contentView] viewWithTag: NSFPSizeField];
float size = [sizeField floatValue];
[self _trySelectSize: size];
[self _doPreview];
}
@end @end