# osk_gui.cpp File Reference

The On Screen Keyboard GUI. More...

`#include "stdafx.h"`
`#include "string_func.h"`
`#include "strings_func.h"`
`#include "debug.h"`
`#include "window_func.h"`
`#include "gfx_func.h"`
`#include "querystring_gui.h"`
`#include "table/sprites.h"`
`#include "table/strings.h"`

Go to the source code of this file.

## Data Structures
struct | OskWindow
## Enumerations
enum | OskWidgets { OSK_WIDGET_CAPTION, OSK_WIDGET_TEXT, OSK_WIDGET_CANCEL, OSK_WIDGET_OK, OSK_WIDGET_BACKSPACE, OSK_WIDGET_SPECIAL, OSK_WIDGET_CAPS, OSK_WIDGET_SHIFT, OSK_WIDGET_SPACE, OSK_WIDGET_LEFT, OSK_WIDGET_RIGHT, OSK_WIDGET_LETTERS, OSK_WIDGET_NUMBERS_FIRST = OSK_WIDGET_LETTERS, OSK_WIDGET_NUMBERS_LAST = OSK_WIDGET_NUMBERS_FIRST + 13, OSK_WIDGET_QWERTY_FIRST, OSK_WIDGET_QWERTY_LAST = OSK_WIDGET_QWERTY_FIRST + 11, OSK_WIDGET_ASDFG_FIRST, OSK_WIDGET_ASDFG_LAST = OSK_WIDGET_ASDFG_FIRST + 11, OSK_WIDGET_ZXCVB_FIRST, OSK_WIDGET_ZXCVB_LAST = OSK_WIDGET_ZXCVB_FIRST + 11 }
| Widget numbers of the on-screen keyboard (OSK) window. More...
enum | KeyStateBits { KEYS_NONE, KEYS_SHIFT, KEYS_CAPS }
## Functions
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.
static NWidgetBase * | MakeTopKeys (int *biggest_index)
| Construct the top row keys (cancel, ok, backspace).
static NWidgetBase * | MakeNumberKeys (int *biggest_index)
| Construct the row containing the digit keys.
static NWidgetBase * | MakeQwertyKeys (int *biggest_index)
| Construct the qwerty row keys.
static NWidgetBase * | MakeAsdfgKeys (int *biggest_index)
| Construct the asdfg row keys.
static NWidgetBase * | MakeZxcvbKeys (int *biggest_index)
| Construct the zxcvb row keys.
static NWidgetBase * | MakeSpacebarKeys (int *biggest_index)
| Construct the spacebar row keys.
void | GetKeyboardLayout ()
| Retrieve keyboard layout from language string or (if set) config file.
void | ShowOnScreenKeyboard (QueryStringBaseWindow *parent, int button, int cancel, int ok)
| Show the on-screen keyboard (osk) associated with a given textbox.
void | UpdateOSKOriginalText (const QueryStringBaseWindow *parent, int button)
| Updates the original text of the OSK so when the 'parent' changes the original and you press on cancel you won't get the 'old' original text but the updated one.
## Variables
char | _keyboard_opt [2][OSK_KEYBOARD_ENTRIES *4+1]
| The number of characters has to be OSK_KEYBOARD_ENTRIES.
static WChar | _keyboard [2][OSK_KEYBOARD_ENTRIES]
static byte | _keystate = KEYS_NONE
static const int | HALF_KEY_WIDTH = 7
static const int | INTER_KEY_SPACE = 2
static const NWidgetPart | _nested_osk_widgets []
static const WindowDesc | _osk_desc (WDP_CENTER, 0, 0, WC_OSK, WC_NONE, WDF_UNCLICK_BUTTONS, _nested_osk_widgets, lengthof(_nested_osk_widgets))

## Detailed Description

The On Screen Keyboard GUI.

Definition in file osk_gui.cpp.

## Enumeration Type Documentation

enum OskWidgets

Widget numbers of the on-screen keyboard (OSK) window.

Enumerator:

  OSK_WIDGET_CAPTION | Title bar.
  OSK_WIDGET_TEXT | Edit box.
  OSK_WIDGET_CANCEL | Cancel key.
  OSK_WIDGET_OK | Ok key.
  OSK_WIDGET_BACKSPACE | Backspace key.
  OSK_WIDGET_SPECIAL | Special key (at keyborads often used for tab key).
  OSK_WIDGET_CAPS | Capslock key.
  OSK_WIDGET_SHIFT | Shift(lock) key.
  OSK_WIDGET_SPACE | Space bar.
  OSK_WIDGET_LEFT | Cursor left key.
  OSK_WIDGET_RIGHT | Cursor right key.
  OSK_WIDGET_LETTERS | First widget of the 'normal' keys.
  OSK_WIDGET_NUMBERS_FIRST | First widget of the numbers row.
  OSK_WIDGET_NUMBERS_LAST | Last widget of the numbers row.
  OSK_WIDGET_QWERTY_FIRST | First widget of the qwerty row.
  OSK_WIDGET_QWERTY_LAST | Last widget of the qwerty row.
  OSK_WIDGET_ASDFG_FIRST | First widget of the asdfg row.
  OSK_WIDGET_ASDFG_LAST | Last widget of the asdfg row.
  OSK_WIDGET_ZXCVB_FIRST | First widget of the zxcvb row.
  OSK_WIDGET_ZXCVB_LAST | Last widget of the zxcvb row.

Definition at line 24 of file osk_gui.cpp.

## Function Documentation

static void AddKey | ( | NWidgetHorizontal * | hor,
|  | int | height,
|  | int | num_half,
|  | WidgetType | widtype,
|  | int | widnum,
|  | uint16 | widdata,
|  | int * | biggest_index |
| ) |  |  | `[static]`

Add a key widget to a row of the keyboard.

Parameters:

  | hor | Row container to add key widget to.
  | height | Height of the key (all keys in a row should have equal height).
  | num_half | Number of 1/2 key widths that this key has.
  | widtype | Widget type of the key. Must be either `NWID_SPACER` for an invisible key, or a `WWT_*` widget.
  | widnum | Widget number of the key.
  | widdata | Data value of the key widget.
  | biggest_index | Collected biggest widget index so far.

Note:
  Key width is measured in 1/2 keys to allow for 1/2 key shifting between rows.

Definition at line 276 of file osk_gui.cpp.

References NWidgetContainer::Add(), NWidgetContainer::IsEmpty(), max(), NWID_SPACER, and NWidgetResizeBase::SetMinimalSize().

Referenced by MakeAsdfgKeys(), MakeNumberKeys(), MakeQwertyKeys(), MakeSpacebarKeys(), MakeTopKeys(), and MakeZxcvbKeys().

void GetKeyboardLayout | ( |  | ) |

Retrieve keyboard layout from language string or (if set) config file.

Also check for invalid characters.

Definition at line 403 of file osk_gui.cpp.

References _keyboard_opt, lastof, OSK_KEYBOARD_ENTRIES, ShowInfoF(), strecpy(), and StrEmpty().

Referenced by ShowOnScreenKeyboard().

static NWidgetBase* MakeAsdfgKeys | ( | int * | biggest_index | ) | `[static]`

Construct the asdfg row keys.

Definition at line 336 of file osk_gui.cpp.

References AddKey(), FONT_HEIGHT_NORMAL, OSK_WIDGET_ASDFG_FIRST, OSK_WIDGET_ASDFG_LAST, OSK_WIDGET_CAPS, and WWT_IMGBTN.

static NWidgetBase* MakeNumberKeys | ( | int * | biggest_index | ) | `[static]`

Construct the row containing the digit keys.

Definition at line 310 of file osk_gui.cpp.

References AddKey(), FONT_HEIGHT_NORMAL, OSK_WIDGET_NUMBERS_FIRST, and OSK_WIDGET_NUMBERS_LAST.

static NWidgetBase* MakeQwertyKeys | ( | int * | biggest_index | ) | `[static]`

Construct the qwerty row keys.

Definition at line 322 of file osk_gui.cpp.

References AddKey(), FONT_HEIGHT_NORMAL, NWID_SPACER, OSK_WIDGET_QWERTY_FIRST, OSK_WIDGET_QWERTY_LAST, and OSK_WIDGET_SPECIAL.

static NWidgetBase* MakeSpacebarKeys | ( | int * | biggest_index | ) | `[static]`

Construct the spacebar row keys.

Definition at line 363 of file osk_gui.cpp.

References AddKey(), FONT_HEIGHT_NORMAL, NWID_SPACER, OSK_WIDGET_LEFT, OSK_WIDGET_RIGHT, and OSK_WIDGET_SPACE.

static NWidgetBase* MakeTopKeys | ( | int * | biggest_index | ) | `[static]`

Construct the top row keys (cancel, ok, backspace).

Definition at line 298 of file osk_gui.cpp.

References AddKey(), FONT_HEIGHT_NORMAL, OSK_WIDGET_BACKSPACE, OSK_WIDGET_CANCEL, OSK_WIDGET_OK, and WWT_TEXTBTN.

static NWidgetBase* MakeZxcvbKeys | ( | int * | biggest_index | ) | `[static]`

Construct the zxcvb row keys.

Definition at line 349 of file osk_gui.cpp.

References AddKey(), FONT_HEIGHT_NORMAL, NWID_SPACER, OSK_WIDGET_SHIFT, OSK_WIDGET_ZXCVB_FIRST, OSK_WIDGET_ZXCVB_LAST, and WWT_IMGBTN.

void ShowOnScreenKeyboard | ( | QueryStringBaseWindow * | parent,
|  | int | button,
|  | int | cancel,
|  | int | ok |
| ) |  |  |

Show the on-screen keyboard (osk) associated with a given textbox.

Parameters:

  | parent | pointer to the Window where this keyboard originated from
  | button | widget number of parent's textbox
  | cancel | widget number of parent's cancel button (0 if cancel events should not be passed)
  | ok | widget number of parent's ok button (0 if ok events should not be passed)

Definition at line 462 of file osk_gui.cpp.

References DeleteWindowById(), and GetKeyboardLayout().

void UpdateOSKOriginalText | ( | const QueryStringBaseWindow * | parent,
|  | int | button |
| ) |  |  |

Updates the original text of the OSK so when the 'parent' changes the original and you press on cancel you won't get the 'old' original text but the updated one.

Parameters:

  | parent | window that just updated its orignal text
  | button | widget number of parent's textbox to update

Definition at line 477 of file osk_gui.cpp.

References Textbuf::buf, FindWindowById(), OskWindow::orig_str_buf, OskWindow::qs, Window::SetDirty(), and OskWindow::text_btn.

## Variable Documentation

char _keyboard_opt[2][OSK_KEYBOARD_ENTRIES *4+1]

The number of characters has to be OSK_KEYBOARD_ENTRIES.

However, these have to be UTF-8 encoded, which means up to 4 bytes per character. Furthermore the string needs to be ''-terminated.

Definition at line 51 of file osk_gui.cpp.

Referenced by GetKeyboardLayout().

const NWidgetPart _nested_osk_widgets[]`[static]`

Initial value:

     {
      NWidget(WWT_CAPTION, COLOUR_GREY, OSK_WIDGET_CAPTION), SetDataTip(STR_WHITE_STRING, STR_NULL),
      NWidget(WWT_PANEL, COLOUR_GREY),
        NWidget(WWT_EDITBOX, COLOUR_GREY, OSK_WIDGET_TEXT), SetMinimalSize(252, 12), SetPadding(2, 2, 2, 2),
      EndContainer(),
      NWidget(WWT_PANEL, COLOUR_GREY), SetPIP(5, 2, 3),
        NWidgetFunction(MakeTopKeys), SetPadding(0, 3, 0, 3),
        NWidgetFunction(MakeNumberKeys), SetPadding(0, 3, 0, 3),
        NWidgetFunction(MakeQwertyKeys), SetPadding(0, 3, 0, 3),
        NWidgetFunction(MakeAsdfgKeys), SetPadding(0, 3, 0, 3),
        NWidgetFunction(MakeZxcvbKeys), SetPadding(0, 3, 0, 3),
        NWidgetFunction(MakeSpacebarKeys), SetPadding(0, 3, 0, 3),
      EndContainer(),
    }

Definition at line 377 of file osk_gui.cpp.