At this point, the task list manager still does very little. If you try running the code (as described in Section 3.2 on page 13), and interacting with any of the elements in the GUI (clicking on a button, choosing a menu command, and so on), then only the "not yet implemented" message is displayed. This section shows you how to remedy this situation, by adding callback functions to the task list manager.
Getting the application to respond to mouse events such as clicking on a button or choosing a menu command consists of two things:
In addition, you need to set up the basic data structures that allow you to work with tasks in your application.
At this point, you may be wondering exactly what a callback is, and why they are used to respond to application events, rather than event handlers. If you have developed GUI applications using other development environments, you may be more used to writing event handlers that work for a whole class of objects, and discriminating on which instance of a class to work on at any one time by means of case statements.
Writing event handlers in this way can be cumbersome. It turns out to be much simpler to define a function that works only for a particular instance of a class, and then refer to this function when defining the class instance. This function is what is referred to as a callback. This makes the source code for your application much clearer and easier to write, and the only price you pay is that you have to specify a callback for each gadget when you define the gadget itself.
In fact, DUIM provides a complete protocol for defining and handling events of all descriptions. However, you only need to use this protocol if you are creating new classes of gadgets, for which you need to define the event behavior, or new classes of events (for example, support for different input devices or notification of low resources). If you are just using gadgets, then you only ever need to use callbacks.