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/>.
8 /** @file querystring_gui.h Base for the GUIs that have an edit box in them. */
10 #ifndef QUERYSTRING_GUI_H
11 #define QUERYSTRING_GUI_H
13 #include "textbuf_type.h"
14 #include "textbuf_gui.h"
15 #include "window_gui.h"
18 * Data stored about a string that can be modified in the GUI
21 /* Special actions when hitting ENTER or ESC. (only keyboard, not OSK) */
22 static const int ACTION_NOTHING
= -1; ///< Nothing.
23 static const int ACTION_DESELECT
= -2; ///< Deselect editbox.
24 static const int ACTION_CLEAR
= -3; ///< Clear editbox.
27 int ok_button
; ///< Widget button of parent window to simulate when pressing OK in OSK.
28 int cancel_button
; ///< Widget button of parent window to simulate when pressing CANCEL in OSK.
30 std::optional
<std::string
> orig
;
35 * @param size Maximum size in bytes.
36 * @param chars Maximum size in chars.
38 QueryString(uint16_t size
, uint16_t chars
= UINT16_MAX
) : ok_button(ACTION_NOTHING
), cancel_button(ACTION_DESELECT
), text(size
, chars
)
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
);
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;
52 void ShowOnScreenKeyboard(Window
*parent
, WidgetID button
);
53 void UpdateOSKOriginalText(const Window
*parent
, WidgetID button
);
54 bool IsOSKOpenedFor(const Window
*w
, WidgetID button
);
56 #endif /* QUERYSTRING_GUI_H */