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.
23 * Declares TextArea widget for displaying long paragraphs of text
24 * @author The GemRB Project
30 #include "GUI/Control.h"
31 #include "GUI/ScrollBar.h"
33 #include "RGBAColor.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
55 #define TA_BITEMYTAIL 2
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
{
65 TextArea(Color hitextcolor
, Color initcolor
, Color lowtextcolor
);
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 */
75 /** Discards scrolled out lines from the textarea */
76 /** preserving 'keeplines' lines for scroll back history */
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' */
85 PopLines((unsigned int) (lines
.size()-minrow
));
87 /** adds empty lines so minrow will be the uppermost visible row */
89 /** Sets up scrolling, tck is the scrolling speed */
90 void SetupScroll(unsigned long tck
);
92 void SetFonts(Font
* init
, Font
* text
);
93 /** Returns Number of Rows */
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 */
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
;
120 /** minimum selectable row */
122 /** lines to be kept even if scrolled out */
124 /** vertical offset for smooth scrolling */
126 /** timer for scrolling */
127 unsigned long starttime
;
128 /** timer ticks for scrolling (speed) */
130 /** Number of Text Rows */
136 Palette
* initpalette
;
139 /** a hack for smooth windows, drop capitals */
140 ieDword InternalFlags
;
142 Font
* finit
, * ftext
;
143 ieResRef PortraitResRef
;
145 /** Text Editing Cursor Sprite */
147 unsigned short CurPos
, CurLine
;
149 private: //internal functions
151 void UpdateControls();
152 void RefreshSprite(const char *portrait
);
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
,
164 /** Mouse button down*/
165 void OnMouseDown(unsigned short x
, unsigned short y
, unsigned short Button
,
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
;