All Manuals > CAPI User Guide and Reference Manual > 9 Adding Toolbars

9.4 Specifying toolbar callbacks

Supply the selection-callback initarg to specify a callback for a toolbar button:

(setf print-button
      (make-instance 'toolbar-button
                     :image :std-print
                     :text "Print File"
                     :selection-callback 'print-callback))

You can also supply selection-callback for a toolbar-component. This specifies the same callback function for each button in the component.

To specify different callback functions for each button in a toolbar-component, either make the buttons explicitly as above, or supply the callbacks initarg.

9.4.1 Sharing toolbar callbacks with menu items

Where you want a toolbar button to perform the same command as a menu item, use the :remapped initarg.

remapped should match (by cl:equalp) the name of the menu-item:

(display
 (make-instance
  'interface
  :menu-bar-items
  (list 
   (make-instance 'menu
                  :items 
                  (list
                   (make-instance 'menu-item
                                  :name 'say-hello
                                  :data "Hello"
                                  :callback
                                  'test-callback))))
  :toolbar-items
  (list 
   (make-instance 'toolbar-button
                  :image :std-file-new
                  :remapped 'say-hello))))

9.4.2 Other types of callback for a toolbar button

You can, if desired, supply a retract-callback which is called when the button is deselected in a :multiple-selection component. You can also make a button display a dropdown menu nearby. See 9.7 Advanced toolbar features for the details.


CAPI User Guide and Reference Manual (Windows version) - 01 Dec 2021 19:33:51