LispWorks CAPI Reference Manual > 1 CAPI Reference Entries

NextPrevUpTopContentsIndex

text-input-pane

Class
Summary

The class text-input-pane is a pane for entering a single line of text.

Package

capi

Superclasses

titled-object
simple-pane

Subclasses

multi-line-text-input-pane
password-pane
text-input-choice

Initargs

:text

The text in the pane.

:caret-position

The position of the caret in the text (from 0).

:max-characters

The maximum number of characters allowed.

:enabled

Controls the enabled state of the pane.

:completion-function

A function called to complete the text.

:in-place-completion-function

A function designator.

:file-completion

t , nil or a pathname designator.

:in-place-filter

A boolean.

:directories-only

A boolean.

:ignore-file-suffices

A list of strings or the keyword :default .

:callback-type

The type of arguments to callback .

:callback

A function usually called when the user presses Return .

:change-callback-type

The type of arguments to callback .

:change-callback

A function called when a change is made.

:confirm-change-function

A function called to validate a change. Note: Implemented for Motif only, not Microsoft Windows or Mac OS X.

:navigation-callback

A function called when certain keyboard gestures occur in the pane.

:editing-callback

A function called when editing starts or stops.

:gesture-callbacks

A list of pairs ( gesture . callback ) .

:complete-do-action

A boolean.

:text-change-callback

A function designator.

:buttons

A plist specifying buttons to add, or t or nil .

Accessors

text-input-pane-text
text-input-pane-max-characters
text-input-pane-completion-function
text-input-pane-callback
text-input-pane-confirm-change-function
text-input-pane-change-callback
text-input-pane-navigation-callback
text-input-pane-editing-callback
text-input-pane-enabled
text-input-pane-buttons-enabled

Readers

text-input-pane-caret-position

Description

The class text-input-pane provides a great deal of flexibility in its handling of the text being entered. It starts with the initial text and caret-position specified by the arguments text and caret-position respectively. It limits the number of characters entered with the max-characters argument (which defaults to nil , meaning there is no maximum).

If enabled is nil , the pane is disabled. If enabled is :read-only , then the pane shows the text and allows it to be selected without it being editable. In this case the visual appearance varies between window systems, but often the text can be copied and the caret position altered. If enabled is any other true value, then the pane is fully enabled. The default value of enabled is t .

Note: enabled :read-only is not supported for the subclass text-input-choice on Microsoft Windows.

A completion-function can be specified which will get called when the completion gesture is made by the user (by pressing the Tab key) or when text-input-pane-complete-text is called. The function should have signature:

completion-function pane string => completions , start , end

where pane is the text-input-pane itself and string is the string to complete. When completion is invoked completion-function is called with pane and a string containing the text of pane to the left of the cursor.

The completion-function is called with the pane and the text to complete and should return either nil , the completed text as a string or a list completions of candidate completions. In the latter case, the CAPI will prompt the user for the completion they wish, and this will become the new text. In addition, the completion-function can return two more values, start and end , which specify a range in the text that is to be replaced if the completion is successful.

in-place-completion-function tells the pane to do in-place completion and specifies the function to use. The function should have signature:

in-place-completion-function pane string => completions , start , end

where pane is the text-input-pane itself and string is the string to complete. When in-place completion is invoked in-place-completion-function is called with pane and a string containing the text of pane to the left of the cursor.

completions needs to be a list of strings that are possible completions, a single string that is a unique completion, or the symbol :destroy . :destroy means that the in-place completion needs to stop and close the in-place window. In addition, the completion function can return two more values, start and end , which specify a range in the text that is to be replaced if the completion is successful. The function is called repeatedly whenever there is a change to the text that should be completed.

Note: If in-place-completion-function needs some dynamic information, it can put it in a property of the pane (using capi-object-property).

Note: The initarg :file-completion overrides :in-place-completion-function .

Note: The in-place completion mechanism uses gesture-callbacks to implement the functionality.

Note: :in-place-filter can be used to specify that the in-place window can have a filter.

See "In-place completion" in the LispWorks CAPI User Guide for the user interaction.

file-completion , if non-nil, tells the pane to do file completion using an in-place window. See "In-place completion" in the LispWorks CAPI User Guide for the interaction.

If file-completion is a pathname designator, its location is used as the root path for the completion.

Note: :file-completion overrides :in-place-completion-function .

Note: The behavior of in-place completion is somewhat different from other completion.

Note: The initargs :directories-only and :ignore-file-suffices can be used to change the behavior of the completion.

The default value of file-completion and in-place-completion-function is nil .

in-place-filter takes effect only when either in-place-completion-function or file-completion is non-nil. If in-place-filter is t then the in-place window can have a filter. Note that the filter needs to requested by a user gesture. Control+Return is the default in-place filter gesture. The default value of in-place-filter is t .

directories-only takes effect only if file-completion is used. If directories-only is t then in-place completion shows only directories. The default value of directories-only is nil .

ignore-file-suffices takes effect only if file-completion is used. It tells in-place completion to ignore files whose file namestring (the result of cl:file-namestring ) ends with any of the strings in the list ignore-file-suffices . If ignore-file-suffices is :default , then completion uses the default value, which is the value of editor:*ignorable-file-suffices* (see config/a-dot-lispworks.lisp ).

callback , if non-nil, is called when the user presses Return , unless navigation-callback is non-nil, in which case navigation-callback is called instead.

When the text or caret-position is changed, the callback change-callback is called with the text , the pane itself, the interface and the caret-position . The arguments that are passed to the change-callback can be altered by specifying the change-callback-type (see the callbacks class for details of possible values).

Note: the change-callback is potentially called more than once for each user gesture.

With the Motif implementation it is possible to check changes that the user makes to the text-input-pane by providing a confirm-change-function which gets passed the new text, the pane itself, its interface and the new caret position, and which should return non-nil if it is OK to make the change. If nil is returned, then the pane will be unaltered and a beep will be signalled to indicate that the new values were invalid.

navigation-callback , if non-nil, is a function that will be called when certain navigation gestures are used in the text-input-pane . The function is called with two arguments, the pane itself, and one of the following keywords:

:tab-forward

Tab was pressed.

:tab-backward

Tab Backwards (usually Shift+Tab ) was pressed.

:return

Return was pressed.

:shift-return

Shift+Return was pressed.

:enter

Enter was pressed.

:shift-enter

Shift+Enter was pressed.

Note: Enter is the key usually found on the numeric keypad.

When navigation-callback is non-nil, it is called instead of callback when Return is pressed. callback is still called via an OK button if there is one (see buttons below).

navigation-callback is implemented only on Microsoft Windows and Cocoa.

editing-callback , if non-nil, is a function of two arguments:

editing-callback pane type

pane is the text-input-pane and type is a keyword. editing-callback is called with type :start when the user starts editing and type :end when the user stops editing. In general, this occurs when the focus changes, but on Cocoa type :start is passed when the first change is made to the text.

gesture-callbacks provides callbacks to perform for specific keyboard gestures. Each gesture must be an object that sys:coerce-to-gesture-spec can coerce to a gesture-spec. Each callback can be a callable (symbol or function) which takes one argument, the pane. Alternatively each callback can be a list of the form ( function arguments ) . Note that in this case, the pane itself is not automatically passed to the function amongst arguments .

When the user enters a gesture that matches gesture in any pair amongst gesture-callbacks , the callback is executed and the gesture is not processed any more.

Note: The interaction of in-place completion is implemented using gesture-callbacks . Gestures which you define explicitly by gesture-callbacks override the gestures which are defined implicitly by the in-place completion mechanism.

Note: For gestures that change the text, text-change-callback is probably better than gesture-callbacks .

When complete-do-action is non-nil, completion of the text in the pane automatically invokes callback (if callback is non-nil). The default value of complete-do-action is nil .

text-change-callback is a change callback (see change-callback ) that is called only when the text in the pane changes. In contrast, change-callback is also called when the caret moves. If both text-change-callback and change-callback are supplied, only text-change-callback is invoked.

buttons specifies toolbar buttons which appear next to the pane and facilitate user actions on it. It also specifies the position of the buttons relative to the pane. This feature appears in the LispWorks IDE, for example the Class box of the Class Browser.

The allowed keys and values of the plist buttons are:

:ok

A boolean or a plist, default value t . If true, a button which calls callback appears. If the value is a plist then this plist supplies details for the button, as described below.

:cancel

A boolean or a plist, default value nil . If true, a button which calls cancel-function appears. A plist value is interpreted as for :ok and can also contain the key :accelerator which specifies an accelerator used for the button. There is no default accelerator.

:completion

A boolean or a plist. If true, a button which calls completion-function appears. The default value is t if completion-function is non-nil, and nil otherwise. A plist value is interpreted as for :ok .

:browse-file

A keyword or a plist. If true, a button which invokes prompt-for-file appears. If the value is :save or :open then it is passed as the operation argument to prompt-for-file, replacing the text in the pane if successful. If the value is a plist, then it supplies details for the button, as described below, and can also contain the keywords :message to specify a message for the file prompter; :pathname to specify the default pathname of the file prompter (defaults to the text in the text-input-pane ) or any of the keywords :ok-check , :filter , :filters , :if-exists , :if-does-not-exist , :operation , :owner , :pane-args or :popup-args which are passed directly to prompt-for-file.

:cancel-function

A function that expects the pane as its single argument. The default is a function which sets text to the empty string.

:help

Specifies a help button. The value must be a plist containing either keys :function and optionally :arguments , or the keys :title , :message and optionally :dialog-p .

If function is supplied, when the user presses the help button it calls

(apply function pane arguments )

where pane is the text-input-pane . title , message and dialog-p are ignored in this case.

Otherwise when the user presses the help button it opens a window with title title displaying the string message in a display-pane. The message can be long, and can include newlines. The window is owned by the pane, but is not modal, so the user can interact with the pane while the help window is displayed. If dialog-p is true, the help window is raised as a dialog. The default value for dialog-p is nil . function and arguments are ignored in this case.

The plist can contain other keys as described below.

:orientation

The value is either :horizontal or :vertical . orientation controls the orientation of the toolbar. This is useful for multi-line-text-input-pane. The default value is :horizontal .

:adjust

The value is :top , :center , :centre or :bottom . adjust controls how the buttons are adjusted vertically relative to the text input pane. This is useful for multi-line-text-input-pane. The default value is :center .

:position

The value is :top , :bottom , :left or :right . position determines whether the buttons appear above, below, left or right of the text input pane. If :position is not supplied, then the buttons appear to the right of the pane.

The value nil for buttons means there are no buttons - this is the default. When buttons is true the buttons appear or not according to their specified values or their default values.

All of the button plists (for :ok , :cancel , :help and so on) can contain the following keys and values in addition to those mentioned above:

:enabled

A value that controls whether the button is enabled. (See the reader text-input-pane-buttons-enabled ).

:image

The image to use for the button. This should be either a pathname or string naming an image file to load, a symbol giving the id of an image registered with register-image-translation, an image object as returned by load-image or an external-image. The default image is one of the symbols ok-button , cancel-button or complete-button , which are pre-registered image identifers corresponding to each button.

:help-key

The help-key used to find a tooltip for the button.

The text-input-pane-buttons-enabled reader returns a list containing keywords such as :ok , :cancel and :completion , one for each corresponding button (as specified by buttons ) that is currently enabled.

The (setf text-input-pane-buttons-enabled) writer takes a list of keywords as described for the reader and sets the enabled state of the buttons, enabling each button if it appears in the list and disabling it otherwise. The value t can also be passed: this enables all the buttons.

For more than one line of input, use multi-line-text-input-pane.

Compatibility note

The confirm-change-function was called before-change-callback in LispWorks 3.1. Both the old initarg before-change-callback and the old accessor text-input-pane-before-change-callback are still supported, but may not be in future releases.

Example
(capi:contain (make-instance 'capi:text-input-pane
                             :text "Hello world"))
(setq tip (capi:contain
                       (make-instance 
                        'capi:text-input-pane
                        :enabled nil)))
 
(capi:apply-in-pane-process 
  tip #'(setf capi:text-input-pane-enabled) t tip)
 
(capi:apply-in-pane-process 
 tip #'(setf capi:text-input-pane-enabled) nil tip)
 
(capi:apply-in-pane-process 
 tip #'(setf capi:text-input-pane-text) "New text" tip)
(capi:contain (make-instance
               'capi:text-input-pane
               :text "Hello world"
               :callback #'(lambda (text interface)
                             (capi:display-message
                              "Interface ~S's text: ~S"
                              interface text))))

This example uses a plist value for the buttons key :cancel to specify that the Cancel button is initially disabled:

(capi:contain 
 (make-instance 'capi:text-input-pane 
                :buttons 
                '(:ok t :cancel (:enabled nil))))

This example shows how to specify a Help button which displays a help message:

(defvar *help-message* "A long help message.")
 
(capi:contain
 (make-instance 'capi:text-input-pane
                :buttons 
                `(:help 
                  (:title "help window"
                   :message ,*help-message*))))

This example illustrates the use of gesture-callbacks . Ctrl+e moves the cursor to the end of the input, Ctrl+a moves it to the start, and Ctrl+6 does something else:

(capi:contain
 (make-instance
  'capi:text-input-pane
  :gesture-callbacks
  (list 
   (cons
    #\Ctrl-\e 
    #'(lambda (tip)
        (setf (capi:text-input-pane-caret-position tip)
              (length (capi:text-input-pane-text tip)))))
   (cons
    #\Ctrl-\a
    #'(lambda (tip)
        (setf (capi:text-input-pane-caret-position tip)
              0)))
   (cons 
    #\Ctrl-6 'do-something-else))))

There is a further example in the file examples/capi/elements/text-input-pane.lisp

See also

display-pane
editor-pane
multi-line-text-input-pane
text-input-choice
text-input-pane-complete-text
text-input-range
title-pane


LispWorks CAPI Reference Manual - 21 Dec 2009

NextPrevUpTopContentsIndex