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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#include <CtrlLib/CtrlLib.h>

NAMESPACE_UPP

#include "GridDisplay.h"
#define IMAGECLASS GridImg
#define IMAGEFILE <GridCtrl/GridCtrl.iml>
#include <Draw/iml_source.h>
#include "GridUtils.h"

GLOBAL_VAR(GridDisplay, StdGridDisplay)

static Image (*vhdr[])() =
{
GridImg::VHdr0,
GridImg::VHdr1,
GridImg::VHdr2,
GridImg::VHdr3,
GridImg::VHdr4,
GridImg::VHdr5,
GridImg::VHdr6,
GridImg::VHdr7
};

void GridDisplay::SetDefault()
{
SetTextAlign();
SetHorzMargin();
SetVertMargin();
SetTheme();
}

void GridDisplay::SetTheme(int th)
{
theme = th;
hdrhigh = Contrast(vhdr[theme](), 230);
}

WString GridDisplay::GetStdConvertedValue(const Value &v) const
{
return IsString(v) ? v : StdConvert().Format(v);
}

void GridDisplay::Paint(Draw &w, int x, int y, int cx, int cy, const Value &val, dword style,
Color &fg, Color &bg, Font &fnt, bool found, int fs, int fe)
{
real_size.cx = 0;
real_size.cy = 0;

if(cx == 0 || cy == 0) return;

Color mg = bg;

int al = style & GD::ALIGN ? style & GD::ALIGN : align;

if(cx > lm + rm && cy > tm + bm)
{
int nx = x + lm;
int ny = y + tm;
int ncx = cx - lm - rm;
int ncy = cy - tm - bm;

if(IsNull(bgImg))
{
if(lm > 0) w.DrawRect(x, y, lm, cy, mg);
if(rm > 0) w.DrawRect(x + cx - rm, y, rm, cy, mg);
if(tm > 0) w.DrawRect(x, y, cx, tm, mg);
if(bm > 0) w.DrawRect(x, y + cy - bm, cx, bm, mg);

w.DrawRect(nx, ny, ncx, ncy, bg);
}
else
w.DrawImage(x, y, cx, cy, bgImg);

w.Clip(nx, ny, ncx, ncy);

if(!leftImg.IsEmpty())
{
Size isz = leftImg.GetSize();
w.DrawImage(nx, ny + (cy - isz.cy) / 2, style & GD::READONLY ? Grayscale(leftImg) : leftImg);
nx += isz.cx + 3;
}
if(!rightImg.IsEmpty())
{
Size isz = rightImg.GetSize();
w.DrawImage(nx + ncx - isz.cx, y + (cy - isz.cy) / 2, style & GD::READONLY ? Grayscale(rightImg) : rightImg);
}
if(!centerImg.IsEmpty())
{
Size isz = centerImg.GetSize();
w.DrawImage(x + (cx - isz.cx) / 2, y + (cy - isz.cy) / 2, style & GD::READONLY ? Grayscale(centerImg) : centerImg);
}

if(!(style & GD::NOTEXT))
{
DrawText(w, nx, nx, ny, ncx, ncy, al, GetStdConvertedValue(val), fnt, fg, bg, found, fs, fe, style & GD::WRAP);
}

w.End();
}
else
w.DrawRect(x, y, cx, cy, bg);
}

void GridDisplay::PaintFixed(Draw &w, bool firstx, bool firsty, int x, int y, int cx, int cy, const Value &val, dword style, Font &fnt,
bool indicator, bool moved, int sortmode, int sortcol, int sortcnt, bool horizontal)
{
real_size.cx = 0;
real_size.cy = 0;

bool chameleon = style & GD::CHAMELEON;
bool highlight = style & GD::HIGHLIGHT;
bool readonly = style & GD::READONLY;

if(chameleon)
{
int ncx = cx;
int nx = x;

int ht = HeaderCtrl::StyleDefault().gridadjustment;

if(firstx)
{
if(ncx >= -ht)
{
ncx -= ht;
if(ncx < 0)
ncx = 0;
}
}
else
nx -= ht;

int q = CTRL_NORMAL;
if(highlight)
q = CTRL_HOT;
if(readonly)
q = CTRL_DISABLED;

ChPaint(w, nx, y, ncx, cy, HeaderCtrl::StyleDefault().look[q]);
}
else
{
if(theme < 0)
w.DrawRect(x, y, cx, cy, highlight ? Blend(SColorFace(), White, 128) : SColorFace());
else
{
int sx = cx > 1 ? cx : 1;
int sy = cy - 1;
if(sx > 0 && sy > 0)
w.DrawImage(x, y, sx, sy, highlight ? hdrhigh : vhdr[theme]());
}

//Color dark(76, 83, 92);
Color dark(155, 154, 153);
//Color dark(155, 154, 153);
Color bright(White);

if(!firstx) w.DrawRect(x, y, 1, cy, bright);
if(!firsty) w.DrawRect(x, y, cx, 1, bright);

if(firstx) w.DrawRect(x, y, 1, cy, dark);
if(firsty) w.DrawRect(x, y, cx, 1, dark);

w.DrawRect(x + cx - 1, y, 1, cy, dark);
w.DrawRect(x, y + cy - 1, cx, 1, dark);
}

int tx = x + lm;

if(firsty)
{
if(!leftImg.IsEmpty())
{
Size isz = leftImg.GetSize();
w.DrawImage(tx, y + (cy - isz.cy) / 2, leftImg);
tx += isz.cx + 3;
}
if(!rightImg.IsEmpty())
{
Size isz = rightImg.GetSize();
w.DrawImage(x + cx - isz.cx - 3, y + (cy - isz.cy) / 2, rightImg);
}
if(!centerImg.IsEmpty())
{
Size isz = centerImg.GetSize();
w.DrawImage(x + (cx - isz.cx) / 2, y + (cy - isz.cy) / 2, centerImg);
}
}

if(moved)
DrawBorder(w, x, y, cx, cy, BlackBorder);

Color col = style & GD::READONLY ? Gray : Black;

if(sortmode > 0)
{
Size isz = GridImg::SortAsc().GetSize();

int yf = y + (cy - isz.cy) / 2;
int xf = tx + 2;
tx = xf + isz.cx + 1;

if(sortcol > 0 && sortcnt > 1)
{
String tcol = AsString(sortcol);

Size tsz = GetTextSize(tcol, fnt);
w.DrawText(tx, y + (cy - tsz.cy) / 2, tcol, fnt);
tx += tsz.cx;
}

if(sortmode == 1)
w.DrawImage(xf, yf, GridImg::SortAsc(), col);
else
w.DrawImage(xf, yf, GridImg::SortDsc(), col);

tx += 3;
}
if(indicator)
{
w.Clip(x, y, cx, cy);
if((style & GD::CURSOR) && (style & GD::SELECT))
{
Size isz = GridImg::FocSel().GetSize();
w.DrawImage(x + (cx - isz.cx) / 2, y + (cy - isz.cy) / 2, GridImg::FocSel(), col);
}
else if(style & GD::CURSOR)
{
Size isz = GridImg::Focused().GetSize();
w.DrawImage(x + (cx - isz.cx) / 2, y + (cy - isz.cy) / 2, GridImg::Focused(), col);
}
else if(style & GD::SELECT)
{
Size isz = GridImg::Selected().GetSize();
w.DrawImage(x + (cx - isz.cx) / 2, y + (cy - isz.cy) / 2, GridImg::Selected(), col);
}
w.End();
}
else if(cx > lm + rm && cy > tm + bm)
{
int nx = x + lm;
int ny = y + tm;
int ncx = cx - lm - rm;
int ncy = cy - tm - bm;

w.Clip(nx, ny, ncx, ncy);

int al = style & GD::ALIGN ? style & GD::ALIGN : align;

Color fg = style & GD::READONLY ? SColorDisabled() : SColorText();

DrawText(w, tx, nx, ny, ncx, ncy, al, GetStdConvertedValue(val), fnt, fg, SColorPaper, 0, 0, 0, style & GD::WRAP);

w.End();
}
}

int GridDisplay::GetLinesCount(int cx, const wchar* s, const Font& font, bool wrap)
{
if(*s == 0)
return 0;

const wchar *p = s;
const wchar *t = s;

const wchar * e = t;
int ccx = max(5, cx);
int enters = 0;
int lines = 0;

while(*p)
{
bool nextline = *p == '\n';
enters += int(nextline);

if(nextline || *(p + 1) == '\0')
{
if(p - e > 0 && wrap)
{
int tcx = GetTextSize(e, font, p - e).cx;
if(tcx > cx)
{
lines += tcx / ccx;
if(tcx % ccx > 0)
lines++;
}
else
lines++;

}
else
lines++;

e = p + 1;
}
p++;
}
return lines;
}

void GridDisplay::DrawText(Draw &w, int mx, int x, int y, int cx, int cy, int align, const wchar *s, const Font &font, const Color &fg, const Color &bg, bool found, int fs, int fe, bool wrap)
{
if(*s == 0)
return;

int tcy = font.Info().GetHeight();

const wchar *p = s;
const wchar *t = s;

int lines = 0;
// int enters = 0;

int ty = y;
Size tsz;

if((align & GD::VCENTER) || (align & GD::BOTTOM))
{
lines = GetLinesCount(cx, s, font, wrap);

if(align & GD::VCENTER)
ty = max(ty, y + (cy - tcy * lines) / 2);
else
ty = y + cy - tcy * lines;
}

//w.DrawText(x, y, Format("lines: %d, cx:%d, cy%d", lines, cx, cy));
Size isz = GridImg::Dots2().GetSize();
int gcx = cx - (wrap ? 0 : isz.cx);

real_size.cy = lines > 1 ? lines * tcy : 0;

while(true)
{
bool nextline = *p == '\n';
bool caret = *p == '\r';
bool endtext = *p == '\0';

const wchar * pp = p;

bool textbreak = false;

if(nextline || endtext)
{
int tx = x;
tsz = GetTextSize(t, font, p - t);

if(tsz.cx > gcx)
{
int size = 0;
const wchar *e = t;
while(e < p)
{
int tcx = GetTextSize(e, font, 1).cx;
size += tcx;
if(size > gcx)
break;
e++;
}

p = e;
if(wrap)
{
textbreak = true;
if(p == t)
p = t + 1;
}
}

if(align & GD::RIGHT)
tx = x + cx - tsz.cx;
else if(align & GD::HCENTER)
tx = x + (cx - tsz.cx) / 2;

Color tfg = fg;

if(found)
{
int chs = t - s;
int che = p - s - 1;

if(fs <= che && fe >= chs)
{
int scx = GetTextSize(t, font, max(chs, fs) - chs).cx;
int ecx = GetTextSize(t, font, min(che, fe) - chs + 1).cx;
Color nbg(255 - fg.GetR(), 255 - fg.GetG(), 255 - fg.GetB());
w.DrawRect(max(mx, tx) + scx, ty, ecx - scx, tcy, Blend(nbg, bg, 100));
}
}

bool dots = !wrap && tsz.cx > gcx;
if(dots)
{
real_size.cx = max(real_size.cx, tsz.cx);

w.Clip(x, y, cx, cy);
w.DrawImage(x + cx - isz.cx, ty + font.Info().GetAscent() - isz.cy, GridImg::Dots2, tfg);
w.End();

if(p > t)
{
w.Clip(x, y, cx - isz.cx , cy);
w.DrawText(max(mx, tx), ty, t, font, tfg, p - t);
w.End();
}
}
else
w.DrawText(max(mx, tx), ty, t, font, tfg, p - t);

ty += tcy;
t = textbreak ? p : (p = pp + 1);
}

if(caret)
*(char *) p = ' ';

if(!textbreak)
{
if(endtext)
break;
else
p++;
}
}
}

END_UPP_NAMESPACE

Change log

r4507 by unodgs on Feb 1, 2012   Diff
GridCtrl: Fixed not scrolling the view
when calling GoEnd()
Go to: 
Project members, sign in to write a code review

Older revisions

r4454 by cxl on Jan 21, 2012   Diff
*GridCtrl: StdGridDisplay now function
instead of global variable (plus some
warning removed)
r3654 by unodgs on Jul 13, 2011   Diff
GridCtrl: Made grid more opengl
friendly
r1683 by unodgs on Nov 7, 2009   Diff
Further fixes to multiline popups
All revisions of this file

File info

Size: 8829 bytes, 428 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting