# querystring_gui.h

Go to the documentation of this file.

    00001 /* $Id: querystring_gui.h 18012 2009-11-08 13:35:45Z rubidium $ */
    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((void*)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, Window::EventState &state);
    00060 };
    00061
    00062 struct QueryStringBaseWindow : public Window, public QueryString {
    00063   char *edit_str_buf;
    00064   const uint16 edit_str_size;
    00065
    00066   QueryStringBaseWindow(uint16 size) : Window(), edit_str_size(size)
    00067   {
    00068     assert(size != 0);
    00069     this->edit_str_buf = CallocT<char>(size);
    00070   }
    00071
    00072   ~QueryStringBaseWindow()
    00073   {
    00074     free(this->edit_str_buf);
    00075   }
    00076
    00077   void DrawEditBox(int wid);
    00078   void HandleEditBox(int wid);
    00079   HandleEditBoxResult HandleEditBoxKey(int wid, uint16 key, uint16 keycode, EventState &state);
    00080   virtual void OnOpenOSKWindow(int wid);
    00081   virtual void OnOSKInput(int wid) {}
    00082 };
    00083
    00084 void ShowOnScreenKeyboard(QueryStringBaseWindow *parent, int button, int cancel, int ok);
    00085 void UpdateOSKOriginalText(const QueryStringBaseWindow *parent, int button);
    00086
    00087 #endif /* QUERYSTRING_GUI_H */