Text Entry Fields

Text entry fields are used for entering one or more lines of plain text. In GTK 2, the GtkEntry control is used for single-line text entry, and GtkTextView for multiple-line text entry.

Figure 6.3. Single and multi-line entry fields

Screenshot of part of a dialog, containing both single and
          multi-line entry fields

Guidelines

Behavior of Return key

Normally, pressing Return in a dialog should activate the dialog's default button, unless the focused control uses Return for its own purposes. You should therefore set the activates-default property of most entry fields to TRUE. (Note that GtkTextView does not have such a setting— pressing Return always inserts a new line.).

However, if your dialog contains several entry fields that are usually filled out in order, for example Name, Address and Telephone Number, consider setting the activates-default property on those entry fields to FALSE. Pressing Return should then move focus on to the next control instead. Doing this will help prevent the user from accidentally closing the window before they have entered all the information they wanted to.

As a further safeguard, remember not to set the default button in a dialog until the minimum amount of required information has been entered, for example, both a username and a password in a login dialog. Again, in this case you should move focus to the next control when the user presses Return, rather than just ignoring the keypress.

If you need to provide a keyboard shortcut that activates the default button while a GtkTextView control has focus, use Ctrl-Return.

[Note]Note

Gtk does not currently move focus to the next control when Return is pressed and either activates-default=FALSE, or there is no default button in the window. For now, Return does nothing in these situations, so remember to implement the focus change behavior yourself.

Behavior of Tab key

Normally, pressing Tab in a single-line entry field should move focus to the next control, and in a multi-line entry field it should insert a tab character. Pressing Ctrl-Tab in a multi-line entry field should move focus to the next control.

If you need to provide a keyboard shortcut that inserts a tab character into a single line entry field, use Ctrl-Tab. You are unlikely to find many situations where this is useful, however.

There is a patch in bugzilla (bugid=53763) that adds an allow_tab_characters function to GtkEntry controls. This allows you to specify on a per-control basis whether Tab should insert a tab character or not. It is currently not known whether this patch is likely to make it into a future version of gtk.