Pluggable Event Handlers

team bbl


You don't have to derive a new class from a window class in order to process events. Instead, you can derive a new class from wxEvtHandler, define the appropriate event table, and then call wxWindow::PushEventHandler to add this object to the window's stack of event handlers. Your new event handler will catch events first; if they are not processed, the next event handler in the stack will be searched, and so on. Use wxWindow::PopEventHandler to pop the topmost event handler off the stack, passing true if you want it to be deleted.

With this method, you can avoid a lot of class derivation and potentially use the same event handler object to handle events from instances of different classes.

Normally, the value returned from wxWindow::GetEventHandler is the window itself, but if you have used PushEventHandler, this will not be the case. If you ever have to call a window's event handler manually, use the GetEvent Handler function to retrieve the window's topmost event handler and use that to call the member function in order to ensure correct processing of the event handler stack.

One use of PushEventHandler is to temporarily or permanently change the behavior of the GUI. For example, you might want to invoke a dialog editor in your application. You can grab all the mouse input for an existing dialog box and its controls, processing events for dragging sizing handles and moving controls, before restoring the dialog's normal mouse behavior. This could be a useful technique for online tutorials, where you take a user through a series of steps and don't want them to diverge from the lesson. Here, you can examine the events coming from buttons and windows and, if acceptable, pass them through to the original event handler using wxEvent::Skip. Events not handled by your event handler will pass through to the window's event table.

    team bbl



    Cross-Platform GUI Programming with wxWidgets
    Cross-Platform GUI Programming with wxWidgets
    ISBN: 0131473816
    EAN: 2147483647
    Year: 2005
    Pages: 262

    flylib.com © 2008-2017.
    If you may any questions please contact us: flylib@qtcs.net