Next Previous Top Contents Index

Building Applications Using DUIM

5 Adding Callbacks to the Application

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:

1. For each gadget in the GUI, you need to specify which callbacks to use. There are several different types of callback, depending on the type of event for which you want to define behavior.
2. You need to define the callback functions themselves. These are the functions that are invoked when a particular callback type is detected, and are the functions you use to define the correct behavior for your application.

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.

5.1 - Defining the underlying data structures for tasks
5.2 - Specifying a callback in the definition of each gadget
5.3 - Defining the callbacks
5.4 - Enhancing the task list manager

Building Applications Using DUIM - 26 May 1999

Next Previous Top Contents Index