factored out the EFFv2 saving into EFFImporter
[gemrb.git] / gemrb / core / GUI / TextArea.h
blobc861c068f46f6af0a21d2dc8dc2d1d7f90cd4698
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 /**
22 * @file TextArea.h
23 * Declares TextArea widget for displaying long paragraphs of text
24 * @author The GemRB Project
27 #ifndef TEXTAREA_H
28 #define TEXTAREA_H
30 #include "GUI/Control.h"
31 #include "GUI/ScrollBar.h"
33 #include "RGBAColor.h"
34 #include "exports.h"
36 #include "Font.h"
38 // Keep these synchronized with GUIDefines.py
39 // 0x05 is the control type of TextArea
40 #define IE_GUI_TEXTAREA_ON_CHANGE 0x05000000
41 #define IE_GUI_TEXTAREA_OUT_OF_TEXT 0x05000001
43 // TextArea flags, keep these in sync too
44 // the control type is intentionally left out
45 #define IE_GUI_TEXTAREA_SELECTABLE 1
46 #define IE_GUI_TEXTAREA_AUTOSCROLL 2
47 #define IE_GUI_TEXTAREA_SMOOTHSCROLL 4
48 #define IE_GUI_TEXTAREA_HISTORY 8
49 #define IE_GUI_TEXTAREA_SPEAKER 16
50 #define IE_GUI_TEXTAREA_ALT_FONT 32 //this one disables drop capitals
51 #define IE_GUI_TEXTAREA_EDITABLE 64
53 // internal flags
54 #define TA_INITIALS 1
55 #define TA_BITEMYTAIL 2
57 /**
58 * @class TextArea
59 * Widget capable of displaying long paragraphs of text.
60 * It is usually scrolled with a ScrollBar widget
63 class GEM_EXPORT TextArea : public Control {
64 public:
65 TextArea(Color hitextcolor, Color initcolor, Color lowtextcolor);
66 ~TextArea(void);
67 /** global configuration */
68 static void SetNoteString(const char *s);
69 /** Draws the Control on the Output Display */
70 void Draw(unsigned short x, unsigned short y);
71 /** Sets the Actual Text */
72 int SetText(const char* text, int pos = 0);
73 /** Clears the textarea */
74 void Clear();
75 /** Discards scrolled out lines from the textarea */
76 /** preserving 'keeplines' lines for scroll back history */
77 void DiscardLines();
78 /** Appends a String to the current Text */
79 int AppendText(const char* text, int pos = 0);
80 /** Deletes `count' lines (either last or top lines)*/
81 void PopLines(unsigned int count, bool top = false);
82 /** Deletes last lines up to current 'minrow' */
83 void PopMinRow()
85 PopLines((unsigned int) (lines.size()-minrow));
87 /** adds empty lines so minrow will be the uppermost visible row */
88 void PadMinRow();
89 /** Sets up scrolling, tck is the scrolling speed */
90 void SetupScroll(unsigned long tck);
91 /** Sets the Fonts */
92 void SetFonts(Font* init, Font* text);
93 /** Returns Number of Rows */
94 int GetRowCount();
95 /** Returns the length of a Row */
96 int GetRowLength(unsigned int row);
97 /** Returns Number of Visible Rows */
98 int GetVisibleRowCount();
99 /** Returns Starting Row */
100 int GetTopIndex();
101 /** Set Starting Row */
102 void SetRow(int row);
103 /** Sets preserved lines */
104 void SetPreservedRow(int arg);
105 /** Set Selectable */
106 void SetSelectable(bool val);
107 /** Set Minimum Selectable Row (to the current ceiling) */
108 void SetMinRow(bool enable);
109 /** Copies the current TextArea content to another TextArea control */
110 void CopyTo(TextArea* ta);
111 /** Returns the selected text */
112 const char* QueryText();
113 /** Marks textarea for redraw with a new value */
114 void RedrawTextArea(const char* VariableName, unsigned int Sum);
115 int SetScrollBar(Control *ptr);
116 private: // Private attributes
117 std::vector< char*> lines;
118 std::vector< int> lrows;
119 int seltext;
120 /** minimum selectable row */
121 int minrow;
122 /** lines to be kept even if scrolled out */
123 int keeplines;
124 /** vertical offset for smooth scrolling */
125 int smooth;
126 /** timer for scrolling */
127 unsigned long starttime;
128 /** timer ticks for scrolling (speed) */
129 unsigned long ticks;
130 /** Number of Text Rows */
131 int rows;
132 /** Starting Row */
133 int startrow;
134 /** Text Colors */
135 Palette* palette;
136 Palette* initpalette;
137 Palette* selected;
138 Palette* lineselpal;
139 /** a hack for smooth windows, drop capitals */
140 ieDword InternalFlags;
141 /** Fonts */
142 Font* finit, * ftext;
143 ieResRef PortraitResRef;
145 /** Text Editing Cursor Sprite */
146 Sprite2D* Cursor;
147 unsigned short CurPos, CurLine;
149 private: //internal functions
150 void CalcRowCount();
151 void UpdateControls();
152 void RefreshSprite(const char *portrait);
154 public: //Events
155 /** Key Press Event */
156 void OnKeyPress(unsigned char Key, unsigned short Mod);
157 /** Special Key Press */
158 void OnSpecialKeyPress(unsigned char Key);
159 /** Mouse Over Event */
160 void OnMouseOver(unsigned short x, unsigned short y);
161 /** Mouse Button Up */
162 void OnMouseUp(unsigned short x, unsigned short y, unsigned short Button,
163 unsigned short Mod);
164 /** Mouse button down*/
165 void OnMouseDown(unsigned short x, unsigned short y, unsigned short Button,
166 unsigned short Mod);
167 /** Set handler for specified event */
168 bool SetEvent(int eventType, EventHandler handler);
169 /** OnChange Scripted Event Function Name */
170 EventHandler TextAreaOnChange;
171 /** OutOfText Scripted Event Function Name */
172 EventHandler TextAreaOutOfText;
175 #endif