Many applications can implement their entire input processing by adding procedures to widget callback lists and by adding mnemonics and accelerators for menu buttons. Some applications change translations, accelerators, or actions. More rarely, an application needs finer control over event processing. Such an application can register an event handler with the Xt event dispatcher.
An event handler is a procedure that the Xt event dispatcher calls when the application receives events of one or more types. An event handler procedure is of type XtEventHandler. It receives four arguments: the widget for which the event arrived; any client data registered with the event handler; a pointer to the event; and a Boolean return argument telling the Xt dispatch facility whether or not to call the remaining event handlers registered for this event. This argument is initialized to True and should rarely be changed.
An application usually registers an event handler by using the function XtAddEventHandler. The arguments are the widget, an event mask, an indication whether or not the hander should be called for nonmaskable events, the procedure itself, and any client data to be passed to the event handler when it is called. The order in which event handlers are called is undefined when more than one handler exists for a given widget and event type. However, if the application registers the event handler by using XtInsertEventHandler, it can specify that the procedure is to be called either before or after all currently registered event handlers.
Motif requires an application to provide an event handler if it wants to post a PopupMenu on a button press. The call to XtAddEventHandler should specify ButtonPressMask as the event mask and the popup RowColumn as the client data. The event handler should use XmMenuPosition to position the menu at the x and y location of the button press event. It should then manage the RowColumn. If the button press matches the event specified by the RowColumn's XmNmenuPost resource, Motif posts the PopupMenu. See Chapter 6 for more information.