Confusion over wxFocusEvent

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
wonkey_monkey
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sun May 26, 2019 8:10 pm

Confusion over wxFocusEvent

Post by wonkey_monkey »

I'm just looking into the events which can be handled when a window loses or gains focus. When my window gains focus, it receives an EVT_SET_FOCUS, and the value of event.GetWindow() is 0.

When the window loses focus, it receives an EVT_KILL_FOCUS, and the value of event.GetWindow().

So far, so good. But while my window does not have focus (and seemingly this is because I'm also handling EVT_MOTION - if I disable that, the following problem does not occur), moving my pointer over the window causes the window to receive, in order, and EVT_SET_FOCUS (GetWindow() == 0), an EVT_KILL_FOCUS (GetWindow() == some high integer), and then EVT_SET_FOCUS (GetWindow() == some high integer).

Some new behaviour I want to implement can probably be made to work simply by looking for EVT_KILL_FOCUS, and checking if GetWindow() == 0, but I was wondering if someone could explain the behaviour I'm seeing. Why does handling EVT_MOTION seem to make the window momentarily take focus, and why does it also receive a focus event for some other window?

To reiterate:

1) When not handling EVT_MOTION, no spurious focus events are fired.
2) When handling EVT_MOTION, mousing over the window (for the first time after losing focus only) causes the window to receive the following:

EVT_SET_FOCUS (GetWindow() == 0, which is what it equals when receiving legit EVT_SET_FOCUS events)
EVT_KILL_FOCUS (GetWIndow() == an integer)
EVT_SET_FOCUS (GetWIndow() == same integer as the EVT_KILL_FOCUS event)
User avatar
doublemax
Moderator
Moderator
Posts: 19160
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: Confusion over wxFocusEvent

Post by doublemax »

Which platform?
What are you doing in the EVT_MOTION handler?
Do you call event.Skip()? If not, does adding it change the behavior?
Use the source, Luke!
wonkey_monkey
Earned a small fee
Earned a small fee
Posts: 22
Joined: Sun May 26, 2019 8:10 pm

Re: Confusion over wxFocusEvent

Post by wonkey_monkey »

Derp... I was calling event.Skip(), but I was also calling SetFocus() for some reason. Sorry! Now working as expected.
Post Reply