22 #include "table/strings.h" 34 static byte _keystate = KEYS_NONE;
47 assert(parent !=
nullptr);
50 assert(par_wid !=
nullptr);
55 this->text_btn = button;
56 this->text = &this->qs->text;
60 this->orig_str_buf =
stredup(this->qs->text.buf);
73 free(this->orig_str_buf);
83 this->shift =
HasBit(_keystate, KEYS_CAPS) ^
HasBit(_keystate, KEYS_SHIFT);
87 !
IsValidChar(_keyboard[this->shift][i], this->qs->text.
afilter) || _keyboard[this->shift][i] ==
' ');
121 if (
HasBit(_keystate, KEYS_SHIFT)) {
167 if (this->qs->orig ==
nullptr || strcmp(this->qs->text.
buf, this->qs->orig) != 0) {
184 qs->text.
Assign(this->orig_str_buf);
202 if (!gui_scope)
return;
214 static const int HALF_KEY_WIDTH = 7;
215 static const int INTER_KEY_SPACE = 2;
230 int key_width = HALF_KEY_WIDTH + (INTER_KEY_SPACE + HALF_KEY_WIDTH) * (num_half - 1);
233 if (!hor->
IsEmpty()) key_width += INTER_KEY_SPACE;
246 *biggest_index =
max(*biggest_index, widnum);
348 _nested_osk_widgets,
lengthof(_nested_osk_widgets)
359 bool has_error =
false;
362 GetString(keyboard[0], STR_OSK_KEYBOARD_LAYOUT,
lastof(keyboard[0]));
368 GetString(keyboard[1], STR_OSK_KEYBOARD_LAYOUT_CAPS,
lastof(keyboard[1]));
373 for (uint j = 0; j < 2; j++) {
374 const char *kbd = keyboard[j];
377 _keyboard[j][i] = Utf8Consume(&kbd);
380 if (_keyboard[j][i] ==
'\0' || ended) {
382 _keyboard[j][i] =
' ';
386 if (IsPrintable(_keyboard[j][i])) {
387 errormark[j][i] =
' ';
390 errormark[j][i] =
'^';
391 _keyboard[j][i] =
' ';
397 ShowInfoF(
"The keyboard layout you selected contains invalid chars. Please check those chars marked with ^.");
398 ShowInfoF(
"Normal keyboard: %s", keyboard[0]);
415 new OskWindow(&_osk_desc, parent, button);
428 if (osk ==
nullptr || osk->
parent != parent || osk->
text_btn != button)
return;
445 return osk !=
nullptr && osk->
parent == w && osk->
text_btn == button;
Functions related to OTTD's strings.
bool MovePos(uint16 keycode)
Handle text navigation with arrow keys left/right.
Base of all video drivers.
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Window * parent
Parent window.
High level window description.
static T ToggleBit(T &x, const uint8 y)
Toggles a bit in a variable.
void SetWidgetDirty(byte widget_index) const
Invalidate a widget, i.e.
Functions related to debugging.
Window * FindWindowById(WindowClass cls, WindowNumber number)
Find a window by its class and window number.
std::vector< Pair >::const_iterator Find(const T &key) const
Finds given key in this map.
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
static NWidgetBase * MakeNumberKeys(int *biggest_index)
Construct the row containing the digit keys.
virtual void OnEditboxChanged(int widget)
The text in an editbox has been edited.
static NWidgetBase * MakeAsdfgKeys(int *biggest_index)
Construct the asdfg row keys.
Textbuf * text
pointer to parent's textbuffer (to update caret position)
bool InsertChar(uint32 key)
Insert a character to a textbuffer.
#define lastof(x)
Get the last element of an fixed size array.
Helper/buffer for input fields.
void DisableWidget(byte widget_index)
Sets a widget to disabled.
static T max(const T a, const T b)
Returns the maximum of two values.
Base for the GUIs that have an edit box in them.
Data structure for an opened window.
void CDECL ShowInfoF(const char *str,...)
Shows some information on the console/a popup box depending on the OS.
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 OnEditboxChanged(int widget) override
The text in an editbox has been edited.
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Functions related to low-level strings.
bool IsValidChar(WChar key, CharSetFilter afilter)
Only allow certain keys.
QueryString * qs
text-input
void ShowOnScreenKeyboard(Window *parent, int button)
Show the on-screen keyboard (osk) associated with a given textbox.
static const uint OSK_KEYBOARD_ENTRIES
The number of 'characters' on the on-screen keyboard.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
On Screen Keyboard; Window numbers:
bool IsOSKOpenedFor(const Window *w, int button)
Check whether the OSK is opened for a specific editbox.
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Functions related to the gfx engine.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
Data stored about a string that can be modified in the GUI.
Definition of base types and functions in a cross-platform compatible way.
void GetKeyboardLayout()
Retrieve keyboard layout from language string or (if set) config file.
A number of safeguards to prevent using unsafe methods.
void OnFocusLost() override
Called when window loses focus.
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
char * stredup(const char *s, const char *last)
Create a duplicate of the given string.
void DrawCharCentered(WChar c, int x, int y, TextColour colour)
Draw single character horizontally centered around (x,y)
static NWidgetBase * MakeTopKeys(int *biggest_index)
Construct the top row keys (cancel, ok, backspace).
#define lengthof(x)
Return the length of an fixed size array.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
static NWidgetBase * MakeQwertyKeys(int *biggest_index)
Construct the qwerty row keys.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
void UpdateOskState()
Only show valid characters; do not show characters that would only insert a space when we have a spac...
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
void Assign(StringID string)
Render a string into the textbuffer.
No window, redirects to WC_MAIN_WINDOW.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
char *const buf
buffer in which text is saved
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
static NWidgetBase * MakeZxcvbKeys(int *biggest_index)
Construct the zxcvb row keys.
bool shift
Is the shift effectively pressed?
static NWidgetBase * MakeSpacebarKeys(int *biggest_index)
Construct the spacebar row keys.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
StringID caption
the caption for this window.
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
virtual void EditBoxLostFocus()
An edit box lost the input focus.
Coordinates of a point in 2D.
int text_btn
widget number of parent's text field
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
bool DeleteChar(uint16 keycode)
Delete a character from a textbuffer, either with 'Delete' or 'Backspace' The character is delete fro...
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Specification of a rectangle with absolute coordinates of all edges.
char * orig_str_buf
Original string.
char _keyboard_opt[2][OSK_KEYBOARD_ENTRIES *4+1]
The number of characters has to be OSK_KEYBOARD_ENTRIES.
Window functions not directly related to making/drawing windows.
CharSetFilter afilter
Allowed characters.
static void AddKey(NWidgetHorizontal *hor, int height, int num_half, WidgetType widtype, int widnum, uint16 widdata, int *biggest_index)
Add a key widget to a row of the keyboard.
uint32 WChar
Type for wide characters, i.e.
const NWID * GetWidget(uint widnum) const
Get the nested widget with number widnum from the nested widget tree.
This file contains all sprite-related enums and defines.
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
int height
Height of the window (number of pixels down in y direction)
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.