• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: How to correctly control cursor???
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to correctly control cursor???


  • Subject: Re: How to correctly control cursor???
  • From: Jiri Volejnik <email@hidden>
  • Date: Sat, 6 Nov 2004 21:57:20 +0100

I don't see any way to get correct cursor behavior except to manage setting
the cursor within my window controller. I have to keep some state info about
which control is currently entered, so that on mouseEntered I know whether
mouseExited has already been called and can account for the exit if not, and
on mouseExited I know whether the exit was already taken into account by
handling an earlier enter event. Is there a better way?

I'm successfully using the following simple techniqe for managing graphical tools/selection cursors in my NSView subclass. I have no problems with this solution.


I have the only one cursor rectangle for the view, and in every moment it represents currently visible area of the view:

-(void)resetCursorRects
{
	[self addCursorRect:[self visibleRect] cursor: mCursor]];
}

Whenever I need to change the cursor, I enforce calling this method by calling invalidateCursorRectsForView:.
In fact, there are only two places in the code where I have to do it - in mouseMoved: and in flagsChanged:


-(void)mouseMoved:(NSEvent*)e
{
	// ...
	[self updateCursor:e];
	// ...
}

-(void)flagsChanged:(NSEvent*)e
{
	// ...
	[self updateCursor:e];
	// ...
}

In this method I choose an appropriate cursor - I examine mouse coordinates and key modifiers for this purpose. mCursor is a member variable of the view:

-(void)updateCursor:(NSEvent*)e
{
	mCursor  = ...
	[[self window] invalidateCursorRectsForView:self];
}

Unfortunately, the event delivered to flagsChanged: does not contain mouse coordinates. As I need them to find out proper cursor, I cannot simply pass the original event but I have to make a new one combining data from the original event and from NSWindow's mouseLocationOutsideOfEventStream: method. So my flagsChanged: looks actually like this:

-(void)flagsChanged:(NSEvent*)e
{
	NSEvent* f = [NSEvent keyEventWithType:[e type]
		location:[[self window] mouseLocationOutsideOfEventStream]
		modifierFlags:[e modifierFlags] timestamp:[e timestamp]
		windowNumber:[e windowNumber] context:[e context]
		characters:@"" charactersIgnoringModifiers:@""
		isARepeat:NO keyCode:[e keyCode]];
	[self updateCursor:f];
}

Last, but not least:
mouseMoved has not been called for me even when I have enabled it somewhere as recommended. So I had to use a little workaround - to subclass my window and to override senEvent. If you know better solution, tell me, please:


-(void)sendEvent:(NSEvent*) event
{
	[super sendEvent:event];

	if (NSMouseMoved == [event type]) {
		NSView* view = [[self contentView]
			hitTest:[event locationInWindow]];
		[view mouseMoved:event];
	}
}

I hope it helps...

-- Jirka

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


  • Prev by Date: Re: cannot find method
  • Next by Date: Help with window/subview's colliding on resize problem
  • Previous by thread: Re: How to correctly control cursor???
  • Next by thread: Changing colour of null placeholder string (don't want grey)
  • Index(es):
    • Date
    • Thread