FLTK 1.3.2

- Main Page
- Related Pages
- Modules
- Classes
- Files

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Protected Member Functions
Fl_Input_ Class Reference

This class provides a low-overhead text input field. More...

`#include <Fl_Input_.H>`

Inheritance diagram for Fl_Input_:

List of all members.

## 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)

## Detailed Description

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.

See also:
  Fl_Text_Display, Fl_Text_Editor for more powerful text handling widgets

## Constructor & Destructor Documentation

Fl_Input_::Fl_Input_ | ( | int | X,
|  | int | Y,
|  | int | W,
|  | int | H,
|  | const char * | l = `0`
| ) |  |

Creates a new Fl_Input_ widget.

This function creates a new Fl_Input_ widget and adds it to the current Fl_Group. The value() is set to `NULL`. The default boxtype is `FL_DOWN_BOX`.

Parameters:

  X,Y,W,H | the dimensions of the new widget
  l | an optional label text

Fl_Input_::~Fl_Input_ | ( |  | ) |

Destroys the widget.

The destructor clears all allocated buffers and removes the widget from the parent Fl_Group.

## Member Function Documentation

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.

Parameters:

  clipboard | the clipboard destination 0 or 1

Returns:
  0 if no text is selected, 1 if the selection was copied

See also:
  Fl::copy(const char *, int, int)

int Fl_Input_::copy_cuts | ( |  | ) |

Copies the yank buffer to the clipboard.

This method copies all the previous contiguous cuts from the undo information to the clipboard. This function implements the `^K` shortcut key.

Returns:
  0 if the operation did not change the clipboard

See also:
  copy(int), cut()

Fl_Color Fl_Input_::cursor_color | ( |  | ) | const`[inline]`

Gets the color of the cursor.

Returns:
  the current cursor color

void Fl_Input_::cursor_color | ( | Fl_Color | n | ) | `[inline]`

Sets the color of the cursor.

The default color for the cursor is `FL_BLACK`.

Parameters:

  [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.

Returns:
  0 if no data was copied

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.

Parameters:

  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.

Returns:
  0 if no data was copied

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.

Parameters:

  a,b | range of bytes rounded to full characters and clamped to the buffer

Returns:
  0 if no data was copied

void Fl_Input_::drawtext | ( | int | X,
|  | int | Y,
|  | int | W,
|  | int | H
| ) |  | `[protected]`

Draws the text in the passed bounding box.

If `damage() & FL_DAMAGE_ALL` is true, this assumes the area has already been erased to color(). Otherwise it does minimal update and erases the area itself.

Parameters:

  X,Y,W,H | area that must be redrawn

void Fl_Input_::handle_mouse | ( | int | X,
|  | int | Y,
|  | int | ,
|  | int | ,
|  | int | drag = `0`
| ) |  | `[protected]`

Handles mouse clicks and mouse moves.

Todo:
  Add comment and parameters

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.

Todo:
  Add comment and parameters

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.

Parameters:

  [in] | i | index into the value field

Returns:
  the character at index `i`

int Fl_Input_::input_type | ( |  | ) | const`[inline]`

Gets the input field type.

Returns:
  the current input type

void Fl_Input_::input_type | ( | int | t | ) | `[inline]`

Sets the input field type.

A redraw() is required to reformat the input field.

Parameters:

  [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.

Parameters:

  [in] | t | text that will be inserted
  [in] | l | length of text, or 0 if the string is terminated by `nul`.

Returns:
  0 if no text was inserted

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`.

Parameters:

  [in] | i | starting index for the search

Returns:
  end of the line

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`.

Parameters:

  [in] | i | starting index for the search

Returns:
  start of the line

int Fl_Input_::mark | ( |  | ) | const`[inline]`

Gets the current selection mark.

Returns:
  index into the text

int Fl_Input_::mark | ( | int | m | ) | `[inline]`

Sets the current selection mark.

mark(n) is the same as `position(position(),n)`.

Parameters:

  m | new index of the mark

Returns:
  0 if the mark did not change

See also:
  position(), position(int, int)

int Fl_Input_::maximum_size | ( |  | ) | const`[inline]`

Gets the maximum length of the input field in characters.

See also:
  maximum_size(int).

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.

Since:
  FLTK 1.3 this is different than the buffer size, since one character can be more than one byte in UTF-8 encoding. In FLTK 1.1 this was the same (one byte = one character).

int Fl_Input_::position | ( |  | ) | const`[inline]`

Gets the position of the text cursor.

Returns:
  the cursor position as an index in the range 0..size()

See also:
  position(int, int)

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.

Parameters:

  p | index for the cursor position
  m | index for the mark

Returns:
  0 if no positions changed

See also:
  position(int), position(), mark(int)

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)`.

Parameters:

  p | new index for cursor and mark

Returns:
  0 if no positions changed

See also:
  position(int, int), position(), mark(int)

int Fl_Input_::readonly | ( |  | ) | const`[inline]`

Gets the read-only state of the input field.

Returns:
  non-zero if this widget is read-only

void Fl_Input_::readonly | ( | int | b | ) | `[inline]`

Sets the read-only state of the input field.

Parameters:

  [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().

Parameters:

  [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

Returns:
  0 if nothing changed

Note:
  If `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.

Parameters:

  [in] | X,Y,W,H | new size of the widget

See also:
  Fl_Widget::resize(int, int, int, int)

Reimplemented from Fl_Widget.

int Fl_Input_::shortcut | ( |  | ) | const`[inline]`

Return the shortcut key associated with this widget.

Returns:
  shortcut keystroke

See also:
  Fl_Button::shortcut()

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.

Parameters:

  [in] | s | new shortcut keystroke

See also:
  Fl_Button::shortcut()

int Fl_Input_::size | ( |  | ) | const`[inline]`

Returns the number of bytes in value().

This may be greater than `strlen(value())` if there are `nul` characters in the text.

Returns:
  number of bytes in the text

void Fl_Input_::size | ( | int | W,
|  | int | H
| ) |  | `[inline]`

Sets the width and height of this widget.

Parameters:

  [in] | W,H | new width and height

See also:
  Fl_Widget::size(int, int)

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.

Parameters:

  [in] | str | the new text

Returns:
  non-zero if the new value is different than the current one

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.

Parameters:

  [in] | str | the new text
  [in] | len | the length of the new text

Returns:
  non-zero if the new value is different than the current one

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.

Parameters:

  [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.

Returns:
  1 if Tab advances focus (default), 0 if Tab inserts tab characters.

See also:
  tab_nav(int)

Fl_Color Fl_Input_::textcolor | ( |  | ) | const`[inline]`

Gets the color of the text in the input field.

Returns:
  the text color

See also:
  textcolor(Fl_Color)

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`.

Parameters:

  [in] | n | new text color

See also:
  textcolor()

Fl_Font Fl_Input_::textfont | ( |  | ) | const`[inline]`

Gets the font of the text in the input field.

Returns:
  the current Fl_Font index

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`.

Parameters:

  [in] | s | the new text font

Fl_Fontsize Fl_Input_::textsize | ( |  | ) | const`[inline]`

Gets the size of the text in the input field.

Returns:
  the text height in pixels

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`.

Parameters:

  [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().

Returns:
  non-zero if any change was made.

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.

Parameters:

  [in] | i | index into the beginning of a line of text
  [in] | keepmark | if set, move only the cursor, but not the mark

Returns:
  index to new cursor position

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 `""`.

Parameters:

  [in] | str | the new text

Returns:
  non-zero if the new value is different than the current one

See also:
  Fl_Input_::value(const char* str, int len), Fl_Input_::value()

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.

Parameters:

  [in] | str | the new text
  [in] | len | the length of the new text

Returns:
  non-zero if the new value is different than the current one

See also:
  Fl_Input_::value(const char* str), Fl_Input_::value()

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.

Returns:
  pointer to an internal buffer - do not free() this

See also:
  Fl_Input_::value(const char*)

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.

Parameters:

  [in] | i | starting index for the search

Returns:
  end of the word

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.

Parameters:

  [in] | i | starting index for the search

Returns:
  start of the word

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.

The documentation for this class was generated from the following files:

- Fl_Input_.H
- Fl_Input_.cxx