TableView Mouse Tracking problem
TableView Mouse Tracking problem
- Subject: TableView Mouse Tracking problem
- From: Matt Ball <email@hidden>
- Date: Tue, 12 Jul 2005 02:07:34 -0400
I am working with tableView, and I am attempting to implement
something similar to Finder and iTunes' "Eject" button (the little
icon that gets a black background when you rollover it). I've set up
some mouse tracking in my NSTableview subclass, and I've had it
working well. However, the CPU usage was through the use, so I rewrote
the method from scratch. However, now, when I rollover cells, they
stay in the rolled-over state, so once I've rolled over all the
buttons, each one appears rolled-over. Could somebody take a look at
this code and see if anything jumps out at you as the reason behind
this? (It's been a long day, so it's probably something stupid)
In my tableView subclass:
- (void)mouseMoved:(NSEvent *)theEvent
{
if(mouseOverView) {
mouseOverRow = [self rowAtPoint:[self convertPoint:[theEvent
locationInWindow] fromView:nil]];
mouseOverColumn = [self columnAtPoint:[self convertPoint:[theEvent
locationInWindow] fromView:nil]];
if(mouseOverRow != lastOverRow || mouseOverColumn != lastOverColumn) {
lastOverRow = mouseOverRow;
lastOverColumn = mouseOverColumn;
[[self delegate] setMouseHoverOnRow:mouseOverRow column:mouseOverColumn];
}
}
}
In my tableView's delegate:
- (void)setMouseHoverOnRow:(int)row column:(int)column {
mouseOverRow = row;
mouseOverColumn = column;
NSRect hoveredCellRect = [tableView
frameOfCellAtColumn:mouseOverColumn row:mouseOverRow];
// Reset all buttons to the unhovered state
NSTableColumn *coreCol = [[tableView tableColumns] objectAtIndex:2];
[[coreCol dataCell] setMouseOver:NO];
NSTableColumn *lockCol = [[tableView tableColumns] objectAtIndex:3];
[[lockCol dataCell] setMouseOver:NO];
if(mouseOverColumn == 2 || mouseOverColumn == 3)
mouseHoveredOnButton = YES;
[tableView setNeedsDisplayInRect:hoveredCellRect];
}
- (void)tableView:(NSTableView *)tableView willDisplayCell:(id)cell
forTableColumn:(NSTableColumn *)tableColumn row:(int)row
{
if(mouseHoveredOnButton) {
[cell setMouseOver:YES];
mouseHoveredOnButton = NO;
}
}
- Matt Ball
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden