home *** CD-ROM | disk | FTP | other *** search
/ PC Format Collection 48 / SENT14D.ISO / tech / delphi / disk14 / doc.pak / OUTLINE.INT < prev    next >
Encoding:
Text File  |  1995-08-24  |  9.4 KB  |  254 lines

  1. {*******************************************************}
  2. {                                                       }
  3. {       Delphi Visual Component Library                 }
  4. {                                                       }
  5. {       Copyright (c) 1995 Borland International        }
  6. {                                                       }
  7. {*******************************************************}
  8.  
  9. unit Outline;
  10.  
  11. interface
  12.  
  13. {$R OUTLINE}
  14.  
  15. uses WinTypes, WinProcs, Messages, Forms, Classes, Graphics,
  16.   Menus, StdCtrls, Grids, Controls, SysUtils;
  17.  
  18. type
  19.   OutlineError = class(TObject); { Raised by GetNodeAtIndex }
  20.   EOutlineError = class(Exception);
  21.   TAttachMode = (oaAdd, oaAddChild, oaInsert);
  22.   TChangeRange = -1..1;
  23.   TCustomOutline = class;
  24.  
  25. { TOutlineNode }
  26.  
  27. { The TOutlineNode is an encapsulation of an outliner item.  Access
  28.   to a TOutlineNode is via the container class TOutline.  Each
  29.   TOutlineNode contains user defined text and data.
  30.   An item is also capable of containing up to 16368 sub-items.
  31.   TOutlineNodes are also persistent.
  32.  
  33.   A TOutlineNode item can be interrogated about its current state :
  34.     Expanded
  35.       Whether the node is open or closed.
  36.     Index
  37.       The current Index of the node.  This changes as items are inserted and
  38.       deleted.  The index will range from 1..n
  39.     Level
  40.       The current depth of the node with 1 being the top level
  41.     HasItems
  42.       Whether the item contains items
  43.     IsVisible
  44.       Whether the item is capable of being displayed. This value is only
  45.       True if all its parent items are visible
  46.     TopItem
  47.       Obtains the parent of the item that resides at level 1
  48.     FullPath
  49.       Returns the fully qualified name of the item starting from its
  50.       level 1 parent.  Each item is separated by the separator string
  51.       specified in the TOutline Container
  52.     Text
  53.       Used to set and get the items text value
  54.     Data
  55.       Used to get and set the items data }
  56.  
  57.   TOutlineNode = class(TPersistent)
  58.   protected
  59.     constructor Create(AOwner: TCustomOutline);
  60.     destructor Destroy; override;
  61.     function GetVisibleNode(TargetCount: LongInt): TOutlineNode;
  62.     function AddNode(Value: TOutlineNode): LongInt;
  63.     function InsertNode(Index: LongInt; Value: TOutlineNode): LongInt;
  64.     function GetNodeAtIndex(TargetIndex: LongInt): TOutlineNode;
  65.     function GetDataItem(Value: Pointer): LongInt;
  66.     function GetTextItem(const Value: string): LongInt;
  67.     function HasAsParent(Value: TOutlineNode): Boolean;
  68.     function GetRowOfNode(TargetNode: TOutlineNode;
  69.       var RowCount: Longint): Boolean;
  70.     procedure Remove(Value: TOutlineNode);
  71.     procedure WriteNode(Buffer: PChar; Stream: TStream);
  72.     property Outline: TCustomOutline;
  73.     property List: TList;
  74.     property ExpandCount: LongInt;
  75.     property Items[Index: LongInt]: TOutlineNode; default;
  76.   public
  77.     procedure ChangeLevelBy(Value: TChangeRange);
  78.     procedure Collapse;
  79.     procedure Expand;
  80.     procedure FullExpand;
  81.     function GetDisplayWidth: Integer;
  82.     function GetFirstChild: LongInt;
  83.     function GetLastChild: LongInt;
  84.     function GetNextChild(Value: LongInt): LongInt;
  85.     function GetPrevChild(Value: LongInt): LongInt;
  86.     procedure MoveTo(Destination: LongInt; AttachMode: TAttachMode);
  87.     property Parent: TOutlineNode;
  88.     property Expanded: Boolean;
  89.     property Text: string;
  90.     property Data: Pointer;
  91.     property Index: LongInt;
  92.     property Level: Cardinal;
  93.     property HasItems: Boolean;
  94.     property IsVisible: Boolean;
  95.     property TopItem: Longint;
  96.     property FullPath: string;
  97.   end;
  98.  
  99. { TCustomOutline }
  100.  
  101. { The TCustomOutline object is a container class for TOutlineNodes.
  102.   All TOutlineNodes contained within a TOutline are presented
  103.   to the user as a flat array of TOutlineNodes, with a parent
  104.   TOutlineNode containing an index value that is one less than
  105.   its first child (if it has any children).
  106.  
  107.   Interaction with a TOutlineNode is typically accomplished through
  108.   the TCustomOutline using the following properties:
  109.     CurItem
  110.       Reads and writes the current item
  111.     ItemCount
  112.       Returns the total number of TOutlineNodes with the TCustomOutline.
  113.       Note this can be computationally expensive as all indexes will
  114.       be forced to be updated!!
  115.     Items
  116.       Allows Linear indexing into the hierarchical list of TOutlineNodes
  117.     SelectedItem
  118.       Returns the Index of the TOutlineNode which has the focus or 0 if
  119.       no TOutlineNode has been selected
  120.  
  121.   The TCustomOutline has a number of properties which will affect all
  122.   TOutlineNodes owned by the TCustomOutline:
  123.     OutlineStyle
  124.       Sets the visual style of the outliner
  125.     ItemSeparator
  126.       Sets the delimiting string for all TOutlineNodes
  127.     PicturePlus, PictureMinus, PictureOpen, PictureClosed, PictureLeaf
  128.       Sets custom bitmaps for these items }
  129.  
  130.   TBitmapArrayRange = 0..4;
  131.   EOutlineChange = procedure (Sender: TObject; Index: LongInt) of object;
  132.   TOutlineStyle = (osText, osPlusMinusText, osPictureText,
  133.     osPlusMinusPictureText, osTreeText, osTreePictureText);
  134.   TOutlineBitmap = (obPlus, obMinus, obOpen, obClose, obLeaf);
  135.   TBitmapArray = array[TBitmapArrayRange] of TBitmap;
  136.   TOutlineType = (otStandard, otOwnerDraw);
  137.   TOutlineOption = (ooDrawTreeRoot, ooDrawFocusRect, ooStretchBitmaps);
  138.   TOutlineOptions = set of TOutlineOption;
  139.  
  140.  
  141.   TCustomOutline = class(TCustomGrid)
  142.   protected
  143.     procedure Loaded; override;
  144.     procedure Click; override;
  145.     procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  146.     procedure KeyPress(var Key: Char); override;
  147.     procedure DrawCell(ACol, ARow: Longint; ARect: TRect;
  148.       AState: TGridDrawState); override;
  149.     procedure DblClick; override;
  150.     procedure SetLevel (Node: TOutlineNode; CurLevel, NewLevel: Cardinal);
  151.     procedure DeleteNode(Node: TOutlineNode; CurIndex: LongInt);
  152.     procedure Expand(Index: LongInt); dynamic;
  153.     procedure Collapse(Index: LongInt); dynamic;
  154.     procedure DefineProperties(Filer: TFiler); override;
  155.     procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
  156.       X, Y: Integer); override;
  157.     procedure Move(Destination, Source: LongInt; AttachMode: TAttachMode);
  158.     procedure SetDisplayWidth(Value: Integer);
  159.     property Lines: TStrings;
  160.     property OutlineStyle: TOutlineStyle default osTreePictureText;
  161.     property OnExpand: EOutlineChange;
  162.     property OnCollapse: EOutlineChange;
  163.     property Options: TOutlineOptions default [ooDrawTreeRoot, ooDrawFocusRect];
  164.     property Style: TOutlineType default otStandard;
  165.     property ItemHeight: Integer;
  166.     property OnDrawItem: TDrawItemEvent;
  167.     property ItemSeparator: string;
  168.     property PicturePlus: TBitmap index 0;
  169.     property PictureMinus: TBitmap index 1;
  170.     property PictureOpen: TBitmap index 2;
  171.     property PictureClosed: TBitmap index 3;
  172.     property PictureLeaf: TBitmap index 4;
  173.   public
  174.     constructor Create(AOwner: TComponent); override;
  175.     destructor Destroy; override;
  176.     function Add(Index: LongInt; const Text: string): LongInt;
  177.     function AddChild(Index: LongInt; const Text: string): LongInt;
  178.     function AddChildObject(Index: LongInt; const Text: string; const Data: Pointer): LongInt;
  179.     function AddObject(Index: LongInt; const Text: string; const Data: Pointer): LongInt;
  180.     function Insert(Index: LongInt; const Text: string): LongInt;
  181.     function InsertObject(Index: LongInt; const Text: string; const Data: Pointer): LongInt;
  182.     procedure Delete(Index: LongInt);
  183.     function GetDataItem(Value: Pointer): Longint;
  184.     function GetNodeDisplayWidth(Node: TOutlineNode): Integer;
  185.     function GetTextItem(const Value: string): Longint;
  186.     function GetItem(X, Y: Integer): LongInt;
  187.     procedure FullExpand;
  188.     procedure FullCollapse;
  189.     procedure LoadFromFile(const FileName: string);
  190.     procedure LoadFromStream(Stream: TStream);
  191.     procedure SaveToFile(const FileName: string);
  192.     procedure SaveToStream(Stream: TStream);
  193.     procedure BeginUpdate;
  194.     procedure EndUpdate;
  195.     procedure SetUpdateState(Value: Boolean);
  196.     procedure Clear;
  197.     property ItemCount: LongInt;
  198.     property Items[Index: LongInt]: TOutlineNode; default;
  199.     property SelectedItem: Longint;
  200.     property Row;
  201.     property Canvas;
  202.   end;
  203.  
  204.   TOutline = class(TCustomOutline)
  205.   published
  206.     property Lines;
  207.     property OutlineStyle;
  208.     property OnExpand;
  209.     property OnCollapse;
  210.     property Options;
  211.     property Style;
  212.     property ItemHeight;
  213.     property OnDrawItem;
  214.     property Align;
  215.     property Enabled;
  216.     property Font;
  217.     property Color;
  218.     property ParentColor;
  219.     property ParentCtl3D;
  220.     property Ctl3D;
  221.     property TabOrder;
  222.     property TabStop;
  223.     property Visible;
  224.     property OnClick;
  225.     property DragMode;
  226.     property DragCursor;
  227.     property OnDragDrop;
  228.     property OnDragOver;
  229.     property OnEndDrag;
  230.     property OnEnter;
  231.     property OnExit;
  232.     property OnMouseDown;
  233.     property OnMouseMove;
  234.     property OnMouseUp;
  235.     property OnDblClick;
  236.     property OnKeyDown;
  237.     property OnKeyPress;
  238.     property OnKeyUp;
  239.     property BorderStyle;
  240.     property ItemSeparator;
  241.     property PicturePlus;
  242.     property PictureMinus;
  243.     property PictureOpen;
  244.     property PictureClosed;
  245.     property PictureLeaf;
  246.     property ParentFont;
  247.     property ParentShowHint;
  248.     property ShowHint;
  249.     property PopupMenu;
  250.     property ScrollBars;
  251.   end;
  252.  
  253. implementation
  254.