diff --git a/Headers/Additions/GNUstepGUI/GSTheme.h b/Headers/Additions/GNUstepGUI/GSTheme.h index ec5ed76c1..a29497027 100644 --- a/Headers/Additions/GNUstepGUI/GSTheme.h +++ b/Headers/Additions/GNUstepGUI/GSTheme.h @@ -976,6 +976,20 @@ APPKIT_EXPORT NSString *GSThemeWillDeactivateNotification; - (void) drawTableViewBackgroundInClipRect: (NSRect)clipRect inView: (NSView *)view withBackgroundColor: (NSColor *)backgroundColor; + +- (void) drawTableViewRect: (NSRect)aRect + inView: (NSView *)view; + +- (void) drawTableViewGridInClipRect: (NSRect)aRect + inView: (NSView *)view; + +- (void) highlightTableViewSelectionInClipRect: (NSRect)clipRect + inView: (NSView *)view + selectingColumns: (BOOL)selectingColumns; + +- (void) drawTableViewRow: (int)rowIndex + clipRect: (NSRect)clipRect + inView: (NSView *)view; @end /** diff --git a/Source/GSThemeDrawing.m b/Source/GSThemeDrawing.m index cb7a0f628..7bd37e272 100644 --- a/Source/GSThemeDrawing.m +++ b/Source/GSThemeDrawing.m @@ -29,6 +29,8 @@ #import "GSThemePrivate.h" #import "Foundation/NSUserDefaults.h" +#import "Foundation/NSIndexSet.h" + #import "AppKit/NSAttributedString.h" #import "AppKit/NSBezierPath.h" #import "AppKit/NSButtonCell.h" @@ -65,6 +67,13 @@ @interface NSTableView (Private) - (float *)_columnOrigins; +- (void) _willDisplayCell: (NSCell*)cell + forTableColumn: (NSTableColumn *)tb + row: (int)index; +@end + +@interface NSCell (Private) +- (void) _setInEditing: (BOOL)flag; @end @implementation GSTheme (Drawing) @@ -2281,4 +2290,217 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil}; DPSgrestore (ctxt); } + +- (void) drawTableViewRect: (NSRect)aRect + inView: (NSView *)view +{ + int startingRow; + int endingRow; + int i; + NSTableView *tableView = (NSTableView *)view; + int numberOfRows = [tableView numberOfRows]; + int numberOfColumns = [tableView numberOfColumns]; + BOOL drawsGrid = [tableView drawsGrid]; + + /* Draw background */ + [tableView drawBackgroundInClipRect: aRect]; + + if ((numberOfRows == 0) || (numberOfColumns == 0)) + { + return; + } + + /* Draw selection */ + [tableView highlightSelectionInClipRect: aRect]; + + /* Draw grid */ + if (drawsGrid) + { + [tableView drawGridInClipRect: aRect]; + } + + /* Draw visible cells */ + /* Using rowAtPoint: here calls them only twice per drawn rect */ + startingRow = [tableView rowAtPoint: NSMakePoint (0, NSMinY (aRect))]; + endingRow = [tableView rowAtPoint: NSMakePoint (0, NSMaxY (aRect))]; + + if (startingRow == -1) + { + startingRow = 0; + } + if (endingRow == -1) + { + endingRow = numberOfRows - 1; + } + // NSLog(@"drawRect : %d-%d", startingRow, endingRow); + { + SEL sel = @selector(drawRow:clipRect:); + IMP imp = [tableView methodForSelector: sel]; + + for (i = startingRow; i <= endingRow; i++) + { + (*imp)(tableView, sel, i, aRect); + } + } +} + +- (void) highlightTableViewSelectionInClipRect: (NSRect)clipRect + inView: (NSView *)view + selectingColumns: (BOOL)selectingColumns +{ + NSTableView *tableView = (NSTableView *)view; + int numberOfRows = [tableView numberOfRows]; + int numberOfColumns = [tableView numberOfColumns]; + NSIndexSet *selectedRows = [tableView selectedRowIndexes]; + NSIndexSet *selectedColumns = [tableView selectedColumnIndexes]; + NSColor *backgroundColor = [tableView backgroundColor]; + + if (selectingColumns == NO) + { + int selectedRowsCount; + int row; + int startingRow, endingRow; + + selectedRowsCount = [selectedRows count]; + if (selectedRowsCount == 0) + return; + + /* highlight selected rows */ + startingRow = [tableView rowAtPoint: NSMakePoint(0, NSMinY(clipRect))]; + endingRow = [tableView rowAtPoint: NSMakePoint(0, NSMaxY(clipRect))]; + + if (startingRow == -1) + startingRow = 0; + if (endingRow == -1) + endingRow = numberOfRows - 1; + + row = [selectedRows indexGreaterThanOrEqualToIndex: startingRow]; + while ((row != NSNotFound) && (row <= endingRow)) + { + NSColor *selectionColor = nil; + + // Switch to the alternate color of the backgroundColor is white. + if([backgroundColor isEqual: [NSColor whiteColor]]) + { + selectionColor = [NSColor colorWithCalibratedRed: 0.86 + green: 0.92 + blue: 0.99 + alpha: 1.0]; + } + else + { + selectionColor = [NSColor whiteColor]; + } + + //NSHighlightRect(NSIntersectionRect([tableView rectOfRow: row], + // clipRect)); + [selectionColor set]; + NSRectFill(NSIntersectionRect([tableView rectOfRow: row], clipRect)); + row = [selectedRows indexGreaterThanIndex: row]; + } + } + else // Selecting columns + { + unsigned int selectedColumnsCount; + unsigned int column; + int startingColumn, endingColumn; + + selectedColumnsCount = [selectedColumns count]; + + if (selectedColumnsCount == 0) + return; + + /* highlight selected columns */ + startingColumn = [tableView columnAtPoint: NSMakePoint(NSMinX(clipRect), 0)]; + endingColumn = [tableView columnAtPoint: NSMakePoint(NSMaxX(clipRect), 0)]; + + if (startingColumn == -1) + startingColumn = 0; + if (endingColumn == -1) + endingColumn = numberOfColumns - 1; + + column = [selectedColumns indexGreaterThanOrEqualToIndex: startingColumn]; + while ((column != NSNotFound) && (column <= endingColumn)) + { + NSHighlightRect(NSIntersectionRect([tableView rectOfColumn: column], + clipRect)); + column = [selectedColumns indexGreaterThanIndex: column]; + } + } +} + +- (void) drawTableViewRow: (int)rowIndex + clipRect: (NSRect)clipRect + inView: (NSView *)view +{ + NSTableView *tableView = (NSTableView *)view; + // int numberOfRows = [tableView numberOfRows]; + int numberOfColumns = [tableView numberOfColumns]; + // NSIndexSet *selectedRows = [tableView selectedRowIndexes]; + // NSColor *backgroundColor = [tableView backgroundColor]; + id dataSource = [tableView dataSource]; + float *columnOrigins = [tableView _columnOrigins]; + int editedRow = [tableView editedRow]; + int editedColumn = [tableView editedColumn]; + NSArray *tableColumns = [tableView tableColumns]; + int startingColumn; + int endingColumn; + NSTableColumn *tb; + NSRect drawingRect; + NSCell *cell; + int i; + float x_pos; + + if (dataSource == nil) + { + return; + } + + /* Using columnAtPoint: here would make it called twice per row per drawn + rect - so we avoid it and do it natively */ + + /* Determine starting column as fast as possible */ + x_pos = NSMinX (clipRect); + i = 0; + while ((i < numberOfColumns) && (x_pos > columnOrigins[i])) + { + i++; + } + startingColumn = (i - 1); + + if (startingColumn == -1) + startingColumn = 0; + + /* Determine ending column as fast as possible */ + x_pos = NSMaxX (clipRect); + // Nota Bene: we do *not* reset i + while ((i < numberOfColumns) && (x_pos > columnOrigins[i])) + { + i++; + } + endingColumn = (i - 1); + + if (endingColumn == -1) + endingColumn = numberOfColumns - 1; + + /* Draw the row between startingColumn and endingColumn */ + for (i = startingColumn; i <= endingColumn; i++) + { + tb = [tableColumns objectAtIndex: i]; + cell = [tb dataCellForRow: rowIndex]; + if (i == editedColumn && rowIndex == editedRow) + [cell _setInEditing: YES]; + [tableView _willDisplayCell: cell + forTableColumn: tb + row: rowIndex]; + [cell setObjectValue: [dataSource tableView: tableView + objectValueForTableColumn: tb + row: rowIndex]]; + drawingRect = [tableView frameOfCellAtColumn: i + row: rowIndex]; + [cell drawWithFrame: drawingRect inView: tableView]; + if (i == editedColumn && rowIndex == editedRow) + [cell _setInEditing: NO]; + } +} @end diff --git a/Source/NSTableView.m b/Source/NSTableView.m index 90f8f5778..4bbde766f 100644 --- a/Source/NSTableView.m +++ b/Source/NSTableView.m @@ -4955,65 +4955,9 @@ This method is deprecated, use -columnIndexesInRect:. */ - (void) drawRow: (int)rowIndex clipRect: (NSRect)clipRect { - int startingColumn; - int endingColumn; - NSTableColumn *tb; - NSRect drawingRect; - NSCell *cell; - int i; - float x_pos; - - if (_dataSource == nil) - { - return; - } - - /* Using columnAtPoint: here would make it called twice per row per drawn - rect - so we avoid it and do it natively */ - - /* Determine starting column as fast as possible */ - x_pos = NSMinX (clipRect); - i = 0; - while ((i < _numberOfColumns) && (x_pos > _columnOrigins[i])) - { - i++; - } - startingColumn = (i - 1); - - if (startingColumn == -1) - startingColumn = 0; - - /* Determine ending column as fast as possible */ - x_pos = NSMaxX (clipRect); - // Nota Bene: we do *not* reset i - while ((i < _numberOfColumns) && (x_pos > _columnOrigins[i])) - { - i++; - } - endingColumn = (i - 1); - - if (endingColumn == -1) - endingColumn = _numberOfColumns - 1; - - /* Draw the row between startingColumn and endingColumn */ - for (i = startingColumn; i <= endingColumn; i++) - { - tb = [_tableColumns objectAtIndex: i]; - cell = [tb dataCellForRow: rowIndex]; - if (i == _editedColumn && rowIndex == _editedRow) - [cell _setInEditing: YES]; - [self _willDisplayCell: cell - forTableColumn: tb - row: rowIndex]; - [cell setObjectValue: [_dataSource tableView: self - objectValueForTableColumn: tb - row: rowIndex]]; - drawingRect = [self frameOfCellAtColumn: i - row: rowIndex]; - [cell drawWithFrame: drawingRect inView: self]; - if (i == _editedColumn && rowIndex == _editedRow) - [cell _setInEditing: NO]; - } + [[GSTheme theme] drawTableViewRow: rowIndex + clipRect: clipRect + inView: self]; } - (void) noteHeightOfRowsWithIndexesChanged: (NSIndexSet*)indexes @@ -5029,79 +4973,9 @@ This method is deprecated, use -columnIndexesInRect:. */ - (void) highlightSelectionInClipRect: (NSRect)clipRect { - if (_selectingColumns == NO) - { - int selectedRowsCount; - int row; - int startingRow, endingRow; - - selectedRowsCount = [_selectedRows count]; - - if (selectedRowsCount == 0) - return; - - /* highlight selected rows */ - startingRow = [self rowAtPoint: NSMakePoint(0, NSMinY(clipRect))]; - endingRow = [self rowAtPoint: NSMakePoint(0, NSMaxY(clipRect))]; - - if (startingRow == -1) - startingRow = 0; - if (endingRow == -1) - endingRow = _numberOfRows - 1; - - row = [_selectedRows indexGreaterThanOrEqualToIndex: startingRow]; - while ((row != NSNotFound) && (row <= endingRow)) - { - NSColor *selectionColor = nil; - - // Switch to the alternate color of the backgroundColor is white. - if([_backgroundColor isEqual: [NSColor whiteColor]]) - { - selectionColor = [NSColor colorWithCalibratedRed: 0.86 - green: 0.92 - blue: 0.99 - alpha: 1.0]; - } - else - { - selectionColor = [NSColor whiteColor]; - } - - //NSHighlightRect(NSIntersectionRect([self rectOfRow: row], - // clipRect)); - [selectionColor set]; - NSRectFill(NSIntersectionRect([self rectOfRow: row], clipRect)); - row = [_selectedRows indexGreaterThanIndex: row]; - } - } - else // Selecting columns - { - unsigned int selectedColumnsCount; - unsigned int column; - int startingColumn, endingColumn; - - selectedColumnsCount = [_selectedColumns count]; - - if (selectedColumnsCount == 0) - return; - - /* highlight selected columns */ - startingColumn = [self columnAtPoint: NSMakePoint(NSMinX(clipRect), 0)]; - endingColumn = [self columnAtPoint: NSMakePoint(NSMaxX(clipRect), 0)]; - - if (startingColumn == -1) - startingColumn = 0; - if (endingColumn == -1) - endingColumn = _numberOfColumns - 1; - - column = [_selectedColumns indexGreaterThanOrEqualToIndex: startingColumn]; - while ((column != NSNotFound) && (column <= endingColumn)) - { - NSHighlightRect(NSIntersectionRect([self rectOfColumn: column], - clipRect)); - column = [_selectedColumns indexGreaterThanIndex: column]; - } - } + [[GSTheme theme] highlightTableViewSelectionInClipRect: clipRect + inView: self + selectedColumns: _selectingColumns]; } - (void) drawBackgroundInClipRect: (NSRect)clipRect @@ -5113,50 +4987,8 @@ This method is deprecated, use -columnIndexesInRect:. */ - (void) drawRect: (NSRect)aRect { - int startingRow; - int endingRow; - int i; - - /* Draw background */ - [self drawBackgroundInClipRect: aRect]; - - if ((_numberOfRows == 0) || (_numberOfColumns == 0)) - { - return; - } - - /* Draw selection */ - [self highlightSelectionInClipRect: aRect]; - - /* Draw grid */ - if (_drawsGrid) - { - [self drawGridInClipRect: aRect]; - } - - /* Draw visible cells */ - /* Using rowAtPoint: here calls them only twice per drawn rect */ - startingRow = [self rowAtPoint: NSMakePoint (0, NSMinY (aRect))]; - endingRow = [self rowAtPoint: NSMakePoint (0, NSMaxY (aRect))]; - - if (startingRow == -1) - { - startingRow = 0; - } - if (endingRow == -1) - { - endingRow = _numberOfRows - 1; - } - // NSLog(@"drawRect : %d-%d", startingRow, endingRow); - { - SEL sel = @selector(drawRow:clipRect:); - IMP imp = [self methodForSelector: sel]; - - for (i = startingRow; i <= endingRow; i++) - { - (*imp)(self, sel, i, aRect); - } - } + [[GSTheme theme] drawTableViewRect: aRect + inView: self]; } - (BOOL) isOpaque