/
stdrend.cpp
1271 lines (1070 loc) · 38.2 KB
/
stdrend.cpp
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
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
///////////////////////////////////////////////////////////////////////////////
// Name: src/univ/stdrend.cpp
// Purpose: implementation of wxStdRenderer
// Author: Vadim Zeitlin
// Created: 2006-09-16
// RCS-ID: $Id$
// Copyright: (c) 2006 Vadim Zeitlin <vadim@wxwindows.org>
// Licence: wxWindows licence
///////////////////////////////////////////////////////////////////////////////
// ============================================================================
// declarations
// ============================================================================
// ----------------------------------------------------------------------------
// headers
// ----------------------------------------------------------------------------
// for compilers that support precompilation, includes "wx.h".
#include "wx/wxprec.h"
#ifdef __BORLANDC__
#pragma hdrstop
#endif
#ifndef WX_PRECOMP
#include "wx/settings.h"
#include "wx/brush.h"
#include "wx/dc.h"
#include "wx/statusbr.h"
#include "wx/toplevel.h"
#endif //WX_PRECOMP
#include "wx/univ/stdrend.h"
#include "wx/univ/colschem.h"
// ----------------------------------------------------------------------------
// constants
// ----------------------------------------------------------------------------
static const int FRAME_TITLEBAR_HEIGHT = 18;
static const int FRAME_BUTTON_WIDTH = 16;
static const int FRAME_BUTTON_HEIGHT = 14;
// the margin between listbox item text and its rectangle
static const int ITEM_MARGIN = 1;
// ============================================================================
// wxStdRenderer implementation
// ============================================================================
// ----------------------------------------------------------------------------
// ctor
// ----------------------------------------------------------------------------
wxStdRenderer::wxStdRenderer(const wxColourScheme *scheme)
: m_scheme(scheme)
{
m_penBlack = wxPen(wxSCHEME_COLOUR(scheme, SHADOW_DARK));
m_penDarkGrey = wxPen(wxSCHEME_COLOUR(scheme, SHADOW_OUT));
m_penLightGrey = wxPen(wxSCHEME_COLOUR(scheme, SHADOW_IN));
m_penHighlight = wxPen(wxSCHEME_COLOUR(scheme, SHADOW_HIGHLIGHT));
m_titlebarFont = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
m_titlebarFont.SetWeight(wxFONTWEIGHT_BOLD);
}
// ----------------------------------------------------------------------------
// helper functions
// ----------------------------------------------------------------------------
void
wxStdRenderer::DrawSolidRect(wxDC& dc, const wxColour& col, const wxRect& rect)
{
wxBrush brush(col, wxSOLID);
dc.SetBrush(brush);
dc.SetPen(*wxTRANSPARENT_PEN);
dc.DrawRectangle(rect);
}
void wxStdRenderer::DrawRect(wxDC& dc, wxRect *rect, const wxPen& pen)
{
// draw
dc.SetPen(pen);
dc.SetBrush(*wxTRANSPARENT_BRUSH);
dc.DrawRectangle(*rect);
// adjust the rect
rect->Inflate(-1);
}
void wxStdRenderer::DrawShadedRect(wxDC& dc, wxRect *rect,
const wxPen& pen1, const wxPen& pen2)
{
// draw the rectangle
dc.SetPen(pen1);
dc.DrawLine(rect->GetLeft(), rect->GetTop(),
rect->GetLeft(), rect->GetBottom());
dc.DrawLine(rect->GetLeft() + 1, rect->GetTop(),
rect->GetRight(), rect->GetTop());
dc.SetPen(pen2);
dc.DrawLine(rect->GetRight(), rect->GetTop(),
rect->GetRight(), rect->GetBottom());
dc.DrawLine(rect->GetLeft(), rect->GetBottom(),
rect->GetRight() + 1, rect->GetBottom());
// adjust the rect
rect->Inflate(-1);
}
// ----------------------------------------------------------------------------
// translate various flags into corresponding renderer constants
// ----------------------------------------------------------------------------
/* static */
void wxStdRenderer::GetIndicatorsFromFlags(int flags,
IndicatorState& state,
IndicatorStatus& status)
{
if ( flags & wxCONTROL_SELECTED )
state = flags & wxCONTROL_DISABLED ? IndicatorState_SelectedDisabled
: IndicatorState_Selected;
else if ( flags & wxCONTROL_DISABLED )
state = IndicatorState_Disabled;
else if ( flags & wxCONTROL_PRESSED )
state = IndicatorState_Pressed;
else
state = IndicatorState_Normal;
status = flags & wxCONTROL_CHECKED ? IndicatorStatus_Checked
: flags & wxCONTROL_UNDETERMINED
? IndicatorStatus_Undetermined
: IndicatorStatus_Unchecked;
}
/* static */
wxStdRenderer::ArrowDirection wxStdRenderer::GetArrowDirection(wxDirection dir)
{
switch ( dir )
{
case wxLEFT:
return Arrow_Left;
case wxRIGHT:
return Arrow_Right;
case wxUP:
return Arrow_Up;
case wxDOWN:
return Arrow_Down;
default:
wxFAIL_MSG(wxT("unknown arrow direction"));
}
return Arrow_Max;
}
// ----------------------------------------------------------------------------
// background
// ----------------------------------------------------------------------------
void wxStdRenderer::DrawBackground(wxDC& dc,
const wxColour& col,
const wxRect& rect,
int WXUNUSED(flags),
wxWindow *window)
{
wxColour colBg;
if (col.IsOk())
{
colBg = col;
}
else if (window)
{
colBg = m_scheme->GetBackground(window);
}
else
{
colBg = wxSCHEME_COLOUR(m_scheme, CONTROL);
}
DrawSolidRect(dc, colBg, rect);
}
void wxStdRenderer::DrawButtonSurface(wxDC& dc,
const wxColour& col,
const wxRect& rect,
int flags)
{
DrawBackground(dc, col, rect, flags);
}
// ----------------------------------------------------------------------------
// text
// ----------------------------------------------------------------------------
void
wxStdRenderer::DrawFocusRect(wxWindow* WXUNUSED(win), wxDC& dc, const wxRect& rect, int WXUNUSED(flags))
{
// draw the pixels manually because the "dots" in wxPen with wxDOT style
// may be short traits and not really dots
//
// note that to behave in the same manner as DrawRect(), we must exclude
// the bottom and right borders from the rectangle
wxCoord x1 = rect.GetLeft(),
y1 = rect.GetTop(),
x2 = rect.GetRight(),
y2 = rect.GetBottom();
dc.SetPen(m_penBlack);
// this seems to be closer than what Windows does than wxINVERT although
// I'm still not sure if it's correct
dc.SetLogicalFunction(wxAND_REVERSE);
wxCoord z;
for ( z = x1 + 1; z < x2; z += 2 )
dc.DrawPoint(z, rect.GetTop());
wxCoord shift = z == x2 ? 0 : 1;
for ( z = y1 + shift; z < y2; z += 2 )
dc.DrawPoint(x2, z);
shift = z == y2 ? 0 : 1;
for ( z = x2 - shift; z > x1; z -= 2 )
dc.DrawPoint(z, y2);
shift = z == x1 ? 0 : 1;
for ( z = y2 - shift; z > y1; z -= 2 )
dc.DrawPoint(x1, z);
dc.SetLogicalFunction(wxCOPY);
}
void wxStdRenderer::DrawLabel(wxDC& dc,
const wxString& label,
const wxRect& rect,
int flags,
int alignment,
int indexAccel,
wxRect *rectBounds)
{
DrawButtonLabel(dc, label, wxNullBitmap, rect, flags,
alignment, indexAccel, rectBounds);
}
void wxStdRenderer::DrawButtonLabel(wxDC& dc,
const wxString& label,
const wxBitmap& image,
const wxRect& rect,
int flags,
int alignment,
int indexAccel,
wxRect *rectBounds)
{
wxDCTextColourChanger clrChanger(dc);
wxRect rectLabel = rect;
if ( !label.empty() && (flags & wxCONTROL_DISABLED) )
{
if ( flags & wxCONTROL_PRESSED )
{
// shift the label if a button is pressed
rectLabel.Offset(1, 1);
}
// draw shadow of the text
clrChanger.Set(m_penHighlight.GetColour());
wxRect rectShadow = rect;
rectShadow.Offset(1, 1);
dc.DrawLabel(label, rectShadow, alignment, indexAccel);
// make the main label text grey
clrChanger.Set(m_penDarkGrey.GetColour());
if ( flags & wxCONTROL_FOCUSED )
{
// leave enough space for the focus rect
rectLabel.Inflate(-2);
}
}
dc.DrawLabel(label, image, rectLabel, alignment, indexAccel, rectBounds);
if ( !label.empty() && (flags & wxCONTROL_FOCUSED) )
{
rectLabel.Inflate(-1);
DrawFocusRect(NULL, dc, rectLabel);
}
}
// ----------------------------------------------------------------------------
// borders
// ----------------------------------------------------------------------------
/*
We implement standard-looking 3D borders which have the following appearance:
The raised border:
WWWWWWWWWWWWWWWWWWWWWWB
WHHHHHHHHHHHHHHHHHHHHGB
WH GB W = white (HILIGHT)
WH GB H = light grey (LIGHT)
WH GB G = dark grey (SHADOI)
WH GB B = black (DKSHADOI)
WH GB
WH GB
WGGGGGGGGGGGGGGGGGGGGGB
BBBBBBBBBBBBBBBBBBBBBBB
The sunken border looks like this:
GGGGGGGGGGGGGGGGGGGGGGW
GBBBBBBBBBBBBBBBBBBBBHW
GB HW
GB HW
GB HW
GB HW
GB HW
GB HW
GHHHHHHHHHHHHHHHHHHHHHW
WWWWWWWWWWWWWWWWWWWWWWW
The static border (used for the controls which don't get focus) is like
this:
GGGGGGGGGGGGGGGGGGGGGGW
G W
G W
G W
G W
G W
G W
G W
WWWWWWWWWWWWWWWWWWWWWWW
The most complicated is the double border which is a combination of special
"anti-sunken" border and an extra border inside it:
HHHHHHHHHHHHHHHHHHHHHHB
HWWWWWWWWWWWWWWWWWWWWGB
HWHHHHHHHHHHHHHHHHHHHGB
HWH HGB
HWH HGB
HWH HGB
HWH HGB
HWHHHHHHHHHHHHHHHHHHHGB
HGGGGGGGGGGGGGGGGGGGGGB
BBBBBBBBBBBBBBBBBBBBBBB
And the simple border is, well, simple:
BBBBBBBBBBBBBBBBBBBBBBB
B B
B B
B B
B B
B B
B B
B B
B B
BBBBBBBBBBBBBBBBBBBBBBB
*/
void wxStdRenderer::DrawRaisedBorder(wxDC& dc, wxRect *rect)
{
DrawShadedRect(dc, rect, m_penHighlight, m_penBlack);
DrawShadedRect(dc, rect, m_penLightGrey, m_penDarkGrey);
}
void wxStdRenderer::DrawSunkenBorder(wxDC& dc, wxRect *rect)
{
DrawShadedRect(dc, rect, m_penDarkGrey, m_penHighlight);
DrawShadedRect(dc, rect, m_penBlack, m_penLightGrey);
}
void wxStdRenderer::DrawAntiSunkenBorder(wxDC& dc, wxRect *rect)
{
DrawShadedRect(dc, rect, m_penLightGrey, m_penBlack);
DrawShadedRect(dc, rect, m_penHighlight, m_penDarkGrey);
}
void wxStdRenderer::DrawBoxBorder(wxDC& dc, wxRect *rect)
{
DrawShadedRect(dc, rect, m_penDarkGrey, m_penHighlight);
DrawShadedRect(dc, rect, m_penHighlight, m_penDarkGrey);
}
void wxStdRenderer::DrawStaticBorder(wxDC& dc, wxRect *rect)
{
DrawShadedRect(dc, rect, m_penDarkGrey, m_penHighlight);
}
void wxStdRenderer::DrawExtraBorder(wxDC& dc, wxRect *rect)
{
DrawRect(dc, rect, m_penLightGrey);
}
void wxStdRenderer::DrawBorder(wxDC& dc,
wxBorder border,
const wxRect& rectTotal,
int WXUNUSED(flags),
wxRect *rectIn)
{
wxRect rect = rectTotal;
switch ( border )
{
case wxBORDER_SUNKEN:
case wxBORDER_THEME:
DrawSunkenBorder(dc, &rect);
break;
// wxBORDER_DOUBLE and wxBORDER_THEME are currently the same value.
#if 0
case wxBORDER_DOUBLE:
DrawAntiSunkenBorder(dc, &rect);
DrawExtraBorder(dc, &rect);
break;
#endif
case wxBORDER_STATIC:
DrawStaticBorder(dc, &rect);
break;
case wxBORDER_RAISED:
DrawRaisedBorder(dc, &rect);
break;
case wxBORDER_SIMPLE:
DrawRect(dc, &rect, m_penBlack);
break;
default:
wxFAIL_MSG(wxT("unknown border type"));
// fall through
case wxBORDER_DEFAULT:
case wxBORDER_NONE:
break;
}
if ( rectIn )
*rectIn = rect;
}
wxRect wxStdRenderer::GetBorderDimensions(wxBorder border) const
{
wxCoord width;
switch ( border )
{
case wxBORDER_SIMPLE:
case wxBORDER_STATIC:
width = 1;
break;
case wxBORDER_RAISED:
case wxBORDER_SUNKEN:
case wxBORDER_THEME:
width = 2;
break;
#if 0
case wxBORDER_DOUBLE:
width = 3;
break;
#endif
default:
wxFAIL_MSG(wxT("unknown border type"));
// fall through
case wxBORDER_DEFAULT:
case wxBORDER_NONE:
width = 0;
break;
}
wxRect rect;
rect.x =
rect.y =
rect.width =
rect.height = width;
return rect;
}
void wxStdRenderer::AdjustSize(wxSize *size, const wxWindow *window)
{
// take into account the border width
wxRect rectBorder = GetBorderDimensions(window->GetBorder());
size->x += rectBorder.x + rectBorder.width;
size->y += rectBorder.y + rectBorder.height;
}
bool wxStdRenderer::AreScrollbarsInsideBorder() const
{
return false;
}
wxCoord wxStdRenderer::GetListboxItemHeight(wxCoord fontHeight)
{
return fontHeight + 2*ITEM_MARGIN;
}
void wxStdRenderer::DrawTextBorder(wxDC& dc,
wxBorder border,
const wxRect& rect,
int flags,
wxRect *rectIn)
{
DrawBorder(dc, border, rect, flags, rectIn);
}
// ----------------------------------------------------------------------------
// lines and boxes
// ----------------------------------------------------------------------------
void
wxStdRenderer::DrawHorizontalLine(wxDC& dc, wxCoord y, wxCoord x1, wxCoord x2)
{
dc.SetPen(m_penDarkGrey);
dc.DrawLine(x1, y, x2 + 1, y);
dc.SetPen(m_penHighlight);
y++;
dc.DrawLine(x1, y, x2 + 1, y);
}
void
wxStdRenderer::DrawVerticalLine(wxDC& dc, wxCoord x, wxCoord y1, wxCoord y2)
{
dc.SetPen(m_penDarkGrey);
dc.DrawLine(x, y1, x, y2 + 1);
dc.SetPen(m_penHighlight);
x++;
dc.DrawLine(x, y1, x, y2 + 1);
}
void wxStdRenderer::DrawFrameWithoutLabel(wxDC& dc,
const wxRect& rectFrame,
const wxRect& rectLabel)
{
// draw left, bottom and right lines entirely
DrawVerticalLine(dc, rectFrame.GetLeft(),
rectFrame.GetTop(), rectFrame.GetBottom() - 2);
DrawHorizontalLine(dc, rectFrame.GetBottom() - 1,
rectFrame.GetLeft(), rectFrame.GetRight());
DrawVerticalLine(dc, rectFrame.GetRight() - 1,
rectFrame.GetTop(), rectFrame.GetBottom() - 1);
// and 2 parts of the top line
DrawHorizontalLine(dc, rectFrame.GetTop(),
rectFrame.GetLeft() + 1, rectLabel.GetLeft());
DrawHorizontalLine(dc, rectFrame.GetTop(),
rectLabel.GetRight(), rectFrame.GetRight() - 2);
}
void wxStdRenderer::DrawFrameWithLabel(wxDC& dc,
const wxString& label,
const wxRect& rectFrame,
const wxRect& rectText,
int flags,
int alignment,
int indexAccel)
{
wxRect rectLabel;
DrawLabel(dc, label, rectText, flags, alignment, indexAccel, &rectLabel);
DrawFrameWithoutLabel(dc, rectFrame, rectLabel);
}
void wxStdRenderer::DrawFrame(wxDC& dc,
const wxString& label,
const wxRect& rect,
int flags,
int alignment,
int indexAccel)
{
wxCoord height = 0; // of the label
wxRect rectFrame = rect;
if ( !label.empty() )
{
// the text should touch the top border of the rect, so the frame
// itself should be lower
dc.GetTextExtent(label, NULL, &height);
rectFrame.y += height / 2;
rectFrame.height -= height / 2;
// we have to draw each part of the frame individually as we can't
// erase the background beyond the label as it might contain some
// pixmap already, so drawing everything and then overwriting part of
// the frame with label doesn't work
// TODO: the +5 shouldn't be hard coded
wxRect rectText;
rectText.x = rectFrame.x + 5;
rectText.y = rect.y;
rectText.width = rectFrame.width - 7; // +2 border width
rectText.height = height;
DrawFrameWithLabel(dc, label, rectFrame, rectText, flags,
alignment, indexAccel);
}
else // no label
{
DrawBoxBorder(dc, &rectFrame);
}
}
void wxStdRenderer::DrawItem(wxDC& dc,
const wxString& label,
const wxRect& rect,
int flags)
{
wxDCTextColourChanger colChanger(dc);
if ( flags & wxCONTROL_SELECTED )
{
colChanger.Set(wxSCHEME_COLOUR(m_scheme, HIGHLIGHT_TEXT));
const wxColour colBg = wxSCHEME_COLOUR(m_scheme, HIGHLIGHT);
dc.SetBrush(colBg);
dc.SetPen(colBg);
dc.DrawRectangle(rect);
}
// horizontal adjustment is arbitrary
wxRect rectText = rect;
rectText.Deflate(2, ITEM_MARGIN);
dc.DrawLabel(label, wxNullBitmap, rectText);
if ( flags & wxCONTROL_FOCUSED )
{
DrawFocusRect(NULL, dc, rect, flags);
}
}
void wxStdRenderer::DrawCheckItemBitmap(wxDC& dc,
const wxBitmap& bitmap,
const wxRect& rect,
int flags)
{
DrawCheckButton(dc, wxEmptyString, bitmap, rect, flags);
}
void wxStdRenderer::DrawCheckItem(wxDC& dc,
const wxString& label,
const wxBitmap& bitmap,
const wxRect& rect,
int flags)
{
wxRect rectBitmap = rect;
rectBitmap.width = GetCheckBitmapSize().x;
DrawCheckItemBitmap(dc, bitmap, rectBitmap, flags);
wxRect rectLabel = rect;
wxCoord shift = rectBitmap.width + 2*GetCheckItemMargin();
rectLabel.x += shift;
rectLabel.width -= shift;
DrawItem(dc, label, rectLabel, flags);
}
// ----------------------------------------------------------------------------
// check and radio bitmaps
// ----------------------------------------------------------------------------
void wxStdRenderer::DrawCheckButton(wxDC& dc,
const wxString& label,
const wxBitmap& bitmap,
const wxRect& rect,
int flags,
wxAlignment align,
int indexAccel)
{
if (bitmap.IsOk())
DrawCheckOrRadioButton(dc, label, bitmap, rect, flags, align, indexAccel);
else
DrawCheckOrRadioButton(dc, label, GetCheckBitmap(flags), rect, flags, align, indexAccel);
}
void wxStdRenderer::DrawRadioButton(wxDC& dc,
const wxString& label,
const wxBitmap& bitmap,
const wxRect& rect,
int flags,
wxAlignment align,
int indexAccel)
{
if (bitmap.IsOk())
DrawCheckOrRadioButton(dc, label, bitmap, rect, flags, align, indexAccel);
else
DrawCheckOrRadioButton(dc, label, GetRadioBitmap(flags), rect, flags, align, indexAccel);
}
void wxStdRenderer::DrawCheckOrRadioButton(wxDC& dc,
const wxString& label,
const wxBitmap& bitmap,
const wxRect& rect,
int flags,
wxAlignment align,
int indexAccel)
{
// calculate the position of the bitmap and of the label
wxCoord heightBmp = bitmap.GetHeight();
wxCoord xBmp,
yBmp = rect.y + (rect.height - heightBmp) / 2;
wxRect rectLabel;
dc.GetMultiLineTextExtent(label, NULL, &rectLabel.height);
rectLabel.y = rect.y + (rect.height - rectLabel.height) / 2;
// align label vertically with the bitmap - looks nicer like this
rectLabel.y -= (rectLabel.height - heightBmp) % 2;
// calc horz position
if ( align == wxALIGN_RIGHT )
{
xBmp = rect.GetRight() - bitmap.GetWidth();
rectLabel.x = rect.x + 3;
rectLabel.SetRight(xBmp);
}
else // normal (checkbox to the left of the text) case
{
xBmp = rect.x;
rectLabel.x = xBmp + bitmap.GetWidth() + 5;
rectLabel.SetRight(rect.GetRight());
}
dc.DrawBitmap(bitmap, xBmp, yBmp, true /* use mask */);
DrawLabel(dc, label, rectLabel, flags,
wxALIGN_LEFT | wxALIGN_TOP, indexAccel);
}
#if wxUSE_TEXTCTRL
void wxStdRenderer::DrawTextLine(wxDC& dc,
const wxString& text,
const wxRect& rect,
int selStart,
int selEnd,
int flags)
{
if ( (selStart == -1) || !(flags & wxCONTROL_FOCUSED) )
{
// just draw it as is
dc.DrawText(text, rect.x, rect.y);
}
else // we have selection
{
wxCoord width,
x = rect.x;
// draw the part before selection
wxString s(text, (size_t)selStart);
if ( !s.empty() )
{
dc.DrawText(s, x, rect.y);
dc.GetTextExtent(s, &width, NULL);
x += width;
}
// draw the selection itself
s = wxString(text.c_str() + selStart, text.c_str() + selEnd);
if ( !s.empty() )
{
wxColour colFg = dc.GetTextForeground(),
colBg = dc.GetTextBackground();
dc.SetTextForeground(wxSCHEME_COLOUR(m_scheme, HIGHLIGHT_TEXT));
dc.SetTextBackground(wxSCHEME_COLOUR(m_scheme, HIGHLIGHT));
dc.SetBackgroundMode(wxSOLID);
dc.DrawText(s, x, rect.y);
dc.GetTextExtent(s, &width, NULL);
x += width;
dc.SetBackgroundMode(wxTRANSPARENT);
dc.SetTextBackground(colBg);
dc.SetTextForeground(colFg);
}
// draw the final part
s = text.c_str() + selEnd;
if ( !s.empty() )
{
dc.DrawText(s, x, rect.y);
}
}
}
void wxStdRenderer::DrawLineWrapMark(wxDC& WXUNUSED(dc),
const wxRect& WXUNUSED(rect))
{
// nothing by default
}
int wxStdRenderer::GetTextBorderWidth(const wxTextCtrl * WXUNUSED(text)) const
{
return 1;
}
wxRect
wxStdRenderer::GetTextTotalArea(const wxTextCtrl *text, const wxRect& rect) const
{
wxRect rectTotal = rect;
rectTotal.Inflate(GetTextBorderWidth(text));
return rectTotal;
}
wxRect wxStdRenderer::GetTextClientArea(const wxTextCtrl *text,
const wxRect& rect,
wxCoord *extraSpaceBeyond) const
{
wxRect rectText = rect;
rectText.Deflate(GetTextBorderWidth(text));
if ( extraSpaceBeyond )
*extraSpaceBeyond = 0;
return rectText;
}
#endif // wxUSE_TEXTCTRL
// ----------------------------------------------------------------------------
// scrollbars drawing
// ----------------------------------------------------------------------------
void wxStdRenderer::DrawScrollbarArrow(wxDC& dc,
wxDirection dir,
const wxRect& rect,
int flags)
{
DrawArrow(dc, dir, rect, flags);
}
void wxStdRenderer::DrawScrollCorner(wxDC& dc, const wxRect& rect)
{
DrawSolidRect(dc, wxSCHEME_COLOUR(m_scheme, CONTROL), rect);
}
// ----------------------------------------------------------------------------
// status bar
// ----------------------------------------------------------------------------
#if wxUSE_STATUSBAR
wxSize wxStdRenderer::GetStatusBarBorders() const
{
// Rendered border may be different depending on field's style, we use
// the largest value so that any field certainly fits into the borders
// we return:
wxRect raised = GetBorderDimensions(wxBORDER_RAISED);
wxRect flat = GetBorderDimensions(wxBORDER_STATIC);
wxASSERT_MSG( raised.x == raised.width && raised.y == raised.height &&
flat.x == flat.width && flat.y == flat.height,
wxT("this code expects uniform borders, you must override GetStatusBarBorders") );
// take the larger of flat/raised values:
wxSize border(wxMax(raised.x, flat.x), wxMax(raised.y, flat.y));
return border;
}
wxCoord wxStdRenderer::GetStatusBarBorderBetweenFields() const
{
return 2;
}
wxSize wxStdRenderer::GetStatusBarFieldMargins() const
{
return wxSize(2, 2);
}
void wxStdRenderer::DrawStatusField(wxDC& dc,
const wxRect& rect,
const wxString& label,
int flags,
int style)
{
wxRect rectIn;
if ( style == wxSB_RAISED )
DrawBorder(dc, wxBORDER_RAISED, rect, flags, &rectIn);
else if ( style != wxSB_FLAT )
DrawBorder(dc, wxBORDER_STATIC, rect, flags, &rectIn);
else
rectIn = rect;
rectIn.Deflate(GetStatusBarFieldMargins());
wxDCClipper clipper(dc, rectIn);
DrawLabel(dc, label, rectIn, flags, wxALIGN_LEFT | wxALIGN_CENTRE_VERTICAL);
}
#endif // wxUSE_STATUSBAR
// ----------------------------------------------------------------------------
// top level windows
// ----------------------------------------------------------------------------
int wxStdRenderer::HitTestFrame(const wxRect& rect, const wxPoint& pt, int flags) const
{
wxRect client = GetFrameClientArea(rect, flags);
if ( client.Contains(pt) )
return wxHT_TOPLEVEL_CLIENT_AREA;
if ( flags & wxTOPLEVEL_TITLEBAR )
{
wxRect client = GetFrameClientArea(rect, flags & ~wxTOPLEVEL_TITLEBAR);
if ( flags & wxTOPLEVEL_ICON )
{
if ( wxRect(client.GetPosition(), GetFrameIconSize()).Contains(pt) )
return wxHT_TOPLEVEL_ICON;
}
wxRect btnRect(client.GetRight() - 2 - FRAME_BUTTON_WIDTH,
client.GetTop() + (FRAME_TITLEBAR_HEIGHT-FRAME_BUTTON_HEIGHT)/2,
FRAME_BUTTON_WIDTH, FRAME_BUTTON_HEIGHT);
if ( flags & wxTOPLEVEL_BUTTON_CLOSE )
{
if ( btnRect.Contains(pt) )
return wxHT_TOPLEVEL_BUTTON_CLOSE;
btnRect.x -= FRAME_BUTTON_WIDTH + 2;
}
if ( flags & wxTOPLEVEL_BUTTON_MAXIMIZE )
{
if ( btnRect.Contains(pt) )
return wxHT_TOPLEVEL_BUTTON_MAXIMIZE;
btnRect.x -= FRAME_BUTTON_WIDTH;
}
if ( flags & wxTOPLEVEL_BUTTON_RESTORE )
{
if ( btnRect.Contains(pt) )
return wxHT_TOPLEVEL_BUTTON_RESTORE;
btnRect.x -= FRAME_BUTTON_WIDTH;
}
if ( flags & wxTOPLEVEL_BUTTON_ICONIZE )
{
if ( btnRect.Contains(pt) )
return wxHT_TOPLEVEL_BUTTON_ICONIZE;
btnRect.x -= FRAME_BUTTON_WIDTH;
}
if ( flags & wxTOPLEVEL_BUTTON_HELP )
{
if ( btnRect.Contains(pt) )
return wxHT_TOPLEVEL_BUTTON_HELP;
btnRect.x -= FRAME_BUTTON_WIDTH;
}
if ( pt.y >= client.y && pt.y < client.y + FRAME_TITLEBAR_HEIGHT )
return wxHT_TOPLEVEL_TITLEBAR;
}
if ( (flags & wxTOPLEVEL_BORDER) && !(flags & wxTOPLEVEL_MAXIMIZED) )
{
// we are certainly at one of borders, let's decide which one:
int border = 0;
// dirty trick, relies on the way wxHT_TOPLEVEL_XXX are defined!
if ( pt.x < client.x )
border |= wxHT_TOPLEVEL_BORDER_W;
else if ( pt.x >= client.width + client.x )
border |= wxHT_TOPLEVEL_BORDER_E;
if ( pt.y < client.y )
border |= wxHT_TOPLEVEL_BORDER_N;
else if ( pt.y >= client.height + client.y )
border |= wxHT_TOPLEVEL_BORDER_S;
return border;
}
return wxHT_NOWHERE;
}
void wxStdRenderer::DrawFrameTitleBar(wxDC& dc,
const wxRect& rect,
const wxString& title,
const wxIcon& icon,
int flags,
int specialButton,
int specialButtonFlags)
{
if ( (flags & wxTOPLEVEL_BORDER) && !(flags & wxTOPLEVEL_MAXIMIZED) )
{
DrawFrameBorder(dc, rect, flags);
}
if ( flags & wxTOPLEVEL_TITLEBAR )
{
DrawFrameBackground(dc, rect, flags);