11.2.1 Handling Input Events
Since the callback approach to event handling is the simplest, we'll begin by discussing that approach. the source code
shows an extremely simple drawing program that associates a line drawing function with the XmNinputCallback
resource. Pressing any of the pointer buttons marks the starting point of a line; releasing the button marks the
endpoint. You can only draw straight lines. Even though the default translation table for the DrawingArea widget
selects key events and these events are passed to the callback function, the callback function itself ignores them and
thus key events have no effect.
To demonstrate the complications inherent in using the DrawingArea widget as a manager, the program also displays
a PushButton gadget that clears the window. A single callback function, drawing_area_callback(), uses both
the reason and the event fields of the XmDrawingAreaCallbackStruct to determine whether to draw a line
or to clear the window.
This simple application draws directly into the DrawingArea widget; the contents of its window is not saved
anywhere. The program does not support redrawing, since its purpose is strictly to demonstrate the way input handling
can be managed using the XmNinputCallback. If the window is exposed due to the movement of other windows,
the contents of the window is not redrawn. A more realistic drawing application would need code to handle both
expose and resize actions. The current application simply clears the window on resize to ...