OpenTTD

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 */
IsOSKOpenedFor
bool IsOSKOpenedFor(const Window *w, int button)
Check whether the OSK is opened for a specific editbox.
Definition: osk_gui.cpp:444
QueryString::ACTION_DESELECT
static const int ACTION_DESELECT
Deselect editbox.
Definition: querystring_gui.h:25
Textbuf::markend
uint16 markend
the end position of the marked area in the buffer, in bytes
Definition: textbuf_type.h:44
QueryString::GetText
const char * GetText() const
Get the current text.
Definition: querystring_gui.h:65
textbuf_type.h
Stuff related to text buffers.
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:26
QueryString::GetCaretPosition
Point GetCaretPosition(const Window *w, int wid) const
Get the current caret position.
Definition: misc_gui.cpp:820
Textbuf
Helper/buffer for input fields.
Definition: textbuf_type.h:32
textbuf_gui.h
Stuff related to the text buffer GUI.
window_gui.h
Functions, definitions and such used only by the GUI.
Window
Data structure for an opened window.
Definition: window_gui.h:271
QueryString::ACTION_NOTHING
static const int ACTION_NOTHING
Nothing.
Definition: querystring_gui.h:24
QueryString::GetBoundingRect
Rect GetBoundingRect(const Window *w, int wid, const char *from, const char *to) const
Get the bounding rectangle for a range of the query string.
Definition: misc_gui.cpp:850
QueryString::QueryString
QueryString(uint16 size, uint16 chars=UINT16_MAX)
Initialize string.
Definition: querystring_gui.h:40
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:29
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:22
Textbuf::caretpos
uint16 caretpos
the current position of the caret in the buffer, in bytes
Definition: textbuf_type.h:41
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:30
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:18
QueryString::GetCaret
const char * GetCaret() const
Get the position of the caret in the text buffer.
Definition: querystring_gui.h:74
QueryString::GetMarkedText
const char * GetMarkedText(size_t *length) const
Get the currently marked text.
Definition: querystring_gui.h:84
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:34
QueryString::~QueryString
~QueryString()
Make sure everything gets freed.
Definition: querystring_gui.h:47
ShowOnScreenKeyboard
void ShowOnScreenKeyboard(Window *parent, int button)
Show the on-screen keyboard (osk) associated with a given textbox.
Definition: osk_gui.cpp:412
UpdateOSKOriginalText
void UpdateOSKOriginalText(const Window *parent, int button)
Updates the original text of the OSK so when the &#39;parent&#39; changes the original and you press on cance...
Definition: osk_gui.cpp:427
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:28
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:40
QueryString::GetCharAtPosition
const char * GetCharAtPosition(const Window *w, int wid, const Point &pt) const
Get the character that is rendered at a position.
Definition: misc_gui.cpp:887
Textbuf::markpos
uint16 markpos
the start position of the marked area in the buffer, in bytes
Definition: textbuf_type.h:43