A menu item is an individual item in a menu or menu component, and instances of menu-item are created automatically by define-interface.







A character or string, or the keyword :default .


An object used for lookup of help. Default value t .


A character, integer or symbol specifying a mnemonic for the menu item.


A character specifying the mnemonic escape. The default value is #\& .


A string specifying the text and a mnemonic.


A setup callback determining whether the item is selected.




The text displayed in the menu item is the contents of the text slot, or the contents of the title slot, otherwise it is the result of applying the print-function to the data .

selected-function defaults to nil , but if non- nil it is a function which is called before the menu-item is displayed and which determines whether or not the menu-item is selected. By default selected-function is called on the interface of the menu-item , but this argument can be changed by passing the menu-object initarg setup-callback-argument .

Callbacks are made in response to a user gesture on a menu-item . The callback-type (see callbacks), callback and callback-data-function (se menu-object) are found by looking for a non- nil value, first in the menu-item , then the menu-component (if any) and finally the menu. This allows a whole menu to have, for example, callback-type :data without having to specify this in each item. Some items could override this by having their callback-type slot non- nil if needed.

To specify a mnemonic in the menu item, you can use the initarg :mnemonic , or the initargs :mnemonic-title and :mnemonic-escape . These initargs are all interpreted just as in menu.

A menu item should not be used more in more than one place at a time.

help-key is interpreted as described for element.

accelerator can be a character or string specifying a key gesture which will be the accelerator for the menu item. Note that both-case-p characters are not allowed with the single modifier Shift in the accelerator argument. So instead of

:accelerator "shift-x"


:accelerator "X"

Note that the Shift modifier still appears in the menu.

A both-case-p character is allowed with Shift if there are other modifiers, for example

:accelerator "alt-shift-x"

accelerator has a special default value :default , which means that, depending on interface-keys-style for the interface, a standard accelerator is added if the item title matches a standard menu command.

(capi:contain (make-instance 'capi:menu-item
                             :text "Press Me"))
(capi:contain (make-instance 'capi:menu-item
                             :data :red
(capi:contain (make-instance
               :data :red
               :print-function 'string-capitalize
               :callback #'(lambda (data interface)
                              "Pressed ~S"

In this example note how the File menu gets accelerators automatically for its standard items:

(defun do-menu-item (item) 
   (format nil "~A" (capi:item-data item))))
(capi:define-interface mmm () ()
  (:menu-bar f-menu a-menu)
    (("Open..." :data "Open...") 
     ("New"     :data "New"))
    :callback 'do-menu-item 
    :callback-type :item)
    "Another Menu" 
    (("Open..." :data "Another Open") 
     ("New" :data "Another New") 
     ("Blancmange" :data "Blancmange" 
                   :accelerator #\Ctrl-\b))
    :callback 'do-menu-item 
    :callback-type :item))
   :width 300
   :height 200))
;; This causes automatic accelerators on all platforms. ;; That is the default behavior on Windows.
(defmethod capi:interface-keys-style ((self mmm))
(capi:contain (make-instance 'mmm))

There are further examples in the files examples/capi/applications/hangman.lisp and examples/capi/printing/fit-to-page.lisp .

See also


LispWorks CAPI Reference Manual - 11 Apr 2005