1 /* $Id: querystring_gui.h 25691 2013-08-05 20:37:53Z michi_cc $ */
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 "textbuf_type.h"
16 #include "textbuf_gui.h"
17 #include "window_gui.h"
20 * Data stored about a string that can be modified in the GUI
23 /* Special actions when hitting ENTER or ESC. (only keyboard, not OSK) */
24 static const int ACTION_NOTHING
= -1; ///< Nothing.
25 static const int ACTION_DESELECT
= -2; ///< Deselect editbox.
26 static const int ACTION_CLEAR
= -3; ///< Clear editbox.
29 int ok_button
; ///< Widget button of parent window to simulate when pressing OK in OSK.
30 int cancel_button
; ///< Widget button of parent window to simulate when pressing CANCEL in OSK.
37 * @param size Maximum size in bytes.
38 * @param chars Maximum size in chars.
40 QueryString(uint16 size
, uint16 chars
= UINT16_MAX
) : ok_button(ACTION_NOTHING
), cancel_button(ACTION_DESELECT
), text(size
, chars
), orig(NULL
)
45 * Make sure everything gets freed.
53 void DrawEditBox(const Window
*w
, int wid
) const;
54 void ClickEditBox(Window
*w
, Point pt
, int wid
, int click_count
, bool focus_changed
);
55 void HandleEditBox(Window
*w
, int wid
);
57 Point
GetCaretPosition(const Window
*w
, int wid
) const;
58 Rect
GetBoundingRect(const Window
*w
, int wid
, const char *from
, const char *to
) const;
59 const char *GetCharAtPosition(const Window
*w
, int wid
, const Point
&pt
) const;
62 * Get the current text.
63 * @return Current text.
65 const char *GetText() const
67 return this->text
.buf
;
71 * Get the position of the caret in the text buffer.
72 * @return Pointer to the caret in the text buffer.
74 const char *GetCaret() const
76 return this->text
.buf
+ this->text
.caretpos
;
80 * Get the currently marked text.
81 * @param[out] length Length of the marked text.
82 * @return Begining of the marked area or NULL if no text is marked.
84 const char *GetMarkedText(size_t *length
) const
86 if (this->text
.markend
== 0) return NULL
;
88 *length
= this->text
.markend
- this->text
.markpos
;
89 return this->text
.buf
+ this->text
.markpos
;
93 void ShowOnScreenKeyboard(Window
*parent
, int button
);
94 void UpdateOSKOriginalText(const Window
*parent
, int button
);
95 bool IsOSKOpenedFor(const Window
*w
, int button
);
97 #endif /* QUERYSTRING_GUI_H */