Next: Field Status, Previous: Field Display Attributes, Up: Forms Library [Contents][Index]
There is also a large collection of field option bits you can set to
control various aspects of forms processing. You can manipulate them
with the procedures set-field-opts!
, field-opts-on!
,
field-opts-off!
, and field-opts
.
The function set-field-opts!
can be used to directly set
attributes of a field or you can chose to switch a few attributes on
and off with field-opts-on!
and field-opts-off!
. You can
query the attributes of a field with field-opts
. The following
is a list of available options. By default, all options are on.
O_VISIBLE
Controls whether the field is visible on the screen. Can be used during form processing to hide or pop up fields depending on the value of parent fields.
O_ACTIVE
Controls whether the field is active during forms processing (i.e. visited by form navigation keys). Can be used to make labels or derived fields with buffer values alterable by the forms application, not the user.
O_PUBLIC
Controls whether data is displayed during field entry. If this option
is turned off on a field, the library will accept and edit data in
that field, but it will not be displayed and the visible field cursor
will not move. You can turn off the O_PUBLIC
bit to define
password fields.
O_EDIT
Controls whether the field’s data can be modified. When this option
is off, all editing requests except REQ_PREV_CHOICE
and
REQ_NEXT_CHOICE
will fail. Such read-only fields may be useful
for help messages.
O_WRAP
Controls word-wrapping in multiline fields. Normally, when any character of a (blank-separated) word reaches the end of the current line, the entire word is wrapped to the next line (assuming there is one). When this option is off, the word will be split across the line break.
O_BLANK
Controls field blanking. When this option is on, entering a character at the first field position erases the entire field (except for the just-entered character).
O_AUTOSKIP
Controls automatic skip to next field when this one fills. Normally, when the forms user tries to type more data into a field than will fit, the editing location jumps to the next field. When this option is off, the user’s cursor will hang at the end of the field. This option is ignored in dynamic fields that have not reached their size limit.
O_NULLOK
Controls whether validation is applied to blank fields. Normally, it is not; the user can leave a field blank without invoking the usual validation check on exit. If this option is off on a field, exit from it will invoke a validation check.
O_PASSOK
Controls whether validation occurs on every exit, or only after the
field is modified. Normally the latter is true. Setting
O_PASSOK
may be useful if your field’s validation function may
change during forms processing.
O_STATIC
Controls whether the field is fixed to its initial dimensions. If you turn this off, the field becomes dynamic and will stretch to fit entered data.
A field’s options cannot be changed while the field is currently selected. However, options may be changed on posted fields that are not current.
The option values are bit-masks and can be composed with logior
in the obvious way. You have seen the usage of watching off
O_AUTOSKIP
option. The following example clarified usage of
some more options. One field is a constant, uneditable field, that
you cannot move to by using the arrow keys. The other field is a
password-like field where the characters are hidden from view.
#!/usr/local/bin/guile !# (use-modules (srfi srfi-1) (ncurses curses) (ncurses form)) ;; Constants (define STARTX 15) (define STARTY 4) (define WIDTH 25) (define N_FIELDS 2) ;; Initialize curses (define stdscr (initscr)) (cbreak!) (noecho!) (keypad! stdscr #t) ;; Initialize the fields (define field (map-in-order (lambda (y) (new-field 1 WIDTH (+ (* y 2) STARTY) STARTX 0 0)) (iota N_FIELDS))) ;; Set field options (set-field-back! (first field) A_UNDERLINE) ;; Don't go to the next field when this field is filled up ;; This field is a static label (field-opts-off! (first field) O_ACTIVE) ;; This field is like a password field (field-opts-off! (second field) O_PUBLIC) (field-opts-off! (second field) O_AUTOSKIP) ;; Create the new form and post it (define my-form (new-form field)) (post-form my-form) (refresh stdscr) (set-field-just! (first field) JUSTIFY_CENTER) (set-field-buffer! (first field) 0 "This is a static field") (addstr "Field 1:" #:y STARTY #:x (- STARTX 10)) (addstr "Field 2:" #:y (+ STARTY 2) #:x (- STARTX 10)) (refresh stdscr) ;; Loop through to get user requests (let loop ((ch (getch))) (if (not (eqv? ch (key-f 1))) (cond ((eqv? ch KEY_DOWN) (begin ;; Go to the end of the next field (form-driver my-form REQ_NEXT_FIELD) (form-driver my-form REQ_END_LINE) (loop (getch)))) ((eqv? ch KEY_UP) (begin ;; Go to the end of the previous field (form-driver my-form REQ_PREV_FIELD) (form-driver my-form REQ_END_LINE) (loop (getch)))) (else (begin ;; Print any normal character (form-driver my-form ch) (loop (getch))))))) ;; Unpost the form (unpost-form my-form) (endwin)
Next: Field Status, Previous: Field Display Attributes, Up: Forms Library [Contents][Index]