The class
interface
is the top level window class, which contains both menus and a hierarchy of panes and layouts. Interfaces can also themselves be contained within a layout, in which case they appear without their menu bar.
The title of the interface.
The layout of the interface.
A flag controlling the automatic addition of system menu objects.
A callback done on closing the window.
A function to verify closing of the window.
The best x position for the interface.
The best y position for the interface.
The best width of the interface.
The best height of the interface.
A function called when the interface geometry changes.
A function called when the interface is activated or deactivated.
A function called when the interface is iconified or restored.
A cursor that takes precedence over the cursors of panes inside the interface.
A boolean determining whether the interface has a message area.
A boolean determining whether Pointer Documentation is enabled.
A boolean determining whether Tooltip Help is enabled.
interface-title
pane-layout
interface-menu-bar-items
interface-destroy-callback
interface-confirm-destroy-function
interface-
geometry-change-callback
interface-
activate-callback
interface-
iconify-callback
interface-override-cursor
interface-
message-area
interface-pointer-documentation-enabled
interface-tooltips-enabled
interface-help-callback
Every interface can have a title title which when it is a top level interface is shown as a title on its window, and when it is contained within another layout is displayed as a decoration (see the class titled-object for more details).
The argument
layout
specifies a layout object that contains the children of the interface. To change this layout you can either use the writer
pane-layout
, or you can use the layout switchable-layout which allows you to easily switch the currently visible child.
The argument menu-bar-items specifies a list of menus to appear on the interface's menu bar.
auto-menus
defaults to
t
, which means that an interface may have some automatic menus created by the environment in which it is running (for example the
Works
menu in the Common LispWorks environment). To switch these automatic menus off, pass
:auto-menus
nil
.
When you have an instance of an interface, you can display it either as an ordinary window or as a dialog using respectively display and display-dialog. Then to remove it from the display again, you use quit-interface and either exit-dialog or
abort-dialog respectively. When the interface is about to be closed, the CAPI calls the
confirm-destroy-function
(if there is one) with the interface, and if this function returns non-
nil
the interface is closed. Once the interface is closed, the
destroy-callback
is called with the interface.
The interface also accepts a number of hints as to the size and position of the interface for when it is first displayed. The arguments
best-x
and
best-y
must be the position as an integer or
nil
(meaning anywhere), while the arguments
best-width
and
best-height
can be any hints accepted by
:visible-max-width
and
:visible-max-height
for elements.
geometry-change-callback
may be
nil
, meaning there is no callback. This is the default value. Otherwise
geometry-change-callback
is a function of five arguments: the interface and the geometry. Its signature is:
geometry-change-callback interface x y width height
activate-callback
may be
nil
, meaning there is no callback. This is the default value. Otherwise
activate-callback
is a function of two arguments: the interface and a boolean
activatep
which is true on activation and false on deactivation. Its signature is:
activate-callback interface activatep
inconify-callback
may be
nil
, meaning there is no callback. This is the default value. Otherwise
inconify-callback
is a function of two arguments: the interface and a boolean
iconify
which is true when
interface
is iconified and and false when it is restored. Its signature is:
iconify-callback interface iconifyp
override-cursor
, if non-
nil
, specifies a cursor that is used instead of the cursor of each pane inside the interface. The default value of
override-cursor
is
nil
. See below for an example of setting and unsetting the override cursor.
If
message-area
is true, then the interface has a message area at the bottom. The text of the message area can be accessed using the titled-object accessor
titled-object-message
. The default value of
message-area
is
nil
.
enable-pointer-documentation
is a boolean controlling whether Pointer Documentation is enabled. The default value is
t
. The actual action is done by the
help-callback
.
enable-tooltips
is a boolean controlling whether Tooltip Help is enabled. The default value is
t
. The actual action is done by the
help-callback
.
help-callback
may be
nil
, meaning there is no callback. This is the default value. Otherwise
help-callback
is a function of four arguments: the interface, the pane inside interface where help is requested, the type of help requested, and the help key of the pane. Its signature is:
help-callback interface pane type help-key
The cursor entered the pane. The function should set the pointer documentation.
The cursor left the pane. The function needs to reset the pointer documentation.
A tooltip is requested. The function needs to return a string to display in the tooltip, or
nil
if no tooltip should be displayed.
The function should display a detailed, asynchronous help.
help-key is the help-key of pane , as described in element. See below for an example help-callback .
top-level-hook can be used to specify a hook function that is called around the interface's top level event handler. The hook is passed two arguments: a continuation function (with no arguments) and the interface. The hook must call the continuation, which normally does not return. top-level-hook is designed especially for error handling - see below for an example. It can also be used for other purposes, for instance to bind special variables around the top level function.
interface-
iconize-callback is deprecated. Use the synonym
interface-iconify-callback
instead.
(capi:display (make-instance 'capi:interface
:title "Test Interface"))
(capi:display (make-instance
'capi:interface
:title "Test Interface"
:destroy-callback
#'(lambda (interface)
(capi:display-message
"Quitting ~S"
interface))))
(capi:display (make-instance
'capi:interface
:title "Test Interface"
:confirm-destroy-function
#'(lambda (interface)
(capi:confirm-yes-or-no
"Really quit ~S"
interface))))
(capi:display (make-instance
'capi:interface
:menu-bar-items
(list
(make-instance 'capi:menu
:title "Menu"
:items '(1 2 3)))
:title "Menu Test"))
(setq interface
(capi:display
(make-instance 'capi:interface
:title "Test Interface"
:layout
(make-instance
'capi:simple-layout
:description
(list (make-instance
'capi:text-input-pane))
))
:process nil))
(setf (capi:pane-layout interface)
(make-instance
'capi:simple-layout
:description
(list (make-instance
'capi:editor-pane))))
(capi:display (make-instance
'capi:interface
:title "Test"
:best-x 200
:best-y 200
:best-width '(/ :screen-width 2)
:best-height 300))
The following forms illustrate the use of help-callback :
(capi:define-interface my-interface ()
()
(:panes
(a-pane
capi:text-input-pane
:help-key 'input)
(another-pane
capi:display-pane
:help-key 'output
:text "some text"))
(:menu-bar a-menu)
(:menus
(A-menu
"A menu"
(("An item" :help-key "item 1")
("Another item" :help-key "item 2"))
:help-key "a menu"))
(:layouts
(main-layout
capi:column-layout
'(a-pane another-pane)))
(:default-initargs
:help-callback 'my-help-callback
:message-area t))
(defun do-detailed-help (interface)
(capi:contain
(make-instance
'capi:display-pane
:text "Detailed help for my interface")
:title
(format nil "Help for ~a"
(capi:capi-object-name interface))))
(defun my-help-callback (interface pane type key)
(declare (ignore pane))
(case type
(:tooltip (if (eq key 'input)
"enter something"
(when (stringp key) key)))
(:pointer-documentation-enter
(when (stringp key)
(setf (capi:titled-object-message interface)
key)))
(:pointer-documentation-leave
(setf (capi:titled-object-message interface)
"Something else"))
(:help (do-detailed-help interface ))))
(capi:display
(make-instance 'my-interface :name "Helpful"))
The following forms illustrate the use of override-cursor to set and then remove an override cursor.
Create an interface with panes that have various different cursors. Move the pointer across each pane.
(setf interface
(capi:element-interface
(car
(capi:contain
(loop for cursor
in '(:crosshair :hand :v-double-arrow)
collect
(make-instance 'capi:editor-pane
:cursor cursor
:text
(format nil "~A CURSOR"
cursor)))))))
Override the pane cursors by setting the override cursor on the interface, and move the pointer across each pane again.
(setf (capi:interface-override-cursor interface)
:i-beam)
(setf (capi:interface-override-cursor interface)
:default)
This example illustrates top-level-hook . Evaluate this form and then get an error by Meta+Control+C (on Motif) or Control+Break (on Windows) in the editor pane. Then select the Destroy Interface restart.
(capi:display
(capi:make-container
(make-instance
'capi:editor-pane)
:top-level-hook
#'(lambda (func interface)
(restart-case (funcall func)
(nil ()
:report
(list "Destroy Interface ~a" interface)
(capi:destroy interface))))))
layout
switchable-layout
menu
display
display-dialog
quit-interface
define-interface
activate-pane
titled-object