Overview
Examples
Screenshots
Comparisons
Applications
Download
Documentation
Tutorials
Bazaar
Status & Roadmap
FAQ
Authors & License
Forums
Funding Ultimate++
Search on this site













SourceForge.net Logo

TextCtrl

 

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.

 

 

Protected Method List

 

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.

 

 

Public Method List

 

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.

 


 

Callback WhenSel

Called when cursor or selection changes.

 


 

Event<int64WhenViewMapping

Called during mapping view stream with current position in the stream.

 


 

void CachePos(int pos)

This is specific optimization hint to the widget saying that following operations will be performed near pos. Unlikely to be used in the client code.

 


 

void CacheLinePos(int linei)

This is specific optimization hint to the widget saying that following operations will be performed near line linei. Unlikely to be used in the client code.

 


 

int Load(Stream& s, byte charset = CHARSET_DEFAULT)

Loads the text from the stream with defined charset. Function returns the detected line endings mode - LE_CRLF, LE_LF or LE_DEFAULT if there were no line endings in the file. If file is bigger then the limit set by MaxLength, editor is put into 'truncated' and read-only mode.

 


 

bool IsTruncated() const

Indicates that last Load had to truncate the size because of MaxLength limit.

 


 

void Save(Stream& s, byte charset = CHARSET_DEFAULT, int line_endings = LE_DEFAULT) const

Saves the text to the stream with defined charset. Characters that cannot be represented in suggested charset are saved as '?'. line_endings parameter sets the line ending mode. LE_DEFAULT uses platform specific line endings (CRLF in Windows, LF in POSIX), LE_CRLF sets CRLF line endings, LE_LF sets LF line endings). If IsTruncated is true, Save is blocked.

 


 

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(int64 pos, int size, byte charset = CHARSET_DEFAULT) const

Gets the part of text in the widget.

 


 

WString GetW(int64 pos, int sizeconst

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 GetLine(int64 posconst

Similar to GetLinePos, but does not alter pos parameter.

 


 

int GetLinePos(int& posconst

Returns the line where character at offset pos resides; pos is altered to contain the position withing the line.

 


 

int GetPos(int line, int columnconst

Returns the offset of character at line and column index within the line.

 


 

int GetPos(int lineconst

Same as GetPos(line, 0).

 


 

const String& GetUtf8Line(int iconst

Returns the line i in UTF-8 encoding.

 


 

WString GetWLine(int iconst

Returns the line i in UNICODE.

 


 

String GetEncodedLine(int i, byte charset = CHARSET_DEFAULT) const

Returns the line i required encoding.

 


 

int GetLineLength(int iconst

Returns the length of line i.

 


 

int GetLineCount() const

Returns the number of lines.

 


 

int GetChar(int64 posconst

int operator[](int64 posconst

Returns the UNICODE character at pos offset.

 


 

int GetChar() const

Returns UNICODE character at cursor, or 0 if cursor is behind the last character.

 


 

int GetLength() const

Returns the total number of characters in the text.

 


 

int GetCursor() const

Returns the position of cursor.

 


 

int GetCursorLine() const

Same as GetLine(GetCursor).

 


 

void SetSelection(int64 anchor = 0, int64 cursor = 2147483647 )

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 normal selection.

 


 

bool IsRectSelection() const

Returns true if there is rectangular selection.

 


 

bool IsAnySelection() const

Returns true if there is either rectangular or normal selection.

 


 

bool GetSelection(int& l, int& hconst

bool GetSelection(int64& l, int64& hconst

Returns the selection lower and upper bounds. int64 version is only useful in view mode. In view mode, 32 bit version returns false if the range is larger than 2GB.

 


 

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(int64 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.

 


 

int Append(const WString& txt)

Same as Insert(GetLength(), txt).

 


 

int Append(const String& txt, byte charset = CHARSET_DEFAULT)

Same as Insert(GetLength(), txt, charset).

 


 

int Append(const char *txt)

Same as Append(WString(txt)).

 


 

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.

 


 

void ClearRedo()

Clears 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(TextCtrl::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 iconst

Gets the color used to display the text.

 


 

int View(Stream& s, byte charset = CHARSET_DEFAULT)

Initiates the view mode. In view mode, file is not loaded, but displayed while loading it from the stream as necessary. TextCtrl retains a reference to s so it must exist for the whole time it is displayed in TextCtrl. TextCtrl is in read-only mode for view operations. View allows viewing of files >2GB, therefore some functions have 64-bit counterparts working in view mode only. View actually needs to scan the file to create a map of file; this operation is performed in background (via PostCallbacks), application can use SerializeViewMap to store cache this map for particular file.

 


 

void WaitView(int line, bool progress)

While mapping of file for view is in progress, makes sure that the file is mapped up to line or EOF. If progress is true, progress is displayed.

 


 

void LockViewMapping()

Stops background mapping of file for view.

 


 

void UnlockViewMapping()

Continues mapping of file for view.

 


 

void SerializeViewMap(Stream& s)

Serializes the file view map.

 


 

bool IsView() const

Returns true if TextCtrl is in view mode.

 


 

int64 GetViewSize() const

Returns GetSize of view stream.

 


 

int GetLinePos64(int64& posconst

int64 GetPos64(int ln, int lposconst

int64 GetLength64() const

int64 GetCursor64() const

These are variants of GetLinePos, GetPos, GetLength and GetCursor64 for view mode (where values > INT_MAX are possible).

 


 

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.

 


 

TextCtrl& MaxLength(int len)

Sets the maximum size of text in unicode characters. Has to be less than 1Gchars. The default is 400Mchars.

 


 

bool IsProcessTab()

Tests whether ProcessTab mode is active.

 

 

 

 

TextCtrl::UndoData

 

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.

 

 

Public Method List

 

void Clear()

Clears the undo/redo state

 

.

Last edit by cxl on 04/29/2018. Do you want to contribute?. T++