Skip to content

Commit

Permalink
Change for #832: Turn TVirtualNode.NodeHeight into a readonly property
Browse files Browse the repository at this point in the history
  • Loading branch information
joachimmarder committed Sep 20, 2023
1 parent 8e8f9ca commit 90a09f8
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 6 additions & 6 deletions Source/VirtualTrees.BaseTree.pas
Original file line number Diff line number Diff line change
Expand Up @@ -4330,7 +4330,7 @@ procedure TBaseVirtualTree.InitRootNode(OldSize: Cardinal = 0);
States := [vsInitialized, vsExpanded, vsHasChildren, vsVisible];
TotalHeight := FDefaultNodeHeight;
TotalCount := 1;
NodeHeight := FDefaultNodeHeight;
SetNodeHeight(FDefaultNodeHeight);
Align := 50;
end;
end;
Expand Down Expand Up @@ -4414,7 +4414,7 @@ function TBaseVirtualTree.MakeNewNode: PVirtualNode;
begin
TotalCount := 1;
TotalHeight := FDefaultNodeHeight;
NodeHeight := FDefaultNodeHeight;
SetNodeHeight(FDefaultNodeHeight);
States := [vsVisible];
Align := 50;
end;
Expand Down Expand Up @@ -5180,7 +5180,7 @@ procedure TBaseVirtualTree.SetDefaultNodeHeight(Value: TDimension);
if FDefaultNodeHeight <> Value then
begin
Inc(FRoot.TotalHeight, Value - FDefaultNodeHeight);
Inc(FRoot.NodeHeight, Value - FDefaultNodeHeight);
FRoot.SetNodeHeight(FRoot.NodeHeight + Value - FDefaultNodeHeight);
FDefaultNodeHeight := Value;
InvalidateCache;
if (FUpdateCount = 0) and HandleAllocated and not (csLoading in ComponentState) then
Expand Down Expand Up @@ -5599,7 +5599,7 @@ procedure TBaseVirtualTree.SetNodeHeight(Node: PVirtualNode; Value: TDimension);
if (Node.NodeHeight <> Value) then
begin
Difference := Value - Node.NodeHeight;
Node.NodeHeight := Value;
Node.SetNodeHeight(Value);

// If the node is effectively filtered out, nothing else has to be done, as it is not visible anyway.
if not IsEffectivelyFiltered[Node] then
Expand Down Expand Up @@ -9027,7 +9027,7 @@ procedure TBaseVirtualTree.ScaleNodeHeights(M, D: Integer);
SetNodeHeight(Run, MulDiv(Run.NodeHeight, M, D))
else // prevent initialization of non-initialzed nodes
begin
Run.NodeHeight := MulDiv(Run.NodeHeight, M, D);
Run.SetNodeHeight(MulDiv(Run.NodeHeight, M, D));
// The next three lines fix issue #1000
lNewNodeTotalHeight := MulDiv(Run.TotalHeight, M, D);
FRoot.TotalHeight := Cardinal(Int64(FRoot.TotalHeight) + Int64(lNewNodeTotalHeight) - Int64(Run.TotalHeight)); // Avoiding EIntOverflow exception.
Expand Down Expand Up @@ -15122,7 +15122,7 @@ function TBaseVirtualTree.ReadChunk(Stream: TStream; Version: Integer; Node: PVi
begin
// Set states first, in case the node is invisible.
States := ChunkBody.States;
NodeHeight := ChunkBody.NodeHeight;
SetNodeHeight(ChunkBody.NodeHeight);
TotalHeight := NodeHeight;
Align := ChunkBody.Align;
CheckState := ChunkBody.CheckState;
Expand Down
9 changes: 8 additions & 1 deletion Source/VirtualTrees.Types.pas
Original file line number Diff line number Diff line change
Expand Up @@ -887,8 +887,8 @@ TScrollBarOptions = class(TPersistent)
private
fIndex: Cardinal; // index of node with regard to its parent
fChildCount: Cardinal; // number of child nodes
fNodeHeight: TDimension; // height in pixels
public
NodeHeight: TDimension; // height in pixels
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.)
Expand Down Expand Up @@ -917,12 +917,14 @@ TScrollBarOptions = class(TPersistent)
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: TDimension); 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: TDimension read fNodeHeight;
private
Data: record end; // this is a placeholder, each node gets extra data determined by NodeDataSize
public
Expand Down Expand Up @@ -1149,6 +1151,11 @@ function TVirtualNode.IsAssigned: Boolean;
Exit(@Self <> nil);
end;

procedure TVirtualNode.SetNodeHeight(const pNodeHeight: TDimension);
begin
fNodeHeight := pNodeHeight;
end;

//----------------------------------------------------------------------------------------------------------------------

procedure TVirtualNode.SetData(pUserData: Pointer);
Expand Down

0 comments on commit 90a09f8

Please sign in to comment.