1998-10-20 01:39:29 +04:00
|
|
|
//
|
|
|
|
// Input base class header file for the Fast Light Tool Kit (FLTK).
|
|
|
|
//
|
2015-07-21 16:55:13 +03:00
|
|
|
// Copyright 1998-2015 by Bill Spitzak and others.
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
2011-07-19 08:49:30 +04:00
|
|
|
// This library is free software. Distribution and use rights are outlined in
|
|
|
|
// the file "COPYING" which should have been included with this file. If this
|
|
|
|
// file is missing or damaged, see the license at:
|
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/COPYING.php
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// Please see the following page on how to report bugs and issues:
|
2005-04-16 04:13:17 +04:00
|
|
|
//
|
2020-07-01 19:03:10 +03:00
|
|
|
// https://www.fltk.org/bugs.php
|
1998-10-20 01:39:29 +04:00
|
|
|
//
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2008-10-15 17:46:06 +04:00
|
|
|
/* \file
|
2008-09-16 11:26:22 +04:00
|
|
|
Fl_Input_ widget . */
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
#ifndef Fl_Input__H
|
|
|
|
#define Fl_Input__H
|
|
|
|
|
|
|
|
#ifndef Fl_Widget_H
|
|
|
|
#include "Fl_Widget.H"
|
|
|
|
#endif
|
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
#define FL_NORMAL_INPUT 0
|
|
|
|
#define FL_FLOAT_INPUT 1
|
|
|
|
#define FL_INT_INPUT 2
|
|
|
|
#define FL_HIDDEN_INPUT 3
|
|
|
|
#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)
|
2002-07-23 20:28:19 +04:00
|
|
|
#define FL_MULTILINE_OUTPUT_WRAP (FL_MULTILINE_INPUT | FL_INPUT_READONLY | FL_INPUT_WRAP)
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2022-11-26 22:28:12 +03:00
|
|
|
class Fl_Input_Undo_Action;
|
2023-02-10 19:13:20 +03:00
|
|
|
class Fl_Input_Undo_Action_List;
|
2022-11-26 22:28:12 +03:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
2009-04-18 22:52:59 +04:00
|
|
|
This class provides a low-overhead text input field.
|
|
|
|
|
2009-04-19 16:47:36 +04:00
|
|
|
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
|
2008-09-15 15:10:51 +04:00
|
|
|
one of those people who likes to change how the editing keys
|
2009-04-18 22:52:59 +04:00
|
|
|
work. It may also be useful for adding scrollbars
|
|
|
|
to the input field.
|
2010-12-15 19:58:08 +03:00
|
|
|
|
2009-04-19 16:47:36 +04:00
|
|
|
This can act like any of the subclasses of Fl_Input, by
|
|
|
|
setting type() to one of the following values:
|
2010-12-15 19:58:08 +03:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
\code
|
2020-07-01 19:03:10 +03:00
|
|
|
#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
|
2008-09-15 15:10:51 +04:00
|
|
|
#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)
|
|
|
|
\endcode
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2009-04-23 19:32:19 +04:00
|
|
|
All variables that represent an index into a text buffer are byte-oriented,
|
2011-12-06 20:55:51 +04:00
|
|
|
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.
|
2009-04-23 19:32:19 +04:00
|
|
|
|
2010-12-15 19:58:08 +03:00
|
|
|
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.
|
2009-04-23 19:32:19 +04:00
|
|
|
|
2009-04-19 16:47:36 +04:00
|
|
|
\see Fl_Text_Display, Fl_Text_Editor for more powerful text handling widgets
|
2020-01-26 21:14:45 +03:00
|
|
|
\see Fl_Widget::shortcut_label(int)
|
2009-04-23 19:32:19 +04:00
|
|
|
|
|
|
|
\internal
|
2010-12-15 19:58:08 +03:00
|
|
|
When porting this widget from ASCII to UTF-8, previously legal pointers into
|
2009-04-23 19:32:19 +04:00
|
|
|
the text of this widget can become illegal by pointing into the middle of
|
2010-12-15 19:58:08 +03:00
|
|
|
a UTF-8 sequence. This is not a big problem for Fl_Input_ because all code
|
2009-04-23 19:32:19 +04:00
|
|
|
in this module is quite tolerant. It could be problematic though when deriving
|
2010-12-15 19:58:08 +03:00
|
|
|
from this class because no feedback for illegal pointers is given. Additionally,
|
|
|
|
a careless "copy" call can put partial UTF-8 sequences into the clipboard.
|
2009-04-23 19:32:19 +04:00
|
|
|
|
2010-12-15 19:58:08 +03:00
|
|
|
None of these issues should be disastrous. Nevertheless, we should
|
|
|
|
discuss how FLTK should handle false UTF-8 sequences and pointers.
|
2008-09-15 15:10:51 +04:00
|
|
|
*/
|
2002-08-14 20:49:38 +04:00
|
|
|
class FL_EXPORT Fl_Input_ : public Fl_Widget {
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2009-04-18 22:52:59 +04:00
|
|
|
/** \internal Storage for the text field. */
|
1998-10-06 22:21:25 +04:00
|
|
|
const char* value_;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** \internal Buffer memory for expanded text. \see expand() */
|
1998-10-06 22:21:25 +04:00
|
|
|
char* buffer;
|
|
|
|
|
2009-04-18 22:52:59 +04:00
|
|
|
/** \internal Size of text in bytes in the \p value_ field. */
|
1998-10-06 22:21:25 +04:00
|
|
|
int size_;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2015-07-21 16:55:13 +03:00
|
|
|
/** \internal Current size of internal value() buffer in bytes. */
|
1998-10-06 22:21:25 +04:00
|
|
|
int bufsize;
|
2015-07-21 16:55:13 +03:00
|
|
|
|
2010-12-15 19:58:08 +03:00
|
|
|
/** \internal Position of the cursor in the document. */
|
1998-10-06 22:21:25 +04:00
|
|
|
int position_;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2015-07-21 16:55:13 +03:00
|
|
|
/** \internal Position of the other end of the selected text.
|
|
|
|
If \p position_ equals \p mark_, no text is selected */
|
1998-10-06 22:21:25 +04:00
|
|
|
int mark_;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
/** \internal Behavior of Tab key in multiline input widget.
|
|
|
|
If enabled (default) Tab causes focus nav, otherwise Tab is inserted
|
2010-12-20 10:48:59 +03:00
|
|
|
as a character. */
|
|
|
|
int tab_nav_;
|
|
|
|
|
2009-09-20 01:16:21 +04:00
|
|
|
/** \internal Offset to text origin within widget bounds */
|
1998-10-06 22:21:25 +04:00
|
|
|
int xscroll_, yscroll_;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2010-12-15 19:58:08 +03:00
|
|
|
/** \internal Minimal update pointer. Display requires redraw from here to the end
|
2009-04-18 22:52:59 +04:00
|
|
|
of the buffer. */
|
1998-10-06 22:21:25 +04:00
|
|
|
int mu_p;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2015-07-21 16:55:13 +03:00
|
|
|
/** \internal Maximum number of (UTF-8) characters a user can input. */
|
1998-10-06 22:21:25 +04:00
|
|
|
int maximum_size_;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2009-07-18 15:03:44 +04:00
|
|
|
/** \internal Shortcut key that will fetch focus for this widget. */
|
2008-04-23 03:33:17 +04:00
|
|
|
int shortcut_;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2009-04-18 22:52:59 +04:00
|
|
|
/** \internal This is set if no text but only the cursor needs updating. */
|
2001-10-29 06:44:33 +03:00
|
|
|
uchar erase_cursor_only;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** \internal The font used for the entire text. */
|
2008-04-23 23:09:28 +04:00
|
|
|
Fl_Font textfont_;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** \internal Height of the font used for the entire text. */
|
2008-08-16 01:11:21 +04:00
|
|
|
Fl_Fontsize textsize_;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** \internal color of the entire text */
|
2009-09-27 15:06:56 +04:00
|
|
|
Fl_Color textcolor_;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** \internal color of the text cursor */
|
2009-09-27 15:06:56 +04:00
|
|
|
Fl_Color cursor_color_;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2022-11-26 22:28:12 +03:00
|
|
|
/** \internal local undo event */
|
|
|
|
Fl_Input_Undo_Action* undo_;
|
2023-02-10 19:13:20 +03:00
|
|
|
Fl_Input_Undo_Action_List* undo_list_;
|
|
|
|
Fl_Input_Undo_Action_List* redo_list_;
|
2022-11-26 22:28:12 +03:00
|
|
|
|
2010-12-15 19:58:08 +03:00
|
|
|
/** \internal Horizontal cursor position in pixels while moving up or down. */
|
2009-04-18 22:52:59 +04:00
|
|
|
static double up_down_pos;
|
|
|
|
|
2010-07-10 13:44:45 +04:00
|
|
|
/** \internal Flag to remember last cursor move. */
|
2009-04-18 22:52:59 +04:00
|
|
|
static int was_up_down;
|
|
|
|
|
|
|
|
/* Convert a given text segment into the text that will be rendered on screen. */
|
2002-08-14 20:49:38 +04:00
|
|
|
const char* expand(const char*, char*) const;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/* Calculates the width in pixels of part of a text buffer. */
|
2002-08-14 20:49:38 +04:00
|
|
|
double expandpos(const char*, const char*, const char*, int*) const;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/* Mark a range of characters for update. */
|
2002-08-14 20:49:38 +04:00
|
|
|
void minimal_update(int, int);
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/* Mark a range of characters for update. */
|
2002-08-14 20:49:38 +04:00
|
|
|
void minimal_update(int p);
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/* Copy the value from a possibly static entry into the internal buffer. */
|
2002-08-14 20:49:38 +04:00
|
|
|
void put_in_buffer(int newsize);
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2009-04-18 22:52:59 +04:00
|
|
|
/* Set the current font and font size. */
|
2002-08-14 20:49:38 +04:00
|
|
|
void setfont() const;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2009-07-18 15:03:44 +04:00
|
|
|
/* Find the start of a word. */
|
2002-08-14 20:49:38 +04:00
|
|
|
int word_start(int i) const;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2009-07-18 15:03:44 +04:00
|
|
|
/* Find the end of a word. */
|
2002-08-14 20:49:38 +04:00
|
|
|
int word_end(int i) const;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2009-07-18 15:03:44 +04:00
|
|
|
/* Find the start of a line. */
|
2002-08-14 20:49:38 +04:00
|
|
|
int line_start(int i) const;
|
2020-07-01 19:03:10 +03:00
|
|
|
|
2009-07-18 15:03:44 +04:00
|
|
|
/* Find the end of a line. */
|
2002-08-14 20:49:38 +04:00
|
|
|
int line_end(int i) const;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/* Draw the text in the passed bounding box. */
|
2002-08-14 20:49:38 +04:00
|
|
|
void drawtext(int, int, int, int);
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2023-08-03 18:35:19 +03:00
|
|
|
/* Draw the text in the passed bounding box. */
|
|
|
|
void drawtext(int, int, int, int, bool draw_active);
|
|
|
|
|
2009-04-18 22:52:59 +04:00
|
|
|
/* Move the cursor to the column given by up_down_pos. */
|
2002-08-14 20:49:38 +04:00
|
|
|
int up_down_position(int, int keepmark=0);
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2010-12-15 19:58:08 +03:00
|
|
|
/* Handle mouse clicks and mouse moves. */
|
2002-08-14 20:49:38 +04:00
|
|
|
void handle_mouse(int, int, int, int, int keepmark=0);
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/* Handle all kinds of text field related events. */
|
2002-08-14 20:49:38 +04:00
|
|
|
int handletext(int e, int, int, int, int);
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/* Check the when() field and do a callback if indicated. */
|
2023-01-05 15:51:30 +03:00
|
|
|
void maybe_do_callback(Fl_Callback_Reason reason = FL_REASON_UNKNOWN);
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** \internal Horizontal offset of text to left edge of widget. */
|
1998-10-06 22:21:25 +04:00
|
|
|
int xscroll() const {return xscroll_;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** \internal Vertical offset of text to top edge of widget. */
|
1998-10-06 22:21:25 +04:00
|
|
|
int yscroll() const {return yscroll_;}
|
2011-10-02 10:25:13 +04:00
|
|
|
void yscroll(int yOffset) { yscroll_ = yOffset; damage(FL_DAMAGE_EXPOSE);}
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2009-04-18 22:52:59 +04:00
|
|
|
/* Return the number of lines displayed on a single page. */
|
|
|
|
int linesPerPage();
|
|
|
|
|
2023-02-10 19:13:20 +03:00
|
|
|
/* Apply the current undo/redo operation, called from undo() or redo() */
|
|
|
|
int apply_undo();
|
|
|
|
|
1998-10-06 22:21:25 +04:00
|
|
|
public:
|
|
|
|
|
2009-04-18 22:52:59 +04:00
|
|
|
/* Change the size of the widget. */
|
2022-12-30 21:14:36 +03:00
|
|
|
void resize(int, int, int, int) FL_OVERRIDE;
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2009-07-18 15:03:44 +04:00
|
|
|
/* Constructor */
|
2002-08-14 20:49:38 +04:00
|
|
|
Fl_Input_(int, int, int, int, const char* = 0);
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/* Destructor */
|
2002-08-14 20:49:38 +04:00
|
|
|
~Fl_Input_();
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2009-04-18 22:52:59 +04:00
|
|
|
/* Changes the widget text. */
|
2002-08-14 20:49:38 +04:00
|
|
|
int value(const char*);
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/* Changes the widget text. */
|
2002-08-14 20:49:38 +04:00
|
|
|
int value(const char*, int);
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2023-11-06 21:09:48 +03:00
|
|
|
/* Changes the widget text. */
|
|
|
|
int value(int value);
|
|
|
|
|
|
|
|
/* Changes the widget text. */
|
|
|
|
int value(double value);
|
|
|
|
|
2009-04-18 22:52:59 +04:00
|
|
|
/* Changes the widget text. */
|
2002-08-14 20:49:38 +04:00
|
|
|
int static_value(const char*);
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/* Changes the widget text. */
|
2002-08-14 20:49:38 +04:00
|
|
|
int static_value(const char*, int);
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
2009-04-18 22:52:59 +04:00
|
|
|
Returns the text displayed in the widget.
|
|
|
|
|
|
|
|
This function returns the current value, which is a pointer
|
2008-09-15 15:10:51 +04:00
|
|
|
to the internal buffer and is valid only until the next event is
|
|
|
|
handled.
|
2020-07-01 19:03:10 +03:00
|
|
|
|
|
|
|
\return pointer to an internal buffer - do not free() this
|
2009-04-19 16:47:36 +04:00
|
|
|
\see Fl_Input_::value(const char*)
|
2008-09-15 15:10:51 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
const char* value() const {return value_;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2023-11-06 21:09:48 +03:00
|
|
|
int ivalue() const;
|
|
|
|
|
2023-11-16 00:45:15 +03:00
|
|
|
double dvalue() const;
|
2023-11-06 21:09:48 +03:00
|
|
|
|
2021-08-30 13:01:32 +03:00
|
|
|
/* Returns the Unicode character at index \p i. */
|
|
|
|
unsigned int index(int i) const;
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
2020-07-01 19:03:10 +03:00
|
|
|
Returns the number of bytes in value().
|
|
|
|
|
|
|
|
This may be greater than <tt>strlen(value())</tt> if there are
|
2009-04-18 22:52:59 +04:00
|
|
|
\c nul characters in the text.
|
|
|
|
|
|
|
|
\return number of bytes in the text
|
2008-09-15 15:10:51 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int size() const {return size_;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** Sets the width and height of this widget.
|
|
|
|
\param [in] W, H new width and height
|
2009-04-19 16:47:36 +04:00
|
|
|
\see Fl_Widget::size(int, int) */
|
2003-06-15 08:47:28 +04:00
|
|
|
void size(int W, int H) { Fl_Widget::size(W, H); }
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2011-12-06 20:55:51 +04:00
|
|
|
/** Gets the maximum length of the input field in characters.
|
|
|
|
\see maximum_size(int). */
|
1998-10-06 22:21:25 +04:00
|
|
|
int maximum_size() const {return maximum_size_;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2011-12-06 20:55:51 +04:00
|
|
|
/** Sets the maximum length of the input field in characters.
|
2015-07-21 16:55:13 +03:00
|
|
|
|
2011-12-06 20:55:51 +04:00
|
|
|
This limits the number of <b>characters</b> that can be inserted
|
|
|
|
in the widget.
|
2015-07-21 16:55:13 +03:00
|
|
|
|
|
|
|
Since FLTK 1.3 this is different than the buffer size, since one
|
2011-12-06 20:55:51 +04:00
|
|
|
character can be more than one byte in UTF-8 encoding. In FLTK 1.1
|
|
|
|
this was the same (one byte = one character).
|
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
void maximum_size(int m) {maximum_size_ = m;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** Gets the position of the text cursor.
|
2011-12-06 20:55:51 +04:00
|
|
|
\return the cursor position as an index in the range 0..size()
|
2023-02-02 22:54:19 +03:00
|
|
|
\see insert_position(int, int)
|
2008-09-15 15:10:51 +04:00
|
|
|
*/
|
2023-02-02 22:54:19 +03:00
|
|
|
int insert_position() const { return position_; }
|
2024-11-01 19:48:13 +03:00
|
|
|
FL_DEPRECATED("since 1.4.0 - use insert_position() instead",
|
2023-02-02 22:54:19 +03:00
|
|
|
int position() const ) { return insert_position(); }
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
/** Gets the current selection mark.
|
2009-04-18 22:52:59 +04:00
|
|
|
\return index into the text */
|
1998-10-06 22:21:25 +04:00
|
|
|
int mark() const {return mark_;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/* Sets the index for the cursor and mark. */
|
2023-02-02 22:54:19 +03:00
|
|
|
int insert_position(int p, int m);
|
2024-11-01 19:48:13 +03:00
|
|
|
FL_DEPRECATED("since 1.4.0 - use insert_position(p, m) or Fl_Widget::position(x, y) instead",
|
2023-02-02 22:54:19 +03:00
|
|
|
int position(int p, int m)) { return insert_position(p, m); }
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2011-12-06 20:55:51 +04:00
|
|
|
/** Sets the cursor position and mark.
|
2009-04-19 16:47:36 +04:00
|
|
|
position(n) is the same as <tt>position(n, n)</tt>.
|
2009-04-18 22:52:59 +04:00
|
|
|
\param p new index for cursor and mark
|
2009-04-19 16:47:36 +04:00
|
|
|
\return 0 if no positions changed
|
2023-02-02 22:54:19 +03:00
|
|
|
\see insert_position(int, int), insert_position(), mark(int)
|
2009-04-18 22:52:59 +04:00
|
|
|
*/
|
2023-02-02 22:54:19 +03:00
|
|
|
int insert_position(int p) { return insert_position(p, p); }
|
2024-11-01 19:48:13 +03:00
|
|
|
FL_DEPRECATED("since 1.4.0 - use insert_position(p) instead",
|
2023-02-02 22:54:19 +03:00
|
|
|
int position(int p)) { return insert_position(p); }
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
/** Sets the current selection mark.
|
2023-02-02 22:54:19 +03:00
|
|
|
mark(n) is the same as <tt>insert_position(insert_position(),n)</tt>.
|
2020-07-01 19:03:10 +03:00
|
|
|
\param m new index of the mark
|
2009-04-19 16:47:36 +04:00
|
|
|
\return 0 if the mark did not change
|
2023-02-02 22:54:19 +03:00
|
|
|
\see insert_position(), insert_position(int, int) */
|
|
|
|
int mark(int m) {return insert_position(insert_position(), m);}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2011-12-06 20:55:51 +04:00
|
|
|
/* Deletes text from \p b to \p e and inserts the new string \p text. */
|
|
|
|
int replace(int b, int e, const char *text, int ilen=0);
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
|
|
|
Deletes the current selection.
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
This function deletes the currently selected text
|
|
|
|
\e without storing it in the clipboard. To use the clipboard,
|
2009-04-19 16:47:36 +04:00
|
|
|
you may call copy() first or copy_cuts() after
|
2009-04-18 22:52:59 +04:00
|
|
|
this call.
|
|
|
|
|
2009-04-19 16:47:36 +04:00
|
|
|
\return 0 if no data was copied
|
2008-09-15 15:10:51 +04:00
|
|
|
*/
|
2023-02-02 22:54:19 +03:00
|
|
|
int cut() {return replace(insert_position(), mark(), 0);}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Deletes the next \p n bytes rounded to characters before or after the cursor.
|
|
|
|
|
|
|
|
This function deletes the currently selected text
|
|
|
|
\e without storing it in the clipboard. To use the clipboard,
|
2009-04-19 16:47:36 +04:00
|
|
|
you may call copy() first or copy_cuts() after
|
2009-04-18 22:52:59 +04:00
|
|
|
this call.
|
|
|
|
|
|
|
|
\param 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.
|
2009-04-19 16:47:36 +04:00
|
|
|
\return 0 if no data was copied
|
2009-04-18 22:52:59 +04:00
|
|
|
*/
|
2023-02-02 22:54:19 +03:00
|
|
|
int cut(int n) {return replace(insert_position(), insert_position()+n, 0);}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
Deletes all characters between index \p a and \p b.
|
|
|
|
|
|
|
|
This function deletes the currently selected text
|
|
|
|
\e without storing it in the clipboard. To use the clipboard,
|
2009-04-19 16:47:36 +04:00
|
|
|
you may call copy() first or copy_cuts() after
|
2009-04-18 22:52:59 +04:00
|
|
|
this call.
|
|
|
|
|
|
|
|
\param a, b range of bytes rounded to full characters and clamped to the buffer
|
2009-04-19 16:47:36 +04:00
|
|
|
\return 0 if no data was copied
|
2009-04-18 22:52:59 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int cut(int a, int b) {return replace(a, b, 0);}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
2009-04-18 22:52:59 +04:00
|
|
|
Inserts text at the cursor position.
|
|
|
|
|
|
|
|
This function inserts the string in \p t at the cursor
|
2009-04-19 16:47:36 +04:00
|
|
|
position() and moves the new position and mark to
|
2009-04-18 22:52:59 +04:00
|
|
|
the end of the inserted text.
|
|
|
|
|
|
|
|
\param [in] t text that will be inserted
|
2009-04-19 16:47:36 +04:00
|
|
|
\param [in] l length of text, or 0 if the string is terminated by \c nul.
|
|
|
|
\return 0 if no text was inserted
|
2008-09-15 15:10:51 +04:00
|
|
|
*/
|
1998-10-06 22:21:25 +04:00
|
|
|
int insert(const char* t, int l=0){return replace(position_, mark_, t, l);}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2019-02-03 00:04:15 +03:00
|
|
|
/* Append text at the end. */
|
|
|
|
int append(const char* t, int l=0, char keep_selection=0);
|
|
|
|
|
2009-04-18 22:52:59 +04:00
|
|
|
/* Put the current selection into the clipboard. */
|
2002-08-14 20:49:38 +04:00
|
|
|
int copy(int clipboard);
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/* Undo previous changes to the text buffer. */
|
2002-08-14 20:49:38 +04:00
|
|
|
int undo();
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2023-04-14 17:32:23 +03:00
|
|
|
/* Return true if the last operation can be undone. */
|
2023-04-17 17:12:03 +03:00
|
|
|
bool can_undo() const;
|
2023-04-14 17:32:23 +03:00
|
|
|
|
2023-02-10 19:13:20 +03:00
|
|
|
/* Redo previous undo operations. */
|
|
|
|
int redo();
|
|
|
|
|
2023-04-14 17:32:23 +03:00
|
|
|
/* Return true if there is a redo action in the list. */
|
2023-04-17 17:12:03 +03:00
|
|
|
bool can_redo() const;
|
2023-04-14 17:32:23 +03:00
|
|
|
|
2009-04-18 22:52:59 +04:00
|
|
|
/* Copy the yank buffer to the clipboard. */
|
2002-08-14 20:49:38 +04:00
|
|
|
int copy_cuts();
|
1998-10-06 22:21:25 +04:00
|
|
|
|
2010-12-15 19:58:08 +03:00
|
|
|
/** Return the shortcut key associated with this widget.
|
2009-04-18 22:52:59 +04:00
|
|
|
\return shortcut keystroke
|
|
|
|
\see Fl_Button::shortcut() */
|
2008-04-23 03:33:17 +04:00
|
|
|
int shortcut() const {return shortcut_;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
/**
|
2010-12-15 19:58:08 +03:00
|
|
|
Sets the shortcut key associated with this widget.
|
2009-04-18 22:52:59 +04:00
|
|
|
Pressing the shortcut key gives text editing focus to this widget.
|
2020-07-01 19:03:10 +03:00
|
|
|
\param [in] s new shortcut keystroke
|
|
|
|
\see Fl_Button::shortcut()
|
2009-04-18 22:52:59 +04:00
|
|
|
*/
|
2008-04-23 03:33:17 +04:00
|
|
|
void shortcut(int s) {shortcut_ = s;}
|
|
|
|
|
2009-04-18 22:52:59 +04:00
|
|
|
/** Gets the font of the text in the input field.
|
2009-04-19 16:47:36 +04:00
|
|
|
\return the current Fl_Font index */
|
2008-04-23 23:09:28 +04:00
|
|
|
Fl_Font textfont() const {return textfont_;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** Sets the font of the text in the input field.
|
|
|
|
The text font defaults to \c FL_HELVETICA.
|
|
|
|
\param [in] s the new text font */
|
2008-04-23 23:09:28 +04:00
|
|
|
void textfont(Fl_Font s) {textfont_ = s;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** Gets the size of the text in the input field.
|
|
|
|
\return the text height in pixels */
|
2008-08-16 01:11:21 +04:00
|
|
|
Fl_Fontsize textsize() const {return textsize_;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** Sets the size of the text in the input field.
|
|
|
|
The text height defaults to \c FL_NORMAL_SIZE.
|
|
|
|
\param [in] s the new font height in pixel units */
|
2008-08-16 01:11:21 +04:00
|
|
|
void textsize(Fl_Fontsize s) {textsize_ = s;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** Gets the color of the text in the input field.
|
|
|
|
\return the text color
|
2009-09-27 15:06:56 +04:00
|
|
|
\see textcolor(Fl_Color) */
|
|
|
|
Fl_Color textcolor() const {return textcolor_;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
|
|
|
/** Sets the color of the text in the input field.
|
|
|
|
The text color defaults to \c FL_FOREGROUND_COLOR.
|
|
|
|
\param [in] n new text color
|
2009-04-19 16:47:36 +04:00
|
|
|
\see textcolor() */
|
2009-09-27 15:06:56 +04:00
|
|
|
void textcolor(Fl_Color n) {textcolor_ = n;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
/** Gets the color of the cursor.
|
2009-04-18 22:52:59 +04:00
|
|
|
\return the current cursor color */
|
2009-09-27 15:06:56 +04:00
|
|
|
Fl_Color cursor_color() const {return cursor_color_;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
/** Sets the color of the cursor.
|
2009-04-18 22:52:59 +04:00
|
|
|
The default color for the cursor is \c FL_BLACK.
|
|
|
|
\param [in] n the new cursor color */
|
2009-09-27 15:06:56 +04:00
|
|
|
void cursor_color(Fl_Color n) {cursor_color_ = n;}
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
/** Gets the input field type.
|
2009-04-18 22:52:59 +04:00
|
|
|
\return the current input type */
|
2002-04-11 15:52:43 +04:00
|
|
|
int input_type() const {return type() & FL_INPUT_TYPE; }
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
/** Sets the input field type.
|
2009-04-19 16:47:36 +04:00
|
|
|
A redraw() is required to reformat the input field.
|
2009-04-18 22:52:59 +04:00
|
|
|
\param [in] t new input type */
|
2002-11-19 19:37:36 +03:00
|
|
|
void input_type(int t) { type((uchar)(t | readonly())); }
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
/** Gets the read-only state of the input field.
|
2009-04-18 22:52:59 +04:00
|
|
|
\return non-zero if this widget is read-only */
|
2002-04-11 15:52:43 +04:00
|
|
|
int readonly() const { return type() & FL_INPUT_READONLY; }
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
/** Sets the read-only state of the input field.
|
2009-04-19 16:47:36 +04:00
|
|
|
\param [in] b if \p b is 0, the text in this widget can be edited by the user */
|
2002-11-19 19:37:36 +03:00
|
|
|
void readonly(int b) { if (b) type((uchar)(type() | FL_INPUT_READONLY));
|
|
|
|
else type((uchar)(type() & ~FL_INPUT_READONLY)); }
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
2020-07-01 19:03:10 +03:00
|
|
|
Gets the word wrapping state of the input field.
|
2009-04-18 22:52:59 +04:00
|
|
|
Word wrap is only functional with multi-line input fields.
|
2008-09-15 15:10:51 +04:00
|
|
|
*/
|
2002-07-23 20:28:19 +04:00
|
|
|
int wrap() const { return type() & FL_INPUT_WRAP; }
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2008-09-15 15:10:51 +04:00
|
|
|
/**
|
2020-07-01 19:03:10 +03:00
|
|
|
Sets the word wrapping state of the input field.
|
2009-04-18 22:52:59 +04:00
|
|
|
Word wrap is only functional with multi-line input fields.
|
2008-09-15 15:10:51 +04:00
|
|
|
*/
|
2002-11-19 19:37:36 +03:00
|
|
|
void wrap(int b) { if (b) type((uchar)(type() | FL_INPUT_WRAP));
|
|
|
|
else type((uchar)(type() & ~FL_INPUT_WRAP)); }
|
2009-04-18 22:52:59 +04:00
|
|
|
|
2010-12-20 10:48:59 +03:00
|
|
|
/**
|
2020-07-01 19:03:10 +03:00
|
|
|
Sets whether the Tab key does focus navigation,
|
2010-12-20 10:48:59 +03:00
|
|
|
or inserts tab characters into Fl_Multiline_Input.
|
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
By default this flag is enabled to provide the 'normal' behavior
|
|
|
|
most users expect; Tab navigates focus to the next widget.
|
2010-12-20 10:48:59 +03:00
|
|
|
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
|
2020-07-01 19:03:10 +03:00
|
|
|
behavior where Tab inserts a tab character instead of navigating
|
|
|
|
focus to the next widget. This behavior was unique to Fl_Multiline_Input.
|
2010-12-20 10:48:59 +03:00
|
|
|
With the advent of Fl_Text_Editor, this old behavior has been deprecated.
|
|
|
|
|
|
|
|
\param [in] val If \p val is 1, Tab advances focus (default).<BR>
|
|
|
|
If \p val is 0, Tab inserts a tab character (old FLTK behavior).
|
2014-04-29 06:56:34 +04:00
|
|
|
|
|
|
|
\see tab_nav(), Fl::OPTION_ARROW_FOCUS.
|
2010-12-20 10:48:59 +03:00
|
|
|
*/
|
|
|
|
void tab_nav(int val) {
|
|
|
|
tab_nav_ = val;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
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.
|
2014-04-29 06:56:34 +04:00
|
|
|
|
|
|
|
\see tab_nav(int), Fl::OPTION_ARROW_FOCUS.
|
2010-12-20 10:48:59 +03:00
|
|
|
*/
|
|
|
|
int tab_nav() const {
|
|
|
|
return tab_nav_;
|
|
|
|
}
|
1998-10-06 22:21:25 +04:00
|
|
|
};
|
|
|
|
|
2020-07-01 19:03:10 +03:00
|
|
|
#endif
|