OpenTTD Source  1.11.2
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 */
QueryString::ok_button
int ok_button
Widget button of parent window to simulate when pressing OK in OSK.
Definition: querystring_gui.h:27
QueryString::GetText
const char * GetText() const
Get the current text.
Definition: querystring_gui.h:63
textbuf_type.h
QueryString::~QueryString
~QueryString()
Make sure everything gets freed.
Definition: querystring_gui.h:45
Textbuf::caretpos
uint16 caretpos
the current position of the caret in the buffer, in bytes
Definition: textbuf_type.h:39
Textbuf::markpos
uint16 markpos
the start position of the marked area in the buffer, in bytes
Definition: textbuf_type.h:41
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:935
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
textbuf_gui.h
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
window_gui.h
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:898
IsOSKOpenedFor
bool IsOSKOpenedFor(const Window *w, int button)
Check whether the OSK is opened for a specific editbox.
Definition: osk_gui.cpp:443
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
QueryString::GetCaret
const char * GetCaret() const
Get the position of the caret in the text buffer.
Definition: querystring_gui.h:72
Textbuf::markend
uint16 markend
the end position of the marked area in the buffer, in bytes
Definition: textbuf_type.h:42
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
UpdateOSKOriginalText
void UpdateOSKOriginalText(const Window *parent, int button)
Updates the original text of the OSK so when the 'parent' changes the original and you press on cance...
Definition: osk_gui.cpp:426
QueryString::GetMarkedText
const char * GetMarkedText(size_t *length) const
Get the currently marked text.
Definition: querystring_gui.h:82
QueryString::QueryString
QueryString(uint16 size, uint16 chars=UINT16_MAX)
Initialize string.
Definition: querystring_gui.h:38
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:24
QueryString::GetCaretPosition
Point GetCaretPosition(const Window *w, int wid) const
Get the current caret position.
Definition: misc_gui.cpp:868
Window
Data structure for an opened window.
Definition: window_gui.h:277
QueryString::ACTION_DESELECT
static const int ACTION_DESELECT
Deselect editbox.
Definition: querystring_gui.h:23
free
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: stdafx.h:456
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
ShowOnScreenKeyboard
void ShowOnScreenKeyboard(Window *parent, int button)
Show the on-screen keyboard (osk) associated with a given textbox.
Definition: osk_gui.cpp:411
QueryString::ACTION_NOTHING
static const int ACTION_NOTHING
Nothing.
Definition: querystring_gui.h:22
Textbuf
Helper/buffer for input fields.
Definition: textbuf_type.h:30