Browse files

rollover test

  • Loading branch information...
1 parent c7aec4e commit e21bd2a32ee7fca5fb978c8cf7dfc780803e5280 @markhuot committed Jul 14, 2011
Showing with 81 additions and 8 deletions.
  1. +11 −1 src/MHOpenFiles.m
  2. +4 −1 src/MHOutlineView.h
  3. +66 −6 src/MHOutlineView.m
View
12 src/MHOpenFiles.m
@@ -6,6 +6,7 @@
// Copyright 2011 Home. All rights reserved.
//
+#import "MHOutlineView.h"
#import "MHOpenFiles.h"
@implementation MHOpenFiles
@@ -152,8 +153,17 @@ - (id)outlineView:(NSOutlineView *)outlineView objectValueForTableColumn:(NSTabl
return [url lastPathComponent];
}
-- (void)outlineView:(NSOutlineView *)outlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
+- (void)outlineView:(MHOutlineView *)theOutlineView willDisplayCell:(id)cell forTableColumn:(NSTableColumn *)tableColumn item:(id)item
{
+
+ //NSInteger rowIndex = [theOutlineView rowForItem:item];
+
+ //if ([theOutlineView mouseOverRow] == rowIndex) {
+ // NSLog(@"%d could be highlighted", rowIndex);
+ //} else {
+ // NSLog(@"%d shouldn't be highlighted", rowIndex);
+ //}
+
if (item == @"WORKSPACE")
{
[cell setImage:nil];
View
5 src/MHOutlineView.h
@@ -10,7 +10,10 @@
@interface MHOutlineView : NSOutlineView {
-
+ NSTrackingRectTag trackingTag;
+ BOOL mouseOverView;
+ int mouseOverRow;
+ int lastOverRow;
}
@end
View
72 src/MHOutlineView.m
@@ -11,17 +11,25 @@
@implementation MHOutlineView
-- (id)init
+- (id)initWithFrame:(NSRect)frameRect
{
- self = [super init];
+ self = [super initWithFrame:frameRect];
if (self) {
- //[[self window] makeFirstResponder:self];
- //[self addTrackingRect:NSMakeRect(0, 0, 500, 500) owner:self userData:nil assumeInside:NO];
+
}
-
return self;
}
+- (void)awakeFromNib
+{
+ NSLog(@"%@", [self window]);
+ [[self window] setAcceptsMouseMovedEvents:YES];
+ trackingTag = [self addTrackingRect:[self frame] owner:self userData:nil assumeInside:NO];
+ mouseOverView = NO;
+ mouseOverRow = -1;
+ lastOverRow = -1;
+}
+
- (NSRect)frameOfCellAtColumn:(NSInteger)column row:(NSInteger)row
{
NSRect rc = [super frameOfCellAtColumn:column row:row];
@@ -36,9 +44,61 @@ - (NSRect)frameOfCellAtColumn:(NSInteger)column row:(NSInteger)row
return rc;
}
+- (void)mouseEntered:(NSEvent*)theEvent
+{
+ NSLog(@"entered.");
+ mouseOverView = YES;
+}
+
+- (void)mouseMoved:(NSEvent*)theEvent
+{
+ id myDelegate = [self delegate];
+
+ if (!myDelegate)
+ return; // No delegate, no need to track the mouse.
+ if (![myDelegate respondsToSelector:@selector(tableView:willDisplayCell:forTableColumn:row:)])
+ return; // If the delegate doesn't modify the drawing, don't track.
+
+ if (mouseOverView) {
+ mouseOverRow = [self rowAtPoint:[self convertPoint:[theEvent locationInWindow] fromView:nil]];
+
+ if (lastOverRow == mouseOverRow)
+ return;
+ else {
+ [self setNeedsDisplayInRect:[self rectOfRow:lastOverRow]];
+ lastOverRow = mouseOverRow;
+ }
+
+ [self setNeedsDisplayInRect:[self rectOfRow:mouseOverRow]];
+ }
+}
+
+- (void)mouseExited:(NSEvent *)theEvent
+{
+ NSLog(@"exited.");
+ mouseOverView = NO;
+ [self setNeedsDisplayInRect:[self rectOfRow:mouseOverRow]];
+ mouseOverRow = -1;
+ lastOverRow = -1;
+}
+
+- (int)mouseOverRow
+{
+ return mouseOverRow;
+}
+
+- (void)viewDidEndLiveResize
+{
+ [super viewDidEndLiveResize];
+
+ [self removeTrackingRect:trackingTag];
+ trackingTag = [self addTrackingRect:[self frame] owner:self userData:nil assumeInside:NO];
+}
+
- (void)dealloc
{
- [super dealloc];
+ [self removeTrackingRect:trackingTag];
+ [super dealloc];
}
@end

0 comments on commit e21bd2a

Please sign in to comment.