OpenTTD Source: src/osk_gui.cpp Source File

OpenTTD Source 12.0-beta1

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"
17 #include "video/video_driver.hpp"
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
27 std::string _keyboard_opt[2];
28 static WChar _keyboard[2][OSK_KEYBOARD_ENTRIES];
29
30 enum KeyStateBits {
31 KEYS_NONE,
32 KEYS_SHIFT,
33 KEYS_CAPS
34 };
35 static byte _keystate = KEYS_NONE;
36
37 struct OskWindow : public Window {
38 StringID caption;
39 QueryString *qs;
40 int text_btn;
41 Textbuf *text;
42 char *orig_str_buf;
43 bool shift;
44
45 OskWindow(WindowDesc *desc, Window *parent, int button) : Window(desc)
46 {
47 this->parent = parent;
48 assert(parent != nullptr);
49
50 NWidgetCore *par_wid = parent->GetWidget<NWidgetCore>(button);
51 assert(par_wid != nullptr);
52
53 assert(parent->querystrings.Contains(button));
54 this->qs = parent->querystrings.Find(button)->second;
55 this->caption = (par_wid->widget_data != STR_NULL) ? par_wid->widget_data : 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_buf = stredup(this->qs->text.buf);
62
63 this->InitNested(0);
64 this->SetFocusedWidget(WID_OSK_TEXT);
65
66 /* Not needed by default. */
67 this->DisableWidget(WID_OSK_SPECIAL);
68
69 this->UpdateOskState();
70 }
71
72 ~OskWindow()
73 {
74 free(this->orig_str_buf);
75 }
76
82 void UpdateOskState()
83 {
84 this->shift = HasBit(_keystate, KEYS_CAPS) ^ HasBit(_keystate, KEYS_SHIFT);
85
86 for (uint i = 0; i < OSK_KEYBOARD_ENTRIES; i++) {
87 this->SetWidgetDisabledState(WID_OSK_LETTERS + i,
88 !IsValidChar(_keyboard[this->shift][i], this->qs->text.afilter) || _keyboard[this->shift][i] == ' ');
89 }
90 this->SetWidgetDisabledState(WID_OSK_SPACE, !IsValidChar(' ', this->qs->text.afilter));
91
92 this->SetWidgetLoweredState(WID_OSK_SHIFT, HasBit(_keystate, KEYS_SHIFT));
93 this->SetWidgetLoweredState(WID_OSK_CAPS, HasBit(_keystate, KEYS_CAPS));
94 }
95
96 void SetStringParameters(int widget) const override
97 {
98 if (widget == WID_OSK_CAPTION) SetDParam(0, this->caption);
99 }
100
101 void DrawWidget(const Rect &r, int widget) const override
102 {
103 if (widget < WID_OSK_LETTERS) return;
104
105 widget -= WID_OSK_LETTERS;
106 DrawCharCentered(_keyboard[this->shift][widget], r, TC_BLACK);
107 }
108
109 void OnClick(Point pt, int widget, int click_count) override
110 {
111 /* clicked a letter */
112 if (widget >= WID_OSK_LETTERS) {
113 WChar c = _keyboard[this->shift][widget - WID_OSK_LETTERS];
114
115 if (!IsValidChar(c, this->qs->text.afilter)) return;
116
117 if (this->qs->text.InsertChar(c)) this->OnEditboxChanged(WID_OSK_TEXT);
118
119 if (HasBit(_keystate, KEYS_SHIFT)) {
120 ToggleBit(_keystate, KEYS_SHIFT);
121 this->UpdateOskState();
122 this->SetDirty();
123 }
124 return;
125 }
126
127 switch (widget) {
128 case WID_OSK_BACKSPACE:
129 if (this->qs->text.DeleteChar(WKC_BACKSPACE)) this->OnEditboxChanged(WID_OSK_TEXT);
130 break;
131
132 case WID_OSK_SPECIAL:
133 /*
134 * Anything device specific can go here.
135 * The button itself is hidden by default, and when you need it you
136 * can not hide it in the create event.
137 */
138 break;
139
140 case WID_OSK_CAPS:
141 ToggleBit(_keystate, KEYS_CAPS);
142 this->UpdateOskState();
143 this->SetDirty();
144 break;
145
146 case WID_OSK_SHIFT:
147 ToggleBit(_keystate, KEYS_SHIFT);
148 this->UpdateOskState();
149 this->SetDirty();
150 break;
151
152 case WID_OSK_SPACE:
153 if (this->qs->text.InsertChar(' ')) this->OnEditboxChanged(WID_OSK_TEXT);
154 break;
155
156 case WID_OSK_LEFT:
157 if (this->qs->text.MovePos(WKC_LEFT)) this->InvalidateData();
158 break;
159
160 case WID_OSK_RIGHT:
161 if (this->qs->text.MovePos(WKC_RIGHT)) this->InvalidateData();
162 break;
163
164 case WID_OSK_OK:
165 if (this->qs->orig == nullptr || strcmp(this->qs->text.buf, this->qs->orig) != 0) {
166 /* pass information by simulating a button press on parent window */
167 if (this->qs->ok_button >= 0) {
168 this->parent->OnClick(pt, this->qs->ok_button, 1);
169 /* Window gets deleted when the parent window removes itself. */
170 return;
171 }
172 }
173 this->Close();
174 break;
175
176 case WID_OSK_CANCEL:
177 if (this->qs->cancel_button >= 0) { // pass a cancel event to the parent window
178 this->parent->OnClick(pt, this->qs->cancel_button, 1);
179 /* Window gets deleted when the parent window removes itself. */
180 return;
181 } else { // or reset to original string
182 qs->text.Assign(this->orig_str_buf);
183 qs->text.MovePos(WKC_END);
184 this->OnEditboxChanged(WID_OSK_TEXT);
185 this->Close();
186 }
187 break;
188 }
189 }
190
191 void OnEditboxChanged(int widget) override
192 {
193 this->SetWidgetDirty(WID_OSK_TEXT);
194 this->parent->OnEditboxChanged(this->text_btn);
195 this->parent->SetWidgetDirty(this->text_btn);
196 }
197
198 void OnInvalidateData(int data = 0, bool gui_scope = true) override
199 {
200 if (!gui_scope) return;
201 this->SetWidgetDirty(WID_OSK_TEXT);
202 this->parent->SetWidgetDirty(this->text_btn);
203 }
204
205 void OnFocusLost() override
206 {
207 VideoDriver::GetInstance()->EditBoxLostFocus();
208 this->Close();
209 }
210 };
211
212 static const int HALF_KEY_WIDTH = 7; // Width of 1/2 key in pixels.
213 static const int INTER_KEY_SPACE = 2; // Number of pixels between two keys.
214
215 static const int TOP_KEY_PADDING = 2; // Vertical padding for the top row of keys.
216 static const int KEY_PADDING = 6; // Vertical padding for remaining key rows.
217
229 static void AddKey(NWidgetHorizontal *hor, int pad_y, int num_half, WidgetType widtype, int widnum, uint16 widdata, int *biggest_index)
230 {
231 int key_width = HALF_KEY_WIDTH + (INTER_KEY_SPACE + HALF_KEY_WIDTH) * (num_half - 1);
232
233 if (widtype == NWID_SPACER) {
234 if (!hor->IsEmpty()) key_width += INTER_KEY_SPACE;
235 NWidgetSpacer *spc = new NWidgetSpacer(key_width, 0);
236 spc->SetMinimalTextLines(1, pad_y, FS_NORMAL);
237 hor->Add(spc);
238 } else {
239 if (!hor->IsEmpty()) {
240 NWidgetSpacer *spc = new NWidgetSpacer(INTER_KEY_SPACE, 0);
241 spc->SetMinimalTextLines(1, pad_y, FS_NORMAL);
242 hor->Add(spc);
243 }
244 NWidgetLeaf *leaf = new NWidgetLeaf(widtype, COLOUR_GREY, widnum, widdata, STR_NULL);
245 leaf->SetMinimalSize(key_width, 0);
246 leaf->SetMinimalTextLines(1, pad_y, FS_NORMAL);
247 hor->Add(leaf);
248 }
249
250 *biggest_index = std::max(*biggest_index, widnum);
251 }
252
254 static NWidgetBase *MakeTopKeys(int *biggest_index)
255 {
256 NWidgetHorizontal *hor = new NWidgetHorizontal();
257
258 AddKey(hor, TOP_KEY_PADDING, 6 * 2, WWT_TEXTBTN, WID_OSK_CANCEL, STR_BUTTON_CANCEL, biggest_index);
259 AddKey(hor, TOP_KEY_PADDING, 6 * 2, WWT_TEXTBTN, WID_OSK_OK, STR_BUTTON_OK, biggest_index);
260 AddKey(hor, TOP_KEY_PADDING, 2 * 2, WWT_PUSHIMGBTN, WID_OSK_BACKSPACE, SPR_OSK_BACKSPACE, biggest_index);
261 return hor;
262 }
263
265 static NWidgetBase *MakeNumberKeys(int *biggest_index)
266 {
267 NWidgetHorizontal *hor = new NWidgetHorizontalLTR();
268
269 for (int widnum = WID_OSK_NUMBERS_FIRST; widnum <= WID_OSK_NUMBERS_LAST; widnum++) {
270 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, 0x0, biggest_index);
271 }
272 return hor;
273 }
274
276 static NWidgetBase *MakeQwertyKeys(int *biggest_index)
277 {
278 NWidgetHorizontal *hor = new NWidgetHorizontalLTR();
279
280 AddKey(hor, KEY_PADDING, 3, WWT_PUSHIMGBTN, WID_OSK_SPECIAL, SPR_OSK_SPECIAL, biggest_index);
281 for (int widnum = WID_OSK_QWERTY_FIRST; widnum <= WID_OSK_QWERTY_LAST; widnum++) {
282 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, 0x0, biggest_index);
283 }
284 AddKey(hor, KEY_PADDING, 1, NWID_SPACER, 0, 0, biggest_index);
285 return hor;
286 }
287
289 static NWidgetBase *MakeAsdfgKeys(int *biggest_index)
290 {
291 NWidgetHorizontal *hor = new NWidgetHorizontalLTR();
292
293 AddKey(hor, KEY_PADDING, 4, WWT_IMGBTN, WID_OSK_CAPS, SPR_OSK_CAPS, biggest_index);
294 for (int widnum = WID_OSK_ASDFG_FIRST; widnum <= WID_OSK_ASDFG_LAST; widnum++) {
295 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, 0x0, biggest_index);
296 }
297 return hor;
298 }
299
301 static NWidgetBase *MakeZxcvbKeys(int *biggest_index)
302 {
303 NWidgetHorizontal *hor = new NWidgetHorizontalLTR();
304
305 AddKey(hor, KEY_PADDING, 3, WWT_IMGBTN, WID_OSK_SHIFT, SPR_OSK_SHIFT, biggest_index);
306 for (int widnum = WID_OSK_ZXCVB_FIRST; widnum <= WID_OSK_ZXCVB_LAST; widnum++) {
307 AddKey(hor, KEY_PADDING, 2, WWT_PUSHBTN, widnum, 0x0, biggest_index);
308 }
309 AddKey(hor, KEY_PADDING, 1, NWID_SPACER, 0, 0, biggest_index);
310 return hor;
311 }
312
314 static NWidgetBase *MakeSpacebarKeys(int *biggest_index)
315 {
316 NWidgetHorizontal *hor = new NWidgetHorizontal();
317
318 AddKey(hor, KEY_PADDING, 8, NWID_SPACER, 0, 0, biggest_index);
319 AddKey(hor, KEY_PADDING, 13, WWT_PUSHTXTBTN, WID_OSK_SPACE, STR_EMPTY, biggest_index);
320 AddKey(hor, KEY_PADDING, 3, NWID_SPACER, 0, 0, biggest_index);
321 AddKey(hor, KEY_PADDING, 2, WWT_PUSHIMGBTN, WID_OSK_LEFT, SPR_OSK_LEFT, biggest_index);
322 AddKey(hor, KEY_PADDING, 2, WWT_PUSHIMGBTN, WID_OSK_RIGHT, SPR_OSK_RIGHT, biggest_index);
323 return hor;
324 }
325
326
327 static const NWidgetPart _nested_osk_widgets[] = {
328 NWidget(WWT_CAPTION, COLOUR_GREY, WID_OSK_CAPTION), SetDataTip(STR_WHITE_STRING, STR_NULL),
329 NWidget(WWT_PANEL, COLOUR_GREY),
330 NWidget(WWT_EDITBOX, COLOUR_GREY, WID_OSK_TEXT), SetMinimalSize(252, 12), SetPadding(2, 2, 2, 2),
331 EndContainer(),
332 NWidget(WWT_PANEL, COLOUR_GREY), SetPIP(5, 2, 3),
333 NWidgetFunction(MakeTopKeys), SetPadding(0, 3, 0, 3),
334 NWidgetFunction(MakeNumberKeys), SetPadding(0, 3, 0, 3),
335 NWidgetFunction(MakeQwertyKeys), SetPadding(0, 3, 0, 3),
336 NWidgetFunction(MakeAsdfgKeys), SetPadding(0, 3, 0, 3),
337 NWidgetFunction(MakeZxcvbKeys), SetPadding(0, 3, 0, 3),
338 NWidgetFunction(MakeSpacebarKeys), SetPadding(0, 3, 0, 3),
339 EndContainer(),
340 };
341
342 static WindowDesc _osk_desc(
343 WDP_CENTER, "query_osk", 0, 0,
344 WC_OSK, WC_NONE,
345 0,
346 _nested_osk_widgets, lengthof(_nested_osk_widgets)
347 );
348
353 void GetKeyboardLayout()
354 {
355 char keyboard[2][OSK_KEYBOARD_ENTRIES * 4 + 1];
356 char errormark[2][OSK_KEYBOARD_ENTRIES + 1]; // used for marking invalid chars
357 bool has_error = false; // true when an invalid char is detected
358
359 if (_keyboard_opt[0].empty()) {
360 GetString(keyboard[0], STR_OSK_KEYBOARD_LAYOUT, lastof(keyboard[0]));
361 } else {
362 strecpy(keyboard[0], _keyboard_opt[0].c_str(), lastof(keyboard[0]));
363 }
364
365 if (_keyboard_opt[1].empty()) {
366 GetString(keyboard[1], STR_OSK_KEYBOARD_LAYOUT_CAPS, lastof(keyboard[1]));
367 } else {
368 strecpy(keyboard[1], _keyboard_opt[1].c_str(), lastof(keyboard[1]));
369 }
370
371 for (uint j = 0; j < 2; j++) {
372 const char *kbd = keyboard[j];
373 bool ended = false;
374 for (uint i = 0; i < OSK_KEYBOARD_ENTRIES; i++) {
375 _keyboard[j][i] = Utf8Consume(&kbd);
376
377 /* Be lenient when the last characters are missing (is quite normal) */
378 if (_keyboard[j][i] == '\0' || ended) {
379 ended = true;
380 _keyboard[j][i] = ' ';
381 continue;
382 }
383
384 if (IsPrintable(_keyboard[j][i])) {
385 errormark[j][i] = ' ';
386 } else {
387 has_error = true;
388 errormark[j][i] = '^';
389 _keyboard[j][i] = ' ';
390 }
391 }
392 }
393
394 if (has_error) {
395 ShowInfoF("The keyboard layout you selected contains invalid chars. Please check those chars marked with ^.");
396 ShowInfoF("Normal keyboard: %s", keyboard[0]);
397 ShowInfoF(" %s", errormark[0]);
398 ShowInfoF("Caps Lock: %s", keyboard[1]);
399 ShowInfoF(" %s", errormark[1]);
400 }
401 }
402
408 void ShowOnScreenKeyboard(Window *parent, int button)
409 {
410 CloseWindowById(WC_OSK, 0);
411
412 GetKeyboardLayout();
413 new OskWindow(&_osk_desc, parent, button);
414 }
415
423 void UpdateOSKOriginalText(const Window *parent, int button)
424 {
425 OskWindow *osk = dynamic_cast<OskWindow *>(FindWindowById(WC_OSK, 0));
426 if (osk == nullptr || osk->parent != parent || osk->text_btn != button) return;
427
428 free(osk->orig_str_buf);
429 osk->orig_str_buf = stredup(osk->qs->text.buf);
430
431 osk->SetDirty();
432 }
433
440 bool IsOSKOpenedFor(const Window *w, int button)
441 {
442 OskWindow *osk = dynamic_cast<OskWindow *>(FindWindowById(WC_OSK, 0));
443 return osk != nullptr && osk->parent == w && osk->text_btn == button;
444 }
OskWindow
Definition: osk_gui.cpp:37
OskWindow::OnFocusLost
void OnFocusLost() override
Called when window loses focus.
Definition: osk_gui.cpp:205
WID_OSK_QWERTY_LAST
@ WID_OSK_QWERTY_LAST
Last widget of the qwerty row.
Definition: osk_widget.h:32
NWidgetFunction
static NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
Definition: widget_type.h:1239
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:27
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:35
querystring_gui.h
Window::OnEditboxChanged
virtual void OnEditboxChanged(int widget)
The text in an editbox has been edited.
Definition: window_gui.h:726
OskWindow::OnEditboxChanged
void OnEditboxChanged(int widget) override
The text in an editbox has been edited.
Definition: osk_gui.cpp:191
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1139
WID_OSK_SPECIAL
@ WID_OSK_SPECIAL
Special key (at keyboards often used for tab key).
Definition: osk_widget.h:20
WID_OSK_OK
@ WID_OSK_OK
Ok key.
Definition: osk_widget.h:18
WID_OSK_ZXCVB_FIRST
@ WID_OSK_ZXCVB_FIRST
First widget of the zxcvb row.
Definition: osk_widget.h:37
WID_OSK_BACKSPACE
@ WID_OSK_BACKSPACE
Backspace key.
Definition: osk_widget.h:19
NWidgetContainer::Add
void Add(NWidgetBase *wid)
Append widget wid to container.
Definition: widget.cpp:1047
MakeQwertyKeys
static NWidgetBase * MakeQwertyKeys(int *biggest_index)
Construct the qwerty row keys.
Definition: osk_gui.cpp:276
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
MakeSpacebarKeys
static NWidgetBase * MakeSpacebarKeys(int *biggest_index)
Construct the spacebar row keys.
Definition: osk_gui.cpp:314
WWT_IMGBTN
@ WWT_IMGBTN
(Toggle) Button with image
Definition: widget_type.h:50
Textbuf::Assign
void Assign(StringID string)
Render a string into the textbuffer.
Definition: textbuf.cpp:396
NWidgetResizeBase::SetMinimalTextLines
void SetMinimalTextLines(uint8 min_lines, uint8 spacing, FontSize size)
Set minimal text lines for the widget.
Definition: widget.cpp:892
Textbuf::MovePos
bool MovePos(uint16 keycode)
Handle text navigation with arrow keys left/right.
Definition: textbuf.cpp:319
FindWindowById
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
Definition: window.cpp:1146
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
NWidgetSpacer
Spacer widget.
Definition: widget_type.h:568
WID_OSK_ZXCVB_LAST
@ WID_OSK_ZXCVB_LAST
Last widget of the zxcvb row.
Definition: osk_widget.h:38
zoom_func.h
NWidgetLeaf
Leaf widget.
Definition: widget_type.h:815
WID_OSK_SHIFT
@ WID_OSK_SHIFT
Shift(lock) key.
Definition: osk_widget.h:22
WC_OSK
@ WC_OSK
On Screen Keyboard; Window numbers:
Definition: window_type.h:154
IsOSKOpenedFor
bool IsOSKOpenedFor(const Window *w, int button)
Check whether the OSK is opened for a specific editbox.
Definition: osk_gui.cpp:440
WID_OSK_LETTERS
@ WID_OSK_LETTERS
First widget of the 'normal' keys.
Definition: osk_widget.h:26
osk_widget.h
OskWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: osk_gui.cpp:101
WID_OSK_CAPTION
@ WID_OSK_CAPTION
Caption of window.
Definition: osk_widget.h:15
MakeZxcvbKeys
static NWidgetBase * MakeZxcvbKeys(int *biggest_index)
Construct the zxcvb row keys.
Definition: osk_gui.cpp:301
WID_OSK_RIGHT
@ WID_OSK_RIGHT
Cursor right key.
Definition: osk_widget.h:25
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:196
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:971
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1107
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
NWidgetCore::widget_data
uint32 widget_data
Data of the widget.
Definition: widget_type.h:335
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
Window::querystrings
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:323
gfx_func.h
WindowDesc
High level window description.
Definition: window_gui.h:168
Window::GetWidget
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
Definition: window_gui.h:908
WID_OSK_LEFT
@ WID_OSK_LEFT
Cursor left key.
Definition: osk_widget.h:24
WWT_PUSHBTN
@ WWT_PUSHBTN
Normal push-button (no toggle button) with custom drawing.
Definition: widget_type.h:103
MakeNumberKeys
static NWidgetBase * MakeNumberKeys(int *biggest_index)
Construct the row containing the digit keys.
Definition: osk_gui.cpp:265
FS_NORMAL
@ FS_NORMAL
Index of the normal font in the font tables.
Definition: gfx_type.h:207
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1789
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:69
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:993
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:104
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:126
OSK_KEYBOARD_ENTRIES
static const uint OSK_KEYBOARD_ENTRIES
The number of 'characters' on the on-screen keyboard.
Definition: textbuf_gui.h:35
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:386
Window::parent
Window * parent
Parent window.
Definition: window_gui.h:332
safeguards.h
IsValidChar
bool IsValidChar(WChar key, CharSetFilter afilter)
Only allow certain keys.
Definition: string.cpp:476
Textbuf::DeleteChar
bool DeleteChar(uint16 keycode)
Delete a character from a textbuffer, either with 'Delete' or 'Backspace' The character is delete fro...
Definition: textbuf.cpp:53
WID_OSK_ASDFG_LAST
@ WID_OSK_ASDFG_LAST
Last widget of the asdfg row.
Definition: osk_widget.h:35
sprites.h
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
Textbuf::afilter
CharSetFilter afilter
Allowed characters.
Definition: textbuf_type.h:31
DrawCharCentered
void DrawCharCentered(WChar c, const Rect &r, TextColour colour)
Draw single character horizontally centered around (x,y)
Definition: gfx.cpp:959
_keyboard_opt
std::string _keyboard_opt[2]
The number of characters has to be OSK_KEYBOARD_ENTRIES.
Definition: osk_gui.cpp:27
Window::SetFocusedWidget
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:506
stdafx.h
GetKeyboardLayout
void GetKeyboardLayout()
Retrieve keyboard layout from language string or (if set) config file.
Definition: osk_gui.cpp:353
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3158
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:199
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:37
WidgetType
WidgetType
Window widget types, nested widget types, and nested widget part types.
Definition: widget_type.h:44
OskWindow::caption
StringID caption
the caption for this window.
Definition: osk_gui.cpp:38
NWidgetContainer::IsEmpty
bool IsEmpty()
Return whether the container is empty.
Definition: widget_type.h:410
OskWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: osk_gui.cpp:96
string_func.h
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WWT_PUSHIMGBTN
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
Definition: widget_type.h:105
Window::OnClick
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
Definition: window_gui.h:618
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:1092
strings_func.h
MakeTopKeys
static NWidgetBase * MakeTopKeys(int *biggest_index)
Construct the top row keys (cancel, ok, backspace).
Definition: osk_gui.cpp:254
NWidgetHorizontal
Horizontal container.
Definition: widget_type.h:493
OskWindow::text_btn
int text_btn
widget number of parent's text field
Definition: osk_gui.cpp:40
MakeAsdfgKeys
static NWidgetBase * MakeAsdfgKeys(int *biggest_index)
Construct the asdfg row keys.
Definition: osk_gui.cpp:289
video_driver.hpp
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1207
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:1010
UpdateOSKOriginalText
void UpdateOSKOriginalText(const Window *parent, int button)
Updates the original text of the OSK so when the 'parent' changes the original and you press on cance...
Definition: osk_gui.cpp:423
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
WID_OSK_ASDFG_FIRST
@ WID_OSK_ASDFG_FIRST
First widget of the asdfg row.
Definition: osk_widget.h:34
WID_OSK_CANCEL
@ WID_OSK_CANCEL
Cancel key.
Definition: osk_widget.h:17
ShowInfoF
void CDECL ShowInfoF(const char *str,...)
Shows some information on the console/a popup box depending on the OS.
Definition: openttd.cpp:154
WID_OSK_NUMBERS_FIRST
@ WID_OSK_NUMBERS_FIRST
First widget of the numbers row.
Definition: osk_widget.h:28
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
WID_OSK_TEXT
@ WID_OSK_TEXT
Edit box.
Definition: osk_widget.h:16
stredup
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
Definition: string.cpp:137
SmallMap::Find
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
Definition: smallmap_type.hpp:41
OskWindow::UpdateOskState
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:82
window_func.h
ToggleBit
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
Definition: bitmath_func.hpp:181
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:378
AddKey
static void AddKey(NWidgetHorizontal *hor, int pad_y, int num_half, WidgetType widtype, int widnum, uint16 widdata, int *biggest_index)
Add a key widget to a row of the keyboard.
Definition: osk_gui.cpp:229
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1169
CloseWindowById
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
Definition: window.cpp:1176
NWidgetHorizontalLTR
Horizontal container that doesn't change the direction of the widgets for RTL languages.
Definition: widget_type.h:505
ShowOnScreenKeyboard
void ShowOnScreenKeyboard(Window *parent, int button)
Show the on-screen keyboard (osk) associated with a given textbox.
Definition: osk_gui.cpp:408
VideoDriver::EditBoxLostFocus
virtual void EditBoxLostFocus()
An edit box lost the input focus.
Definition: video_driver.hpp:153
OskWindow::shift
bool shift
Is the shift effectively pressed?
Definition: osk_gui.cpp:43
Window
Data structure for an opened window.
Definition: window_gui.h:279
OskWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: osk_gui.cpp:109
OskWindow::text
Textbuf * text
pointer to parent's textbuffer (to update caret position)
Definition: osk_gui.cpp:41
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:112
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:460
WID_OSK_CAPS
@ WID_OSK_CAPS
Capslock key.
Definition: osk_widget.h:21
NWidgetCore
Base class for a 'real' widget.
Definition: widget_type.h:311
Window::SetWidgetDirty
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Definition: window.cpp:608
Textbuf::InsertChar
bool InsertChar(WChar key)
Insert a character to a textbuffer.
Definition: textbuf.cpp:132
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
OskWindow::qs
QueryString * qs
text-input
Definition: osk_gui.cpp:39
Window::DisableWidget
void DisableWidget(byte widget_index)
Sets a widget to disabled.
Definition: window_gui.h:396
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:394
NWidgetResizeBase::SetMinimalSize
void SetMinimalSize(uint min_x, uint min_y)
Set minimal size of the widget.
Definition: widget.cpp:866
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:157
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:447
OskWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: osk_gui.cpp:198
OskWindow::orig_str_buf
char * orig_str_buf
Original string.
Definition: osk_gui.cpp:42
WID_OSK_QWERTY_FIRST
@ WID_OSK_QWERTY_FIRST
First widget of the qwerty row.
Definition: osk_widget.h:31
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
WID_OSK_SPACE
@ WID_OSK_SPACE
Space bar.
Definition: osk_widget.h:23
WID_OSK_NUMBERS_LAST
@ WID_OSK_NUMBERS_LAST
Last widget of the numbers row.
Definition: osk_widget.h:29
debug.h
Textbuf
Helper/buffer for input fields.
Definition: textbuf_type.h:30
Window::Close
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
Definition: window.cpp:1092
SmallMap::Contains
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
Definition: smallmap_type.hpp:79