class fltk::Input


Class Hierarchy

fltk::Widget
   |
   +----fltk::Input
           |
           +----fltk::FloatInput, fltk::IntInput,
                fltk::MultilineInput, fltk::SecretInput, fltk::Output

Include Files

#include <fltk/Input.h>

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 fltk::MultilineInput only, otherwise it moves to the next input field).
^OInsert a newline and put the cursor before it.
^P or UpMove up (for fltk::MultilineInput only, otherwise it moves to the previous input field).
^TSwap the two characters around the cursor, or the two characters before it if at the end of line.
^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ñ
c|¢ 2² A^Â `OÒ ^aâ `oò
L-£ 3³ ~AÃ 'OÓ ~aã 'oó
ox¤ '´ :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û
~¬ 141/4 `IÌ :UÜ `iì :uü
-­ 121/2 'IÍ 'YÝ 'ií 'yý
r® 343/4 ^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_Multikey. 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

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

Creates a new fltk::Input widget using the given position, size, and label string. The default boxtype is fltk::DOWN_BOX.

virtual fltk::Input::~Input()

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

int fltk::Input::word_start(int position) const

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

int fltk::Input::word_end(int position) const

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

int fltk::Input::line_start(int position) const

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

int fltk::Input::line_end(int position) const

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

void fltk::Input::drawtext(int,int,int,int)

Draw the text in the passed bounding box. If damage() fltk::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 fltk::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 fltk::PUSH, fltk::DRAG, fltk::RELEASE to select text, handles fltk::FOCUS and fltk::UNFOCUS to show and hide the cursor.

int fltk::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 fltk::Input::maybe_do_callback()

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

int fltk::Input::position() const
int fltk::Input::position(int new_position, int new_mark)
int fltk::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 fltk::Input::mark() const
int fltk::Input::mark(int new_mark)

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

virtual int fltk::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()&fltk::WHEN_CHANGED and there is a change.

Subclasses of fltk::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 fltk::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 fltk::Input::cut()
int fltk::Input::cut(int n)
int fltk::Input::cut(int a, int b);

These are wrappers around replace(). fltk::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 fltk::Input::copy() before calling fltk::Input::cut().

int fltk::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 fltk::Input::copy(bool clipboard=true)

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

If clipboard is true the text is put into the user-visible cut & paste clipboard (this is probably what you want). If false it is put into the less-visible selection buffer that is used to do middle-mouse paste and drag & drop.

To paste the clipboard, call fltk::paste(true) and fltk will send the widget a fltk::PASTE event with the text, which will cause it to be inserted.

int fltk::Input::undo()

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

const char *fltk::Input::value() const
int fltk::Input::value(const char*)
int fltk::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 fltk::Input::static_value(const char*)
int fltk::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 fltk::Input is destroyed or value() is called again.

int fltk::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 fltk::Input::index(int) const

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

fltk::When fltk::Widget::when() const
void fltk::Widget::when(fltk::When)

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

fltk::Color fltk::Input::textcolor() const
void fltk::Input::textcolor(fltk::Color)

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

fltk::Font fltk::Input::textfont() const
void fltk::Input::textfont(fltk::Font)

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

uchar fltk::Input::textsize() const
void fltk::Input::textsize(uchar)

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

fltk::Color fltk::Input::cursor_color() const
void fltk::Input::cursor_color(fltk::Color)

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