OpenTTD Source 20250312-master-gcdcc6b491d
osk_gui.cpp
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10#include "stdafx.h"
11#include "string_func.h"
12#include "strings_func.h"
13#include "debug.h"
14#include "window_func.h"
15#include "gfx_func.h"
16#include "querystring_gui.h"
18#include "zoom_func.h"
19
20#include "widgets/osk_widget.h"
21
22#include "table/sprites.h"
23#include "table/strings.h"
24
25#include "safeguards.h"
26
27std::string _keyboard_opt[2];
28static char32_t _keyboard[2][OSK_KEYBOARD_ENTRIES];
29
30enum KeyStateBits : uint8_t {
31 KEYS_NONE,
32 KEYS_SHIFT,
33 KEYS_CAPS
34};
35static uint8_t _keystate = KEYS_NONE;
36
37struct OskWindow : public Window {
39 QueryString *qs = nullptr;
41 Textbuf *text = nullptr;
42 std::string orig_str{};
43 bool shift = false;
44
45 OskWindow(WindowDesc &desc, Window *parent, WidgetID button) : Window(desc)
46 {
47 this->parent = parent;
48 assert(parent != nullptr);
49
51 assert(par_wid != nullptr);
52
53 assert(parent->querystrings.count(button) != 0);
54 this->qs = parent->querystrings.find(button)->second;
55 this->caption = (par_wid->GetString() != STR_NULL) ? par_wid->GetString() : this->qs->caption;
56 this->text_btn = button;
57 this->text = &this->qs->text;
58 this->querystrings[WID_OSK_TEXT] = this->qs;
59
60 /* make a copy in case we need to reset later */
61 this->orig_str = this->qs->text.GetText();
62
63 this->InitNested(0);
65
66 /* Not needed by default. */
68
69 this->UpdateOskState();
70 }
71
78 {
79 this->shift = HasBit(_keystate, KEYS_CAPS) ^ HasBit(_keystate, KEYS_SHIFT);
80
81 for (uint i = 0; i < OSK_KEYBOARD_ENTRIES; i++) {
83 !IsValidChar(_keyboard[this->shift][i], this->qs->text.afilter) || _keyboard[this->shift][i] == ' ');
84 }
85 this->SetWidgetDisabledState(WID_OSK_SPACE, !IsValidChar(' ', this->qs->text.afilter));
86
87 this->SetWidgetLoweredState(WID_OSK_SHIFT, HasBit(_keystate, KEYS_SHIFT));
88 this->SetWidgetLoweredState(WID_OSK_CAPS, HasBit(_keystate, KEYS_CAPS));
89 }
90
91 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
92 {
93 if (widget == WID_OSK_CAPTION) return GetString(this->caption);
94
95 return this->Window::GetWidgetString(widget, stringid);
96 }
97
98 void DrawWidget(const Rect &r, WidgetID widget) const override
99 {
100 if (widget < WID_OSK_LETTERS) return;
101
102 widget -= WID_OSK_LETTERS;
103 DrawCharCentered(_keyboard[this->shift][widget], r, TC_BLACK);
104 }
105
106 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
107 {
108 /* clicked a letter */
109 if (widget >= WID_OSK_LETTERS) {
110 char32_t c = _keyboard[this->shift][widget - WID_OSK_LETTERS];
111
112 if (!IsValidChar(c, this->qs->text.afilter)) return;
113
114 if (this->qs->text.InsertChar(c)) this->OnEditboxChanged(WID_OSK_TEXT);
115
116 if (HasBit(_keystate, KEYS_SHIFT)) {
117 ToggleBit(_keystate, KEYS_SHIFT);
118 this->UpdateOskState();
119 this->SetDirty();
120 }
121 return;
122 }
123
124 switch (widget) {
126 if (this->qs->text.DeleteChar(WKC_BACKSPACE)) this->OnEditboxChanged(WID_OSK_TEXT);
127 break;
128
129 case WID_OSK_SPECIAL:
130 /*
131 * Anything device specific can go here.
132 * The button itself is hidden by default, and when you need it you
133 * can not hide it in the create event.
134 */
135 break;
136
137 case WID_OSK_CAPS:
138 ToggleBit(_keystate, KEYS_CAPS);
139 this->UpdateOskState();
140 this->SetDirty();
141 break;
142
143 case WID_OSK_SHIFT:
144 ToggleBit(_keystate, KEYS_SHIFT);
145 this->UpdateOskState();
146 this->SetDirty();
147 break;
148
149 case WID_OSK_SPACE:
150 if (this->qs->text.InsertChar(' ')) this->OnEditboxChanged(WID_OSK_TEXT);
151 break;
152
153 case WID_OSK_LEFT:
154 if (this->qs->text.MovePos(WKC_LEFT)) this->InvalidateData();
155 break;
156
157 case WID_OSK_RIGHT:
158 if (this->qs->text.MovePos(WKC_RIGHT)) this->InvalidateData();
159 break;
160
161 case WID_OSK_OK:
162 if (!this->qs->orig.has_value() || this->qs->text.GetText() != this->qs->orig) {
163 /* pass information by simulating a button press on parent window */
164 if (this->qs->ok_button >= 0) {
165 this->parent->OnClick(pt, this->qs->ok_button, 1);
166 /* Window gets deleted when the parent window removes itself. */
167 return;
168 }
169 }
170 this->Close();
171 break;
172
173 case WID_OSK_CANCEL:
174 if (this->qs->cancel_button >= 0) { // pass a cancel event to the parent window
175 this->parent->OnClick(pt, this->qs->cancel_button, 1);
176 /* Window gets deleted when the parent window removes itself. */
177 return;
178 } else { // or reset to original string
179 qs->text.Assign(this->orig_str);
180 qs->text.MovePos(WKC_END);
182 this->Close();
183 }
184 break;
185 }
186 }
187
188 void OnEditboxChanged(WidgetID widget) override
189 {
190 if (widget == WID_OSK_TEXT) {
192 this->parent->OnEditboxChanged(this->text_btn);
193 this->parent->SetWidgetDirty(this->text_btn);
194 }
195 }
196
197 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
198 {
199 if (!gui_scope) return;
201 this->parent->SetWidgetDirty(this->text_btn);
202 }
203
204 void OnFocusLost(bool closing) override
205 {
207 if (!closing) this->Close();
208 }
209};
210
211static const int HALF_KEY_WIDTH = 7; // Width of 1/2 key in pixels.
212static const int INTER_KEY_SPACE = 2; // Number of pixels between two keys.
213
214static const int TOP_KEY_PADDING = 2; // Vertical padding for the top row of keys.
215static const int KEY_PADDING = 6; // Vertical padding for remaining key rows.
216
227static void AddKey(std::unique_ptr<NWidgetHorizontal> &hor, int pad_y, int num_half, WidgetType widtype, WidgetID widnum, const WidgetData &widdata)
228{
229 int key_width = HALF_KEY_WIDTH + (INTER_KEY_SPACE + HALF_KEY_WIDTH) * (num_half - 1);
230
231 if (widtype == NWID_SPACER) {
232 auto spc = std::make_unique<NWidgetSpacer>(key_width, 0);
233 spc->SetMinimalTextLines(1, pad_y, FS_NORMAL);
234 hor->Add(std::move(spc));
235 } else {
236 auto leaf = std::make_unique<NWidgetLeaf>(widtype, COLOUR_GREY, widnum, widdata, STR_NULL);
237 leaf->SetMinimalSize(key_width, 0);
238 leaf->SetMinimalTextLines(1, pad_y, FS_NORMAL);
239 hor->Add(std::move(leaf));
240 }
241}
242
244static std::unique_ptr<NWidgetBase> MakeTopKeys()
245{
246 auto hor = std::make_unique<NWidgetHorizontal>();
247 hor->SetPIP(0, INTER_KEY_SPACE, 0);
248
249 AddKey(hor, TOP_KEY_PADDING, 6 * 2, WWT_TEXTBTN, WID_OSK_CANCEL, WidgetData{.string = STR_BUTTON_CANCEL});
250 AddKey(hor, TOP_KEY_PADDING, 6 * 2, WWT_TEXTBTN, WID_OSK_OK, WidgetData{.string = STR_BUTTON_OK});
251 AddKey(hor, TOP_KEY_PADDING, 2 * 2, WWT_PUSHIMGBTN, WID_OSK_BACKSPACE, WidgetData{.sprite = SPR_OSK_BACKSPACE});
252 return hor;
253}
254
256static std::unique_ptr<NWidgetBase> MakeNumberKeys()
257{
258 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
259 hor->SetPIP(0, INTER_KEY_SPACE, 0);
260
261 for (WidgetID widnum = WID_OSK_NUMBERS_FIRST; widnum <= WID_OSK_NUMBERS_LAST; widnum++) {
262 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
263 }
264 return hor;
265}
266
268static std::unique_ptr<NWidgetBase> MakeQwertyKeys()
269{
270 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
271 hor->SetPIP(0, INTER_KEY_SPACE, 0);
272
273 AddKey(hor, KEY_PADDING, 3, WWT_PUSHIMGBTN, WID_OSK_SPECIAL, WidgetData{.sprite = SPR_OSK_SPECIAL});
274 for (WidgetID widnum = WID_OSK_QWERTY_FIRST; widnum <= WID_OSK_QWERTY_LAST; widnum++) {
275 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
276 }
277 AddKey(hor, KEY_PADDING, 1, NWID_SPACER, 0, {});
278 return hor;
279}
280
282static std::unique_ptr<NWidgetBase> MakeAsdfgKeys()
283{
284 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
285 hor->SetPIP(0, INTER_KEY_SPACE, 0);
286
287 AddKey(hor, KEY_PADDING, 4, WWT_IMGBTN, WID_OSK_CAPS, WidgetData{.sprite = SPR_OSK_CAPS});
288 for (WidgetID widnum = WID_OSK_ASDFG_FIRST; widnum <= WID_OSK_ASDFG_LAST; widnum++) {
289 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
290 }
291 return hor;
292}
293
295static std::unique_ptr<NWidgetBase> MakeZxcvbKeys()
296{
297 std::unique_ptr<NWidgetHorizontal> hor = std::make_unique<NWidgetHorizontalLTR>();
298 hor->SetPIP(0, INTER_KEY_SPACE, 0);
299
300 AddKey(hor, KEY_PADDING, 3, WWT_IMGBTN, WID_OSK_SHIFT, WidgetData{.sprite = SPR_OSK_SHIFT});
301 for (WidgetID widnum = WID_OSK_ZXCVB_FIRST; widnum <= WID_OSK_ZXCVB_LAST; widnum++) {
302 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, {});
303 }
304 AddKey(hor, KEY_PADDING, 1, NWID_SPACER, 0, {});
305 return hor;
306}
307
309static std::unique_ptr<NWidgetBase> MakeSpacebarKeys()
310{
311 auto hor = std::make_unique<NWidgetHorizontal>();
312 hor->SetPIP(0, INTER_KEY_SPACE, 0);
313
314 AddKey(hor, KEY_PADDING, 8, NWID_SPACER, 0, {});
315 AddKey(hor, KEY_PADDING, 13, WWT_PUSHTXTBTN, WID_OSK_SPACE, WidgetData{.string = STR_EMPTY});
316 AddKey(hor, KEY_PADDING, 3, NWID_SPACER, 0, {});
317 AddKey(hor, KEY_PADDING, 2, WWT_PUSHIMGBTN, WID_OSK_LEFT, WidgetData{.sprite = SPR_OSK_LEFT});
318 AddKey(hor, KEY_PADDING, 2, WWT_PUSHIMGBTN, WID_OSK_RIGHT, WidgetData{.sprite = SPR_OSK_RIGHT});
319 return hor;
320}
321
322
323static constexpr NWidgetPart _nested_osk_widgets[] = {
324 NWidget(WWT_CAPTION, COLOUR_GREY, WID_OSK_CAPTION), SetTextStyle(TC_WHITE),
325 NWidget(WWT_PANEL, COLOUR_GREY),
326 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_OSK_TEXT), SetMinimalSize(252, 0), SetPadding(2, 2, 2, 2),
327 EndContainer(),
328 NWidget(WWT_PANEL, COLOUR_GREY),
329 NWidget(NWID_VERTICAL), SetPadding(3), SetPIP(0, INTER_KEY_SPACE, 0),
336 EndContainer(),
337 EndContainer(),
338};
339
340static WindowDesc _osk_desc(
341 WDP_CENTER, nullptr, 0, 0,
343 {},
344 _nested_osk_widgets
345);
346
352{
353 std::string keyboard[2];
354 std::string errormark[2]; // used for marking invalid chars
355 bool has_error = false; // true when an invalid char is detected
356
357 keyboard[0] = _keyboard_opt[0].empty() ? GetString(STR_OSK_KEYBOARD_LAYOUT) : _keyboard_opt[0];
358 keyboard[1] = _keyboard_opt[1].empty() ? GetString(STR_OSK_KEYBOARD_LAYOUT_CAPS) : _keyboard_opt[1];
359
360 for (uint j = 0; j < 2; j++) {
361 auto kbd = keyboard[j].begin();
362 bool ended = false;
363 for (uint i = 0; i < OSK_KEYBOARD_ENTRIES; i++) {
364 _keyboard[j][i] = Utf8Consume(kbd);
365
366 /* Be lenient when the last characters are missing (is quite normal) */
367 if (_keyboard[j][i] == '\0' || ended) {
368 ended = true;
369 _keyboard[j][i] = ' ';
370 continue;
371 }
372
373 if (IsPrintable(_keyboard[j][i])) {
374 errormark[j] += ' ';
375 } else {
376 has_error = true;
377 errormark[j] += '^';
378 _keyboard[j][i] = ' ';
379 }
380 }
381 }
382
383 if (has_error) {
384 ShowInfo("The keyboard layout you selected contains invalid chars. Please check those chars marked with ^.");
385 ShowInfo("Normal keyboard: {}", keyboard[0]);
386 ShowInfo(" {}", errormark[0]);
387 ShowInfo("Caps Lock: {}", keyboard[1]);
388 ShowInfo(" {}", errormark[1]);
389 }
390}
391
398{
400
402 new OskWindow(_osk_desc, parent, button);
403}
404
412void UpdateOSKOriginalText(const Window *parent, WidgetID button)
413{
414 OskWindow *osk = dynamic_cast<OskWindow *>(FindWindowById(WC_OSK, 0));
415 if (osk == nullptr || osk->parent != parent || osk->text_btn != button) return;
416
417 osk->orig_str = osk->qs->text.GetText();
418
419 osk->SetDirty();
420}
421
428bool IsOSKOpenedFor(const Window *w, WidgetID button)
429{
430 OskWindow *osk = dynamic_cast<OskWindow *>(FindWindowById(WC_OSK, 0));
431 return osk != nullptr && osk->parent == w && osk->text_btn == button;
432}
debug_inline constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr T ToggleBit(T &x, const uint8_t y)
Toggles a bit in a variable.
Base class for a 'real' widget.
StringID GetString() const
Get the string that has been set for this nested widget.
Definition widget.cpp:1225
virtual void EditBoxLostFocus()
An edit box lost the input focus.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Functions related to debugging.
void DrawCharCentered(char32_t c, const Rect &r, TextColour colour)
Draw single character horizontally centered around (x,y)
Definition gfx.cpp:906
Functions related to the gfx engine.
@ FS_NORMAL
Index of the normal font in the font tables.
Definition gfx_type.h:243
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition window.cpp:943
static void AddKey(std::unique_ptr< NWidgetHorizontal > &hor, int pad_y, int num_half, WidgetType widtype, WidgetID widnum, const WidgetData &widdata)
Add a key widget to a row of the keyboard.
Definition osk_gui.cpp:227
static std::unique_ptr< NWidgetBase > MakeZxcvbKeys()
Construct the zxcvb row keys.
Definition osk_gui.cpp:295
void ShowOnScreenKeyboard(Window *parent, WidgetID button)
Show the on-screen keyboard (osk) associated with a given textbox.
Definition osk_gui.cpp:397
std::string _keyboard_opt[2]
The number of characters has to be OSK_KEYBOARD_ENTRIES.
Definition osk_gui.cpp:27
static std::unique_ptr< NWidgetBase > MakeNumberKeys()
Construct the row containing the digit keys.
Definition osk_gui.cpp:256
static std::unique_ptr< NWidgetBase > MakeAsdfgKeys()
Construct the asdfg row keys.
Definition osk_gui.cpp:282
static std::unique_ptr< NWidgetBase > MakeTopKeys()
Construct the top row keys (cancel, ok, backspace).
Definition osk_gui.cpp:244
void GetKeyboardLayout()
Retrieve keyboard layout from language string or (if set) config file.
Definition osk_gui.cpp:351
static std::unique_ptr< NWidgetBase > MakeSpacebarKeys()
Construct the spacebar row keys.
Definition osk_gui.cpp:309
bool IsOSKOpenedFor(const Window *w, WidgetID button)
Check whether the OSK is opened for a specific editbox.
Definition osk_gui.cpp:428
void UpdateOSKOriginalText(const Window *parent, WidgetID button)
Updates the original text of the OSK so when the 'parent' changes the original and you press on cance...
Definition osk_gui.cpp:412
static std::unique_ptr< NWidgetBase > MakeQwertyKeys()
Construct the qwerty row keys.
Definition osk_gui.cpp:268
Types related to the osk widgets.
@ WID_OSK_CAPTION
Caption of window.
Definition osk_widget.h:15
@ WID_OSK_QWERTY_FIRST
First widget of the qwerty row.
Definition osk_widget.h:31
@ WID_OSK_BACKSPACE
Backspace key.
Definition osk_widget.h:19
@ WID_OSK_SPACE
Space bar.
Definition osk_widget.h:23
@ WID_OSK_TEXT
Edit box.
Definition osk_widget.h:16
@ WID_OSK_QWERTY_LAST
Last widget of the qwerty row.
Definition osk_widget.h:32
@ WID_OSK_CANCEL
Cancel key.
Definition osk_widget.h:17
@ WID_OSK_LEFT
Cursor left key.
Definition osk_widget.h:24
@ WID_OSK_RIGHT
Cursor right key.
Definition osk_widget.h:25
@ WID_OSK_NUMBERS_FIRST
First widget of the numbers row.
Definition osk_widget.h:28
@ WID_OSK_SPECIAL
Special key (at keyboards often used for tab key).
Definition osk_widget.h:20
@ WID_OSK_CAPS
Capslock key.
Definition osk_widget.h:21
@ WID_OSK_OK
Ok key.
Definition osk_widget.h:18
@ WID_OSK_ASDFG_LAST
Last widget of the asdfg row.
Definition osk_widget.h:35
@ WID_OSK_ZXCVB_FIRST
First widget of the zxcvb row.
Definition osk_widget.h:37
@ WID_OSK_LETTERS
First widget of the 'normal' keys.
Definition osk_widget.h:26
@ WID_OSK_ASDFG_FIRST
First widget of the asdfg row.
Definition osk_widget.h:34
@ WID_OSK_SHIFT
Shift(lock) key.
Definition osk_widget.h:22
@ WID_OSK_ZXCVB_LAST
Last widget of the zxcvb row.
Definition osk_widget.h:38
@ WID_OSK_NUMBERS_LAST
Last widget of the numbers row.
Definition osk_widget.h:29
Base for the GUIs that have an edit box in them.
A number of safeguards to prevent using unsafe methods.
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
bool IsValidChar(char32_t key, CharSetFilter afilter)
Only allow certain keys.
Definition string.cpp:414
Functions related to low-level strings.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:426
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Partial widget specification to allow NWidgets to be written nested.
StringID caption
the caption for this window.
Definition osk_gui.cpp:38
WidgetID text_btn
widget number of parent's text field
Definition osk_gui.cpp:40
bool shift
Is the shift effectively pressed?
Definition osk_gui.cpp:43
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
Definition osk_gui.cpp:98
void OnEditboxChanged(WidgetID widget) override
The text in an editbox has been edited.
Definition osk_gui.cpp:188
void OnFocusLost(bool closing) override
The window has lost focus.
Definition osk_gui.cpp:204
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition osk_gui.cpp:197
QueryString * qs
text-input
Definition osk_gui.cpp:39
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition osk_gui.cpp:106
std::string orig_str
Original string.
Definition osk_gui.cpp:42
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
Definition osk_gui.cpp:91
Textbuf * text
pointer to parent's textbuffer (to update caret position)
Definition osk_gui.cpp:41
void UpdateOskState()
Only show valid characters; do not show characters that would only insert a space when we have a spac...
Definition osk_gui.cpp:77
Coordinates of a point in 2D.
Data stored about a string that can be modified in the GUI.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Specification of a rectangle with absolute coordinates of all edges.
Helper/buffer for input fields.
bool MovePos(uint16_t keycode)
Handle text navigation with arrow keys left/right.
Definition textbuf.cpp:365
bool DeleteChar(uint16_t keycode)
Delete a character from a textbuffer, either with 'Delete' or 'Backspace' The character is delete fro...
Definition textbuf.cpp:50
void Assign(const std::string_view text)
Copy a string into the textbuffer.
Definition textbuf.cpp:422
const char * GetText() const
Get the current text.
Definition textbuf.cpp:286
CharSetFilter afilter
Allowed characters.
bool InsertChar(char32_t key)
Insert a character to a textbuffer.
Definition textbuf.cpp:128
Container with the data associated to a single widget.
High level window description.
Definition window_gui.h:168
Data structure for an opened window.
Definition window_gui.h:274
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1050
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition window_gui.h:321
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition window.cpp:3164
Window * parent
Parent window.
Definition window_gui.h:329
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:554
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:502
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:392
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition window.cpp:483
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:442
virtual void OnEditboxChanged(WidgetID widget)
The text in an editbox has been edited.
Definition window_gui.h:768
virtual void OnClick(Point pt, WidgetID widget, int click_count)
A click with the left mouse button has been made on the window.
Definition window_gui.h:667
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition window_gui.h:973
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1749
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:382
static const uint OSK_KEYBOARD_ENTRIES
The number of 'characters' on the on-screen keyboard.
Definition textbuf_gui.h:33
Base of all video drivers.
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition widget_type.h:36
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ WWT_IMGBTN
(Toggle) Button with image
Definition widget_type.h:42
@ WWT_PUSHBTN
Normal push-button (no toggle button) with custom drawing.
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:69
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:61
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:45
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:40
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition widget_type.h:51
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:67
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1143
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition window.cpp:1101
Window functions not directly related to making/drawing windows.
@ WDP_CENTER
Center the window.
Definition window_gui.h:146
int WidgetID
Widget ID.
Definition window_type.h:20
@ WC_OSK
On Screen Keyboard; Window numbers:
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition window_type.h:47
Functions related to zooming.