|
class TextCtrl : public Ctrl, protected TextArrayOps
A base class that implements operations common for DocEdit (raw text editor where lines - LF delimited sections - are displayed as paragraphs - wrapped when they do not fit the width) and LineEdit.(where lines are simply lines and are never wrapped). TextCtrl works in UNICODE, but is able performing conversions to any of predefined charsets. The Value of TextCtrl is contained text; setting it is the same as using Set method, reading is equivalent to Get method.
virtual void SelectionChanged()
Selection anchor or cursor has changed. (called even when there is no selection, just cursor). If you override this, you should call base-class version in the body.
virtual void ClearLines()
The content was removed (e.g. Clear or Load operations). If you override this, you should call base-class version in the body.
virtual void InsertLines(int line, int count)
count lines at line position were inserted. If you override this, you should call base-class version in the body.
virtual void RemoveLines(int line, int count)
count lines at line position were removed. If you override this, you should call base-class version in the body.
virtual void PreInsert(int pos, const WString& text)
Called before any text gets inserted at pos. If you override this, you should call base-class version in the body.
virtual void PostInsert(int pos, const WString& text)
Called after text was inserted at pos. If you override this, you should call base-class version in the body.
virtual void PreRemove(int pos, int size)
Called before size characters get removed from the pos. If you override this, you should call base-class version in the body.
virtual void PostRemove(int pos, int size)
Called after size characters was removed from the pos. If you override this, you should call base-class version in the body.
virtual void RefreshLine(int i)
This virtual method is called by TextCtrl when the content of line i is changed. If you override this, you should call base-class version in the body.
Callback1<Bar&> WhenBar
This callback is invoked when user right-clicks the widget and should specify local menu. It is initialized by the constructor to the StdBar method.
Callback WhenState
This callback is invoked when the status of widget changes from not-modified to modified ("dirty") or back.
void CachePos(int pos)
This is specific optimization hint to the widget saying that following operations will be performed near after pos. Unlikely to be used in the client code.
void Load(Stream& s, byte charset = CHARSET_DEFAULT)
Loads the text from the stream with defined charset.
void Save(Stream& s, byte charset = CHARSET_DEFAULT, bool crlf) const
Saves the text to the stream with defined charset. Characters that cannot be represented in suggested charset are saved as '?'. If crlf is true, line endings are forced to be "\r\n" even on POSIX platforms.
int GetInvalidCharPos(byte charset = CHARSET_DEFAULT) const
Returns the position of the first character that cannot be represented charset. If there is none, returns negative value.
bool CheckCharset(byte charset = CHARSET_DEFAULT) const
Same as GetInvalidCharPos(charset) < 0.
void Set(const WString& s)
void Set(const String& s, byte charset = CHARSET_DEFAULT)
Sets the text in the widget.
String Get(byte charset = CHARSET_DEFAULT) const
Gets the text in the widget.
String Get(int pos, int size, byte charset = CHARSET_DEFAULT) const
Gets the part of text in the widget.
WString GetW(int pos, int size) const
Gets the part of text in the widget in UNICODE.
WString GetW() const
Gets the text in the widget in UNICODE.
void ClearDirty()
Clears dirty flag. Note that the difference between "dirty" flag and "modified" flag of Ctrl interface is that "dirty" flag can get cleared by undo operation, when the text is restored to the original state (one after setting it or at ClearDirty).
bool IsDirty() const
Tests if text is different from "original" state (one after setting it or at ClearDirty).
void Clear()
Empties the text.
int GetLinePos(int& pos) const
Returns the line where character at offset pos resides; pos is altered to contain the position withing the line.
int GetPos(int line, int column) const
Returns the offset of character at line and column index within the line.
int GetPos(int line) const
Same as GetPos(line, 0).
int GetLine(int pos) const
Similar to GetLinePos, but does not alter pos parameter.
const String& GetUtf8Line(int i) const
Returns the line i in UTF-8 encoding.
WString GetWLine(int i) const
Returns the line i in UNICODE.
String GetEncodedLine(int i, byte charset = CHARSET_DEFAULT) const
Returns the line i required encoding.
int GetLineLength(int i) const
Returns the length of line i.
int GetLineCount() const
Returns the number of lines.
virtual int GetChar(int pos) const
int operator[](int pos) const
Returns the UNICODE character at pos offset.
virtual int GetLength() const
Returns the total number of characters in the text.
int GetCursor() const
Returns the position of cursor.
int GetCursorLine()
Same as GetLine(GetCursor).
void SetSelection(int anchor = 0, int cursor = INT_MAX)
Sets the selection. If anchor or cursor are out of range, they are "fixed". If they are equal, method changes the position of cursor.
bool IsSelection() const
Tests whether there is non-empty selection.
bool GetSelection(int& l, int& h) const
Returns the selection lower and upper bounds.
String GetSelection(byte charset = CHARSET_DEFAULT) const
Returns the selected text in given charset.
WString GetSelectionW() const
Returns the selected text in UNICODE.
void ClearSelection()
Cancels the selection.
bool RemoveSelection()
Deletes the selection text.
void SetCursor(int cursor)
Places cursor at new position.
int Paste(const WString& text)
Pastes text at current cursor position.
int Insert(int pos, const WString& txt)
Inserts txt at pos.
int Insert(int pos, const String& txt, byte charset = CHARSET_DEFAULT)
Inserts txt encoded with charset at pos.
int Insert(int pos, const char *txt)
Inserts txt at pos using default charset.
void Remove(int pos, int size)
Removes the text.
void NextUndo()
Marks the beginning of next undo block. All text altering operations (inserts and removes) are recorded into undo buffer in sections where each sections represents single user action. NextUndo tells TextCtrl that the next altering operation belongs to the new section. Note that NextUndo does not create a new section (yet); calling it twice without any altering operation in between is the same as calling it once.
void Undo()
Performs undo.
void Redo()
Performs redo.
bool IsUndo() const
Tests whether there are some undo records.
bool IsRedo() const
Tests whether there are some redo records.
void ClearUndo()
Clears all undo and redo records.
UndoData PickUndoData()
Picks undo and redo record. This is useful when single widget is used to edit various text, this allows to change undo/redo records with the text. Must be followed by either SetPickUndoData or ClearUndo before performing any text altering operation.
void SetPickUndoData(pick_ UndoData& data)
Sets the undo/redo records. data is picked (destroyed) during the operation.
void Cut()
Performs Cut.
void Copy()
Performs Copy.
void Paste()
Performs Paste.
void SelectAll()
Selects the whole text.
void StdBar(Bar& menu)
Provides the standard local menu.
void SetCharset(byte cs)
Sets the input character encoding of widget. This character set is used to decide which characters can be entered by the user into the text.
byte GetCharset() const
Returns the value set by SetCharset.
void SetColor(int i, Color c)
Sets one of colors used to display the text.
|
TextCtrl::INK_NORMAL
|
Normal text color.
|
TextCtrl::INK_DISABLED
|
Text color when widget is disabled.
|
TextCtrl::INK_SELECTED
|
Selected text color.
|
TextCtrl::PAPER_NORMAL
|
Normal paper color.
|
TextCtrl::PAPER_READONLY
|
Paper color when widget is read-only.
|
TextCtrl::PAPER_SELECTED
|
Selected paper color.
|
TextCtrl::COLOR_COUNT
|
Total number of color indexes.
|
|
|
Color GetColor(int i) const
Gets the color used to display the text.
TextCtrl& UndoSteps(int n)
Sets the maximum number of undo steps.
TextCtrl& ProcessTab(bool b = true)
If active (default), widget accepts K_TAB keystrokes (inserts '\t').
TextCtrl& NoProcessTab()
Same as ProcessTab(false).
TextCtrl& ProcessEnter(bool b = true)
If active (non-default), widget accepts K_ENTER keystrokes (inserts a new line).
TextCtrl& NoProcessEnter()
Same as ProcessEnter(false).
TextCtrl& NoBackground(bool b = true)
Sets the widget into transparent mode - background is not painted and Transparent is activated - a result, anything painted behind the widget is visible, allowing client code to provide any background it needs.
bool IsProcessTab()
Tests whether ProcessTab mode is active.
struct UndoData
This structure contains informations about undo/redo state of the widget. It can be with PickUndoData and SetPickUndoDate to store and restore undo/redo state.
void Clear()
Clears the undo/redo state
.
|