## 2.6 Registering Callbacks and Event Handlers

Callbacks and event handlers are the only means that an application interacts with EZ widgets. When the user acts on a widget, e.g. pressing a CheckButton, the callbacks or the event handlers for the corresponding widget, if any, will be invoked. And hence some work will be done.

We have already used callbacks in our first three examples. In the first example, the program exists when the button is pressed; in the second example, press on different buttons generate different actions, and in the last example, a double click on an DirTree Item cause the corresponding file be loaded into the textWidget.

There are four function lists for each widget.

- A normal callback list.

- A destroy callback list.

- A motion callback list.

- A list of event handlers.

Normal callbacks are invoked when the default action has occured on a widget, e.g., press a push button, a double click on a listbox item or drag a slider button.

Destroy callbacks are invoked at the time a widget is being destroyed. This is useful if your application attaches a complex data structure to a widget, since this is a convenient way to clean up your complex data structure associated with a widget, e.g. free allocated memory.

Motion callbacks are available only for Entry, OptionalEntry, FreeLabel, ListBox, FancyListBox and ListTree widgets. They are invoked whenever the entry changes or the selection of a widget changes or the location of a FreeLabel changes.

Event handlers behave differently from callbacks. An event handler is triggered by the events it handles. User defined event handlers are called before the default event handler. The order in which the event handlers are invoked cannot be sensablly controled when more than one handler exists for a widget and event type. The EZ event dispatcher just calls all the handlers on the handler list, from the beginning to the end. However, a handler may modify the event type to an invalid event type, say, `0`, which disable all handlers after the handler in question, including the default handler.

HTML Documentation Maintainance:`Arturo Espinosa <arturo@nuclecu.unam.mx>`