Skip to content

Commit 90a09f8

Browse files
committed
Change for #832: Turn TVirtualNode.NodeHeight into a readonly property
1 parent 8e8f9ca commit 90a09f8

File tree

2 files changed

+14
-7
lines changed

2 files changed

+14
-7
lines changed

Source/VirtualTrees.BaseTree.pas

+6-6
Original file line numberDiff line numberDiff line change
@@ -4330,7 +4330,7 @@ procedure TBaseVirtualTree.InitRootNode(OldSize: Cardinal = 0);
43304330
States := [vsInitialized, vsExpanded, vsHasChildren, vsVisible];
43314331
TotalHeight := FDefaultNodeHeight;
43324332
TotalCount := 1;
4333-
NodeHeight := FDefaultNodeHeight;
4333+
SetNodeHeight(FDefaultNodeHeight);
43344334
Align := 50;
43354335
end;
43364336
end;
@@ -4414,7 +4414,7 @@ function TBaseVirtualTree.MakeNewNode: PVirtualNode;
44144414
begin
44154415
TotalCount := 1;
44164416
TotalHeight := FDefaultNodeHeight;
4417-
NodeHeight := FDefaultNodeHeight;
4417+
SetNodeHeight(FDefaultNodeHeight);
44184418
States := [vsVisible];
44194419
Align := 50;
44204420
end;
@@ -5180,7 +5180,7 @@ procedure TBaseVirtualTree.SetDefaultNodeHeight(Value: TDimension);
51805180
if FDefaultNodeHeight <> Value then
51815181
begin
51825182
Inc(FRoot.TotalHeight, Value - FDefaultNodeHeight);
5183-
Inc(FRoot.NodeHeight, Value - FDefaultNodeHeight);
5183+
FRoot.SetNodeHeight(FRoot.NodeHeight + Value - FDefaultNodeHeight);
51845184
FDefaultNodeHeight := Value;
51855185
InvalidateCache;
51865186
if (FUpdateCount = 0) and HandleAllocated and not (csLoading in ComponentState) then
@@ -5599,7 +5599,7 @@ procedure TBaseVirtualTree.SetNodeHeight(Node: PVirtualNode; Value: TDimension);
55995599
if (Node.NodeHeight <> Value) then
56005600
begin
56015601
Difference := Value - Node.NodeHeight;
5602-
Node.NodeHeight := Value;
5602+
Node.SetNodeHeight(Value);
56035603

56045604
// If the node is effectively filtered out, nothing else has to be done, as it is not visible anyway.
56055605
if not IsEffectivelyFiltered[Node] then
@@ -9027,7 +9027,7 @@ procedure TBaseVirtualTree.ScaleNodeHeights(M, D: Integer);
90279027
SetNodeHeight(Run, MulDiv(Run.NodeHeight, M, D))
90289028
else // prevent initialization of non-initialzed nodes
90299029
begin
9030-
Run.NodeHeight := MulDiv(Run.NodeHeight, M, D);
9030+
Run.SetNodeHeight(MulDiv(Run.NodeHeight, M, D));
90319031
// The next three lines fix issue #1000
90329032
lNewNodeTotalHeight := MulDiv(Run.TotalHeight, M, D);
90339033
FRoot.TotalHeight := Cardinal(Int64(FRoot.TotalHeight) + Int64(lNewNodeTotalHeight) - Int64(Run.TotalHeight)); // Avoiding EIntOverflow exception.
@@ -15122,7 +15122,7 @@ function TBaseVirtualTree.ReadChunk(Stream: TStream; Version: Integer; Node: PVi
1512215122
begin
1512315123
// Set states first, in case the node is invisible.
1512415124
States := ChunkBody.States;
15125-
NodeHeight := ChunkBody.NodeHeight;
15125+
SetNodeHeight(ChunkBody.NodeHeight);
1512615126
TotalHeight := NodeHeight;
1512715127
Align := ChunkBody.Align;
1512815128
CheckState := ChunkBody.CheckState;

Source/VirtualTrees.Types.pas

+8-1
Original file line numberDiff line numberDiff line change
@@ -887,8 +887,8 @@ TScrollBarOptions = class(TPersistent)
887887
private
888888
fIndex: Cardinal; // index of node with regard to its parent
889889
fChildCount: Cardinal; // number of child nodes
890+
fNodeHeight: TDimension; // height in pixels
890891
public
891-
NodeHeight: TDimension; // height in pixels
892892
States: TVirtualNodeStates; // states describing various properties of the node (expanded, initialized etc.)
893893
Align: Byte; // line/button alignment
894894
CheckState: TCheckState; // indicates the current check state (e.g. checked, pressed etc.)
@@ -917,12 +917,14 @@ TScrollBarOptions = class(TPersistent)
917917
procedure SetLastChild(const pLastChild: PVirtualNode); inline; //internal method, do not call directly
918918
procedure SetIndex(const pIndex: Cardinal); inline; //internal method, do not call directly.
919919
procedure SetChildCount(const pCount: Cardinal); inline; //internal method, do not call directly.
920+
procedure SetNodeHeight(const pNodeHeight: TDimension); inline; //internal method, do not call directly.
920921
property Index: Cardinal read fIndex;
921922
property ChildCount: Cardinal read fChildCount;
922923
property Parent: PVirtualNode read fParent;
923924
property PrevSibling: PVirtualNode read fPrevSibling;
924925
property NextSibling: PVirtualNode read fNextSibling;
925926
property LastChild: PVirtualNode read fLastChild;
927+
property NodeHeight: TDimension read fNodeHeight;
926928
private
927929
Data: record end; // this is a placeholder, each node gets extra data determined by NodeDataSize
928930
public
@@ -1149,6 +1151,11 @@ function TVirtualNode.IsAssigned: Boolean;
11491151
Exit(@Self <> nil);
11501152
end;
11511153

1154+
procedure TVirtualNode.SetNodeHeight(const pNodeHeight: TDimension);
1155+
begin
1156+
fNodeHeight := pNodeHeight;
1157+
end;
1158+
11521159
//----------------------------------------------------------------------------------------------------------------------
11531160

11541161
procedure TVirtualNode.SetData(pUserData: Pointer);

0 commit comments

Comments
 (0)