-
Notifications
You must be signed in to change notification settings - Fork 261
/
Copy pathVirtualTrees.Types.pas
1719 lines (1483 loc) · 76.6 KB
/
VirtualTrees.Types.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
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
unit VirtualTrees.Types;
interface
uses
WinApi.ActiveX,
Winapi.Windows,
Winapi.Messages,
System.Types,
System.Classes,
System.SysUtils,
Vcl.Controls,
Vcl.GraphUtil,
Vcl.Themes,
Vcl.Graphics,
Vcl.ImgList,
System.UITypes; // some types moved from Vcl.* to System.UITypes
{$MINENUMSIZE 1, make enumerations as small as possible}
const
VTTreeStreamVersion = 3;
VTHeaderStreamVersion = 6; // The header needs an own stream version to indicate changes only relevant to the header.
CacheThreshold = 2000; // Number of nodes a tree must at least have to start caching and at the same
// time the maximum number of nodes between two cache entries.
FadeAnimationStepCount = 255; // Number of animation steps for hint fading (0..255).
ShadowSize = 5; // Size in pixels of the hint shadow. This value has no influence on Win2K and XP systems
// as those OSes have native shadow support.
cDefaultTextMargin = 4; // The default margin of text
cInitialDefaultNodeHeight= 18; // the default value of the DefualtNodeHeight property
// Special identifiers for columns.
NoColumn = - 1;
InvalidColumn = - 2;
// Indices for check state images used for checking.
ckEmpty = 0; // an empty image used as place holder
// radio buttons
ckRadioUncheckedNormal = 1;
ckRadioUncheckedHot = 2;
ckRadioUncheckedPressed = 3;
ckRadioUncheckedDisabled = 4;
ckRadioCheckedNormal = 5;
ckRadioCheckedHot = 6;
ckRadioCheckedPressed = 7;
ckRadioCheckedDisabled = 8;
// check boxes
ckCheckUncheckedNormal = 9;
ckCheckUncheckedHot = 10;
ckCheckUncheckedPressed = 11;
ckCheckUncheckedDisabled = 12;
ckCheckCheckedNormal = 13;
ckCheckCheckedHot = 14;
ckCheckCheckedPressed = 15;
ckCheckCheckedDisabled = 16;
ckCheckMixedNormal = 17;
ckCheckMixedHot = 18;
ckCheckMixedPressed = 19;
ckCheckMixedDisabled = 20;
// simple button
ckButtonNormal = 21;
ckButtonHot = 22;
ckButtonPressed = 23;
ckButtonDisabled = 24;
// Instead using a TTimer class for each of the various events I use Windows timers with messages
// as this is more economical.
ExpandTimer = 1;
EditTimer = 2;
HeaderTimer = 3;
ScrollTimer = 4;
ChangeTimer = 5;
StructureChangeTimer = 6;
SearchTimer = 7;
ThemeChangedTimer = 8;
ThemeChangedTimerDelay = 500;
// Virtual Treeview does not need to be subclassed by an eventual Theme Manager instance as it handles
// Windows XP theme painting itself. Hence the special message is used to prevent subclassing.
CM_DENYSUBCLASSING = CM_BASE + 2000;
// Decoupling message for auto-adjusting the internal edit window.
CM_AUTOADJUST = CM_BASE + 2005;
// Drag image helpers for Windows 2000 and up.
IID_IDropTargetHelper : TGUID = (D1 : $4657278B; D2 : $411B; D3 : $11D2; D4 : ($83, $9A, $00, $C0, $4F, $D9, $18, $D0));
IID_IDragSourceHelper : TGUID = (D1 : $DE5BF786; D2 : $477A; D3 : $11D2; D4 : ($83, $9D, $00, $C0, $4F, $D9, $18, $D0));
IID_IDropTarget : TGUID = (D1 : $00000122; D2 : $0000; D3 : $0000; D4 : ($C0, $00, $00, $00, $00, $00, $00, $46));
// VT's own clipboard formats,
// Note: The reference format is used internally to allow to link to a tree reference
// to implement optimized moves and other back references.
CFSTR_VIRTUALTREE = 'Virtual Tree Data';
CFSTR_VTREFERENCE = 'Virtual Tree Reference';
CFSTR_VTHEADERREFERENCE = 'Virtual Tree Header Reference';
CFSTR_HTML = 'HTML Format';
CFSTR_RTF = 'Rich Text Format';
CFSTR_RTFNOOBJS = 'Rich Text Format Without Objects';
CFSTR_CSV = 'CSV';
// Help identifiers for exceptions. Application developers are responsible to link them with actual help topics.
hcTFEditLinkIsNil = 2000;
hcTFWrongMoveError = 2001;
hcTFWrongStreamFormat = 2002;
hcTFWrongStreamVersion = 2003;
hcTFStreamTooSmall = 2004;
hcTFCorruptStream1 = 2005;
hcTFCorruptStream2 = 2006;
hcTFClipboardFailed = 2007;
hcTFCannotSetUserData = 2008;
// Header standard split cursor.
crHeaderSplit = crHSplit deprecated 'Use vrHSplit instead';
// Height changing cursor.
crVertSplit = crVSplit deprecated 'Use vrVSplit instead';
// chunk IDs
NodeChunk = 1;
BaseChunk = 2; // chunk containing node state, check state, child node count etc.
// this chunk is immediately followed by all child nodes
CaptionChunk = 3; // used by the string tree to store a node's caption
UserChunk = 4; // used for data supplied by the application
type
{$IFDEF VT_FMX}
TDimension = Single;
PDimension = ^Single;
TNodeHeight = Single;
TVTCursor = TCursor;
TVTDragDataObject = TDragObject;
TVTBackground = TBitmap;
TVTPaintContext = TCanvas;
TVTBrush = TBrush;
{$ELSE}
TDimension = Integer; // Introduced for Firemonkey support, see #841
PDimension = ^Integer;
TNodeHeight = NativeInt;
TVTCursor = HCURSOR;
IDataObject= WinApi.ActiveX.IDataObject;
TVTDragDataObject = IDataObject;
TVTBackground = TPicture;
TVTPaintContext = HDC;
TVTBrush = HBRUSH;
{$ENDIF}
TColumnIndex = {$if CompilerVersion < 36} type {$endif} Integer; // See issue #1276
TColumnPosition = type Cardinal;
PCardinal = ^Cardinal;
// The exception used by the trees.
EVirtualTreeError = class(Exception);
// Limits the speed interval which can be used for auto scrolling (milliseconds).
TAutoScrollInterval = 1 .. 1000;
TVTScrollIncrement = 1 .. 10000;
// OLE drag'n drop support
TFormatEtcArray = array of TFormatEtc;
TFormatArray = array of Word;
// See issue #1270.
// Taken from: https://learn.microsoft.com/en-us/windows/win32/menurc/about-cursors
// To be used with: LoadCursor(0, MAKEINTRESOURCE(TPanningCursor.MoveAll))
TPanningCursor = (
MoveAll = 32654,
MoveNS = 32652,
MoveEW = 32653,
MoveN = 32655,
MoveNE = 32660,
MoveE = 32658,
MoveSE = 32662,
MoveS = 32656,
MoveSW = 32661,
MoveW = 32657,
MoveNW = 32659
);
TSmartAutoFitType = (
smaAllColumns, // consider nodes in view only for all columns
smaNoColumn, // consider nodes in view only for no column
smaUseColumnOption // use coSmartResize of the corresponding column
); // describes the used column resize behaviour for AutoFitColumns
TAddPopupItemType = (
apNormal,
apDisabled,
apHidden
);
TCheckType = (
ctNone,
ctTriStateCheckBox,
ctCheckBox,
ctRadioButton,
ctButton
);
// The check states include both, transient and fluent (temporary) states. The only temporary state defined so
// far is the pressed state.
TCheckState = (
csUncheckedNormal, // unchecked and not pressed
csUncheckedPressed, // unchecked and pressed
csCheckedNormal, // checked and not pressed
csCheckedPressed, // checked and pressed
csMixedNormal, // 3-state check box and not pressed
csMixedPressed, // 3-state check box and pressed
csUncheckedDisabled, // disabled checkbox, not checkable
csCheckedDisabled, // disabled checkbox, not uncheckable
csMixedDisabled // disabled 3-state checkbox
);
/// Adds some convenience methods to type TCheckState
TCheckStateHelper = record helper for TCheckState
strict private
const
// Lookup to quickly convert a specific check state into its pressed counterpart and vice versa.
cPressedState : array [TCheckState] of TCheckState = (
csUncheckedPressed, csUncheckedPressed, csCheckedPressed, csCheckedPressed, csMixedPressed, csMixedPressed, csUncheckedDisabled, csCheckedDisabled, csMixedDisabled);
cUnpressedState : array [TCheckState] of TCheckState = (
csUncheckedNormal, csUncheckedNormal, csCheckedNormal, csCheckedNormal, csMixedNormal, csMixedNormal, csUncheckedDisabled, csCheckedDisabled, csMixedDisabled);
cEnabledState : array [TCheckState] of TCheckState = (
csUncheckedNormal, csUncheckedPressed, csCheckedNormal, csCheckedPressed, csMixedNormal, csMixedPressed, csUncheckedNormal, csCheckedNormal, csMixedNormal);
cToggledState : array [TCheckState] of TCheckState = (
csCheckedNormal, csCheckedPressed, csUncheckedNormal, csUncheckedPressed, csCheckedNormal, csCheckedPressed, csUncheckedDisabled, csCheckedDisabled, csMixedDisabled);
public
function GetPressed() : TCheckState; inline;
function GetUnpressed() : TCheckState; inline;
function GetEnabled() : TCheckState; inline;
function GetToggled() : TCheckState; inline;
function IsDisabled() : Boolean; inline;
function IsChecked() : Boolean; inline;
function IsUnChecked() : Boolean; inline;
function IsMixed() : Boolean; inline;
end;
type
// Options per column.
TVTColumnOption = (
coAllowClick, // Column can be clicked (must be enabled too).
coDraggable, // Column can be dragged.
coEnabled, // Column is enabled.
coParentBidiMode, // Column uses the parent's bidi mode.
coParentColor, // Column uses the parent's background color.
coResizable, // Column can be resized.
coShowDropMark, // Column shows the drop mark if it is currently the drop target.
coVisible, // Column is shown.
coAutoSpring, // Column takes part in the auto spring feature of the header (must be resizable too).
coFixed, // Column is fixed and can not be selected or scrolled etc.
coSmartResize, // Column is resized to its largest entry which is in view (instead of its largest
// visible entry).
coAllowFocus, // Column can be focused.
coDisableAnimatedResize, // Column resizing is not animated.
coWrapCaption, // Caption could be wrapped across several header lines to fit columns width.
coUseCaptionAlignment, // Column's caption has its own aligment.
coEditable, // Column can be edited
coStyleColor // Prefer background color of VCL style over TVirtualTreeColumn.Color
);
TVTColumnOptions = set of TVTColumnOption;
TVirtualTreeColumnStyle = (
vsText,
vsOwnerDraw
);
TSortDirection = (
sdAscending,
sdDescending
);
TSortDirectionHelper = record helper for VirtualTrees.Types.TSortDirection
strict private
const
cSortDirectionToInt : Array [TSortDirection] of Integer = (1, - 1);
public
/// Returns +1 for ascending and -1 for descending sort order.
function ToInt() : Integer; inline;
end;
// Used during owner draw of the header to indicate which drop mark for the column must be drawn.
TVTDropMarkMode = (
dmmNone,
dmmLeft,
dmmRight
);
// auto scroll directions
TScrollDirections = set of TScrollDirection;
// sdLeft,
// sdUp,
// sdRight,
// sdDown
// );
// There is a heap of switchable behavior in the tree. Since published properties may never exceed 4 bytes,
// which limits sets to at most 32 members, and because for better overview tree options are splitted
// in various sub-options and are held in a commom options class.
//
// Options to customize tree appearance:
TVTPaintOption = (
toHideFocusRect, // Avoid drawing the dotted rectangle around the currently focused node.
toHideSelection, // Selected nodes are drawn as unselected nodes if the tree is unfocused.
toHotTrack, // Track which node is under the mouse cursor.
toPopupMode, // Paint tree as would it always have the focus (useful for tree combo boxes etc.)
toShowBackground, // Use the background image if there's one.
toShowButtons, // Display collapse/expand buttons left to a node.
toShowDropmark, // Show the dropmark during drag'n drop operations.
toShowHorzGridLines, // Display horizontal lines to simulate a grid.
toShowRoot, // Show lines also at top level (does not show the hidden/internal root node).
toShowTreeLines, // Display tree lines to show hierarchy of nodes.
toShowVertGridLines, // Display vertical lines (depending on columns) to simulate a grid.
toThemeAware, // Draw UI elements (header, tree buttons etc.) according to the current theme if enabled (Windows XP+ only, application must be themed).
toUseBlendedImages, // Enable alpha blending for ghosted nodes or those which are being cut/copied.
toGhostedIfUnfocused, // Ghosted images are still shown as ghosted if unfocused (otherwise the become non-ghosted images).
toFullVertGridLines, // Display vertical lines over the full client area, not only the space occupied by nodes.
// This option only has an effect if toShowVertGridLines is enabled too.
toAlwaysHideSelection, // Do not draw node selection, regardless of focused state.
toUseBlendedSelection, // Enable alpha blending for node selections.
toStaticBackground, // Show simple static background instead of a tiled one.
toChildrenAbove, // Display child nodes above their parent.
toFixedIndent, // Draw the tree with a fixed indent.
toUseExplorerTheme, // Use the explorer theme if run under Windows Vista (or above).
toHideTreeLinesIfThemed, // Do not show tree lines if theming is used.
toShowFilteredNodes // Draw nodes even if they are filtered out.
);
TVTPaintOptions = set of TVTPaintOption;
{ Options to toggle animation support:
**Do not use toAnimatedToggle when a background image is used for the tree.
The animation does not look good as the image splits and moves with it.
}
TVTAnimationOption = (
toAnimatedToggle, // Expanding and collapsing a node is animated (quick window scroll).
// **See note above.
toAdvancedAnimatedToggle // Do some advanced animation effects when toggling a node.
);
TVTAnimationOptions = set of TVTAnimationOption;
// Options which toggle automatic handling of certain situations:
TVTAutoOption = (
toAutoDropExpand, // Expand node if it is the drop target for more than a certain time.
toAutoExpand, // Nodes are expanded (collapsed) when getting (losing) the focus.
toAutoScroll, // Scroll if mouse is near the border while dragging or selecting.
toAutoScrollOnExpand, // Scroll as many child nodes in view as possible after expanding a node.
toAutoSort, // Sort tree when Header.SortColumn or Header.SortDirection change or sort node if
// child nodes are added. Sorting will take place also if SortColum is NoColumn (-1).
toAutoSpanColumns, // Large entries continue into next column(s) if there's no text in them (no clipping).
toAutoTristateTracking, // Checkstates are automatically propagated for tri state check boxes.
toAutoHideButtons, // Node buttons are hidden when there are child nodes, but all are invisible.
toAutoDeleteMovedNodes, // Delete nodes which where moved in a drag operation (if not directed otherwise).
toDisableAutoscrollOnFocus, // Disable scrolling a node or column into view if it gets focused.
toAutoChangeScale, // Change default node height and header height automatically according to the height of the used font.
toAutoFreeOnCollapse, // Frees any child node after a node has been collapsed (HasChildren flag stays there).
toDisableAutoscrollOnEdit, // Do not center a node horizontally when it is edited.
toAutoBidiColumnOrdering // When set then columns (if any exist) will be reordered from lowest index to highest index
// and vice versa when the tree's bidi mode is changed.
);
TVTAutoOptions = set of TVTAutoOption;
// Options which determine the tree's behavior when selecting nodes:
TVTSelectionOption = (
toDisableDrawSelection, // Prevent user from selecting with the selection rectangle in multiselect mode.
toExtendedFocus, // Entries other than in the main column can be selected, edited etc.
toFullRowSelect, // Hit test as well as selection highlight are not constrained to the text of a node.
toLevelSelectConstraint, // Constrain selection to the same level as the selection anchor.
toMiddleClickSelect, // Allow selection, dragging etc. with the middle mouse button. This and toWheelPanning
// are mutual exclusive.
toMultiSelect, // Allow more than one node to be selected.
toRightClickSelect, // Allow selection, dragging etc. with the right mouse button.
toSiblingSelectConstraint, // Constrain selection to nodes with same parent.
toCenterScrollIntoView, // Center nodes vertically in the client area when scrolling into view.
toSimpleDrawSelection, // Simplifies draw selection, so a node's caption does not need to intersect with the
// selection rectangle.
toAlwaysSelectNode, // If this flag is set to true, the tree view tries to always have a node selected.
// This behavior is closer to the Windows TreeView and useful in Windows Explorer style applications.
toRestoreSelection, // Set to true if upon refill the previously selected nodes should be selected again.
// The nodes will be identified by its caption (text in MainColumn)
// You may use TVTHeader.RestoreSelectiuonColumnIndex to define an other column that should be used for indentification.
toSyncCheckboxesWithSelection, // If checkboxes are shown, they follow the change in selections. When checkboxes are
// changed, the selections follow them and vice-versa.
// **Only supported for ctCheckBox type checkboxes.
toSelectNextNodeOnRemoval // If the selected node gets deleted, automatically select the next node.
);
TVTSelectionOptions = set of TVTSelectionOption;
TVTEditOptions = (
toDefaultEdit, // Standard behaviour for end of editing (after VK_RETURN stay on edited cell).
toVerticalEdit, // After VK_RETURN switch to next column.
toHorizontalEdit // After VK_RETURN switch to next row.
);
// Options which do not fit into any of the other groups:
TVTMiscOption = (
toAcceptOLEDrop, // Register tree as OLE accepting drop target
toCheckSupport, // Show checkboxes/radio buttons.
toEditable, // Node captions can be edited.
toFullRepaintOnResize, // Fully invalidate the tree when its window is resized (CS_HREDRAW/CS_VREDRAW).
toGridExtensions, // Use some special enhancements to simulate and support grid behavior.
toInitOnSave, // Initialize nodes when saving a tree to a stream.
toReportMode, // Tree behaves like TListView in report mode.
toToggleOnDblClick, // Toggle node expansion state when it is double clicked.
toWheelPanning, // Support for mouse panning (wheel mice only). This option and toMiddleClickSelect are
// mutal exclusive, where panning has precedence.
toReadOnly, // The tree does not allow to be modified in any way. No action is executed and
// node editing is not possible.
toVariableNodeHeight, // When set then GetNodeHeight will trigger OnMeasureItem to allow variable node heights.
toFullRowDrag, // Start node dragging by clicking anywhere in it instead only on the caption or image.
// Must be used together with toDisableDrawSelection.
toNodeHeightResize, // Allows changing a node's height via mouse.
toNodeHeightDblClickResize, // Allows to reset a node's height to FDefaultNodeHeight via a double click.
toEditOnClick, // Editing mode can be entered with a single click
toEditOnDblClick, // Editing mode can be entered with a double click
toReverseFullExpandHotKey // Used to define Ctrl+'+' instead of Ctrl+Shift+'+' for full expand (and similar for collapsing)
);
TVTMiscOptions = set of TVTMiscOption;
// Options to control data export
TVTExportMode = (
emAll, // export all records (regardless checked state)
emChecked, // export checked records only
emUnchecked, // export unchecked records only
emVisibleDueToExpansion, // Do not export nodes that are not visible because their parent is not expanded
emSelected // export selected nodes only
);
// Describes the type of text to return in the text and draw info retrival events.
TVSTTextType = (
ttNormal, // normal label of the node, this is also the text which can be edited
ttStatic // static (non-editable) text after the normal text
);
// Options regarding strings (useful only for the string tree and descendants):
TVTStringOption = (
toSaveCaptions, // If set then the caption is automatically saved with the tree node, regardless of what is
// saved in the user data.
toShowStaticText, // Show static text in a caption which can be differently formatted than the caption
// but cannot be edited.
toAutoAcceptEditChange // Automatically accept changes during edit if the user finishes editing other then
// VK_RETURN or ESC. If not set then changes are cancelled.
);
TVTStringOptions = set of TVTStringOption;
// Be careful when adding new states as this might change the size of the type which in turn
// changes the alignment in the node record as well as the stream chunks.
// Do not reorder the states and always add new states at the end of this enumeration in order to avoid
// breaking existing code.
TVirtualNodeState = (
vsInitialized, // Set after the node has been initialized.
vsChecking, // Node's check state is changing, avoid propagation.
vsCutOrCopy, // Node is selected as cut or copy and paste source.
vsDisabled, // Set if node is disabled.
vsDeleting, // Set when the node is about to be freed.
vsExpanded, // Set if the node is expanded.
vsHasChildren, // Indicates the presence of child nodes without actually setting them.
vsVisible, // Indicate whether the node is visible or not (independant of the expand states of its parents).
vsSelected, // Set if the node is in the current selection.
vsOnFreeNodeCallRequired, // Set if user data has been set which requires OnFreeNode.
vsAllChildrenHidden, // Set if vsHasChildren is set and no child node has the vsVisible flag set.
vsReleaseCallOnUserDataRequired, // Indicates that the user data is a reference to an interface which should be released.
vsMultiline, // Node text is wrapped at the cell boundaries instead of being shorted.
vsHeightMeasured, // Node height has been determined and does not need a recalculation.
vsToggling, // Set when a node is expanded/collapsed to prevent recursive calls.
vsFiltered, // Indicates that the node should not be painted (without effecting its children).
vsInitializing // Set when the node is being initialized
);
TVirtualNodeStates = set of TVirtualNodeState;
// States used in InitNode to indicate states a node shall initially have.
TVirtualNodeInitState = (
ivsDisabled,
ivsExpanded,
ivsHasChildren,
ivsMultiline,
ivsSelected,
ivsFiltered,
ivsReInit
);
TVirtualNodeInitStates = set of TVirtualNodeInitState;
// Various events must be handled at different places than they were initiated or need
// a persistent storage until they are reset.
TVirtualTreeStates = set of (
tsChangePending, // A selection change is pending.
tsCheckPropagation, // Set during automatic check state propagation.
tsCollapsing, // A full collapse operation is in progress.
tsToggleFocusedSelection, // Node selection was modifed using Ctrl-click. Change selection state on next mouse up.
tsClearPending, // Need to clear the current selection on next mouse move.
tsClearOnNewSelection, // Need to clear the current selection before selecting a new node
tsClipboardFlushing, // Set during flushing the clipboard to avoid freeing the content.
tsCopyPending, // Indicates a pending copy operation which needs to be finished.
tsCutPending, // Indicates a pending cut operation which needs to be finished.
tsDrawSelPending, // Multiselection only. User held down the left mouse button on a free
// area and might want to start draw selection.
tsDrawSelecting, // Multiselection only. Draw selection has actually started.
tsEditing, // Indicates that an edit operation is currently in progress.
tsEditPending, // An mouse up start edit if dragging has not started.
tsExpanding, // A full expand operation is in progress.
tsNodeHeightTracking, // A node height changing operation is in progress.
tsNodeHeightTrackPending, // left button is down, user might want to start changing a node's height.
tsHint, // Set when our hint is visible or soon will be.
tsInAnimation, // Set if the tree is currently in an animation loop.
tsIncrementalSearching, // Set when the user starts incremental search.
tsIncrementalSearchPending, // Set in WM_KEYDOWN to tell to use the char in WM_CHAR for incremental search.
tsIterating, // Set when IterateSubtree is currently in progress.
tsLeftButtonDown, // Set when the left mouse button is down.
tsLeftDblClick, // Set when the left mouse button was doubly clicked.
tsMiddleButtonDown, // Set when the middle mouse button is down.
tsMiddleDblClick, // Set when the middle mouse button was doubly clicked.
tsNeedRootCountUpdate, // Set if while loading a root node count is set.
tsOLEDragging, // OLE dragging in progress.
tsOLEDragPending, // User has requested to start delayed dragging.
tsPainting, // The tree is currently painting itself.
tsRightButtonDown, // Set when the right mouse button is down.
tsRightDblClick, // Set when the right mouse button was doubly clicked.
tsPopupMenuShown, // The user clicked the right mouse button, which might cause a popup menu to appear.
tsScrolling, // Set when autoscrolling is active.
tsScrollPending, // Set when waiting for the scroll delay time to elapse.
tsSizing, // Set when the tree window is being resized. This is used to prevent recursive calls
// due to setting the scrollbars when sizing.
tsStopValidation, // Cache validation can be stopped (usually because a change has occured meanwhile).
tsStructureChangePending, // The structure of the tree has been changed while the update was locked.
tsSynchMode, // Set when the tree is in synch mode, where no timer events are triggered.
tsThumbTracking, // Stop updating the horizontal scroll bar while dragging the vertical thumb and vice versa.
tsToggling, // A toggle operation (for some node) is in progress.
tsUpdateHiddenChildrenNeeded, // Pending update for the hidden children flag after massive visibility changes.
tsUseCache, // The tree's node caches are validated and non-empty.
tsUserDragObject, // Signals that the application created an own drag object in OnStartDrag.
tsUseThemes, // The tree runs under WinXP+, is theme aware and themes are enabled.
tsValidating, // The tree's node caches are currently validated.
tsPreviouslySelectedLocked,// The member FPreviouslySelected should not be changed
tsValidationNeeded, // Something in the structure of the tree has changed. The cache needs validation.
tsVCLDragging, // VCL drag'n drop in progress.
tsVCLDragPending, // One-shot flag to avoid clearing the current selection on implicit mouse up for VCL drag.
tsVCLDragFinished, // Flag to avoid triggering the OnColumnClick event twice
tsPanning, // Mouse panning is active.
tsWindowCreating, // Set during window handle creation to avoid frequent unnecessary updates.
tsUseExplorerTheme // The tree runs under WinVista+ and is using the explorer theme
);
TCheckImageKind = (
ckCustom, // application defined check images
ckSystemDefault // Uses the system check images, theme aware.
);
// mode to describe a move action
TVTNodeAttachMode = (
amNoWhere, // just for simplified tests, means to ignore the Add/Insert command
amInsertBefore, // insert node just before destination (as sibling of destination)
amInsertAfter, // insert node just after destionation (as sibling of destination)
amAddChildFirst, // add node as first child of destination
amAddChildLast // add node as last child of destination
);
// modes to determine drop position further
TDropMode = (
dmNowhere,
dmAbove,
dmOnNode,
dmBelow
);
// operations basically allowed during drag'n drop
TDragOperation = (
doCopy,
doMove,
doLink
);
TDragOperations = set of TDragOperation;
TVTImageKind = (
ikNormal,
ikSelected,
ikState,
ikOverlay
);
{
Fine points: Observed when fixing issue #623
-- hmHint allows multiline hints automatically if provided through OnGetHint event.
This is irresptive of whether node itself is multi-line or not.
-- hmToolTip shows a hint only when node text is not fully shown. It's meant to
fully show node text when not visible. It will show multi-line hint only if
the node itself is multi-line. If you provide a custom multi-line hint then
you must force linebreak style to hlbForceMultiLine in the OnGetHint event
in order to show the complete hint.
}
TVTHintMode = (
hmDefault, // show the hint of the control
hmHint, // show node specific hint string returned by the application
hmHintAndDefault, // same as hmHint but show the control's hint if no node is concerned
hmTooltip // show the text of the node if it isn't already fully shown
);
// Indicates how to format a tooltip.
TVTTooltipLineBreakStyle = (
hlbDefault, // Use multi-line style of the node.
hlbForceSingleLine, // Use single line hint.
hlbForceMultiLine // Use multi line hint.
);
TMouseButtons = set of TMouseButton;
// Used to describe the action to do when using the OnBeforeItemErase event.
TItemEraseAction = (
eaColor, // Use the provided color to erase the background instead the one of the tree.
eaDefault, // The tree should erase the item's background (bitmap or solid).
eaNone // Do nothing. Let the application paint the background.
);
// Kinds of operations
TVTOperationKind = (
okAutoFitColumns,
okGetMaxColumnWidth,
okSortNode,
okSortTree,
okExport,
okExpand
);
TVTOperationKinds = set of TVTOperationKind;
// Indicates in the OnUpdating event what state the tree is currently in.
TVTUpdateState = (
usBegin, // The tree just entered the update state (BeginUpdate call for the first time).
usBeginSynch, // The tree just entered the synch update state (BeginSynch call for the first time).
usSynch, // Begin/EndSynch has been called but the tree did not change the update state.
usUpdate, // Begin/EndUpdate has been called but the tree did not change the update state.
usEnd, // The tree just left the update state (EndUpdate called for the last level).
usEndSynch // The tree just left the synch update state (EndSynch called for the last level).
);
// These elements are used both to query the application, which of them it wants to draw itself and to tell it during
// painting, which elements must be drawn during the advanced custom draw events.
THeaderPaintElements = set of (
hpeBackground,
hpeDropMark,
hpeHeaderGlyph,
hpeSortGlyph,
hpeText,
// New in 7.0: Use this in FOnHeaderDrawQueryElements and OnAdvancedHeaderDraw
// for additional custom header drawing while keeping the default drawing
hpeOverlay
);
// determines whether and how the drag image is to show
TVTDragImageKind = (
diComplete, // show a complete drag image with all columns, only visible columns are shown
diMainColumnOnly, // show only the main column (the tree column)
diNoImage // don't show a drag image at all
);
// Switch for OLE and VCL drag'n drop. Because it is not possible to have both simultanously.
TVTDragType = (
dtOLE,
dtVCL
);
// Determines the look of a tree's lines that show the hierarchy
TVTLineStyle = (
lsCustomStyle, // application provides a line pattern
lsDotted, // usual dotted lines (default)
lsSolid // simple solid lines
);
// TVTLineType is used during painting a tree for its tree lines that show the hierarchy
TVTLineType = (
ltNone, // no line at all
ltBottomRight, // a line from bottom to the center and from there to the right
ltTopDown, // a line from top to bottom
ltTopDownRight, // a line from top to bottom and from center to the right
ltRight, // a line from center to the right
ltTopRight, // a line from bottom to center and from there to the right
// special styles for alternative drawings of tree lines
ltLeft, // a line from top to bottom at the left
ltLeftBottom // a combination of ltLeft and a line at the bottom from left to right
);
// Determines how to draw tree lines.
TVTLineMode = (
lmNormal, // usual tree lines (as in TTreeview)
lmBands // looks similar to a Nassi-Schneidermann diagram
);
// A collection of line type IDs which is used while painting a node.
TLineImage = array of TVTLineType;
// Export type
TVTExportType = (
etNone, // No export, normal displaying on the screen
etRTF, // contentToRTF
etHTML, // contentToHTML
etText, // contentToText
etExcel, // supported by external tools
etWord, // supported by external tools
etPDF, // supported by external tools
etPrinter,// supported by external tools
etCSV, // supported by external tools
etCustom // supported by external tools
);
// Options which are used when modifying the scroll offsets.
TScrollUpdateOptions = set of (
suoRepaintHeader, // if suoUpdateNCArea is also set then invalidate the header
suoRepaintScrollBars, // if suoUpdateNCArea is also set then repaint both scrollbars after updating them
suoScrollClientArea, // scroll and invalidate the proper part of the client area
suoUpdateNCArea // update non-client area (scrollbars, header)
);
// Determines the look of a tree's buttons.
TVTButtonStyle = (
bsRectangle, // traditional Windows look (plus/minus buttons)
bsTriangle // traditional Macintosh look
);
// TButtonFillMode is only used when the button style is bsRectangle and determines how to fill the interior.
TVTButtonFillMode = (
fmTreeColor, // solid color, uses the tree's background color
fmWindowColor, // solid color, uses clWindow
fmShaded, // no longer supported, use toThemeAware for Windows XP and later instead
fmTransparent // transparent color, use the item's background color
);
// Method called by the Animate routine for each animation step.
TVTAnimationCallback = function(Step, StepSize: Integer; Data: Pointer): Boolean of object;
TVTIncrementalSearch = (
isAll, // search every node in tree, initialize if necessary
isNone, // disable incremental search
isInitializedOnly, // search only initialized nodes, skip others
isVisibleOnly // search only visible nodes, initialize if necessary
);
// Determines which direction to use when advancing nodes during an incremental search.
TVTSearchDirection = (
sdForward,
sdBackward
);
// Determines where to start incremental searching for each key press.
TVTSearchStart = (
ssAlwaysStartOver, // always use the first/last node (depending on direction) to search from
ssLastHit, // use the last found node
ssFocusedNode // use the currently focused node
);
// Determines how to use the align member of a node.
TVTNodeAlignment = (
naFromBottom, // the align member specifies amount of units (usually pixels) from top border of the node
naFromTop, // align is to be measured from bottom
naProportional // align is to be measure in percent of the entire node height and relative to top
);
// Determines how to draw the selection rectangle used for draw selection.
TVTDrawSelectionMode = (
smDottedRectangle, // same as DrawFocusRect
smBlendedRectangle // alpha blending, uses special colors (see TVTColors)
);
// Determines for which purpose the cell paint event is called.
TVTCellPaintMode = (
cpmPaint, // painting the cell
cpmGetContentMargin // getting cell content margin
);
// Determines which sides of the cell content margin should be considered.
TVTCellContentMarginType = (
ccmtAllSides, // consider all sides
ccmtTopLeftOnly, // consider top margin and left margin only
ccmtBottomRightOnly // consider bottom margin and right margin only
);
TChangeReason = (
crIgnore, // used as placeholder
crAccumulated, // used for delayed changes
crChildAdded, // one or more child nodes have been added
crChildDeleted, // one or more child nodes have been deleted
crNodeAdded, // a node has been added
crNodeCopied, // a node has been duplicated
crNodeMoved // a node has been moved to a new place
); // desribes what made a structure change event happen
TChunkHeader = record
ChunkType,
ChunkSize: Integer; // contains the size of the chunk excluding the header
end;
const
DefaultPaintOptions = [toShowButtons, toShowDropmark, toShowTreeLines, toShowRoot, toThemeAware, toUseBlendedImages, toFullVertGridLines];
DefaultAnimationOptions = [];
DefaultAutoOptions = [toAutoDropExpand, toAutoTristateTracking, toAutoScrollOnExpand, toAutoDeleteMovedNodes, toAutoChangeScale, toAutoSort, toAutoHideButtons];
DefaultSelectionOptions = [toSelectNextNodeOnRemoval];
DefaultMiscOptions = [toAcceptOLEDrop, toFullRepaintOnResize, toInitOnSave, toToggleOnDblClick, toWheelPanning, toEditOnClick];
DefaultStringOptions = [toSaveCaptions, toAutoAcceptEditChange];
type
TCustomVirtualTreeOptions = class(TPersistent)
private
FOwner : TCustomControl;
FPaintOptions : TVTPaintOptions;
FAnimationOptions : TVTAnimationOptions;
FAutoOptions : TVTAutoOptions;
FSelectionOptions : TVTSelectionOptions;
FMiscOptions : TVTMiscOptions;
FExportMode : TVTExportMode;
FEditOptions : TVTEditOptions;
procedure SetAnimationOptions(const Value : TVTAnimationOptions);
procedure SetAutoOptions(const Value : TVTAutoOptions);
procedure SetMiscOptions(const Value : TVTMiscOptions);
procedure SetPaintOptions(const Value : TVTPaintOptions);
procedure SetSelectionOptions(const Value : TVTSelectionOptions);
protected
// 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;
public
constructor Create(AOwner : TCustomControl); virtual;
//these bypass the side effects in the regular setters.
procedure InternalSetMiscOptions(const Value : TVTMiscOptions);
procedure AssignTo(Dest : TPersistent); override;
property AnimationOptions : TVTAnimationOptions read FAnimationOptions write SetAnimationOptions default DefaultAnimationOptions;
property AutoOptions : TVTAutoOptions read FAutoOptions write SetAutoOptions default DefaultAutoOptions;
property ExportMode : TVTExportMode read FExportMode write FExportMode default emAll;
property MiscOptions : TVTMiscOptions read FMiscOptions write SetMiscOptions default DefaultMiscOptions;
property PaintOptions : TVTPaintOptions read FPaintOptions write SetPaintOptions default DefaultPaintOptions;
property SelectionOptions : TVTSelectionOptions read FSelectionOptions write SetSelectionOptions default DefaultSelectionOptions;
property EditOptions : TVTEditOptions read FEditOptions write FEditOptions default toDefaultEdit;
property Owner: TCustomControl read FOwner;
end;
TTreeOptionsClass = class of TCustomVirtualTreeOptions;
TVirtualTreeOptions = class(TCustomVirtualTreeOptions)
published
property AnimationOptions;
property AutoOptions;
property ExportMode;
property MiscOptions;
property PaintOptions;
property SelectionOptions;
end;
TCustomStringTreeOptions = class(TCustomVirtualTreeOptions)
private
FStringOptions : TVTStringOptions;
procedure SetStringOptions(const Value : TVTStringOptions);
protected
public
constructor Create(AOwner : TCustomControl); override;
procedure AssignTo(Dest : TPersistent); override;
property StringOptions : TVTStringOptions read FStringOptions write SetStringOptions default DefaultStringOptions;
end;
TStringTreeOptions = class(TCustomStringTreeOptions)
published
property AnimationOptions;
property AutoOptions;
property ExportMode;
property MiscOptions;
property PaintOptions;
property SelectionOptions;
property StringOptions;
property EditOptions;
end;
TScrollBarStyle = (
sbmRegular,
sbm3D
);
// A class to manage scroll bar aspects.
TScrollBarOptions = class(TPersistent)
private
FAlwaysVisible : Boolean;
FOwner : TCustomControl;
FScrollBars : TScrollStyle; // used to hide or show vertical and/or horizontal scrollbar
FScrollBarStyle : TScrollBarStyle; // kind of scrollbars to use
FIncrementX, FIncrementY : TVTScrollIncrement; // number of pixels to scroll in one step (when auto scrolling)
procedure SetAlwaysVisible(Value : Boolean);
procedure SetScrollBars(Value : TScrollStyle);
procedure SetScrollBarStyle(Value : TScrollBarStyle);
protected
function GetOwner : TPersistent; override;
public
constructor Create(AOwner : TCustomControl);
procedure Assign(Source : TPersistent); override;
published
property AlwaysVisible : Boolean read FAlwaysVisible write SetAlwaysVisible default False;
property HorizontalIncrement : TVTScrollIncrement read FIncrementX write FIncrementX default 20;
property ScrollBars : TScrollStyle read FScrollBars write SetScrollBars default TScrollStyle.ssBoth;
property ScrollBarStyle : TScrollBarStyle read FScrollBarStyle write SetScrollBarStyle default sbmRegular;
property VerticalIncrement : TVTScrollIncrement read FIncrementY write FIncrementY default 20;
end;
PVirtualNode = ^TVirtualNode;
TVirtualNode = packed record
private
fIndex: Cardinal; // index of node with regard to its parent
fChildCount: Cardinal; // number of child nodes
fNodeHeight: TNodeHeight; // height in pixels
public
States: TVirtualNodeStates; // states describing various properties of the node (expanded, initialized etc.)
Align: Byte; // line/button alignment
CheckState: TCheckState; // indicates the current check state (e.g. checked, pressed etc.)
CheckType: TCheckType; // indicates which check type shall be used for this node
Dummy: Byte; // dummy value to fill DWORD boundary
TotalCount: Cardinal; // sum of this node, all of its child nodes and their child nodes etc.
TotalHeight: TNodeHeight;// height in pixels this node covers on screen including the height of all of its children.
_Filler: TDWordFiller; // Ensure 8 Byte alignment of following pointers for 64bit builds. Issue #1136
// Note: Some copy routines require that all pointers (as well as the data area) in a node are
// located at the end of the node! Hence if you want to add new member fields (except pointers to internal
// data) then put them before field Parent.
private
fParent: PVirtualNode; // reference to the node's parent (for the root this contains the treeview)
fPrevSibling: PVirtualNode; // link to the node's previous sibling or nil if it is the first node
fNextSibling: PVirtualNode; // link to the node's next sibling or nil if it is the last node
public // still public as it is used as var parameter in MergeSortAscending()
FirstChild: PVirtualNode; // link to the node's first child...
private
fLastChild: PVirtualNode; // link to the node's last child...
public
procedure SetParent(const pParent: PVirtualNode); inline; //internal method, do not call directly but use Parent[Node] := x on tree control.
procedure SetPrevSibling(const pPrevSibling: PVirtualNode); inline; //internal method, do not call directly
procedure SetNextSibling(const pNextSibling: PVirtualNode); inline; //internal method, do not call directly
procedure SetFirstChild(const pFirstChild: PVirtualNode); inline; //internal method, do not call directly
procedure SetLastChild(const pLastChild: PVirtualNode); inline; //internal method, do not call directly
procedure SetIndex(const pIndex: Cardinal); inline; //internal method, do not call directly.
procedure SetChildCount(const pCount: Cardinal); inline; //internal method, do not call directly.
procedure SetNodeHeight(const pNodeHeight: TNodeHeight); inline; //internal method, do not call directly.
property Index: Cardinal read fIndex;
property ChildCount: Cardinal read fChildCount;
property Parent: PVirtualNode read fParent;
property PrevSibling: PVirtualNode read fPrevSibling;
property NextSibling: PVirtualNode read fNextSibling;
property LastChild: PVirtualNode read fLastChild;
property NodeHeight: TNodeHeight read fNodeHeight;
private
Data: record end; // this is a placeholder, each node gets extra data determined by NodeDataSize
public
function IsAssigned(): Boolean; inline;
function GetData(): Pointer; overload; inline;
function GetData<T>(): T; overload; inline;
procedure SetData(pUserData: Pointer); overload;
procedure SetData<T>(pUserData: T); overload;
procedure SetData(const pUserData: IInterface); overload;
end;
TVTHeaderColumnLayout = (
blGlyphLeft,
blGlyphRight,
blGlyphTop,
blGlyphBottom
);
// These flags are used to indicate where a click in the header happened.
TVTHeaderHitPosition = (
hhiNoWhere, // No column is involved (possible only if the tree is smaller than the client area).
hhiOnColumn, // On a column.
hhiOnIcon, // On the bitmap associated with a column.
hhiOnCheckbox // On the checkbox if enabled.
);
TVTHeaderHitPositions = set of TVTHeaderHitPosition;
// These flags are returned by the hit test method.
THitPosition = (
hiAbove, // above the client area (if relative) or the absolute tree area
hiBelow, // below the client area (if relative) or the absolute tree area
hiNowhere, // no node is involved (possible only if the tree is not as tall as the client area)
hiOnItem, // on the bitmaps/buttons or label associated with an item
hiOnItemButton, // on the button associated with an item
hiOnItemButtonExact, // exactly on the button associated with an item
hiOnItemCheckbox, // on the checkbox if enabled
hiOnItemIndent, // in the indentation area in front of a node
hiOnItemLabel, // on the normal text area associated with an item
hiOnItemLeft, // in the area to the left of a node's text area (e.g. when right aligned or centered)
hiOnItemRight, // in the area to the right of a node's text area (e.g. if left aligned or centered)
hiOnNormalIcon, // on the "normal" image
hiOnStateIcon, // on the state image
hiToLeft, // to the left of the client area (if relative) or the absolute tree area
hiToRight, // to the right of the client area (if relative) or the absolute tree area
hiUpperSplitter, // in the upper splitter area of a node
hiLowerSplitter // in the lower splitter area of a node
);
THitPositions = set of THitPosition;
// Structure used when info about a certain position in the header is needed.
TVTHeaderHitInfo = record
X,