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