diff --git a/Source/GSThemeDrawing.m b/Source/GSThemeDrawing.m index b17edfe60..a87fe7458 100644 --- a/Source/GSThemeDrawing.m +++ b/Source/GSThemeDrawing.m @@ -3384,30 +3384,17 @@ - (void) highlightTableViewSelectionInClipRect: (NSRect)clipRect } } -- (void) drawTableViewRow: (NSInteger)rowIndex - clipRect: (NSRect)clipRect - inView: (NSTableView *)tableView +- (void) _calculatedStartingColumn: (NSInteger *)startingColumn + endingColumn: (NSInteger *)endingColumn + withTableView: (NSTableView *)tableView + inClipRect: (NSRect)clipRect + { - // NSInteger numberOfRows = [tableView numberOfRows]; + CGFloat x_pos = 0.0; + NSInteger i = 0; NSInteger numberOfColumns = [tableView numberOfColumns]; - // NSIndexSet *selectedRows = [tableView selectedRowIndexes]; - // NSColor *backgroundColor = [tableView backgroundColor]; CGFloat *columnOrigins = [tableView _columnOrigins]; - NSInteger editedRow = [tableView editedRow]; - NSInteger editedColumn = [tableView editedColumn]; - NSArray *tableColumns = [tableView tableColumns]; - NSInteger startingColumn; - NSInteger endingColumn; - NSTableColumn *tb; - NSRect drawingRect; - NSCell *cell; - NSInteger i; - CGFloat x_pos; - const BOOL rowSelected = [[tableView selectedRowIndexes] containsIndex: rowIndex]; - NSColor *tempColor = nil; - NSColor *selectedTextColor = [self colorNamed: @"highlightedTableRowTextColor" - state: GSThemeNormalState]; - + /* Using columnAtPoint: here would make it called twice per row per drawn rect - so we avoid it and do it natively */ @@ -3418,10 +3405,10 @@ - (void) drawTableViewRow: (NSInteger)rowIndex { i++; } - startingColumn = (i - 1); + *startingColumn = (i - 1); - if (startingColumn == -1) - startingColumn = 0; + if (*startingColumn == -1) + *startingColumn = 0; /* Determine ending column as fast as possible */ x_pos = NSMaxX (clipRect); @@ -3430,11 +3417,35 @@ - (void) drawTableViewRow: (NSInteger)rowIndex { i++; } - endingColumn = (i - 1); + *endingColumn = (i - 1); - if (endingColumn == -1) - endingColumn = numberOfColumns - 1; + if (*endingColumn == -1) + *endingColumn = numberOfColumns - 1; +} + +- (void) drawTableViewRow: (NSInteger)rowIndex + clipRect: (NSRect)clipRect + inView: (NSTableView *)tableView +{ + NSInteger editedRow = [tableView editedRow]; + NSInteger editedColumn = [tableView editedColumn]; + NSArray *tableColumns = [tableView tableColumns]; + NSInteger startingColumn; + NSInteger endingColumn; + NSTableColumn *tb; + NSRect drawingRect; + NSCell *cell; + NSInteger i; + const BOOL rowSelected = [[tableView selectedRowIndexes] containsIndex: rowIndex]; + NSColor *tempColor = nil; + NSColor *selectedTextColor = [self colorNamed: @"highlightedTableRowTextColor" + state: GSThemeNormalState]; + [self _calculatedStartingColumn: &startingColumn + endingColumn: &endingColumn + withTableView: tableView + inClipRect: clipRect]; + /* Draw the row between startingColumn and endingColumn */ for (i = startingColumn; i <= endingColumn; i++) { @@ -3484,26 +3495,84 @@ - (void) drawTableViewRow: (NSInteger)rowIndex } } +- (NSRect) _drawOutlineTableColumn: (NSTableColumn *)tb + outlineView: (NSOutlineView *)outlineView + item: (id)item + drawingRect: (NSRect)inputRect + rowIndex: (NSInteger)rowIndex +{ + NSRect drawingRect = inputRect; + NSImage *image = nil; + NSInteger level = 0; + CGFloat indentationFactor = 0.0; + CGFloat indentationPerLevel = [outlineView indentationPerLevel]; + NSCell *imageCell = nil; + NSRect imageRect; + id delegate = [outlineView delegate]; + + // display the correct arrow... + if ([outlineView isItemExpanded: item]) + { + image = [NSImage imageNamed: @"common_ArrowDownH"]; + } + else + { + image = [NSImage imageNamed: @"common_ArrowRightH"]; + } + + if (![outlineView isExpandable: item]) + { + image = AUTORELEASE([[NSImage alloc] initWithSize: NSMakeSize(14.0,14.0)]); + } + + level = [outlineView levelForItem: item]; + indentationFactor = indentationPerLevel * level; + imageCell = [[NSCell alloc] initImageCell: image]; + imageRect = [outlineView frameOfOutlineCellAtRow: rowIndex]; + + if ([delegate respondsToSelector: @selector(outlineView:willDisplayOutlineCell:forTableColumn:item:)]) + { + [delegate outlineView: outlineView + willDisplayOutlineCell: imageCell + forTableColumn: tb + item: item]; + } + + /* Do not indent if the delegate set the image to nil. */ + if ([imageCell image]) + { + imageRect.size.width = [image size].width; + imageRect.size.height = [image size].height + 5; + [imageCell drawWithFrame: imageRect inView: outlineView]; + drawingRect.origin.x + += indentationFactor + imageRect.size.width + 5; + drawingRect.size.width + -= indentationFactor + imageRect.size.width + 5; + } + else + { + drawingRect.origin.x += indentationFactor; + drawingRect.size.width -= indentationFactor; + } + + RELEASE(imageCell); + + return drawingRect; +} + - (void) drawOutlineViewRow: (NSInteger)rowIndex clipRect: (NSRect)clipRect inView: (NSOutlineView *)outlineView { - NSInteger numberOfColumns = [outlineView numberOfColumns]; - CGFloat *columnOrigins = [outlineView _columnOrigins]; NSInteger editedRow = [outlineView editedRow]; NSInteger editedColumn = [outlineView editedColumn]; NSArray *tableColumns = [outlineView tableColumns]; - CGFloat indentationPerLevel = [outlineView indentationPerLevel]; NSInteger numberOfRows = [outlineView numberOfRows]; NSInteger startingColumn; NSInteger endingColumn; NSRect drawingRect; - NSCell *imageCell = nil; - NSRect imageRect; NSInteger i; - CGFloat x_pos; id dataSource = [outlineView dataSource]; - id delegate = [outlineView delegate]; NSTableColumn *outlineTableColumn = [outlineView outlineTableColumn]; if (dataSource == nil) @@ -3519,30 +3588,11 @@ - (void) drawOutlineViewRow: (NSInteger)rowIndex return; } - /* 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; - + [self _calculatedStartingColumn: &startingColumn + endingColumn: &endingColumn + withTableView: outlineView + inClipRect: clipRect]; + /* Draw the row between startingColumn and endingColumn */ for (i = startingColumn; i <= endingColumn; i++) { @@ -3564,62 +3614,18 @@ - (void) drawOutlineViewRow: (NSInteger)rowIndex objectValueForTableColumn: tb byItem: item]]; } + drawingRect = [outlineView frameOfCellAtColumn: i row: rowIndex]; if (tb == outlineTableColumn) { - NSImage *image = nil; - NSInteger level = 0; - CGFloat indentationFactor = 0.0; - - // display the correct arrow... - if ([outlineView isItemExpanded: item]) - { - image = [NSImage imageNamed: @"common_ArrowDownH"]; - } - else - { - image = [NSImage imageNamed: @"common_ArrowRightH"]; - } - - if (![outlineView isExpandable: item]) - { - image = AUTORELEASE([[NSImage alloc] initWithSize: NSMakeSize(14.0,14.0)]); - } - - level = [outlineView levelForItem: item]; - indentationFactor = indentationPerLevel * level; - imageCell = [[NSCell alloc] initImageCell: image]; - imageRect = [outlineView frameOfOutlineCellAtRow: rowIndex]; - - if ([delegate respondsToSelector: @selector(outlineView:willDisplayOutlineCell:forTableColumn:item:)]) - { - [delegate outlineView: outlineView - willDisplayOutlineCell: imageCell - forTableColumn: tb - item: item]; - } - - /* Do not indent if the delegate set the image to nil. */ - if ([imageCell image]) - { - imageRect.size.width = [image size].width; - imageRect.size.height = [image size].height; - [imageCell drawWithFrame: imageRect inView: outlineView]; - drawingRect.origin.x - += indentationFactor + imageRect.size.width + 5; - drawingRect.size.width - -= indentationFactor + imageRect.size.width + 5; - } - else - { - drawingRect.origin.x += indentationFactor; - drawingRect.size.width -= indentationFactor; - } - - RELEASE(imageCell); - } + drawingRect = [self _drawOutlineTableColumn: tb + outlineView: outlineView + item: item + drawingRect: drawingRect + rowIndex: rowIndex]; + } [cell drawWithFrame: drawingRect inView: outlineView]; if (i == editedColumn && rowIndex == editedRow) @@ -3630,18 +3636,30 @@ - (void) drawOutlineViewRow: (NSInteger)rowIndex } } +- (id) _prototypeCellViewFromTableColumn: (NSTableColumn *)tb +{ + NSArray *protoCellViews = [tb _prototypeCellViews]; + id view = nil; + + // it seems there is always one prototype... + if ([protoCellViews count] > 0) + { + view = [protoCellViews objectAtIndex: 0]; + view = [view copy]; // instantiate the prototype... + } + + return view; +} + - (void) drawCellViewRow: (NSInteger)rowIndex clipRect: (NSRect)clipRect inView: (NSTableView *)v { - NSInteger numberOfColumns = [v numberOfColumns]; - CGFloat *columnOrigins = [v _columnOrigins]; NSArray *tableColumns = [v tableColumns]; NSInteger numberOfRows = [v numberOfRows]; NSInteger startingColumn; NSInteger endingColumn; NSInteger i; - CGFloat x_pos; id dataSource = [v dataSource]; id delegate = [v delegate]; BOOL hasMethod = NO; @@ -3671,30 +3689,12 @@ - (void) drawCellViewRow: (NSInteger)rowIndex { hasMethod = [delegate respondsToSelector: @selector(tableView:viewForTableColumn:row:)]; } - - /* 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); - while ((i < numberOfColumns) && (x_pos > columnOrigins[i])) - { - i++; - } - endingColumn = (i - 1); - - if (endingColumn == -1) - endingColumn = numberOfColumns - 1; + [self _calculatedStartingColumn: &startingColumn + endingColumn: &endingColumn + withTableView: v + inClipRect: clipRect]; + /* Draw the row between startingColumn and endingColumn */ for (i = startingColumn; i <= endingColumn; i++) { @@ -3708,64 +3708,19 @@ - (void) drawCellViewRow: (NSInteger)rowIndex if (ov != nil) { id item = [ov itemAtRow: rowIndex]; - CGFloat indentationPerLevel = [ov indentationPerLevel]; if (tb == outlineTableColumn) { - NSImage *image = nil; - NSInteger level = 0; - CGFloat indentationFactor = 0.0; - NSImageView *imageView = nil; - NSRect imageRect = NSZeroRect; - - // display the correct arrow... - if ([ov isItemExpanded: item]) - { - image = [NSImage imageNamed: @"common_ArrowDownH"]; - } - else - { - image = [NSImage imageNamed: @"common_ArrowRightH"]; - } - - if (![ov isExpandable: item]) - { - image = AUTORELEASE([[NSImage alloc] initWithSize: NSMakeSize(14.0,14.0)]); - } - - level = [ov levelForItem: item]; - indentationFactor = indentationPerLevel * level; - imageView = [[NSImageView alloc] init]; - [imageView setImage: image]; - imageRect = [ov frameOfOutlineCellAtRow: rowIndex]; - - /* Do not indent if the delegate set the image to nil. */ - if ([imageView image]) - { - imageRect.size.width = [image size].width; - imageRect.size.height = [ov rowHeight]; - - // Place the image... - [imageView setFrame: imageRect]; - [ov addSubview: imageView]; - - drawingRect.origin.x - += indentationFactor + imageRect.size.width + 5; - drawingRect.size.width - -= indentationFactor + imageRect.size.width + 5; - } - else - { - drawingRect.origin.x += indentationFactor; - drawingRect.size.width -= indentationFactor; - } - - RELEASE(imageView); + drawingRect = [self _drawOutlineTableColumn: tb + outlineView: ov + item: item + drawingRect: drawingRect + rowIndex: rowIndex]; } if (view == nil) { - if (hasMethod && ov != nil) + if (hasMethod) { view = [delegate outlineView: ov viewForTableColumn: tb @@ -3773,18 +3728,8 @@ - (void) drawCellViewRow: (NSInteger)rowIndex } else { - NSArray *protoCellViews = [tb _prototypeCellViews]; - - // it seems there is always one prototype... - if ([protoCellViews count] > 0) - { - view = [protoCellViews objectAtIndex: 0]; - view = [view copy]; // instantiate the prototype... - } + view = [self _prototypeCellViewFromTableColumn: tb]; } - - [ov _setRenderedView: view forPath: path]; - [ov addSubview: view]; } } else @@ -3801,22 +3746,15 @@ - (void) drawCellViewRow: (NSInteger)rowIndex } else { - NSArray *protoCellViews = [tb _prototypeCellViews]; - - // it seems there is always one prototype... - if ([protoCellViews count] > 0) - { - view = [protoCellViews objectAtIndex: 0]; - view = [view copy]; // instantiate the prototype... - } + view = [self _prototypeCellViewFromTableColumn: tb]; } - - // Store the object... - [v _setRenderedView: view forPath: path]; - [v addSubview: view]; } } + // Store the object... + [v _setRenderedView: view forPath: path]; + [v addSubview: view]; + // Place the view... [view setFrame: drawingRect]; } diff --git a/Source/NSOutlineView.m b/Source/NSOutlineView.m index c40a8956f..37d11e6cf 100644 --- a/Source/NSOutlineView.m +++ b/Source/NSOutlineView.m @@ -878,8 +878,8 @@ - (void) mouseDown: (NSEvent *)theEvent position += _columnOrigins[_clickedColumn]; if ([self isExpandable:item] - && location.x >= position - && location.x <= position + [image size].width + 5) + && location.x >= position - 5 + && location.x <= position + [image size].width + 10) { BOOL withChildren = ([theEvent modifierFlags] & NSAlternateKeyMask) ? YES : NO; diff --git a/Source/NSTableColumn.m b/Source/NSTableColumn.m index 372c28791..ff99499ee 100644 --- a/Source/NSTableColumn.m +++ b/Source/NSTableColumn.m @@ -73,6 +73,10 @@ #import "AppKit/NSTableView.h" #import "GSBindingHelpers.h" +@interface NSTableView (__NSTableColumnPrivate__) +- (void) _registerPrototypeViews: (NSArray *)prototypeViews; +@end + /**

@@ -510,6 +514,7 @@ - (void) encodeWithCoder: (NSCoder*)aCoder [aCoder encodeObject: _dataCell]; [aCoder encodeObject: _sortDescriptorPrototype]; + [aCoder encodeObject: _tableView]; [aCoder encodeObject: _prototypeCellViews]; } } @@ -580,6 +585,7 @@ - (id) initWithCoder: (NSCoder*)aDecoder if ([aDecoder containsValueForKey: @"NSPrototypeCellViews"]) { ASSIGN(_prototypeCellViews, [aDecoder decodeObjectForKey: @"NSPrototypeCellViews"]); + [_tableView _registerPrototypeViews: _prototypeCellViews]; } } else @@ -609,7 +615,9 @@ - (id) initWithCoder: (NSCoder*)aDecoder if (version >= 4) { + _tableView = [aDecoder decodeObject]; // not retained, tableView retains us... _prototypeCellViews = RETAIN([aDecoder decodeObject]); + [_tableView _registerPrototypeViews: _prototypeCellViews]; } } else diff --git a/Source/NSTableView.m b/Source/NSTableView.m index a5badd1a9..145c3c37c 100644 --- a/Source/NSTableView.m +++ b/Source/NSTableView.m @@ -55,6 +55,7 @@ #import "AppKit/NSGraphics.h" #import "AppKit/NSKeyValueBinding.h" #import "AppKit/NSNib.h" +#import "AppKit/NSNibLoading.h" #import "AppKit/NSScroller.h" #import "AppKit/NSScrollView.h" #import "AppKit/NSTableColumn.h" @@ -6903,7 +6904,8 @@ - (NSView *) makeViewWithIdentifier: (NSUserInterfaceItemIdentifier)identifier o if (view != nil) { view = [view copy]; - // [owner awakeFromNib]; + [view awakeFromNib]; + [owner awakeFromNib]; } else { @@ -6950,6 +6952,32 @@ - (NSDictionary *) registeredNibsByIdentifier return [_registeredNibs copy]; } +// Private helper methods... + +- (void) _registerPrototypeViews: (NSArray *)prototypeViews +{ + NSEnumerator *en = [prototypeViews objectEnumerator]; + NSView *view = nil; + + while ((view = [en nextObject]) != nil) + { + NSUserInterfaceItemIdentifier identifier = [view identifier]; + [_registeredViews setObject: view + forKey: identifier]; + } +} + +- (NSView *) _renderedViewForPath: (NSIndexPath *)path +{ + return [_renderedViewPaths objectForKey: path]; +} + +- (void) _setRenderedView: (NSView *)view forPath: (NSIndexPath *)path +{ + [_renderedViewPaths setObject: view forKey: path]; + [_pathsToViews setObject: path forKey: view]; +} + @end /* implementation of NSTableView */ @implementation NSTableView (SelectionHelper) @@ -7138,15 +7166,4 @@ - (id) valueForKey: (NSString*)aKey } } -- (NSView *) _renderedViewForPath: (NSIndexPath *)path -{ - return [_renderedViewPaths objectForKey: path]; -} - -- (void) _setRenderedView: (NSView *)view forPath: (NSIndexPath *)path -{ - [_renderedViewPaths setObject: view forKey: path]; - [_pathsToViews setObject: path forKey: view]; -} - @end