mirror of
https://github.com/gnustep/libs-gui.git
synced 2025-04-22 13:10:59 +00:00
Use an NSMapTable to store which views have been displayed
This commit is contained in:
parent
a73c3cc876
commit
e19038665b
3 changed files with 56 additions and 53 deletions
|
@ -166,7 +166,8 @@ APPKIT_EXPORT_CLASS
|
|||
* We cache column origins (precisely, the x coordinate of the left
|
||||
* origin of each column). When a column width is changed through
|
||||
* [NSTableColumn setWidth:], then [NSTableView tile] gets called,
|
||||
* which updates the cache. */
|
||||
* which updates the cache.
|
||||
*/
|
||||
CGFloat *_columnOrigins;
|
||||
|
||||
/*
|
||||
|
@ -188,7 +189,7 @@ APPKIT_EXPORT_CLASS
|
|||
|
||||
/* Supporting ivars for view based tables */
|
||||
BOOL _viewBased;
|
||||
NSMutableArray *_renderedViewPaths;
|
||||
NSMapTable *_renderedViewPaths;
|
||||
}
|
||||
|
||||
/* Data Source */
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
row: (NSInteger)index;
|
||||
- (id)_objectValueForTableColumn: (NSTableColumn *)tb
|
||||
row: (NSInteger)index;
|
||||
- (NSMutableArray *) _renderedViewPaths;
|
||||
- (NSMapTable *) _renderedViewPaths;
|
||||
@end
|
||||
|
||||
@interface NSTableColumn (Private)
|
||||
|
@ -3542,38 +3542,39 @@ static NSDictionary *titleTextAttributes[3] = {nil, nil, nil};
|
|||
NSTableColumn *tb = nil;
|
||||
NSIndexPath *path = [NSIndexPath indexPathForItem: i
|
||||
inSection: rowIndex];
|
||||
NSMutableArray *paths = [tableView _renderedViewPaths];
|
||||
|
||||
// If the path has been rendered, move on...
|
||||
if ([paths containsObject: path])
|
||||
continue;
|
||||
NSMapTable *paths = [tableView _renderedViewPaths];
|
||||
NSView *view = [paths objectForKey: path];
|
||||
|
||||
// Store the path...
|
||||
[paths addObject: path];
|
||||
|
||||
// drawingRect.origin.y += headerHeight;
|
||||
tb = [tableColumns objectAtIndex: i];
|
||||
if (hasMethod)
|
||||
// If the view has been stored use it, if not
|
||||
// then grab it.
|
||||
if (view == nil)
|
||||
{
|
||||
NSView *view = [delegate tableView: tableView
|
||||
viewForTableColumn: tb
|
||||
row: rowIndex];
|
||||
[view setFrame: drawingRect];
|
||||
[tableView addSubview: view];
|
||||
}
|
||||
else
|
||||
{
|
||||
NSArray *protoCellViews = [tb _prototypeCellViews];
|
||||
NSEnumerator *en = [protoCellViews objectEnumerator];
|
||||
id cellView = nil;
|
||||
|
||||
while ((cellView = [en nextObject]) != nil)
|
||||
tb = [tableColumns objectAtIndex: i];
|
||||
if (hasMethod)
|
||||
{
|
||||
cellView = [cellView copy]; // instantiate the prototype...
|
||||
[cellView setFrame: drawingRect];
|
||||
[tableView addSubview: cellView];
|
||||
view = [delegate tableView: tableView
|
||||
viewForTableColumn: tb
|
||||
row: 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...
|
||||
}
|
||||
}
|
||||
|
||||
// Store the object...
|
||||
[paths setObject: view forKey: path];
|
||||
}
|
||||
|
||||
// Place the view...
|
||||
[view setFrame: drawingRect];
|
||||
[tableView addSubview: view];
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -2044,9 +2044,8 @@ static void computeNewSelection
|
|||
| NSDragOperationLink | NSDragOperationGeneric | NSDragOperationPrivate;
|
||||
_draggingSourceOperationMaskForRemote = NSDragOperationNone;
|
||||
ASSIGN(_sortDescriptors, [NSArray array]);
|
||||
|
||||
_viewBased = NO;
|
||||
_renderedViewPaths = [[NSMutableArray alloc] init];
|
||||
_renderedViewPaths = RETAIN([NSMapTable strongToWeakObjectsMapTable]);
|
||||
}
|
||||
|
||||
- (id) initWithFrame: (NSRect)frameRect
|
||||
|
@ -2359,6 +2358,11 @@ static void computeNewSelection
|
|||
|
||||
- (void) reloadData
|
||||
{
|
||||
if (_viewBased)
|
||||
{
|
||||
[_renderedViewPaths removeAllObjects];
|
||||
}
|
||||
|
||||
[self noteNumberOfRowsChanged];
|
||||
[self setNeedsDisplay: YES];
|
||||
}
|
||||
|
@ -3866,27 +3870,24 @@ if (currentRow >= 0 && currentRow < _numberOfRows) \
|
|||
|
||||
if (eventType == NSLeftMouseDown)
|
||||
{
|
||||
if (_viewBased == NO)
|
||||
/*
|
||||
* Can never get here from a dragging source
|
||||
* so they need to track in mouse up.
|
||||
*/
|
||||
NSCell *cell = [self preparedCellAtColumn: _clickedColumn
|
||||
row: _clickedRow];
|
||||
|
||||
[self _trackCellAtColumn: _clickedColumn
|
||||
row: _clickedRow
|
||||
withEvent: theEvent];
|
||||
didTrackCell = YES;
|
||||
|
||||
if ([[cell class] prefersTrackingUntilMouseUp])
|
||||
{
|
||||
/*
|
||||
* Can never get here from a dragging source
|
||||
* so they need to track in mouse up.
|
||||
*/
|
||||
NSCell *cell = [self preparedCellAtColumn: _clickedColumn
|
||||
row: _clickedRow];
|
||||
|
||||
[self _trackCellAtColumn: _clickedColumn
|
||||
row: _clickedRow
|
||||
withEvent: theEvent];
|
||||
didTrackCell = YES;
|
||||
|
||||
if ([[cell class] prefersTrackingUntilMouseUp])
|
||||
{
|
||||
/* the mouse could have gone up outside of the cell
|
||||
* avoid selecting the row under mouse cursor */
|
||||
sendAction = YES;
|
||||
done = YES;
|
||||
}
|
||||
/* the mouse could have gone up outside of the cell
|
||||
* avoid selecting the row under mouse cursor */
|
||||
sendAction = YES;
|
||||
done = YES;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -7090,7 +7091,7 @@ For a more detailed explanation, -setSortDescriptors:. */
|
|||
}
|
||||
}
|
||||
|
||||
- (NSMutableArray *) _renderedViewPaths
|
||||
- (NSMapTable *) _renderedViewPaths
|
||||
{
|
||||
return _renderedViewPaths;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue