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)])
{
@ -460,27 +460,26 @@
// Draw border
switch (_border_type)
{
case NSNoBorder:
break;
case NSLineBorder:
[[NSColor controlDarkShadowColor] set];
NSFrameRect(_border_rect);
break;
case NSBezelBorder:
[[GSTheme theme] drawDarkBezel: _border_rect withClip: rect];
break;
case NSGrooveBorder:
[[GSTheme theme] drawGroove: _border_rect withClip: rect];
break;
case NSNoBorder:
break;
case NSLineBorder:
[[NSColor controlDarkShadowColor] set];
NSFrameRect(_border_rect);
break;
case NSBezelBorder:
[[GSTheme theme] drawDarkBezel: _border_rect withClip: rect];
break;
case NSGrooveBorder:
[[GSTheme theme] drawGroove: _border_rect withClip: rect];
break;
}
// Draw title
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,262 +597,277 @@
- (NSRect) calcSizesAllowingNegative: (BOOL)aFlag
{
GSTheme *theme = [GSTheme theme];
NSRect r = NSZeroRect;
switch (_title_position)
{
case NSNoTitle:
{
NSSize borderSize = _sizeForBorderType (_border_type);
_border_rect = _bounds;
_title_rect = NSZeroRect;
case NSNoTitle:
{
NSSize borderSize = [theme sizeForBorderType: _border_type];
_border_rect = _bounds;
_title_rect = NSZeroRect;
// Add the offsets to the border rect
r.origin.x = _offsets.width + borderSize.width;
r.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)
- (2 * borderSize.height);
// Add the offsets to the border rect
r.origin.x = _offsets.width + borderSize.width;
r.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)
- (2 * borderSize.height);
break;
}
case NSAboveTop:
{
NSSize titleSize = [_cell cellSize];
NSSize borderSize = _sizeForBorderType (_border_type);
float c;
break;
}
case NSAboveTop:
{
NSSize titleSize = [_cell cellSize];
NSSize borderSize = [theme sizeForBorderType: _border_type];
float c;
// Add spacer around title
titleSize.width += 6;
titleSize.height += 2;
// Add spacer around title
titleSize.width += 6;
titleSize.height += 2;
// Adjust border rect by title cell
_border_rect = _bounds;
_border_rect.size.height -= titleSize.height + borderSize.height;
// Adjust border rect by title cell
_border_rect = _bounds;
_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.size.width = _border_rect.size.width - (2 * _offsets.width)
- (2 * borderSize.width);
r.size.height = _border_rect.size.height - (2 * _offsets.height)
- (2 * 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.size.width = _border_rect.size.width - (2 * _offsets.width)
- (2 * borderSize.width);
r.size.height = _border_rect.size.height - (2 * _offsets.height)
- (2 * borderSize.height);
// center the title cell
c = (_bounds.size.width - titleSize.width) / 2;
if (c < 0) c = 0;
_title_rect.origin.x = _bounds.origin.x + c;
_title_rect.origin.y = _bounds.origin.y + _border_rect.size.height
+ borderSize.height;
_title_rect.size = titleSize;
// center the title cell
c = (_bounds.size.width - titleSize.width) / 2;
if (c < 0) c = 0;
_title_rect.origin.x = _bounds.origin.x + c;
_title_rect.origin.y = _bounds.origin.y + _border_rect.size.height
+ borderSize.height;
_title_rect.size = titleSize;
break;
}
case NSBelowTop:
{
NSSize titleSize = [_cell cellSize];
NSSize borderSize = _sizeForBorderType (_border_type);
float c;
break;
}
case NSBelowTop:
{
NSSize titleSize = [_cell cellSize];
NSSize borderSize = [theme sizeForBorderType: _border_type];
float c;
// Add spacer around title
titleSize.width += 6;
titleSize.height += 2;
// Add spacer around title
titleSize.width += 6;
titleSize.height += 2;
// Adjust border rect by title cell
_border_rect = _bounds;
// Adjust border rect by title cell
_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.size.width = _border_rect.size.width - (2 * _offsets.width)
- (2 * borderSize.width);
r.size.height = _border_rect.size.height - (2 * _offsets.height)
- (2 * 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.size.width = _border_rect.size.width - (2 * _offsets.width)
- (2 * borderSize.width);
r.size.height = _border_rect.size.height - (2 * _offsets.height)
- (2 * borderSize.height);
// Adjust by the title size
r.size.height -= titleSize.height + borderSize.height;
// Adjust by the title size
r.size.height -= titleSize.height + borderSize.height;
// center the title cell
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
- titleSize.height - borderSize.height;
_title_rect.size = titleSize;
// center the title cell
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
- titleSize.height - borderSize.height;
_title_rect.size = titleSize;
break;
}
case NSAtTop:
{
NSSize titleSize = [_cell cellSize];
NSSize borderSize = _sizeForBorderType (_border_type);
float c;
float topMargin;
float topOffset;
break;
}
case NSAtTop:
{
NSSize titleSize = [_cell cellSize];
NSSize borderSize = [theme sizeForBorderType: _border_type];
float c;
float topMargin;
float topOffset;
// Add spacer around title
titleSize.width += 6;
titleSize.height += 2;
// Add spacer around title
titleSize.width += 6;
titleSize.height += 2;
_border_rect = _bounds;
_border_rect = _bounds;
topMargin = ceil(titleSize.height / 2);
topOffset = titleSize.height - topMargin;
// Adjust by the title size
_border_rect.size.height -= topMargin;
// Add the offsets to the border rect
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.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.size.height = _border_rect.size.height - (2 * _offsets.height)
- (2 * borderSize.height);
}
topMargin = ceil(titleSize.height / 2);
topOffset = titleSize.height - topMargin;
// Adjust by the title size
_border_rect.size.height -= topMargin;
// Add the offsets to the border rect
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.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.size.height = _border_rect.size.height - (2 * _offsets.height)
- (2 * borderSize.height);
}
// Adjust by the title size
// r.size.height -= titleSize.height + borderSize.height;
// Adjust by the title size
// r.size.height -= titleSize.height + borderSize.height;
// center the title cell
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.size = titleSize;
// center the title cell
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.size = titleSize;
break;
}
case NSAtBottom:
{
NSSize titleSize = [_cell cellSize];
NSSize borderSize = _sizeForBorderType (_border_type);
float c;
float bottomMargin;
float bottomOffset;
break;
}
case NSAtBottom:
{
NSSize titleSize = [_cell cellSize];
NSSize borderSize = [theme sizeForBorderType: _border_type];
float c;
float bottomMargin;
float bottomOffset;
// Add spacer around title
titleSize.width += 6;
titleSize.height += 2;
// Add spacer around title
titleSize.width += 6;
titleSize.height += 2;
_border_rect = _bounds;
_border_rect = _bounds;
bottomMargin = ceil(titleSize.height / 2);
bottomOffset = titleSize.height - bottomMargin;
bottomMargin = ceil(titleSize.height / 2);
bottomOffset = titleSize.height - bottomMargin;
// Adjust by the title size
_border_rect.origin.y += bottomMargin;
_border_rect.size.height -= bottomMargin;
// Adjust by the title size
_border_rect.origin.y += bottomMargin;
_border_rect.size.height -= bottomMargin;
// Add the offsets to the border rect
r.origin.x = _border_rect.origin.x + _offsets.width + borderSize.width;
r.size.width = _border_rect.size.width - (2 * _offsets.width)
- (2 * borderSize.width);
// Add the offsets to the border rect
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 (bottomOffset > _offsets.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.size.height = _border_rect.size.height - (2 * _offsets.height)
- (2 * borderSize.height);
}
if (bottomOffset > _offsets.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.size.height = _border_rect.size.height - (2 * _offsets.height)
- (2 * borderSize.height);
}
// Adjust by the title size
/*
r.origin.y += (titleSize.height / 2) + borderSize.height;
r.size.height -= (titleSize.height / 2) + borderSize.height;
*/
// center the title cell
c = (_border_rect.size.width - titleSize.width) / 2;
if (c < 0) c = 0;
_title_rect.origin.x = c;
_title_rect.origin.y = 0;
_title_rect.size = titleSize;
// Adjust by the title size
/*
r.origin.y += (titleSize.height / 2) + borderSize.height;
r.size.height -= (titleSize.height / 2) + borderSize.height;
*/
// center the title cell
c = (_border_rect.size.width - titleSize.width) / 2;
if (c < 0) c = 0;
_title_rect.origin.x = c;
_title_rect.origin.y = 0;
_title_rect.size = titleSize;
break;
}
case NSBelowBottom:
{
NSSize titleSize = [_cell cellSize];
NSSize borderSize = _sizeForBorderType (_border_type);
float c;
break;
}
case NSBelowBottom:
{
NSSize titleSize = [_cell cellSize];
NSSize borderSize = [theme sizeForBorderType: _border_type];
float c;
// Add spacer around title
titleSize.width += 6;
titleSize.height += 2;
// Add spacer around title
titleSize.width += 6;
titleSize.height += 2;
// Adjust by the title
_border_rect = _bounds;
_border_rect.origin.y += titleSize.height + borderSize.height;
_border_rect.size.height -= titleSize.height + borderSize.height;
// Adjust by the title
_border_rect = _bounds;
_border_rect.origin.y += titleSize.height + borderSize.height;
_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.size.width = _border_rect.size.width - (2 * _offsets.width)
- (2 * borderSize.width);
r.size.height = _border_rect.size.height - (2 * _offsets.height)
- (2 * 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.size.width = _border_rect.size.width - (2 * _offsets.width)
- (2 * borderSize.width);
r.size.height = _border_rect.size.height - (2 * _offsets.height)
- (2 * borderSize.height);
// center the title cell
c = (_border_rect.size.width - titleSize.width) / 2;
if (c < 0) c = 0;
_title_rect.origin.x = c;
_title_rect.origin.y = 0;
_title_rect.size = titleSize;
// center the title cell
c = (_border_rect.size.width - titleSize.width) / 2;
if (c < 0) c = 0;
_title_rect.origin.x = c;
_title_rect.origin.y = 0;
_title_rect.size = titleSize;
break;
}
case NSAboveBottom:
{
NSSize titleSize = [_cell cellSize];
NSSize borderSize = _sizeForBorderType (_border_type);
float c;
break;
}
case NSAboveBottom:
{
NSSize titleSize = [_cell cellSize];
NSSize borderSize = [theme sizeForBorderType: _border_type];
float c;
// Add spacer around title
titleSize.width += 6;
titleSize.height += 2;
// Add spacer around title
titleSize.width += 6;
titleSize.height += 2;
_border_rect = _bounds;
_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.size.width = _border_rect.size.width - (2 * _offsets.width)
- (2 * borderSize.width);
r.size.height = _border_rect.size.height - (2 * _offsets.height)
- (2 * 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.size.width = _border_rect.size.width - (2 * _offsets.width)
- (2 * borderSize.width);
r.size.height = _border_rect.size.height - (2 * _offsets.height)
- (2 * borderSize.height);
// Adjust by the title size
r.origin.y += titleSize.height + borderSize.height;
r.size.height -= titleSize.height + borderSize.height;
// Adjust by the title size
r.origin.y += titleSize.height + borderSize.height;
r.size.height -= titleSize.height + borderSize.height;
// center the title cell
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 + borderSize.height;
_title_rect.size = titleSize;
// center the title cell
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 + borderSize.height;
_title_rect.size = titleSize;
break;
}
break;
}
}
if (!aFlag)

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;