UserInputEvent wasHandled flag

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

UserInputEvent wasHandled flag

Chris Muller-5
In Morph>>#handleMouseDown:, it sets the wasHandled: flag of the
incoming Event to true.

Isn't it more appropriate for wasHandled: to be set by the code that
actually _handles_ the event?  i.e., in #mouseDown:?

In my overridden mouseDown:, I have several code paths that may or may
not choose to handle the event.  The logical approach seemed to be for
each to simply checked #wasHandled and, if not, decide whether it
wants to handle it and, if so, set wasHandled: true, so none of the
subsequent possibilities will attempt to handle it.

Reply | Threaded
Open this post in threaded view
|

Re: UserInputEvent wasHandled flag

Andreas.Raab
On 7/28/2010 2:14 PM, Chris Muller wrote:
> In Morph>>#handleMouseDown:, it sets the wasHandled: flag of the
> incoming Event to true.
>
> Isn't it more appropriate for wasHandled: to be set by the code that
> actually _handles_ the event?  i.e., in #mouseDown:?

It would be *very* error-prone if every mouseDown: handler had to mark
the event explicitly as handled. The common case is that if you request
to handle the event via #handlesMouseDown: then the assumption is that
you will indeed handle it, and only if for some reason you decide that
you need to reject it halfways through the handler you would explicit
reset the handled flag.

> In my overridden mouseDown:, I have several code paths that may or may
> not choose to handle the event.  The logical approach seemed to be for
> each to simply checked #wasHandled and, if not, decide whether it
> wants to handle it and, if so, set wasHandled: true, so none of the
> subsequent possibilities will attempt to handle it.

You can still do that by initially resetting the wasHandled flag before
going through your handler. However, do keep in mind that the flag isn't
a "user flag" but rather that the flag will be used to determine if the
event should instead be handled by one of your parent morphs. If that
isn't the semantics you're trying to implement you should probably leave
that flag alone.

Cheers,
   - Andreas