From 811ae4cf9fc970c83c26e69a3a71b0a6312f9260 Mon Sep 17 00:00:00 2001 From: Alexander Malmberg Date: Tue, 21 Sep 2004 16:55:43 +0000 Subject: [PATCH] * Source/GSFontInfo.m (-defaultLineHeightForFont): Adjust line height calculation. * Source/NSButtonCell.m (-drawInteriorWithFrame:inView:): Always initialize imageRect and titleRect. Adjust the calculations to match the new line height. (-cellSize): Always initialize imageRect and titleRect. * Headers/AppKit/NSCell.h (-_drawImage:inFrame:isFlipped:): Remove. * Source/NSCell.m (-_drawImage:inFrame:isFlipped:): Remove. Move code back ... (-drawInteriorWithFrame:inView:): ... here. * Source/NSToolbarItem.m (+initialize): Remove. (+cellClass): Add. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@20100 72102866-910b-0410-8b05-ffd578937521 --- ChangeLog | 15 ++++++++++++ Headers/AppKit/NSCell.h | 2 -- Source/GSFontInfo.m | 12 ++++++---- Source/NSButtonCell.m | 33 ++++++++++++++++++-------- Source/NSCell.m | 52 +++++++++++++++++------------------------ Source/NSToolbarItem.m | 5 ++-- 6 files changed, 69 insertions(+), 50 deletions(-) diff --git a/ChangeLog b/ChangeLog index 70d9e1c21..017f0a127 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,18 @@ +2004-09-21 18:53 Alexander Malmberg + + * Source/GSFontInfo.m (-defaultLineHeightForFont): Adjust line + height calculation. + * Source/NSButtonCell.m (-drawInteriorWithFrame:inView:): Always + initialize imageRect and titleRect. Adjust the calculations to match + the new line height. + (-cellSize): Always initialize imageRect and titleRect. + * Headers/AppKit/NSCell.h (-_drawImage:inFrame:isFlipped:): Remove. + * Source/NSCell.m (-_drawImage:inFrame:isFlipped:): Remove. Move code + back ... + (-drawInteriorWithFrame:inView:): ... here. + * Source/NSToolbarItem.m (+initialize): Remove. + (+cellClass): Add. + 2004-09-18 15:15 Alexander Malmberg * Source/GSServicesManager.m (_serviceFromAnyLocalizedTitle): Rename diff --git a/Headers/AppKit/NSCell.h b/Headers/AppKit/NSCell.h index 6eee820f9..b3f992225 100644 --- a/Headers/AppKit/NSCell.h +++ b/Headers/AppKit/NSCell.h @@ -454,8 +454,6 @@ typedef enum _NSControlSize { - (void) _drawText: (NSString*)aString inFrame: (NSRect)cellFrame; - (void) _drawAttributedText: (NSAttributedString*)aString inFrame: (NSRect)aRect; -- (void) _drawImage: (NSImage *)anImage inFrame: (NSRect)aRect - isFlipped: (BOOL)flipped; - (BOOL) _sendsActionOn:(int)eventTypeMask; @end diff --git a/Source/GSFontInfo.m b/Source/GSFontInfo.m index be19606f6..33c8f4a6a 100644 --- a/Source/GSFontInfo.m +++ b/Source/GSFontInfo.m @@ -425,15 +425,17 @@ static GSFontEnumerator *sharedEnumerator = nil; - (float) defaultLineHeightForFont { /* - Generally, roman text is centered in the line disregarding the descender, - and the descender height is added above and below. Thus, the line height - should be ascender_height+2*descender_height. (Note that descender is - negative below the baseline.) + In the absence of a more accurate line height from the font itself, we + use ascender_height+descender_height (note that descender is negative + below the baseline). This matches what other systems do, and it matches + the font-provided line height in most cases. (Note that the ascender + height usually includes a bit of space above the top of the actual + glyphs, so we get some inter-line spacing anyway.) This calculation should match the baseline calculation in GSHorizontalTypesetter, or text will look odd. */ - return [self ascender] - 2 * [self descender]; + return [self ascender] - [self descender]; } - (NSSize) advancementForGlyph: (NSGlyph)aGlyph diff --git a/Source/NSButtonCell.m b/Source/NSButtonCell.m index b2aadef83..609d78a56 100644 --- a/Source/NSButtonCell.m +++ b/Source/NSButtonCell.m @@ -353,12 +353,12 @@ /* * Setting the Images */ -- (NSImage*) alternateImage +- (NSImage*) alternateImage { return _altImage; } -- (NSCellImagePosition) imagePosition +- (NSCellImagePosition) imagePosition { return _cell.image_position; } @@ -434,7 +434,7 @@ return _buttoncell_is_transparent; } -- (void) setTransparent: (BOOL)flag +- (void) setTransparent: (BOOL)flag { _buttoncell_is_transparent = flag; } @@ -907,9 +907,11 @@ */ switch (ipos) { + default: case NSNoImage: imageToDisplay = nil; titleRect = cellFrame; + imageRect = NSZeroRect; if (titleSize.width + 6 <= titleRect.size.width) { titleRect.origin.x += 3; @@ -920,6 +922,7 @@ case NSImageOnly: titleToDisplay = nil; imageRect = cellFrame; + titleRect = NSZeroRect; break; case NSImageLeft: @@ -949,7 +952,8 @@ imageRect.origin.x -= 3; } titleRect.origin = cellFrame.origin; - titleRect.size.width = imageRect.origin.x - titleRect.origin.x - GSCellTextImageXDist; + titleRect.size.width = imageRect.origin.x - titleRect.origin.x + - GSCellTextImageXDist; titleRect.size.height = cellFrame.size.height; if (titleSize.width + 3 <= titleRect.size.width) { @@ -964,19 +968,22 @@ * above the text. * The drawing code below will then center the image in imageRect. */ - titleRect.origin.x = cellFrame.origin.x; - titleRect.origin.y = cellFrame.origin.y + GSCellTextImageYDist; + titleRect.origin = cellFrame.origin; titleRect.size.width = cellFrame.size.width; titleRect.size.height = titleSize.height; + if (_cell.is_bordered || _cell.is_bezeled) + { + titleRect.origin.y += 3; + } imageRect.origin.x = cellFrame.origin.x; - imageRect.origin.y = NSMaxY(titleRect); + imageRect.origin.y = NSMaxY(titleRect) + GSCellTextImageYDist; imageRect.size.width = cellFrame.size.width; imageRect.size.height = NSMaxY(cellFrame) - imageRect.origin.y; if (_cell.is_bordered || _cell.is_bezeled) { - imageRect.origin.y -= 1; + imageRect.size.height -= 3; } if (titleSize.width + 6 <= titleRect.size.width) { @@ -995,6 +1002,10 @@ titleRect.origin.y = NSMaxY(cellFrame) - titleSize.height; titleRect.size.width = cellFrame.size.width; titleRect.size.height = titleSize.height; + if (_cell.is_bordered || _cell.is_bezeled) + { + titleRect.origin.y -= 3; + } imageRect.origin.x = cellFrame.origin.x; imageRect.origin.y = cellFrame.origin.y; @@ -1003,7 +1014,8 @@ if (_cell.is_bordered || _cell.is_bezeled) { - imageRect.origin.y += 1; + imageRect.origin.y += 3; + imageRect.size.height -= 3; } if (titleSize.width + 6 <= titleRect.size.width) { @@ -1028,7 +1040,7 @@ { [self drawGradientWithFrame: cellFrame inView: controlView]; } - + // Draw image if (imageToDisplay != nil) { @@ -1105,6 +1117,7 @@ switch (_cell.image_position) { + default: case NSNoImage: s = titleSize; break; diff --git a/Source/NSCell.m b/Source/NSCell.m index 31fb98f82..cfbcc95da 100644 --- a/Source/NSCell.m +++ b/Source/NSCell.m @@ -889,7 +889,7 @@ static NSColor *shadowCol; return textObject; } -- (NSString*) title +- (NSString*) title { return [self stringValue]; } @@ -1670,21 +1670,34 @@ static NSColor *shadowCol; switch (_cell.type) { case NSTextCellType: - [self _drawAttributedText: [self attributedStringValue] - inFrame: cellFrame]; + { + [self _drawAttributedText: [self attributedStringValue] + inFrame: cellFrame]; + } break; case NSImageCellType: if (_cell_image) { - [self _drawImage: _cell_image - inFrame: cellFrame - isFlipped: [controlView isFlipped]]; - } - break; + NSSize size; + NSPoint position; + + size = [_cell_image size]; + position.x = MAX(NSMidX(cellFrame) - (size.width/2.),0.); + position.y = MAX(NSMidY(cellFrame) - (size.height/2.),0.); + /* + * Images are always drawn with their bottom-left corner + * at the origin so we must adjust the position to take + * account of a flipped view. + */ + if ([controlView isFlipped]) + position.y += size.height; + [_cell_image compositeToPoint: position operation: NSCompositeSourceOver]; + } + break; case NSNullCellType: - break; + break; } if (_cell.shows_first_responder) @@ -2199,27 +2212,6 @@ static NSColor *shadowCol; RELEASE (attributes); } -- (void) _drawImage: (NSImage *)anImage inFrame: (NSRect)aRect - isFlipped: (BOOL)flipped -{ - NSSize size; - NSPoint position; - - size = [anImage size]; - position.x = MAX(NSMidX(aRect) - (size.width/2.),0.); - position.y = MAX(NSMidY(aRect) - (size.height/2.),0.); - - /* - * Images are always drawn with their bottom-left corner - * at the origin so we must adjust the position to take - * account of a flipped view. - */ - if (flipped) - position.y += size.height; - - [anImage compositeToPoint: position operation: NSCompositeSourceOver]; -} - - (BOOL) _sendsActionOn:(int)eventTypeMask { return (_action_mask & eventTypeMask); diff --git a/Source/NSToolbarItem.m b/Source/NSToolbarItem.m index a448f2c2f..3f2f1e650 100644 --- a/Source/NSToolbarItem.m +++ b/Source/NSToolbarItem.m @@ -145,10 +145,9 @@ NSString *GSMovableToolbarItemPboardType = @"GSMovableToolbarItemPboardType"; // --- @implementation GSToolbarButton -+ (void) initialize ++ (Class) cellClass { - if (self == [GSToolbarButton class]) - [GSToolbarButton setCellClass: [GSToolbarButtonCell class]]; + return [GSToolbarButtonCell class]; } - (id) initWithToolbarItem: (NSToolbarItem *)toolbarItem