Tracking Area resets to view's bounds
Tracking Area resets to view's bounds
- Subject: Tracking Area resets to view's bounds
- From: Jim Thomason <email@hidden>
- Date: Tue, 28 Sep 2010 13:34:38 -0500
I'm utterly confused by what I thought would be something simple.
I have a custom view that I want to establish a few tracking areas
for. So I go and create several NSTrackingAreas and add them to the
view. All looks well. But later on, when my mouse events fire off,
they're associated with the ENTIRE view, not just my tracking area.
Even more bizarre, the tracking area at the memory address I
originally created has had its associated rect adjusted to be the
view.
I've boiled it down to a trivial test case.
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
//this one ends up with a tracking area encompassing the entire view
[self addTrackingArea:
[[[NSTrackingArea alloc]
initWithRect:NSMakeRect(100, 100, 50, 50)
options:NSTrackingActiveInKeyWindow
| NSTrackingMouseEnteredAndExited |
NSTrackingMouseMoved | NSTrackingInVisibleRect owner:self userInfo:nil
] autorelease]
];
//this one works as expected
[self addTrackingRect:NSMakeRect(100,100,50,50) owner:self
userData:nil assumeInside:NO];
NSLog(@"HAS TRACKING AREAS %@", [self trackingAreas]);
}
return self;
}
- (void)mouseEntered:(NSEvent *)theEvent {
NSLog(@"MOUSE ENTERED IN %@", [theEvent trackingArea]);return;
}
If I do it "new-style" with addTrackingArea, then the entire view
becomes my tracking area. If I do it "old-style" with addTrackingRect,
it behaves as I would've expected. For example, doing it with tracking
areas:
2010-09-28 13:26:41.564 TrackingAreaTest[32602:a0f] HAS TRACKING AREAS (
"NSTrackingArea 0x100621760: rect={{100, 100}, {50, 50}},...)
2010-09-28 13:26:43.122 TrackingAreaTest[32602:a0f] MOUSE ENTERED IN
NSTrackingArea 0x100621760: rect={{0, 0}, {400, 400}}, ...
2010-09-28 13:26:43.539 TrackingAreaTest[32602:a0f] MOUSE EXITED FROM
NSTrackingArea 0x100621760: rect={{0, 0}, {400, 400}}, ...
Same tracking area (or same memory address, at least), but different
rectangles. Only difference I can see is that the first one (called
right after I set it) has extra flags of "pendingInstall notInstalled
disabled". The one I get from mouseEntered is "installed enabled".
I'm completely stumped. Surely I'm doing something horribly stupid,
but bugger all if I know what it is. What do I need to do to make it
work?
Sample code at:
http://www.prototypesite.net/trackingareatest.zip
-Jim.....
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden