1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef GLK_WINDOW_TEXT_GRID_H
24 #define GLK_WINDOW_TEXT_GRID_H
25 
26 #include "glk/windows.h"
27 #include "glk/conf.h"
28 #include "glk/speech.h"
29 
30 namespace Glk {
31 
32 /**
33  * Text Grid window
34  */
35 class TextGridWindow : public TextWindow, Speech {
36 	/**
37 	 * Structure for a row within the grid window
38 	 */
39 	struct TextGridRow {
40 		Common::Array<uint32> _chars;
41 		Common::Array<Attributes> _attrs;
42 		bool dirty;
43 
44 		/**
45 		 * Constructor
46 		 */
TextGridRowTextGridRow47 		TextGridRow() : dirty(false) {}
48 
49 		/**
50 		 * Resize the row
51 		 */
52 		void resize(size_t newSize);
53 	};
54 	typedef Common::Array<TextGridRow> TextGridRows;
55 private:
56 	MonoFontInfo &_font;
57 private:
58 	/**
59 	 * Mark a given text row as modified
60 	 */
61 	void touch(int line);
62 
63 	/**
64 	 * Return or enter, during line input. Ends line input.
65 	 */
66 	void acceptLine(uint32 keycode);
67 public:
68 	int _width, _height;
69 	TextGridRows _lines;
70 
71 	int _curX, _curY;    ///< the window cursor position
72 
73 	///< for line input
74 	void *_inBuf;        ///< unsigned char* for latin1, uint32* for unicode
75 	int _inOrgX, _inOrgY;
76 	int _inMax;
77 	int _inCurs, _inLen;
78 	Attributes _origAttr;
79 	gidispatch_rock_t _inArrayRock;
80 	uint32 *_lineTerminators;
81 
82 	WindowStyle _styles[style_NUMSTYLES]; ///< style hints and settings
83 public:
84 	/**
85 	 * Constructor
86 	 */
87 	TextGridWindow(Windows *windows, uint rock);
88 
89 	/**
90 	 * Destructor
91 	 */
92 	~TextGridWindow() override;
93 
94 	/**
95 	 * Get the font info structure associated with the window
96 	 */
getFontInfo()97 	FontInfo *getFontInfo() override { return &_font; }
98 
99 	/**
100 	 * Set the size of a window
101 	 */
setSize(const Point & newSize)102 	void setSize(const Point &newSize) override {
103 		Window::setSize(newSize);
104 		_curX = CLIP((int16)_curX, _bbox.left, _bbox.right);
105 		_curY = CLIP((int16)_curY, _bbox.top, _bbox.bottom);
106 	}
107 
108 	/**
109 	 * Sets the position of a window
110 	 */
setPosition(const Point & newPos)111 	void setPosition(const Point &newPos) override {
112 		_bbox.moveTo(newPos);
113 		_curX = CLIP((int16)_curX, _bbox.left, _bbox.right);
114 		_curY = CLIP((int16)_curY, _bbox.top, _bbox.bottom);
115 	}
116 
117 	/**
118 	 * Rearranges the window
119 	 */
120 	void rearrange(const Rect &box) override;
121 
122 	/**
123 	 * Get window split size within parent pair window
124 	 */
125 	uint getSplit(uint size, bool vertical) const override;
126 
127 	/**
128 	 * Write a unicode character
129 	 */
130 	void putCharUni(uint32 ch) override;
131 
132 	/**
133 	 * Unput a unicode character
134 	 */
135 	bool unputCharUni(uint32 ch) override;
136 
137 	/**
138 	 * Get the cursor position
139 	 */
getCursor()140 	Point getCursor() const override { return Point(_curX, _curY); }
141 
142 	/**
143 	 * Move the cursor
144 	 */
145 	void moveCursor(const Point &newPos) override;
146 
147 	/**
148 	 * Clear the window
149 	 */
150 	void clear() override;
151 
152 	/**
153 	 * Click the window
154 	 */
155 	void click(const Point &newPos) override;
156 
157 	/**
158 	 * Cancel a hyperlink event
159 	 */
cancelHyperlinkEvent()160 	void cancelHyperlinkEvent() override {
161 		_hyperRequest = false;
162 	}
163 
164 	/**
165 	 * Redraw the window
166 	 */
167 	void redraw() override;
168 
169 	void acceptReadLine(uint32 arg) override;
170 
171 	void acceptReadChar(uint arg) override;
172 
173 	void getSize(uint *width, uint *height) const override;
174 
175 	void requestCharEvent() override;
176 
177 	void requestCharEventUni() override;
178 
179 	/**
180 	 * Prepare for inputing a line
181 	 */
182 	void requestLineEvent(char *buf, uint maxlen, uint initlen) override;
183 
184 	/**
185 	 * Prepare for inputing a line
186 	 */
187 	void requestLineEventUni(uint32 *buf, uint maxlen, uint initlen) override;
188 
189 	/**
190 	 * Cancel an input line event
191 	 */
192 	void cancelLineEvent(Event *ev) override;
193 
194 	/**
195 	 * Cancel a mouse event
196 	 */
cancelMouseEvent()197 	void cancelMouseEvent() override {
198 		_mouseRequest = false;
199 	}
200 
requestMouseEvent()201 	void requestMouseEvent() override {
202 		_mouseRequest = true;
203 	}
204 
requestHyperlinkEvent()205 	void requestHyperlinkEvent() override {
206 		_hyperRequest = true;
207 	}
208 
cancelCharEvent()209 	void cancelCharEvent() override {
210 		_charRequest = _charRequestUni = false;
211 	}
212 
213 	/**
214 	 * Returns a pointer to the styles for the window
215 	 */
getStyles()216 	const WindowStyle *getStyles() const override {
217 		return _styles;
218 	}
219 };
220 
221 } // End of namespace Glk
222 
223 #endif
224