FLTK 1.3.2
|
This class provides a low-overhead text input field. More...
#include <Fl_Input_.H>
Public Member Functions | |
int | copy (int clipboard) |
Put the current selection into the clipboard. | |
int | copy_cuts () |
Copies the yank buffer to the clipboard. | |
Fl_Color | cursor_color () const |
Gets the color of the cursor. | |
void | cursor_color (Fl_Color n) |
Sets the color of the cursor. | |
int | cut () |
Deletes the current selection. | |
int | cut (int n) |
Deletes the next n bytes rounded to characters before or after the cursor. | |
int | cut (int a, int b) |
Deletes all characters between index a and b . | |
Fl_Input_ (int, int, int, int, const char *=0) | |
Creates a new Fl_Input_ widget. | |
Fl_Char | index (int i) const |
Returns the character at index i . | |
int | input_type () const |
Gets the input field type. | |
void | input_type (int t) |
Sets the input field type. | |
int | insert (const char *t, int l=0) |
Inserts text at the cursor position. | |
int | mark () const |
Gets the current selection mark. | |
int | mark (int m) |
Sets the current selection mark. | |
int | maximum_size () const |
Gets the maximum length of the input field in characters. | |
void | maximum_size (int m) |
Sets the maximum length of the input field in characters. | |
int | position () const |
Gets the position of the text cursor. | |
int | position (int p, int m) |
Sets the index for the cursor and mark. | |
int | position (int p) |
Sets the cursor position and mark. | |
int | readonly () const |
Gets the read-only state of the input field. | |
void | readonly (int b) |
Sets the read-only state of the input field. | |
int | replace (int b, int e, const char *text, int ilen=0) |
Deletes text from b to e and inserts the new string text . | |
void | resize (int, int, int, int) |
Changes the size of the widget. | |
int | shortcut () const |
Return the shortcut key associated with this widget. | |
void | shortcut (int s) |
Sets the shortcut key associated with this widget. | |
int | size () const |
Returns the number of bytes in value(). | |
void | size (int W, int H) |
Sets the width and height of this widget. | |
int | static_value (const char *) |
Changes the widget text. | |
int | static_value (const char *, int) |
Changes the widget text. | |
void | tab_nav (int val) |
Sets whether the Tab key does focus navigation, or inserts tab characters into Fl_Multiline_Input. | |
int | tab_nav () const |
Gets whether the Tab key causes focus navigation in multiline input fields or not. | |
Fl_Color | textcolor () const |
Gets the color of the text in the input field. | |
void | textcolor (Fl_Color n) |
Sets the color of the text in the input field. | |
Fl_Font | textfont () const |
Gets the font of the text in the input field. | |
void | textfont (Fl_Font s) |
Sets the font of the text in the input field. | |
Fl_Fontsize | textsize () const |
Gets the size of the text in the input field. | |
void | textsize (Fl_Fontsize s) |
Sets the size of the text in the input field. | |
int | undo () |
Undoes previous changes to the text buffer. | |
int | value (const char *) |
Changes the widget text. | |
int | value (const char *, int) |
Changes the widget text. | |
const char * | value () const |
Returns the text displayed in the widget. | |
int | wrap () const |
Gets the word wrapping state of the input field. | |
void | wrap (int b) |
Sets the word wrapping state of the input field. | |
~Fl_Input_ () | |
Destroys the widget. | |
Protected Member Functions | |
void | drawtext (int, int, int, int) |
Draws the text in the passed bounding box. | |
void | handle_mouse (int, int, int, int, int keepmark=0) |
Handles mouse clicks and mouse moves. | |
int | handletext (int e, int, int, int, int) |
Handles all kinds of text field related events. | |
int | line_end (int i) const |
Finds the end of a line. | |
int | line_start (int i) const |
Finds the start of a line. | |
int | linesPerPage () |
void | maybe_do_callback () |
int | up_down_position (int, int keepmark=0) |
Moves the cursor to the column given by up_down_pos . | |
int | word_end (int i) const |
Finds the end of a word. | |
int | word_start (int i) const |
Finds the start of a word. | |
int | xscroll () const |
int | yscroll () const |
void | yscroll (int yOffset) |
This class provides a low-overhead text input field.
This is a virtual base class below Fl_Input. It has all the same interfaces, but lacks the handle() and draw() method. You may want to subclass it if you are one of those people who likes to change how the editing keys work. It may also be useful for adding scrollbars to the input field.
This can act like any of the subclasses of Fl_Input, by setting type() to one of the following values:
#define FL_NORMAL_INPUT 0 #define FL_FLOAT_INPUT 1 #define FL_INT_INPUT 2 #define FL_MULTILINE_INPUT 4 #define FL_SECRET_INPUT 5 #define FL_INPUT_TYPE 7 #define FL_INPUT_READONLY 8 #define FL_NORMAL_OUTPUT (FL_NORMAL_INPUT | FL_INPUT_READONLY) #define FL_MULTILINE_OUTPUT (FL_MULTILINE_INPUT | FL_INPUT_READONLY) #define FL_INPUT_WRAP 16 #define FL_MULTILINE_INPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_WRAP) #define FL_MULTILINE_OUTPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_READONLY | FL_INPUT_WRAP)
All variables that represent an index into a text buffer are byte-oriented, not character oriented, counting from 0 (at or before the first character) to size() (at the end of the buffer, after the last byte). Since UTF-8 characters can be up to six bytes long, simply incrementing such an index will not reliably advance to the next character in the text buffer.
Indices and pointers into the text buffer should always point at a 7 bit ASCII character or the beginning of a UTF-8 character sequence. Behavior for false UTF-8 sequences and pointers into the middle of a sequence are undefined.
Fl_Input_::Fl_Input_ | ( | int | X, |
int | Y, | ||
int | W, | ||
int | H, | ||
const char * | l = 0 |
||
) |
Destroys the widget.
The destructor clears all allocated buffers and removes the widget from the parent Fl_Group.
int Fl_Input_::copy | ( | int | clipboard | ) |
Put the current selection into the clipboard.
This function copies the current selection between mark() and position() into the specified clipboard
. This does not replace the old clipboard contents if position() and mark() are equal. Clipboard 0 maps to the current text selection and clipboard 1 maps to the cut/paste clipboard.
clipboard | the clipboard destination 0 or 1 |
int Fl_Input_::copy_cuts | ( | ) |
Fl_Color Fl_Input_::cursor_color | ( | ) | const [inline] |
Gets the color of the cursor.
void Fl_Input_::cursor_color | ( | Fl_Color | n | ) | [inline] |
Sets the color of the cursor.
The default color for the cursor is FL_BLACK
.
[in] | n | the new cursor color |
int Fl_Input_::cut | ( | ) | [inline] |
Deletes the current selection.
This function deletes the currently selected text without storing it in the clipboard. To use the clipboard, you may call copy() first or copy_cuts() after this call.
int Fl_Input_::cut | ( | int | n | ) | [inline] |
Deletes the next n
bytes rounded to characters before or after the cursor.
This function deletes the currently selected text without storing it in the clipboard. To use the clipboard, you may call copy() first or copy_cuts() after this call.
n | number of bytes rounded to full characters and clamped to the buffer. A negative number will cut characters to the left of the cursor. |
int Fl_Input_::cut | ( | int | a, |
int | b | ||
) | [inline] |
Deletes all characters between index a
and b
.
This function deletes the currently selected text without storing it in the clipboard. To use the clipboard, you may call copy() first or copy_cuts() after this call.
a,b | range of bytes rounded to full characters and clamped to the buffer |
void Fl_Input_::drawtext | ( | int | X, |
int | Y, | ||
int | W, | ||
int | H | ||
) | [protected] |
void Fl_Input_::handle_mouse | ( | int | X, |
int | Y, | ||
int | , | ||
int | , | ||
int | drag = 0 |
||
) | [protected] |
Handles mouse clicks and mouse moves.
int Fl_Input_::handletext | ( | int | event, |
int | X, | ||
int | Y, | ||
int | W, | ||
int | H | ||
) | [protected] |
Handles all kinds of text field related events.
This is called by derived classes.
unsigned int Fl_Input_::index | ( | int | i | ) | const |
Returns the character at index i
.
This function returns the UTF-8 character at i
as a ucs4 character code.
[in] | i | index into the value field |
i
int Fl_Input_::input_type | ( | ) | const [inline] |
Gets the input field type.
void Fl_Input_::input_type | ( | int | t | ) | [inline] |
Sets the input field type.
A redraw() is required to reformat the input field.
[in] | t | new input type |
int Fl_Input_::insert | ( | const char * | t, |
int | l = 0 |
||
) | [inline] |
Inserts text at the cursor position.
This function inserts the string in t
at the cursor position() and moves the new position and mark to the end of the inserted text.
[in] | t | text that will be inserted |
[in] | l | length of text, or 0 if the string is terminated by nul . |
int Fl_Input_::line_end | ( | int | i | ) | const [protected] |
Finds the end of a line.
This call calculates the end of a line based on the given index i
.
[in] | i | starting index for the search |
int Fl_Input_::line_start | ( | int | i | ) | const [protected] |
Finds the start of a line.
This call calculates the start of a line based on the given index i
.
[in] | i | starting index for the search |
int Fl_Input_::mark | ( | ) | const [inline] |
Gets the current selection mark.
int Fl_Input_::mark | ( | int | m | ) | [inline] |
Sets the current selection mark.
mark(n) is the same as position(position(),n)
.
m | new index of the mark |
int Fl_Input_::maximum_size | ( | ) | const [inline] |
Gets the maximum length of the input field in characters.
void Fl_Input_::maximum_size | ( | int | m | ) | [inline] |
Sets the maximum length of the input field in characters.
This limits the number of characters that can be inserted in the widget.
int Fl_Input_::position | ( | ) | const [inline] |
Gets the position of the text cursor.
int Fl_Input_::position | ( | int | p, |
int | m | ||
) |
Sets the index for the cursor and mark.
The input widget maintains two pointers into the string. The position (p
) is where the cursor is. The mark (m
) 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.
p | index for the cursor position |
m | index for the mark |
Reimplemented from Fl_Widget.
int Fl_Input_::position | ( | int | p | ) | [inline] |
Sets the cursor position and mark.
position(n) is the same as position(n, n)
.
p | new index for cursor and mark |
int Fl_Input_::readonly | ( | ) | const [inline] |
Gets the read-only state of the input field.
void Fl_Input_::readonly | ( | int | b | ) | [inline] |
Sets the read-only state of the input field.
[in] | b | if b is 0, the text in this widget can be edited by the user |
int Fl_Input_::replace | ( | int | b, |
int | e, | ||
const char * | text, | ||
int | ilen = 0 |
||
) |
Deletes text from b
to e
and inserts the new string text
.
All changes to the text buffer go through this function. It deletes the region between b
and e
(either one may be less or equal to the other), and then inserts the string text
at that point and moves the mark() and position() to the end of the insertion. Does the callback if when() & FL_WHEN_CHANGED
and there is a change.
Set b
and e
equal to not delete anything. Set text
to NULL
to not insert anything.
ilen
can be zero or strlen(text)
, which saves a tiny bit of time if you happen to already know the length of the insertion, or can be used to insert a portion of a string. If ilen
is zero, strlen(text)
is used instead.
b
and e
are clamped to the 0..size()
range, so it is safe to pass any values. b
, e
, and ilen
are used as numbers of bytes (not characters), where b
and e
count from 0 to size() (end of buffer).
If b
and/or e
don't point to a valid UTF-8 character boundary, they are adjusted to the previous (b
) or the next (e
) valid UTF-8 character boundary, resp..
If the current number of characters in the buffer minus deleted characters plus inserted characters in text
would overflow the number of allowed characters (maximum_size()), then only the first characters of the string are inserted, so that maximum_size() is not exceeded.
cut() and insert() are just inline functions that call replace().
[in] | b | beginning index of text to be deleted |
[in] | e | ending index of text to be deleted and insertion position |
[in] | text | string that will be inserted |
[in] | ilen | length of text or 0 for nul terminated strings |
text
does not point to a valid UTF-8 character or includes invalid UTF-8 sequences, the text is inserted nevertheless (counting invalid UTF-8 bytes as one character each). void Fl_Input_::resize | ( | int | X, |
int | Y, | ||
int | W, | ||
int | H | ||
) | [virtual] |
Changes the size of the widget.
This call updates the text layout so that the cursor is visible.
[in] | X,Y,W,H | new size of the widget |
Reimplemented from Fl_Widget.
int Fl_Input_::shortcut | ( | ) | const [inline] |
Return the shortcut key associated with this widget.
void Fl_Input_::shortcut | ( | int | s | ) | [inline] |
Sets the shortcut key associated with this widget.
Pressing the shortcut key gives text editing focus to this widget.
[in] | s | new shortcut keystroke |
int Fl_Input_::size | ( | ) | const [inline] |
void Fl_Input_::size | ( | int | W, |
int | H | ||
) | [inline] |
Sets the width and height of this widget.
[in] | W,H | new width and height |
Reimplemented from Fl_Widget.
int Fl_Input_::static_value | ( | const char * | str | ) |
Changes the widget text.
This function changes the text and sets 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.
[in] | str | the new text |
int Fl_Input_::static_value | ( | const char * | str, |
int | len | ||
) |
Changes the widget text.
This function changes the text and sets 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.
You can use the len
parameter to directly set the length if you know it already or want to put nul
characters in the text.
[in] | str | the new text |
[in] | len | the length of the new text |
void Fl_Input_::tab_nav | ( | int | val | ) | [inline] |
Sets whether the Tab key does focus navigation, or inserts tab characters into Fl_Multiline_Input.
By default this flag is enabled to provide the 'normal' behavior most users expect; Tab navigates focus to the next widget. To inserting an actual Tab character, users can use Ctrl-I or copy/paste.
Disabling this flag gives the old FLTK behavior where Tab inserts a tab character into the text field, in which case only the mouse can be used to navigate to the next field.
History: This flag was provided for backwards support of FLTK's old 1.1.x behavior where Tab inserts a tab character instead of navigating focus to the next widget. This behavior was unique to Fl_Multiline_Input. With the advent of Fl_Text_Editor, this old behavior has been deprecated.
[in] | val | If val is 1, Tab advances focus (default).If val is 0, Tab inserts a tab character (old FLTK behavior). |
int Fl_Input_::tab_nav | ( | ) | const [inline] |
Gets whether the Tab key causes focus navigation in multiline input fields or not.
If enabled (default), hitting Tab causes focus navigation to the next widget.
If disabled, hitting Tab inserts a tab character into the text field.
Fl_Color Fl_Input_::textcolor | ( | ) | const [inline] |
void Fl_Input_::textcolor | ( | Fl_Color | n | ) | [inline] |
Sets the color of the text in the input field.
The text color defaults to FL_FOREGROUND_COLOR
.
[in] | n | new text color |
Fl_Font Fl_Input_::textfont | ( | ) | const [inline] |
Gets the font of the text in the input field.
void Fl_Input_::textfont | ( | Fl_Font | s | ) | [inline] |
Sets the font of the text in the input field.
The text font defaults to FL_HELVETICA
.
[in] | s | the new text font |
Fl_Fontsize Fl_Input_::textsize | ( | ) | const [inline] |
Gets the size of the text in the input field.
void Fl_Input_::textsize | ( | Fl_Fontsize | s | ) | [inline] |
Sets the size of the text in the input field.
The text height defaults to FL_NORMAL_SIZE
.
[in] | s | the new font height in pixel units |
int Fl_Input_::undo | ( | ) |
Undoes previous changes to the text buffer.
This call undoes a number of previous calls to replace().
int Fl_Input_::up_down_position | ( | int | i, |
int | keepmark = 0 |
||
) | [protected] |
Moves the cursor to the column given by up_down_pos
.
This function is helpful when implementing up and down cursor movement. It moves the cursor from the beginning of a line to the column indicated by the global variable up_down_pos
in pixel units.
[in] | i | index into the beginning of a line of text |
[in] | keepmark | if set, move only the cursor, but not the mark |
int Fl_Input_::value | ( | const char * | str | ) |
Changes the widget text.
This function changes the text and sets the mark and the point to the end of it. The string is copied to the internal buffer. Passing NULL
is the same as ""
.
[in] | str | the new text |
Reimplemented in Fl_File_Input.
int Fl_Input_::value | ( | const char * | str, |
int | len | ||
) |
Changes the widget text.
This function changes the text and sets the mark and the point to the end of it. The string is copied to the internal buffer. Passing NULL
is the same as "".
You can use the length
parameter to directly set the length if you know it already or want to put nul
characters in the text.
[in] | str | the new text |
[in] | len | the length of the new text |
Reimplemented in Fl_File_Input.
const char* Fl_Input_::value | ( | ) | const [inline] |
Returns the text displayed in the widget.
This function returns the current value, which is a pointer to the internal buffer and is valid only until the next event is handled.
int Fl_Input_::word_end | ( | int | i | ) | const [protected] |
Finds the end of a word.
This call calculates the end of a word based on the given index i
. Calling this function repeatedly will move forwards to the end of the text.
[in] | i | starting index for the search |
int Fl_Input_::word_start | ( | int | i | ) | const [protected] |
Finds the start of a word.
This call calculates the start of a word based on the given index i
. Calling this function repeatedly will move backwards to the beginning of the text.
[in] | i | starting index for the search |
int Fl_Input_::wrap | ( | ) | const [inline] |
Gets the word wrapping state of the input field.
Word wrap is only functional with multi-line input fields.
void Fl_Input_::wrap | ( | int | b | ) | [inline] |
Sets the word wrapping state of the input field.
Word wrap is only functional with multi-line input fields.