Re: hey, Cocoa, don't touch that cursor
Re: hey, Cocoa, don't touch that cursor
- Subject: Re: hey, Cocoa, don't touch that cursor
- From: email@hidden
- Date: Tue, 29 Jan 2002 22:14:01 -0800
My window redraws parts of itself periodically. If the user holds down
the
mouse on the window, I set the cursor (using push) and reset it to the
arrow when the user release the mouse (using pop). But if the window
happens to redraw itself while the mouse is being held down, the cursor
is
(prematurely) reset to the arrow at that moment, even though I know
for a
fact that no code of mine said to do so - I haven't popped the cursor.
So I
conclude that Cocoa is resetting the cursor even though I haven't told
it
to. Is this a bug? It sure feels like one. Whether or not it is, anyone
got
a workaround? Thx - m.
As I recall, there is a private method which gets called whenever a
window updates (in the AppKit sense of "update", not necessarily a view
redisplay). That private method calculates the "correct" cursor based
upon the cursor rects in the window and sets it absolutely (wiping out
whatever cursor stack may be in place). This is based upon the implicit
assumption that cursor rects will correctly reflect the application's
desire for the cursor whenever the top of the run loop is reached --
cursor push/pops should all be resolved before the run loop top.
It might be possible to use SelfIntrospector and find the method in
question, override it, etc. However, this sort of patching is quite
dangerous and dependent upon AppKit internals. Not that I haven't done
it, mind you. :->
A better fix would probably be to do what you are doing now using
push/pop using cursor rects instead, if you can. Change the cursor for
your view, or whatever subset of your view, to properly be the cursor
you want. This way if the AppKit decides to recalculate what the cursor
is, which it does from time to time, it will get the correct answer.
Another possible fix would be not to return to the top of the run loop
until you are done with your drag and have popped the cursor.
Ben Haller
Stick Software