I have implemented a solution where I override mouseDown:. I don't really like it. But it works. Still hoping for better ideas.
- (void)mouseDown:(NSEvent *)theEvent
{
if (! [self handleMouseDown:theEvent]) {
[super mouseDown:theEvent];
}
}
- (BOOL)handleMouseDown:(NSEvent *)theEvent
{
NSInteger clickCount = [theEvent clickCount];
if (clickCount != 1) {
return NO;
}
NSPoint locationInWindow = [theEvent locationInWindow];
NSPoint locationInView = [self convertPoint:locationInWindow fromView:nil];
NSInteger clickedRow = [self rowAtPoint:locationInView];
NSInteger clickedColumn = [self columnAtPoint:locationInView];
if ((clickedRow < 0) || (clickedColumn < 0)) {
return NO;
}
if ((clickedRow >= [self numberOfRows]) || (clickedColumn >= [self numberOfColumns])) {
return NO;
}
NSArray *tableColumns = [self tableColumns];
NSTableColumn *tableColumn = [tableColumns objectAtIndex:clickedColumn];
NSCell *cell = [tableColumn dataCellForRow:clickedRow];
id <NSTableViewDelegate> delegate = [self delegate];
BOOL shouldTrackCell = NO;
if ([delegate respondsToSelector:@selector(tableView:shouldTrackCell:forTableColumn:row:)]) {
shouldTrackCell = [delegate tableView:self shouldTrackCell:cell forTableColumn:tableColumn row:clickedRow];
}
if (! shouldTrackCell) {
return NO;
}
BOOL prefersTrackingUntilMouseUp = [[cell class] prefersTrackingUntilMouseUp];
NSRect cellFrame = [self frameOfCellAtColumn:clickedColumn row:clickedRow];
return [cell trackMouse:theEvent inRect:cellFrame ofView:self untilMouseUp:prefersTrackingUntilMouseUp];
}