Next Prev Up Top Contents Index

button

Class
Summary

A button is a pane that displays either a piece of text or a generic image, and that performs an action when pressed. Certain types of buttons can also be selected and deselected.

Superclasses

simple-pane
item

Subclasses

push-button
radio-button
check-button

Slots

interaction

The interaction style for the button.

selected

For radio button and check button styles, if selected is set to t , the button is initially selected.

callback

Specifies the callback to use when the button is selected.

image

A generic image for the button (or nil ).

disabled-image

The image for the button when disabled (or nil ).

enabled

If nil the button cannot be selected.

Accessors

button-enabled
button-selected

Readers

button-image
button-disabled-image

Description

The abstract class button is the class that push-button , radio-button , and check-button are built on. It can be displayed either with text or a generic image, and a callback is called when the button is clicked. It inherits all of its textual behavior from item , including the slot text which is the text that appears in the button. For more details, see item.

The subclasses of button are just buttons with different interaction styles. It can often be easier just to make an instance of button with the correct interaction (for instance, when the interaction is only known at run-time). The interaction styles are as follows:

:no-selection

A push button.

:single-selection

A radio button.

:multiple-selection

A check button.

Both radio buttons and check buttons can have a selection which can be set using the initarg :selected and the accessor button-selected .

The button's callback gets called when the user clicks on the button, and by default gets passed the data in the button and the interface. This can be changed by specifying a callback type as described in the description of callbacks. The following callbacks are accepted by buttons:

:callback

Called when the button is pressed.

:selection-callback

Called when the button is selected.

:retract-callback

Called when the button is deselected.

By default, image and disabled-image are nil , meaning that the button is a text button, but if image is provided then the button displays an image instead of the text. The image can be the name of an image that can be found in the image search path, or an instance of a generic image. The disabled image is the image that is shown when the button is disabled (or nil , meaning that it is left for the window system to decide how to display the image as disabled). For more details about generic images, see the LispWorks CAPI User Guide .

The button's actions can be enabled and disabled with the enabled slot, and its associated accessor button-enabled . This means that when the button is disabled, pressing on it does not call any callbacks or change its selection.

Note that the class button-panel provides functionality to group buttons together, and should normally be used in preference to creating individual buttons yourself. For instance, a radio-button-panel makes a number of radio buttons and also controls them such that only one button is ever selected at a time.

To specify a mnemonic in the button, you can use the initarg :mnemonic . This controls mnemonics in the button's text in the same way as it controls mnemonics in the title of a menu.

An alternate way to specify a mnemonic in the button is to use the :mnemonic-text initarg. This is used in the same way as :mnemonic-title is used in menu. Also, :mnemonic-escape can be specified if needed.

Example

In the following example a button is created. Using the button-enabled accessor the button is then enabled and disabled.

(setq button
      (capi:contain (make-instance
                     'capi:push-button
                     :text "Press Me")
                    :process nil))
(setf (capi:button-enabled button) nil) (setf (capi:button-enabled button) t)

In the next example a button with an image instead of text is created.

(setq button
      (capi:contain (make-instance
                     'capi:push-button
                     :image "new-lispworks-logo")))
See also

button-panel
callbacks


LispWorks CAPI Reference Manual - 14 Dec 2001

Next Prev Up Top Contents Index