Re: Document Cursor
Re: Document Cursor
- Subject: Re: Document Cursor
- From: Quincey Morris <email@hidden>
- Date: Wed, 25 Aug 2010 00:30:55 -0700
On Aug 24, 2010, at 15:27, Richard Somers wrote:
> The following code is used to set the cursor when ever the window containing the view becomes key and the cursor is inside the view. I have confirmed that [[NSCursor crosshairCursor] set] is called but nothing happens. The cursor does not change.
I've been staying out of this because I don't have a definitive answer for you. There should be nothing fundamental preventing you from setting the cursor under *approximately* correct conditions. The insoluble problems should only affect the edge cases.
> @implementation MyCustomDocumentView
>
> - (void)windowDidBecomeKeyNotification:(NSNotification *)notification
> {
> if ([notification object] == [self window]) {
> NSPoint point = [[self window] mouseLocationOutsideOfEventStream];
> NSRect frame = [self convertRectToBase:[self frame]];
> BOOL condition = NSMouseInRect(point, frame, NO);
> if (condition) {
> [[NSCursor crosshairCursor] set]; // Called but does not work!
> }
> }
> }
>
> @end
The implication of this is likely that the cursor is being set again after you do it. Have you tried setting a breakpoint on [NSCursor set]? It's tricky to debug, because you don't want application switching to mess up the testing conditions, so you probably need to enable the breakpoint from the floating debugger window, and/or use carefully constructed debugger conditions.
Note that you should be able to figure this out without getting tangled up in the tracking area at all. You might find it simpler to comment out all your tracking area and cursorUpdate code, and just try to get the following intermediate results:
a. Unconditionally set the cursor to a crosshair when your document window opens.
b. Set the cursor to a crosshair when your document window becomes key while the mouse pointer is inside your view. (Or when it becomes main? If there were a key window and a main window, would your custom view be in the main or the key window?)
You're going to have to get (a) to work before (b) can work, and you're going to have to get (b) to work before your tracking area is going to work.
> The following code will change the cursor but only when it enters the tracking area. If the cursor is already inside the area then it does not work. I have tried all the tracking area options. Nothing seems to work.
>
> @implementation MyCustomDocumentView
>
> - (void)awakeFromNib
> {
> NSTrackingAreaOptions options = NSTrackingCursorUpdate | NSTrackingActiveWhenFirstResponder | NSTrackingInVisibleRect;
> _trackingArea = [[NSTrackingArea alloc] initWithRect:[self frame] options:options owner:self userInfo:nil];
> [self addTrackingArea:_trackingArea];
> }
>
> - (void)cursorUpdate:(NSEvent *)event
> {
> [[NSCursor crosshairCursor] set];
> }
>
> @end
The best combination of options is probably 'NSTrackingCursorUpdate | NSTrackingAssumeInside | NSTrackingInVisibleRect'. (Ignore the documentation for NSTrackingAssumeInside -- it's wrong. The only case when you *don't* want to use it is when your tracking area behavior must not start until the mouse pointer makes a true outside-to-inside transition after the tracking area is installed. That's not the situation here. OTOH I'm not entirely sure whether the option affects cursor update events at all.) Don't bother with NSTrackingActiveWhenFirstResponder until after you've everything else working, since it just adds complexity to the conditions.
Incidentally, the "approximately" above comes from the difficulty of testing whether the mouse is inside the tracking area. That's because the relevant events (cursorUpdate, mouseMoved, mouseEntered, mouseExited) are synchronized with the event stream, but there's no way to get the mouse location synchronized with the event stream unless you have an event (which you don't, for example, in your notification code above). But I doubt that's your problem here.
_______________________________________________
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