All Manuals > LispWorks IDE User Guide > 21 Example: Using The Interface Builder

NextPrevUpTopContentsIndex

21.4 Specifying callbacks in the interface definition

The interface that you have designed contains a complete description of the layouts and menus that are available, but does not yet specify what any of the various elements do. To do this, you need to specify callbacks in the interface definition. As you might expect, this is done by setting attribute values for the appropriate elements in the interface.

In this example, the callbacks that you supply are calls to other functions, the definitions for which are assumed to be available in a separate source code file, and are discussed in Defining the callbacks. Note that you do not have to take this approach; you can just as easily specify callback functions within the interface definition itself, using lambda notation. It is up to you whether you do this within the Interface Builder, or by loading the code in the editor. If you choose the former, note that it may be easier to use the code view, rather than typing lambda functions into the Attributes dialog.

21.4.1 Specifying layout callbacks and other callback information

This section shows you how to specify all the callbacks necessary for each element in the example interface, together with other attributes that are required for correct operation of the callback functions. You need to specify attribute values for the display pane, the list panel and the graph pane.

  1. If necessary, click the Layouts tab at the top of the Interface Builder to display the layouts view.
  2. Select Selection-Text in the layout hierarchy and display the Attributes dialog.
  3. Set the Reader attribute to selection-reader and click OK .
  4. This reader allows the display pane to be identified by the callback code.

    For the list panel, you need to specify four callbacks and a reader.

  5. Select List in the layout hierarchy and display its Attributes dialog.
  6. Set the Reader attribute to list-reader. Do not click OK yet.
  7. Like the display pane, this reader is necessary so that the list panel can be identified by the callback code.

    Next, you need to specify the following four types of callback (make sure you click the Callbacks tab):

    Selection callback. The function that is called when you select a list item.

    Extend callback. The function that is called when you extend the current selection.

    Retract callback. The function that is called when you deselect a list item.

    Action callback. The function that is called when you double-click on a list item.

  8. Now set the following attributes of the list panel.
  9. Selection-Callback to 'update-selection-select
    Extend-Callback to 'update-selection-extend
    Retract-Callback to 'update-selection-retract
    Action-Callback to 'display-selection-in-dialog

    Click OK when done.

  10. Select the Graph graph pane and display its Attributes dialog.
  11. For the graph pane, you need to set the same four callbacks, as well as a reader, and two other attributes that are important for the callback code to run correctly.

  12. Set the following attributes of the graph pane.
  13. Selection-Callback to 'update-selection-select
    Extend-Callback to 'update-selection-extend
    Retract-Callback to 'update-selection-retract
    Action-Callback to 'display-selection-in-dialog

  14. Set the Reader attribute to graph-reader.
  15. Before you set the next callback, evaluate this form:
  16. (defun children-function (x)
      (when (< x 8)
        (list (* x 2) (1+ (* x 2)))))

    Now set the Children-Function attribute to 'children-function.

    The children function defines what is drawn in the graph, and so is vital for any graph pane. It is called when displaying the prototype interface, so it is best to define it before setting this attribute.

  17. Click OK to dismiss the Attributes dialog..

21.4.2 Specifying menu callbacks

The callbacks that are necessary for the menu system are much simpler than for the layouts; the example interface only contains two menu commands, and they only require one callback each.

  1. Click the Menus tab to switch to the menus view.
  2. Choose the "Graph" menu item, display its Attributes dialog and change the Callback attribute to 'display-graph-selection. Click OK .
  3. Choose the "List Panel" menu item, display its Attributes dialog and change the Callback attribute to 'display-list-selection. Click OK .

LispWorks IDE User Guide (Windows version) - 13 Sep 2017

NextPrevUpTopContentsIndex