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 true 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:
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.
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.
The function enabled-function should not display a dialog or do anything that may cause the system to hang. In general this means interacting with anything outside the Lisp image, including files, databases and so on.
(capi:contain (make-instance
'capi:menu-item
:text "Press Me"
:enabled-function #'(lambda (item)
(eq (random 2)
1))))
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 ()
()
(:panes
(list-panel
capi:list-panel
:items '(1 2 3 4 5 6 7 8 9 0)
:interaction :extended-selection
:visible-min-height '(character 10)))
(:menus
(a-menu
"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)
(append
(capi:menu-items a-menu)
(list
(make-instance 'capi:menu
:items-function
'capi:choice-selected-items
:setup-callback-argument
list-panel
:enabled-function
'capi:choice-selection
:title
"Selected Items"))))))
(capi:display (make-instance 'my-interface))
CAPI Reference Manual - 15 Dec 2011