From 4b2cb3d369f8f4b380940ef390720ac1ebd8cadf Mon Sep 17 00:00:00 2001 From: Nicola Pero Date: Sat, 18 Mar 2000 00:26:02 +0000 Subject: [PATCH] Rewritten much git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gui/trunk@6306 72102866-910b-0410-8b05-ffd578937521 --- Source/NSTableHeaderView.m | 63 ++++++++++++++++++++++---------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/Source/NSTableHeaderView.m b/Source/NSTableHeaderView.m index c81de14b9..4afe3501c 100644 --- a/Source/NSTableHeaderView.m +++ b/Source/NSTableHeaderView.m @@ -74,6 +74,7 @@ // We do not RETAIN aTableView but aTableView is supposed // to RETAIN us. _tableView = aTableView; + } - (NSTableView*)tableView { @@ -102,33 +103,28 @@ */ - (int)columnAtPoint: (NSPoint)aPoint { - // TODO - return -1; + if (_tableView == nil) + return -1; + + /* Ask to the tableview, which is caching geometry info */ + aPoint = [self convertPoint: aPoint toView: _tableView]; + aPoint.y = [_tableView bounds].origin.y; + return [_tableView columnAtPoint: aPoint]; } + - (NSRect)headerRectOfColumn: (int)columnIndex { - NSArray* columns; NSRect rect; - int i; if (_tableView == nil) return NSZeroRect; - columns = [_tableView tableColumns]; - - NSAssert(columnIndex > 0, NSInternalInconsistencyException); - NSAssert(columnIndex < [columns count], NSInternalInconsistencyException); - - rect.origin.x = _bounds.origin.x; + /* Ask to the tableview, which is caching geometry info */ + rect = [_tableView rectOfColumn: columnIndex]; + rect = [self convertRect: rect fromView: _tableView]; rect.origin.y = _bounds.origin.y; rect.size.height = _bounds.size.height; - for (i = 0; i < columnIndex; i++) - { - rect.origin.x += [[columns objectAtIndex: i] width]; - } - rect.size.width = [[columns objectAtIndex: columnIndex] width]; - return rect; } @@ -137,24 +133,39 @@ */ - (void)drawRect: (NSRect)aRect { - NSArray* columns; - NSRange columnsToDraw; + NSArray *columns; + int firstColumnToDraw; + int lastColumnToDraw; + NSRect drawingRect; + NSTableColumn *column; + float width; int i; if (_tableView == nil) return; - - columnsToDraw = [_tableView columnsInRect: aRect]; - if (columnsToDraw.length == 0) - return; + firstColumnToDraw = [self columnAtPoint: NSMakePoint (aRect.origin.x, + aRect.origin.y)]; + if (firstColumnToDraw == -1) + firstColumnToDraw = 0; + + lastColumnToDraw = [self columnAtPoint: NSMakePoint (NSMaxX (aRect), + aRect.origin.y)]; + if (lastColumnToDraw == -1) + lastColumnToDraw = [_tableView numberOfColumns] - 1; + + drawingRect = [self headerRectOfColumn: firstColumnToDraw]; + columns = [_tableView tableColumns]; - for (i = columnsToDraw.location; i < columnsToDraw.length + 1; i++) + for (i = firstColumnToDraw; i <= lastColumnToDraw; i++) { - [[[columns objectAtIndex: i] headerCell] - drawWithFrame: [self headerRectOfColumn: i] - inView: self]; + column = [columns objectAtIndex: i]; + width = [column width]; + drawingRect.size.width = width; + [[column headerCell] drawWithFrame: drawingRect + inView: self]; + drawingRect.origin.x += width; } } -(void)mouseDown: (NSEvent*)event