Re: Document Cursor
Re: Document Cursor
- Subject: Re: Document Cursor
- From: Richard Somers <email@hidden>
- Date: Tue, 24 Aug 2010 16:27:49 -0600
On Aug 24, 2010, at 11:38 AM, John C. Randolph wrote:
You can just check where the cursor is when you open your document
and send [[NSCursor IBeamCursor] push] yourself if it's inside your
view.
This does not work for me.
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.
@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 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
There are lots of applications that when a window is activated by a
mouse click with the mouse over a tracking area, the cursor will
change. You do not need to exit and re-enter the tracking area. This
should be elementary stuff. But I can't figure out how to do it.
--Richard
_______________________________________________
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