querystring_gui.h

Go to the documentation of this file.
00001 /* $Id: querystring_gui.h 25691 2013-08-05 20:37:53Z michi_cc $ */
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 struct QueryString {
00023   /* Special actions when hitting ENTER or ESC. (only keyboard, not OSK) */
00024   static const int ACTION_NOTHING  = -1; 
00025   static const int ACTION_DESELECT = -2; 
00026   static const int ACTION_CLEAR    = -3; 
00027 
00028   StringID caption;
00029   int ok_button;      
00030   int cancel_button;  
00031   Textbuf text;
00032   const char *orig;
00033   bool handled;
00034 
00040   QueryString(uint16 size, uint16 chars = UINT16_MAX) : ok_button(ACTION_NOTHING), cancel_button(ACTION_DESELECT), text(size, chars), orig(NULL)
00041   {
00042   }
00043 
00047   ~QueryString()
00048   {
00049     free(this->orig);
00050   }
00051 
00052 public:
00053   void DrawEditBox(const Window *w, int wid) const;
00054   void ClickEditBox(Window *w, Point pt, int wid, int click_count, bool focus_changed);
00055   void HandleEditBox(Window *w, int wid);
00056 
00057   Point GetCaretPosition(const Window *w, int wid) const;
00058   Rect GetBoundingRect(const Window *w, int wid, const char *from, const char *to) const;
00059   const char *GetCharAtPosition(const Window *w, int wid, const Point &pt) const;
00060 
00065   const char *GetText() const
00066   {
00067     return this->text.buf;
00068   }
00069 
00074   const char *GetCaret() const
00075   {
00076     return this->text.buf + this->text.caretpos;
00077   }
00078 
00084   const char *GetMarkedText(size_t *length) const
00085   {
00086     if (this->text.markend == 0) return NULL;
00087 
00088     *length = this->text.markend - this->text.markpos;
00089     return this->text.buf + this->text.markpos;
00090   }
00091 };
00092 
00093 void ShowOnScreenKeyboard(Window *parent, int button);
00094 void UpdateOSKOriginalText(const Window *parent, int button);
00095 bool IsOSKOpenedFor(const Window *w, int button);
00096 
00097 #endif /* QUERYSTRING_GUI_H */