Keyboard focus question.

Bill Baxter wbaxter at gmail.com
Sun Jul 22 20:53:30 PDT 2007


On 7/23/07, Matt Connolly <matt at soundevolution.com.au> wrote:
> I have an app that opens documents. I hav a class MyDocument that is derived
> from wxDocument, where I can attach an event handler like:
>
>
> EVT_KEY_DOWN( MyDocument::OnKeyDown )
> The function receives key events and everything is cool, until I click in
> the window and use the mouse (scrolling the window, for example)
>
> After this point, no key down events are received.
>
> I can't find anything useful in the docs about keyboard focus....

The closest thing I've found to "useful" is the topic overview on
event handling:
http://www.wxwidgets.org/manuals/2.8/wx_eventhandlingoverview.html#eventhandlingoverview

> I thought that events that weren't handled by windows were propogated to
> their parents, and that a top-level-window of
>  wxDocMDIChildFrame always propogated events to the document instance....

Nope.  Read that topic overview.  Propagation only happens for command
events.  I personally thing it should apply to keyboard events too,
having used other toolkits that worked that way, but that's not the
way it works in wx.

There may be something special for this case in the MDI framework.  I
don't know the MDI framework very well though.

There are a few things you can do about it.  For instance all events
that aren't handled eventually go to your App, so you can add a
handler there.  I think there are also tricks you can do like have the
parent where you want to handle the key do some dynamic binding of the
events in the children you want to monitor.  Another option I think is
to have the parent push an event handler on all the children you want
to get events from.

Hopefully that gives you some directions in which to look till someone
has a more authoritative response for you.

--bb




More information about the wx-users mailing list