OpenTTD
textbuf_type.h
Go to the documentation of this file.
1 /* $Id: textbuf_type.h 25692 2013-08-05 20:37:57Z michi_cc $ */
2 
3 /*
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/>.
8  */
9 
12 #ifndef TEXTBUF_TYPE_H
13 #define TEXTBUF_TYPE_H
14 
15 #include "string_type.h"
16 #include "strings_type.h"
17 #include "string_base.h"
18 
23 {
29 };
30 
32 struct Textbuf {
34  char * const buf;
35  uint16 max_bytes;
36  uint16 max_chars;
37  uint16 bytes;
38  uint16 chars;
39  uint16 pixels;
40  bool caret;
41  uint16 caretpos;
42  uint16 caretxoffs;
43  uint16 markpos;
44  uint16 markend;
45  uint16 markxoffs;
46  uint16 marklength;
47 
48  explicit Textbuf(uint16 max_bytes, uint16 max_chars = UINT16_MAX);
49  ~Textbuf();
50 
51  void Assign(StringID string);
52  void Assign(const char *text);
53  void CDECL Print(const char *format, ...) WARN_FORMAT(2, 3);
54 
55  void DeleteAll();
56  bool InsertClipboard();
57 
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);
60 
61  bool DeleteChar(uint16 keycode);
62  bool MovePos(uint16 keycode);
63 
64  HandleKeyPressResult HandleKeyPress(WChar key, uint16 keycode);
65 
66  bool HandleCaret();
67  void UpdateSize();
68 
69  void DiscardMarkedText(bool update = true);
70 
71 private:
72  StringIterator *char_iter;
73 
74  bool CanDelChar(bool backspace);
75 
76  void DeleteText(uint16 from, uint16 to, bool update);
77 
78  void UpdateStringIter();
79  void UpdateWidth();
80  void UpdateCaretPosition();
81  void UpdateMarkedText();
82 };
83 
84 #endif /* TEXTBUF_TYPE_H */