diff options
author | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2012-02-21 12:17:14 +0200 |
---|---|---|
committer | Graeme Geldenhuys <graeme@mastermaths.co.za> | 2012-02-21 12:17:14 +0200 |
commit | 4f397af51f4169214f05a1f1dc91d680dd7260cb (patch) | |
tree | 692037a11a1250b15a83b6fdcc3107645198c8da | |
parent | 0078222a95b7833c591ac58419eb380b66f9f14e (diff) | |
download | fpGUI-4f397af51f4169214f05a1f1dc91d680dd7260cb.tar.xz |
New method GetNodeAt() for TfpgTreeView.
This is vital for drag-n-drop support inside a treeview component.
-rw-r--r-- | src/gui/fpg_tree.pas | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/src/gui/fpg_tree.pas b/src/gui/fpg_tree.pas index 6c9415fa..3b94cfdd 100644 --- a/src/gui/fpg_tree.pas +++ b/src/gui/fpg_tree.pas @@ -225,6 +225,7 @@ type procedure SetColumnWidth(AIndex, AWidth: word); // the width of a column - aIndex of the rootnode = 0 function GetColumnWidth(AIndex: word): word; + function GetNodeAt(const X, Y: integer): TfpgTreeNode; procedure GotoNextNodeUp; procedure GotoNextNodeDown; procedure FullCollapse; @@ -1191,6 +1192,56 @@ begin result := DefaultColumnWidth; end; +function TfpgTreeView.GetNodeAt(const X, Y: integer): TfpgTreeNode; +var + col: integer; + lTop: integer; + lLeft: integer; + i, i1: integer; + cancel: boolean; + last, node: TfpgTreeNode; + w: integer; + lNodeXOffset: integer; +begin + if ShowColumns then + col := FColumnHeight + else + col := 0; + + Result := nil; + i := 0; + lTop := y - col - 1 + FYOffset; + lLeft := x + FXOffset; + cancel := False; + last := RootNode; + + while not ((((i - 1) * GetNodeHeight) <= lTop) and ((i * GetNodeHeight) >= lTop)) do + begin + node := NextVisualNode(last); + if node = nil then + exit; //==> + if node = last then + begin + cancel := True; + break; //==> + end; + inc(i); + last := node; + end; + + if (not cancel) or (node <> nil) then + begin + // +/- or node-selection? + i1 := StepToRoot(node); + w := GetColumnLeft(i1); + lNodeXOffset := w - GetColumnWidth(i1) div 2 + 6; + if lLeft > lNodeXOffset then { we are in the actual treenode area } + begin + Result := node; + end; + end; +end; + procedure TfpgTreeView.GotoNextNodeUp; begin if Selection = RootNode.FirstSubNode then |