Re: Document Cursor
Re: Document Cursor
- Subject: Re: Document Cursor
- From: "John C. Randolph" <email@hidden>
- Date: Wed, 25 Aug 2010 12:41:46 -0700
On Aug 25, 2010, at 12:30 PM, Richard Somers wrote:
> On Aug 25, 2010, at 1:30 AM, Quincey Morris wrote:
>
>>> @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.
>
> I checked this with a breakpoint. When a window become key the cursor is set. So setting a custom cursor using this approach will never work. This also explains why setting the cursor in initWithFrame: or awakeFromNib of a NSView object also will not work.
Sounds like a job for delayed messaging.
Change the code above to:
- (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] performSelector:@selector(set) withObject:nil afterDelay:0];
}
}
}
That will send a -set message the next time through the event loop.
-jcr
_______________________________________________
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