LispWorks CAPI User Guide > 9 Defining Interface Classes

NextPrevUpTopContentsIndex

9.3 Adapting the example

The :panes and :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 the row-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 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 named viewer .

(: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:"
         :text "No file selected."
         :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. Similarly, you can also specify writers or accessors. If you omit accessor methods, it is still possible to access panes and other elements in an interface instance using with-slots .

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 called main-layout . This is used as the default layout, specified by setting the :layout initarg to main-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:"
          :text "No file selected."
          :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 A CAPI interface with editor pane:

(display (make-instance 'demo))

Figure 9.2 A CAPI interface with editor pane

9.3.1 Adding menus


LispWorks CAPI User Guide (Macintosh version) - 22 Dec 2009

NextPrevUpTopContentsIndex