OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
55 bool word = (keycode & WKC_CTRL) != 0;
57 keycode &= ~WKC_SPECIAL_KEYS;
58 if (keycode != WKC_BACKSPACE && keycode != WKC_DELETE)
return false;
60 bool backspace = keycode == WKC_BACKSPACE;
78 for (
const char *ss = s; ss < s + len; Utf8Consume(&ss)) {
93 for (
const char *ss = s; ss < s + len; Utf8Consume(&ss)) {
100 memmove(s, s + len, this->
bytes - (s - this->
buf) - len);
103 if (backspace) this->caretpos -= len;
162 bool Textbuf::InsertString(
const char *str,
bool marked,
const char *caret,
const char *insert_location,
const char *replacement_end)
165 if (insert_location !=
nullptr) {
166 insertpos = insert_location - this->
buf;
167 if (insertpos > this->
bytes)
return false;
169 if (replacement_end !=
nullptr) {
170 this->
DeleteText(insertpos, replacement_end - this->buf, str ==
nullptr);
176 if (str ==
nullptr)
return false;
180 for (
const char *ptr = str; (c = Utf8Consume(&ptr)) !=
'\0';) {
194 if (
bytes == 0)
return false;
201 memmove(this->
buf + insertpos +
bytes, this->
buf + insertpos, this->bytes - insertpos);
202 memcpy(this->
buf + insertpos, str,
bytes);
204 this->bytes +=
bytes;
209 this->
buf[this->bytes - 1] =
'\0';
243 const char *s = this->
buf + from;
244 while (s < this->
buf + to) {
250 memmove(this->
buf + from, this->
buf + to, this->
bytes - to);
251 this->
bytes -= to - from;
276 if (this->
markend == 0)
return;
323 case WKC_CTRL | WKC_LEFT: {
335 case WKC_CTRL | WKC_RIGHT: {
372 : buf(
MallocT<char>(max_bytes))
388 delete this->char_iter;
418 va_start(va, format);
432 const char *
buf = this->
buf;
437 while ((c = Utf8Consume(&
buf)) !=
'\0') {
459 bool b = !!(_caret_timer & 0x20);
461 if (b != this->
caret) {
475 case WKC_RETURN:
case WKC_NUM_ENTER:
return HKPR_CONFIRM;
477 case (WKC_CTRL |
'V'):
481 case (WKC_CTRL |
'U'):
486 case WKC_BACKSPACE:
case WKC_DELETE:
487 case WKC_CTRL | WKC_BACKSPACE:
case WKC_CTRL | WKC_DELETE:
491 case WKC_LEFT:
case WKC_RIGHT:
case WKC_END:
case WKC_HOME:
492 case WKC_CTRL | WKC_LEFT:
case WKC_CTRL | WKC_RIGHT:
void DeleteText(uint16 from, uint16 to, bool update)
Delete a part of the text.
virtual size_t Prev(IterType what=ITER_CHARACTER)=0
Move the cursor back by one iteration unit.
@ HKPR_EDITING
Textbuf content changed.
char32_t WChar
Type for wide characters, i.e.
uint16 max_bytes
the maximum size of the buffer in bytes (including terminating '\0')
void CDECL Print(const char *format,...) WARN_FORMAT(2
Print a formatted string into the textbuffer.
@ HKPR_CONFIRM
Return or enter key pressed.
static const size_t END
Sentinel to indicate end-of-iteration.
void Assign(StringID string)
Render a string into the textbuffer.
bool MovePos(uint16 keycode)
Handle text navigation with arrow keys left/right.
static int8 Utf8CharLen(WChar c)
Return the length of a UTF-8 encoded character.
uint16 caretpos
the current position of the caret in the buffer, in bytes
size_t Utf8Encode(T buf, WChar c)
Encode a unicode character and place it in the buffer.
uint16 caretxoffs
the current position of the caret in pixels
virtual size_t Next(IterType what=ITER_CHARACTER)=0
Advance the cursor by one iteration unit.
uint16 markpos
the start position of the marked area in the buffer, in bytes
virtual void SetString(const char *s)=0
Set a new iteration string.
static T * MallocT(size_t num_elements)
Simplified allocation function that allocates the specified number of elements of the given type.
bool InsertString(const char *str, bool marked, const char *caret=nullptr, const char *insert_location=nullptr, const char *replacement_end=nullptr)
Insert a string into the text buffer.
@ ITER_CHARACTER
Iterate over characters (or more exactly grapheme clusters).
uint16 pixels
the current size of the string in pixels
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
char *const buf
buffer in which text is saved
static StringIterator * Create()
Create a new iterator instance.
bool HandleCaret()
Handle the flashing of the caret.
bool GetClipboardContents(char *buffer, const char *last)
Try to retrieve the current clipboard contents.
@ FS_NORMAL
Index of the normal font in the font tables.
virtual size_t SetCurPosition(size_t pos)=0
Change the current string cursor.
uint16 marklength
the length of the marked area in pixels
HandleKeyPressResult
Return values for Textbuf::HandleKeypress.
void UpdateMarkedText()
Update pixel positions of the marked text area.
bool caret
is the caret ("_") visible or not
bool IsValidChar(WChar key, CharSetFilter afilter)
Only allow certain keys.
bool DeleteChar(uint16 keycode)
Delete a character from a textbuffer, either with 'Delete' or 'Backspace' The character is delete fro...
void UpdateCaretPosition()
Update pixel position of the caret.
int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap)
Safer implementation of vsnprintf; same as vsnprintf except:
CharSetFilter afilter
Allowed characters.
@ ITER_WORD
Iterate over words.
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
size_t Utf8Decode(WChar *c, const char *s)
Decode and consume the next UTF-8 encoded character.
uint16 markend
the end position of the marked area in the buffer, in bytes
uint32 StringID
Numeric value that represents a string, independent of the selected language.
uint16 bytes
the current size of the string in bytes (including terminating '\0')
bool InsertClipboard()
Insert a chunk of text from the clipboard onto the textbuffer.
Textbuf(uint16 max_bytes, uint16 max_chars=UINT16_MAX)
Initialize the textbuffer by supplying it the buffer to write into and the maximum length of this buf...
void UpdateSize()
Update Textbuf type with its actual physical character and screenlength Get the count of characters i...
@ HKPR_CANCEL
Escape key pressed.
void UpdateStringIter()
Update the character iter after the text has changed.
uint16 chars
the current size of the string in characters (including terminating '\0')
uint16 max_chars
the maximum size of the buffer in characters (including terminating '\0')
@ HKPR_NOT_HANDLED
Key does not affect editboxes.
void UpdateWidth()
Update pixel width of the text.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
bool InsertChar(WChar key)
Insert a character to a textbuffer.
Point GetCharPosInString(const char *str, const char *ch, FontSize start_fontsize)
Get the leading corner of a character in a single-line string relative to the start of the string.
#define lastof(x)
Get the last element of an fixed size array.
bool CanDelChar(bool backspace)
Checks if it is possible to delete a character.
void CDECL void DeleteAll()
Delete every character in the textbuffer.
static char * Utf8PrevChar(char *s)
Retrieve the previous UNICODE character in an UTF-8 encoded string.
@ HKPR_CURSOR
Non-text change, e.g. cursor position.
void DiscardMarkedText(bool update=true)
Discard any marked text.
uint16 markxoffs
the start position of the marked area in pixels