Thanks to your replies, I'm replying to both of them to avoid bifurcating
the thread:
On Wed, 19 Aug 2020 07:36:45 +0000 Stefan Csomor wrote:
SC> I also think that we should do something here, perhaps just some naming
SC> or aptly named parameter values together with an overload might already
SC> help, if we don't come to a more elaborate solution.
SC>
SC> A few comparisons
SC>
SC> In my 4th GL, Omnis
SC>
SC> I have a command "Quit event handler" that has two options "Discard
SC> Event" and "Pass to Next Handler"
But what is the default behaviour? Or do you have to use one of those 2
commands?
SC> In Cocoa
SC>
SC> There is the notion of a responder on an object, it is a subclass of
SC> NSResponder. That's your handler. A responder can have a nextResponder,
SC> this forms the responder chain. You have to override the eventMethods
SC> you are interested in, eg mouseDown:, if you are handling this and you
SC> want to pass it on, you must call [super mouseDown],
This is close to what C++ does (except for ctors and dtors) and has the
advantage that you can call the default handler before, or in the middle,
of your own handling code, instead of only after it. However it has an
important drawback too: I don't think it's universally implementable. E.g.
HTML5 API, discussed below, doesn't seem to provide anything like this.
As another random example, looking at Android UI events documentation
(
https://developer.android.com/guide/topics/ui/ui-events), this doesn't
seem possible there neither. So I don't think we can guarantee such API on
all platforms.
Besides, in my own experience with wx PushEventHandler(), which is rather
next-responder-like, using it often results in unclear and fragile code and
Bind() is much simpler and less error-prone, so I wouldn't really regret
not having anything like this in an event handling API.
SC> In contrast to these so called Event Messages there are also Action
SC> Messages, comparable to our commands
This is another thing I was wondering about: does it really make sense to
distinguish between command events and all the rest? Our experience seems
to show that people expect all events to bubble up
SC> JavaScript
SC>
SC> anyone more fluent please correct me - an Event Handler (which is also
SC> called Event Listener, making the situation of multiple 'handlers' more
SC> obvious to me)
Yes, I agree that from the terminological point of view "listener" is
better than "handler", which is more final. OTOH it makes sense to talk
about the "default handler", but not so much about "default listener". So
even this is not obvious :-(
SC> for an event that usually gets propagated does have to call
SC> stopPropagation on the vent to stop further processing in 'user
SC> handlers'. And there's the concept of 'default' ie built-in handlers,
SC> if you don't want that one to jump in after the user handlers you have
SC> to call preventDefault on the event
One thing to notice is that stopPropagation() "skips" the other handlers
defined in the program, but still allows the default handling to take
place. I think this is useful, but it's not supported by wx currently.
On Fri, 21 Aug 2020 08:35:31 +0200 QuentinC wrote:
Q> In HTML5/DOM/ you have three methods: preventDefault, stopPropagation
Q> and stopImmediatePropagation.
Q> I don't find it super clear what exactly the difference is between the
Q> three.
I think MDN explains it rather clearly. It's interesting that calling
preventDefault() doesn't actually prevent default processing for some
events, as this is something I thought about implementing for some wx
events (e.g. focus ones) too, as you (almost?) always want the default
processing to take place for them. This "almost?" part has prevented me
from doing it, because I couldn't conclusively prove, even to myself, that
there were no cases in which this could be useful. But if we're discussing
backwards-incompatible changes anyhow, this is something I'd definitely
consider doing.
Q> The advantage of return value is that you have to decide something, and
Q> write it explicitely.
Q> Perhaps it would be interesting to return an enum instead of a bool ?
Q> something like CALL_DEFAULT / PROPAGATE / DONE.
One problem with this is that you need to have an extra statement in all
your event handlers. It might not sound like a lot, but if you have many
simple handlers, this gets unnecessarily verbose and it seems like there
ought to be a reasonable default. OTOH having a mandatory "return" is, of
course, more explicit.
Q> Unfortunately this would totally break WX compatibility.
All this discussion is about some new/parallel event system, replacing the
current one. I don't think we can really do anything about the existing API
without subtly (i.e. horribly) breaking tons of existing code.