LispWorks CAPI User Guide > 9 Defining Interface Classes > 9.3 Adapting the example


9.3.1 Adding menus

To add menus to your interface you must first specify the menus themselves, and then a menu bar of which they will be a part.

Let us add some menus that duplicate the proposed functionality for the buttons. We will add:

The extra code needed in the define-interface call is this:

  (file-menu "File"
  (page-menu "Page"
             ("Page Up" "Page Down")))
 (:menu-bar file-menu page-menu)

Menu definitions give a slot name for the menu, followed by the title of the menu, a list of menu item descriptions, and then, optionally, a list of keyword arguments for the menu.

In this instance the menu item descriptions are just strings naming each item, but you may wish to supply initialization arguments for an item -- in which case you would enclose the name and those arguments in a list.

The menu bar definition simply names all the menus that will be on the bar, in the order that they will appear. By default, of course, the environment may add menus of its own to an interface -- for example the Works menu in the LispWorks IDE in multiple menu bar mode.

The code for the new interface is:

(define-interface demo ()
   (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))
    (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
   (file-menu "File"
   (page-menu "Page"
              ("Page Up" "Page Down")))
  (:menu-bar file-menu page-menu)
  (:default-initargs :title "Demo"))

Figure 9.3 A CAPI interface with menu items

The menus contain the items specified -- try it out to be sure.

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