A menu can be created in much the same way as any of the CAPI classes you have already met.
(setq menu
(make-instance 'menu
:title "Foo"
:items '("One" "Two" "Three" "Four")
:callback 'test-callback))
(setq interface
(make-instance 'interface
:menu-bar-items (list menu)))
(display interface)
This creates a CAPI interface with a menu,
Foo
, which contains four items. Choosing any of these items displays its arguments. Each item has the callback specified by the :callback
keyword.
A submenu can be created simply by specifying a menu as one of the items of the top-level menu.
(setq submenu
(make-instance 'menu
:title "Bar"
:items '("One" "Two" "Three" "Four")
:callback 'test-callback))
(setq menu
(make-instance 'menu
:title "Baz"
:items (list 1 2 submenu 4 5)
:callback 'test-callback))
(contain menu)
This creates an interface which has a menu, called Baz , which itself contains five items. The third item is another menu, Bar , which contains four items. Once again, selecting any item returns its arguments.
Menus can be nested as deeply as required using this method.
Note: In general you must not use a CAPI menu object in multiple different places in menu bar(s) at the same time. This is because menu bar menus are created when the interface is displayed, and (like any other CAPI pane) cannot be used elsewhere at the same time. Supply distinct instances instead. The one exception is popup menus, which are actually created only when they are on the screen, so they can be used repeatedly and in different places.
CAPI User Guide and Reference Manual (Unix version) - 25 Feb 2015