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 TEXTBUF_TYPE_H 00013 #define TEXTBUF_TYPE_H 00014 00015 #include "string_type.h" 00016 #include "strings_type.h" 00017 00021 enum HandleKeyPressResult 00022 { 00023 HKPR_EDITING, 00024 HKPR_CURSOR, 00025 HKPR_CONFIRM, 00026 HKPR_CANCEL, 00027 HKPR_NOT_HANDLED, 00028 }; 00029 00031 struct Textbuf { 00032 CharSetFilter afilter; 00033 char * const buf; 00034 uint16 max_bytes; 00035 uint16 max_chars; 00036 uint16 bytes; 00037 uint16 chars; 00038 uint16 pixels; 00039 bool caret; 00040 uint16 caretpos; 00041 uint16 caretxoffs; 00042 00043 explicit Textbuf(uint16 max_bytes, uint16 max_chars = UINT16_MAX); 00044 ~Textbuf(); 00045 00046 void Assign(StringID string); 00047 void Assign(const char *text); 00048 void CDECL Print(const char *format, ...) WARN_FORMAT(2, 3); 00049 00050 void DeleteAll(); 00051 bool InsertClipboard(); 00052 00053 bool InsertChar(uint32 key); 00054 00055 bool DeleteChar(uint16 keycode); 00056 bool MovePos(uint16 keycode); 00057 00058 HandleKeyPressResult HandleKeyPress(uint16 key, uint16 keycode); 00059 00060 bool HandleCaret(); 00061 void UpdateSize(); 00062 00063 private: 00064 bool CanDelChar(bool backspace); 00065 WChar GetNextDelChar(bool backspace); 00066 void DelChar(bool backspace); 00067 bool CanMoveCaretLeft(); 00068 WChar MoveCaretLeft(); 00069 bool CanMoveCaretRight(); 00070 WChar MoveCaretRight(); 00071 00072 }; 00073 00074 #endif /* TEXTBUF_TYPE_H */