OpenTTD Source
12.0-beta2
|
Go to the documentation of this file.
23 #include "table/strings.h"
35 static byte _keystate = KEYS_NONE;
51 assert(par_wid !=
nullptr);
56 this->text_btn = button;
57 this->text = &this->qs->text;
61 this->orig_str_buf =
stredup(this->qs->text.
buf);
74 free(this->orig_str_buf);
84 this->shift =
HasBit(_keystate, KEYS_CAPS) ^
HasBit(_keystate, KEYS_SHIFT);
88 !
IsValidChar(_keyboard[this->shift][i], this->qs->text.
afilter) || _keyboard[this->shift][i] ==
' ');
119 if (
HasBit(_keystate, KEYS_SHIFT)) {
165 if (this->qs->orig ==
nullptr || strcmp(this->qs->text.
buf, this->qs->orig) != 0) {
182 qs->text.
Assign(this->orig_str_buf);
200 if (!gui_scope)
return;
212 static const int HALF_KEY_WIDTH = 7;
213 static const int INTER_KEY_SPACE = 2;
215 static const int TOP_KEY_PADDING = 2;
216 static const int KEY_PADDING = 6;
231 int key_width = HALF_KEY_WIDTH + (INTER_KEY_SPACE + HALF_KEY_WIDTH) * (num_half - 1);
234 if (!hor->
IsEmpty()) key_width += INTER_KEY_SPACE;
250 *biggest_index = std::max(*biggest_index, widnum);
346 _nested_osk_widgets,
lengthof(_nested_osk_widgets)
357 bool has_error =
false;
360 GetString(keyboard[0], STR_OSK_KEYBOARD_LAYOUT,
lastof(keyboard[0]));
366 GetString(keyboard[1], STR_OSK_KEYBOARD_LAYOUT_CAPS,
lastof(keyboard[1]));
371 for (uint j = 0; j < 2; j++) {
372 const char *kbd = keyboard[j];
375 _keyboard[j][i] = Utf8Consume(&kbd);
378 if (_keyboard[j][i] ==
'\0' || ended) {
380 _keyboard[j][i] =
' ';
384 if (IsPrintable(_keyboard[j][i])) {
385 errormark[j][i] =
' ';
388 errormark[j][i] =
'^';
389 _keyboard[j][i] =
' ';
395 ShowInfoF(
"The keyboard layout you selected contains invalid chars. Please check those chars marked with ^.");
396 ShowInfoF(
"Normal keyboard: %s", keyboard[0]);
413 new OskWindow(&_osk_desc, parent, button);
426 if (osk ==
nullptr || osk->
parent != parent || osk->
text_btn != button)
return;
443 return osk !=
nullptr && osk->
parent == w && osk->
text_btn == button;
void OnFocusLost() override
Called when window loses focus.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
char32_t WChar
Type for wide characters, i.e.
virtual void OnEditboxChanged(int widget)
The text in an editbox has been edited.
void OnEditboxChanged(int widget) override
The text in an editbox has been edited.
static NWidgetBase * MakeQwertyKeys(int *biggest_index)
Construct the qwerty row keys.
static NWidgetBase * MakeSpacebarKeys(int *biggest_index)
Construct the spacebar row keys.
void Assign(StringID string)
Render a string into the textbuffer.
bool MovePos(uint16 keycode)
Handle text navigation with arrow keys left/right.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
@ WC_OSK
On Screen Keyboard; Window numbers:
bool IsOSKOpenedFor(const Window *w, int button)
Check whether the OSK is opened for a specific editbox.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
static NWidgetBase * MakeZxcvbKeys(int *biggest_index)
Construct the zxcvb row keys.
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Data stored about a string that can be modified in the GUI.
char *const buf
buffer in which text is saved
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
High level window description.
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
static NWidgetBase * MakeNumberKeys(int *biggest_index)
Construct the row containing the digit keys.
@ FS_NORMAL
Index of the normal font in the font tables.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
static const uint OSK_KEYBOARD_ENTRIES
The number of 'characters' on the on-screen keyboard.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Window * parent
Parent window.
bool IsValidChar(WChar key, CharSetFilter afilter)
Only allow certain keys.
bool DeleteChar(uint16 keycode)
Delete a character from a textbuffer, either with 'Delete' or 'Backspace' The character is delete fro...
Coordinates of a point in 2D.
CharSetFilter afilter
Allowed characters.
void DrawCharCentered(WChar c, const Rect &r, TextColour colour)
Draw single character horizontally centered around (x,y)
std::string _keyboard_opt[2]
The number of characters has to be OSK_KEYBOARD_ENTRIES.
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
void GetKeyboardLayout()
Retrieve keyboard layout from language string or (if set) config file.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
StringID caption
the caption for this window.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
static NWidgetBase * MakeTopKeys(int *biggest_index)
Construct the top row keys (cancel, ok, backspace).
int text_btn
widget number of parent's text field
static NWidgetBase * MakeAsdfgKeys(int *biggest_index)
Construct the asdfg row keys.
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...
void CDECL ShowInfoF(const char *str,...)
Shows some information on the console/a popup box depending on the OS.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
void UpdateOskState()
Only show valid characters; do not show characters that would only insert a space when we have a spac...
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
#define lengthof(x)
Return the length of an fixed size array.
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.
void CloseWindowById(WindowClass cls, WindowNumber number, bool force)
Close a window by its class and window number (if it is open).
void ShowOnScreenKeyboard(Window *parent, int button)
Show the on-screen keyboard (osk) associated with a given textbox.
virtual void EditBoxLostFocus()
An edit box lost the input focus.
bool shift
Is the shift effectively pressed?
Data structure for an opened window.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Textbuf * text
pointer to parent's textbuffer (to update caret position)
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
bool InsertChar(WChar key)
Insert a character to a textbuffer.
Specification of a rectangle with absolute coordinates of all edges.
QueryString * qs
text-input
void DisableWidget(byte widget_index)
Sets a widget to disabled.
#define lastof(x)
Get the last element of an fixed size array.
@ WDP_CENTER
Center the window.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
char * orig_str_buf
Original string.
Helper/buffer for input fields.
virtual void Close()
Hide the window and all its child windows, and mark them for a later deletion.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.