* 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
This commit is contained in:
Alexander Malmberg 2004-09-21 16:55:43 +00:00
parent e2e0084fdb
commit 811ae4cf9f
6 changed files with 69 additions and 50 deletions

View file

@ -1,3 +1,18 @@
2004-09-21 18:53 Alexander Malmberg <alexander@malmberg.org>
* 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 <alexander@malmberg.org>
* Source/GSServicesManager.m (_serviceFromAnyLocalizedTitle): Rename

View file

@ -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

View file

@ -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

View file

@ -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)
{
@ -1105,6 +1117,7 @@
switch (_cell.image_position)
{
default:
case NSNoImage:
s = titleSize;
break;

View file

@ -1670,16 +1670,29 @@ static NSColor *shadowCol;
switch (_cell.type)
{
case NSTextCellType:
{
[self _drawAttributedText: [self attributedStringValue]
inFrame: cellFrame];
}
break;
case NSImageCellType:
if (_cell_image)
{
[self _drawImage: _cell_image
inFrame: cellFrame
isFlipped: [controlView isFlipped]];
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;
@ -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);

View file

@ -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