textbuf_type.h

Go to the documentation of this file.
00001 /* $Id: textbuf_type.h 25692 2013-08-05 20:37:57Z 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 TEXTBUF_TYPE_H
00013 #define TEXTBUF_TYPE_H
00014 
00015 #include "string_type.h"
00016 #include "strings_type.h"
00017 #include "string_base.h"
00018 
00022 enum HandleKeyPressResult
00023 {
00024   HKPR_EDITING,     
00025   HKPR_CURSOR,      
00026   HKPR_CONFIRM,     
00027   HKPR_CANCEL,      
00028   HKPR_NOT_HANDLED, 
00029 };
00030 
00032 struct Textbuf {
00033   CharSetFilter afilter;    
00034   char * const buf;         
00035   uint16 max_bytes;         
00036   uint16 max_chars;         
00037   uint16 bytes;             
00038   uint16 chars;             
00039   uint16 pixels;            
00040   bool caret;               
00041   uint16 caretpos;          
00042   uint16 caretxoffs;        
00043   uint16 markpos;           
00044   uint16 markend;           
00045   uint16 markxoffs;         
00046   uint16 marklength;        
00047 
00048   explicit Textbuf(uint16 max_bytes, uint16 max_chars = UINT16_MAX);
00049   ~Textbuf();
00050 
00051   void Assign(StringID string);
00052   void Assign(const char *text);
00053   void CDECL Print(const char *format, ...) WARN_FORMAT(2, 3);
00054 
00055   void DeleteAll();
00056   bool InsertClipboard();
00057 
00058   bool InsertChar(uint32 key);
00059   bool InsertString(const char *str, bool marked, const char *caret = NULL, const char *insert_location = NULL, const char *replacement_end = NULL);
00060 
00061   bool DeleteChar(uint16 keycode);
00062   bool MovePos(uint16 keycode);
00063 
00064   HandleKeyPressResult HandleKeyPress(WChar key, uint16 keycode);
00065 
00066   bool HandleCaret();
00067   void UpdateSize();
00068 
00069   void DiscardMarkedText(bool update = true);
00070 
00071 private:
00072   StringIterator *char_iter;
00073 
00074   bool CanDelChar(bool backspace);
00075 
00076   void DeleteText(uint16 from, uint16 to, bool update);
00077 
00078   void UpdateStringIter();
00079   void UpdateWidth();
00080   void UpdateCaretPosition();
00081   void UpdateMarkedText();
00082 };
00083 
00084 #endif /* TEXTBUF_TYPE_H */