FLTK 1.3.0
Fl_Input_ Class Reference

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

#include <Fl_Input_.H>

Inheritance diagram for Fl_Input_:
Fl_Widget Fl_Input Fl_File_Input Fl_Float_Input Fl_Int_Input Fl_Multiline_Input Fl_Output Fl_Secret_Input Fl_Multiline_Output

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.
void maximum_size (int m)
 Sets the maximum length of the input field.
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)
 Set 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, int, const char *, int=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 y)

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. 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,Hthe dimensions of the new widget
lan optional label text

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:
clipboardthe 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)

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]nthe 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:
nnumber 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,brange 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,Harea 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]iindex 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]tnew 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]ttext that will be inserted
[in]llength 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]istarting 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]istarting 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:
mnew 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.

Todo:
It is not clear if this function is actually required
void Fl_Input_::maximum_size ( int  m) [inline]

Sets the maximum length of the input field.

Todo:
It is not clear if this function is actually required
int Fl_Input_::position ( ) const [inline]

Gets the position of the text cursor.

Returns:
the cursor position as an index
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:
pindex for the cursor position
mindex 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]

Set the cursor position and mark.

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

Parameters:
pnew 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]bif 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 a and b (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.

b and e are clamped to the 0..size() range, so it is safe to pass any values.

cut() and insert() are just inline functions that call replace().

Parameters:
[in]bbeginning index of text to be deleted
[in]eending index of text to be deleted and insertion position
[in]textstring that will be inserted
[in]ilenlength of text or 0 for nul terminated strings
Returns:
0 if nothing changed
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,Hnew 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]snew 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,Hnew 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]strthe 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]strthe new text
[in]lenthe 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]valIf 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]nnew 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]sthe 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]sthe 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]iindex into the beginning of a line of text
[in]keepmarkif 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]strthe 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]strthe new text
[in]lenthe 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]istarting 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]istarting 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: