Re: How to imitiate mouse move programmatically? [NSApp postEvent:atStart:] does not work...
Re: How to imitiate mouse move programmatically? [NSApp postEvent:atStart:] does not work...
- Subject: Re: How to imitiate mouse move programmatically? [NSApp postEvent:atStart:] does not work...
- From: Oleg Krupnov <email@hidden>
- Date: Tue, 3 Nov 2009 13:39:39 +0200
Thanks Graham,
There are basically two or three custom views of different class in
the window that need refresh. These views are totally custom, which
means I could of course implement the corresponding methods that would
explicitly refresh their state, but because the state depends on the
mouse position, the method would have to query the current mouse
position outside the event loop and then do the same thing as I do in
mouse moved event handler. That's why I thought I could spare on extra
code in all views and just send one fake mouse moved event to whatever
view is hovered, specifying the current mouse coordinate (i.e. no
actual coordinate change).
The lengthy operation is an animation. During the animation, the mouse
moved events are absorbed, so that when it is done, the state of the
views do not correspond to the current mouse position, and a refresh
is needed.
Yes, I always use NSTrackingArea, and I don't use any hacks there. I
expected that the fake mouse moved event that I post would get
dispatched as a normal mouse event and tracked by the tracking area.
Anyway, thanks for your recommendation. Is there any final argument
that would convince me that posting fake mouse moved events is a bad
idea? Some discouragement in the docs, or something?
Oleg.
On Tue, Nov 3, 2009 at 12:07 PM, Graham Cox <email@hidden> wrote:
>
> On 03/11/2009, at 8:48 PM, Oleg Krupnov wrote:
>
>> As I said, I am trying to refresh the state of the view after a
>> lengthy operation is complete.
>
> No disrespect, but you did not say that - this is the first mention of a
> "lengthy operation". How lengthy? What is it?. Not sure why the coyness but
> if you want help you have to be helpful.
>
>
>> By "state" I mean that the item in the
>> view on which the mouse is hovered, should highlight.
>
> Why not just tell the view to sort itself out when the "lengthy operation"
> completes? Just send it a message and implement whatever you need to do to
> fix it up.
>
>
>> Also, if I don't
>> refresh, the view will not respond to the following mouse down event,
>> unless it is preceded with another mouse move event (because the view
>> only respond to clicks if there is a highlighted item).
>
> Well, that doesn't sound right. Are you sure there isn't some other bug
> causing that?
>
>> There are
>> multiple views of different kind
>
> What kind? Are they custom views of your own design? In which case you can
> do whatever you want, you are not constrained by the architecture of
> controls or other built-in views.
>
>
>> in the window, each with its own kind
>> of state. I'd like the currently hovered view to refresh its state, as
>> if it received a regular mouse move event. I thought imititating the
>> mouse move event would be the most straightforward and simple way. Was
>> I wrong?
>
> Hard to be sure without seeing any code, but on the face of it, yes, I think
> this is wrong. You normally don't need to post events to make things happen.
> There is a situation where you might need to post a mouse-up if you are
> implementing your own tracking loop inside a view that expects mouse
> down/move/up events and the mouse up is expected to balance the mouse down
> and your inner tracking loop has already swallowed it, but those cases are
> pretty unusual and it doesn't sound like yours is like that.
>
> How are you doing the hovering? Using NSTrackingArea (or tracking rects) is
> a good solution - trying to trap & dispatch mouse events in a loop is not.
>
> --Graham
>
>
_______________________________________________
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