diff --git a/ChangeLog b/ChangeLog index ce1ad9428..2c67e92ff 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-11-27 Gregory John Casamento + + * Source/GSThemeDrawing.m: Added methods to draw NSTableView + header and view. + * Source/NSTableView.m: Added call in to drawing methods in + GSTheme. + * Headers/Additions/GNUstepGUI/GSTheme.h: + Added declaration for new method. + 2010-11-27 Gregory John Casamento * Source/GSThemeDrawing.m: Added methods to draw NSTableHeaderView diff --git a/Headers/Additions/GNUstepGUI/GSTheme.h b/Headers/Additions/GNUstepGUI/GSTheme.h index e8f86764a..ec5ed76c1 100644 --- a/Headers/Additions/GNUstepGUI/GSTheme.h +++ b/Headers/Additions/GNUstepGUI/GSTheme.h @@ -966,7 +966,16 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification; - (NSRect) tableHeaderCellDrawingRectForBounds: (NSRect)theRect; -- (void) drawTableHeaderRect: (NSRect)aRect inView: (NSView *)view; +- (void) drawTableHeaderRect: (NSRect)aRect + inView: (NSView *)view; + +- (void) drawPopUpButtonCellInteriorWithFrame: (NSRect)cellFrame + withCell: (NSCell *)cell + inView: (NSView *)controlView; + +- (void) drawTableViewBackgroundInClipRect: (NSRect)clipRect + inView: (NSView *)view + withBackgroundColor: (NSColor *)backgroundColor; @end /** diff --git a/Source/GSThemeDrawing.m b/Source/GSThemeDrawing.m index 3ec458326..cb7a0f628 100644 --- a/Source/GSThemeDrawing.m +++ b/Source/GSThemeDrawing.m @@ -63,6 +63,10 @@ /* 8.0 gives us the NeXT Look */ #define COLOR_WELL_BORDER_WIDTH 8.0 +@interface NSTableView (Private) +- (float *)_columnOrigins; +@end + @implementation GSTheme (Drawing) - (void) drawButton: (NSRect)frame @@ -2157,4 +2161,124 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil}; drawingRect.origin.x += width; } } + +- (void) drawPopUpButtonCellInteriorWithFrame: (NSRect)cellFrame + withCell: (NSCell *)cell + inView: (NSView *)controlView +{ + // Default implementation of this method does nothing. +} + +- (void) drawTableViewBackgroundInClipRect: (NSRect)clipRect + inView: (NSView *)view + withBackgroundColor: (NSColor *)backgroundColor +{ + + [backgroundColor set]; + NSRectFill (clipRect); +} + +- (void) drawTableViewGridInClipRect: (NSRect)aRect + inView: (NSView *)view +{ + NSTableView *tableView = (NSTableView *)view; + NSRect bounds = [view bounds]; + float minX = NSMinX (aRect); + float maxX = NSMaxX (aRect); + float minY = NSMinY (aRect); + float maxY = NSMaxY (aRect); + int i; + float x_pos; + int startingColumn; + int endingColumn; + int numberOfColumns = [tableView numberOfColumns]; + NSArray *tableColumns = [tableView tableColumns]; + NSGraphicsContext *ctxt = GSCurrentContext (); + float position = 0.0; + float *columnOrigins = [tableView _columnOrigins]; + int startingRow = [tableView rowAtPoint: + NSMakePoint (bounds.origin.x, minY)]; + int endingRow = [tableView rowAtPoint: + NSMakePoint (bounds.origin.x, maxY)]; + NSColor *gridColor = [tableView gridColor]; + int rowHeight = [tableView rowHeight]; + int numberOfRows = [tableView numberOfRows]; + + /* Using columnAtPoint:, rowAtPoint: here calls them only twice + per drawn rect */ + x_pos = minX; + i = 0; + while ((i < numberOfColumns) && (x_pos > columnOrigins[i])) + { + i++; + } + startingColumn = (i - 1); + + x_pos = maxX; + // Nota Bene: we do *not* reset i + while ((i < numberOfColumns) && (x_pos > columnOrigins[i])) + { + i++; + } + endingColumn = (i - 1); + + if (endingColumn == -1) + endingColumn = numberOfColumns - 1; + /* + int startingColumn = [tableView columnAtPoint: + NSMakePoint (minX, bounds.origin.y)]; + int endingColumn = [tableView columnAtPoint: + NSMakePoint (maxX, bounds.origin.y)]; + */ + + DPSgsave (ctxt); + DPSsetlinewidth (ctxt, 1); + [gridColor set]; + + if (numberOfRows > 0) + { + /* Draw horizontal lines */ + if (startingRow == -1) + startingRow = 0; + if (endingRow == -1) + endingRow = numberOfRows - 1; + + position = bounds.origin.y; + position += startingRow * rowHeight; + for (i = startingRow; i <= endingRow + 1; i++) + { + DPSmoveto (ctxt, minX, position); + DPSlineto (ctxt, maxX, position); + DPSstroke (ctxt); + position += rowHeight; + } + } + + if (numberOfColumns > 0) + { + int lastRowPosition = position - rowHeight; + /* Draw vertical lines */ + if (startingColumn == -1) + startingColumn = 0; + if (endingColumn == -1) + endingColumn = numberOfColumns - 1; + + for (i = startingColumn; i <= endingColumn; i++) + { + DPSmoveto (ctxt, columnOrigins[i], minY); + DPSlineto (ctxt, columnOrigins[i], lastRowPosition); + DPSstroke (ctxt); + } + position = columnOrigins[endingColumn]; + position += [[tableColumns objectAtIndex: endingColumn] width]; + /* Last vertical line must moved a pixel to the left */ + if (endingColumn == (numberOfColumns - 1)) + position -= 1; + DPSmoveto (ctxt, position, minY); + DPSlineto (ctxt, position, lastRowPosition); + DPSstroke (ctxt); + } + + DPSgrestore (ctxt); +} @end diff --git a/Source/NSPopUpButtonCell.m b/Source/NSPopUpButtonCell.m index 4dfa8dd3a..dc7d39b41 100644 --- a/Source/NSPopUpButtonCell.m +++ b/Source/NSPopUpButtonCell.m @@ -1063,6 +1063,9 @@ static NSImage *_pbc_image[5]; /* We need to calc our size to get images placed correctly */ [self calcSize]; + [[GSTheme theme] drawPopUpButtonCellInteriorWithFrame: cellFrame + withCell: self + inView: controlView]; [super drawInteriorWithFrame: cellFrame inView: controlView]; /* Unset the item to restore balance if a new was created */ diff --git a/Source/NSTableView.m b/Source/NSTableView.m index af818d317..90f8f5778 100644 --- a/Source/NSTableView.m +++ b/Source/NSTableView.m @@ -5023,100 +5023,8 @@ This method is deprecated, use -columnIndexesInRect:. */ - (void) drawGridInClipRect: (NSRect)aRect { - float minX = NSMinX (aRect); - float maxX = NSMaxX (aRect); - float minY = NSMinY (aRect); - float maxY = NSMaxY (aRect); - int i; - float x_pos; - int startingColumn; - int endingColumn; - - NSGraphicsContext *ctxt = GSCurrentContext (); - float position = 0.0; - - int startingRow = [self rowAtPoint: - NSMakePoint (_bounds.origin.x, minY)]; - int endingRow = [self rowAtPoint: - NSMakePoint (_bounds.origin.x, maxY)]; - - /* Using columnAtPoint:, rowAtPoint: here calls them only twice - - per drawn rect */ - x_pos = minX; - i = 0; - while ((i < _numberOfColumns) && (x_pos > _columnOrigins[i])) - { - i++; - } - startingColumn = (i - 1); - - x_pos = maxX; - // Nota Bene: we do *not* reset i - while ((i < _numberOfColumns) && (x_pos > _columnOrigins[i])) - { - i++; - } - endingColumn = (i - 1); - - if (endingColumn == -1) - endingColumn = _numberOfColumns - 1; - /* - int startingColumn = [self columnAtPoint: - NSMakePoint (minX, _bounds.origin.y)]; - int endingColumn = [self columnAtPoint: - NSMakePoint (maxX, _bounds.origin.y)]; - */ - - DPSgsave (ctxt); - DPSsetlinewidth (ctxt, 1); - [_gridColor set]; - - if (_numberOfRows > 0) - { - /* Draw horizontal lines */ - if (startingRow == -1) - startingRow = 0; - if (endingRow == -1) - endingRow = _numberOfRows - 1; - - position = _bounds.origin.y; - position += startingRow * _rowHeight; - for (i = startingRow; i <= endingRow + 1; i++) - { - DPSmoveto (ctxt, minX, position); - DPSlineto (ctxt, maxX, position); - DPSstroke (ctxt); - position += _rowHeight; - } - } - - if (_numberOfColumns > 0) - { - int lastRowPosition = position - _rowHeight; - /* Draw vertical lines */ - if (startingColumn == -1) - startingColumn = 0; - if (endingColumn == -1) - endingColumn = _numberOfColumns - 1; - - for (i = startingColumn; i <= endingColumn; i++) - { - DPSmoveto (ctxt, _columnOrigins[i], minY); - DPSlineto (ctxt, _columnOrigins[i], lastRowPosition); - DPSstroke (ctxt); - } - position = _columnOrigins[endingColumn]; - position += [[_tableColumns objectAtIndex: endingColumn] width]; - /* Last vertical line must moved a pixel to the left */ - if (endingColumn == (_numberOfColumns - 1)) - position -= 1; - DPSmoveto (ctxt, position, minY); - DPSlineto (ctxt, position, lastRowPosition); - DPSstroke (ctxt); - } - - DPSgrestore (ctxt); + [[GSTheme theme] drawTableViewGridInClipRect: aRect + inView: self]; } - (void) highlightSelectionInClipRect: (NSRect)clipRect @@ -5198,9 +5106,10 @@ This method is deprecated, use -columnIndexesInRect:. */ - (void) drawBackgroundInClipRect: (NSRect)clipRect { - [_backgroundColor set]; - NSRectFill (clipRect); -} + [[GSTheme theme] drawTableViewBackgroundInClipRect: clipRect + inView: self + withBackgroundColor: _backgroundColor]; +} - (void) drawRect: (NSRect)aRect {