Next: , Previous: , Up: Part I Defining Forms   [Contents][Index]


3.7 Input Fields

It is often required to obtain textual input from the user, e.g., a file name, some fields in a database, etc. To this end input fields exist in the Forms Library. An input field is a field that can be edited by the user using the keyboard. To add an input field to a form use

FL_OBJECT *fl_add_input(int type, FL_Coord x, FL_Coord y,
                        FL_Coord w, FL_Coord h, const char *label);

The main type of input field available is FL_NORMAL_INPUT. The input field normally looks like an FL_DOWN_BOX. This can be changed using the routine fl_set_object_boxtype() to be described in Changing Attributes.

Whenever the user presses the mouse inside an input field a cursor will appear in it (and it will change color). Further input will appear inside this field. Full emacs(1) style editing is supported. When the user presses <Return> or <Tab> the input field is returned to the application program and further input is directed to the next input field. (The <Return> key only works if there are no default buttons in the form. See the overview of object classes. The <Tab> key always works.)

xforms_images/input

The user can use the mouse to select parts of the input field which will be removed when the user types the erase character or replaced by any new input the user types in. Also the location of the cursor can be moved in the input field using the mouse.

The input field is fully integrated with the X Selection mechanism. Use the left button to cut from and the middle button to paste into an input field.

The application program can direct the focus to a particular object using the call

void fl_set_focus_object(FL_FORM *form, FL_OBJECT *obj);

It puts the input focus in the form form onto object obj. To obtain the focus object, the following routine is available

FL_OBJECT *fl_get_focus_object(FL_FORM *form);

Note that the label is not the default text in the input field. The label is (by default) placed in front of the input field. To set the contents of the input field use the routines

void fl_set_input(FL_OBJECT *obj, const char *str);
void fl_set_input_f(FL_OBJECT *obj, const char *fmt, ...);

To change the color of the input text or the cursor use

void fl_set_input_color(FL_OBJECT *obj, int tcol, int ccol);

Here tcol indicates the color of the text and ccol is the color of the cursor. To obtain the string in the field (when the user has changed it) use:

const char *fl_get_input(FL_OBJECT *obj);

See the program demo06.c for an example of the use of input fields.


Next: , Previous: , Up: Part I Defining Forms   [Contents][Index]