OpenTTD Source 20261112-master-gbcbec5e63f
querystring_gui.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#ifndef QUERYSTRING_GUI_H
11#define QUERYSTRING_GUI_H
12
13#include "textbuf_type.h"
14#include "window_gui.h"
15
20 /* Special actions when hitting ENTER or ESC. (only keyboard, not OSK) */
21 static const int ACTION_NOTHING = -1;
22 static const int ACTION_DESELECT = -2;
23 static const int ACTION_CLEAR = -3;
24
25 StringID caption{};
28 Textbuf text;
29 std::optional<std::string> orig{};
30 bool handled = false;
31
37 QueryString(uint16_t size, uint16_t chars = UINT16_MAX) : text(size, chars)
38 {
39 }
40
41public:
42 void DrawEditBox(const Window *w, WidgetID wid) const;
43 void ClickEditBox(Window *w, Point pt, WidgetID wid, int click_count, bool focus_changed);
44 void HandleEditBox(Window *w, WidgetID wid);
45
46 Point GetCaretPosition(const Window *w, WidgetID wid) const;
47 Rect GetBoundingRect(const Window *w, WidgetID wid, size_t from, size_t to) const;
48 ptrdiff_t GetCharAtPosition(const Window *w, WidgetID wid, const Point &pt) const;
49};
50
51void ShowOnScreenKeyboard(Window *parent, WidgetID button);
52void UpdateOSKOriginalText(const Window *parent, WidgetID button);
53bool IsOSKOpenedFor(const Window *w, WidgetID button);
54
55#endif /* QUERYSTRING_GUI_H */
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
void ShowOnScreenKeyboard(Window *parent, WidgetID button)
Show the on-screen keyboard (osk) associated with a given textbox.
Definition osk_gui.cpp:396
bool IsOSKOpenedFor(const Window *w, WidgetID button)
Check whether the OSK is opened for a specific editbox.
Definition osk_gui.cpp:427
void UpdateOSKOriginalText(const Window *parent, WidgetID button)
Updates the original text of the OSK so when the 'parent' changes the original and you press on cance...
Definition osk_gui.cpp:411
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
QueryString(uint16_t size, uint16_t chars=UINT16_MAX)
Initialize string.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
static const int ACTION_DESELECT
Deselect editbox.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
ptrdiff_t GetCharAtPosition(const Window *w, WidgetID wid, const Point &pt) const
Get the character that is rendered at a position.
Definition misc_gui.cpp:848
static const int ACTION_NOTHING
Nothing.
static const int ACTION_CLEAR
Clear editbox.
Point GetCaretPosition(const Window *w, WidgetID wid) const
Get the current caret position.
Definition misc_gui.cpp:790
Rect GetBoundingRect(const Window *w, WidgetID wid, size_t from, size_t to) const
Get the bounding rectangle for a range of the query string.
Definition misc_gui.cpp:818
Helper/buffer for input fields.
Data structure for an opened window.
Definition window_gui.h:272
Stuff related to text buffers.
Functions, definitions and such used only by the GUI.
int WidgetID
Widget ID.
Definition window_type.h:21