1 /* $XTermId: linedata.c,v 1.79 2011/01/21 00:07:35 tom Exp $ */
3 /************************************************************
5 Copyright 2009-2010,2011 by Thomas E. Dickey
9 Permission is hereby granted, free of charge, to any person obtaining a
10 copy of this software and associated documentation files (the
11 "Software"), to deal in the Software without restriction, including
12 without limitation the rights to use, copy, modify, merge, publish,
13 distribute, sublicense, and/or sell copies of the Software, and to
14 permit persons to whom the Software is furnished to do so, subject to
15 the following conditions:
17 The above copyright notice and this permission notice shall be included
18 in all copies or substantial portions of the Software.
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 IN NO EVENT SHALL THE ABOVE LISTED COPYRIGHT HOLDER(S) BE LIABLE FOR ANY
24 CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 Except as contained in this notice, the name(s) of the above copyright
29 holders shall not be used in advertising or otherwise to promote the
30 sale, use or other dealings in this Software without prior written
33 ********************************************************/
36 #include <data.h> /* FIXME - needed for 'term' */
41 * Given a row-number, find the corresponding data for the line in the VT100
42 * widget. Row numbers can be positive or negative.
44 * If the data comes from the scrollback, defer that to getScrollback().
47 getLineData(TScreen * screen, int row)
51 int max_row = screen->max_row;
54 buffer = screen->visbuf;
58 result = getScrollback(screen, row);
60 buffer = screen->saveBuf_index;
61 row += screen->savelines;
62 max_row += screen->savelines;
65 if (row >= 0 && row <= max_row) {
66 result = (LineData *) scrnHeadAddr(screen, buffer, (unsigned) row);
68 #if 1 /* FIXME - these should be done in setupLineData, etc. */
69 result->lineSize = (Dimension) MaxCols(screen);
71 if (screen->wide_chars) {
72 result->combSize = (Char) screen->max_combining;
85 * Copy line's data, e.g., from one screen buffer to another, given the preset
86 * pointers for the destination.
88 * TODO: optionally prune unused combining character data from the result.
91 copyLineData(LineData * dst, LineData * src)
93 dst->bufHead = src->bufHead;
96 dst->combSize = src->combSize;
100 * Usually we're copying the same-sized line; a memcpy is faster than
103 if (dst->lineSize == src->lineSize) {
104 size_t size = (sizeof(dst->attribs[0])
106 + sizeof(dst->color[0])
108 + sizeof(dst->charData[0])
110 + sizeof(dst->combData[0][0]) * dst->combSize
114 memcpy(dst->attribs, src->attribs, size * dst->lineSize);
117 Dimension limit = ((dst->lineSize < src->lineSize)
124 for (col = 0; col < limit; ++col) {
125 dst->attribs[col] = src->attribs[col];
127 dst->color[col] = src->color[col];
129 dst->charData[col] = src->charData[col];
131 for (comb = 0; comb < dst->combSize; ++comb) {
132 dst->combData[comb][col] = src->combData[comb][col];
136 for (col = limit; col < dst->lineSize; ++col) {
137 dst->attribs[col] = 0;
141 dst->charData[col] = 0;
143 for (comb = 0; comb < dst->combSize; ++comb) {
144 dst->combData[comb][col] = 0;
152 #define initLineExtra(screen) \
153 screen->lineExtra = ((size_t) (screen->max_combining) * sizeof(IChar *))
155 #define initLineExtra(screen) \
156 screen->lineExtra = 0
160 initLineData(XtermWidget xw)
162 TScreen *screen = TScreenOf(xw);
164 initLineExtra(screen);
166 TRACE(("initLineData %lu\n", (unsigned long) screen->lineExtra));
167 TRACE(("...sizeof(LineData) %lu\n", (unsigned long) sizeof(LineData)));
169 TRACE(("...sizeof(CellColor) %lu\n", (unsigned long) sizeof(CellColor)));
171 TRACE(("...sizeof(RowData) %lu\n", (unsigned long) sizeof(RowData)));
172 TRACE(("...offset(lineSize) %lu\n", (unsigned long) offsetof(LineData, lineSize)));
173 TRACE(("...offset(bufHead) %lu\n", (unsigned long) offsetof(LineData, bufHead)));
175 TRACE(("...offset(combSize) %lu\n", (unsigned long) offsetof(LineData, combSize)));
177 TRACE(("...offset(attribs) %lu\n", (unsigned long) offsetof(LineData, attribs)));
179 TRACE(("...offset(color) %lu\n", (unsigned long) offsetof(LineData, color)));
181 TRACE(("...offset(charData) %lu\n", (unsigned long) offsetof(LineData, charData)));
182 TRACE(("...offset(combData) %lu\n", (unsigned long) offsetof(LineData, combData)));
186 * CellData size depends on the "combiningChars" resource.
187 * FIXME - revise this to reduce arithmetic...
189 #define CellDataSize(screen) (SizeOfCellData + screen->lineExtra)
191 #define CellDataAddr(screen, data, cell) \
192 (CellData *)(void *) ((char *)data + (cell * CellDataSize(screen)))
195 newCellData(XtermWidget xw, Cardinal count)
198 TScreen *screen = TScreenOf(xw);
200 initLineExtra(screen);
201 result = (CellData *) calloc((size_t) count, (size_t) CellDataSize(screen));
206 saveCellData(TScreen * screen,
212 CellData *item = CellDataAddr(screen, data, cell);
214 if (column < MaxCols(screen)) {
215 item->attribs = ld->attribs[column];
217 item->color = ld->color[column];
219 item->charData = ld->charData[column];
220 if_OPT_WIDE_CHARS(screen, {
222 item->combSize = ld->combSize;
223 for_each_combData(off, ld) {
224 item->combData[off] = ld->combData[off][column];
231 restoreCellData(TScreen * screen,
237 CellData *item = CellDataAddr(screen, data, cell);
239 if (column < MaxCols(screen)) {
240 ld->attribs[column] = item->attribs;
242 ld->color[column] = item->color;
244 ld->charData[column] = item->charData;
245 if_OPT_WIDE_CHARS(screen, {
247 ld->combSize = item->combSize;
248 for_each_combData(off, ld) {
249 ld->combData[off][column] = item->combData[off];