4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
10 /** @file querystring_gui.h Base for the GUIs that have an edit box in them. */
12 #ifndef QUERYSTRING_GUI_H
13 #define QUERYSTRING_GUI_H
15 #include "core/pointer.h"
16 #include "textbuf_type.h"
17 #include "textbuf_gui.h"
18 #include "window_gui.h"
21 * Data stored about a string that can be modified in the GUI
23 struct QueryString
: Textbuf
{
24 /* Special actions when hitting ENTER or ESC. (only keyboard, not OSK) */
25 static const int ACTION_NOTHING
= -1; ///< Nothing.
26 static const int ACTION_DESELECT
= -2; ///< Deselect editbox.
27 static const int ACTION_CLEAR
= -3; ///< Clear editbox.
30 int ok_button
; ///< Widget button of parent window to simulate when pressing OK in OSK.
31 int cancel_button
; ///< Widget button of parent window to simulate when pressing CANCEL in OSK.
32 ttd_unique_free_ptr
<char> orig
;
37 * @param size Maximum size in bytes.
38 * @param buffer String buffer.
39 * @param chars Maximum size in chars.
41 QueryString (uint16 size
, char *buffer
, uint16 chars
= UINT16_MAX
) :
42 Textbuf (size
, buffer
, chars
),
43 ok_button (ACTION_NOTHING
), cancel_button (ACTION_DESELECT
)
48 void DrawEditBox (BlitArea
*area
, const Window
*w
, int wid
) const;
49 void ClickEditBox(Window
*w
, Point pt
, int wid
, int click_count
, bool focus_changed
);
50 void HandleEditBox(Window
*w
, int wid
);
52 Point
GetCaretPosition(const Window
*w
, int wid
) const;
53 Rect
GetBoundingRect(const Window
*w
, int wid
, const char *from
, const char *to
) const;
54 const char *GetCharAtPosition(const Window
*w
, int wid
, const Point
&pt
) const;
57 /** QueryString with integrated buffer. */
58 template <uint16 N
, uint16 M
= UINT16_MAX
>
59 struct QueryStringN
: QueryString
{
62 QueryStringN (void) : QueryString (N
, this->data
, M
)
67 /** QueryString with integrated buffer in chars. */
69 struct QueryStringC
: QueryStringN
<C
* MAX_CHAR_LENGTH
, C
> {
72 void ShowOnScreenKeyboard(Window
*parent
, int button
);
73 void UpdateOSKOriginalText(const Window
*parent
, int button
);
74 bool IsOSKOpenedFor(const Window
*w
, int button
);
76 #endif /* QUERYSTRING_GUI_H */