NSCursor Tracking
NSCursor Tracking
- Subject: NSCursor Tracking
- From: Harriet Kerry <email@hidden>
- Date: Thu, 3 Apr 2003 09:31:47 -0800 (PST)
Hi,
This may turn out to be a stupid question, but I will
try anyway. I have an application under development
which tracks the cursor as it moves over the content
view of my window. I have one of two or three cursors
which I set as the case may be. They have to be set
programmatically; they are not correspondent to
particular static areas of the view.
Everything works wonderfully - up to a point. I create
the necessary cursors at startup, and even hold onto
the arrow cursor to make it easier to work with. Then,
as the mouse moves over the view, I set the cursor
properly as the case may be. And yes, I do make sure I
am getting the mouseMoved message, and yes, my view is
a subclass of NSView, which is why all of this works.
The problem occurs when I go up to the menu bar. If
whatever I invoke on that menu bar results in an alert
panel or any other kind of window (e.g. about box),
then when this additional window is dismissed, my
cursor tracking works correctly again. But if I just
meander up there on the menu bar with nothing
happening with the application window, the cursor
tracking stops, and I need to click on the title bar
of the application window to make it start again.
You might think this is because my window is no longer
main or key - despite the menu bar belonging to the
same application - but this would not seem to be the
case. I have added code to add a tracking rect to the
application (to the subclass of NSView that is the
application window's content view) and I can thereby
get a signal when the mouse enters the view area -
with mouseEntered - and when this happens, I can check
that the application window is indeed the main window
and the key window - and it is.
And despite this, and despite the mouseEntered message
being received, and despite the NSEvent that is sent
being exactly what I would otherwise get for the
mouseMoved message - it does not work. The cursor
tracking for a reason I would love to know is somehow
not working.
So that's the question! I cannot conceive of this
being some sort of programmatic thing, that you have
to counteract detours to the menu bar. Something in
the app itself must be missing. I think I have
described most of what is going on, so that there are
few parts missing from the account.
The last thing I have contemplated - but not yet
tried, as it would seem to be yet another futile wild
goose chase - is subclassing NSCursor itself, so that
this subclass gets the mouseEntered messages instead
of my subclass of NSView. This kind of subclassing,
what I have read of the documentation, is mostly
designed for setting a specific cursor on entering a
specific area. When I do mouse tracking, however, I do
not know what cursor I need - it changes all the time.
The trick I have not tried, but only contemplated, is
to catch the mouseEntered message in a subclass of
NSCursor, and then use the NSEvent instance sent to
set the cursor to whatever I want. The reason I have
not yet tried this is twofold: 1) I am tired - I have
been looking for the answer for days now; and 2) I
really don't think it's that difficult. As one guru
keeps saying, even though none of us remember his
name, "if it's hard to do, you're not doing it right."
Any suggestions - or the final, easy solution - are
most welcome. Much obliged to you all.
HK
Yahoo! Tax Center - File online, calculators, forms, and more
http://tax.yahoo.com
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.