I've added an NSTrackingArea
to my NSView
because I want a certain rectangular area to show a different cursor. As expected, my view gets a call to it's cursorUpdate:(NSEvent*)
method, but how do I tell whether it's an "enter" or "leave".
- (void)cursorUpdate:(NSEvent *)event {
// Do I push or pop my custom NSCursor?
}
I notice the event.modifierFlags
changes from 8 to 9. But I don't see any public enum constants to test that, so I don't know if I can depend on that. The public enum contains stuff like this, in the higher bits.
typedef NS_OPTIONS(NSUInteger, NSEventModifierFlags) {
NSEventModifierFlagCapsLock = 1 << 16,
NSEventModifierFlagShift = 1 << 17,
...
The tracking area setup code:
NSRect nsRect = ...
NSTrackingAreaOptions options = NSTrackingCursorUpdate | NSTrackingActiveInKeyWindow;
NSTrackingArea *trackingArea = [[NSTrackingArea alloc] initWithRect: nsRect options: options owner: owner userInfo: userInfo];
[myView addTrackingArea: trackingArea];