OpenTTD

- Main Page
- Related Pages
- Modules
- Namespaces
- Data Structures
- Files

- File List
- Globals

querystring_gui.h
Go to the documentation of this file.
1 /* $Id: querystring_gui.h 25691 2013-08-05 20:37:53Z michi_cc $ */
2
3 /*
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/>.
8 */
9
12 #ifndef QUERYSTRING_GUI_H
13 #define QUERYSTRING_GUI_H
14
15 #include "textbuf_type.h"
16 #include "textbuf_gui.h"
17 #include "window_gui.h"
18
22 struct QueryString {
23 /* Special actions when hitting ENTER or ESC. (only keyboard, not OSK) */
24 static const int ACTION_NOTHING = -1;
25 static const int ACTION_DESELECT = -2;
26 static const int ACTION_CLEAR = -3;
27
28 StringID caption;
29 int ok_button;
30 int cancel_button;
31 Textbuf text;
32 const char *orig;
33 bool handled;
34
40 QueryString(uint16 size, uint16 chars = UINT16_MAX) : ok_button(ACTION_NOTHING), cancel_button(ACTION_DESELECT), text(size, chars), orig(NULL)
41 {
42 }
43
47 ~QueryString()
48 {
49 free(this->orig);
50 }
51
52 public:
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);
56
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;
60
65 const char *GetText() const
66 {
67 return this->text.buf;
68 }
69
74 const char *GetCaret() const
75 {
76 return this->text.buf + this->text.caretpos;
77 }
78
84 const char *GetMarkedText(size_t *length) const
85 {
86 if (this->text.markend == 0) return NULL;
87
88 *length = this->text.markend - this->text.markpos;
89 return this->text.buf + this->text.markpos;
90 }
91 };
92
93 void ShowOnScreenKeyboard(Window *parent, int button);
94 void UpdateOSKOriginalText(const Window *parent, int button);
95 bool IsOSKOpenedFor(const Window *w, int button);
96
97 #endif /* QUERYSTRING_GUI_H */