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
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
#include "CtrlLib.h"

NAMESPACE_UPP

void CtrlsImageLook(Value *look, int i, int n)
{
while(n--)
*look++ = CtrlsImg::Get(i++);
}

void CtrlsImageLook(Value *look, int i, const Image& image, const Color *color, int n)
{
for(int q = 0; q < n; q++)
*look++ = ChLookWith(CtrlsImg::Get(i++), image, *color++);
}

void CtrlsImageLook(Value *look, int i, const Image& image, int n)
{
for(int q = 0; q < n; q++)
*look++ = ChLookWith(CtrlsImg::Get(i++), image);
}

String DeAmp(const char *s)
{
String out;
for(; *s; out.Cat(*s++))
if(*s == '&')
out.Cat('&');
return out;
}

Size GetSmartTextSize(const char *text, Font font, int cx) {
if(*text == '\1') {
Size sz;
RichText txt = ParseQTF(text + 1);
txt.ApplyZoom(GetRichTextStdScreenZoom());
sz.cx = min(cx, txt.GetWidth());
sz.cy = txt.GetHeight(Zoom(1, 1), sz.cx);
return sz;
}
return GetTLTextSize(ToUnicode(text, CHARSET_DEFAULT), font);
}

int GetSmartTextHeight(const char *s, int cx, Font font) {
if(*s == '\1') {
Size sz;
RichText txt = ParseQTF(s + 1);
txt.ApplyZoom(GetRichTextStdScreenZoom());
return txt.GetHeight(Zoom(1, 1), cx);
}
int cy = font.Info().GetHeight();
int h = cy;
while(*s) {
if(*s == '\n')
h += cy;
s++;
}
return h;
}

void DrawSmartText(Draw& draw, int x, int y, int cx, const char *text, Font font, Color ink, int accesskey) {
if(*text == '\1') {
RichText txt = ParseQTF(text + 1, accesskey);
txt.ApplyZoom(GetRichTextStdScreenZoom());
txt.Paint(Zoom(1, 1), draw, x, y, cx);
return;
}
DrawTLText(draw, x, y, cx, ToUnicode(text, CHARSET_DEFAULT), font, ink, accesskey);
}

bool CompareAccessKey(int accesskey, dword key)
{
return accesskey && dword(ToUpper(accesskey & 255) - 'A' + K_ALT_A) == key;
}

int ExtractAccessKey(const char *s, String& label)
{
byte akey = 0;
int pos = 0;
String text;
bool qtf = *s == '\1';
while(*s)
if((*s == '&' && !qtf || *s == '\b') && s[1] && s[1] != '&') {
akey = ToAscii(ToUpper(s[1]));
pos = text.GetLength() + 1;
s++;
}
else
text.Cat(*s++);
text.Shrink();
label = text;
return MAKELONG(akey, pos);
}

int ChooseAccessKey(const char *text, dword used)
{
for(const char *s = text; *s; s++) {
byte ac = *s;
if(ac < 128 && ac >= 'A' && ac <= 'Z' && (Ctrl::AccessKeyBit(ac) & used) == 0)
return MAKELONG(ac, s - text + 1);
}
for(const char *s = text; *s; s++) {
byte ac = ToUpper(*s);
if(ac < 128 && ac >= 'A' && ac <= 'Z' && ac != 'I' && ac != 'L' && (Ctrl::AccessKeyBit(ac) & used) == 0)
return ac;
}
for(const char *s = text; *s; s++) {
byte ac = ToUpper(*s);
if(ac < 128 && ac >= 'A' && ac <= 'Z' && (Ctrl::AccessKeyBit(ac) & used) == 0)
return ac;
}
return 0;
}

DrawLabel::DrawLabel()
{
push = focus = disabled = false;
lspc = rspc = 0;
limg_never_hide = false;
rimg_never_hide = false;
ink = disabledink = Null;
align = valign = ALIGN_CENTER;
accesskey = 0;
accesspos = -1;
font = StdFont();
}

Size DrawLabel::GetSize(int txtcx) const
{
return GetSize(txtcx, limg.GetSize(), lspc, rimg.GetSize(), rspc);
}

Size DrawLabel::GetSize(int txtcx, Size sz1, int lspc, Size sz2, int rspc) const
{
Size isz(0, 0);
Size txtsz = *text ? GetSmartTextSize(text, font, txtcx) : paintrect.GetStdSize();

if(!IsNull(lspc)) {
isz.cx = lspc;
isz.cy = sz1.cy;
isz.cx += sz1.cx;
}

if(!IsNull(rspc)) {
isz.cx += rspc;
if(sz2.cy > isz.cy) isz.cy = sz2.cy;
isz.cx += sz2.cx;
}

isz.cy = max(txtsz.cy, max(sz1.cy, sz2.cy));
isz.cx += txtsz.cx;

return isz;
}

Image DisImage(const Image& m)
{
Image mm = Grayscale(m, 200);
ImageBuffer ib(mm);
RGBA *s = ~ib;
RGBA *e = s + ib.GetLength();
while(s < e)
(s++)->a /= 3;
Premultiply(ib);
return ib;
}

Image DisabledImage(const Image& img, bool dis)
{
return dis ? MakeImage(img, GUI_GlobalStyle() == GUISTYLE_CLASSIC ? Etched : DisImage)
: img;
}

Color GetLabelTextColor(const Ctrl *ctrl)
{
if(!IsLabelTextColorMismatch())
return SColorLabel();
while(ctrl) {
if(!ctrl->IsTransparent()) {
if(dynamic_cast<const TopWindow *>(ctrl) || dynamic_cast<const TabCtrl *>(ctrl) ||
dynamic_cast<const ToolBar *>(ctrl) || dynamic_cast<const MenuBar *>(ctrl) ||
dynamic_cast<const StaticRect *>(ctrl) || dynamic_cast<const StaticBarArea *>(ctrl))
break;
return SColorText();
}
ctrl = ctrl->GetParent();
}
return SColorLabel();
}

Size DrawLabel::Paint(Ctrl *ctrl, Draw& w, const Rect& r, bool visibleaccesskey) const
{
int lspc = this->lspc;
int rspc = this->rspc;
Size sz1 = limg.GetSize();
Size sz2 = rimg.GetSize();
int txtcx = r.GetWidth() - sz1.cx - Nvl(lspc, 0) - sz2.cx - Nvl(rspc, 0);
Size txtsz = *text ? GetSmartTextSize(text, font, txtcx) : paintrect.GetStdSize();
if(txtsz.cx) {
if(!rimg_never_hide && txtsz.cx + sz1.cx + sz2.cx + Nvl(lspc, 0) + Nvl(rspc, 0) > r.GetWidth()) {
sz2.cx = 0;
rspc = 0;
}
if(!limg_never_hide && txtsz.cx + sz1.cx + sz2.cx + Nvl(lspc, 0) + Nvl(rspc, 0) > r.GetWidth()) {
sz1.cx = 0;
lspc = 0;
}
}
Size isz = GetSize(txtcx, sz1, lspc, sz2, rspc);
Point p = r.TopLeft(), ip;
if(align == ALIGN_LEFT)
p.x = r.left;
else
if(align == ALIGN_RIGHT)
p.x = r.right - isz.cx;
else
if(align == ALIGN_CENTER)
p.x = (r.right + r.left - isz.cx) / 2;
if(valign == ALIGN_TOP)
p.y = r.top;
else
if(valign == ALIGN_BOTTOM)
p.y = r.bottom - isz.cy;
else
if(valign == ALIGN_CENTER)
p.y = (r.bottom + r.top - txtsz.cy) / 2;
Color color = disabled && !IsNull(disabledink) ? disabledink : ink;
if(IsNull(color))
color = disabled ? SColorDisabled : GetLabelTextColor(ctrl);
int ix;
if(IsNull(lspc))
ix = r.left + push;
else {
ix = p.x + push;
p.x += sz1.cx;
p.x += lspc;
}
int iy = push + (r.top + r.bottom - sz1.cy) / 2;

if(sz1.cx)
if(IsNull(lcolor))
w.DrawImage(ix, iy, DisabledImage(limg, disabled));
else
w.DrawImage(ix, iy, limg, lcolor);

iy = push + (r.top + r.bottom - sz2.cy) / 2;
ix = (IsNull(rspc) ? r.right - sz2.cx : p.x + txtsz.cx + rspc) + push;
if(sz2.cx)
if(IsNull(rcolor))
w.DrawImage(ix, iy, DisabledImage(rimg, disabled));
else
w.DrawImage(ix, iy, rimg, rcolor);
paintrect.Paint(w, p.x + push, p.y + push, txtsz.cx, isz.cy, color, Null);
if(*text) {
if(disabled)
DrawSmartText(w, p.x + push + 1, p.y + push + (isz.cy - txtsz.cy) / 2 + 1,
txtsz.cx, text, font, SColorPaper);
DrawSmartText(w, p.x + push, p.y + push, txtcx,
text, font, color, visibleaccesskey ? accesskey : 0);
if(focus)
DrawFocus(w, p.x - 2, p.y, txtsz.cx + 5, isz.cy);
}

return isz;
}

Size DrawLabel::Paint(Ctrl *ctrl, Draw& w, int x, int y, int cx, int cy, bool visibleaccesskey) const
{
return Paint(ctrl, w, RectC(x, y, cx, cy), visibleaccesskey);
}

Size DrawLabel::Paint(Draw& w, const Rect& r, bool visibleaccesskey) const
{
return Paint(NULL, w, r, visibleaccesskey);
}

Size DrawLabel::Paint(Draw& w, int x, int y, int cx, int cy, bool vak) const
{
return Paint(w, RectC(x, y, cx, cy), vak);
}

void LabelBase::LabelUpdate() {}

LabelBase& LabelBase::SetLeftImage(const Image& img, int spc, bool never_hide) {
lbl.limg = img;
lbl.lspc = spc;
lbl.limg_never_hide = never_hide;
LabelUpdate();
return *this;
}

LabelBase& LabelBase::SetRightImage(const Image& img, int spc, bool never_hide) {
lbl.rimg = img;
lbl.rspc = spc;
lbl.rimg_never_hide = never_hide;
LabelUpdate();
return *this;
}

LabelBase& LabelBase::SetPaintRect(const PaintRect& paintrect) {
lbl.paintrect = paintrect;
LabelUpdate();
return *this;
}


LabelBase& LabelBase::SetText(const char *text) {
lbl.text = text;
LabelUpdate();
return *this;
}

LabelBase& LabelBase::SetFont(Font font) {
if(lbl.font != font) {
lbl.font = font;
LabelUpdate();
}
return *this;
}

LabelBase& LabelBase::SetInk(Color ink, Color disabledink) {
if(lbl.ink != ink || lbl.disabledink != disabledink) {
lbl.ink = ink;
lbl.disabledink = disabledink;
LabelUpdate();
}
return *this;
}

LabelBase& LabelBase::SetAlign(int align) {
if(lbl.align != align) {
lbl.align = align;
LabelUpdate();
}
return *this;
}

LabelBase& LabelBase::SetVAlign(int valign) {
if(lbl.valign != valign) {
lbl.valign = valign;
LabelUpdate();
}
return *this;
}

Size LabelBase::PaintLabel(Ctrl *ctrl, Draw& w, const Rect& r, bool disabled, bool push, bool focus, bool vak)
{
DrawLabel lbl1 = lbl;
lbl1.disabled = disabled;
lbl1.push = push;
lbl1.focus = focus;
return lbl1.Paint(ctrl, w, r, vak);
}

Size LabelBase::PaintLabel(Ctrl *ctrl, Draw& w, int x, int y, int cx, int cy, bool disabled, bool push, bool focus, bool vak)
{
return PaintLabel(ctrl, w, RectC(x, y, cx, cy), disabled, push, focus, vak);
}

Size LabelBase::PaintLabel(Draw& w, const Rect& r, bool disabled, bool push, bool focus, bool vak)
{
return PaintLabel(NULL, w, r, disabled, push, focus, vak);
}


Size LabelBase::PaintLabel(Draw& w, int x, int y, int cx, int cy, bool disabled, bool push, bool focus, bool vak)
{
return PaintLabel(w, RectC(x, y, cx, cy), disabled, push, focus, vak);
}

Size LabelBase::GetLabelSize() const
{
return lbl.GetSize();
}

void LinkToolTipIn__();

LabelBase::~LabelBase() {
LinkToolTipIn__();
}

void DrawFocus(Draw& w, int x, int y, int cx, int cy, Color c) {
w.Clipoff(x, y, cx, cy);
for(int a = 0; a < cx; a += CtrlImg::focus_h().GetWidth()) {
w.DrawImage(a, 0, CtrlImg::focus_h(), c);
w.DrawImage(a, cy - 1, CtrlImg::focus_h(), c);
}
for(int a = 0; a < cy; a += CtrlImg::focus_v().GetHeight()) {
w.DrawImage(0, a, CtrlImg::focus_v(), c);
w.DrawImage(cx - 1, a, CtrlImg::focus_v(), c);
}
w.End();
}

void DrawFocus(Draw& w, const Rect& r, Color c) {
DrawFocus(w, r.left, r.top, r.Width(), r.Height(), c);
}

void DrawHorzDrop(Draw& w, int x, int y, int cx)
{
w.DrawRect(x, y, cx, 2, SColorHighlight);
w.DrawRect(x, y - 2, 1, 6, SColorHighlight);
w.DrawRect(x + cx - 1, y - 2, 1, 6, SColorHighlight);
w.DrawRect(x + 1, y - 1, 1, 4, SColorHighlight);
w.DrawRect(x + cx - 2, y - 1, 1, 4, SColorHighlight);
}

void DrawVertDrop(Draw& w, int x, int y, int cy)
{
w.DrawRect(x, y, 2, cy, SColorHighlight);
w.DrawRect(x - 2, y, 6, 1, SColorHighlight);
w.DrawRect(x - 2, y + cy - 1, 6, 1, SColorHighlight);
w.DrawRect(x - 1, y + 1, 4, 1, SColorHighlight);
w.DrawRect(x - 1, y + cy - 2, 4, 1, SColorHighlight);
}

Point GetDragScroll(Ctrl *ctrl, Point p, Size max)
{
if(ctrl->IsReadOnly())
return Point(0, 0);
Size sz = ctrl->GetSize();
Size sd = min(sz / 6, Size(16, 16));
Point d(0, 0);
if(p.x < sd.cx)
d.x = p.x - sd.cx;
if(p.x > sz.cx - sd.cx)
d.x = p.x - sz.cx + sd.cx;
if(p.y < sd.cy)
d.y = p.y - sd.cy;
if(p.y > sz.cy - sd.cy)
d.y = p.y - sz.cy + sd.cy;
d.x = minmax(d.x, -max.cx, max.cx);
d.y = minmax(d.y, -max.cy, max.cy);
return d;
}

Point GetDragScroll(Ctrl *ctrl, Point p, int max)
{
return GetDragScroll(ctrl, p, Size(max, max));
}

Point DisplayPopup::Op(Point p)
{
return p + GetScreenView().TopLeft() - ctrl->GetScreenView().TopLeft();
}

void DisplayPopup::LeftDown(Point p, dword flags)
{
ctrl->LeftDown(Op(p), flags);
}

void DisplayPopup::LeftDrag(Point p, dword flags)
{
Cancel();
ctrl->LeftDrag(Op(p), flags);
}

void DisplayPopup::LeftDouble(Point p, dword flags)
{
ctrl->LeftDouble(Op(p), flags);
}

void DisplayPopup::RightDown(Point p, dword flags)
{
ctrl->RightDown(Op(p), flags);
}

void DisplayPopup::LeftUp(Point p, dword flags)
{
ctrl->LeftUp(Op(p), flags);
}

void DisplayPopup::MouseWheel(Point p, int zdelta, dword flags)
{
ctrl->MouseWheel(Op(p), zdelta, flags);
}

void DisplayPopup::MouseLeave()
{
Cancel();
}

void DisplayPopup::MouseMove(Point p, dword flags)
{
p += GetScreenView().TopLeft();
if(!slim.Contains(p))
MouseLeave();
}

void DisplayPopup::Paint(Draw& w)
{
Rect r = GetSize();
w.DrawRect(r, SColorPaper);
if(display) {
display->PaintBackground(w, r, value, ink, paper, style);
r.left += margin;
display->Paint(w, r, value, ink, paper, style);
}
}

DisplayPopup::DisplayPopup()
{
SetFrame(BlackFrame());
display = NULL;
paper = ink = Null;
style = 0;
item = slim = Null;
margin = 0;
ONCELOCK {
InstallStateHook(StateHook);
InstallMouseHook(MouseHook);
}
LinkBefore(all());
}

DisplayPopup::~DisplayPopup()
{
Unlink();
}

void DisplayPopup::Sync()
{
if(display && ctrl && !ctrl->IsDragAndDropTarget() && !IsDragAndDropTarget()) {
Ctrl *top = ctrl->GetTopCtrl();
if(top && top->HasFocusDeep()) {
Size sz = display->GetStdSize(value);
if(sz.cx + 2 * margin > item.GetWidth() || sz.cy > item.GetHeight()) {
slim = item + ctrl->GetScreenView().TopLeft();
if(slim.Contains(GetMousePos())) {
Rect r = item;
r.right = max(r.right, r.left + sz.cx + 2 * margin);
r.bottom = max(r.bottom, r.top + sz.cy);
r.Inflate(1, 1);
r.Offset(ctrl->GetScreenView().TopLeft());
SetRect(r);
if(!IsOpen())
Ctrl::PopUp(ctrl, true, false, false);
Refresh();
return;
}
}
}
}
if(IsOpen())
Close();
}

Link<DisplayPopup> *DisplayPopup::all()
{
static Link<DisplayPopup> all;
return &all;
}

void DisplayPopup::SyncAll()
{
int n = 0;
for(DisplayPopup *p = all()->Link<DisplayPopup>::GetNext(); p != all(); p = p->Link<DisplayPopup>::GetNext())
if(p->ctrl && p->ctrl->IsOpen()) {
p->Sync();
n++;
}
}

bool DisplayPopup::StateHook(Ctrl *, int reason)
{
if(reason == FOCUS)
SyncAll();
return false;
}


bool DisplayPopup::MouseHook(Ctrl *, bool, int, Point, int, dword)
{
SyncAll();
return false;
}

void DisplayPopup::Cancel()
{
display = NULL;
Sync();
}

bool DisplayPopup::IsOpen()
{
return Ctrl::IsOpen();
}

bool DisplayPopup::HasMouse()
{
return Ctrl::HasMouse() || ctrl && ctrl->HasMouse();
}

void DisplayPopup::Set(Ctrl *_ctrl, const Rect& _item,
const Value& _value, const Display *_display,
Color _ink, Color _paper, dword _style, int _margin)
{
if(item != _item || ctrl != _ctrl || value != _value || display != _display || ink != _ink ||
paper != _paper || style != _style) {
item = _item;
ctrl = _ctrl;
value = _value;
display = _display;
ink = _ink;
paper = _paper;
style = _style;
margin = _margin;
Sync();
}
else
Refresh();
}

END_UPP_NAMESPACE

Change log

r4714 by cxl on Mar 23, 2012   Diff
*CtrlLib: Improved syncing of DisplayPopup
to avoid stall popups (e.g. in ide
navigator)
Go to: 
Project members, sign in to write a code review

Older revisions

r4457 by cxl on Jan 21, 2012   Diff
*uppsrc: Fixed many GCC warnings
r4453 by cxl on Jan 21, 2012   Diff
Fixed some warning
r3887 by cxl on Sep 19, 2011   Diff
CtrlLib, Draw: Improved support for
dark visual themes (corrected text
color, icon inversion for toolbar /
menubar)
All revisions of this file

File info

Size: 14201 bytes, 614 lines

File properties

svn:eol-style
native
Powered by Google Project Hosting