57 bool word = (keycode & WKC_CTRL) != 0;
59 keycode &= ~WKC_SPECIAL_KEYS;
60 if (keycode != WKC_BACKSPACE && keycode != WKC_DELETE)
return false;
62 bool backspace = keycode == WKC_BACKSPACE;
80 for (
const char *ss = s; ss < s + len; Utf8Consume(&ss)) {
95 for (
const char *ss = s; ss < s + len; Utf8Consume(&ss)) {
102 memmove(s, s + len, this->
bytes - (s - this->
buf) - len);
105 if (backspace) this->caretpos -= len;
167 if (insert_location != NULL) {
168 insertpos = insert_location - this->
buf;
169 if (insertpos > this->
bytes)
return false;
171 if (replacement_end != NULL) {
172 this->
DeleteText(insertpos, replacement_end - this->buf, str == NULL);
178 if (str == NULL)
return false;
182 for (
const char *ptr = str; (c = Utf8Consume(&ptr)) !=
'\0';) {
186 if (this->bytes + bytes + len > this->
max_bytes)
break;
196 if (bytes == 0)
return false;
203 memmove(this->
buf + insertpos + bytes, this->
buf + insertpos, this->bytes - insertpos);
204 memcpy(this->
buf + insertpos, str, bytes);
206 this->bytes +=
bytes;
211 this->
buf[this->bytes - 1] =
'\0';
245 const char *s = this->
buf + from;
246 while (s < this->
buf + to) {
252 memmove(this->
buf + from, this->
buf + to, this->
bytes - to);
253 this->
bytes -= to - from;
278 if (this->
markend == 0)
return;
325 case WKC_CTRL | WKC_LEFT: {
337 case WKC_CTRL | WKC_RIGHT: {
377 assert(max_bytes != 0);
378 assert(max_chars != 0);
391 delete this->char_iter;
421 va_start(va, format);
435 const char *
buf = this->
buf;
440 while ((c = Utf8Consume(&buf)) !=
'\0') {
462 bool b = !!(_caret_timer & 0x20);
464 if (b != this->
caret) {
478 case WKC_RETURN:
case WKC_NUM_ENTER:
return HKPR_CONFIRM;
480 case (WKC_CTRL |
'V'):
484 case (WKC_CTRL |
'U'):
489 case WKC_BACKSPACE:
case WKC_DELETE:
490 case WKC_CTRL | WKC_BACKSPACE:
case WKC_CTRL | WKC_DELETE:
494 case WKC_LEFT:
case WKC_RIGHT:
case WKC_END:
case WKC_HOME:
495 case WKC_CTRL | WKC_LEFT:
case WKC_CTRL | WKC_RIGHT:
Functions related to OTTD's strings.
bool MovePos(uint16 keycode)
Handle text navigation with arrow keys left/right.
uint16 markend
the end position of the marked area in the buffer, in bytes
uint16 chars
the current size of the string in characters (including terminating '\0')
virtual size_t Next(IterType what=ITER_CHARACTER)=0
Advance the cursor by one iteration unit.
static const size_t END
Sentinel to indicate end-of-iteration.
static StringIterator * Create()
Create a new iterator instance.
Stuff related to text buffers.
int CDECL vseprintf(char *str, const char *last, const char *format, va_list ap)
Safer implementation of vsnprintf; same as vsnprintf except:
void CDECL void DeleteAll()
Delete every character in the textbuffer.
void CDECL Print(const char *format,...) WARN_FORMAT(2
Print a formatted string into the textbuffer.
size_t Utf8Decode(WChar *c, const char *s)
Decode and consume the next UTF-8 encoded character.
bool InsertChar(uint32 key)
Insert a character to a textbuffer.
#define lastof(x)
Get the last element of an fixed size array.
virtual void SetString(const char *s)=0
Set a new iteration string.
uint16 bytes
the current size of the string in bytes (including terminating '\0')
Non-text change, e.g. cursor position.
void UpdateCaretPosition()
Update pixel position of the caret.
void UpdateStringIter()
Update the character iter after the text has changed.
void UpdateWidth()
Update pixel width of the text.
virtual size_t Prev(IterType what=ITER_CHARACTER)=0
Move the cursor back by one iteration unit.
virtual size_t SetCurPosition(size_t pos)=0
Change the current string cursor.
void UpdateMarkedText()
Update pixel positions of the marked text area.
Iterate over characters (or more exactly grapheme clusters).
bool InsertString(const char *str, bool marked, const char *caret=NULL, const char *insert_location=NULL, const char *replacement_end=NULL)
Insert a string into the text buffer.
Functions related to low-level strings.
bool caret
is the caret ("_") visible or not
bool IsValidChar(WChar key, CharSetFilter afilter)
Only allow certain keys.
bool GetClipboardContents(char *buffer, const char *last)
Try to retrieve the current clipboard contents.
uint16 markxoffs
the start position of the marked area in pixels
Functions related to the allocation of memory.
static T * MallocT(size_t num_elements)
Simplified allocation function that allocates the specified number of elements of the given type...
uint16 pixels
the current size of the string in pixels
Functions related to the gfx engine.
Definition of base types and functions in a cross-platform compatible way.
A number of safeguards to prevent using unsafe methods.
Key does not affect editboxes.
HandleKeyPressResult
Return values for Textbuf::HandleKeypress.
static int8 Utf8CharLen(WChar c)
Return the length of a UTF-8 encoded character.
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...
bool InsertClipboard()
Insert a chunk of text from the clipboard onto the textbuffer.
bool CanDelChar(bool backspace)
Checks if it is possible to delete a character.
void DeleteText(uint16 from, uint16 to, bool update)
Delete a part of the text.
uint16 caretpos
the current position of the caret in the buffer, in bytes
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void Assign(StringID string)
Render a string into the textbuffer.
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
void DiscardMarkedText(bool update=true)
Discard any marked text.
Return or enter key pressed.
char *const buf
buffer in which text is saved
Both numeric and alphabetic and spaces and stuff.
uint16 max_bytes
the maximum size of the buffer in bytes (including terminating '\0')
bool HandleCaret()
Handle the flashing of the caret.
uint16 max_chars
the maximum size of the buffer in characters (including terminating '\0')
uint16 caretxoffs
the current position of the caret in pixels
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
static char * Utf8PrevChar(char *s)
Retrieve the previous UNICODE character in an UTF-8 encoded string.
Index of the normal font in the font tables.
size_t Utf8Encode(char *buf, WChar c)
Encode a unicode character and place it in the buffer.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
bool DeleteChar(uint16 keycode)
Delete a character from a textbuffer, either with 'Delete' or 'Backspace' The character is delete fro...
Window functions not directly related to making/drawing windows.
CharSetFilter afilter
Allowed characters.
uint16 marklength
the length of the marked area in pixels
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...
uint32 WChar
Type for wide characters, i.e.
uint16 markpos
the start position of the marked area in the buffer, in bytes
Types related to the graphics and/or input devices.
void UpdateSize()
Update Textbuf type with its actual physical character and screenlength Get the count of characters i...