From a0221c0818b71737e824bf39093b37ab0c7f8a46 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Tue, 25 Mar 2008 03:17:35 +0000 Subject: [PATCH] simplify the priority selector mouse-over code --- macosx/FileOutlineController.m | 4 +++ macosx/FileOutlineView.h | 4 +-- macosx/FileOutlineView.m | 48 ++++++---------------------------- macosx/FilePriorityCell.h | 4 +-- macosx/FilePriorityCell.m | 11 ++------ 5 files changed, 18 insertions(+), 53 deletions(-) diff --git a/macosx/FileOutlineController.m b/macosx/FileOutlineController.m index 7d924b9ca..8e4ce8516 100644 --- a/macosx/FileOutlineController.m +++ b/macosx/FileOutlineController.m @@ -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; } diff --git a/macosx/FileOutlineView.h b/macosx/FileOutlineView.h index 71300dd7c..f70e7ee39 100644 --- a/macosx/FileOutlineView.h +++ b/macosx/FileOutlineView.h @@ -25,7 +25,6 @@ #import @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 diff --git a/macosx/FileOutlineView.m b/macosx/FileOutlineView.m index 71e41ee71..166aba593 100644 --- a/macosx/FileOutlineView.m +++ b/macosx/FileOutlineView.m @@ -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]) diff --git a/macosx/FilePriorityCell.h b/macosx/FilePriorityCell.h index e76b5ebdc..8d99a937a 100644 --- a/macosx/FilePriorityCell.h +++ b/macosx/FilePriorityCell.h @@ -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 diff --git a/macosx/FilePriorityCell.m b/macosx/FilePriorityCell.m index 6a8d218fe..b523e718d 100644 --- a/macosx/FilePriorityCell.m +++ b/macosx/FilePriorityCell.m @@ -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 -- 2.40.0