Go to the documentation of this file.
1 /* $Id: querystring_gui.h 25691 2013-08-05 20:37:53Z michi_cc $ */
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 <>.
8  */
15 #include "textbuf_type.h"
16 #include "textbuf_gui.h"
17 #include "window_gui.h"
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;
28  StringID caption;
29  int ok_button;
31  Textbuf text;
32  const char *orig;
33  bool handled;
40  QueryString(uint16 size, uint16 chars = UINT16_MAX) : ok_button(ACTION_NOTHING), cancel_button(ACTION_DESELECT), text(size, chars), orig(NULL)
41  {
42  }
48  {
49  free(this->orig);
50  }
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);
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;
65  const char *GetText() const
66  {
67  return this->text.buf;
68  }
74  const char *GetCaret() const
75  {
76  return this->text.buf + this->text.caretpos;
77  }
84  const char *GetMarkedText(size_t *length) const
85  {
86  if (this->text.markend == 0) return NULL;
88  *length = this->text.markend - this->text.markpos;
89  return this->text.buf + this->text.markpos;
90  }
91 };
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 */
bool IsOSKOpenedFor(const Window *w, int button)
Check whether the OSK is opened for a specific editbox.
Definition: osk_gui.cpp:444
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:44
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:819
Helper/buffer for input fields.
Definition: textbuf_type.h:32
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:271
static const int ACTION_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:849
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:41
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:18
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:34
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:412
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
Coordinates of a point in 2D.
static void free(const void *ptr)
Version of the standard free that accepts const pointers.
Definition: depend.cpp:114
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:886
uint16 markpos
the start position of the marked area in the buffer, in bytes
Definition: textbuf_type.h:43