Public Member Functions | Data Fields | Private Member Functions

Textbuf Struct Reference

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.

Detailed Description

Helper/buffer for input fields.

Definition at line 18 of file textbuf_type.h.


Member Function Documentation

bool Textbuf::CanDelChar ( bool  backspace  )  [private]

Checks if it is possible to delete a character.

Parameters:
backspace if set, delete the character before the caret, otherwise, delete the character after it.
Returns:
true if a character can be deleted in the given direction.

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.

Returns:
true if the caret can be moved to the left, otherwise false.

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.

Returns:
true if the caret can be moved to the right, otherwise false.

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.

Parameters:
backspace if set, delete the character before the caret, else delete the character after it.
Warning:
You should ensure Textbuf::CanDelChar returns true before calling this function.

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.

Parameters:
delmode Type of deletion, either WKC_BACKSPACE or WKC_DELETE
Returns:
Return true on successful change of Textbuf, or false otherwise

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.

Parameters:
backspace if set, delete the character before the caret, otherwise, delete the character after it.
Returns:
the next character that will be removed by DelChar.
Warning:
You should ensure Textbuf::CanDelChar returns true before calling this function.

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.

Returns:
True if the caret state changes.

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.

Parameters:
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.

Parameters:
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

Returns:
true on successful change of Textbuf, or false otherwise

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.

Precondition:
Ensure that Textbuf::CanMoveCaretLeft returns true
Returns:
The character under the caret.

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.

Precondition:
Ensure that Textbuf::CanMoveCaretRight returns true
Returns:
The character under the caret.

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

Parameters:
navmode Direction in which navigation occurs (WKC_CTRL |) WKC_LEFT, (WKC_CTRL |) WKC_RIGHT, WKC_END, WKC_HOME
Returns:
Return true on successful change of Textbuf, or false otherwise

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


The documentation for this struct was generated from the following files: