diff options
author | Graeme Geldenhuys <graemeg@gmail.com> | 2009-12-29 18:03:16 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graemeg@gmail.com> | 2009-12-29 18:03:16 +0200 |
commit | a2371f5b6d98b1b28553c9d748e372e82c84b113 (patch) | |
tree | fa4db2b696ce3eb884b0c605724810044b9e0986 | |
parent | bdeb99dd80861e54f427a6511d82ad4d42940b3a (diff) | |
download | fpGUI-a2371f5b6d98b1b28553c9d748e372e82c84b113.tar.xz |
New methods GotoNextNodeUp and GotoNextNodeDown to step through a tree.
-rw-r--r-- | src/gui/fpg_tree.pas | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/gui/fpg_tree.pas b/src/gui/fpg_tree.pas index 5f511f05..19c41fb9 100644 --- a/src/gui/fpg_tree.pas +++ b/src/gui/fpg_tree.pas @@ -203,8 +203,12 @@ type procedure DrawHeader(ACol: integer; ARect: TfpgRect; AFlags: integer); virtual; procedure DoChange; virtual; procedure DoExpand(ANode: TfpgTreeNode); virtual; + // only visual (visible) nodes function NextVisualNode(ANode: TfpgTreeNode): TfpgTreeNode; function PrevVisualNode(ANode: TfpgTreeNode): TfpgTreeNode; + // any next node, even if node is collapsed + function NextNode(ANode: TfpgTreeNode): TfpgTreeNode; + function PrevNode(ANode: TfpgTreeNode): TfpgTreeNode; // the nodes between the given node and the direct next node function SpaceToVisibleNext(aNode: TfpgTreeNode): integer; function StepToRoot(aNode: TfpgTreeNode): integer; @@ -214,6 +218,8 @@ type procedure SetColumnWidth(AIndex, AWidth: word); // the width of a column - aIndex of the rootnode = 0 function GetColumnWidth(AIndex: word): word; + procedure GotoNextNodeUp; + procedure GotoNextNodeDown; property Font: TfpgFont read FFont; // Invisible node that starts the tree property RootNode: TfpgTreeNode read GetRootNode; @@ -1052,6 +1058,20 @@ begin result := DefaultColumnWidth; end; +procedure TfpgTreeView.GotoNextNodeUp; +begin + if Selection = RootNode.FirstSubNode then + Exit; + Selection := PrevNode(Selection); +end; + +procedure TfpgTreeView.GotoNextNodeDown; +begin + if Selection = RootNode.LastSubNode then + Exit; + Selection := NextNode(Selection); +end; + procedure TfpgTreeview.PreCalcColumnLeft; var Aleft: TfpgCoord; @@ -1759,6 +1779,58 @@ begin end; end; +function TfpgTreeView.NextNode(ANode: TfpgTreeNode): TfpgTreeNode; + //---------------- + procedure _FindNextNode; + begin + if ANode.Next <> nil then + begin + result := ANode.Next; + end + else + begin + while ANode.Next = nil do + begin + ANode := ANode.Parent; + if ANode = nil then + exit; //==> + end; + result := ANode.Next; + end; + end; + +begin + result := nil; + if ANode.Count > 0 then + result := ANode.FirstSubNode + else + _FindNextNode; +end; + +function TfpgTreeView.PrevNode(ANode: TfpgTreeNode): TfpgTreeNode; +var + n: TfpgTreeNode; +begin + n := ANode; + if ANode.Prev <> nil then + begin + result := ANode.Prev; + ANode := ANode.Prev; + while {(not ANode.Collapsed) and} (ANode.Count > 0) do + begin + result := ANode.LastSubNode; + ANode := ANode.LastSubNode; + end; + end + else + begin + if ANode.Parent <> nil then + result := ANode.Parent + else + result := n; + end; +end; + function TfpgTreeview.SpaceToVisibleNext(aNode: TfpgTreeNode): integer; var h: TfpgTreeNode; |