mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-05-31 18:40:47 +00:00
Updated -cellSize to process multiline string value. This should
improve greately the behaviour of NSTextField and consequently of the NSPanel building functions. Updated -[NSCell _drawText:inFrame:] and -[NSButtonCell drawInteriorWithFrame:inView:] to handle properly multiline strings. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6257 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
99f2fb6496
commit
23a6b9f034
2 changed files with 54 additions and 24 deletions
|
@ -48,6 +48,7 @@
|
||||||
#include <AppKit/NSGraphics.h>
|
#include <AppKit/NSGraphics.h>
|
||||||
#include <AppKit/PSOperators.h>
|
#include <AppKit/PSOperators.h>
|
||||||
|
|
||||||
|
#include "GSUtil.h"
|
||||||
|
|
||||||
|
|
||||||
@implementation NSButtonCell
|
@implementation NSButtonCell
|
||||||
|
@ -489,11 +490,10 @@
|
||||||
imageSize = [imageToDisplay size];
|
imageSize = [imageToDisplay size];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (titleToDisplay && (ipos == NSImageAbove || ipos == NSImageBelow))
|
if (titleToDisplay && (ipos == NSImageAbove || ipos == NSImageBelow)) {
|
||||||
{
|
titleSize =GSUtil_sizeOfMultilineStringWithFont(titleToDisplay,
|
||||||
titleSize = NSMakeSize([_cell_font widthOfString: titleToDisplay],
|
_cell_font);
|
||||||
[_cell_font boundingRectForFont].size.height);
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if (flippedView == YES)
|
if (flippedView == YES)
|
||||||
{
|
{
|
||||||
|
@ -686,11 +686,12 @@
|
||||||
else
|
else
|
||||||
imageSize = NSZeroSize;
|
imageSize = NSZeroSize;
|
||||||
|
|
||||||
if (titleToDisplay)
|
if(titleToDisplay!=nil){
|
||||||
titleSize = NSMakeSize ([_cell_font widthOfString: titleToDisplay],
|
titleSize=GSUtil_sizeOfMultilineStringWithFont(titleToDisplay,
|
||||||
[_cell_font boundingRectForFont].size.height);
|
_cell_font);
|
||||||
else
|
}else{
|
||||||
titleSize = NSZeroSize;
|
titleSize=NSZeroSize;
|
||||||
|
}
|
||||||
|
|
||||||
switch (_cell.image_position)
|
switch (_cell.image_position)
|
||||||
{
|
{
|
||||||
|
|
|
@ -49,6 +49,7 @@
|
||||||
#include <AppKit/NSGraphics.h>
|
#include <AppKit/NSGraphics.h>
|
||||||
#include <AppKit/NSColor.h>
|
#include <AppKit/NSColor.h>
|
||||||
#include <AppKit/PSOperators.h>
|
#include <AppKit/PSOperators.h>
|
||||||
|
#include "GSUtil.h"
|
||||||
|
|
||||||
static Class colorClass;
|
static Class colorClass;
|
||||||
static Class cellClass;
|
static Class cellClass;
|
||||||
|
@ -59,10 +60,12 @@ static NSColor *txtCol;
|
||||||
static NSColor *dtxtCol;
|
static NSColor *dtxtCol;
|
||||||
static NSColor *shadowCol;
|
static NSColor *shadowCol;
|
||||||
|
|
||||||
|
|
||||||
@interface NSCell (PrivateColor)
|
@interface NSCell (PrivateColor)
|
||||||
+ (void) _systemColorsChanged: (NSNotification*)n;
|
+ (void) _systemColorsChanged: (NSNotification*)n;
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation NSCell (PrivateColor)
|
@implementation NSCell (PrivateColor)
|
||||||
+ (void) _systemColorsChanged: (NSNotification*)n
|
+ (void) _systemColorsChanged: (NSNotification*)n
|
||||||
{
|
{
|
||||||
|
@ -72,6 +75,7 @@ static NSColor *shadowCol;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
@implementation NSCell
|
@implementation NSCell
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -1060,6 +1064,8 @@ static NSColor *shadowCol;
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
- (NSSize) cellSize
|
- (NSSize) cellSize
|
||||||
{
|
{
|
||||||
NSSize borderSize, s;
|
NSSize borderSize, s;
|
||||||
|
@ -1083,9 +1089,8 @@ static NSColor *shadowCol;
|
||||||
switch (_cell.type)
|
switch (_cell.type)
|
||||||
{
|
{
|
||||||
case NSTextCellType:
|
case NSTextCellType:
|
||||||
s = NSMakeSize([_cell_font widthOfString: _contents],
|
s=GSUtil_sizeOfMultilineStringWithFont(_contents,_cell_font);
|
||||||
[_cell_font boundingRectForFont].size.height);
|
break;
|
||||||
break;
|
|
||||||
case NSImageCellType:
|
case NSImageCellType:
|
||||||
if (_cell_image == nil)
|
if (_cell_image == nil)
|
||||||
{
|
{
|
||||||
|
@ -1182,8 +1187,8 @@ static NSColor *shadowCol;
|
||||||
{
|
{
|
||||||
NSColor *textColor;
|
NSColor *textColor;
|
||||||
float titleWidth;
|
float titleWidth;
|
||||||
float titleHeight;
|
|
||||||
NSDictionary *dict;
|
NSDictionary *dict;
|
||||||
|
NSSize titleSize;
|
||||||
|
|
||||||
if (!title)
|
if (!title)
|
||||||
return;
|
return;
|
||||||
|
@ -1193,17 +1198,41 @@ static NSColor *shadowCol;
|
||||||
if (!_cell_font)
|
if (!_cell_font)
|
||||||
[NSException raise: NSInvalidArgumentException
|
[NSException raise: NSInvalidArgumentException
|
||||||
format: @"Request to draw a text cell but no font specified!"];
|
format: @"Request to draw a text cell but no font specified!"];
|
||||||
titleWidth = [_cell_font widthOfString: title];
|
|
||||||
// Important: text should always be vertically centered without
|
|
||||||
// considering descender [as if descender did not exist].
|
|
||||||
// At present (13/1/00) the following code produces the correct output,
|
|
||||||
// even if it seems to be trying to make it wrong.
|
|
||||||
// Please make sure the output remains always correct.
|
|
||||||
titleHeight = [_cell_font pointSize] - [_cell_font descender];
|
|
||||||
|
|
||||||
// Determine the y position of the text
|
titleSize=GSUtil_sizeOfMultilineStringWithFont(title,_cell_font);
|
||||||
cellFrame.origin.y = NSMidY (cellFrame) - titleHeight / 2;
|
titleWidth=titleSize.width;
|
||||||
cellFrame.size.height = titleHeight;
|
/*
|
||||||
|
PJB:
|
||||||
|
The following comment was found here, in the previous version that
|
||||||
|
supposed that title was one-line, in spite of the fact that title
|
||||||
|
knows how to draw itself (drawInRect:withAttributes:) when
|
||||||
|
contening several lines.
|
||||||
|
|
||||||
|
// Important: text should always be vertically centered without
|
||||||
|
// considering descender [as if descender did not exist].
|
||||||
|
// At present (13/1/00) the following code produces the correct output,
|
||||||
|
// even if it seems to be trying to make it wrong.
|
||||||
|
// Please make sure the output remains always correct.
|
||||||
|
|
||||||
|
When the cellFrame has been computed from sizeToFit, applying
|
||||||
|
GSUtil_sizeOfMultilineStringWithFont to the _content of the cell,
|
||||||
|
and this is exactly the parameters we have here, respecting this
|
||||||
|
comment would imply moving down for half a descender the block of
|
||||||
|
text, because GSUtil_sizeOfMultilineStringWithFont does not add a
|
||||||
|
"centering" half descender above the text. Therefore we won't,
|
||||||
|
and we will respect this comment only in the other cases were
|
||||||
|
we'll merely substract the font descender to the titleSize.heigh.
|
||||||
|
*/
|
||||||
|
if((cellFrame.size.width!=titleSize.width)
|
||||||
|
||(cellFrame.size.height!=titleSize.height)){
|
||||||
|
float titleHeight=titleSize.height-[_cell_font descender];
|
||||||
|
// Determine the y position of the text
|
||||||
|
cellFrame.origin.y = NSMidY (cellFrame) - titleHeight / 2;
|
||||||
|
cellFrame.size.height = titleHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Determine the x position of text
|
// Determine the x position of text
|
||||||
switch (_cell.text_align)
|
switch (_cell.text_align)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue