experiment with hilighting the buttons on rollover (10.5-only, and still incomplete)
This commit is contained in:
parent
7933bc4d9e
commit
0a7d8cd3a5
|
@ -102,6 +102,8 @@
|
|||
|
||||
- (void) updateTrackingAreas
|
||||
{
|
||||
[super updateTrackingAreas];
|
||||
|
||||
NSEnumerator * enumerator = [[self trackingAreas] objectEnumerator];
|
||||
NSTrackingArea * area;
|
||||
while ((area = [enumerator nextObject]))
|
||||
|
@ -167,7 +169,7 @@
|
|||
|
||||
- (NSCell *) preparedCellAtColumn: (NSInteger) column row: (NSInteger) row
|
||||
{
|
||||
if (row == fMouseRow && column == [self columnWithIdentifier: @"Priority"])
|
||||
if (![self selectedCell] && row == fMouseRow && column == [self columnWithIdentifier: @"Priority"])
|
||||
return fMouseCell;
|
||||
else
|
||||
return [super preparedCellAtColumn: column row: row];
|
||||
|
|
|
@ -30,7 +30,7 @@
|
|||
BOOL fHoverRow;
|
||||
}
|
||||
|
||||
- (void) addTrackingAreasForView:( NSView *) controlView inRect: (NSRect) cellFrame withUserInfo: (NSDictionary *) userInfo
|
||||
- (void) addTrackingAreasForView: (NSView *) controlView inRect: (NSRect) cellFrame withUserInfo: (NSDictionary *) userInfo
|
||||
mouseLocation: (NSPoint) mouseLocation;
|
||||
- (void) mouseEntered: (NSEvent *) event;
|
||||
- (void) mouseExited: (NSEvent *) event;
|
||||
|
|
|
@ -85,11 +85,11 @@
|
|||
[controlView reloadData];
|
||||
}
|
||||
|
||||
- (void) addTrackingAreasForView:( NSView *) controlView inRect: (NSRect) cellFrame withUserInfo: (NSDictionary *) userInfo
|
||||
- (void) addTrackingAreasForView: (NSView *) controlView inRect: (NSRect) cellFrame withUserInfo: (NSDictionary *) userInfo
|
||||
mouseLocation: (NSPoint) mouseLocation
|
||||
{
|
||||
NSTrackingAreaOptions options = NSTrackingEnabledDuringMouseDrag | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways;
|
||||
|
||||
|
||||
if (NSMouseInRect(mouseLocation, cellFrame, [controlView isFlipped]))
|
||||
{
|
||||
options |= NSTrackingAssumeInside;
|
||||
|
|
|
@ -24,14 +24,14 @@
|
|||
|
||||
@class CTGradient;
|
||||
|
||||
@interface TorrentCell : NSCell
|
||||
@interface TorrentCell : NSActionCell
|
||||
{
|
||||
NSUserDefaults * fDefaults;
|
||||
NSImage * fErrorImage;
|
||||
|
||||
NSMutableDictionary * fTitleAttributes, * fStatusAttributes;
|
||||
|
||||
BOOL fMouseDownControlButton, fMouseDownRevealButton;
|
||||
BOOL fMouseDownControlButton, fMouseDownRevealButton, fHoverControl, fHoverReveal;
|
||||
|
||||
NSColor * fBarOverlayColor;
|
||||
CTGradient * fWhiteGradient, * fGrayGradient, * fLightGrayGradient, * fBlueGradient, * fDarkBlueGradient,
|
||||
|
@ -54,4 +54,9 @@
|
|||
- (NSRect) revealButtonRectForBounds: (NSRect) bounds;
|
||||
- (NSRect) actionButtonRectForBounds: (NSRect) bounds;
|
||||
|
||||
- (void) addTrackingAreasForView: (NSView *) controlView inRect: (NSRect) cellFrame withUserInfo: (NSDictionary *) userInfo
|
||||
mouseLocation: (NSPoint) mouseLocation;
|
||||
- (void) mouseEntered: (NSEvent *) event;
|
||||
- (void) mouseExited: (NSEvent *) event;
|
||||
|
||||
@end
|
||||
|
|
|
@ -345,6 +345,65 @@
|
|||
return YES;
|
||||
}
|
||||
|
||||
- (void) addTrackingAreasForView: (NSView *) controlView inRect: (NSRect) cellFrame withUserInfo: (NSDictionary *) userInfo
|
||||
mouseLocation: (NSPoint) mouseLocation
|
||||
{
|
||||
NSTrackingAreaOptions options = NSTrackingEnabledDuringMouseDrag | NSTrackingMouseEnteredAndExited | NSTrackingActiveAlways;
|
||||
|
||||
//control button
|
||||
NSRect controlButtonRect = [self controlButtonRectForBounds: cellFrame];
|
||||
NSTrackingAreaOptions controlOptions = options;
|
||||
if (NSMouseInRect(mouseLocation, controlButtonRect, [controlView isFlipped]))
|
||||
{
|
||||
controlOptions |= NSTrackingAssumeInside;
|
||||
[controlView setNeedsDisplayInRect: controlButtonRect];
|
||||
}
|
||||
|
||||
NSMutableDictionary * controlInfo = [userInfo mutableCopy];
|
||||
[controlInfo setObject: @"Control" forKey: @"Type"];
|
||||
NSTrackingArea * area = [[NSTrackingArea alloc] initWithRect: controlButtonRect options: controlOptions owner: controlView
|
||||
userInfo: controlInfo];
|
||||
[controlView addTrackingArea: area];
|
||||
[controlInfo release];
|
||||
[area release];
|
||||
|
||||
//reveal button
|
||||
NSRect revealButtonRect = [self revealButtonRectForBounds: cellFrame];
|
||||
NSTrackingAreaOptions revealOptions = options;
|
||||
if (NSMouseInRect(mouseLocation, revealButtonRect, [controlView isFlipped]))
|
||||
{
|
||||
revealOptions |= NSTrackingAssumeInside;
|
||||
[controlView setNeedsDisplayInRect: revealButtonRect];
|
||||
}
|
||||
|
||||
NSMutableDictionary * revealInfo = [userInfo mutableCopy];
|
||||
[revealInfo setObject: @"Reveal" forKey: @"Type"];
|
||||
area = [[NSTrackingArea alloc] initWithRect: revealButtonRect options: revealOptions owner: controlView userInfo: revealInfo];
|
||||
[controlView addTrackingArea: area];
|
||||
[revealInfo release];
|
||||
[area release];
|
||||
}
|
||||
|
||||
- (void) mouseEntered: (NSEvent *) event
|
||||
{
|
||||
NSDictionary * userInfo = [event userData];
|
||||
|
||||
if ([[userInfo objectForKey: @"Type"] isEqualToString: @"Control"])
|
||||
fHoverControl = YES;
|
||||
else
|
||||
fHoverReveal = YES;
|
||||
|
||||
[(NSControl *)[self controlView] updateCell: self];
|
||||
}
|
||||
|
||||
- (void) mouseExited: (NSEvent *) event
|
||||
{
|
||||
fHoverControl = NO;
|
||||
fHoverReveal = NO;
|
||||
|
||||
[(NSControl *)[self controlView] updateCell: self];
|
||||
}
|
||||
|
||||
- (void) drawWithFrame: (NSRect) cellFrame inView: (NSView *) controlView
|
||||
{
|
||||
[super drawWithFrame: cellFrame inView: controlView];
|
||||
|
@ -431,8 +490,9 @@
|
|||
//bar
|
||||
[self drawBar: [self barRectForBounds: cellFrame]];
|
||||
|
||||
#warning get hover images
|
||||
//control button
|
||||
NSString * controlImageSuffix = fMouseDownControlButton ? @"On.png" : @"Off.png";
|
||||
NSString * controlImageSuffix = fMouseDownControlButton || fHoverControl ? @"On.png" : @"Off.png";
|
||||
NSImage * controlImage;
|
||||
if ([torrent isActive])
|
||||
controlImage = [NSImage imageNamed: [@"Pause" stringByAppendingString: controlImageSuffix]];
|
||||
|
@ -450,7 +510,8 @@
|
|||
fraction: 1.0];
|
||||
|
||||
//reveal button
|
||||
NSImage * revealImage = fMouseDownRevealButton ? [NSImage imageNamed: @"RevealOn.png"] : [NSImage imageNamed: @"RevealOff.png"];
|
||||
NSString * revealImageSuffix = fMouseDownRevealButton || fHoverReveal ? @"On.png" : @"Off.png";
|
||||
NSImage * revealImage = [NSImage imageNamed: [@"Reveal" stringByAppendingString: revealImageSuffix]];
|
||||
[revealImage setFlipped: YES];
|
||||
[revealImage drawInRect: [self revealButtonRectForBounds: cellFrame] fromRect: NSZeroRect operation: NSCompositeSourceOver
|
||||
fraction: 1.0];
|
||||
|
|
|
@ -26,6 +26,8 @@
|
|||
#import <transmission.h>
|
||||
#import <Controller.h>
|
||||
|
||||
@class TorrentCell;
|
||||
|
||||
@interface TorrentTableView : NSTableView
|
||||
{
|
||||
IBOutlet Controller * fController;
|
||||
|
@ -35,6 +37,9 @@
|
|||
|
||||
IBOutlet NSMenu * fContextRow, * fContextNoRow;
|
||||
|
||||
int fMouseRow;
|
||||
TorrentCell * fMouseCell;
|
||||
|
||||
NSMutableArray * fKeyStrokes;
|
||||
|
||||
IBOutlet NSMenu * fActionMenu, * fUploadMenu, * fDownloadMenu, * fRatioMenu;
|
||||
|
|
|
@ -35,6 +35,8 @@
|
|||
|
||||
@interface TorrentTableView (Private)
|
||||
|
||||
/*- (BOOL) pointInControlRect: (NSPoint) point;
|
||||
- (BOOL) pointInRevealRect: (NSPoint) point;*/
|
||||
- (BOOL) pointInActionRect: (NSPoint) point;
|
||||
|
||||
- (BOOL) pointInIconRect: (NSPoint) point;
|
||||
|
@ -52,6 +54,8 @@
|
|||
{
|
||||
fDefaults = [NSUserDefaults standardUserDefaults];
|
||||
|
||||
fMouseRow = -1;
|
||||
|
||||
[self setDelegate: self];
|
||||
}
|
||||
|
||||
|
@ -60,6 +64,8 @@
|
|||
|
||||
- (void) dealloc
|
||||
{
|
||||
[fMouseCell release];
|
||||
|
||||
[fKeyStrokes release];
|
||||
[fMenuTorrent release];
|
||||
|
||||
|
@ -81,6 +87,89 @@
|
|||
return [[fTorrents objectAtIndex: row] name];
|
||||
}
|
||||
|
||||
- (void) updateTrackingAreas
|
||||
{
|
||||
[super updateTrackingAreas];
|
||||
|
||||
NSEnumerator * enumerator = [[self trackingAreas] objectEnumerator];
|
||||
NSTrackingArea * area;
|
||||
while ((area = [enumerator nextObject]))
|
||||
{
|
||||
if ([area owner] == self && [[area userInfo] objectForKey: @"Row"])
|
||||
[self removeTrackingArea: area];
|
||||
}
|
||||
|
||||
NSRange visibleRows = [self rowsInRect: [self visibleRect]];
|
||||
if (visibleRows.length == 0)
|
||||
return;
|
||||
|
||||
int col = [self columnWithIdentifier: @"Torrent"];
|
||||
NSPoint mouseLocation = [self convertPoint: [[self window] convertScreenToBase: [NSEvent mouseLocation]] fromView: nil];
|
||||
|
||||
int row;
|
||||
for (row = visibleRows.location; row < NSMaxRange(visibleRows); row++)
|
||||
{
|
||||
TorrentCell * cell = (TorrentCell *)[self preparedCellAtColumn: col row: row];
|
||||
|
||||
NSDictionary * userInfo = [NSDictionary dictionaryWithObject: [NSNumber numberWithInt: row] forKey: @"Row"];
|
||||
[cell addTrackingAreasForView: self inRect: [self frameOfCellAtColumn: col row: row] withUserInfo: userInfo
|
||||
mouseLocation: mouseLocation];
|
||||
}
|
||||
}
|
||||
|
||||
- (void) mouseEntered: (NSEvent *) event
|
||||
{
|
||||
NSNumber * row;
|
||||
if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
|
||||
{
|
||||
int rowVal = [row intValue];
|
||||
TorrentCell * cell = (TorrentCell *)[self preparedCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: rowVal];
|
||||
if (fMouseCell != cell)
|
||||
{
|
||||
[fMouseCell release];
|
||||
|
||||
fMouseRow = rowVal;
|
||||
fMouseCell = [cell copy];
|
||||
|
||||
[fMouseCell setRepresentedObject: [fTorrents objectAtIndex: rowVal]];
|
||||
[fMouseCell setControlView: self];
|
||||
[fMouseCell mouseEntered: event];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void) mouseExited: (NSEvent *) event
|
||||
{
|
||||
NSNumber * row;
|
||||
if ((row = [(NSDictionary *)[event userData] objectForKey: @"Row"]))
|
||||
{
|
||||
TorrentCell * cell = (TorrentCell *)[self preparedCellAtColumn: [self columnWithIdentifier: @"Torrent"]
|
||||
row: [row intValue]];
|
||||
[cell setControlView: self];
|
||||
[cell mouseExited: event];
|
||||
|
||||
[fMouseCell release];
|
||||
fMouseCell = nil;
|
||||
fMouseRow = -1;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSCell *) preparedCellAtColumn: (NSInteger) column row: (NSInteger) row
|
||||
{
|
||||
if (![self selectedCell] && row == fMouseRow && column == [self columnWithIdentifier: @"Torrent"])
|
||||
return fMouseCell;
|
||||
else
|
||||
return [super preparedCellAtColumn: column row: row];
|
||||
}
|
||||
|
||||
- (void) updateCell: (NSCell *) cell
|
||||
{
|
||||
if (cell == fMouseCell)
|
||||
[self setNeedsDisplayInRect: [self frameOfCellAtColumn: [self columnWithIdentifier: @"Torrent"] row: fMouseRow]];
|
||||
else
|
||||
[super updateCell: cell];
|
||||
}
|
||||
|
||||
- (void) mouseDown: (NSEvent *) event
|
||||
{
|
||||
[super mouseDown: event];
|
||||
|
@ -471,6 +560,26 @@
|
|||
|
||||
@implementation TorrentTableView (Private)
|
||||
|
||||
/*- (BOOL) pointInControlRect: (NSPoint) point
|
||||
{
|
||||
int row = [self rowAtPoint: point];
|
||||
if (row < 0)
|
||||
return NO;
|
||||
|
||||
TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
|
||||
return NSPointInRect(point, [cell controlButtonRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
|
||||
}
|
||||
|
||||
- (BOOL) pointInRevealRect: (NSPoint) point
|
||||
{
|
||||
int row = [self rowAtPoint: point];
|
||||
if (row < 0)
|
||||
return NO;
|
||||
|
||||
TorrentCell * cell = [[self tableColumnWithIdentifier: @"Torrent"] dataCell];
|
||||
return NSPointInRect(point, [cell revealButtonRectForBounds: [self frameOfCellAtColumn: 0 row: row]]);
|
||||
}*/
|
||||
|
||||
- (BOOL) pointInActionRect: (NSPoint) point
|
||||
{
|
||||
int row = [self rowAtPoint: point];
|
||||
|
|
Loading…
Reference in New Issue