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   /* Special actions when hitting ENTER or ESC. (only keyboard, not OSK) */
00035   static const int ACTION_NOTHING  = -1; 
00036   static const int ACTION_DESELECT = -2; 
00037   static const int ACTION_CLEAR    = -3; 
00038 
00039   StringID caption;
00040   int ok_button;      
00041   int cancel_button;  
00042   Textbuf text;
00043   const char *orig;
00044   CharSetFilter afilter;
00045   bool handled;
00046 
00052   QueryString(uint16 size, uint16 chars = UINT16_MAX) : ok_button(ACTION_NOTHING), cancel_button(ACTION_DESELECT), text(size, chars), orig(NULL)
00053   {
00054   }
00055 
00059   ~QueryString()
00060   {
00061     free(this->orig);
00062   }
00063 
00064 private:
00065   bool HasEditBoxFocus(const Window *w, int wid) const;
00066 public:
00067   void DrawEditBox(const Window *w, int wid) const;
00068   void ClickEditBox(Window *w, Point pt, int wid, int click_count, bool focus_changed);
00069   void HandleEditBox(Window *w, int wid);
00070   HandleEditBoxResult HandleEditBoxKey(Window *w, int wid, uint16 key, uint16 keycode, EventState &state);
00071 };
00072 
00073 void ShowOnScreenKeyboard(Window *parent, int button);
00074 void UpdateOSKOriginalText(const Window *parent, int button);
00075 
00076 #endif /* QUERYSTRING_GUI_H */