OpenTTD
querystring_gui.h
Go to the documentation of this file.
1 /*
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/>.
6  */
7 
10 #ifndef QUERYSTRING_GUI_H
11 #define QUERYSTRING_GUI_H
12 
13 #include "textbuf_type.h"
14 #include "textbuf_gui.h"
15 #include "window_gui.h"
16 
20 struct QueryString {
21  /* Special actions when hitting ENTER or ESC. (only keyboard, not OSK) */
22  static const int ACTION_NOTHING = -1;
23  static const int ACTION_DESELECT = -2;
24  static const int ACTION_CLEAR = -3;
25 
26  StringID caption;
27  int ok_button;
29  Textbuf text;
30  const char *orig;
31  bool handled;
32 
38  QueryString(uint16 size, uint16 chars = UINT16_MAX) : ok_button(ACTION_NOTHING), cancel_button(ACTION_DESELECT), text(size, chars), orig(nullptr)
39  {
40  }
41 
46  {
47  free(this->orig);
48  }
49 
50 public:
51  void DrawEditBox(const Window *w, int wid) const;
52  void ClickEditBox(Window *w, Point pt, int wid, int click_count, bool focus_changed);
53  void HandleEditBox(Window *w, int wid);
54 
55  Point GetCaretPosition(const Window *w, int wid) const;
56  Rect GetBoundingRect(const Window *w, int wid, const char *from, const char *to) const;
57  const char *GetCharAtPosition(const Window *w, int wid, const Point &pt) const;
58 
63  const char *GetText() const
64  {
65  return this->text.buf;
66  }
67 
72  const char *GetCaret() const
73  {
74  return this->text.buf + this->text.caretpos;
75  }
76 
82  const char *GetMarkedText(size_t *length) const
83  {
84  if (this->text.markend == 0) return nullptr;
85 
86  *length = this->text.markend - this->text.markpos;
87  return this->text.buf + this->text.markpos;
88  }
89 };
90 
91 void ShowOnScreenKeyboard(Window *parent, int button);
92 void UpdateOSKOriginalText(const Window *parent, int button);
93 bool IsOSKOpenedFor(const Window *w, int button);
94 
95 #endif /* QUERYSTRING_GUI_H */
bool IsOSKOpenedFor(const Window *w, int button)
Check whether the OSK is opened for a specific editbox.
Definition: osk_gui.cpp:442
static const int ACTION_DESELECT
Deselect editbox.
uint16 markend
the end position of the marked area in the buffer, in bytes
Definition: textbuf_type.h:42
const char * GetText() const
Get the current text.
Stuff related to text buffers.
static const int ACTION_CLEAR
Clear editbox.
Point GetCaretPosition(const Window *w, int wid) const
Get the current caret position.
Definition: misc_gui.cpp:841
Helper/buffer for input fields.
Definition: textbuf_type.h:30
Stuff related to the text buffer GUI.
Functions, definitions and such used only by the GUI.
Data structure for an opened window.
Definition: window_gui.h:276
static const int ACTION_NOTHING
Nothing.
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:871
QueryString(uint16 size, uint16 chars=UINT16_MAX)
Initialize string.
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Data stored about a string that can be modified in the GUI.
uint16 caretpos
the current position of the caret in the buffer, in bytes
Definition: textbuf_type.h:39
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
const char * GetCaret() const
Get the position of the caret in the text buffer.
const char * GetMarkedText(size_t *length) const
Get the currently marked text.
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
~QueryString()
Make sure everything gets freed.
void ShowOnScreenKeyboard(Window *parent, int button)
Show the on-screen keyboard (osk) associated with a given textbox.
Definition: osk_gui.cpp:410
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:425
Coordinates of a point in 2D.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:129
Specification of a rectangle with absolute coordinates of all edges.
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:908
uint16 markpos
the start position of the marked area in the buffer, in bytes
Definition: textbuf_type.h:41