My favorites | Sign in
Project Home Downloads Source
Checkout   Browse   Changes    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
#include "RichText.h"

NAMESPACE_UPP

RichTable::Format::Format()
{
grid = 4;
gridcolor = Black;
frame = 10;
framecolor = Black;
before = after = lm = rm = 0;
header = 0;
keep = false;
}

#include "RichText.h"

void RichTable::ExpandFrr(VectorMap<int, Rect>& frr, int pi, int l, int r, int t, int b)
{
Rect& fr = frr.GetAdd(pi, Rect(INT_MAX, INT_MAX, INT_MIN, INT_MIN));
fr.left = min(fr.left, l);
fr.right = max(fr.right, r);
fr.top = min(fr.top, t);
fr.bottom = max(fr.bottom, b);
}

bool RichTable::RowPaint(PageDraw& pw, const RichStyles& st, const Layout& tab,
int i, int ny, const Rect& pg, VectorMap<int, Rect>& frr,
PaintInfo& pi, int pd, bool sel) const
{
RichContext rc(st);
const Array<RichCell>& row = cell[i];
const PaintRow& pr = tab[i];
rc.py = pr.py;
rc.py.page += pd;
if(pw.tracer)
pw.tracer->TableRow(pg, rc.py, i, *this);
int gridln = LineZoom(pi.zoom, format.grid);
int ff2ln = gridln - gridln / 2;
Color gc = format.gridcolor;
if(gridln == 0 && !IsNull(pi.showcodes)) {
gridln = 1;
gc = pi.showcodes;
}
for(int j = 0; j < format.column.GetCount();) {
const RichCell& cell = row[j];
const PaintCell& pc = pr[j];
if(pc.top) {
PageY pyy = tab[min(ny - 1, i + cell.vspan)].pyy;
pyy.page += pd;
bool paint = pyy > pi.top;
rc.page = pr[j].page;
Rect xpg = pg;
int y;
int ny = pi.zoom * pyy.y;
y = pi.zoom * pr.gpy.y;
if(j) {
xpg.left = pi.zoom * pc.left - ff2ln;
if(pyy.page == rc.py.page)
pw.Page(rc.py.page).DrawRect(xpg.left, y, gridln, ny - y, gc);
else {
pw.Page(rc.py.page).DrawRect(xpg.left, y, gridln, pg.bottom - y, gc);
for(int i = rc.py.page + 1; i < pyy.page; i++)
pw.Page(i).DrawRect(xpg.left, pg.top, gridln, pg.bottom - pg.top, gc);
pw.Page(pyy.page).DrawRect(xpg.left, pg.top, gridln, ny - pg.top, gc);
}
xpg.left += gridln;
}
if(j + cell.hspan < format.column.GetCount() - 1)
xpg.right = pi.zoom * pc.right - ff2ln;
if(!pr.first) {
y += gridln;
if(paint)
pw.Page(rc.py.page).DrawRect(xpg.left, y - gridln, xpg.Width(), gridln, gc);
}
if(paint) {
if(pw.tracer)
pw.tracer->TableCell(rc.page, rc.py, i, j, *this, pyy);
row[j].Paint(pw, rc, pyy, xpg, y, ny, pi,
sel && j >= pi.cells.left && i >= pi.cells.top &&
j + cell.hspan <= pi.cells.right && i + cell.vspan <= pi.cells.bottom);
if(pw.tracer)
pw.tracer->EndTableCell(pyy);
}
if(pyy.page == rc.py.page)
ExpandFrr(frr, pyy.page, xpg.left, xpg.right, y, ny);
else {
ExpandFrr(frr, rc.py.page, xpg.left, xpg.right, y, xpg.bottom);
for(int i = rc.py.page + 1; i < pyy.page; i++)
ExpandFrr(frr, i, xpg.left, xpg.right, xpg.top, xpg.bottom);
ExpandFrr(frr, pyy.page, xpg.left, xpg.right, xpg.top, ny);
}
int l = cell.text.GetLength() + 1;
pi.sell -= l;
pi.selh -= l;
pi.tablesel -= cell.text.GetTableCount();
}
j += cell.hspan + 1;
}
if(pw.tracer)
pw.tracer->EndTableRow(rc.py);
return rc.py >= pi.bottom;
}

void RichTable::Paint(PageDraw& pw, RichContext rc, const PaintInfo& _pi) const
{
if(pw.tracer)
pw.tracer->Table(rc.page, rc.py, *this);
const TabLayout& tab = Realize(rc);
if(!tab.page.IsEmpty()) {
PaintInfo pi = _pi;
int frameln = LineZoom(pi.zoom, format.frame);
int gridln = LineZoom(pi.zoom, format.grid);
Rect pg = rc.page;
pg.left += format.lm;
pg.right -= format.rm;
pg.left = pi.zoom * pg.left;
pg.right = pi.zoom * pg.right;
pg.top = pi.zoom * pg.top;
pg.bottom = pi.zoom * pg.bottom;
pg.Deflate(frameln);
int hy = min(format.header, cell.GetCount());
Rect hpg = pg;
if(tab.hasheader) {
hpg.bottom = pi.zoom * tab.header[hy - 1].pyy.y;
pg.top = hpg.bottom + gridln;
}
bool allsel = false;
if(pi.sell < 0 && pi.selh >= 0) {
pi.sell = pi.selh = 0;
allsel = true;
}
bool sel = pi.tablesel == 0;
int ny = cell.GetCount();
VectorMap<int, Rect> frr;
for(int i = 0; i < ny; i++)
if(RowPaint(pw, rc.styles, tab, i, ny, pg, frr, pi, 0, sel))
break;

Color gc = format.gridcolor;
Color fc = format.framecolor;
int fl = frameln;
if(!IsNull(pi.showcodes)) {
if(fl == 0 && !IsNull(pi.showcodes)) {
fl = 1;
fc = pi.showcodes;
}
if(gridln == 0) {
gridln = 1;
gc = pi.showcodes;
}
}
for(int i = 0; i < frr.GetCount(); i++) {
pi.tablesel = 0;
pi.sell = pi.selh = -1;
int pgi = frr.GetKey(i);
Draw& w = pw.Page(pgi);
if(pgi > tab.page0 && tab.hasheader)
for(int i = 0; i < hy; i++) {
RowPaint(pw, rc.styles, tab.header, i, hy, hpg, frr, pi, pgi, false);
w.DrawRect(pg.left, hpg.bottom, pg.Width(), gridln, format.gridcolor);
}
Rect r = frr[i].Inflated(frameln);
if(!r.IsEmpty()) {
DrawFatFrame(w, r, fc, fl);
if(allsel)
w.DrawRect(r, InvertColor);
}
}
}
if(pw.tracer)
pw.tracer->EndTable(rc.py);
}

PageY RichTable::GetHeight(RichContext rc) const
{
PageY pyy = Realize(rc).pyy;
pyy.y += format.frame;
pyy.y += format.after;
if(pyy.y > rc.page.bottom) {
pyy.y = rc.page.top;
pyy.page++;
}
return pyy;
}

PageY RichTable::GetTop(RichContext rc) const
{
if(cell.GetCount() == 0)
return rc.py;
rc.py = Realize(rc)[0].py;
rc.py.y -= format.frame;
return rc.py;
}

RichCaret RichTable::GetCaret(int pos, RichContext rc) const
{
ASSERT(pos >= 0);
int nx = format.column.GetCount();
int ny = cell.GetCount();
int ti = 0;
const TabLayout& tab = Realize(rc);
for(int i = 0; i < ny; i++) {
const PaintRow& pr = tab[i];
rc.py = pr.py;
PageY pyy;
for(int j = 0; j < nx; j++) {
if(ci[i][j].valid) {
const RichCell& cl = cell[i][j];
pyy = tab[min(ny - 1, i + cl.vspan)].pyy;
int l = cl.text.GetLength() + 1;
if(pos < l) {
rc.page = pr[j].page;
return cl.GetCaret(pos, rc, pyy);
}
ti += cl.text.GetTableCount();
pos -= l;
}
}
}
NEVER();
return RichCaret();
}

int RichTable::GetPos(int x, PageY y, RichContext rc) const
{
int nx = format.column.GetCount();
int ny = cell.GetCount();
const TabLayout& tab = Realize(rc);
int pos = 0;
for(int i = 0; i < ny; i++) {
const PaintRow& pr = tab[i];
rc.py = pr.py;
for(int j = 0; j < nx; j++)
if(ci[i][j].valid) {
const RichCell& cl = cell[i][j];
const PaintCell& pc = pr[j];
PageY pyy = tab[min(ny - 1, i + cl.vspan)].pyy;
if(y < pyy
&& (j == 0 || x >= pc.page.left - format.grid)
&& (j == nx - 1 || x < pc.page.right)) {
rc.page = pc.page;
return cl.GetPos(x, y, rc, pyy) + pos;
}
pos += cl.text.GetLength() + 1;
}
}
return pos ? pos - 1 : 0;
}

RichHotPos RichTable::GetHotPos(int x, PageY y, int tolerance, RichContext rc) const
{
RichHotPos hp;
hp.textleft = rc.page.left;
hp.textcx = rc.page.Width();
int nx = format.column.GetCount();
int ny = cell.GetCount();
const TabLayout& tab = Realize(rc);
if(abs(x - tab.page.left) <= tolerance) {
hp.table = 0;
hp.column = RICHHOT_LM;
hp.delta = x - tab.page.left;
return hp;
}
if(abs(x - tab.page.right) <= tolerance) {
hp.table = 0;
hp.column = RICHHOT_RM;
hp.delta = x - tab.page.right;
return hp;
}
int ti = 0;
for(int i = 0; i < ny; i++) {
const PaintRow& pr = tab[i];
rc.py = pr.py;
for(int j = 0; j < nx; j++) {
if(ci[i][j].valid) {
const RichCell& cl = cell[i][j];
const PaintCell& pc = pr[j];
PageY pyy = tab[min(ny - 1, i + cl.vspan)].pyy;
if(y < pyy) {
if(j < nx - 1 && abs(x - pc.page.right) <= tolerance) {
hp.table = 0;
hp.column = j + cl.hspan;
hp.delta = x - pc.page.right;
hp.left = tab.page.left;
hp.cx = tab.page.Width();
return hp;
}
if((j == 0 || x >= pc.page.left - format.grid) && (j == nx - 1 || x < pc.page.right)) {
rc.page = pc.page;
hp = cl.GetHotPos(x, y, tolerance, rc, pyy);
hp.table += ti;
return hp;
}
}
ti += cl.text.GetTableCount();
}
}
}
return RichHotPos();
}

int RichTable::GetVertMove(int pos, int gx, RichContext rc, int dir) const
{
if(cell.GetCount() == 0)
return -1;
int nx = format.column.GetCount();
int ny = cell.GetCount();
const TabLayout& tab = Realize(rc);
Point cp;
if(pos >= 0)
cp = FindCell(pos);
else {
cp.y = dir > 0 ? 0 : cell.GetCount() - 1;
cp.x = 0;
const PaintRow& pr = tab[cp.y];
for(int j = 0; j < nx; j++)
if(ci[cp.y][cp.x].valid && gx < pr[j].page.right) {
cp.x = j;
break;
}
pos = -1;
}
for(;;) {
rc.page = tab[cp.y][cp.x].page;
const RichCell& c = cell[cp.y][cp.x];
RichContext rc1 = rc;
if(c.Reduce(rc1)) {
int q = cell[cp.y][cp.x].text.GetVertMove(pos, gx, rc1, dir);
if(q >= 0)
return q + GetCellPos(cp);
}
pos = -1;
cp.y += dir;
if(cp.y < 0 || cp.y >= ny)
return -1;
}
}

void RichTable::GatherValPos(Vector<RichValPos>& f, RichContext rc, int pos, int type) const
{
ASSERT(pos >= 0);
int nx = format.column.GetCount();
int ny = cell.GetCount();
const TabLayout& tab = Realize(rc);
for(int i = 0; i < ny; i++) {
const PaintRow& pr = tab[i];
rc.py = pr.py;
for(int j = 0; j < nx; j++)
if(ci[i][j].valid) {
const RichCell& cl = cell[i][j];
rc.page = pr[j].page;
cl.GatherValPos(f, rc, tab[min(ny - 1, i + cl.vspan)].pyy, pos, type);
pos += cl.text.GetLength() + 1;
}
}
}

void RichTable::ApplyZoom(Zoom z, const RichStyles& ostyle, const RichStyles& zstyle)
{
Invalidate();
r_row = -1;
int nx = format.column.GetCount();
int ny = cell.GetCount();
format.frame = LineZoom(z, format.frame);
format.grid = LineZoom(z, format.grid);
format.before *= z;
format.lm *= z;
format.rm *= z;
format.after *= z;
for(int i = 0; i < ny; i++)
for(int j = 0; j < nx; j++)
if(ci[i][j].valid) {
RichCell& c = cell[i][j];
c.format.border *= z;
c.format.margin *= z;
c.format.minheight *= z;
c.text.ApplyZoom(z, ostyle, zstyle);
}
}

END_UPP_NAMESPACE

Change log

r4457 by cxl on Jan 21, 2012   Diff
*uppsrc: Fixed many GCC warnings
Go to: 
Project members, sign in to write a code review

Older revisions

r1655 by cxl on Oct 25, 2009   Diff
RichText: RichTextLayoutTracer added
npy parameter to TableCell
r1513 by cxl on Aug 16, 2009   Diff
RichText, Report: RichTextLayoutTracer
ability, theide: workspace
slash/backslash fix
r440 by cxl on Sep 13, 2008   Diff
Fixed RichText zoom problem of tables
(seen as bad tables in help window)
All revisions of this file

File info

Size: 9962 bytes, 382 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting