I was surprised by some cursor behaviour and whittled down the following code (the only code in an NSTableView subclass):

- (void)updateTrackingAreas {
        NSLog(@"Tracking update");
        for (NSTrackingArea *area in [self trackingAreas]) {
        if ([area owner] == self) {
            [self removeTrackingArea:area];
        }
    }
//NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[self bounds] options:NSTrackingCursorUpdate | NSTrackingActiveAlways owner:self userInfo:nil]; NSTrackingArea *area = [[NSTrackingArea alloc] initWithRect:[self bounds] options:NSTrackingCursorUpdate | NSTrackingActiveInActiveApp owner:self userInfo:nil];
        [self addTrackingArea:area];
}

- (void)cursorUpdate:(NSEvent *)event {
        [[NSCursor openHandCursor] set];
        NSLog(@"Cursor updated");
}

This code correctly sets the cursor to the open hand cursor when the mouse is moved over the table view. I tried both NSTrackingActiveAlways and NSTrackingActiveInActiveApp because of some note in the docs that talks about the interaction of NSTrackingCursorUpdate and NSTrackingActiveAlways - but the behaviour here is the same.

The odd behaviour is that the cursor is reset back to the regular arrowCursor after a few seconds, with the cursor still over the view. At this point I don't know 'who' is doing this or why; nor how to stop it.

The -updateTrackingAreas method is called exactly once in my simple test (I wondered if some change in the state of the tracking areas would reset the cursor state - but evidently it's not as simple as that).

There's a good chance that I'm displaying continued ignorance of Cocoa - but I've been through the docs several times for clues without enlightenment. Surely the system should be able to change the cursor on you without giving you a chance to reassert the cursor you want (even if it does this on some kind of timer to avoid stale cursor states from poorly written application code - or whatever).

Is there a parallel mechanism to the tracking areas here that I should also be interacting with to ensure that my cursor stays set the way I want it?

Cheers

-- Luke




_______________________________________________

Cocoa-dev mailing list ([email protected])

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [email protected]

Reply via email to