24 #include "table/strings.h" 36 static byte _keystate = KEYS_NONE;
49 assert(parent != NULL);
52 assert(par_wid != NULL);
57 this->text_btn = button;
58 this->text = &this->qs->text;
62 this->orig_str_buf =
stredup(this->qs->text.buf);
75 free(this->orig_str_buf);
85 this->shift =
HasBit(_keystate, KEYS_CAPS) ^
HasBit(_keystate, KEYS_SHIFT);
89 !
IsValidChar(_keyboard[this->shift][i], this->qs->text.
afilter) || _keyboard[this->shift][i] ==
' ');
123 if (
HasBit(_keystate, KEYS_SHIFT)) {
169 if (this->qs->orig == NULL || strcmp(this->qs->text.
buf, this->qs->orig) != 0) {
186 qs->text.
Assign(this->orig_str_buf);
204 if (!gui_scope)
return;
216 static const int HALF_KEY_WIDTH = 7;
217 static const int INTER_KEY_SPACE = 2;
232 int key_width = HALF_KEY_WIDTH + (INTER_KEY_SPACE + HALF_KEY_WIDTH) * (num_half - 1);
235 if (!hor->
IsEmpty()) key_width += INTER_KEY_SPACE;
248 *biggest_index =
max(*biggest_index, widnum);
350 _nested_osk_widgets,
lengthof(_nested_osk_widgets)
361 bool has_error =
false;
364 GetString(keyboard[0], STR_OSK_KEYBOARD_LAYOUT,
lastof(keyboard[0]));
370 GetString(keyboard[1], STR_OSK_KEYBOARD_LAYOUT_CAPS,
lastof(keyboard[1]));
375 for (uint j = 0; j < 2; j++) {
376 const char *kbd = keyboard[j];
379 _keyboard[j][i] = Utf8Consume(&kbd);
382 if (_keyboard[j][i] ==
'\0' || ended) {
384 _keyboard[j][i] =
' ';
388 if (IsPrintable(_keyboard[j][i])) {
389 errormark[j][i] =
' ';
392 errormark[j][i] =
'^';
393 _keyboard[j][i] =
' ';
399 ShowInfoF(
"The keyboard layout you selected contains invalid chars. Please check those chars marked with ^.");
400 ShowInfoF(
"Normal keyboard: %s", keyboard[0]);
417 new OskWindow(&_osk_desc, parent, button);
430 if (osk == NULL || osk->
parent != parent || osk->
text_btn != button)
return;
447 return osk != NULL && 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.
bool Contains(const T &key) const
Tests whether a key is assigned in this map.
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.
const Pair * Find(const T &key) const
Finds given key in this map.
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.
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 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.
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.
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.
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
virtual void OnInvalidateData(int data=0, bool gui_scope=true)
Some data on this window has become invalid.
virtual void OnFocusLost()
Called when window looses focus.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
static NWidgetBase * MakeZxcvbKeys(int *biggest_index)
Construct the zxcvb row keys.
virtual void SetStringParameters(int widget) const
Initialize string parameters for a widget.
virtual void DrawWidget(const Rect &r, int widget) const
Draw the contents of a nested widget.
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.
virtual void OnClick(Point pt, int widget, int click_count)
A click with the left mouse button has been made on the window.
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 OnEditboxChanged(int widget)
The text in an editbox has been edited.
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.