forked from pyscripter/pyscripter
-
Notifications
You must be signed in to change notification settings - Fork 0
/
cThemedVirtualStringTree.pas
255 lines (231 loc) · 9.12 KB
/
cThemedVirtualStringTree.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
{-----------------------------------------------------------------------------
Unit Name: cThemedVirtualStringTree
Author: Kiriakos
Date: 06-March-2012
Purpose: SpTBXLib themeing of TVirtualStringTree
History:
-----------------------------------------------------------------------------}
unit cThemedVirtualStringTree;
interface
uses
Types, Windows, Classes, Graphics, VirtualTrees, VirtualTrees.Utils,
SpTBXSkins;
type
TThemedVirtualStringTree = class helper for TCustomVirtualStringTree
private
procedure VirtualStringTreeAdvancedHeaderDraw(Sender: TVTHeader;
var PaintInfo: THeaderPaintInfo; const Elements: THeaderPaintElements);
procedure VirtualStringTreeDrawQueryElements(
Sender: TVTHeader; var PaintInfo: THeaderPaintInfo;
var Elements: THeaderPaintElements);
procedure VirtualStringTreeBeforeCellPaint(Sender: TBaseVirtualTree;
TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
CellPaintMode: TVTCellPaintMode; CellRect: TRect; var ContentRect: TRect);
procedure VirtualStringTreePaintText(Sender: TBaseVirtualTree;
const TargetCanvas: TCanvas; Node: PVirtualNode; Column: TColumnIndex;
TextType: TVSTTextType);
public
procedure SkinTree;
procedure ReinitInitializedNode(Node: PVirtualNode; Recursive: Boolean);
procedure ReinitInitializedChildren(Node: PVirtualNode; Recursive: Boolean);
end;
implementation
Uses
dmCommands;
type
// to help us access protected methods
TCrackedCustomStringTreeOptions = class(TCustomStringTreeOptions)
end;
TCrackedVirtualStringTree = class(TCustomVirtualStringTree)
end;
{ TThemedVirtualStringTree }
procedure TThemedVirtualStringTree.ReinitInitializedChildren(Node: PVirtualNode;
Recursive: Boolean);
// Forces all child nodes of Node to be reinitialized.
// If Recursive is True then also the grandchildren are reinitialized.
// Modified version to reinitialize only when the node is already initialized
var
Run: PVirtualNode;
begin
if Assigned(Node) then
begin
TCrackedVirtualStringTree(Self).InitChildren(Node);
Run := Node.FirstChild;
end
else
begin
TCrackedVirtualStringTree(Self).InitChildren(RootNode);
Run := RootNode.FirstChild;
end;
while Assigned(Run) do
begin
if vsInitialized in Run.States then
ReinitInitializedNode(Run, Recursive);
Run := Run.NextSibling;
end;
end;
procedure TThemedVirtualStringTree.ReinitInitializedNode(Node: PVirtualNode;
Recursive: Boolean);
// Forces the given node and all its children (if recursive is True) to be initialized again without
// modifying any data in the nodes nor deleting children (unless the application requests a different amount).
begin
if Assigned(Node) and (Node <> RootNode) and (vsInitialized in Node.States) then
begin
// Remove dynamic styles.
Node.States := Node.States - [vsChecking, vsCutOrCopy, vsDeleting, vsHeightMeasured];
TCrackedVirtualStringTree(self).InitNode(Node);
end;
if Recursive and (not Assigned(Node) or Assigned(Node) and (vsInitialized in Node.States)) then
ReinitInitializedChildren(Node, True);
end;
procedure TThemedVirtualStringTree.SkinTree;
begin
TreeOptions.PaintOptions := TreeOptions.PaintOptions + [toThemeAware, toUseExplorerTheme];
if SkinManager.GetSkinType = sknSkin then
begin
OnAdvancedHeaderDraw := VirtualStringTreeAdvancedHeaderDraw;
OnHeaderDrawQueryElements := VirtualStringTreeDrawQueryElements;
OnBeforeCellPaint := VirtualStringTreeBeforeCellPaint;
OnPaintText := VirtualStringTreePaintText;
end else begin
OnAdvancedHeaderDraw := nil;
OnHeaderDrawQueryElements := nil;
OnBeforeCellPaint := nil;
OnPaintText := nil;
end;
if Assigned(Header) then
Header.Invalidate(nil, True);
Invalidate;
// Cannot remember why this was needed.
// if SkinManager.GetSkinType in [sknNone, sknWindows] then
// TreeOptions.PaintOptions := TreeOptions.PaintOptions - [toAlwaysHideSelection]
// else
// TreeOptions.PaintOptions := TreeOptions.PaintOptions + [toAlwaysHideSelection];
end;
procedure TThemedVirtualStringTree.VirtualStringTreeAdvancedHeaderDraw(
Sender: TVTHeader; var PaintInfo: THeaderPaintInfo;
const Elements: THeaderPaintElements);
Var
R : TRect;
State: TSpTBXSkinStatesType;
DrawFormat: Cardinal;
Text : string;
TextSpace: Integer;
Size: TSize;
DC : HDC;
begin
with PaintInfo do begin
State := CurrentSkin.GetState(IsEnabled, IsDownIndex, IsHoverIndex, False);
if ShowSortGlyph and not(IsHoverIndex or IsDownIndex) then
State := sknsChecked;
end;
if hpeBackground in Elements then begin
R := PaintInfo.PaintRectangle;
if (PaintInfo.Column = nil) then begin
SpDrawXPHeader(PaintInfo.TargetCanvas, R, False, False);
end else with PaintInfo do begin
SpDrawXPHeader(PaintInfo.TargetCanvas, R, IsHoverIndex, IsDownIndex);
end;
end;
if (hpeText in Elements) and Assigned(PaintInfo.Column) then begin
R := PaintInfo.TextRectangle;
DC := PaintInfo.TargetCanvas.Handle;
Text := PaintInfo.Column.Text;
GetTextExtentPoint32W(DC, PWideChar(Text), Length(Text), Size);
TextSpace := R.Right - R.Left;
if TextSpace < Size.cx then
Text := ShortenString(DC, Text, TextSpace);
SetTextColor(DC, ColorToRGB(CurrentSkin.GetTextColor(skncHeader, State)));
DrawFormat := DT_LEFT or DT_TOP or DT_NOPREFIX;
if Sender.TreeView.UseRightToLeftReading then
DrawFormat := DrawFormat + DT_RTLREADING;
SetBkMode(DC, TRANSPARENT);
Windows.DrawTextW(DC, PWideChar(Text), Length(Text), R, DrawFormat);
end;
end;
procedure TThemedVirtualStringTree.VirtualStringTreeBeforeCellPaint(
Sender: TBaseVirtualTree; TargetCanvas: TCanvas; Node: PVirtualNode;
Column: TColumnIndex; CellPaintMode: TVTCellPaintMode; CellRect: TRect;
var ContentRect: TRect);
Var
InnerRect, R: TRect;
NodeWidth : integer;
CurrentAlignment: TAlignment;
begin
if SkinManager.IsDefaultSkin then Exit;
if CellPaintMode <> cpmPaint then Exit;
with TCustomVirtualStringTree(Sender), TargetCanvas do begin
if (Column = FocusedColumn) or
(toFullRowSelect in TCrackedCustomStringTreeOptions(TreeOptions).SelectionOptions)
then
begin
if (vsSelected in Node.States) or (Node = HotNode) then
begin
if (toGridExtensions in TCrackedCustomStringTreeOptions(TreeOptions).MiscOptions) or
(toFullRowSelect in TCrackedCustomStringTreeOptions(TreeOptions).SelectionOptions)
then
InnerRect := CellRect
else begin
InnerRect:= ContentRect;
R := GetDisplayRect(Node, Column, True);
NodeWidth := R.Right - R.Left;
if Column <= NoColumn then
CurrentAlignment := Alignment
else
CurrentAlignment := Header.Columns[Column].Alignment;
case CurrentAlignment of
taLeftJustify:
with InnerRect do
if Left + NodeWidth < Right then
Right := Left + NodeWidth;
taCenter:
with InnerRect do
if (Right - Left) > NodeWidth then
begin
Left := (Left + Right - NodeWidth) div 2;
Right := Left + NodeWidth;
end;
taRightJustify:
with InnerRect do
if (Right - Left) > NodeWidth then
Left := Right - NodeWidth;
end;
end;
if not IsRectEmpty(InnerRect) then begin
TargetCanvas.FillRect(InnerRect);
SpDrawXPListItemBackground(TargetCanvas, InnerRect, vsSelected in Node.States, Node = HotNode,
False, True, False);
end;
end;
end;
end;
end;
procedure TThemedVirtualStringTree.VirtualStringTreeDrawQueryElements(
Sender: TVTHeader; var PaintInfo: THeaderPaintInfo;
var Elements: THeaderPaintElements);
begin
if SkinManager.IsDefaultSkin then
Elements := []
else
Elements := [hpeBackground, hpeText];
end;
procedure TThemedVirtualStringTree.VirtualStringTreePaintText(
Sender: TBaseVirtualTree; const TargetCanvas: TCanvas; Node: PVirtualNode;
Column: TColumnIndex; TextType: TVSTTextType);
begin
if SkinManager.IsDefaultSkin then Exit;
with TVirtualStringTree(Sender) do begin
if (Column = FocusedColumn) or (toFullRowSelect in TreeOptions.SelectionOptions) then
begin
if (Node = HotNode) or (vsSelected in Node.States) then
TargetCanvas.Font.Color :=
CurrentSkin.GetTextColor(skncListItem,
CurrentSkin.GetState(True, False, Node = HotNode,
vsSelected in Node.States))
else if CommandsDataModule.PyIDEOptions.UsePythonColorsInIDE and (Color <> clWindow) then
TargetCanvas.Font.Color := CommandsDataModule.SynPythonSyn.IdentifierAttri.Foreground;
end else if CommandsDataModule.PyIDEOptions.UsePythonColorsInIDE and (Color <> clWindow) then
TargetCanvas.Font.Color := CommandsDataModule.SynPythonSyn.IdentifierAttri.Foreground;
end;
end;
end.