Make code a little easier to read (and a tiny bit more efficient).

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@27452 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2008-12-29 12:28:50 +00:00
parent c2dc1e5647
commit 3217c7304a
7 changed files with 269 additions and 252 deletions

View file

@ -1,3 +1,15 @@
2008-12-29 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSBrowser.m:
* Source/NSPopUpButtonCell.m:
* Source/NSBox.m:
* Source/NSComboBoxCell.m:
* Source/NSScrollView.m:
* Headers/Additions/GNUstepGUI/GSTheme.h:
Make code clearer by removing function and replacing it with
method call so you can see what's actually going on and also
be a little more efficient.
2008-12-29 Richard Frith-Macdonald <rfm@gnu.org> 2008-12-29 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSHelpManager.m: Allow the GSHelpViewer user default to * Source/NSHelpManager.m: Allow the GSHelpViewer user default to

View file

@ -556,14 +556,5 @@ withRepeatedImage: (NSImage*)image
flipped: (BOOL)flipped; flipped: (BOOL)flipped;
@end @end
//
// Function which should be somewhere else
//
static inline NSSize
_sizeForBorderType (NSBorderType aType)
{
return [[GSTheme theme] sizeForBorderType: aType];
}
#endif /* OS_API_VERSION */ #endif /* OS_API_VERSION */
#endif /* _GNUstep_H_GSTheme */ #endif /* _GNUstep_H_GSTheme */

View file

@ -332,7 +332,7 @@
-(NSSize) minimumSize -(NSSize) minimumSize
{ {
NSRect rect; NSRect rect;
NSSize borderSize = _sizeForBorderType (_border_type); NSSize borderSize = [[GSTheme theme] sizeForBorderType: _border_type];
if ([_content_view respondsToSelector: @selector(minimumSize)]) if ([_content_view respondsToSelector: @selector(minimumSize)])
{ {
@ -478,9 +478,8 @@
if (_title_position != NSNoTitle) if (_title_position != NSNoTitle)
{ {
// If the title is on the border, clip a hole in the later // If the title is on the border, clip a hole in the later
if ((_border_type != NSNoBorder) && if ((_border_type != NSNoBorder)
((_title_position == NSAtTop) || && ((_title_position == NSAtTop) || (_title_position == NSAtBottom)))
(_title_position == NSAtBottom)))
{ {
[color set]; [color set];
NSRectFill(_title_rect); NSRectFill(_title_rect);
@ -598,13 +597,14 @@
- (NSRect) calcSizesAllowingNegative: (BOOL)aFlag - (NSRect) calcSizesAllowingNegative: (BOOL)aFlag
{ {
GSTheme *theme = [GSTheme theme];
NSRect r = NSZeroRect; NSRect r = NSZeroRect;
switch (_title_position) switch (_title_position)
{ {
case NSNoTitle: case NSNoTitle:
{ {
NSSize borderSize = _sizeForBorderType (_border_type); NSSize borderSize = [theme sizeForBorderType: _border_type];
_border_rect = _bounds; _border_rect = _bounds;
_title_rect = NSZeroRect; _title_rect = NSZeroRect;
@ -621,7 +621,7 @@
case NSAboveTop: case NSAboveTop:
{ {
NSSize titleSize = [_cell cellSize]; NSSize titleSize = [_cell cellSize];
NSSize borderSize = _sizeForBorderType (_border_type); NSSize borderSize = [theme sizeForBorderType: _border_type];
float c; float c;
// Add spacer around title // Add spacer around title
@ -633,8 +633,10 @@
_border_rect.size.height -= titleSize.height + borderSize.height; _border_rect.size.height -= titleSize.height + borderSize.height;
// Add the offsets to the border rect // Add the offsets to the border rect
r.origin.x = _border_rect.origin.x + _offsets.width + borderSize.width; r.origin.x
r.origin.y = _border_rect.origin.y + _offsets.height + borderSize.height; = _border_rect.origin.x + _offsets.width + borderSize.width;
r.origin.y
= _border_rect.origin.y + _offsets.height + borderSize.height;
r.size.width = _border_rect.size.width - (2 * _offsets.width) r.size.width = _border_rect.size.width - (2 * _offsets.width)
- (2 * borderSize.width); - (2 * borderSize.width);
r.size.height = _border_rect.size.height - (2 * _offsets.height) r.size.height = _border_rect.size.height - (2 * _offsets.height)
@ -653,7 +655,7 @@
case NSBelowTop: case NSBelowTop:
{ {
NSSize titleSize = [_cell cellSize]; NSSize titleSize = [_cell cellSize];
NSSize borderSize = _sizeForBorderType (_border_type); NSSize borderSize = [theme sizeForBorderType: _border_type];
float c; float c;
// Add spacer around title // Add spacer around title
@ -664,8 +666,10 @@
_border_rect = _bounds; _border_rect = _bounds;
// Add the offsets to the border rect // Add the offsets to the border rect
r.origin.x = _border_rect.origin.x + _offsets.width + borderSize.width; r.origin.x
r.origin.y = _border_rect.origin.y + _offsets.height + borderSize.height; = _border_rect.origin.x + _offsets.width + borderSize.width;
r.origin.y
= _border_rect.origin.y + _offsets.height + borderSize.height;
r.size.width = _border_rect.size.width - (2 * _offsets.width) r.size.width = _border_rect.size.width - (2 * _offsets.width)
- (2 * borderSize.width); - (2 * borderSize.width);
r.size.height = _border_rect.size.height - (2 * _offsets.height) r.size.height = _border_rect.size.height - (2 * _offsets.height)
@ -678,7 +682,8 @@
c = (_border_rect.size.width - titleSize.width) / 2; c = (_border_rect.size.width - titleSize.width) / 2;
if (c < 0) c = 0; if (c < 0) c = 0;
_title_rect.origin.x = _border_rect.origin.x + c; _title_rect.origin.x = _border_rect.origin.x + c;
_title_rect.origin.y = _border_rect.origin.y + _border_rect.size.height _title_rect.origin.y
= _border_rect.origin.y + _border_rect.size.height
- titleSize.height - borderSize.height; - titleSize.height - borderSize.height;
_title_rect.size = titleSize; _title_rect.size = titleSize;
@ -687,7 +692,7 @@
case NSAtTop: case NSAtTop:
{ {
NSSize titleSize = [_cell cellSize]; NSSize titleSize = [_cell cellSize];
NSSize borderSize = _sizeForBorderType (_border_type); NSSize borderSize = [theme sizeForBorderType: _border_type];
float c; float c;
float topMargin; float topMargin;
float topOffset; float topOffset;
@ -705,19 +710,22 @@
_border_rect.size.height -= topMargin; _border_rect.size.height -= topMargin;
// Add the offsets to the border rect // Add the offsets to the border rect
r.origin.x = _border_rect.origin.x + _offsets.width + borderSize.width; r.origin.x
= _border_rect.origin.x + _offsets.width + borderSize.width;
r.size.width = _border_rect.size.width - (2 * _offsets.width) r.size.width = _border_rect.size.width - (2 * _offsets.width)
- (2 * borderSize.width); - (2 * borderSize.width);
if (topOffset > _offsets.height) if (topOffset > _offsets.height)
{ {
r.origin.y = _border_rect.origin.y + _offsets.height + borderSize.height; r.origin.y
= _border_rect.origin.y + _offsets.height + borderSize.height;
r.size.height = _border_rect.size.height - _offsets.height r.size.height = _border_rect.size.height - _offsets.height
- (2 * borderSize.height) - topOffset; - (2 * borderSize.height) - topOffset;
} }
else else
{ {
r.origin.y = _border_rect.origin.y + _offsets.height + borderSize.height; r.origin.y
= _border_rect.origin.y + _offsets.height + borderSize.height;
r.size.height = _border_rect.size.height - (2 * _offsets.height) r.size.height = _border_rect.size.height - (2 * _offsets.height)
- (2 * borderSize.height); - (2 * borderSize.height);
} }
@ -729,8 +737,8 @@
c = (_border_rect.size.width - titleSize.width) / 2; c = (_border_rect.size.width - titleSize.width) / 2;
if (c < 0) c = 0; if (c < 0) c = 0;
_title_rect.origin.x = _border_rect.origin.x + c; _title_rect.origin.x = _border_rect.origin.x + c;
_title_rect.origin.y = _border_rect.origin.y + _border_rect.size.height _title_rect.origin.y
- topMargin; = _border_rect.origin.y + _border_rect.size.height - topMargin;
_title_rect.size = titleSize; _title_rect.size = titleSize;
break; break;
@ -738,7 +746,7 @@
case NSAtBottom: case NSAtBottom:
{ {
NSSize titleSize = [_cell cellSize]; NSSize titleSize = [_cell cellSize];
NSSize borderSize = _sizeForBorderType (_border_type); NSSize borderSize = [theme sizeForBorderType: _border_type];
float c; float c;
float bottomMargin; float bottomMargin;
float bottomOffset; float bottomOffset;
@ -763,14 +771,16 @@
if (bottomOffset > _offsets.height) if (bottomOffset > _offsets.height)
{ {
r.origin.y = _border_rect.origin.y + bottomOffset + borderSize.height; r.origin.y
= _border_rect.origin.y + bottomOffset + borderSize.height;
r.size.height = _border_rect.size.height - _offsets.height r.size.height = _border_rect.size.height - _offsets.height
- bottomOffset - bottomOffset
- (2 * borderSize.height); - (2 * borderSize.height);
} }
else else
{ {
r.origin.y = _border_rect.origin.y + _offsets.height + borderSize.height; r.origin.y
= _border_rect.origin.y + _offsets.height + borderSize.height;
r.size.height = _border_rect.size.height - (2 * _offsets.height) r.size.height = _border_rect.size.height - (2 * _offsets.height)
- (2 * borderSize.height); - (2 * borderSize.height);
} }
@ -792,7 +802,7 @@
case NSBelowBottom: case NSBelowBottom:
{ {
NSSize titleSize = [_cell cellSize]; NSSize titleSize = [_cell cellSize];
NSSize borderSize = _sizeForBorderType (_border_type); NSSize borderSize = [theme sizeForBorderType: _border_type];
float c; float c;
// Add spacer around title // Add spacer around title
@ -805,8 +815,10 @@
_border_rect.size.height -= titleSize.height + borderSize.height; _border_rect.size.height -= titleSize.height + borderSize.height;
// Add the offsets to the border rect // Add the offsets to the border rect
r.origin.x = _border_rect.origin.x + _offsets.width + borderSize.width; r.origin.x
r.origin.y = _border_rect.origin.y + _offsets.height + borderSize.height; = _border_rect.origin.x + _offsets.width + borderSize.width;
r.origin.y
= _border_rect.origin.y + _offsets.height + borderSize.height;
r.size.width = _border_rect.size.width - (2 * _offsets.width) r.size.width = _border_rect.size.width - (2 * _offsets.width)
- (2 * borderSize.width); - (2 * borderSize.width);
r.size.height = _border_rect.size.height - (2 * _offsets.height) r.size.height = _border_rect.size.height - (2 * _offsets.height)
@ -824,7 +836,7 @@
case NSAboveBottom: case NSAboveBottom:
{ {
NSSize titleSize = [_cell cellSize]; NSSize titleSize = [_cell cellSize];
NSSize borderSize = _sizeForBorderType (_border_type); NSSize borderSize = [theme sizeForBorderType: _border_type];
float c; float c;
// Add spacer around title // Add spacer around title
@ -834,8 +846,10 @@
_border_rect = _bounds; _border_rect = _bounds;
// Add the offsets to the border rect // Add the offsets to the border rect
r.origin.x = _border_rect.origin.x + _offsets.width + borderSize.width; r.origin.x
r.origin.y = _border_rect.origin.y + _offsets.height + borderSize.height; = _border_rect.origin.x + _offsets.width + borderSize.width;
r.origin.y
= _border_rect.origin.y + _offsets.height + borderSize.height;
r.size.width = _border_rect.size.width - (2 * _offsets.width) r.size.width = _border_rect.size.width - (2 * _offsets.width)
- (2 * borderSize.width); - (2 * borderSize.width);
r.size.height = _border_rect.size.height - (2 * _offsets.height) r.size.height = _border_rect.size.height - (2 * _offsets.height)

View file

@ -1236,7 +1236,7 @@ static NSTextFieldCell *titleCell;
sw = scrollerWidth; sw = scrollerWidth;
// Take the border into account // Take the border into account
if (_separatesColumns) if (_separatesColumns)
sw += 2 * (_sizeForBorderType (NSBezelBorder)).width; sw += 2 * ([[GSTheme theme] sizeForBorderType: NSBezelBorder]).width;
// Column width cannot be less than scroller and border // Column width cannot be less than scroller and border
if (columnWidth < sw) if (columnWidth < sw)
@ -1296,7 +1296,7 @@ static NSTextFieldCell *titleCell;
// Take the border into account // Take the border into account
if (_separatesColumns) if (_separatesColumns)
cw += 2 * (_sizeForBorderType(NSBezelBorder)).width; cw += 2 * ([[GSTheme theme] sizeForBorderType: NSBezelBorder]).width;
return cw; return cw;
} }
@ -1308,7 +1308,7 @@ static NSTextFieldCell *titleCell;
cw = columnWidth; cw = columnWidth;
// Take the border into account // Take the border into account
if (_separatesColumns) if (_separatesColumns)
cw -= 2 * (_sizeForBorderType(NSBezelBorder)).width; cw -= 2 * ([[GSTheme theme] sizeForBorderType: NSBezelBorder]).width;
return cw; return cw;
} }
@ -1753,7 +1753,7 @@ static NSTextFieldCell *titleCell;
- (NSRect) frameOfColumn: (int)column - (NSRect) frameOfColumn: (int)column
{ {
NSRect rect = NSZeroRect; NSRect rect = NSZeroRect;
NSSize bezelBorderSize = _sizeForBorderType (NSBezelBorder); NSSize bezelBorderSize = [[GSTheme theme] sizeForBorderType: NSBezelBorder];
int n; int n;
// Number of columns over from the first // Number of columns over from the first
@ -1846,7 +1846,7 @@ static NSTextFieldCell *titleCell;
*/ */
- (void) tile - (void) tile
{ {
NSSize bezelBorderSize = _sizeForBorderType (NSBezelBorder); NSSize bezelBorderSize = [[GSTheme theme] sizeForBorderType: NSBezelBorder];
int i, num, columnCount, delta; int i, num, columnCount, delta;
float frameWidth; float frameWidth;
@ -2231,7 +2231,7 @@ static NSTextFieldCell *titleCell;
_browserDelegate = nil; _browserDelegate = nil;
_passiveDelegate = YES; _passiveDelegate = YES;
_doubleAction = NULL; _doubleAction = NULL;
bs = _sizeForBorderType (NSBezelBorder); bs = [[GSTheme theme] sizeForBorderType: NSBezelBorder];
_minColumnWidth = scrollerWidth + (2 * bs.width); _minColumnWidth = scrollerWidth + (2 * bs.width);
if (_minColumnWidth < 100.0) if (_minColumnWidth < 100.0)
_minColumnWidth = 100.0; _minColumnWidth = 100.0;
@ -2340,7 +2340,7 @@ static NSTextFieldCell *titleCell;
if (_hasHorizontalScroller && _separatesColumns) if (_hasHorizontalScroller && _separatesColumns)
{ {
NSRect scrollerBorderRect = _scrollerRect; NSRect scrollerBorderRect = _scrollerRect;
NSSize bs = _sizeForBorderType (NSBezelBorder); NSSize bs = [[GSTheme theme] sizeForBorderType: NSBezelBorder];
scrollerBorderRect.origin.x = 0; scrollerBorderRect.origin.x = 0;
scrollerBorderRect.origin.y = 0; scrollerBorderRect.origin.y = 0;
@ -2745,7 +2745,7 @@ static NSTextFieldCell *titleCell;
_browserDelegate = nil; _browserDelegate = nil;
_passiveDelegate = YES; _passiveDelegate = YES;
_doubleAction = NULL; _doubleAction = NULL;
bs = _sizeForBorderType (NSBezelBorder); bs = [[GSTheme theme] sizeForBorderType: NSBezelBorder];
_minColumnWidth = scrollerWidth + (2 * bs.width); _minColumnWidth = scrollerWidth + (2 * bs.width);
if (_minColumnWidth < 100.0) if (_minColumnWidth < 100.0)
_minColumnWidth = 100.0; _minColumnWidth = 100.0;

View file

@ -220,7 +220,7 @@ static GSComboWindow *gsWindow = nil;
- (void) layoutWithComboBoxCell: (NSComboBoxCell *)comboBoxCell - (void) layoutWithComboBoxCell: (NSComboBoxCell *)comboBoxCell
{ {
NSMatrix *matrix = [_browser matrixInColumn: 0]; NSMatrix *matrix = [_browser matrixInColumn: 0];
NSSize bsize = _sizeForBorderType(NSLineBorder); NSSize bsize = [[GSTheme theme] sizeForBorderType: NSLineBorder];
NSSize size; NSSize size;
float itemHeight; float itemHeight;
float textCellWidth; float textCellWidth;

View file

@ -1019,7 +1019,7 @@ static NSImage *_pbc_image[5];
s.width += 4; /* Right border to image (border included) */ s.width += 4; /* Right border to image (border included) */
/* (vertical) border: */ /* (vertical) border: */
s.height += 2 * (_sizeForBorderType (NSBezelBorder).height); s.height += 2 * [[GSTheme theme] sizeForBorderType: NSBezelBorder].height;
/* Spacing between border and inside: */ /* Spacing between border and inside: */
s.height += 2 * 1; s.height += 2 * 1;

View file

@ -121,7 +121,7 @@ static float scrollerWidth;
borderType: (NSBorderType)borderType borderType: (NSBorderType)borderType
{ {
NSSize size = frameSize; NSSize size = frameSize;
NSSize border = _sizeForBorderType(borderType); NSSize border = [[GSTheme theme] sizeForBorderType: borderType];
/* /*
* Substract 1 from the width and height of * Substract 1 from the width and height of
@ -149,7 +149,7 @@ static float scrollerWidth;
borderType: (NSBorderType)borderType borderType: (NSBorderType)borderType
{ {
NSSize size = contentSize; NSSize size = contentSize;
NSSize border = _sizeForBorderType(borderType); NSSize border = [[GSTheme theme] sizeForBorderType: borderType];
/* /*
* Add 1 to the width and height for the line that separates the * Add 1 to the width and height for the line that separates the
@ -974,7 +974,7 @@ static float scrollerWidth;
- (void) tile - (void) tile
{ {
NSRect headerRect, contentRect; NSRect headerRect, contentRect;
NSSize border = _sizeForBorderType(_borderType); NSSize border = [[GSTheme theme] sizeForBorderType: _borderType];
NSRectEdge bottomEdge, topEdge; NSRectEdge bottomEdge, topEdge;
float headerViewHeight = 0; float headerViewHeight = 0;
NSRectEdge verticalScrollerEdge = NSMinXEdge; NSRectEdge verticalScrollerEdge = NSMinXEdge;