4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file textbuf_type.h Stuff related to text buffers. */
12 #ifndef TEXTBUF_TYPE_H
13 #define TEXTBUF_TYPE_H
15 #include "string_type.h"
16 #include "strings_type.h"
17 #include "string_base.h"
20 * Return values for Textbuf::HandleKeypress
22 enum HandleKeyPressResult
24 HKPR_EDITING
, ///< Textbuf content changed.
25 HKPR_CURSOR
, ///< Non-text change, e.g. cursor position.
26 HKPR_CONFIRM
, ///< Return or enter key pressed.
27 HKPR_CANCEL
, ///< Escape key pressed.
28 HKPR_NOT_HANDLED
, ///< Key does not affect editboxes.
31 /** Helper/buffer for input fields. */
33 CharSetFilter afilter
; ///< Allowed characters
34 char * const buf
; ///< buffer in which text is saved
35 uint16 max_bytes
; ///< the maximum size of the buffer in bytes (including terminating '\0')
36 uint16 max_chars
; ///< the maximum size of the buffer in characters (including terminating '\0')
37 uint16 bytes
; ///< the current size of the string in bytes (including terminating '\0')
38 uint16 chars
; ///< the current size of the string in characters (including terminating '\0')
39 uint16 pixels
; ///< the current size of the string in pixels
40 bool caret
; ///< is the caret ("_") visible or not
41 uint16 caretpos
; ///< the current position of the caret in the buffer, in bytes
42 uint16 caretxoffs
; ///< the current position of the caret in pixels
43 uint16 markpos
; ///< the start position of the marked area in the buffer, in bytes
44 uint16 markend
; ///< the end position of the marked area in the buffer, in bytes
45 uint16 markxoffs
; ///< the start position of the marked area in pixels
46 uint16 marklength
; ///< the length of the marked area in pixels
48 explicit Textbuf(uint16 max_bytes
, uint16 max_chars
= UINT16_MAX
);
51 void Assign(StringID string
);
52 void Assign(const char *text
);
53 void CDECL
Print(const char *format
, ...) WARN_FORMAT(2, 3);
56 bool InsertClipboard();
58 bool InsertChar(uint32 key
);
59 bool InsertString(const char *str
, bool marked
, const char *caret
= NULL
, const char *insert_location
= NULL
, const char *replacement_end
= NULL
);
61 bool DeleteChar(uint16 keycode
);
62 bool MovePos(uint16 keycode
);
64 HandleKeyPressResult
HandleKeyPress(WChar key
, uint16 keycode
);
69 void DiscardMarkedText(bool update
= true);
72 StringIterator
*char_iter
;
74 bool CanDelChar(bool backspace
);
76 void DeleteText(uint16 from
, uint16 to
, bool update
);
78 void UpdateStringIter();
80 void UpdateCaretPosition();
81 void UpdateMarkedText();
84 #endif /* TEXTBUF_TYPE_H */