The class menu-object is the superclass of all menu objects, and provides functionality for handling generic aspects of menus, menu components and menu items.









Callback before the menu appears.


Returns non- nil if the menu is enabled.


The object is enabled if the slot is non- nil.


The selection callback for the object.


A function to return data for the callback.


If non- nil , specifies the argument to the setup callbacks (listed below) that are used to set up the menu-object .






When the menu object is about to appear on the screen, the CAPI does the following:

  1. The setup callback items-function (if there is one) is called and the result is used to set the items, for menu and menu-component. The argument passed to items-function is the same as for the other setup callbacks (see below).
  2. The popup-callback (if there is one) is called and can make arbitrary changes to that object. The popup-callback is always called with the menu object, regardless of the value of setup-callback-argument .
  3. The other setup callbacks are called to set up the selection, enabled state and title. These setup callbacks include enabled-function for all menu-object s and title-function for all titled-menu-objects. The additional setup callbacks for menu-component are selection-function , selected-item-function , and selected-items-function . menu-item has the additional setup callback selected-function .

By default setup-callback-argument is nil , which means that each of the setup callbacks is called on the interface of the menu-object . If setup-callback-argument is non- nil , then it is passed (instead of the interface) as the argument to each of the setup callbacks.

  1. The menu containing the object appears with all of the changes made.

Note that enabled-slot is a short-hand means of creating an enabled-function which checks the value of a slot in the menu object's interface.

The enabled state of a menu-object is computed each time the menu is displayed, using enabled-function or enabled-slot . Therefore the accessor menu-object-enabled is only useful as a reader.

The callback argument is placed in the selection-callback , extend-callback and retract-callback slots unless these are given explicitly, and so will get called when the menu object is selected or deselected.

The callback-data-function is a function that is called with no arguments and the value it returns is used as the data to the callbacks.

(capi:contain (make-instance
               :text "Press Me"
               :enabled-function #'(lambda (item)
                                     (eq (random 2)

The next example illustrates the use of setup-callback-argument . The initialize-instance method adds to the "Some Numbers" menu a sub-menu that lists the selected items in the list-panel. By using setup-callback-argument in this menu, the setup callbacks (in this case enabled-function and items-function ) are called directly on the list-panel.

Note that, while this example uses a CAPI object as the setup-callback-argument , any object of any type can be used.

(capi:define-interface my-interface ()
    :items '(1 2 3 4 5 6 7 8 9 0)
    :interaction :extended-selection
    :visible-min-height '(character 10)))
    "Some Numbers"
    ("One" "Two")
  (:menu-bar a-menu))
(defmethod initialize-instance :after 
  ((self my-interface) &key)
  (with-slots (a-menu list-panel) self
    (setf (capi:menu-items a-menu)
           (capi:menu-items a-menu)
            (make-instance 'capi:menu
                           "Selected Items"))))))
(capi:display (make-instance 'my-interface))
See also


LispWorks CAPI Reference Manual - 17 Mar 2008