OpenTTD Source  14.0-beta1
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 <http://www.gnu.org/licenses/>.
6  */
7 
10 #ifndef QUERYSTRING_GUI_H
11 #define QUERYSTRING_GUI_H
12 
13 #include "textbuf_type.h"
14 #include "textbuf_gui.h"
15 #include "window_gui.h"
16 
20 struct QueryString {
21  /* Special actions when hitting ENTER or ESC. (only keyboard, not OSK) */
22  static const int ACTION_NOTHING = -1;
23  static const int ACTION_DESELECT = -2;
24  static const int ACTION_CLEAR = -3;
25 
26  StringID caption;
27  int ok_button;
29  Textbuf text;
30  std::optional<std::string> orig;
31  bool handled;
32 
38  QueryString(uint16_t size, uint16_t chars = UINT16_MAX) : ok_button(ACTION_NOTHING), cancel_button(ACTION_DESELECT), text(size, chars)
39  {
40  }
41 
42 public:
43  void DrawEditBox(const Window *w, WidgetID wid) const;
44  void ClickEditBox(Window *w, Point pt, WidgetID wid, int click_count, bool focus_changed);
45  void HandleEditBox(Window *w, WidgetID wid);
46 
47  Point GetCaretPosition(const Window *w, WidgetID wid) const;
48  Rect GetBoundingRect(const Window *w, WidgetID wid, const char *from, const char *to) const;
49  ptrdiff_t GetCharAtPosition(const Window *w, WidgetID wid, const Point &pt) const;
50 };
51 
52 void ShowOnScreenKeyboard(Window *parent, WidgetID button);
53 void UpdateOSKOriginalText(const Window *parent, WidgetID button);
54 bool IsOSKOpenedFor(const Window *w, WidgetID button);
55 
56 #endif /* QUERYSTRING_GUI_H */
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:27
textbuf_type.h
UpdateOSKOriginalText
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:408
StringID
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
textbuf_gui.h
WidgetID
int WidgetID
Widget ID.
Definition: window_type.h:18
window_gui.h
QueryString::GetCharAtPosition
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:890
QueryString::GetBoundingRect
Rect GetBoundingRect(const Window *w, WidgetID wid, const char *from, const char *to) const
Get the bounding rectangle for a range of the query string.
Definition: misc_gui.cpp:859
QueryString::QueryString
QueryString(uint16_t size, uint16_t chars=UINT16_MAX)
Initialize string.
Definition: querystring_gui.h:38
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
QueryString::GetCaretPosition
Point GetCaretPosition(const Window *w, WidgetID wid) const
Get the current caret position.
Definition: misc_gui.cpp:830
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:24
ShowOnScreenKeyboard
void ShowOnScreenKeyboard(Window *parent, WidgetID button)
Show the on-screen keyboard (osk) associated with a given textbox.
Definition: osk_gui.cpp:393
Window
Data structure for an opened window.
Definition: window_gui.h:267
QueryString::ACTION_DESELECT
static const int ACTION_DESELECT
Deselect editbox.
Definition: querystring_gui.h:23
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:75
IsOSKOpenedFor
bool IsOSKOpenedFor(const Window *w, WidgetID button)
Check whether the OSK is opened for a specific editbox.
Definition: osk_gui.cpp:424
QueryString::ACTION_NOTHING
static const int ACTION_NOTHING
Nothing.
Definition: querystring_gui.h:22
Textbuf
Helper/buffer for input fields.
Definition: textbuf_type.h:30