00001 /* $Id: textbuf_type.h 24738 2012-11-14 22:50:17Z frosch $ */ 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 00019 struct Textbuf { 00020 char * const buf; 00021 uint16 max_bytes; 00022 uint16 max_chars; 00023 uint16 bytes; 00024 uint16 chars; 00025 uint16 pixels; 00026 bool caret; 00027 uint16 caretpos; 00028 uint16 caretxoffs; 00029 00030 explicit Textbuf(uint16 max_bytes, uint16 max_chars = UINT16_MAX); 00031 ~Textbuf(); 00032 00033 void Assign(StringID string); 00034 void Assign(const char *text); 00035 void CDECL Print(const char *format, ...) WARN_FORMAT(2, 3); 00036 00037 void DeleteAll(); 00038 bool DeleteChar(int delmode); 00039 bool InsertChar(uint32 key); 00040 bool InsertClipboard(); 00041 bool MovePos(int navmode); 00042 00043 bool HandleCaret(); 00044 void UpdateSize(); 00045 00046 private: 00047 bool CanDelChar(bool backspace); 00048 WChar GetNextDelChar(bool backspace); 00049 void DelChar(bool backspace); 00050 bool CanMoveCaretLeft(); 00051 WChar MoveCaretLeft(); 00052 bool CanMoveCaretRight(); 00053 WChar MoveCaretRight(); 00054 00055 }; 00056 00057 #endif /* TEXTBUF_TYPE_H */