This section shows you how to create the callback functions you need to define in order to complete the working example.
ib-example.lisp
, and call this new file ib-callbacks.lisp
.ib-callbacks.lisp
file:
(in-package "COMMON-LISP-USER")
The functions that you need to define in this file are divided into the following categories:
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))
As with update-selection
, one main function serves to display the data from any action in a dialog.
(defun display-in-dialog (type data interface)
(capi:display-message
"~S: ~A ~S"
(capi:interface-title interface) type data))
The function 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))
Note:
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.
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"
(capi:capi-object-name
(funcall reader interface))
(capi:choice-selected-items
(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.
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 ib-callbacks.lisp
:
(defun children-function (x)
(when (< x 8)
(list (* x 2) (1+ (* x 2)))))
Note:
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
:best-height 300
:best-width 200)))
LispWorks IDE User Guide (Windows version) - 13 Sep 2017