simplify the priority selector mouse-over code

This commit is contained in:
Mitchell Livingston 2008-03-25 03:17:35 +00:00
parent 695b6b105d
commit a0221c0818
5 changed files with 18 additions and 53 deletions

View File

@ -25,6 +25,7 @@
#import "FileOutlineController.h"
#import "Torrent.h"
#import "FileOutlineView.h"
#import "FilePriorityCell.h"
#import "NSApplicationAdditions.h"
#define ROW_SMALL_HEIGHT 18.0
@ -117,7 +118,10 @@ typedef enum
if ([identifier isEqualToString: @"Check"])
[cell setEnabled: [fTorrent canChangeDownloadCheckForFiles: [item objectForKey: @"Indexes"]]];
else if ([identifier isEqualToString: @"Priority"])
{
[cell setRepresentedObject: item];
[(FilePriorityCell *)cell setHovered: [NSApp isOnLeopardOrBetter] ? [fOutline hoveredRow] == [fOutline rowForItem: item] : NO];
}
else;
}

View File

@ -25,7 +25,6 @@
#import <Cocoa/Cocoa.h>
@class Torrent;
@class FilePriorityCell;
@class CTGradient;
@interface FileOutlineView : NSOutlineView
@ -35,10 +34,11 @@
CTGradient * fHighPriorityGradient, * fLowPriorityGradient, * fMixedPriorityGradient;
int fMouseRow;
FilePriorityCell * fMouseCell;
}
- (void) setTorrent: (Torrent *) torrent;
- (Torrent *) torrent;
- (int) hoveredRow;
@end

View File

@ -22,8 +22,6 @@
* DEALINGS IN THE SOFTWARE.
*****************************************************************************/
#warning treat hovering the same as in the table?
#import "FileOutlineView.h"
#import "FileNameCell.h"
#import "FilePriorityCell.h"
@ -66,8 +64,6 @@
[fLowPriorityGradient release];
[fMixedPriorityGradient release];
[fMouseCell release];
[super dealloc];
}
@ -132,24 +128,18 @@
}
}
- (int) hoveredRow
{
return fMouseRow;
}
- (void) mouseEntered: (NSEvent *) event
{
NSNumber * row;
if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
{
int rowVal = [row intValue];
FilePriorityCell * cell = (FilePriorityCell *)[self preparedCellAtColumn: [self columnWithIdentifier: @"Priority"] row: rowVal];
if (fMouseCell != cell)
{
[fMouseCell release];
fMouseRow = rowVal;
fMouseCell = [cell copy];
[fMouseCell setControlView: self];
[fMouseCell mouseEntered: event];
[fMouseCell setRepresentedObject: [cell representedObject]];
}
fMouseRow = [row intValue];
[self setNeedsDisplayInRect: [self rectOfRow: fMouseRow]];
}
}
@ -158,33 +148,11 @@
NSNumber * row;
if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
{
FilePriorityCell * cell = (FilePriorityCell *)[self preparedCellAtColumn: [self columnWithIdentifier: @"Priority"]
row: [row intValue]];
[cell setControlView: self];
[cell mouseExited: event];
[fMouseCell release];
fMouseCell = nil;
[self setNeedsDisplayInRect: [self rectOfRow: [row intValue]]];
fMouseRow = -1;
}
}
- (NSCell *) preparedCellAtColumn: (NSInteger) column row: (NSInteger) row
{
if (![self selectedCell] && row == fMouseRow && column == [self columnWithIdentifier: @"Priority"])
return fMouseCell;
else
return [super preparedCellAtColumn: column row: row];
}
- (void) updateCell: (NSCell *) cell
{
if (cell == fMouseCell)
[self setNeedsDisplayInRect: [self frameOfCellAtColumn: [self columnWithIdentifier: @"Priority"] row: fMouseRow]];
else
[super updateCell: cell];
}
- (void) drawRow: (int) row clipRect: (NSRect) clipRect
{
if (![self isRowSelected: row])

View File

@ -32,7 +32,7 @@
- (void) addTrackingAreasForView: (NSView *) controlView inRect: (NSRect) cellFrame withUserInfo: (NSDictionary *) userInfo
mouseLocation: (NSPoint) mouseLocation;
- (void) mouseEntered: (NSEvent *) event;
- (void) mouseExited: (NSEvent *) event;
- (void) setHovered: (BOOL) hovered;
@end

View File

@ -93,16 +93,9 @@
[area release];
}
- (void) mouseEntered: (NSEvent *) event
- (void) setHovered: (BOOL) hovered
{
fHoverRow = YES;
[(NSControl *)[self controlView] updateCell: self];
}
- (void) mouseExited: (NSEvent *) event
{
fHoverRow = NO;
[(NSControl *)[self controlView] updateCell: self];
fHoverRow = hovered;
}
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView