21.6 Defining the callbacks
This section shows you how to create the callback functions you need to define in order to complete the working example.
In an Editor tool, choose
File > New
to create a new file.
File > Save
to save the file. Save it in the same directory you saved
ib-example.lisp, and call this new file
In the editor, specify the package for the callback definitions by typing the following into the
Enter the function definitions given in the rest of this section.
File > Save
to save the file when you have entered all the function definitions.
The functions that you need to define in this file are divided into the following categories:
Callbacks to update the display pane.
Callbacks to display data in a dialog.
Callbacks for menu items.
Other miscellaneous functions.
21.6.1 Callbacks to update the display pane
One main function,
update-selection, serves to update the display pane whenever selections are made in the graph pane or the list panel.
(defun update-selection (type data interface)
(setf (capi:display-pane-text (selection-reader interface))
(format nil "~A ~A" data type)))
The following three functions are the callbacks specified whenever a select, retract or extend action is performed in either the list panel or the graph pane. Each function is named according to the type of callback it is used for, and it simply calls
update-selection with an additional argument denoting the callback type.
(defun update-selection-select (&rest args)
(apply 'update-selection "selected" args))
(defun update-selection-retract (&rest args)
(apply 'update-selection "deselected" args))
(defun update-selection-extend (&rest args)
(apply 'update-selection "extended" args))
21.6.2 Callbacks to display data in a dialog
update-selection, one main function serves to display the data from any action in a dialog.
(defun display-in-dialog (type data interface)
"~S: ~A ~S"
(capi:interface-title interface) type data))
display-selection-in-dialog is the action callback for both the graph pane and the list panel. It calls
display-in-dialog, specifying one of the required arguments.
(defun display-selection-in-dialog (&rest args)
(apply 'display-in-dialog "selected" args))
Although only one action callback is specified in the example interface, the relevant functions have been defined in this modular way to allow for the possibility of extending the interface. For instance, you may decide at a later date that you want to display the information for an extended selection in a dialog, rather than in the display pane. You could do this by defining a new callback which calls
display-in-dialog, passing it an appropriate argument.
21.6.3 Callbacks for menu items
Both menu items in the interface need a callback function. As with other callback functions, these are specified by defining a general callback,
display-pane-selection, which displays, in a dialog, the current selection of any pane.
(defun display-pane-selection (reader data interface)
(declare (ignore data))
(capi:display-message "~S: ~S selected"
(funcall reader interface))
(funcall reader interface))))
The following two functions call
display-pane-selection, passing the reader of a pane as an argument. These functions are specified as the callbacks for the two menu items.
(defun display-graph-selection (&rest args)
(apply 'display-pane-selection 'graph-reader args))
(defun display-list-selection (&rest args)
(apply 'display-pane-selection 'list-reader args))
As with the other callback functions, specifying the callbacks in this way allows for easy extension of the example.
21.6.4 Other miscellaneous functions
Graph panes require a function which is used to plot information, called the children function. The value of the ROOTS attribute of a graph is passed as an argument to the children function in order to start the plot. The example interface uses the following simple children function. You already defined this if you have followed the example, but add it also in
(defun children-function (x)
(when (< x 8)
(list (* x 2) (1+ (* x 2)))))
The ROOTS attribute of a graph pane has a default value of
(1). This is generated automatically by the Interface Builder.
Finally, the function
test-ib-example is used to create an instance of the example interface.
(defun test-ib-example ()
(capi:display (make-instance 'ib-example
LispWorks IDE User Guide (Unix version) - 12 Feb 2015