home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
PC World Komputer 1997 May
/
Pcwk0597.iso
/
borland
/
cb
/
setup
/
cbuilder
/
data.z
/
OUTLINE.INT
< prev
next >
Wrap
Text File
|
1997-02-28
|
10KB
|
263 lines
{*******************************************************}
{ }
{ Delphi Visual Component Library }
{ }
{ Copyright (c) 1995,96 Borland International }
{ }
{*******************************************************}
unit Outline;
{$R-}
interface
{$R OUTLINE}
uses Windows, Messages, Forms, Classes, Graphics, Menus, StdCtrls, Grids,
Controls, SysUtils;
type
OutlineError = class(TObject); { Raised by GetNodeAtIndex }
EOutlineError = class(Exception);
TOutlineNodeCompare = (ocLess, ocSame, ocGreater, ocInvalid);
TAttachMode = (oaAdd, oaAddChild, oaInsert);
TChangeRange = -1..1;
TCustomOutline = class;
{ TOutlineNode }
{ The TOutlineNode is an encapsulation of an outliner item. Access
to a TOutlineNode is via the container class TOutline. Each
TOutlineNode contains user defined text and data.
An item is also capable of containing up to 16368 sub-items.
TOutlineNodes are also persistent.
A TOutlineNode item can be interrogated about its current state :
Expanded
Whether the node is open or closed.
Index
The current Index of the node. This changes as items are inserted and
deleted. The index will range from 1..n
Level
The current depth of the node with 1 being the top level
HasItems
Whether the item contains items
IsVisible
Whether the item is capable of being displayed. This value is only
True if all its parent items are visible
TopItem
Obtains the parent of the item that resides at level 1
FullPath
Returns the fully qualified name of the item starting from its
level 1 parent. Each item is separated by the separator string
specified in the TOutline Container
Text
Used to set and get the items text value
Data
Used to get and set the items data }
TOutlineNode = class(TPersistent)
protected
constructor Create(AOwner: TCustomOutline);
destructor Destroy; override;
function GetVisibleNode(TargetCount: LongInt): TOutlineNode;
function AddNode(Value: TOutlineNode): LongInt;
function InsertNode(Index: LongInt; Value: TOutlineNode): LongInt;
function GetNodeAtIndex(TargetIndex: LongInt): TOutlineNode;
function GetDataItem(Value: Pointer): LongInt;
function GetTextItem(const Value: string): LongInt;
function HasAsParent(Value: TOutlineNode): Boolean;
function GetRowOfNode(TargetNode: TOutlineNode;
var RowCount: Longint): Boolean;
procedure InternalRemove(Value: TOutlineNode; Index: Integer);
procedure Remove(Value: TOutlineNode);
procedure WriteNode(Buffer: PChar; Stream: TStream);
property Outline: TCustomOutline;
property List: TList;
property ExpandCount: LongInt;
property Items[Index: LongInt]: TOutlineNode; default;
public
procedure ChangeLevelBy(Value: TChangeRange);
procedure Collapse;
procedure Expand;
procedure FullExpand;
function GetDisplayWidth: Integer;
function getFirstChild: LongInt;
function GetLastChild: LongInt;
function GetNextChild(Value: LongInt): LongInt;
function GetPrevChild(Value: LongInt): LongInt;
procedure MoveTo(Destination: LongInt; AttachMode: TAttachMode);
property Parent: TOutlineNode;
property Expanded: Boolean;
property Text: string;
property Data: Pointer;
property Index: LongInt;
property Level: Cardinal;
property HasItems: Boolean;
property IsVisible: Boolean;
property TopItem: Longint;
property FullPath: string;
end;
{ TCustomOutline }
{ The TCustomOutline object is a container class for TOutlineNodes.
All TOutlineNodes contained within a TOutline are presented
to the user as a flat array of TOutlineNodes, with a parent
TOutlineNode containing an index value that is one less than
its first child (if it has any children).
Interaction with a TOutlineNode is typically accomplished through
the TCustomOutline using the following properties:
CurItem
Reads and writes the current item
ItemCount
Returns the total number of TOutlineNodes with the TCustomOutline.
Note this can be computationally expensive as all indexes will
be forced to be updated!!
Items
Allows Linear indexing into the hierarchical list of TOutlineNodes
SelectedItem
Returns the Index of the TOutlineNode which has the focus or 0 if
no TOutlineNode has been selected
The TCustomOutline has a number of properties which will affect all
TOutlineNodes owned by the TCustomOutline:
OutlineStyle
Sets the visual style of the outliner
ItemSeparator
Sets the delimiting string for all TOutlineNodes
PicturePlus, PictureMinus, PictureOpen, PictureClosed, PictureLeaf
Sets custom bitmaps for these items }
TBitmapArrayRange = 0..4;
EOutlineChange = procedure (Sender: TObject; Index: LongInt) of object;
TOutlineStyle = (osText, osPlusMinusText, osPictureText,
osPlusMinusPictureText, osTreeText, osTreePictureText);
TOutlineBitmap = (obPlus, obMinus, obOpen, obClose, obLeaf);
TOutlineBitmaps = set of TOutlineBitmap;
TBitmapArray = array[TBitmapArrayRange] of TBitmap;
TOutlineType = (otStandard, otOwnerDraw);
TOutlineOption = (ooDrawTreeRoot, ooDrawFocusRect, ooStretchBitmaps);
TOutlineOptions = set of TOutlineOption;
TCustomOutline = class(TCustomGrid)
protected
procedure Loaded; override;
procedure Click; override;
procedure KeyDown(var Key: Word; Shift: TShiftState); override;
procedure KeyPress(var Key: Char); override;
function SetGoodIndex(Value: TOutlineNode): TOutlineNode;
procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
AState: TGridDrawState); override;
procedure DblClick; override;
procedure SetLevel(Node: TOutlineNode; CurLevel, NewLevel: Cardinal);
function BadIndex(Value: TOutlineNode): Boolean;
procedure DeleteNode(Node: TOutlineNode; CurIndex: LongInt);
procedure Expand(Index: LongInt); dynamic;
procedure Collapse(Index: LongInt); dynamic;
procedure DefineProperties(Filer: TFiler); override;
procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
X, Y: Integer); override;
procedure Move(Destination, Source: LongInt; AttachMode: TAttachMode);
procedure SetDisplayWidth(Value: Integer);
property Lines: TStrings;
property OutlineStyle: TOutlineStyle default osTreePictureText;
property OnExpand: EOutlineChange;
property OnCollapse: EOutlineChange;
property Options: TOutlineOptions default [ooDrawTreeRoot, ooDrawFocusRect];
property Style: TOutlineType default otStandard;
property ItemHeight: Integer;
property OnDrawItem: TDrawItemEvent;
property ItemSeparator: string;
property PicturePlus: TBitmap index 0;
property PictureMinus: TBitmap index 1;
property PictureOpen: TBitmap index 2;
property PictureClosed: TBitmap index 3;
property PictureLeaf: TBitmap index 4;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
function Add(Index: LongInt; const Text: string): LongInt;
function AddChild(Index: LongInt; const Text: string): LongInt;
function AddChildObject(Index: LongInt; const Text: string; const Data: Pointer): LongInt;
function AddObject(Index: LongInt; const Text: string; const Data: Pointer): LongInt;
function Insert(Index: LongInt; const Text: string): LongInt;
function InsertObject(Index: LongInt; const Text: string; const Data: Pointer): LongInt;
procedure Delete(Index: LongInt);
function GetDataItem(Value: Pointer): Longint;
function GetItem(X, Y: Integer): LongInt;
function GetNodeDisplayWidth(Node: TOutlineNode): Integer;
function GetTextItem(const Value: string): Longint;
function GetVisibleNode(Index: LongInt): TOutlineNode;
procedure FullExpand;
procedure FullCollapse;
procedure LoadFromFile(const FileName: string);
procedure LoadFromStream(Stream: TStream);
procedure SaveToFile(const FileName: string);
procedure SaveToStream(Stream: TStream);
procedure BeginUpdate;
procedure EndUpdate;
procedure SetUpdateState(Value: Boolean);
procedure Clear;
property ItemCount: LongInt;
property Items[Index: LongInt]: TOutlineNode; default;
property SelectedItem: Longint;
property Row;
property Canvas;
end;
TOutline = class(TCustomOutline)
published
property Lines;
property OutlineStyle;
property OnExpand;
property OnCollapse;
property Options;
property Style;
property ItemHeight;
property OnDrawItem;
property Align;
property Enabled;
property Font;
property Color;
property ParentColor;
property ParentCtl3D;
property Ctl3D;
property TabOrder;
property TabStop;
property Visible;
property OnClick;
property DragMode;
property DragCursor;
property OnDragDrop;
property OnDragOver;
property OnEndDrag;
property OnStartDrag;
property OnEnter;
property OnExit;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
property OnDblClick;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property BorderStyle;
property ItemSeparator;
property PicturePlus;
property PictureMinus;
property PictureOpen;
property PictureClosed;
property PictureLeaf;
property ParentFont;
property ParentShowHint;
property ShowHint;
property PopupMenu;
property ScrollBars;
end;
implementation