Implementing Photoshop-like focus policy

Bill Baxter wbaxter at gmail.com
Fri Jul 6 09:58:07 PDT 2007


On 7/6/07, Vadim Zeitlin <vadim at wxwidgets.org> wrote:
>
> On Sun, 1 Jul 2007 09:33:44 +0900 Bill Baxter <wbaxter at gmail.com> wrote:
>
> BB> The main issue I have right now is that the App key handler gets
> called
> BB> twice with every key event.  For instance if you just stick add a key
> down
> BB> hander in the auidemo's MyApp and try hitting a key, you get two calls
> to
> BB> MyApp::OnKeyDown with the same event.
>
> I tried to reproduce this using this patch:


It doesn't happen in the minimal sample.  I've been poking around and trying
to figure out why and it looks like AUI's manager is the reason.  When you
call SetManagedWindow on the top level frame, the AUI frame manager does
frame->PushEventHandler(this);

Add these two lines to Minimal's MyFrame::MyFrame in addition to your
previous patch and you'll see the two message boxes:

    wxEvtHandler *evt =3D new wxEvtHandler();
    this->PushEventHandler(evt);

Seems like the proper behavior for pushed event handlers would be for only
the last handler to percolate events up beyond the frame it's pushed onto.

I think maybe ProcessEvent in wxEvtHandler could be changed to this:

    [...]
    // Try going down the event handler chain
    if ( GetNextHandler() )
    {
        if ( GetNextHandler()->ProcessEvent(event) )
            return true;
        return false; // <----- NEW ADDITION
    }

    // Finally propagate the event upwards the window chain and/or to the
    // application object as necessary
    return TryParent(event);

And that does indeed seem to fix it in both the modified AUI demo and
modified Minimal.  I don't know what other ramifications it might have, but
other demos seem to work with the change, in particular the Menu and Event
samples which use PushEventHandler seem ok.

Note that It doesn't prevent double calls to App's handlers in the case
where wxApp calls evt.Skip().  But probably App has no business calling
Skip() anyway since it's supposed to be the last stop for events.  I'd half
expect it to go into an infinite loop if you call Skip in the App's event
handler.  That it only gets called one more time is probably a feature.

--bb
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.wxwidgets.org/pipermail/wx-users/attachments/20070707/0e4=
d52bc/attachment.htm


More information about the wx-users mailing list