class Fl_Input


Class Hierarchy

Include Files

Description

This is the FLTK text input widget. It displays a single line of text and lets the user edit it. Normally it is drawn with an inset box and a white background. The text may contain any characters (even 0). The unprintable control characters are displayed with ^X notation. The appearance of other characters will depend on your operating system.

Mouse button 1Moves the cursor to this point. Drag selects characters. Double click selects words. Triple click selects all text. Shift+click extends the selection. When you select text it is automatically copied to the clipboard.
Mouse button 2Insert the clipboard at the point clicked. You can also select a region and replace it with the clipboard by selecting the region with mouse button 2.
Mouse button 3Currently acts like button 1.
BackspaceDeletes one character to the left, or deletes the selected region.
EnterMay cause the callback, see when().
^A or HomeGo to start of line.
^B or LeftMove left
^CCopy the selection to the clipboard
^D or DeleteDeletes one character to the right or deletes the selected region.
^E or EndGo to the end of line.
^F or RightMove right
^KDelete to the end of line (next \n character) or deletes a single \n character. These deletions are all concatenated into the clipboard.
^N or DownMove down (for Fl_Multiline_Input only, otherwise it moves to the next input field).
^P or UpMove up (for Fl_Multiline_Input only, otherwise it moves to the previous input field).
^UDelete everything.
^V or ^YPaste the clipboard
^X or ^WCopy the region to the clipboard and delete it.
^Z or ^_Undo. This is a single-level undo mechanism, but all adjacent deletions and insertions are concatenated into a single "undo". Often this will undo a lot more than you expected.
Shift+moveMove the cursor but also extend the selection.
RightCtrl or
Compose
Start a compose-character sequence. The next one or two keys typed define the character to insert:
KeysChar KeysChar KeysChar KeysChar KeysChar KeysChar
spacenbsp *° `AÀ D-Ð `aà d-ð
!¡ +-± 'AÁ ~NÑ 'aá ~nñ
%¢ 2² A^Â `OÒ ^aâ `oò
#£ 3³ ~AÃ 'OÓ ~aã 'oó
$¤ '´ :AÄ ^OÔ :aä ^oô
y=¥ uµ *AÅ ~OÕ *aå ~oõ
|¦ p AEÆ :OÖ aeæ :oö
&§ .· ,CÇ x× ,cç -:÷
:¨ ,¸ E`È O/Ø `eè o/ø
c© 1¹ 'EÉ `UÙ 'eé `uù
aª oº ^EÊ 'UÚ ^eê 'uú
<<« >>» :EË ^UÛ :eë ^uû
~¬ 14¼ `IÌ :UÜ `iì :uü
-­ 12½ 'IÍ 'YÝ 'ií 'yý
r® 34¾ ^IÎ THÞ ^iî thþ
_¯ ?¿ :IÏ ssß :iï :yÿ

For instance, to type "á" type [compose][a]['] or [compose]['][a].

The character "nbsp" (non-breaking space) is typed by using [compose][space].

The single-character sequences may be followed by a space if necessary to remove ambiguity. For instance, if you really want to type "ª~" rather than "ã" you must type [compose][a][space][~].

The same key may be used to "quote" control characters into the text. If you need a ^Q character you can get one by typing [compose][Control+Q].

X may have a key on the keyboard defined as XK_Multi_key. If so this key may be used as well as the right-hand control key. You can set this up with the program xmodmap.

If your keyboard is set to support a foreign language you should also be able to type "dead key" prefix characters. On X you will actually be able to see what dead key you typed, and if you then move the cursor without completing the sequence the accent will remain inserted.

Methods

Methods

Fl_Input::Fl_Input(int x, int y, int w, int h, const char *label = 0)

Creates a new Fl_Input widget using the given position, size, and label string. The default boxtype is FL_DOWN_BOX.

virtual Fl_Input::~Fl_Input()

The destructor removes the widget and any value associated with it.

int Fl_Input::word_start(int position) const

Returns the location of the first word boundary at or before position.

int Fl_Input::word_end(int position) const

Returns the location of the next word boundary at or after position.

int Fl_Input::line_start(int position) const

Returns the location of the start of the line containing the position.

int Fl_Input::line_end(int position) const

Returns the location of the next newline or wordwrap space at or after position.

void Fl_Input::drawtext(int,int,int,int)

Draw the text in the passed bounding box. If damage() FL_DAMAGE_ALL is true, this assummes the area has already been erased to color(). Otherwise it does minimal update and erases the area itself.

void Fl_Input::handletext(int e,int,int,int,int)

Default handler for all event types. Your handle() method should call this for all events that it does not handle completely. You must pass it the same bounding box as passed to draw(). Handles FL_PUSH, FL_DRAG, FL_RELEASE to select text, handles FL_FOCUS and FL_UNFOCUS to show and hide the cursor.

int Fl_Input::up_down_position(int i, int keepmark=0)

Do the correct thing for arrow keys. i must be the location of the start of a line. Sets the position (and mark if keepmark is zero) to somewhere after i, such that pressing the arrows repeatedly will cause the point to move up and down.

void Fl_Input::maybe_do_callback()

Does the callback if changed() is true or if when() FL_WHEN_NOT_CHANGED is non-zero. You should call this at any point you think you should generate a callback.

int Fl_Input::position() const
int Fl_Input::position(int new_position, int new_mark)
int Fl_Input::position(int new_position_and_new_mark)

The input widget maintains two pointers into the string. The "position" is where the cursor is. The "mark" is the other end of the selected text. If they are equal then there is no selection. Changing this does not affect the clipboard (use copy() to do that).

Changing these values causes a redraw(). The new values are bounds checked. The return value is non-zero if the new position is different than the old one. position(n) is the same as position(n,n). mark(n) is the same as position(position(),n).

int Fl_Input::mark() const
int Fl_Input::mark(int new_mark)

Gets or sets the current selection mark. mark(n) is the same as position(position(),n).

virtual int Fl_Input::replace(int a, int b, const char* insert, int length)

This call does all editing of the text. It deletes the region between a and b (either one may be less or equal to the other), and then inserts length (which may be zero) characters from the string insert at that point and leaves the mark() and position() after the insertion. Does the callback if when()&FL_WHEN_CHANGED and there is a change.

Subclasses of Fl_Input can override this function to control what characters can be inserted into the text. A typical implementation will check the characters in the insertion for legality and then call Fl_Input::replace only if they are all ok.

Subclasses should return true if the keystroke that produced this call should be "eaten". If false is returned the keystroke is allowed to be tested as a shortcut for other widgets. In our experience it is best to return true even if you don't make changes. The base class version returns true always.

int Fl_Input::cut()
int Fl_Input::cut(int n)
int Fl_Input::cut(int a, int b);

These are wrappers around replace(). Fl_Input::cut() deletes the area between mark() and position(). cut(n) deletes n characters after the position(). cut(-n) deletes n characters before the position() . cut(a,b) deletes the characters between offsets a and b. A, b, and n are all clamped to the size of the string. The mark and point are left where the deleted text was.

If you want the data to go into the clipboard, do Fl_Input::copy() before calling Fl_Input::cut().

int Fl_Input::insert(const char *t,int l=0)

Insert the string t at the current position, and leave the mark and position after it. If l is not zero then it is assummed to be strlen(t).

int Fl_Input::copy()

Put the current selection between mark() and position() into the clipboard. Does not replace the old clipboard contents if position() and mark() are equal.

int Fl_Input::undo()

Does undo of several previous calls to replace(). Returns non-zero if any change was made.

Fl_Input::Fl_Input(int x, int y, int w, int h, const char *label = 0)

Creates a new Fl_Input widget using the given position, size, and label string. The default boxtype is FL_DOWN_BOX.

virtual Fl_Input::~Fl_Input()

Destroys the widget and any value associated with it.

const char *Fl_Input::value() const
int Fl_Input::value(const char*)
int Fl_Input::value(const char*, int)

The first form returns the current value, which is a pointer to the internal buffer and is valid only until the next event is handled.

The second two forms change the text and set the mark and the point to the end of it. The string is copied to the internal buffer. Passing NULL is the same as "". This returns non-zero if the new value is different than the current one. You can use the second version to directly set the length if you know it already or want to put nul's in the text.

int Fl_Input::static_value(const char*)
int Fl_Input::static_value(const char*, int)

Change the text and set the mark and the point to the end of it. The string is not copied. If the user edits the string it is copied to the internal buffer then. This can save a great deal of time and memory if your program is rapidly changing the values of text fields, but this will only work if the passed string remains unchanged until either the Fl_Input is destroyed or value() is called again.

int Fl_Input::size() const

Returns the number of characters in value(). This may be greater than strlen(value()) if there are nul characters in it.

char Fl_Input::index(int) const

Same as value()[n], but may be faster in plausible implementations. No bounds checking is done.

Fl_When Fl_Widget::when() const
void Fl_Widget::when(Fl_When)

Controls when callbacks are done. The following values are useful, the default value is FL_WHEN_RELEASE:

Fl_Color Fl_Input::textcolor() const
void Fl_Input::textcolor(Fl_Color)

Gets or sets the color of the text in the input field.

Fl_Font Fl_Input::textfont() const
void Fl_Input::textfont(Fl_Font)

Gets or sets the font of the text in the input field.

uchar Fl_Input::textsize() const
void Fl_Input::textsize(uchar)

Gets or sets the size of the text in the input field.

Fl_Color Fl_Input::cursor_color() const
void Fl_Input::cursor_color(Fl_Color)

Get or set the color of the cursor. This is black by default.