7 Defining Interface Classes

7.3 Adapting the example

The:panesand:layouts keywords can take a number of panes and layouts, each specified one after the other. By listing several panes, menus, and so on, complicated interfaces can be constructed quickly.

To see how simply this is done, let us add an editor pane to our interface. We need this to display the text contained in the file chosen with the Open File button.

The editor pane needs a layout. It could be added to therow-layout already built, or another layout could be made for it. Then, the two layouts would have to be put inside a third to contain them (see Chapter 5, Laying Out CAPI Panes).

The first thing to do is add the editor pane to the panes description. The old panes description read:

 (:panes
  (page-up push-button 
           :text "Page Up")
  (page-down push-button
             :text "Page Down")
  (open-file push-button
             :text "Open File"))

The new one includes an editor pane namedviewer.

(:panes
 (page-up push-button
          :text "Page Up")
 (page-down push-button
            :text "Page Down")
 (open-file push-button
            :text "Open File")
 (viewer editor-pane
         :title "File:"
         :visible-min-height '(:character 8)
         :reader viewer-pane))

This specifies the editor pane, with a stipulation that it must be at least 8 characters high. This allows you to see a worthwhile amount of the file being viewed in the pane.

Note the use of:reader, which defines a reader method for the interface which returns the editor pane. You can also specify writers or accessors in this way.

The interface also needs a layout for the editor pane in the layouts section. The old layouts description read:

  (:layouts
   (row-of-buttons row-layout
                   '(page-up page-down open-file)))

The new one reads:

  (:layouts
   (main-layout column-layout 
                '(row-of-buttons row-with-editor-pane))
   (row-of-buttons row-layout
                   '(page-up page-down open-file))
   (row-with-editor-pane row-layout
                         '(viewer)))

This creates another row-layout for the new pane and then encapsulates the two row layouts into a third column-layout calledmain-layout. This is used as the default layout, specified by setting the:layout initarg tomain-layout in the:default-initargs section. If there is no default layout specified,define-interface uses the first one listed.

By putting the layout of buttons and the layout with the editor pane in a column layout, their relative position has been controlled: the buttons appear in a row above the editor pane.

The code for the new interface is now as follows:

(define-interface demo ()
  ()
 (:panes
  (page-up push-button 
           :text "Page Up")
  (page-down push-button
             :text "Page Down")
  (open-file push-button
             :text "Open File")
  (viewer editor-pane
          :title "File:"
          :visible-min-height '(:character 8)
          :reader viewer-pane))
 (:layouts
   (main-layout column-layout 
                '(row-of-buttons row-with-editor-pane))
   (row-of-buttons row-layout
                   '(page-up page-down open-file))
   (row-with-editor-pane row-layout
                         '(viewer)))
  (:default-initargs :title "Demo"))

Displaying an instance of the interface by entering the line of code below produces the window in Figure 7.2:

(display (make-instance 'demo))

Figure 7.2 A CAPI interface with editor pane

7.3.1 - Adding menus

CAPI User Guide, Liquid Common Lisp Version 5.0 - 2 OCT 1997

Generated with Harlequin WebMaker