OpenTTD Source
1.11.0-beta2
|
Go to the documentation of this file.
22 #include "table/strings.h"
34 static byte _keystate = KEYS_NONE;
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 = std::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;
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.
char _keyboard_opt[2][OSK_KEYBOARD_ENTRIES *4+1]
The number of characters has to be OSK_KEYBOARD_ENTRIES.
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.
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.
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...
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Coordinates of a point in 2D.
CharSetFilter afilter
Allowed characters.
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.
void DrawCharCentered(WChar c, int x, int y, TextColour colour)
Draw single character horizontally centered around (x,y)
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.
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
static NWidgetBase * MakeTopKeys(int *biggest_index)
Construct the top row keys (cancel, ok, backspace).
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
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.
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.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.