Mark Amery
Mark Amery

Reputation: 155024

Does .Skip() on an EVT_TEXT event do anything?

wx event handlers attached with .Bind(...) receive as a parameter an event object with a .Skip() method. Calling .Skip() allows the event's default behaviour to happen; attaching a handler that does not call .Skip() suppresses the default behaviour. For instance, an EVT_CHAR handler that doesn't call .Skip() suppresses the default behaviour of entering the character into the field, thus blocking user input.

How about EVT_TEXT? Does it have any default behaviour? It doesn't seem to - typing into a field with an EVT_TEXT handler appears to behave the same regardless of whether I call .Skip() or not. But is there some edge case or non-obvious effect that's affected by whether I call .Skip(), and which should therefore dictate my choice of whether to call it?

Upvotes: 1

Views: 380

Answers (2)

VZ.
VZ.

Reputation: 22753

Not calling wxEvent::Skip() does 2 related but different things: it prevents the default event handler inside the underlying UI toolkit from from processing it and it also prevents any other handlers of the same event in your own code from processing it.

The first aspect is indeed not important for command events, which typically don't have any default event handlers at the toolkit level. The second one still is, however, especially because command events bubble upwards the window hierarchy by default.

So if you bound some handler to your text control and also happen to have a catch all wxEVT_TEXT handler at the frame level, you can easily see the difference between calling Skip() or not: the frame handler will only get the event if you do call it.

From the practical point of view, you typically do not want to skip command event handlers as they should be processed once and once only. But it's not an absolute interdiction and there are situations when you may still do it, e.g. if your event handler didn't do anything with this particular event.

Upvotes: 1

Igor
Igor

Reputation: 6275

Generally speaking calling Skip() inside the event handler only make sense for non-wxCommandEvent handlers. You can just let the handler finish and you program will do next event iteration.

Since wxEVT_TEXT is wxCommandEvent event calling Skip() does not make much sense.

However not calling Skip() on non-wxCommandEvent is bad and you really should know what you are doing if you omit such call.

Upvotes: 0

Related Questions