Event Handlers

The X Toolkit allows applications to catch low level X events occurring in a window owned by a widget. This can be accomplished with a call to xtAddEventHandler/5. This predicate is exactly like the corresponding X Toolkit function, therefore refer to the Xt manual for more information about it. Note that the event mask is represented as a list of event names in ProXT. There is also the xtAddRawEventHandler/5 predicate, which is almost the same as xtAddEventHandler/5 except that it does not affect the widget's event mask. To remove an event handler use xtAddRawEventHandler/5 or xtAddRawEventHandler/5 accordingly.

Following is the first example rewritten in order to utilize event handlers.

     create_button :-
             xtAppInitialize(App,'Demo',[],Shell),
             xmCreatePushButton(Shell,push_button,
                                [xmNwidth(100), xmNheight(100)],Button),
             xtManageChild(Button),
             xtAddEventHandler(Button,[buttonPressMask],false,
                               pressed,'Hello Quintus!'),
             xtRealizeWidget(Shell),
             xtAppMainLoop(App).
     
     pressed(Widget, ClientData, CallData) :-
             write(Widget), nl,
             write(ClientData), nl,
             write(CallData), nl.