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>
* Source/NSHelpManager.m: Allow the GSHelpViewer user default to

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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