2008-05-11 12:26:20 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2008-05-11 12:26:20 +00:00
|
|
|
/** @file querystring_gui.h Base for the GUIs that have an edit box in them. */
|
|
|
|
|
|
|
|
#ifndef QUERYSTRING_GUI_H
|
|
|
|
#define QUERYSTRING_GUI_H
|
|
|
|
|
|
|
|
#include "textbuf_gui.h"
|
|
|
|
#include "window_gui.h"
|
|
|
|
|
2008-10-25 19:59:11 +00:00
|
|
|
/**
|
|
|
|
* Return values for HandleEditBoxKey
|
|
|
|
*/
|
|
|
|
enum HandleEditBoxResult
|
|
|
|
{
|
|
|
|
HEBR_EDITING = 0, // Other key pressed.
|
|
|
|
HEBR_CONFIRM, // Return or enter key pressed.
|
|
|
|
HEBR_CANCEL, // Escape key pressed.
|
2009-02-09 01:22:29 +00:00
|
|
|
HEBR_NOT_FOCUSED, // Edit box widget not focused.
|
2008-10-25 19:59:11 +00:00
|
|
|
};
|
|
|
|
|
2008-08-11 22:08:56 +00:00
|
|
|
/**
|
|
|
|
* Data stored about a string that can be modified in the GUI
|
|
|
|
*/
|
2008-05-11 12:26:20 +00:00
|
|
|
struct QueryString {
|
|
|
|
StringID caption;
|
|
|
|
Textbuf text;
|
|
|
|
const char *orig;
|
|
|
|
CharSetFilter afilter;
|
|
|
|
bool handled;
|
|
|
|
|
2008-08-11 22:08:56 +00:00
|
|
|
/**
|
|
|
|
* Make sure everything gets initialized properly.
|
|
|
|
*/
|
|
|
|
QueryString() : orig(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Make sure everything gets freed.
|
|
|
|
*/
|
|
|
|
~QueryString()
|
|
|
|
{
|
2011-11-12 13:00:29 +00:00
|
|
|
free(this->orig);
|
2008-08-11 22:08:56 +00:00
|
|
|
}
|
|
|
|
|
2009-10-18 20:56:38 +00:00
|
|
|
private:
|
2009-02-09 01:22:29 +00:00
|
|
|
bool HasEditBoxFocus(const Window *w, int wid) const;
|
2009-10-18 20:56:38 +00:00
|
|
|
public:
|
2008-05-11 12:26:20 +00:00
|
|
|
void DrawEditBox(Window *w, int wid);
|
|
|
|
void HandleEditBox(Window *w, int wid);
|
2010-05-30 12:06:18 +00:00
|
|
|
HandleEditBoxResult HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, EventState &state);
|
2008-05-11 12:26:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct QueryStringBaseWindow : public Window, public QueryString {
|
2010-12-05 22:21:37 +00:00
|
|
|
char *edit_str_buf; ///< Buffer for string.
|
|
|
|
const uint16 edit_str_size; ///< Maximum length of string (in bytes), including terminating '\0'.
|
2010-12-05 22:22:54 +00:00
|
|
|
const uint16 max_chars; ///< Maximum length of string (in characters), including terminating '\0'.
|
2008-08-11 22:08:56 +00:00
|
|
|
|
2010-12-05 22:22:54 +00:00
|
|
|
QueryStringBaseWindow(uint16 size, uint16 chars = UINT16_MAX) : Window(), edit_str_size(size), max_chars(chars == UINT16_MAX ? size : chars)
|
2009-09-11 18:52:56 +00:00
|
|
|
{
|
|
|
|
assert(size != 0);
|
|
|
|
this->edit_str_buf = CallocT<char>(size);
|
|
|
|
}
|
|
|
|
|
2008-08-11 22:08:56 +00:00
|
|
|
~QueryStringBaseWindow()
|
2008-05-11 12:26:20 +00:00
|
|
|
{
|
2008-08-11 22:08:56 +00:00
|
|
|
free(this->edit_str_buf);
|
2008-05-11 12:26:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void DrawEditBox(int wid);
|
|
|
|
void HandleEditBox(int wid);
|
2009-01-03 23:40:29 +00:00
|
|
|
HandleEditBoxResult HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state);
|
2011-05-04 20:24:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for when the OSK window is opened.
|
|
|
|
* @param wid The widget the OSK is opened of.
|
|
|
|
*/
|
2009-01-03 13:59:05 +00:00
|
|
|
virtual void OnOpenOSKWindow(int wid);
|
2011-05-04 20:24:23 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for when on input has been entered with the OSK.
|
|
|
|
* @param wid The widget the OSK was attached to.
|
|
|
|
*/
|
2009-02-06 11:57:25 +00:00
|
|
|
virtual void OnOSKInput(int wid) {}
|
2008-05-11 12:26:20 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button, int cancel, int ok);
|
2009-10-10 12:47:04 +00:00
|
|
|
void UpdateOSKOriginalText(const QueryStringBaseWindow *parent, int button);
|
2008-05-11 12:26:20 +00:00
|
|
|
|
|
|
|
#endif /* QUERYSTRING_GUI_H */
|