📄 teetree.pas
字号:
private
FList : PPointerList;
FCount : Integer;
FCapacity : Integer;
IDelta : Integer;
protected
procedure SetCapacity(NewCapacity: Integer);
procedure SetCount(NewCount: Integer);
function Add(Item: TObject): Integer;
procedure Clear; //virtual;
procedure Delete(Index: Integer);
procedure Exchange(Index1, Index2: Integer);
procedure Insert(Index: Integer; Item: TObject);
procedure Move(CurIndex, NewIndex: Integer);
function Remove(Item: TObject): Integer;
property Capacity: Integer read FCapacity write SetCapacity;
property List: PPointerList read FList;
public
Destructor Destroy; override;
property Count: Integer read FCount write SetCount;
function IndexOf(Item: TObject): Integer;
end;
{$ENDIF}
// List of nodes
TNodeShapeList=class(TTreeList)
private
ITree : TCustomTree;
Function GetShape(Index:Integer):TTreeNodeShape;
public
Function Add(Node:TTreeNodeShape):Integer;
Function Clicked(x,y:Integer):TTreeNodeShape;
Function Find(Const S:String; Partial:Boolean=False):TTreeNodeShape;
Function FindObject(Value:TObject):TTreeNodeShape;
Function First:TTreeNodeShape;
Procedure ForEach(Proc:TNodeListForEachProc);
Function Last:TTreeNodeShape;
procedure Sort(AscendingOrder,IgnoreCase:Boolean);
property Items[Index:Integer]:TTreeNodeShape read GetShape; default;
end;
TTreeChildrenList=TNodeShapeList; // alias
TConnListForEachProc=Procedure(Sender:TTreeConnection) of object;
TDeleteConnectionEvent=Procedure(Sender:TTreeConnection; Var AllowDelete:Boolean) of object;
// List of Connection objects. Used in Node class.
TNodeConnectionList=class(TTreeList)
private
FVisible : Boolean;
Function GetConnection(Index:Integer):TTreeConnection;
Procedure SetVisible(Value:Boolean);
public
Function Clicked(x,y:Integer):TTreeConnection;
Function DeleteConnection(AConnection:TTreeConnection):Boolean; virtual;
Procedure DeleteAllTo(AShape:TTreeNodeShape);
Procedure ForEach(Proc:TConnListForEachProc);
Function ToShape(AShape:TTreeNodeShape):TTreeConnection;
property Items[Index:Integer]:TTreeConnection read GetConnection; default;
published
property Visible:Boolean read FVisible write SetVisible default True;
end;
// Default node "handles" (small squares displayed when a node is selected)
TTreeShapeHandle=( rcNone,
rcLeftTop,rcRightBottom,
rcLeftBottom,rcRightTop,
rcLeft,rcTop,
rcRight,rcBottom,
rcCustom
);
// List of Connection objects. Used in TCustomTree class.
TTreeConnectionList=class(TNodeConnectionList)
private
FMagneticHandle : TTreeShapeHandle;
FMagneticPos : TPoint;
FOnDeleting : TDeleteConnectionEvent;
FSelected : TTreeConnection;
ITree : TCustomTree;
Procedure DrawMagnetic;
Procedure SetSelected(Const Value:TTreeConnection);
public
Function DeleteConnection(AConnection:TTreeConnection):Boolean; override;
property Selected:TTreeConnection read FSelected write SetSelected;
property OnDeleting:TDeleteConnectionEvent read FOnDeleting write FOnDeleting;
end;
// Constants for default "stock" images.
// See TreeImagePool global variable.
TTreeNodeImageIndex=( tiNone,
tiFolderClose,
tiFolderOpen,
tiDesktop,
tiMyPC,
tiNetworkNei,tiFloppy3,tiRecycleBin,tiHardDisk,
tiNetShare,tiComputer,tiWorld,
tiFolderOpenClose,
tiFolderCloseChecked,tiFolderCloseUnChecked,
tiChecked,tiUnChecked,
tiRadioChecked,tiRadioUnChecked,
tiFolderRadioChecked,tiFolderRadioUnChecked
);
// Styles for node's CrossBox.
TTreeNodeShapeShowCross=(
scAuto, // displayed only when node has children
scAlways, // always displayed
scNever // never displayed
);
TClickShapeEvent=procedure( Sender:TTreeNodeShape;
Button:TMouseButton;
Shift: TShiftState;
X, Y: Integer) of object;
TMouseShapeEvent=procedure(Sender:TTreeNodeShape; Shift:TShiftState;
X,Y:Integer) of object;
// Constants used to determine the position of a node's image.
TTreeImageAlignment=( iaAutomatic,
iaLeftTop,
iaRightBottom,
iaLeftBottom,
iaRightTop,
iaLeft,
iaTop,
iaRight,
iaBottom,
iaCenter );
TTreePicture=class(TPicture)
private
function GetTransp: Boolean;
procedure SetTransp(const Value: Boolean);
published
property Transparent:Boolean read GetTransp write SetTransp default False;
end;
// Constants for node Style
TTreeShapeStyle=( tssRectangle,
tssCircle,
tssVertLine,
tssHorizLine,
tssLine,
tssInvertLine,
tssDiamond,
tssTriangleTop,
tssTriangleBottom,
tssTriangleLeft,
tssTriangleRight,
tssRoundRectangle,
tssCustom
);
// Most important class. Node class.
TTreeNodeShape=class(TCustomTreeElement)
private
FAdjustedRect : TRect; // contains shape bounds plus image bounds
FAutoSize : Boolean; // when true, node size is determined by text size
FAutoPosition : TTreeShapeAutoPosition; // default is left and top true
FBackColor : TColor; // color used as background when Brush style is not solid
FBorder : TTreePen; // pen used to draw border
FBrush : TTreeShapeBrush; // brush used to fill node interior
FGradient : TShapeGradient; // gradient to fill node
FGradientClip : Boolean; // when false, draw gradient in shape rect bounds
FImage : TTreePicture; // image to draw near node or inside it
FImageAlignment: TTreeImageAlignment; // automatic, left, top, etc
FImageHeight : Integer; // height of image
FImageRect : TRect; // read-only rectangle returning image position
FImageWidth : Integer; // width of image
FImageIndex : TTreeNodeImageIndex; // default image "stock" (pool) index
FImageListIndex : Integer; // Index, when using Tree.Images property
FShadow : TTeeShadow; // shadow around node
FStyle : TTreeShapeStyle; // line, rectangle, ellipse, etc
FTransparency : TTeeTransparency; // from 0 to 100 %
FTransparent : Boolean; // when true, node interior is not filled
FVisible : Boolean; // true if node parent is expanded
FX0,FY0 : Integer; { position left,top }
FX1,FY1 : Integer; { position right,bottom }
{ Parent - Child variables }
FBrotherIndex: Integer; // -1 when node has no parent
FChildren : TTreeChildrenList; // list of children nodes
FConnections : TNodeConnectionList; // list of connection objects
FExpanded : Boolean; // True if node is expanded
FParent : TTreeNodeShape; // Parent Node
FParents : TNodeShapeList; // List of other Parent nodes.
FShowCross : TTreeNodeShapeShowCross; // Style for CrossBox
{ Events }
FOnClick : TClickShapeEvent;
FOnDblClick : TClickShapeEvent;
FOnMouseEnter : TMouseShapeEvent;
FOnMouseLeave : TMouseShapeEvent;
FOnMouseMove : TMouseShapeEvent;
{ internal }
IImageHeight : Integer; // pre-calculated ImageHeight.
IImageWidth : Integer; // pre-calculated ImageWidth.
IMouseInside : Boolean; // true when mouse is inside node bounds.
IParents0 : TTreeNodeShape; // optimization: see GetParents method.
Procedure ChangeTreeRecursive(NewTree:TCustomTree);
Procedure DoMove(DeltaX,DeltaY:Integer; AltShift:Boolean);
Function Get3DRectangle:TRect;
Function GetAdjustedRectangle:TRect;
Function GetAutoPosition:TTreeShapeAutoPosition;
Function GetAutoSize:Boolean;
Function GetBackColor:TColor;
Function GetBorder:TTreePen;
Function GetBrotherIndex: Integer;
Function GetExpanded:Boolean;
Function GetGradient:TShapeGradient;
Function GetGradientClip:Boolean;
Function GetImageAlignment:TTreeImageAlignment;
Function GetImageHeight:Integer;
Function GetImageIndex:TTreeNodeImageIndex;
Function GetImageWidth:Integer;
Function GetImageListIndex:Integer;
Function GetImageRect:TRect;
Function GetSelected:Boolean;
Function GetShadow:TTeeShadow;
Function GetShowCross:TTreeNodeShapeShowCross;
Function GetStyle:TTreeShapeStyle;
Function GetTransparent:Boolean;
Function GetTransparency:TTeeTransparency;
Procedure GetTrianglePoints( Const R:TRect;
MidX,MidY:Integer;
Var P:TShapePoints);
Function GetVisible:Boolean;
Function InternalBrush:TTreeShapeBrush;
Function InternalClipText:Boolean;
Procedure InternalDrawShadow( tmpR:TRect; ACanvas:TCanvas3D;
tmpStyle:TTreeShapeStyle); virtual;
Procedure InternalDrawShape( tmpR:TRect; ACanvas:TCanvas3D;
tmpStyle:TTreeShapeStyle);
Function InternalPen:TTreePen;
procedure InternalSetImage(const Value:TPicture);
Function InternalTextAngle:Integer;
Function IsSizeStored:Boolean;
procedure PositionChanged(Sender:TObject);
Procedure SetAutoPosition(Value:TTreeShapeAutoPosition);
Procedure SetAutoSize(Value:Boolean);
procedure SetBackColor(const Value: TColor);
procedure SetBorder(Value:TTreePen);
procedure SetBrush(Value : TTreeShapeBrush);
procedure SetImageAlignment(Value:TTreeImageAlignment);
procedure SetImageHeight(Value:Integer);
procedure SetImageWidth(Value:Integer);
Procedure SetGradient(Value:TShapeGradient);
Procedure SetGradientClip(Value:Boolean);
Procedure SetShadow(Value:TTeeShadow);
procedure SetStyle(const Value:TTreeShapeStyle);
procedure SetTransparent(const Value: Boolean);
Procedure SetVisible(const Value:Boolean);
Procedure SetX0(Value:Integer);
Procedure SetX1(Value:Integer);
Procedure SetY0(Value:Integer);
Procedure SetY1(Value:Integer);
function GetHeight: Integer;
function GetWidth: Integer;
procedure SetHeight(const Value: Integer);
procedure SetTransparency(const Value: TTeeTransparency);
procedure SetWidth(const Value: Integer);
function GetColor: TColor;
procedure SetColor(const Value: TColor);
procedure SetImageListIndex(const Value: Integer);
{ Parent - Child }
Procedure SetExpanded(Value:Boolean);
Function GetPreviousBrother:TTreeNodeShape;
Function GetRoot:TTreeNodeShape;
Function InternalAddConnection(AToShape:TTreeNodeShape):TTreeConnection;
Function IsImageStored:Boolean;
Function IsPositionLeftStored:Boolean;
Function IsPositionTopStored:Boolean;
Procedure RemoveChild(AShape:TTreeNodeShape);
procedure SetImageIndex(Value:TTreeNodeImageIndex);
Procedure SetParent(Value:TTreeNodeShape);
procedure SetShowCross(Value:TTreeNodeShapeShowCross);
function GetX0: Integer;
function GetY0: Integer;
function GetX1: Integer;
function GetY1: Integer;
function GetChildNodes: TTreeChildrenList;
function GetConnections: TNodeConnectionList;
function GetParents: TNodeShapeList;
function GetParent: TTreeNodeShape;
procedure SetLeft(const Value: Integer);
procedure SetTop(const Value: Integer);
function IsBorderStored: Boolean;
function IsBrushStored: Boolean;
function IsGradientStored: Boolean;
function IsShadowStored: Boolean;
function IsImageIndexStored: Boolean;
procedure SetBrotherIndex(const Value: Integer);
protected
IAutoSized : Boolean; // when False, recalculate again the node size.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -