Drop-Fields

OBJECTS

  typedef void (*ControlFunc)  (Control *c);

FUNCTIONS

  Control *new_drop_field(Window *w, Rect r, char **lines);
  Control *add_drop_field(Control *c, Rect r, char **lines);

  char *   get_control_text(Control *c);

  void     set_field_allowed_width(Control *c, int width);
  void     set_field_allowed_chars(Control *c, char *allowed);
  void     set_field_disallowed_chars(Control *c, char *disallowed);

NOTES

A drop field is a one-line text field with an associated push-button which, when clicked, displays a drop-down menu list of selectable names. The control is created using new_drop_field on the specified window, within the given rectangle. The lines parameter is a NULL-terminated list of strings, to be displayed in the menu.

Text can be typed as normal into the text field, or an item can be selected from the drop-down menu, which will then set the text field's text to be the selected item.

The add_drop_field function works in the same way as new_drop_field, except that it attaches the drop field to a control rather than directly to a window.

The get_control_text function can be used to discover what text was typed or selected.

The maximum number of characters which can be typed into a drop field can be controlled with the set_field_allowed_width function. The width parameter controls the number of Unicode characters which can be typed. If the value is zero, the field is unrestricted in width, which is the default. Lines chosen via drop-down menu may be able to violate this constraint.

A drop field can be restricted with set_field_allowed_chars, so that only a set of allowed characters can be typed into the field by the user. All other characters will be passed to the parent control or window. Setting the allowed string to NULL removes all restrictions, which is the default situation.

A drop field can also be instructed to ignore certain characters, and instead pass them up to its parent control or window, using the set_field_disallowed_chars function. By default, the tab, newline and escape keys are disallowed for drop fields, and are thus sent to the window.

EXAMPLES