# querystring_gui.h

Go to the documentation of this file.

    00001 /* $Id$ */
    00002
    00003 /*
    00004  * This file is part of OpenTTD.
    00005  * 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.
    00006  * 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.
    00007  * 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/>.
    00008  */
    00009
    00012 #ifndef QUERYSTRING_GUI_H
    00013 #define QUERYSTRING_GUI_H
    00014
    00015 #include "textbuf_gui.h"
    00016 #include "window_gui.h"
    00017
    00021 enum HandleEditBoxResult
    00022 {
    00023   HEBR_EDITING = 0, // Other key pressed.
    00024   HEBR_CONFIRM,     // Return or enter key pressed.
    00025   HEBR_CANCEL,      // Escape key pressed.
    00026   HEBR_NOT_FOCUSED, // Edit box widget not focused.
    00027 };
    00028
    00032 struct QueryString {
    00033   StringID caption;
    00034   Textbuf text;
    00035   const char *orig;
    00036   CharSetFilter afilter;
    00037   bool handled;
    00038
    00042   QueryString() : orig(NULL)
    00043   {
    00044   }
    00045
    00049   ~QueryString()
    00050   {
    00051     free(this->orig);
    00052   }
    00053
    00054 private:
    00055   bool HasEditBoxFocus(const Window *w, int wid) const;
    00056 public:
    00057   void DrawEditBox(Window *w, int wid);
    00058   void HandleEditBox(Window *w, int wid);
    00059   HandleEditBoxResult HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, EventState &state);
    00060 };
    00061
    00062 struct QueryStringBaseWindow : public Window, public QueryString {
    00063   char *edit_str_buf;
    00064   const uint16 edit_str_size;
    00065   const uint16 max_chars;
    00066
    00067   QueryStringBaseWindow(uint16 size, uint16 chars = UINT16_MAX) : Window(), edit_str_size(size), max_chars(chars == UINT16_MAX ? size : chars)
    00068   {
    00069     assert(size != 0);
    00070     this->edit_str_buf = CallocT<char>(size);
    00071   }
    00072
    00073   ~QueryStringBaseWindow()
    00074   {
    00075     free(this->edit_str_buf);
    00076   }
    00077
    00078   void DrawEditBox(int wid);
    00079   void HandleEditBox(int wid);
    00080   HandleEditBoxResult HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state);
    00081
    00086   virtual void OnOpenOSKWindow(int wid);
    00087
    00092   virtual void OnOSKInput(int wid) {}
    00093 };
    00094
    00095 void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button, int cancel, int ok);
    00096 void UpdateOSKOriginalText(const QueryStringBaseWindow *parent, int button);
    00097
    00098 #endif /* QUERYSTRING_GUI_H */