1 #include "CtrlLib.h"
2
3 namespace Upp {
4
Paint(Draw & w)5 void StaticText::Paint(Draw& w)
6 {
7 Size sz = GetSize();
8 if(!IsTransparent())
9 w.DrawRect(0, 0, sz.cx, sz.cy, SColorFace);
10 PaintLabel(this, w, 0, 0, sz.cx, sz.cy, !IsShowEnabled(), false, false, VisibleAccessKeys());
11 }
12
GetMinSize() const13 Size StaticText::GetMinSize() const
14 {
15 return GetLabelSize();
16 }
17
LabelUpdate()18 void StaticText::LabelUpdate() {
19 Refresh();
20 }
21
StaticText()22 StaticText::StaticText()
23 {
24 NoWantFocus();
25 IgnoreMouse();
26 Transparent();
27 SetAlign(ALIGN_LEFT);
28 }
29
SetText(const char * text)30 Label& Label::SetText(const char *text)
31 {
32 LabelBase::SetText(text);
33 lbl.accesskey = 0;
34 noac = false;
35 return *this;
36 }
37
SetLabel(const char * _text)38 Label& Label::SetLabel(const char *_text)
39 {
40 String text;
41 int accesskey = ExtractAccessKey(_text, text);
42 LabelBase::SetText(text);
43 lbl.accesskey = accesskey;
44 return *this;
45 }
46
HotKey(dword key)47 bool Label::HotKey(dword key) {
48 if(CompareAccessKey(lbl.accesskey, key)) {
49 IterateFocusForward(this, GetParent());
50 return true;
51 }
52 return false;
53 }
54
GetAccessKeys() const55 dword Label::GetAccessKeys() const
56 {
57 return AccessKeyBit(lbl.accesskey);
58 }
59
AssignAccessKeys(dword used)60 void Label::AssignAccessKeys(dword used)
61 {
62 if(noac)
63 return;
64 Ctrl *next = GetNext();
65 if(!lbl.accesskey && next && next->IsInitFocus()) {
66 next->AssignAccessKeys(used);
67 if(!next->GetAccessKeysDeep()) {
68 lbl.accesskey = ChooseAccessKey(GetText(), used);
69 if(lbl.accesskey) Refresh();
70 used |= AccessKeyBit(lbl.accesskey);
71 }
72 }
73 Ctrl::AssignAccessKeys(used);
74 }
75
Label()76 Label::Label() {
77 noac = false;
78 }
79
~Label()80 Label::~Label() {}
81
82 CH_COLOR(LabelBoxColor, SColorShadow());
83
84 CH_COLOR(LabelBoxTextColor, SColorText());
85 CH_COLOR(LabelBoxDisabledTextColor, SColorDisabled());
86
LabelBox()87 LabelBox::LabelBox()
88 {
89 color = Null;
90 LabelBase::SetInk(LabelBoxTextColor(), LabelBoxDisabledTextColor());
91 SetVAlign(ALIGN_TOP);
92 }
93
AssignAccessKeys(dword used)94 void LabelBox::AssignAccessKeys(dword used)
95 {
96 Ctrl::AssignAccessKeys(used);
97 }
98
~LabelBox()99 LabelBox::~LabelBox() {}
100
GetVoidRect() const101 Rect LabelBox::GetVoidRect() const
102 {
103 Rect r = GetSize();
104 r.left += 2;
105 r.top += max(GetLabelSize().cy, 2);
106 r.bottom -= 2;
107 r.right -= 2;
108 return r;
109 }
110
111 Value LabelBox::LabelBoxLook;
112
PaintLabelBox(Draw & w,Size sz,Color color,int d)113 void PaintLabelBox(Draw& w, Size sz, Color color, int d)
114 {
115 bool hline = sz.cy < 2 * Draw::GetStdFontCy();
116 bool vline = sz.cx < 2 * Draw::GetStdFontCy();
117 if(GUI_GlobalStyle() >= GUISTYLE_XP || !IsNull(color)) {
118 if(hline) {
119 d = sz.cy / 2;
120 w.DrawRect(0, d - 1, sz.cx, 1, SColorLight);
121 w.DrawRect(0, d, sz.cx, 1, SColorShadow);
122 w.DrawRect(0, d + 1, sz.cx, 1, SColorLight);
123 }
124 else
125 if(vline) {
126 d = sz.cx / 2;
127 w.DrawRect(d - 1, 0, 1, sz.cy, SColorLight);
128 w.DrawRect(d, 0, 1, sz.cy, SColorShadow);
129 w.DrawRect(d + 1, 0, 1, sz.cy, SColorLight);
130 }
131 else {
132 Value look = LabelBox::GetLook();
133 if(IsNull(look) || !IsNull(color)) {
134 Color c = Nvl(color, LabelBoxColor);
135 w.DrawRect(0, d + 2, 1, sz.cy - d - 4, c);
136 w.DrawRect(sz.cx - 1, d + 2, 1, sz.cy - d - 4, c);
137 w.DrawRect(2, sz.cy - 1, sz.cx - 4, 1, c);
138 w.DrawRect(2, d, sz.cx - 4, 1, c);
139
140 w.DrawRect(1, d + 1, 2, 1, c);
141 w.DrawRect(1, d + 2, 1, 1, c);
142
143 w.DrawRect(sz.cx - 3, d + 1, 2, 1, c);
144 w.DrawRect(sz.cx - 2, d + 2, 1, 1, c);
145
146 w.DrawRect(1, sz.cy - 2, 2, 1, c);
147 w.DrawRect(1, sz.cy - 3, 1, 1, c);
148
149 w.DrawRect(sz.cx - 3, sz.cy - 2, 2, 1, c);
150 w.DrawRect(sz.cx - 2, sz.cy - 3, 1, 1, c);
151 }
152 else {
153 Rect r = sz;
154 r.top = d;
155 ChPaintEdge(w, r, look);
156 }
157 }
158 }
159 else {
160 if(hline) {
161 d = sz.cy / 2;
162 w.DrawRect(0, d, sz.cx, 1, SColorShadow);
163 w.DrawRect(0, d + 1, sz.cx, 1, SColorLight);
164 }
165 else
166 if(vline) {
167 d = sz.cx / 2;
168 w.DrawRect(d, 0, 1, sz.cy, SColorShadow);
169 w.DrawRect(d - 1, 1, 0, sz.cy, SColorLight);
170 }
171 else {
172 w.DrawRect(1, d, sz.cx - 2, 1, SColorShadow);
173 w.DrawRect(1, d + 1, sz.cx - 2, 1, SColorLight);
174
175 w.DrawRect(0, d, 1, sz.cy - d - 1, SColorShadow);
176 w.DrawRect(1, d + 1, 1, sz.cy - d - 2, SColorLight);
177
178 w.DrawRect(sz.cx - 2, d, 1, sz.cy - d, SColorShadow);
179 w.DrawRect(sz.cx - 1, d, 1, sz.cy - d, SColorLight);
180
181 w.DrawRect(1, sz.cy - 2, sz.cx - 2, 1, SColorShadow);
182 w.DrawRect(1, sz.cy - 1, sz.cx - 2, 1, SColorLight);
183 }
184 }
185 }
186
Paint(Draw & w)187 void LabelBox::Paint(Draw& w)
188 {
189 Size sz = GetSize();
190 if(!IsTransparent())
191 w.DrawRect(sz, SColorFace);
192 Size lsz = GetLabelSize();
193 int d = lsz.cy >> 1;
194 int ty = sz.cy < 2 * Draw::GetStdFontCy() ? (sz.cy - lsz.cy) / 2 : 0;
195 Size ts = PaintLabel(w, d + DPI(2), ty, sz.cx, lsz.cy, !IsShowEnabled(), false, false, VisibleAccessKeys());
196 w.Begin();
197 w.ExcludeClip(d, ty, ts.cx + DPI(4), ts.cy);
198 PaintLabelBox(w, sz, color, d);
199 w.End();
200 }
201
GetVoidRect() const202 Rect ParentCtrl::GetVoidRect() const
203 {
204 return GetSize();
205 }
206
GetStdSize() const207 Size ParentCtrl::GetStdSize() const
208 {
209 return GetMinSize();
210 }
211
GetMinSize() const212 Size ParentCtrl::GetMinSize() const
213 {
214 return IsNull(minsize) ? Ctrl::GetMinSize() : minsize;
215 }
216
ParentCtrl()217 ParentCtrl::ParentCtrl()
218 {
219 NoWantFocus();
220 Transparent();
221 minsize = Null;
222 }
223
Background(const Value & chvalue)224 StaticRect& StaticRect::Background(const Value& chvalue)
225 {
226 if(chvalue != bg) {
227 bg = chvalue;
228 Refresh();
229 }
230 return *this;
231 }
232
Paint(Draw & w)233 void StaticRect::Paint(Draw& w)
234 {
235 ChPaint(w, GetSize(), bg);
236 }
237
StaticRect()238 StaticRect::StaticRect() {
239 bg = SColorFace();
240 NoWantFocus();
241 }
242
~StaticRect()243 StaticRect::~StaticRect() {}
244
Paint(Draw & w)245 void ImageCtrl::Paint(Draw& w)
246 {
247 if(!img) return;
248 Size sz = GetSize();
249 Size bsz = GetStdSize();
250 w.DrawImage((sz.cx - bsz.cx) / 2, (sz.cy - bsz.cy) / 2, img);
251 }
252
GetStdSize() const253 Size ImageCtrl::GetStdSize() const
254 {
255 return img.GetSize();
256 }
257
GetMinSize() const258 Size ImageCtrl::GetMinSize() const
259 {
260 return img.GetSize();
261 }
262
263
Background(Color color)264 DrawingCtrl& DrawingCtrl::Background(Color color)
265 {
266 background = color;
267 Transparent(IsNull(color));
268 Refresh();
269 return *this;
270 }
271
Paint(Draw & w)272 void DrawingCtrl::Paint(Draw& w) {
273 Size sz = GetSize();
274 w.DrawRect(0, 0, sz.cx, sz.cy, background);
275 if(!picture) return;
276 int dx = 0;
277 int dy = 0;
278 Size rz = sz;
279 if(ratio) {
280 Size sr = picture.GetSize();
281 if(sr.cy * sz.cx < sz.cy * sr.cx) {
282 if(sr.cx) {
283 rz.cy = sr.cy * sz.cx / sr.cx;
284 dy = (sz.cy - rz.cy) / 2;
285 }
286 }
287 else {
288 if(sr.cy) {
289 rz.cx = sr.cx * sz.cy / sr.cy;
290 dx = (sz.cx - rz.cx) / 2;
291 }
292 }
293 }
294 w.Clipoff(dx, dy, rz.cx, rz.cy);
295 w.DrawDrawing(0, 0, rz.cx, rz.cy, picture);
296 w.End();
297 }
298
DrawingCtrl()299 DrawingCtrl::DrawingCtrl() {
300 ratio = true;
301 background = White;
302 }
303
GetMinSize() const304 Size SeparatorCtrl::GetMinSize() const {
305 return Size(size, size);
306 }
307
CH_STYLE(SeparatorCtrl,Style,StyleDefault)308 CH_STYLE(SeparatorCtrl, Style, StyleDefault)
309 {
310 l1 = SColorShadow();
311 l2 = Null;
312 }
313
Paint(Draw & w)314 void SeparatorCtrl::Paint(Draw& w) {
315 Size sz = GetSize();
316 if(sz.cx > sz.cy) {
317 int q = sz.cy / 2;
318 ChPaint(w, lmargin, q - 1, sz.cx - (lmargin + rmargin), 1, style->l1);
319 ChPaint(w, lmargin, q, sz.cx - (lmargin + rmargin), 1, style->l2);
320 }
321 else {
322 int q = sz.cx / 2;
323 ChPaint(w, q - 1, lmargin, 1, sz.cy - (lmargin + rmargin), style->l1);
324 ChPaint(w, q, lmargin, 1, sz.cy - (lmargin + rmargin), style->l2);
325 }
326 };
327
Margin(int l,int r)328 SeparatorCtrl& SeparatorCtrl::Margin(int l, int r)
329 {
330 if(l != lmargin || r != rmargin) {
331 lmargin = l;
332 rmargin = r;
333 Refresh();
334 }
335 return *this;
336 }
337
SetSize(int w)338 SeparatorCtrl& SeparatorCtrl::SetSize(int w)
339 {
340 if(w != size) {
341 size = w;
342 Refresh();
343 }
344 return *this;
345 }
346
SetStyle(const Style & s)347 SeparatorCtrl& SeparatorCtrl::SetStyle(const Style& s)
348 {
349 if(&s != style) {
350 style = &s;
351 Refresh();
352 }
353 return *this;
354 }
355
SeparatorCtrl()356 SeparatorCtrl::SeparatorCtrl()
357 {
358 lmargin = rmargin = 2;
359 size = 7;
360 NoWantFocus();
361 Transparent();
362 Disable();
363 style = &StyleDefault();
364 }
365
Paint(Draw & w)366 void DisplayCtrl::Paint(Draw& w)
367 {
368 pr.Paint(w, GetSize());
369 }
370
GetMinSize() const371 Size DisplayCtrl::GetMinSize() const
372 {
373 return pr.GetStdSize();
374 }
375
SetData(const Value & v)376 void DisplayCtrl::SetData(const Value& v)
377 {
378 pr.SetValue(v);
379 Refresh();
380 }
381
GetData() const382 Value DisplayCtrl::GetData() const
383 {
384 return pr.GetValue();
385 }
386
SetDisplay(const Display & d)387 void DisplayCtrl::SetDisplay(const Display& d)
388 {
389 pr.SetDisplay(d);
390 }
391
392 }
393