1 /* 2 This file is part of Warzone 2100. 3 Copyright (C) 1999-2004 Eidos Interactive 4 Copyright (C) 2005-2020 Warzone 2100 Project 5 6 Warzone 2100 is free software; you can redistribute it and/or modify 7 it under the terms of the GNU General Public License as published by 8 the Free Software Foundation; either version 2 of the License, or 9 (at your option) any later version. 10 11 Warzone 2100 is distributed in the hope that it will be useful, 12 but WITHOUT ANY WARRANTY; without even the implied warranty of 13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 GNU General Public License for more details. 15 16 You should have received a copy of the GNU General Public License 17 along with Warzone 2100; if not, write to the Free Software 18 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 19 */ 20 /** @file 21 * Definitions for the edit box functions. 22 */ 23 24 #ifndef __INCLUDED_LIB_WIDGET_EDITBOX_H__ 25 #define __INCLUDED_LIB_WIDGET_EDITBOX_H__ 26 27 #include "widget.h" 28 #include "widgbase.h" 29 #include "lib/framework/wzstring.h" 30 31 /* Edit Box states */ 32 #define WEDBS_FIXED 0x0001 // No editing is going on 33 #define WEDBS_INSERT 0x0002 // Insertion editing 34 #define WEDBS_OVER 0x0003 // Overwrite editing 35 #define WEDBS_MASK 0x000f // 36 #define WEDBS_HILITE 0x0010 // 37 #define WEDBS_DISABLE 0x0020 // disable button from selection 38 39 struct EditBoxDisplayCache { 40 WzText wzDisplayedText; 41 WzText modeText; 42 }; 43 44 class W_EDITBOX : public WIDGET 45 { 46 47 public: 48 W_EDITBOX(W_EDBINIT const *init); 49 W_EDITBOX(); 50 ~W_EDITBOX(); 51 52 void clicked(W_CONTEXT *psContext, WIDGET_KEY key = WKEY_PRIMARY) override; 53 void simulateClick(W_CONTEXT *psContext, bool silenceClickAudio = false, WIDGET_KEY key = WKEY_PRIMARY); 54 void highlight(W_CONTEXT *psContext) override; 55 void highlightLost() override; 56 void focusLost() override; 57 void run(W_CONTEXT *psContext) override; 58 void display(int xOffset, int yOffset) override; 59 void geometryChanged() override; 60 61 void setState(unsigned state) override; 62 WzString getString() const override; 63 void setString(WzString string) override; 64 void setMaxStringSize(int size); 65 66 void setBoxColours(PIELIGHT first, PIELIGHT second, PIELIGHT background); 67 68 UDWORD state; // The current edit box state 69 WzString aText; // The text in the edit box 70 iV_fonts FontID; 71 int blinkOffset; // Cursor should be visible at time blinkOffset. 72 int maxStringSize; // max characters string will accept 73 int insPos; // The insertion point in the buffer 74 int printStart; // Where in the string appears at the far left of the box 75 int printChars; // The number of characters appearing in the box 76 int printWidth; // The pixel width of the characters in the box 77 WIDGET_DISPLAY pBoxDisplay; // Optional callback to display the edit box background. 78 SWORD HilightAudioID; // Audio ID for form clicked sound 79 SWORD ClickedAudioID; // Audio ID for form hilighted sound 80 SWORD ErrorAudioID; // Audio ID for error sound 81 WIDGET_AUDIOCALLBACK AudioCallback; // Pointer to audio callback function 82 83 private: 84 void initialise(); // Moves the cursor to the end. 85 void delCharRight(); 86 void delCharLeft(); 87 bool insertChar(WzUniCodepoint ch); 88 bool overwriteChar(WzUniCodepoint ch); 89 void fitStringStart(); // Calculate how much of the start of a string can fit into the edit box 90 void fitStringEnd(); 91 void setCursorPosPixels(int xPos); 92 93 PIELIGHT boxColourFirst, boxColourSecond, boxColourBackground; 94 EditBoxDisplayCache displayCache; 95 bool suppressAudioCallback = false; 96 }; 97 98 #endif // __INCLUDED_LIB_WIDGET_EDITBOX_H__ 99