-
Notifications
You must be signed in to change notification settings - Fork 261
/
Copy pathVirtualTrees.Colors.pas
274 lines (244 loc) · 11.5 KB
/
VirtualTrees.Colors.pas
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
unit VirtualTrees.Colors;
interface
uses
System.Classes,
Vcl.Graphics,
Vcl.Themes,
Vcl.Controls;
type
//class to collect all switchable colors into one place
TVTColors = class(TPersistent)
private type
TVTColorEnum = (
cDisabledColor
, cDropMarkColor
, cDropTargetColor
, cFocusedSelectionColor
, cGridLineColor
, cTreeLineColor
, cUnfocusedSelectionColor
, cBorderColor
, cHotColor
, cFocusedSelectionBorderColor
, cUnfocusedSelectionBorderColor
, cDropTargetBorderColor
, cSelectionRectangleBlendColor
, cSelectionRectangleBorderColor
, cHeaderHotColor
, cSelectionTextColor
, cUnfocusedColor
);
//Please make sure that the published Color properties at the corresponding index
//have the same color if you change anything here!
const
cDefaultColors : array [TVTColorEnum] of TColor = (
clBtnShadow, //DisabledColor
clHighlight, //DropMarkColor
clHighlight, //DropTargetColor
clHighlight, //FocusedSelectionColor
clBtnFace, //GridLineColor
clBtnShadow, //TreeLineColor
clInactiveCaption, //UnfocusedSelectionColor
clBtnFace, //BorderColor
clWindowText, //HotColor
clHighlight, //FocusedSelectionBorderColor
clInactiveCaption, //UnfocusedSelectionBorderColor
clHighlight, //DropTargetBorderColor
clHighlight, //SelectionRectangleBlendColor
clHighlight, //SelectionRectangleBorderColor
clBtnShadow, //HeaderHotColor
clHighlightText, //SelectionTextColor
clInactiveCaptionText //UnfocusedColor [IPK]
);
private
FOwner : TCustomControl;
FColors : array [TVTColorEnum] of TColor; //[IPK] 15 -> 16
function GetColor(const Index : TVTColorEnum) : TColor;
procedure SetColor(const Index : TVTColorEnum; const Value : TColor);
function GetBackgroundColor : TColor;
function GetHeaderFontColor : TColor;
function GetNodeFontColor : TColor;
public
constructor Create(AOwner : TCustomControl);
procedure Assign(Source : TPersistent); override;
function GetSelectedNodeFontColor(Focused : boolean) : TColor;
property BackGroundColor : TColor read GetBackgroundColor;
property HeaderFontColor : TColor read GetHeaderFontColor;
property NodeFontColor : TColor read GetNodeFontColor;
//Mitigator function to use the correct style service for this context (either the style assigned to the control for Delphi > 10.4 or the application style)
function StyleServices(AControl : TControl = nil) : TCustomStyleServices;
published
property BorderColor : TColor index cBorderColor read GetColor write SetColor default clBtnFace;
property DisabledColor : TColor index cDisabledColor read GetColor write SetColor default clBtnShadow;
property DropMarkColor : TColor index cDropMarkColor read GetColor write SetColor default clHighlight;
property DropTargetColor : TColor index cDropTargetColor read GetColor write SetColor default clHighlight;
property DropTargetBorderColor : TColor index cDropTargetBorderColor read GetColor write SetColor default clHighlight;
///The background color of selected nodes in case the tree has the focus, or the toPopupMode flag is set.
property FocusedSelectionColor : TColor index cFocusedSelectionColor read GetColor write SetColor default clHighlight;
///The border color of selected nodes when the tree has the focus.
property FocusedSelectionBorderColor : TColor index cFocusedSelectionBorderColor read GetColor write SetColor default clHighlight;
///The color of the grid lines
property GridLineColor : TColor index cGridLineColor read GetColor write SetColor default clBtnFace;
property HeaderHotColor : TColor index cHeaderHotColor read GetColor write SetColor default clBtnShadow;
property HotColor : TColor index cHotColor read GetColor write SetColor default clWindowText;
property SelectionRectangleBlendColor : TColor index cSelectionRectangleBlendColor read GetColor write SetColor default clHighlight;
property SelectionRectangleBorderColor : TColor index cSelectionRectangleBorderColor read GetColor write SetColor default clHighlight;
///The text color of selected nodes
property SelectionTextColor : TColor index cSelectionTextColor read GetColor write SetColor default clHighlightText;
property TreeLineColor : TColor index cTreeLineColor read GetColor write SetColor default clBtnShadow;
property UnfocusedColor : TColor index cUnfocusedColor read GetColor write SetColor default clInactiveCaptionText; //[IPK] Added
///The background color of selected nodes in case the tree does not have the focus and the toPopupMode flag is not set.
property UnfocusedSelectionColor : TColor index cUnfocusedSelectionColor read GetColor write SetColor default clInactiveCaption;
///The border color of selected nodes in case the tree does not have the focus and the toPopupMode flag is not set.
property UnfocusedSelectionBorderColor : TColor index cUnfocusedSelectionBorderColor read GetColor write SetColor default clInactiveCaption;
end;
implementation
uses
WinApi.Windows,
VirtualTrees.Types,
VirtualTrees.Utils,
VirtualTrees.StyleHooks,
VirtualTrees.BaseTree;
type
TBaseVirtualTreeCracker = class(TBaseVirtualTree);
TVTColorsHelper = class helper for TVTColors
function TreeView : TBaseVirtualTreeCracker;
end;
//----------------- TVTColors ------------------------------------------------------------------------------------------
constructor TVTColors.Create(AOwner : TCustomControl);
var
CE : TVTColorEnum;
begin
FOwner := AOwner;
for CE := Low(TVTColorEnum) to High(TVTColorEnum) do
FColors[CE] := cDefaultColors[CE];
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTColors.GetBackgroundColor : TColor;
begin
//XE2 VCL Style
if TreeView.VclStyleEnabled and (seClient in FOwner.StyleElements) then
Result := StyleServices.GetStyleColor(scTreeView)
else
Result := TreeView.Color;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTColors.GetColor(const Index : TVTColorEnum) : TColor;
begin
//Only try to fetch the color via StyleServices if theses are enabled
//Return default/user defined color otherwise
if not (csDesigning in TreeView.ComponentState) { see issue #1185 } and TreeView.VclStyleEnabled then
begin
//If the ElementDetails are not defined, fall back to the SystemColor
case Index of
cDisabledColor :
if not StyleServices.GetElementColor(StyleServices.GetElementDetails(ttItemDisabled), ecTextColor, Result) then
Result := StyleServices.GetSystemColor(FColors[Index]);
cTreeLineColor :
if not StyleServices.GetElementColor(StyleServices.GetElementDetails(ttBranch), ecBorderColor, Result) then
Result := StyleServices.GetSystemColor(FColors[Index]);
cBorderColor :
if (seBorder in FOwner.StyleElements) then
Result := StyleServices.GetSystemColor(FColors[Index])
else
Result := FColors[Index];
cHotColor :
if not StyleServices.GetElementColor(StyleServices.GetElementDetails(ttItemHot), ecTextColor, Result) then
Result := StyleServices.GetSystemColor(FColors[Index]);
cHeaderHotColor :
if not StyleServices.GetElementColor(StyleServices.GetElementDetails(thHeaderItemHot), ecTextColor, Result) then
Result := StyleServices.GetSystemColor(FColors[Index]);
cSelectionTextColor :
if not StyleServices.GetElementColor(StyleServices.GetElementDetails(ttItemSelected), ecTextColor, Result) then
Result := StyleServices.GetSystemColor(clHighlightText);
cUnfocusedColor :
if not StyleServices.GetElementColor(StyleServices.GetElementDetails(ttItemSelectedNotFocus), ecTextColor, Result) then
Result := StyleServices.GetSystemColor(FColors[Index]);
else
Result := StyleServices.GetSystemColor(FColors[Index]);
end;
end
else
Result := FColors[Index];
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTColors.GetHeaderFontColor : TColor;
begin
//XE2+ VCL Style
if TreeView.VclStyleEnabled and (seFont in FOwner.StyleElements) then
StyleServices.GetElementColor(StyleServices.GetElementDetails(thHeaderItemNormal), ecTextColor, Result)
else
Result := TreeView.Header.Font.Color;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTColors.GetNodeFontColor : TColor;
begin
if TreeView.VclStyleEnabled and (seFont in FOwner.StyleElements) then
StyleServices.GetElementColor(StyleServices.GetElementDetails(ttItemNormal), ecTextColor, Result)
else
Result := TreeView.Font.Color;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTColors.GetSelectedNodeFontColor(Focused : boolean) : TColor;
begin
if Focused then
begin
if (tsUseExplorerTheme in TreeView.TreeStates) and not IsHighContrastEnabled then
begin
Result := NodeFontColor
end
else
Result := SelectionTextColor
end//if Focused
else
Result := UnfocusedColor;
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTColors.SetColor(const Index : TVTColorEnum; const Value : TColor);
begin
if FColors[Index] <> Value then
begin
FColors[Index] := Value;
if not (csLoading in FOwner.ComponentState) and FOwner.HandleAllocated then
begin
//Cause helper bitmap rebuild if the button color changed.
case Index of
cTreeLineColor :
begin
TreeView.PrepareBitmaps(True, False);
FOwner.Invalidate;
end;
cBorderColor :
RedrawWindow(FOwner.Handle, nil, 0, RDW_FRAME or RDW_INVALIDATE or RDW_NOERASE or RDW_NOCHILDREN)
else
if not (tsPainting in TreeView.TreeStates) then // See issue #1186
FOwner.Invalidate;
end;//case
end;// if
end;
end;
//----------------------------------------------------------------------------------------------------------------------
function TVTColors.StyleServices(AControl : TControl) : TCustomStyleServices;
begin
if AControl = nil then
AControl := FOwner;
Result := VTStyleServices(AControl);
end;
//----------------------------------------------------------------------------------------------------------------------
procedure TVTColors.Assign(Source : TPersistent);
begin
if Source is TVTColors then
begin
FColors := TVTColors(Source).FColors;
if TreeView.UpdateCount = 0 then
TreeView.Invalidate;
end
else
inherited;
end;
{ TVTColorsHelper }
function TVTColorsHelper.TreeView : TBaseVirtualTreeCracker;
begin
Result := TBaseVirtualTreeCracker(FOwner);
end;
end.