2004-06-07 19:17:31 +00:00
|
|
|
{
|
|
|
|
:: X2UtVirtualTree provides a set of functions commonly used with
|
|
|
|
:: TVirtualTree (http://www.delphi-gems.com/).
|
|
|
|
::
|
|
|
|
:: Last changed: $Date$
|
|
|
|
:: Revision: $Rev$
|
|
|
|
:: Author: $Author$
|
|
|
|
}
|
|
|
|
unit X2UtVirtualTree;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
2005-01-25 10:44:32 +00:00
|
|
|
Graphics,
|
2005-02-26 22:06:31 +00:00
|
|
|
VirtualTrees,
|
|
|
|
Windows;
|
2004-06-07 19:17:31 +00:00
|
|
|
|
2005-02-26 22:06:31 +00:00
|
|
|
//:$ Applies the sort order on the specified column.
|
2004-06-07 19:17:31 +00:00
|
|
|
//:: When a column is already sorted, the sort order is reversed.
|
2005-01-25 10:44:32 +00:00
|
|
|
//:: Specify a SortColor to provide the new column with that color
|
|
|
|
//:: (similar to Explorer in Windows XP). If you choose to use SortColor,
|
|
|
|
//:: the column's Tag property will be used to restore the color when calling
|
|
|
|
//:: SortColumn for the second time, so be sure not to rely on that.
|
2004-06-07 19:17:31 +00:00
|
|
|
procedure SortColumn(const AHeader: TVTHeader;
|
2005-01-25 10:44:32 +00:00
|
|
|
const AColumn: TColumnIndex;
|
2005-03-12 16:01:52 +00:00
|
|
|
const ASortColor: TColor = clNone;
|
|
|
|
const AApplySort: Boolean = True);
|
2004-06-07 19:17:31 +00:00
|
|
|
|
2005-02-26 22:06:31 +00:00
|
|
|
//:$ Calculates the position of an image in a virtual string tree.
|
|
|
|
function CalcImagePos(const ATree: TVirtualStringTree;
|
|
|
|
const ANode: PVirtualNode;
|
2005-03-12 16:01:52 +00:00
|
|
|
const ACellRect: TRect): TPoint;
|
2005-02-26 22:06:31 +00:00
|
|
|
|
2004-06-07 19:17:31 +00:00
|
|
|
implementation
|
|
|
|
|
2005-02-26 22:06:31 +00:00
|
|
|
procedure SortColumn(const AHeader: TVTHeader;
|
|
|
|
const AColumn: TColumnIndex;
|
2005-03-12 16:01:52 +00:00
|
|
|
const ASortColor: TColor;
|
|
|
|
const AApplySort: Boolean);
|
2004-06-07 19:17:31 +00:00
|
|
|
begin
|
|
|
|
with AHeader do
|
2005-01-25 10:44:32 +00:00
|
|
|
begin
|
|
|
|
if (ASortColor <> clNone) and (SortColumn <> -1) then
|
|
|
|
with Columns[SortColumn] do
|
|
|
|
if Tag <> 0 then
|
|
|
|
begin
|
2005-10-18 09:25:05 +00:00
|
|
|
if Tag = clNone then
|
|
|
|
Options := Options + [coParentColor]
|
|
|
|
else
|
|
|
|
Color := Tag;
|
|
|
|
|
2005-01-25 10:44:32 +00:00
|
|
|
Tag := 0;
|
|
|
|
end;
|
|
|
|
|
2005-03-12 16:01:52 +00:00
|
|
|
if AApplySort then
|
|
|
|
if SortColumn = AColumn then
|
|
|
|
SortDirection := TSortDirection(1 - Integer(SortDirection))
|
|
|
|
else begin
|
|
|
|
SortColumn := AColumn;
|
|
|
|
SortDirection := sdAscending;
|
|
|
|
end;
|
2005-01-25 10:44:32 +00:00
|
|
|
|
|
|
|
if ASortColor <> clNone then
|
|
|
|
with Columns[SortColumn] do
|
|
|
|
begin
|
2005-10-18 09:25:05 +00:00
|
|
|
if coParentColor in Options then
|
|
|
|
Tag := clNone
|
|
|
|
else
|
|
|
|
Tag := Color;
|
|
|
|
|
2005-01-25 10:44:32 +00:00
|
|
|
Color := ASortColor;
|
|
|
|
end;
|
|
|
|
end;
|
2004-06-07 19:17:31 +00:00
|
|
|
end;
|
|
|
|
|
2005-02-26 22:06:31 +00:00
|
|
|
function CalcImagePos(const ATree: TVirtualStringTree;
|
|
|
|
const ANode: PVirtualNode;
|
2005-03-12 16:01:52 +00:00
|
|
|
const ACellRect: TRect): TPoint;
|
2005-02-26 22:06:31 +00:00
|
|
|
var
|
|
|
|
pNode: PVirtualNode;
|
|
|
|
|
|
|
|
begin
|
2005-03-12 16:01:52 +00:00
|
|
|
Result := ACellRect.TopLeft;
|
2005-02-26 22:06:31 +00:00
|
|
|
|
|
|
|
with ATree do
|
|
|
|
begin
|
|
|
|
pNode := ANode;
|
2005-03-12 16:01:52 +00:00
|
|
|
if Assigned(pNode) and not (toShowRoot in ATree.TreeOptions.PaintOptions) then
|
|
|
|
pNode := pNode^.Parent;
|
|
|
|
|
2005-02-26 22:06:31 +00:00
|
|
|
while Assigned(pNode) and (pNode <> ATree.RootNode) do
|
|
|
|
begin
|
|
|
|
Inc(Result.X, Indent);
|
|
|
|
pNode := pNode^.Parent;
|
|
|
|
end;
|
|
|
|
|
|
|
|
Inc(Result.X, Margin);
|
|
|
|
Inc(Result.Y, (Integer(NodeHeight[ANode]) - Images.Height) div 2);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2004-06-07 19:17:31 +00:00
|
|
|
end.
|
|
|
|
|