Helper/buffer for input fields. More...
#include <textbuf_type.h>
Public Member Functions | |
void | Initialize (char *buf, uint16 max_bytes) |
Initialize the textbuffer by supplying it the buffer to write into and the maximum length of this buffer. | |
void | Initialize (char *buf, uint16 max_bytes, uint16 max_chars) |
Initialize the textbuffer by supplying it the buffer to write into and the maximum length of this buffer. | |
void | DeleteAll () |
Delete every character in the textbuffer. | |
bool | DeleteChar (int delmode) |
Delete a character from a textbuffer, either with 'Delete' or 'Backspace' The character is delete from the position the caret is at. | |
bool | InsertChar (uint32 key) |
bool | InsertClipboard () |
Insert a chunk of text from the clipboard onto the textbuffer. | |
bool | MovePos (int navmode) |
Handle text navigation with arrow keys left/right. | |
bool | HandleCaret () |
Handle the flashing of the caret. | |
void | UpdateSize () |
Update Textbuf type with its actual physical character and screenlength Get the count of characters in the string as well as the width in pixels. | |
Data Fields | |
char * | buf |
buffer in which text is saved | |
uint16 | max_bytes |
the maximum size of the buffer in bytes (including terminating '') | |
uint16 | max_chars |
the maximum size of the buffer in characters (including terminating '') | |
uint16 | bytes |
the current size of the string in bytes (including terminating '') | |
uint16 | chars |
the current size of the string in characters (including terminating '') | |
uint16 | pixels |
the current size of the string in pixels | |
bool | caret |
is the caret ("_") visible or not | |
uint16 | caretpos |
the current position of the caret in the buffer, in bytes | |
uint16 | caretxoffs |
the current position of the caret in pixels | |
Private Member Functions | |
bool | CanDelChar (bool backspace) |
Checks if it is possible to delete a character. | |
WChar | GetNextDelChar (bool backspace) |
Get the next character that will be removed by DelChar. | |
void | DelChar (bool backspace) |
Delete a character at the caret position in a text buf. | |
bool | CanMoveCaretLeft () |
Checks if it is possible to move carret to the left. | |
WChar | MoveCaretLeft () |
Moves the caret to the left. | |
bool | CanMoveCaretRight () |
Checks if it is possible to move carret to the right. | |
WChar | MoveCaretRight () |
Moves the caret to the right. |
Helper/buffer for input fields.
Definition at line 18 of file textbuf_type.h.
bool Textbuf::CanDelChar | ( | bool | backspace | ) | [private] |
Checks if it is possible to delete a character.
backspace | if set, delete the character before the caret, otherwise, delete the character after it. |
Definition at line 36 of file textbuf.cpp.
References bytes, and caretpos.
Referenced by DelChar(), DeleteChar(), and GetNextDelChar().
bool Textbuf::CanMoveCaretLeft | ( | ) | [private] |
Checks if it is possible to move carret to the left.
Definition at line 223 of file textbuf.cpp.
References caretpos.
Referenced by MoveCaretLeft(), and MovePos().
bool Textbuf::CanMoveCaretRight | ( | ) | [private] |
Checks if it is possible to move carret to the right.
Definition at line 250 of file textbuf.cpp.
References bytes, and caretpos.
Referenced by MoveCaretRight(), and MovePos().
void Textbuf::DelChar | ( | bool | backspace | ) | [private] |
Delete a character at the caret position in a text buf.
backspace | if set, delete the character before the caret, else delete the character after it. |
Definition at line 70 of file textbuf.cpp.
References buf, bytes, CanDelChar(), caretpos, caretxoffs, chars, FS_NORMAL, GetCharacterWidth(), pixels, Utf8Decode(), and Utf8PrevChar().
Referenced by DeleteChar().
bool Textbuf::DeleteChar | ( | int | delmode | ) |
Delete a character from a textbuffer, either with 'Delete' or 'Backspace' The character is delete from the position the caret is at.
delmode | Type of deletion, either WKC_BACKSPACE or WKC_DELETE |
Definition at line 100 of file textbuf.cpp.
References CanDelChar(), DelChar(), GetNextDelChar(), and IsWhitespace().
Referenced by OskWindow::OnClick(), and IConsoleWindow::OnKeyPress().
WChar Textbuf::GetNextDelChar | ( | bool | backspace | ) | [private] |
Get the next character that will be removed by DelChar.
backspace | if set, delete the character before the caret, otherwise, delete the character after it. |
Definition at line 48 of file textbuf.cpp.
References buf, CanDelChar(), caretpos, Utf8Decode(), and Utf8PrevChar().
Referenced by DeleteChar().
bool Textbuf::HandleCaret | ( | ) |
Handle the flashing of the caret.
Definition at line 410 of file textbuf.cpp.
References caret.
Referenced by IConsoleWindow::OnMouseLoop().
void Textbuf::Initialize | ( | char * | buf, | |
uint16 | max_bytes, | |||
uint16 | max_chars | |||
) |
Initialize the textbuffer by supplying it the buffer to write into and the maximum length of this buffer.
buf | the buffer that will be holding the data for input | |
max_bytes | maximum size in bytes, including terminating '' | |
max_chars | maximum size in chars, including terminating '' |
Definition at line 368 of file textbuf.cpp.
References caret, and UpdateSize().
void Textbuf::Initialize | ( | char * | buf, | |
uint16 | max_bytes | |||
) |
Initialize the textbuffer by supplying it the buffer to write into and the maximum length of this buffer.
buf | the buffer that will be holding the data for input | |
max_bytes | maximum size in bytes, including terminating '' |
Definition at line 356 of file textbuf.cpp.
Referenced by AIDebugWindow::AIDebugWindow(), NetworkChatWindow::NetworkChatWindow(), and NetworkContentListWindow::NetworkContentListWindow().
bool Textbuf::InsertClipboard | ( | ) |
Insert a chunk of text from the clipboard onto the textbuffer.
Get TEXT clipboard and append this up to the maximum length (either absolute or screenlength). If maxlength is zero, we don't care about the screenlength but only about the physical length of the string
Definition at line 180 of file textbuf.cpp.
References buf, bytes, caretpos, caretxoffs, chars, FS_NORMAL, GetCharacterWidth(), GetClipboardContents(), lengthof, max_bytes, max_chars, pixels, and Utf8CharLen().
Referenced by IConsoleWindow::OnKeyPress().
WChar Textbuf::MoveCaretLeft | ( | ) | [private] |
Moves the caret to the left.
Definition at line 233 of file textbuf.cpp.
References buf, CanMoveCaretLeft(), caretpos, caretxoffs, FS_NORMAL, GetCharacterWidth(), Utf8Decode(), and Utf8PrevChar().
Referenced by MovePos().
WChar Textbuf::MoveCaretRight | ( | ) | [private] |
Moves the caret to the right.
Definition at line 260 of file textbuf.cpp.
References buf, CanMoveCaretRight(), caretpos, caretxoffs, FS_NORMAL, GetCharacterWidth(), and Utf8Decode().
Referenced by MovePos().
bool Textbuf::MovePos | ( | int | navmode | ) |
Handle text navigation with arrow keys left/right.
This defines where the caret will blink and the next characer interaction will occur
navmode | Direction in which navigation occurs (WKC_CTRL |) WKC_LEFT, (WKC_CTRL |) WKC_RIGHT, WKC_END, WKC_HOME |
Definition at line 278 of file textbuf.cpp.
References bytes, CanMoveCaretLeft(), CanMoveCaretRight(), caretpos, caretxoffs, IsWhitespace(), MoveCaretLeft(), MoveCaretRight(), and pixels.
Referenced by OskWindow::OnClick(), and IConsoleWindow::OnKeyPress().
void Textbuf::UpdateSize | ( | ) |
Update Textbuf type with its actual physical character and screenlength Get the count of characters in the string as well as the width in pixels.
Useful when copying in a larger amount of text at once
Definition at line 385 of file textbuf.cpp.
References buf, bytes, caretpos, caretxoffs, chars, FS_NORMAL, GetCharacterWidth(), max_bytes, max_chars, pixels, and Utf8CharLen().
Referenced by AIDebugWindow::AIDebugWindow(), NetworkChatWindow::ChatTabCompletion(), SignListWindow::ClearFilterTextWidget(), IConsoleHistoryNavigate(), Initialize(), and OskWindow::OnClick().