Inherited by fltk::FileInput, fltk::MultiLineInput, fltk::NumericInput, fltk::Output, fltk::SecretInput, and fltk::WordwrapInput.
Public Types | |
enum | { NORMAL, FLOAT_INPUT, INT_INPUT, SECRET, MULTILINE, WORDWRAP } |
Public Member Functions | |
char | at (int i) const |
bool | copy (bool clipboard=true) |
bool | cut (int a, int b) |
bool | cut (int n) |
bool | cut () |
void | draw (const Rectangle &) |
void | draw () |
int | handle (int event, const Rectangle &) |
int | handle (int) |
bool | handle_key () |
Input (int, int, int, int, const char *=0) | |
bool | insert (const char *t, int l) |
bool | insert (const char *t) |
int | line_end (int i) const |
int | line_start (int i) const |
void | mark (int m) |
int | mark () const |
void | maybe_do_callback () |
int | mouse_position (const Rectangle &) const |
void | position (int p) |
void | position (int p, int m) |
int | position () const |
bool | replace (int a, int b, char c) |
virtual bool | replace (int, int, const char *, int) |
void | reserve (int newsize) |
int | size () const |
bool | static_text (const char *, int) |
bool | static_text (const char *) |
bool | static_value (const char *v) |
const char * | text () const |
bool | text (const char *, int) |
bool | text (const char *) |
bool | undo () |
void | up_down_position (int position, bool extend) |
const char * | value () const |
bool | value (const char *v, int n) |
bool | value (const char *v) |
int | word_end (int i) const |
int | word_start (int i) const |
int | xscroll () const |
int | yscroll () const |
~Input () | |
Static Public Attributes | |
static NamedStyle * | default_style |
The default when() is WHEN_RELEASE. This is fine for a popup control panel where nothing happens until the panel is closed. But for most other uses of the input field you want to change it. Useful values are:
If you wish to restrict the text the user can type (such as limiting it to numbers, a particular length, etc), you should subclass this and override the replace() function with a version that rejects changes you don't want to allow.
If you don't like the keybindings you can override handle() to change them.
All arguments that are lengths or offsets into the strings are in bytes, not the UTF-8 characters they represent.
Input::Input | ( | int | x, | |
int | y, | |||
int | w, | |||
int | h, | |||
const char * | l = 0 | |||
) |
The constructor initializes:
References fltk::ALIGN_LEFT, fltk::ALIGN_MASK, fltk::Widget::clear_flag(), and fltk::Widget::set_flag().
Input::~Input | ( | ) |
The destructor destroys the memory used by text()
void Input::draw | ( | void | ) | [virtual] |
The default version draws the box and calls draw(x,y,w,h) with the area inside the box. It also draws any inside labels at the left of the text.
Reimplemented from fltk::Widget.
References fltk::ALIGN_INSIDE, fltk::Widget::damage(), fltk::DAMAGE_ALL, fltk::Widget::draw_frame(), fltk::drawtext(), fltk::fillrect(), fltk::Widget::flag(), fltk::Widget::flags(), fltk::getwidth(), fltk::Rectangle::h(), fltk::inactive(), fltk::INACTIVE_R, fltk::Symbol::inset(), fltk::Rectangle::move_x(), fltk::Rectangle::r(), fltk::setcolor(), fltk::setfont(), fltk::Rectangle::w(), fltk::Rectangle::x(), and fltk::Rectangle::y().
void Input::draw | ( | const Rectangle & | r | ) |
Draw the text, where the passed rectangle is the area the text is to be drawn into. This method is provided so a subclass can place the text into a subrectangle.
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.
References fltk::contrast(), fltk::Widget::damage(), fltk::DAMAGE_ALL, fltk::DAMAGE_EXPOSE, fltk::drawstyle(), fltk::drawtext(), fltk::fillrect(), fltk::Widget::flags(), fltk::Widget::focused(), fltk::getbgcolor(), fltk::getcolor(), fltk::Rectangle::h(), fltk::HIGHLIGHT, fltk::Rectangle::move_y(), fltk::pop_clip(), fltk::push_clip(), fltk::Widget::pushed(), fltk::Rectangle::r(), fltk::setcolor(), size(), fltk::transform(), fltk::Widget::type(), fltk::Rectangle::w(), fltk::Rectangle::x(), and fltk::Rectangle::y().
int Input::handle | ( | int | event | ) | [virtual] |
Calls handle(x,y,w,h) with the area inside the box().
Reimplemented from fltk::Widget.
Reimplemented in fltk::NumericInput.
References fltk::Rectangle::h(), fltk::Symbol::inset(), fltk::Rectangle::move_x(), fltk::Rectangle::r(), and fltk::Rectangle::w().
int Input::handle | ( | int | event, | |
const Rectangle & | r | |||
) |
Default handler for all event types, where the passed rectangle is the area the text is to be drawn into. This method is provided so a subclass can place the text into a subrectangle.
References fltk::Widget::add_timeout(), fltk::ALT, fltk::Widget::belowmouse(), copy(), fltk::CTRL, cut(), fltk::dnd(), fltk::DND_DRAG, fltk::DND_ENTER, fltk::DND_LEAVE, fltk::DND_RELEASE, fltk::DRAG, fltk::ENTER, fltk::event(), fltk::event_button(), fltk::event_clicks(), fltk::event_is_click(), fltk::event_key(), fltk::event_length(), fltk::event_state(), fltk::event_text(), fltk::FOCUS, fltk::Widget::focused(), handle_key(), fltk::HIDE, fltk::KEY, fltk::LEAVE, line_end(), line_start(), fltk::META, mouse_position(), fltk::MOVE, fltk::PASTE, fltk::paste(), fltk::PUSH, fltk::RELEASE, fltk::Widget::remove_timeout(), replace(), fltk::SHIFT, size(), fltk::Widget::take_focus(), fltk::TIMEOUT, fltk::Widget::type(), fltk::UNFOCUS, up_down_position(), word_end(), and word_start().
bool Input::handle_key | ( | ) |
Handle KEY events. The handle() method calls this. This provides an Emacs and Windows style of editing. Most Emacs commands are first run through fltk::try_shortcut() to test if they are menu items for the program.
For the (obsolete) MULTILINE mode you can also do these:
References fltk::BackSpaceKey, fltk::COMMAND, fltk::compose(), copy(), fltk::CTRL, cut(), fltk::DeleteKey, fltk::Widget::do_callback(), fltk::DownKey, fltk::EndKey, fltk::EscapeKey, fltk::event_key(), fltk::event_length(), fltk::event_state(), fltk::event_text(), fltk::Rectangle::h(), fltk::HomeKey, fltk::InsertKey, fltk::KeypadEnter, fltk::LeftCtrlKey, fltk::LeftKey, fltk::LeftShiftKey, line_end(), line_start(), fltk::OPTION, fltk::PageDownKey, fltk::PageUpKey, fltk::paste(), replace(), fltk::ReturnKey, fltk::RightCtrlKey, fltk::RightKey, fltk::RightShiftKey, fltk::SHIFT, size(), fltk::TabKey, fltk::try_shortcut(), fltk::Widget::type(), undo(), up_down_position(), fltk::UpKey, utf8back(), utf8fwd(), word_end(), and word_start().
Referenced by handle().
bool Input::text | ( | const char * | str | ) |
Same as text(str, str ? strlen(str) : 0)
References text().
bool Input::text | ( | const char * | str, | |
int | len | |||
) |
Change the text() to return the first len bytes of str and size() to return len, and set the position() to len and the mark() to zero (thus highlighting the entire value).
Returns true if the bytes in the new string are different than the old string.
References reserve(), and static_text().
bool Input::static_text | ( | const char * | str | ) |
Same as static_text(str, str ? strlen(str) : 0)
Referenced by text().
bool Input::static_text | ( | const char * | str, | |
int | len | |||
) |
Same as text(str,len), except it does not copy the string, instead it makes text() return a pointer to str (unless len is 0, in which case it makes it point to a zero-length string).
str must point to static memory that will not be altered until at least the Input widget is destroyed or the text() is changed again. If the user attempts to edit the string it is then copied to the internal buffer and the editing done there. This can save a lot of time and memory if your program is changing the string to various constants a lot but the user rarely edits it.
References size(), and fltk::Widget::type().
const char * Input::text | ( | ) | const [inline] |
The current string, as edited by the user. There is an extra NUL character at the end, so this returned pointer can be used directly by C functions. size() returns how many bytes are in the string, which is useful if you want to look at embedded NUL characters.
Pointer is to an internal buffer and is only value until the next event is handled by the Input widget.
Referenced by fltk::FloatInput::fvalue(), fltk::FloatInput::lvalue(), text(), and fltk::NumericInput::value().
char Input::at | ( | int | i | ) | const [inline] |
Same as text()[n], but may be faster in plausible implementations. No bounds checking is done.
Referenced by fltk::NumericInput::handle_arrow(), line_end(), line_start(), replace(), word_end(), and word_start().
int Input::size | ( | ) | const [inline] |
Returns the number of characters in text(). This may be greater than strlen(text()) if there are NUL characters in it.
Referenced by draw(), handle(), handle_key(), line_end(), mouse_position(), position(), static_text(), and word_end().
void Input::reserve | ( | int | len | ) |
void Input::position | ( | int | new_position, | |
int | 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 X selection, call copy() if you want that.
Changing these values causes a redraw(). The new values are bounds checked and limited to the size of the string.
It is up to the caller to make sure the position and mark are at the borders of UTF-8 characters!
Reimplemented from fltk::Widget.
References size().
void Input::position | ( | int | n | ) | [inline] |
void Input::up_down_position | ( | int | i, | |
bool | keepmark | |||
) |
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 false) to somewhere after i, such that pressing the arrows repeatedly will cause the point to move up and down.
References fltk::Rectangle::h(), fltk::Symbol::inset(), fltk::Rectangle::r(), fltk::Widget::type(), utf8back(), utf8fwd(), and fltk::Rectangle::w().
Referenced by handle(), and handle_key().
void Input::mark | ( | int | n | ) | [inline] |
Same as position(position(),n)
bool Input::replace | ( | int | b, | |
int | e, | |||
const char * | text, | |||
int | ilen | |||
) | [virtual] |
This call does all editing of the text. It deletes the region between b and e (either one may be less or equal to the other), and then inserts ilen (which may be zero) characters from the string text at that point and leaves the mark() and position() after the insertion. If the text is changed the callback is done if the when() flags indicate it should be done.
Subclasses of Input can override this method 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 Input::replace() only if they are all ok.
b and e are bounds checked so don't worry about sending values outside the length of the string.
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.
References at(), reserve(), and fltk::Widget::type().
Referenced by handle(), fltk::NumericInput::handle_arrow(), and handle_key().
bool Input::cut | ( | ) | [inline] |
Wrapper around replace(), this deletes the region between the point and the mark. It does nothing if they are equal.
Referenced by handle(), and handle_key().
bool Input::cut | ( | int | n | ) | [inline] |
Wrapper around replace() this deletes up to n characters after the point, or before the point if n is negative. N is bounds checked.
bool Input::cut | ( | int | a, | |
int | b | |||
) | [inline] |
Wrapper around replace() this deletes the characters between a and b. The values are clamped to the ends of the string, and b can be less than a.
bool Input::insert | ( | const char * | text | ) |
Wrapper around replace(). This inserts the string at the point and leaves the point after it.
bool Input::insert | ( | const char * | text, | |
int | n | |||
) | [inline] |
Wrapper around replace(). This inserts n characters from the text (including '\0' characters!) at the point and leaves the point after it.
bool Input::replace | ( | int | a, | |
int | b, | |||
char | c | |||
) | [inline] |
bool Input::copy | ( | bool | clipboard = true |
) |
Put the current selection between mark() and position() into the selection or clipboard by calling fltk::copy(). If position() and mark() are equal this does nothing (ie it does not clear the clipboard).
If clipboard is true the text is put into the user-visible cut & paste clipboard (this is probably what you want). If clipboard is 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.
References fltk::Rectangle::b(), and fltk::Widget::type().
Referenced by handle(), and handle_key().
bool Input::undo | ( | ) |
If this is the most recent widget on which replace() was done on, this will undo that replace() and probably several others (ie if the user has typed a lot of text it will undo all of it even though that was probably many calls to replace()). Returns true if any change was made.
References fltk::Rectangle::b(), and reserve().
Referenced by handle_key().
int Input::word_start | ( | int | i | ) | const |
Returns the location of the first word boundary at or before position.
References at(), and fltk::Widget::type().
Referenced by handle(), and handle_key().
int Input::word_end | ( | int | i | ) | const |
Returns the location of the next word boundary at or after position.
References at(), size(), and fltk::Widget::type().
Referenced by handle(), and handle_key().
int Input::line_start | ( | int | i | ) | const |
Returns the location of the start of the line containing the position.
References at(), fltk::Rectangle::h(), fltk::Symbol::inset(), fltk::Rectangle::r(), fltk::Widget::type(), and fltk::Rectangle::w().
Referenced by handle(), and handle_key().
int Input::line_end | ( | int | i | ) | const |
Returns the location of the next newline or wordwrap space at or after position.
References at(), fltk::Rectangle::h(), fltk::Symbol::inset(), fltk::Rectangle::r(), size(), fltk::Widget::type(), and fltk::Rectangle::w().
Referenced by handle(), and handle_key().
int Input::mouse_position | ( | const Rectangle & | r | ) | const |
Figure out what character the most recent mouse event would be pointing at, assumming you drew the text by calling draw() with the same rectangle. Returns 0 if the mouse is before the first character, and size() if it is after the last one.
References fltk::Rectangle::b(), fltk::event_x(), fltk::event_y(), size(), fltk::Widget::type(), utf8back(), utf8fwd(), fltk::Rectangle::w(), fltk::Rectangle::x(), and fltk::Rectangle::y().
Referenced by handle().