Repository navigation
Expand file tree
/
Copy pathNewGroupBox.pas
More file actions
224 lines (201 loc) · 5.87 KB
/
Copy pathNewGroupBox.pas
File metadata and controls
224 lines (201 loc) · 5.87 KB
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
unit NewGroupBox;
{
TNewGroupBox - fixes two TGroupBox bugs when ShowFrame is False.
In Delphi 13.0 and earlier, TCustomGroupBox.Paint has a bug where Details
is not initialized when ShowFrame is False, but is still used to draw the
Text. Embarcadero fixed this in Delphi 13.1 but since we can't detect 13.0
vs 13.1, the fix must be active for 13.1 also.
The VCL Styles hook did not have this bug, so no VCL Styles code needed.
Note: ShowFrame did not exist before Delphi 12.
Another note: This unit actually fixes a second bug which Embarcadero did
not fix, even though it's pretty much the same issue: R.Right is used
without being initialized when ShowFrame is False and RTL is active. This
bug is also not present in the VCL Styles hook.
}
interface
{$IF CompilerVersion >= 36.0}
{$DEFINE FIX}
{$ENDIF}
uses
Vcl.StdCtrls;
type
{$IFDEF FIX}
TNewGroupBox = class(TCustomGroupBox)
protected
procedure Paint; override;
published
property Align;
property Anchors;
property BiDiMode;
property Caption;
property Color;
property Constraints;
property Ctl3D;
property DefaultHeaderFont;
property DockSite;
property DoubleBuffered;
property DoubleBufferedMode;
property DragCursor;
property DragKind;
property DragMode;
property Enabled;
property Font;
property HeaderFont;
property Padding;
property ParentBackground default True;
property ParentBiDiMode;
property ParentColor;
property ParentCtl3D;
property ParentDoubleBuffered;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ShowHint;
property ShowFrame;
property TabOrder;
property TabStop;
property Touch;
property Visible;
property StyleElements;
property StyleName;
property OnAlignInsertBefore;
property OnAlignPosition;
property OnClick;
property OnContextPopup;
property OnDblClick;
property OnDragDrop;
property OnDockDrop;
property OnDockOver;
property OnDragOver;
property OnEndDock;
property OnEndDrag;
property OnEnter;
property OnExit;
property OnGesture;
property OnGetSiteInfo;
property OnMouseActivate;
property OnMouseDown;
property OnMouseEnter;
property OnMouseLeave;
property OnMouseMove;
property OnMouseUp;
property OnStartDock;
property OnStartDrag;
property OnUnDock;
end;
{$ELSE}
TNewGroupBox = class(TGroupBox);
{$ENDIF}
procedure Register;
implementation
uses
{$IFDEF FIX}
Winapi.Windows, System.Classes, System.Types,
{$IFDEF VCLSTYLES} Vcl.Themes, {$ELSE} Themes, {$ENDIF}
Vcl.Graphics, Vcl.Menus;
{$ELSE}
System.Classes;
{$ENDIF}
procedure Register;
begin
RegisterComponents('JR', [TNewGroupBox]);
end;
{ TNewGroupBox }
{$IFDEF FIX}
{ The following is based on Delphi 13.1's TCustomGroupBox.Paint, which fixed
Details not being initialized when ShowFrame is False.
Changes done:
-FShowFrame -> ShowFrame
-Turning off warnings for the implicit integer casts the original code has.
-Fixed R.Right not being initialized when ShowFrame is False. }
{$WARN IMPLICIT_INTEGER_CAST_LOSS OFF}
{$WARN SYMBOL_DEPRECATED OFF}
procedure TNewGroupBox.Paint;
var
H: Integer;
R: TRect;
Flags: Longint;
CaptionRect,
OuterRect: TRect;
Size: TSize;
Box: TThemedButton;
Details: TThemedElementDetails;
LStyle: TCustomStyleServices;
S: string;
TextFormat: TTextFormatFlags;
begin
with Canvas do
begin
Font := HeaderFont;
if ThemeControl(Self) then
begin
LStyle := StyleServices(Self);
if Text <> '' then
begin
S := StripHotkey(Text);
GetTextExtentPoint32(Handle, S, Length(S), Size);
CaptionRect := Rect(0, 0, Size.cx, Size.cy);
if not UseRightToLeftAlignment then
OffsetRect(CaptionRect, 8, 0)
else
OffsetRect(CaptionRect, Width - 8 - CaptionRect.Right, 0);
end
else
CaptionRect := Rect(0, 0, 0, 0);
OuterRect := ClientRect;
OuterRect.Top := (CaptionRect.Bottom - CaptionRect.Top) div 2;
with CaptionRect do
ExcludeClipRect(Handle, Left, Top, Right, Bottom);
if Enabled then
Box := tbGroupBoxNormal
else
Box := tbGroupBoxDisabled;
Details := LStyle.GetElementDetails(Box);
if ShowFrame then
LStyle.DrawElement(Handle, Details, OuterRect);
SelectClipRgn(Handle, 0);
Brush.Style := bsClear;
if Text <> '' then
if IsRightToLeft then
begin
TextFormat := TTextFormatFlags(DrawTextBiDiModeFlags(DT_SINGLELINE));
LStyle.DrawText(Handle, Details, Text, CaptionRect, TextFormat, Font.Color);
end
else
LStyle.DrawText(Handle, Details, Text, CaptionRect, [tfLeft], Font.Color);
end
else
begin
H := TextHeight('0');
R := Rect(0, H div 2 - 1, Width, Height);
if ShowFrame then
begin
if Ctl3D then
begin
Inc(R.Left);
Inc(R.Top);
Brush.Color := clBtnHighlight;
FrameRect(R);
OffsetRect(R, -1, -1);
Brush.Color := clBtnShadow;
end else
Brush.Color := clWindowFrame;
FrameRect(R);
end;
if Text <> '' then
begin
if not UseRightToLeftAlignment then
R := Rect(8, 0, 0, H)
else
R := Rect(R.Right - Canvas.TextWidth(Text) - 8, 0, 0, H);
Flags := DrawTextBiDiModeFlags(DT_SINGLELINE);
DrawText(Handle, Text, Length(Text), R, Flags or DT_CALCRECT);
Brush.Color := Color;
DrawText(Handle, Text, Length(Text), R, Flags);
end;
end;
end;
end;
{$WARN SYMBOL_DEPRECATED ON}
{$ENDIF}
end.