fctreeview.pas
上传用户:hylc_2004
上传日期:2014-01-23
资源大小:46800k
文件大小:166k
- unit fcTreeView;
- {
- //
- // Components : TfcTreeView
- //
- // Copyright (c) 1999 by Woll2Woll Software
- // 3/3/99 - (RSW) Remove tvoUnderscoreAllowed Option
- // 5/21/99 - Complete editing
- // 6/14/99 - Fix disappearing tree when going into edit mode
- // 6/23/99 - Fire OnDblClick event even when ExpandOnDblClick is False
- // 7/3/99 - Only call Invalidate if not in expanding/collapsing
- // 7/6/99 - Support streaming of TfcTreeView Items to TfcTreecombo's tree
- // 11/12/99 - If right mouse button, then exit so multi-selected records are
- // not unselected
- // 1/5/2000 - Fix TFrame duplicate streaming problem
- // 2/3/2000 - Optimize imagelist usage so that resources are better
- // managed with regards to bitmaps
- //
- // 2/28/2000 - Always increment refcount so that treeview does not incorrectly
- // free temp image list.
- // 5/16/2000 - PYW - Fix Memory leak from code left over from Delphi 3
- // 6/9/2000 - PYW - Prevent default button handling for treeview
- // 12/13/2001 - Don't use temp canvas for XP Themes. TreeView not painted in some cases otherwise
- // 1/31/2002 - In WMPaint call inherited if nodes are in beginupdate/endupdate.
- // 1/31/2002 - PYW - Added new property to respect expanded node settings.
- // 5/10/2002 - Use DrawText to calculate font based on current canvas settings from OnCalcNodeAttributes event.
- }
- interface
- {$i fcIfdef.pas}
- {$R-}
- uses
- Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
- CommCtrl, ComStrs, consts, comctrls, fccustomdraw, fccanvas, extctrls, fccommon,
- {$ifdef fcdelphi6Up}
- variants,
- {$endif}
- {$ifdef fcdelphi7Up}
- themes,
- {$endif}
- {$ifdef ThemeManager}
- thememgr, themesrv, uxtheme,
- {$endif}
- shellapi
- {$ifdef fcDelphi4Up}, ImgList{$endif};
- type
- TfcCustomTreeView = class;
- TfcTreeNode = class;
- TfcItemState = (fcisSelected, fcisGrayed, fcisDisabled, fcisChecked,
- fcisFocused, fcisDefault, fcisHot, fcisMarked, fcisIndeterminate);
- TfcItemStates = set of TfcItemState;
- TfcTVDrawTextEvent = procedure (TreeView: TfcCustomTreeview;
- Node: TfcTreeNode; ARect: TRect; AItemState: TfcItemStates;
- var DefaultDrawing: boolean) of object;
- TfcTreeMouseMoveEvent = procedure(TreeView: TfcCustomTreeView;
- Node: TfcTreeNode;
- Shift: TShiftState; X, Y: Integer)of object;
- TfcTreeMouseEvent = procedure(TreeView: TfcCustomTreeView;
- Node: TfcTreeNode;
- Button: TMouseButton; Shift: TShiftState; X, Y: Integer) of object;
- TfcTreeNodes = class;
- TfcNodeState = (fcnsCut, fcnsDropHilited, fcnsFocused, fcnsSelected,
- fcnsExpanded);
- TfcNodeAttachMode = (fcnaAdd, fcnaAddFirst, fcnaAddChild, fcnaAddChildFirst,
- fcnaInsert, fcnaInsertAfter);
- TfcAddMode = (fctaAddFirst, fctaAdd, fctaInsert);
- TfcTreeViewCheckboxType = (tvctNone, tvctCheckbox, tvctRadioGroup);
- TfcTreeViewOption = (tvoExpandOnDblClk, tvoExpandButtons3D,
- tvoFlatCheckBoxes, tvoHideSelection,
- tvoRowSelect, tvoShowButtons,
- tvoShowLines, tvoShowRoot,
- {tvoUnderscoreAllowed,} tvoHotTrack, tvoAutoURL, tvoToolTips,
- tvoEditText, tvo3StateCheckbox);
- TfcTreeViewOptions = set of TfcTreeViewOption;
- PfcNodeInfo = ^TfcNodeInfo;
- TfcNodeInfo = packed record
- ImageIndex: Integer;
- SelectedIndex: Integer;
- StateIndex: Integer;
- OverlayIndex: Integer;
- CheckboxType: TfcTreeViewCheckboxType;
- Checked: byte;
- Expanded: boolean;
- DummyPad: packed array[1..3] of char; { Allow Future growth }
- Data: Pointer;
- StringDataSize1: integer;
- StringDataSize2: integer;
- Count: Integer;
- Text: string[255];
- { Future growth so that old executables can still run with newer tree view formats }
- // Dummy1: integer;
- // Dummy2: integer;
- // Dummy3: integer;
- // Dummy4: integer;
- end;
- TfcTreeNode = class(TPersistent)
- private
- FMultiSelected: boolean;
- FCheckboxType: TfcTreeViewCheckboxType;
- FChecked: boolean;
- FOwner: TfcTreeNodes;
- FText: string;
- FStringData1, FStringData2: String;
- FData: Pointer;
- FItemId: HTreeItem;
- FImageIndex: Integer;
- FSelectedIndex: Integer;
- FOverlayIndex: Integer;
- FStateIndex: Integer;
- FDeleting: Boolean;
- FInTree: Boolean;
- FGrayed: boolean;
- procedure SetCheckboxType(val: TfcTreeViewCheckboxType);
- function CompareCount(CompareMe: Integer): Boolean;
- function DoCanExpand(Expand: Boolean): Boolean;
- procedure DoExpand(Expand: Boolean);
- procedure ExpandItem(Expand: Boolean; Recurse: Boolean);
- function GetAbsoluteIndex: Integer;
- function GetExpanded: Boolean;
- function GetLevel: Integer;
- function GetParent: TfcTreeNode;
- function GetChildren: Boolean;
- function GetCut: Boolean;
- function GetDropTarget: Boolean;
- function GetFocused: Boolean;
- function GetIndex: Integer;
- function GetItem(Index: Integer): TfcTreeNode;
- function GetSelected: Boolean;
- function GetState(NodeState: TfcNodeState): Boolean;
- function GetCount: Integer;
- function GetTreeView: TfcCustomTreeView;
- procedure InternalMove(ParentNode, Node: TfcTreeNode; HItem: HTreeItem;
- AddMode: TfcAddMode);
- // function IsEqual(Node: TfcTreeNode): Boolean;
- function IsNodeVisible: Boolean;
- procedure SetChildren(Value: Boolean);
- procedure SetCut(Value: Boolean);
- procedure SetData(Value: Pointer);
- procedure SetDropTarget(Value: Boolean);
- procedure SetItem(Index: Integer; Value: TfcTreeNode);
- procedure SetExpanded(Value: Boolean);
- procedure SetFocused(Value: Boolean);
- procedure SetImageIndex(Value: Integer);
- procedure SetOverlayIndex(Value: Integer);
- procedure SetSelectedIndex(Value: Integer);
- procedure SetSelected(Value: Boolean);
- procedure SetStateIndex(Value: Integer);
- procedure SetText(const S: string);
- function GetMultiSelected: Boolean;
- procedure SetMultiSelected(Value: Boolean);
- procedure SetChecked(val: boolean);
- procedure SetGrayed(val: boolean);
- protected
- // function ShowBlankImage: boolean; virtual;
- {$ifdef fcDelphi4Up}
- ReadDataSize: integer;
- {$endif}
- procedure Invalidate; virtual;
- Function GetSizeOfNodeInfo: integer; virtual;
- procedure ReadData(Stream: TStream; Info: PfcNodeInfo); virtual;
- procedure WriteData(Stream: TStream; Info: PfcNodeInfo); virtual;
- public
- Patch: Variant;
- function GetStateIndex: integer;
- Function IsRadioGroup: boolean;
- function GetSortText: string; virtual;
- constructor Create(AOwner: TfcTreeNodes); virtual;
- destructor Destroy; override;
- function AlphaSort: Boolean;
- procedure Assign(Source: TPersistent); override;
- procedure Collapse(Recurse: Boolean);
- function CustomSort(SortProc: TTVCompare; Data: Longint): Boolean;
- procedure Delete;
- procedure DeleteChildren;
- function DisplayRect(TextOnly: Boolean): TRect;
- function EditText: Boolean;
- procedure EndEdit(Cancel: Boolean);
- procedure Expand(Recurse: Boolean);
- function GetFirstChild: TfcTreeNode;
- function GetHandle: HWND;
- function GetLastChild: TfcTreeNode;
- function GetNext: TfcTreeNode;
- function GetNextChild(Value: TfcTreeNode): TfcTreeNode;
- function GetNextSibling: TfcTreeNode;
- function GetNextVisible: TfcTreeNode;
- function GetPrev: TfcTreeNode;
- function GetPrevChild(Value: TfcTreeNode): TfcTreeNode;
- function GetPrevSibling: TfcTreeNode;
- function GetPrevVisible: TfcTreeNode;
- function HasAsParent(Value: TfcTreeNode): Boolean;
- function IndexOf(Value: TfcTreeNode): Integer;
- procedure MakeVisible;
- procedure MoveTo(Destination: TfcTreeNode; Mode: TfcNodeAttachMode); virtual;
- property AbsoluteIndex: Integer read GetAbsoluteIndex;
- property Count: Integer read GetCount;
- property Cut: Boolean read GetCut write SetCut;
- property Data: Pointer read FData write SetData;
- property Deleting: Boolean read FDeleting;
- property Focused: Boolean read GetFocused write SetFocused;
- property DropTarget: Boolean read GetDropTarget write SetDropTarget;
- property Selected: Boolean read GetSelected write SetSelected;
- property Expanded: Boolean read GetExpanded write SetExpanded;
- property Handle: HWND read GetHandle;
- property HasChildren: Boolean read GetChildren write SetChildren;
- property ImageIndex: Integer read FImageIndex write SetImageIndex;
- property Index: Integer read GetIndex;
- property IsVisible: Boolean read IsNodeVisible;
- property Item[Index: Integer]: TfcTreeNode read GetItem write SetItem; default;
- property ItemId: HTreeItem read FItemId;
- property Level: Integer read GetLevel;
- property OverlayIndex: Integer read FOverlayIndex write SetOverlayIndex;
- property Owner: TfcTreeNodes read FOwner;
- property Parent: TfcTreeNode read GetParent;
- property SelectedIndex: Integer read FSelectedIndex write SetSelectedIndex;
- property StateIndex: Integer read FStateIndex write SetStateIndex;
- property Text: string read FText write SetText;
- property StringData: string read FStringData1 write FStringData1;
- property StringData2: string read FStringData2 write FStringData2;
- property TreeView: TfcCustomTreeView read GetTreeView;
- property Checked: boolean read FChecked write SetChecked;
- property Grayed: boolean read FGRayed write SetGrayed;
- property CheckboxType: TfcTreeViewCheckboxType read FCheckboxType write SetCheckboxType;
- property MultiSelected: Boolean read GetMultiSelected write SetMultiSelected;
- end;
- { TfcTreeNodes }
- PfcNodeCache = ^TfcNodeCache;
- TfcNodeCache = record
- CacheNode: TfcTreeNode;
- CacheIndex: Integer;
- end;
- TwwStoreData = (sdStoreText, sdStoreData1, sdStoreData2);
- TfcTreeNodes = class(TPersistent)
- private
- FOwner: TfcCustomTreeView;
- FUpdateCount: Integer;
- FNodeCache: TfcNodeCache;
- InDestroy: boolean;
- procedure AddedNode(Value: TfcTreeNode);
- function GetHandle: HWND;
- function GetNodeFromIndex(Index: Integer): TfcTreeNode;
- procedure ReadData(Stream: TStream);
- procedure Repaint(Node: TfcTreeNode);
- procedure WriteData(Stream: TStream);
- procedure ClearCache;
- procedure ReadStreamVersion(Reader: TReader);
- procedure WriteStreamVersion(Writer: TWriter);
- protected
- function AddItem(Parent, Target: HTreeItem; const Item: TTVItem;
- AddMode: TfcAddMode): HTreeItem;
- function InternalAddObject(Node: TfcTreeNode; const S: string;
- Ptr: Pointer; AddMode: TfcAddMode): TfcTreeNode;
- procedure DefineProperties(Filer: TFiler); override;
- function CreateItem(Node: TfcTreeNode): TTVItem;
- function GetCount: Integer;
- procedure SetItem(Index: Integer; Value: TfcTreeNode);
- procedure SetUpdateState(Updating: Boolean);
- public
- constructor Create(AOwner: TfcCustomTreeView);
- destructor Destroy; override;
- function AddChildFirst(Node: TfcTreeNode; const S: string): TfcTreeNode;
- function AddChild(Node: TfcTreeNode; const S: string): TfcTreeNode;
- function AddChildObjectFirst(Node: TfcTreeNode; const S: string;
- Ptr: Pointer): TfcTreeNode;
- function AddChildObject(Node: TfcTreeNode; const S: string;
- Ptr: Pointer): TfcTreeNode;
- function AddFirst(Node: TfcTreeNode; const S: string): TfcTreeNode;
- function Add(Node: TfcTreeNode; const S: string): TfcTreeNode;
- function AddObjectFirst(Node: TfcTreeNode; const S: string;
- Ptr: Pointer): TfcTreeNode;
- function AddObject(Node: TfcTreeNode; const S: string;
- Ptr: Pointer): TfcTreeNode;
- procedure Assign(Source: TPersistent); override;
- procedure BeginUpdate;
- procedure Clear;
- procedure Delete(Node: TfcTreeNode);
- procedure EndUpdate;
- function GetFirstNode: TfcTreeNode;
- function GetNode(ItemId: HTreeItem): TfcTreeNode;
- function Insert(Node: TfcTreeNode; const S: string): TfcTreeNode;
- function InsertObject(Node: TfcTreeNode; const S: string;
- Ptr: Pointer): TfcTreeNode;
- function FindNode(SearchText: string; VisibleOnly: Boolean): TfcTreeNode;
- function FindNodeInfo(SearchText: string; VisibleOnly: Boolean;
- StoreDataUsing: TwwStoreData = sdStoreText): TfcTreeNode;
- property Count: Integer read GetCount;
- property Handle: HWND read GetHandle;
- property Item[Index: Integer]: TfcTreeNode read GetNodeFromIndex; default;
- property Owner: TfcCustomTreeView read FOwner;
- end;
- { TfcCustomTreeView }
- TfcTVMultiSelectAttributes = class(TPersistent)
- private
- FEnabled: Boolean;
- FAutoUnselect: boolean;
- // FAlwaysIncludeSelectedItem: Boolean;
- FMultiSelectLevel: integer;
- FMultiSelectCheckbox: boolean;
- TreeView: TfcCustomTreeView;
- procedure SetEnabled(val: boolean);
- procedure SetMultiSelectLevel(val: integer);
- procedure SetMultiSelectCheckBox(val: boolean);
- public
- constructor Create(Owner: TComponent);
- procedure Assign(Source: TPersistent); override;
- published
- property AutoUnselect : boolean read FAutoUnselect write FAutoUnselect default True;
- // property AlwaysIncludeSelectedItem: Boolean read FAlwaysIncludeSelectedItem write FAlwaysIncludeSelectedItem default False;
- property Enabled: boolean read FEnabled write SetEnabled default False;
- property MultiSelectLevel: integer read FMultiSelectLevel write SetMultiSelectLevel default 0;
- property MultiSelectCheckbox: boolean read FMultiSelectCheckbox write SetMultiSelectCheckbox default True;
- end;
- TfcHitTest = (fchtAbove, fchtBelow, fchtNowhere, fchtOnItem, fchtOnButton, fchtOnIcon,
- fchtOnIndent, fchtOnLabel, fchtOnRight, fchtOnStateIcon, fchtToLeft, fchtToRight);
- TfcHitTests = set of TfcHitTest;
- TfcSortType = (fcstNone, fcstData, fcstText, fcstBoth);
- EfcTreeViewError = class(Exception);
- TfcTVChangingEvent = procedure(TreeView: TfcCustomTreeView; Node: TfcTreeNode;
- var AllowChange: Boolean) of object;
- TfcTVChangedEvent = procedure(TreeView: TfcCustomTreeView; Node: TfcTreeNode) of object;
- TfcTVEditingEvent = procedure(TreeView: TfcCustomTreeView; Node: TfcTreeNode;
- var AllowEdit: Boolean) of object;
- TfcTVEditedEvent = procedure(TreeView: TfcCustomTreeView; Node: TfcTreeNode; var S: string) of object;
- TfcTVExpandingEvent = procedure(TreeView: TfcCustomTreeView; Node: TfcTreeNode;
- var AllowExpansion: Boolean) of object;
- TfcTVCollapsingEvent = procedure(TreeView: TfcCustomTreeView; Node: TfcTreeNode;
- var AllowCollapse: Boolean) of object;
- TfcTVExpandedEvent = procedure(TreeView: TfcCustomTreeView; Node: TfcTreeNode) of object;
- TfcTVCompareEvent = procedure(TreeView: TfcCustomTreeView; Node1, Node2: TfcTreeNode;
- Data: Integer; var Compare: Integer) of object;
- TfcTVCustomDrawEvent = procedure(TreeView: TfcCustomTreeView; const ARect: TRect;
- var DefaultDraw: Boolean) of object;
- TfcCalcNodeAttributesEvent = procedure(TreeView: TfcCustomTreeView;
- Node: TfcTreeNode; State: TfcItemStates) of object;
- TfcItemChangeAction = (icaAdd, icaDelete, icaText, icaImageIndex);
- TfcItemChangeEvent = procedure(TreeView: TfcCustomTreeView; Node: TfcTreeNode;
- Action: TfcItemChangeAction; NewValue: Variant) of object;
- TfcToggleCheckboxEvent = procedure(TreeView: TfcCustomTreeView; Node: TfcTreeNode) of object;
- TfcTreeNodeClass = class of TfcTreeNode;
- TfcCustomTreeView = class(TWinControl)
- private
- FOnItemChange: TfcItemChangeEvent;
- // FOnItemChanging: TfcItemChangeEvent;
- FAutoExpand: Boolean;
- FBorderStyle: TBorderStyle;
- FCanvas: TfcCanvas;
- FPaintCanvas: TfcCanvas;
- FCanvasChanged: Boolean;
- FDefEditProc: Pointer;
- FDragged: Boolean;
- FDragImage: {$ifdef fcDelphi4Up}TDragImageList{$else}TCustomImageList{$endif};
- FDragNode: TfcTreeNode;
- FEditHandle: HWND;
- FEditInstance: Pointer;
- FImageChangeLink: TChangeLink;
- FImages: TCustomImageList;
- FLastDropTarget: TfcTreeNode;
- FManualNotify: Boolean;
- FMemStream: TMemoryStream;
- FRClickNode: TfcTreeNode;
- FRightClickSelects: Boolean;
- FReadOnly: Boolean;
- FSaveIndex: Integer;
- FSaveIndent: Integer;
- FSaveItems: TStringList;
- FSaveTopIndex: Integer;
- FSortType: TfcSortType;
- FStateChanging: Boolean;
- FStateImages: TCustomImageList;
- FStateChangeLink: TChangeLink;
- FStreamExpandedNode: Boolean;
- // FToolTips: Boolean;
- FTreeNodes: TfcTreeNodes;
- FWideText: WideString;
- FOnEditing: TfcTVEditingEvent;
- FOnEdited: TfcTVEditedEvent;
- FOnExpanded: TfcTVExpandedEvent;
- FOnExpanding: TfcTVExpandingEvent;
- FOnCollapsed: TfcTVExpandedEvent;
- FOnCollapsing: TfcTVCollapsingEvent;
- FOnChanging: TfcTVChangingEvent;
- FOnChange: TfcTVChangedEvent;
- FOnCompare: TfcTVCompareEvent;
- FOnDeletion: TfcTVExpandedEvent;
- FOnGetImageIndex: TfcTVExpandedEvent;
- FOnGetSelectedIndex: TfcTVExpandedEvent;
- FLineColor: TColor;
- FInactiveFocusColor: TColor;
- FOnMouseDown, FOnMouseUp, FOnDblClick: TfcTreeMouseEvent;
- FOnMouseMove: TfcTreeMouseMoveEvent;
- FOnToggleCheckbox: TfcToggleCheckboxEvent;
- FNodeClass: TfcTreeNodeClass;
- FMultiSelectAttributes: TfcTVMultiSelectAttributes;
- FOnCalcNodeAttributes: TfcCalcNodeAttributesEvent;
- FBorderWidth: Integer;
- FOnDrawText: TfcTVDrawTextEvent;
- // FFixBugImageList: TImageList;
- FOptions: TfcTreeViewOptions;
- FDisableThemes: boolean;
- FPaintBitmap: TBitmap;
- FIndent: Integer;
- LastSelectedNode: TfcTreeNode;
- MouseNode: TfcTreeNode;
- LastMouseMoveNode: TfcTreeNode; // For themes with checkboxes and radiobuttons invalidation
- LastMouseHitTest: TfcHitTests;
- ClickedNode: TfcTreeNode;
- Down: boolean;
- EditNode, BeforeMouseDownNode: TfcTreeNode;
- FStreamVersion: integer;
- FUsePaintBuffering: boolean;
- // FEditControl: TWinControl;
- procedure CanvasChanged(Sender: TObject);
- procedure CMColorChanged(var Message: TMessage); message CM_COLORCHANGED;
- procedure CMCtl3DChanged(var Message: TMessage); message CM_CTL3DCHANGED;
- procedure CMFontChanged(var Message: TMessage); message CM_FONTCHANGED;
- procedure CMDrag(var Message: TCMDrag); message CM_DRAG;
- procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
- procedure WMNCHitTest(var Message: TWMNCHitTest); message WM_NCHITTEST;
- procedure EditWndProc(var Message: TMessage);
- procedure DoDragOver(Source: TDragObject; X, Y: Integer; CanDrop: Boolean);
- function GetChangeDelay: Integer;
- function GetDropTarget: TfcTreeNode;
- function GetIndent: Integer;
- function GetNodeFromItem(const Item: TTVItem): TfcTreeNode;
- function GetSelection: TfcTreeNode;
- function GetTopItem: TfcTreeNode;
- procedure ImageListChange(Sender: TObject);
- procedure SetAutoExpand(Value: Boolean);
- procedure SetBorderStyle(Value: TBorderStyle);
- procedure SetChangeDelay(Value: Integer);
- procedure SetDropTarget(Value: TfcTreeNode);
- procedure SetImageList(Value: HImageList; Flags: Integer);
- procedure SetIndent(Value: Integer);
- procedure SetImages(Value: TCustomImageList);
- procedure SetReadOnly(Value: Boolean);
- procedure SetSelection(Value: TfcTreeNode);
- procedure SetSortType(Value: TfcSortType);
- procedure SetStateImages(Value: TCustomImageList);
- // procedure SetToolTips(Value: Boolean);
- procedure SeTfcTreeNodes(Value: TfcTreeNodes);
- procedure SetTopItem(Value: TfcTreeNode);
- procedure OnChangeTimer(Sender: TObject);
- procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
- procedure WMRButtonDown(var Message: TWMRButtonDown); message WM_RBUTTONDOWN;
- procedure WMRButtonUp(var Message: TWMRButtonUp); message WM_RBUTTONUP;
- procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
- procedure WMNotify(var Message: TWMNotify); message WM_NOTIFY;
- procedure CMSysColorChange(var Message: TMessage); message CM_SYSCOLORCHANGE;
- procedure WMPaint(var Message: TWMPaint); message WM_PAINT;
- procedure WMEraseBkgnd(var Message: TWmEraseBkgnd); message WM_ERASEBkgnd;
- procedure CMExit(var Message: TMessage); message CM_EXIT;
- procedure CMDesignHitTest(var Message: TCMDesignHitTest); message CM_DESIGNHITTEST;
- procedure WMDestroy(var Message: TWMDestroy); message WM_DESTROY;
- function ValidMultiSelectLevel(ALevel: Integer): Boolean;
- Function CheckboxNeeded(Node: TfcTreeNode): boolean;
- Function GetCenterPoint(ARect: TRect): TPoint;
- procedure SetOptions(Value: TfcTreeViewOptions);
- procedure SetLineColor(Value: TColor);
- procedure SetInactiveFocusColor(Value: TColor);
- function GetItemHeight: ShortInt;
- procedure SetItemHeight(Value: ShortInt);
- function GetScrollTime: Integer;
- procedure SetScrollTime(Value: Integer);
- function GetMultiSelectListCount: integer;
- function GetMultiSelectItem(Index: integer): TfcTreeNode;
- procedure HintTimerEvent(Sender: TObject);
- function GetPaintCanvas: TfcCanvas;
- protected
- FMultiSelectList: TList;
- SkipErase: boolean;
- SkipChangeMessages: boolean; { Notify method skips processing of change notifications }
- InLoading: boolean; { During expansion of Reference tree,
- do not recursively expand item's children.
- Calling MoveTo expands parent so we prevent this}
- FChangeTimer: TTimer;
- DisplayedItems: integer;
- FMouseInControl : boolean;
- { Implement hint handling }
- HintWindow: THintWindow;
- HintTimer: TTimer;
- HintTimerCount: integer;
- LastHintNode: TfcTreeNode;
- function CanEdit(Node: TfcTreeNode): Boolean; dynamic;
- function CanChange(Node: TfcTreeNode): Boolean; dynamic;
- function CanCollapse(Node: TfcTreeNode): Boolean; dynamic;
- function CanExpand(Node: TfcTreeNode): Boolean; dynamic;
- procedure Change(Node: TfcTreeNode); dynamic;
- procedure Collapse(Node: TfcTreeNode); dynamic;
- function CreateNode: TfcTreeNode; virtual;
- procedure CreateParams(var Params: TCreateParams); override;
- procedure CreateWnd; override;
- procedure Delete(Node: TfcTreeNode); dynamic;
- procedure DestroyWnd; override;
- procedure DoEndDrag(Target: TObject; X, Y: Integer); override;
- procedure DoStartDrag(var DragObject: TDragObject); override;
- procedure Edit(const Item: TTVItem); dynamic;
- procedure Expand(Node: TfcTreeNode); dynamic;
- function GetDragImages: {$ifdef fcDelphi4Up}TDragImageList{$else}TCustomImageList{$endif}; override;
- procedure GetImageIndex(Node: TfcTreeNode); virtual;
- procedure GetSelectedIndex(Node: TfcTreeNode); virtual;
- procedure Loaded; override;
- procedure KeyPress(var Key: Char); override;
- procedure KeyDown(var Key: Word; Shift: TShiftState); override;
- procedure Notification(AComponent: TComponent;
- Operation: TOperation); override;
- procedure SetDragMode(Value: TDragMode); override;
- procedure WndProc(var Message: TMessage); override;
- property AutoExpand: Boolean read FAutoExpand write SetAutoExpand default False;
- property BorderStyle: TBorderStyle read FBorderStyle write SetBorderStyle default bsSingle;
- property ChangeDelay: Integer read GetChangeDelay write SetChangeDelay default 0;
- property Images: TCustomImageList read FImages write SetImages;
- property Indent: Integer read GetIndent write SetIndent;
- property ReadOnly: Boolean read FReadOnly write SetReadOnly default False;
- property RightClickSelects: Boolean read FRightClickSelects write FRightClickSelects default False;
- property SortType: TfcSortType read FSortType write SetSortType default fcstNone;
- property StateImages: TCustomImageList read FStateImages write SetStateImages;
- property StreamExpandedNode: Boolean read FStreamExpandedNode write FStreamExpandedNode default False;
- // property ToolTips: Boolean read FToolTips write SetToolTips default False;
- property OnEditing: TfcTVEditingEvent read FOnEditing write FOnEditing;
- property OnEdited: TfcTVEditedEvent read FOnEdited write FOnEdited;
- property OnExpanding: TfcTVExpandingEvent read FOnExpanding write FOnExpanding;
- property OnExpanded: TfcTVExpandedEvent read FOnExpanded write FOnExpanded;
- property OnCollapsing: TfcTVCollapsingEvent read FOnCollapsing write FOnCollapsing;
- property OnCollapsed: TfcTVExpandedEvent read FOnCollapsed write FOnCollapsed;
- property OnChanging: TfcTVChangingEvent read FOnChanging write FOnChanging;
- property OnChange: TfcTVChangedEvent read FOnChange write FOnChange;
- property OnCompare: TfcTVCompareEvent read FOnCompare write FOnCompare;
- property OnDeletion: TfcTVExpandedEvent read FOnDeletion write FOnDeletion;
- property OnGetImageIndex: TfcTVExpandedEvent read FOnGetImageIndex write FOnGetImageIndex;
- property OnGetSelectedIndex: TfcTVExpandedEvent read FOnGetSelectedIndex write FOnGetSelectedIndex;
- procedure MultiSelectNode(Node: TfcTreeNode; Select: boolean; redraw: boolean); virtual;
- function IsVisible(Node: TfcTreeNode; PartialOK: Boolean): Boolean; virtual;
- function ItemRect(Node: TfcTreeNode; LabelOnly: Boolean): TRect;
- procedure PaintButton(Node: TfcTreeNode; pt: TPoint; size: integer);
- procedure PaintLines(Node: TfcTreeNode);
- procedure PaintImage(Node: TfcTreeNode; State: TfcItemStates);
- function LevelRect(ANode: TfcTreeNode): TRect;
- procedure DoDrawText(TreeView: TfcCustomTreeView;
- Node: TfcTreeNode; ARect: TRect; AItemState: TfcItemStates;
- var DefaultDrawing: boolean); virtual;
- procedure Compare(Node1, Node2: TfcTreeNode; lParam: integer; var Result: integer); virtual;
- procedure CalcNodeAttributes(Node: TfcTreeNode; AItemState: TfcItemStates); virtual;
- function GetDisplayText(Node: TfcTreeNode): string; virtual;
- procedure LoadCanvasDefaults(Node: TfcTreeNode; AItemState: TfcItemStates);
- function ProcessKeyPress(Key: char; shift: TShiftState): boolean; virtual;
- function IsRowSelect: boolean; virtual;
- procedure MouseLoop(X, Y: Integer); virtual;
- procedure MouseDown(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer); override;
- function UseImages(Node: TfcTreeNode): Boolean;
- function UseStateImages(Node: TfcTreeNode): Boolean;
- procedure BeginPainting; virtual;
- procedure EndPainting; virtual;
- procedure BeginItemPainting(Node: TfcTreeNode; ARect: TRect; AItemState: TfcItemStates); virtual;
- procedure EndItemPainting(Node: TfcTreeNode; ARect: TRect; AItemState: TfcItemStates); virtual;
- procedure PaintItem(Node: TfcTreeNode); virtual;
- procedure ClearStateImageIndexes;
- procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
- procedure MouseUp(Button: TMouseButton; Shift: TShiftState;
- X, Y: Integer); override;
- procedure DoToggleCheckbox(Node: TfcTreeNode); virtual;
- procedure FreeHintWindow; virtual;
- Function CreateHintWindow(Node: TfcTreeNode): THintWindow; virtual;
- Procedure UnselectAllNodes(IgnoreNode: TfcTreeNode);
- procedure InvalidateNoErase;
- property ItemHeight: ShortInt read GetItemHeight write SetItemHeight;
- property OnCalcNodeAttributes: TfcCalcNodeAttributesEvent read FOnCalcNodeAttributes write FOnCalcNodeAttributes;
- property ScrollTime: Integer read GetScrollTime write SetScrollTime;
- property NodeClass: TfcTreeNodeClass read FNodeClass write FNodeClass;
- public
- Patch: Variant;
- procedure ResetStateImages;
- property StreamVersion: integer read FStreamVersion;
- Function GetFirstSibling(Node: TfcTreeNode): TfcTreeNode;
- Procedure InvalidateNode(Node: TfcTreeNode);
- Function MultiSelectCheckboxNeeded(Node: TfcTreeNode): boolean;
- Procedure UnselectAll;
- constructor Create(AOwner: TComponent); override;
- destructor Destroy; override;
- function AlphaSort: Boolean;
- function CustomSort(SortProc: TTVCompare; Data: Longint): Boolean;
- procedure FullCollapse;
- procedure FullExpand;
- function GetHitTestInfoAt(X, Y: Integer): TfcHitTests;
- function GetNodeAt(X, Y: Integer): TfcTreeNode;
- function IsEditing: Boolean;
- procedure LoadFromFile(const FileName: string);
- procedure LoadFromStream(Stream: TStream);
- procedure SaveToFile(const FileName: string);
- procedure SaveToStream(Stream: TStream);
- property Canvas: TfcCanvas read GetPaintCanvas;
- property DropTarget: TfcTreeNode read GetDropTarget write SetDropTarget;
- property Selected: TfcTreeNode read GetSelection write SetSelection;
- property TopItem: TfcTreeNode read GetTopItem write SetTopItem;
- property RightClickNode: TfcTreeNode read FRClickNode;
- property Options: TfcTreeViewOptions read FOptions write SetOptions default
- [tvoExpandOnDblClk, tvoShowButtons, tvoShowRoot, tvoShowLines, tvoHideSelection, tvoToolTips];
- property Items: TfcTreeNodes read FTreeNodes write SeTfcTreeNodes;
- property MultiSelectAttributes: TfcTVMultiSelectAttributes
- read FMultiSelectAttributes write FMultiSelectAttributes;
- property OnDrawText: TfcTVDrawTextEvent read FOnDrawText write FOnDrawText;
- property OnItemChange: TfcItemChangeEvent read FOnItemChange write FOnItemChange;
- property MultiSelectList[Index: Integer]: TfcTreeNode read GetMultiSelectItem;
- property MultiSelectListCount : integer read GetMultiSelectListCount;
- property LineColor: TColor read FLineColor write SetLineColor default clBtnShadow;
- property InactiveFocusColor: TColor read FInactiveFocusColor write SetInactiveFocusColor default clBtnFace;
- property OnMouseMove: TfcTreeMouseMoveEvent read FOnMouseMove write FOnMouseMove;
- property OnMouseDown: TfcTreeMouseEvent read FOnMouseDown write FOnMouseDown;
- property OnMouseUp: TfcTreeMouseEvent read FOnMouseUp write FOnMouseUp;
- property OnDblClick: TfcTreeMouseEvent read FOnDblClick write FOnDblClick;
- property OnToggleCheckbox: TfcToggleCheckboxEvent read FOnToggleCheckbox write FOnToggleCheckbox;
- property UsePaintBuffering: boolean read FUsePaintBuffering write FUsePaintBuffering default False;
- property DisableThemes : boolean read FDisableThemes write FDisableThemes default False;
- end;
- TfcTreeView = class(TfcCustomTreeView)
- published
- property DisableThemes;
- property Align;
- {$ifdef fcDelphi4Up}
- property Anchors;
- {$endif}
- property AutoExpand;
- {$ifdef fcDelphi4Up}
- property BiDiMode;
- {$endif}
- property BorderStyle;
- // property BorderWidth;
- property ChangeDelay;
- property Color;
- property LineColor;
- property InactiveFocusColor;
- property Ctl3D;
- {$ifdef fcDelphi4Up}
- property Constraints;
- property DragKind;
- {$endIf}
- property DragCursor;
- property DragMode;
- property Enabled;
- property Font;
- property Images;
- property Indent;
- property MultiSelectAttributes;
- property Options;
- property Items;
- {$ifdef fcDelphi4Up}
- property ParentBiDiMode;
- {$endif}
- property ParentColor default False;
- property ParentCtl3D;
- property ParentFont;
- property ParentShowHint;
- property UsePaintBuffering;
- property PopupMenu;
- property ReadOnly;
- property RightClickSelects;
- {$ifdef fcDelphi4Up}
- property ShowHint;
- {$endif}
- property SortType;
- property StateImages;
- property StreamExpandedNode;
- property TabOrder;
- property TabStop default True;
- // property ToolTips;
- property Visible;
- property OnChange;
- property OnChanging;
- property OnClick;
- property OnCollapsing;
- property OnCollapsed;
- property OnCompare;
- property OnDblClick;
- property OnDeletion;
- property OnDragDrop;
- property OnDragOver;
- property OnEdited;
- property OnEditing;
- {$ifdef fcDelphi4Up}
- property OnEndDock;
- {$endif}
- property OnEndDrag;
- property OnEnter;
- property OnExit;
- property OnExpanding;
- property OnExpanded;
- property OnGetImageIndex;
- property OnGetSelectedIndex;
- property OnKeyDown;
- property OnKeyPress;
- property OnKeyUp;
- property OnMouseDown;
- property OnMouseMove;
- property OnMouseUp;
- property OnToggleCheckbox;
- {$ifdef fcDelphi4Up}
- property OnStartDock;
- {$endif}
- property OnStartDrag;
- property OnCalcNodeAttributes;
- property OnDrawText;
- end;
- procedure fcTreeViewError(const Msg: string);
- implementation
- { TfcTreeNode }
- {$ifdef fcDelphi6Up}
- uses RTLConsts;
- {$endif}
- const MaxCheckboxSize = 6;
- FixBugImageListSize = 16;
- var FFixBugImageList: TImageList;
- RefCount: integer;
- procedure SetComCtlStyle(Ctl: TWinControl; Value: Integer; UseStyle: Boolean);
- var
- Style: Integer;
- begin
- if Ctl.HandleAllocated then
- begin
- Style := GetWindowLong(Ctl.Handle, GWL_STYLE);
- if not UseStyle then Style := Style and not Value
- else Style := Style or Value;
- SetWindowLong(Ctl.Handle, GWL_STYLE, Style);
- end;
- end;
- function DefaultTreeViewSort(Node1, Node2: TfcTreeNode; lParam: Integer): Integer; stdcall;
- begin
- // Result := lstrcmp(PChar(Node1.Text), PChar(Node2.Text));
- Node1.TreeView.Compare(Node1, Node2, lParam, Result);
- end;
- {
- function DefaultTreeViewSort(Node1, Node2: TfcTreeNode; lParam: Integer): Integer; stdcall;
- begin
- with Node1 do
- if Assigned(TreeView.OnCompare) then
- TreeView.OnCompare(TreeView, Node1, Node2, lParam, Result)
- else Result := lstrcmp(PChar(Node1.Text), PChar(Node2.Text));
- end;
- }
- procedure TreeViewError(const Msg: string);
- begin
- raise ETreeViewError.Create(Msg);
- end;
- {procedure TreeViewErrorFmt(const Msg: string; Format: array of const);
- begin
- raise ETreeViewError.CreateFmt(Msg, Format);
- end;
- }
- constructor TfcTreeNode.Create(AOwner: TfcTreeNodes);
- begin
- inherited Create;
- FOverlayIndex := -1;
- FStateIndex := -1;
- FOwner := AOwner;
- end;
- destructor TfcTreeNode.Destroy;
- var
- Node: TfcTreeNode;
- CheckValue: Integer;
- i: integer;
- MultiSelectList: TList;
- begin
- Owner.ClearCache;
- FDeleting := True;
- // 6/30/03 - Clear LastMouseMoveNode
- if fcUseThemes(TreeView) then
- begin
- if TfcCustomTreeView(TreeView).LastMouseMoveNode = Self then
- TfcCustomTreeView(TreeView).LastMouseMoveNode:= nil;
- end;
- if FMultiSelected then begin
- if TfcCustomTreeView(TreeView).LastSelectedNode= self then
- TfcCustomTreeView(TreeView).LastSelectedNode:= nil;
- MultiSelectList:= (TreeView as TfcCustomTreeView).FMultiSelectList;
- for i:= 0 to MultiSelectList.count-1 do begin { Bad code }
- if self=TfcTreeNode(MultiSelectList[i]) then
- begin
- MultiSelectList.delete(i);
- break;
- end
- end
- end;
- if Owner.Owner.FLastDropTarget = Self then
- Owner.Owner.FLastDropTarget := nil;
- Node := Parent;
- if (Node <> nil) and (not Node.Deleting) then
- begin
- if Node.IndexOf(Self) <> -1 then CheckValue := 1
- else CheckValue := 0;
- if Node.CompareCount(CheckValue) then
- begin
- Expanded := False;
- Node.HasChildren := False;
- end;
- end;
- if ItemId <> nil then TreeView_DeleteItem(Handle, ItemId);
- Data := nil;
- inherited Destroy;
- end;
- function TfcTreeNode.GetHandle: HWND;
- begin
- Result := TreeView.Handle;
- end;
- function TfcTreeNode.GetTreeView: TfcCustomTreeView;
- begin
- Result := Owner.Owner;
- end;
- function TfcTreeNode.HasAsParent(Value: TfcTreeNode): Boolean;
- begin
- if Value <> Nil then
- begin
- if Parent = nil then Result := False
- else if Parent = Value then Result := True
- else Result := Parent.HasAsParent(Value);
- end
- else Result := True;
- end;
- procedure TfcTreeNode.SetText(const S: string);
- var
- Item: TTVItem;
- AVariant: Variant;
- begin
- if s = '' then AVariant := NULL else AVariant := s;
- if Assigned(TreeView.OnItemChange) then TreeView.OnItemChange(TreeView, self, icaText, AVariant);
- FText := S;
- with Item do
- begin
- mask := TVIF_TEXT;
- hItem := ItemId;
- pszText := LPSTR_TEXTCALLBACK;
- end;
- TreeView_SetItem(Handle, Item);
- if (TreeView.SortType in [fcstText, fcstBoth]) and FInTree then
- begin
- if (Parent <> nil) then Parent.AlphaSort
- else TreeView.AlphaSort;
- end;
- end;
- procedure TfcTreeNode.SetData(Value: Pointer);
- begin
- FData := Value;
- if (TreeView.SortType in [fcstData, fcstBoth]) and Assigned(TreeView.OnCompare)
- and (not Deleting) and FInTree then
- begin
- if Parent <> nil then Parent.AlphaSort
- else TreeView.AlphaSort;
- end;
- end;
- function TfcTreeNode.GetState(NodeState: TfcNodeState): Boolean;
- var
- Item: TTVItem;
- begin
- Result := False;
- with Item do
- begin
- mask := TVIF_STATE;
- hItem := ItemId;
- if TreeView_GetItem(Handle, Item) then
- case NodeState of
- fcnsCut: Result := (state and TVIS_CUT) <> 0;
- fcnsFocused: Result := (state and TVIS_FOCUSED) <> 0;
- fcnsSelected: Result := (state and TVIS_SELECTED) <> 0;
- fcnsExpanded: Result := (state and TVIS_EXPANDED) <> 0;
- fcnsDropHilited: Result := (state and TVIS_DROPHILITED) <> 0;
- end;
- end;
- end;
- procedure TfcTreeNode.SetImageIndex(Value: Integer);
- var
- Item: TTVItem;
- begin
- if Assigned(TreeView.OnItemChange) then TreeView.OnItemChange(TreeView, self, icaImageIndex, Value);
- FImageIndex := Value;
- with Item do
- begin
- mask := TVIF_IMAGE or TVIF_HANDLE;
- hItem := ItemId;
- iImage := I_IMAGECALLBACK;
- end;
- TreeView_SetItem(Handle, Item);
- end;
- procedure TfcTreeNode.SetSelectedIndex(Value: Integer);
- var
- Item: TTVItem;
- begin
- FSelectedIndex := Value;
- with Item do
- begin
- mask := TVIF_SELECTEDIMAGE or TVIF_HANDLE;
- hItem := ItemId;
- iSelectedImage := I_IMAGECALLBACK;
- end;
- TreeView_SetItem(Handle, Item);
- end;
- procedure TfcTreeNode.SetOverlayIndex(Value: Integer);
- var
- Item: TTVItem;
- begin
- FOverlayIndex := Value;
- with Item do
- begin
- mask := TVIF_STATE or TVIF_HANDLE;
- stateMask := TVIS_OVERLAYMASK;
- hItem := ItemId;
- state := IndexToOverlayMask(OverlayIndex + 1);
- end;
- TreeView_SetItem(Handle, Item);
- end;
- procedure TfcTreeNode.SetStateIndex(Value: Integer);
- var
- Item: TTVItem;
- begin
- if Value=0 then Value:= -1; // 11/21/98 - (RSW) Don't allow 0 as state index
- if (CheckboxType = tvctCheckbox) and (Value<>-1) and (Value<>1) then exit; { 3/8/99}
- FStateIndex := Value;
- if Value >= 0 then Dec(Value);
- with Item do
- begin
- mask := TVIF_STATE or TVIF_HANDLE;
- stateMask := TVIS_STATEIMAGEMASK;
- hItem := ItemId;
- state := IndexToStateImageMask(Value + 1);
- end;
- TreeView_SetItem(Handle, Item);
- end;
- function TfcTreeNode.CompareCount(CompareMe: Integer): Boolean;
- var
- Count: integer;
- Node: TfcTreeNode;
- Begin
- Count := 0;
- Result := False;
- Node := GetFirstChild;
- while Node <> nil do
- begin
- Inc(Count);
- Node := Node.GetNextChild(Node);
- if Count > CompareMe then Exit;
- end;
- if Count = CompareMe then Result := True;
- end;
- function TfcTreeNode.DoCanExpand(Expand: Boolean): Boolean;
- begin
- Result := False;
- if HasChildren then
- begin
- if Expand then Result := TreeView.CanExpand(Self)
- else Result := TreeView.CanCollapse(Self);
- end;
- end;
- procedure TfcTreeNode.DoExpand(Expand: Boolean);
- begin
- if HasChildren then
- begin
- if Expand then TreeView.Expand(Self)
- else TreeView.Collapse(Self);
- end;
- end;
- procedure TfcTreeNode.ExpandItem(Expand: Boolean; Recurse: Boolean);
- var
- Flag: Integer;
- Node: TfcTreeNode;
- begin
- if Recurse then
- begin
- Node := Self;
- repeat
- Node.ExpandItem(Expand, False);
- Node := Node.GetNext;
- until (Node = nil) or (not Node.HasAsParent(Self));
- end
- else begin
- TreeView.FManualNotify := True;
- try
- Flag := 0;
- if Expand then
- begin
- if DoCanExpand(True) then
- begin
- Flag := TVE_EXPAND;
- DoExpand(True);
- end;
- end
- else begin
- if DoCanExpand(False) then
- begin
- Flag := TVE_COLLAPSE;
- DoExpand(False);
- end;
- end;
- if Flag <> 0 then TreeView_Expand(Handle, ItemId, Flag);
- finally
- TreeView.FManualNotify := False;
- end;
- end;
- end;
- procedure TfcTreeNode.Expand(Recurse: Boolean);
- begin
- ExpandItem(True, Recurse);
- end;
- procedure TfcTreeNode.Collapse(Recurse: Boolean);
- begin
- ExpandItem(False, Recurse);
- end;
- function TfcTreeNode.GetExpanded: Boolean;
- begin
- Result := GetState(fcnsExpanded);
- end;
- procedure TfcTreeNode.SetExpanded(Value: Boolean);
- begin
- if Value then Expand(False)
- else Collapse(False);
- end;
- function TfcTreeNode.GetSelected: Boolean;
- begin
- Result := GetState(fcnsSelected);
- end;
- procedure TfcTreeNode.SetSelected(Value: Boolean);
- begin
- if Value then TreeView_SelectItem(Handle, ItemId)
- else if Selected then TreeView_SelectItem(Handle, nil);
- end;
- function TfcTreeNode.GetCut: Boolean;
- begin
- Result := GetState(fcnsCut);
- end;
- procedure TfcTreeNode.SetCut(Value: Boolean);
- var
- Item: TTVItem;
- Template: DWORD;
- begin
- if Value then Template := DWORD(-1)
- else Template := 0;
- with Item do
- begin
- mask := TVIF_STATE;
- hItem := ItemId;
- stateMask := TVIS_CUT;
- state := stateMask and Template;
- end;
- TreeView_SetItem(Handle, Item);
- end;
- function TfcTreeNode.GetDropTarget: Boolean;
- begin
- Result := GetState(fcnsDropHilited);
- end;
- procedure TfcTreeNode.SetDropTarget(Value: Boolean);
- begin
- if Value then TreeView_SelectDropTarget(Handle, ItemId)
- else if DropTarget then TreeView_SelectDropTarget(Handle, nil);
- end;
- function TfcTreeNode.GetChildren: Boolean;
- var
- Item: TTVItem;
- begin
- Item.mask := TVIF_CHILDREN;
- Item.hItem := ItemId;
- if TreeView_GetItem(Handle, Item) then Result := Item.cChildren > 0
- else Result := False;
- end;
- procedure TfcTreeNode.SetFocused(Value: Boolean);
- var
- Item: TTVItem;
- Template: DWORD;
- begin
- if Value then Template := DWORD(-1)
- else Template := 0;
- with Item do
- begin
- mask := TVIF_STATE;
- hItem := ItemId;
- stateMask := TVIS_FOCUSED;
- state := stateMask and Template;
- end;
- TreeView_SetItem(Handle, Item);
- end;
- function TfcTreeNode.GetFocused: Boolean;
- begin
- Result := GetState(fcnsFocused);
- end;
- procedure TfcTreeNode.SetChildren(Value: Boolean);
- var
- Item: TTVItem;
- begin
- with Item do
- begin
- mask := TVIF_CHILDREN;
- hItem := ItemId;
- cChildren := Ord(Value);
- end;
- TreeView_SetItem(Handle, Item);
- end;
- function TfcTreeNode.GetParent: TfcTreeNode;
- begin
- with FOwner do
- Result := GetNode(TreeView_GetParent(Handle, ItemId));
- end;
- function TfcTreeNode.GetNextSibling: TfcTreeNode;
- begin
- with FOwner do
- Result := GetNode(TreeView_GetNextSibling(Handle, ItemId));
- end;
- function TfcTreeNode.GetPrevSibling: TfcTreeNode;
- begin
- with FOwner do
- Result := GetNode(TreeView_GetPrevSibling(Handle, ItemId));
- end;
- function TfcTreeNode.GetNextVisible: TfcTreeNode;
- begin
- if IsVisible then
- with FOwner do
- Result := GetNode(TreeView_GetNextVisible(Handle, ItemId))
- else Result := nil;
- end;
- function TfcTreeNode.GetPrevVisible: TfcTreeNode;
- begin
- with FOwner do
- Result := GetNode(TreeView_GetPrevVisible(Handle, ItemId));
- end;
- function TfcTreeNode.GetNextChild(Value: TfcTreeNode): TfcTreeNode;
- begin
- if Value <> nil then Result := Value.GetNextSibling
- else Result := nil;
- end;
- function TfcTreeNode.GetPrevChild(Value: TfcTreeNode): TfcTreeNode;
- begin
- if Value <> nil then Result := Value.GetPrevSibling
- else Result := nil;
- end;
- function TfcTreeNode.GetFirstChild: TfcTreeNode;
- begin
- with FOwner do
- Result := GetNode(TreeView_GetChild(Handle, ItemId));
- end;
- function TfcTreeNode.GetLastChild: TfcTreeNode;
- var
- Node: TfcTreeNode;
- begin
- Result := GetFirstChild;
- if Result <> nil then
- begin
- Node := Result;
- repeat
- Result := Node;
- Node := Result.GetNextSibling;
- until Node = nil;
- end;
- end;
- function TfcTreeNode.GetNext: TfcTreeNode;
- var
- NodeID, ParentID: HTreeItem;
- Handle: HWND;
- begin
- Handle := FOwner.Handle;
- NodeID := TreeView_GetChild(Handle, ItemId);
- if NodeID = nil then NodeID := TreeView_GetNextSibling(Handle, ItemId);
- ParentID := ItemId;
- while (NodeID = nil) and (ParentID <> nil) do
- begin
- ParentID := TreeView_GetParent(Handle, ParentID);
- NodeID := TreeView_GetNextSibling(Handle, ParentID);
- end;
- Result := FOwner.GetNode(NodeID);
- end;
- function TfcTreeNode.GetPrev: TfcTreeNode;
- var
- Node: TfcTreeNode;
- begin
- Result := GetPrevSibling;
- if Result <> nil then
- begin
- Node := Result;
- repeat
- Result := Node;
- Node := Result.GetLastChild;
- until Node = nil;
- end else
- Result := Parent;
- end;
- function TfcTreeNode.GetAbsoluteIndex: Integer;
- var
- Node: TfcTreeNode;
- begin
- if Owner.FNodeCache.CacheNode = Self then
- Result := Owner.FNodeCache.CacheIndex
- else begin
- Result := -1;
- Node := Self;
- while Node <> nil do
- begin
- Inc(Result);
- Node := Node.GetPrev;
- end;
- end;
- end;
- function TfcTreeNode.GetIndex: Integer;
- var
- Node: TfcTreeNode;
- begin
- Result := -1;
- Node := Self;
- while Node <> nil do
- begin
- Inc(Result);
- Node := Node.GetPrevSibling;
- end;
- end;
- function TfcTreeNode.GetItem(Index: Integer): TfcTreeNode;
- begin
- Result := GetFirstChild;
- while (Result <> nil) and (Index > 0) do
- begin
- Result := GetNextChild(Result);
- Dec(Index);
- end;
- if Result = nil then TreeViewError(SListIndexError);
- end;
- procedure TfcTreeNode.SetItem(Index: Integer; Value: TfcTreeNode);
- begin
- item[Index].Assign(Value);
- end;
- function TfcTreeNode.IndexOf(Value: TfcTreeNode): Integer;
- var
- Node: TfcTreeNode;
- begin
- Result := -1;
- Node := GetFirstChild;
- while (Node <> nil) do
- begin
- Inc(Result);
- if Node = Value then Break;
- Node := GetNextChild(Node);
- end;
- if Node = nil then Result := -1;
- end;
- function TfcTreeNode.GetCount: Integer;
- var
- Node: TfcTreeNode;
- begin
- Result := 0;
- Node := GetFirstChild;
- while Node <> nil do
- begin
- Inc(Result);
- Node := Node.GetNextChild(Node);
- end;
- end;
- procedure TfcTreeNode.EndEdit(Cancel: Boolean);
- begin
- TreeView_EndEditLabelNow(Handle, Cancel);
- end;
- procedure TfcTreeNode.InternalMove(ParentNode, Node: TfcTreeNode;
- HItem: HTreeItem; AddMode: TfcAddMode);
- var
- I: Integer;
- NodeId: HTreeItem;
- TreeViewItem: TTVItem;
- Children: Boolean;
- IsSelected: Boolean;
- begin
- { if ParentNode = Node then Exit; }
- Owner.ClearCache;
- if (AddMode = fctaInsert) and (Node <> nil) then
- NodeId := Node.ItemId else
- NodeId := nil;
- Children := HasChildren;
- IsSelected := Selected;
- if (Parent <> nil) and (Parent.CompareCount(1)) then
- begin
- Parent.Expanded := False;
- Parent.HasChildren := False;
- end;
- with TreeViewItem do
- begin
- mask := TVIF_PARAM;
- hItem := ItemId;
- lParam := 0;
- end;
- TreeView_SetItem(Handle, TreeViewItem);
- with Owner do
- HItem := AddItem(HItem, NodeId, CreateItem(Self), AddMode);
- if HItem = nil then
- raise EOutOfResources.Create(sInsertError);
- for I := Count - 1 downto 0 do
- Item[I].InternalMove(Self, nil, HItem, fctaAddFirst);
- TreeView_DeleteItem(Handle, ItemId);
- FItemId := HItem;
- Assign(Self);
- HasChildren := Children;
- Selected := IsSelected;
- end;
- procedure TfcTreeNode.MoveTo(Destination: TfcTreeNode; Mode: TfcNodeAttachMode);
- var
- AddMode: TfcAddMode;
- Node: TfcTreeNode;
- HItem: HTreeItem;
- OldOnChanging: TfcTVChangingEvent;
- OldOnChange: TfcTVChangedEvent;
- begin
- OldOnChanging := TreeView.OnChanging;
- OldOnChange := TreeView.OnChange;
- TreeView.OnChanging := nil;
- TreeView.OnChange := nil;
- try
- if (Destination = nil) or not Destination.HasAsParent(Self) then
- begin
- AddMode := fctaAdd;
- if (Destination <> nil) and not (Mode in [fcnaAddChild, fcnaAddChildFirst]) then
- Node := Destination.Parent else
- Node := Destination;
- case Mode of
- fcnaAdd,
- fcnaAddChild: AddMode := fctaAdd;
- fcnaAddFirst,
- fcnaAddChildFirst: AddMode := fctaAddFirst;
- fcnaInsert:
- begin
- Destination := Destination.GetPrevSibling;
- if Destination = Self then exit;
- if Destination = nil then AddMode := fctaAddFirst
- else AddMode := fctaInsert;
- end;
- fcnaInsertAfter:
- begin
- if Destination.GetNextSibling = nil then AddMode := fctaAdd
- else AddMode := fctaInsert;
- end;
- end;
- if Node <> nil then
- HItem := Node.ItemId else
- HItem := nil;
- InternalMove(Node, Destination, HItem, AddMode);
- Node := Parent;
- if Node <> nil then
- begin
- Node.HasChildren := True;
- Node.Expanded := True;
- end;
- end;
- finally
- TreeView.OnChanging := OldOnChanging;
- TreeView.OnChange := OldOnChange;
- Invalidate;
- end;
- end;
- procedure TfcTreeNode.MakeVisible;
- begin
- TreeView_EnsureVisible(Handle, ItemId);
- end;
- function TfcTreeNode.GetLevel: Integer;
- var
- Node: TfcTreeNode;
- begin
- Result := 0;
- Node := Parent;
- while Node <> nil do
- begin
- Inc(Result);
- Node := Node.Parent;
- end;
- end;
- function TfcTreeNode.IsNodeVisible: Boolean;
- var
- Rect: TRect;
- begin
- Result := TreeView_GetItemRect(Handle, ItemId, Rect, True);
- end;
- function TfcTreeNode.EditText: Boolean;
- begin
- Result := TreeView_EditLabel(Handle, ItemId) <> 0;
- end;
- {function TfcTreeNode.ShowBlankImage: boolean;
- begin
- result:= not ((TreeView.Images<>nil) and (ImageIndex=-2));
- end;
- }
- function TfcTreeNode.DisplayRect(TextOnly: Boolean): TRect;
- begin
- FillChar(Result, SizeOf(Result), 0);
- TreeView_GetItemRect(Handle, ItemId, Result, TextOnly);
- { Special case of imageindex=-2, do not show blank image }
- if TextOnly and (TreeView.Images<>nil) and not TreeView.UseImages(self) then
- result.Left:= result.Left - TImageList(TreeView.Images).Width-1
- end;
- function TfcTreeNode.AlphaSort: Boolean;
- begin
- Result := CustomSort(nil, 0);
- end;
- function TfcTreeNode.CustomSort(SortProc: TTVCompare; Data: Longint): Boolean;
- var
- SortCB: TTVSortCB;
- begin
- Owner.ClearCache;
- with SortCB do
- begin
- if not Assigned(SortProc) then lpfnCompare := @DefaultTreeViewSort
- else lpfnCompare := SortProc;
- hParent := ItemId;
- lParam := Data;
- end;
- Result := TreeView_SortChildrenCB(Handle, SortCB, 0);
- end;
- procedure TfcTreeNode.Delete;
- begin
- if not Deleting then Free;
- end;
- procedure TfcTreeNode.DeleteChildren;
- begin
- Owner.ClearCache;
- TreeView_Expand(TreeView.Handle, ItemID, TVE_COLLAPSE or TVE_COLLAPSERESET);
- HasChildren := False;
- end;
- procedure TfcTreeNode.Assign(Source: TPersistent);
- var
- Node: TfcTreeNode;
- begin
- Owner.ClearCache;
- if Source is TfcTreeNode then
- begin
- Node := TfcTreeNode(Source);
- Text := Node.Text;
- Data := Node.Data;
- CheckboxType:= Node.CheckboxType; { 4/26/99 - Do before assign State Index }
- StringData:= Node.StringData;
- StringData2:= Node.StringData2;
- ImageIndex := Node.ImageIndex;
- SelectedIndex := Node.SelectedIndex;
- StateIndex := Node.StateIndex;
- OverlayIndex := Node.OverlayIndex;
- Focused := Node.Focused;
- DropTarget := Node.DropTarget;
- Cut := Node.Cut;
- HasChildren := Node.HasChildren;
- // CheckboxType:= Node.CheckboxType;
- Checked:= Node.Checked;
- end
- else inherited Assign(Source);
- end;
- {function TfcTreeNode.IsEqual(Node: TfcTreeNode): Boolean;
- begin
- Result := (Text = Node.Text) and (Data = Node.Data);
- end;
- }
- procedure TfcTreeNode.ReadData(Stream: TStream; Info: PfcNodeInfo);
- var
- I, Size, ItemCount: Integer;
- StrBuffer: PChar;
- Temp: Integer;
- UseExpanded:Boolean;
- begin
- Owner.ClearCache;
- Stream.ReadBuffer(Size, SizeOf(Size));
- { 7/6/99 - Save for fcTreeCombo streaming }
- {$ifdef fcDelphi4Up}
- ReadDataSize:= Size;
- {$endif}
- { RSW - Advance if somehow size is greater than node size }
- Stream.ReadBuffer(Info^, fcmin(Size, SizeOf(Info^)));
- Temp := SizeOf(TfcNodeInfo) - (255 - Length(Info^.Text));
- { Support StringData property }
- if Info^.StringDataSize1>0 then
- begin
- StrBuffer:= StrAlloc(Info^.StringDataSize1+1);
- StrBuffer[Info^.StringDataSize1]:= #0;
- Stream.ReadBuffer(StrBuffer^, Info^.StringDataSize1);
- StringData:= StrPas(StrBuffer);
- StrDispose(StrBuffer);
- end
- else StringData:= '';
- { Support StringData property }
- if Info^.StringDataSize2>0 then
- begin
- StrBuffer:= StrAlloc(Info^.StringDataSize2+1);
- StrBuffer[Info^.StringDataSize2]:= #0;
- Stream.ReadBuffer(StrBuffer^, Info^.StringDataSize2);
- StringData2:= StrPas(StrBuffer);
- StrDispose(StrBuffer);
- end
- else StringData2:= '';
- Text := Info^.Text;
- ImageIndex := Info^.ImageIndex;
- SelectedIndex := Info^.SelectedIndex;
- StateIndex := Info^.StateIndex;
- OverlayIndex := Info^.OverlayIndex;
- Data := Info^.Data;
- ItemCount := Info^.Count;
- CheckboxType:= Info^.CheckboxType;
- Checked:= (Info^.Checked and $01)<>0;
- Grayed:= (Info^.Checked and $02)<>0;
- UseExpanded:= Info^.Expanded;
- for I := 0 to ItemCount - 1 do
- with Owner.AddChild(Self, '') do ReadData(Stream, Info);
- // 1/31/2002-PYW-Added new property to respect expanded node settings.
- if (Owner.Owner<>nil) and (Owner.Owner.StreamExpandedNode) then
- Expanded := UseExpanded;
- if TreeView.StreamVersion=1 then
- if Size > Temp then Stream.Position:= Stream.Position + (Size - Temp);
- end;
- Function TfcTreeNode.GetSizeOfNodeInfo: integer;
- begin
- result:= SizeOf(TfcNodeInfo);
- end;
- procedure TfcTreeNode.WriteData(Stream: TStream; Info: PfcNodeInfo);
- var
- Size, L, ItemCount: Integer;
- Node: TfcTreeNode;
- begin
- L := Length(Text);
- if L > 255 then L := 255;
- Size := GetSizeOfNodeInfo + L - 255;
- // Size := SizeOf(TfcNodeInfo) + L - 255;
- FillChar(Info^, SizeOf(TfcNodeInfo), 0);
- Info^.Text := Text;
- Info^.ImageIndex := ImageIndex;
- Info^.SelectedIndex := SelectedIndex;
- Info^.OverlayIndex := OverlayIndex;
- Info^.StateIndex := StateIndex;
- Info^.Data := Data;
- ItemCount := Count;
- Info^.Count := ItemCount;
- Info^.CheckboxType:= CheckboxType;
- Info^.Checked:= ord(Checked) + $02 * Ord(Grayed);
- Info^.Expanded := Expanded;
- Info^.StringDataSize1:= length(StringData);
- Info^.StringDataSize2:= length(StringData2);
- Stream.WriteBuffer(Size, SizeOf(Size));
- Stream.WriteBuffer(Info^, Size);
- { Support StringData properties }
- if Info^.StringDataSize1>0 then begin
- Stream.WriteBuffer(PChar(StringData)^, length(StringData));
- end;
- if Info^.StringDataSize2>0 then begin
- Stream.WriteBuffer(PChar(StringData2)^, length(StringData2));
- end;
- Node := GetFirstChild;
- while Node <> nil do
- begin
- Node.WriteData(Stream, Info);
- Node := Node.GetNextSibling;
- end;
- // for I := 0 to ItemCount - 1 do Item[I].WriteData(Stream, Info);
- end;
- { TfcTreeNodes }
- constructor TfcTreeNodes.Create(AOwner: TfcCustomTreeView);
- begin
- inherited Create;
- FOwner := AOwner;
- end;
- destructor TfcTreeNodes.Destroy;
- begin
- InDestroy:= True;
- Clear;
- // FOwner := nil;
- inherited Destroy;
- end;
- function TfcTreeNodes.GetCount: Integer;
- begin
- if Owner.HandleAllocated then Result := TreeView_GetCount(Handle)
- else Result := 0;
- end;
- function TfcTreeNodes.GetHandle: HWND;
- begin
- Result := Owner.Handle;
- end;
- procedure TfcTreeNodes.Delete(Node: TfcTreeNode);
- begin
- if (Node.ItemId = nil) then
- Owner.Delete(Node);
- Node.Delete;
- end;
- procedure TfcTreeNodes.Clear;
- var PrevNode, Node: TfcTreeNode;
- begin
- ClearCache;
- if { (Owner <> nil) and ksw - prevent problem }Owner.HandleAllocated then
- begin
- if count<=0 then exit;
- Owner.SkipChangeMessages:= True;
- try
- BeginUpdate;
- Owner.Selected:= nil;
- { Clearing by scanning backwards seems to be significantly faster }
- { TreeView_DeleteAllItem's current implementation is slower than this
- { technique. Scanning forwards is also slower. }
- Node := GetFirstNode;
- Owner.TopItem:= Node;
- { Retrieve last node }
- while Node.GetNextSibling <> nil do Node:= Node.GetNextSibling;
- while Node.GetNext <> nil do Node:= Node.GetNext;
- While Node<>Nil do
- begin
- PrevNode:= Node;
- Node := Node.GetPrev;
- TreeView_DeleteItem(PrevNode.Handle, PrevNode.ItemId);
- end;
- finally
- Owner.SkipChangeMessages:= False;
- if not inDestroy then EndUpdate;
- end
- end
- end;
- {procedure TfcTreeNodes.Clear;
- begin
- ClearCache;
- if Owner.HandleAllocated then
- TreeView_DeleteAllItems(Handle);
- end;}
- function TfcTreeNodes.AddChildFirst(Node: TfcTreeNode; const S: string): TfcTreeNode;
- begin
- Result := AddChildObjectFirst(Node, S, nil);
- end;
- function TfcTreeNodes.AddChildObjectFirst(Node: TfcTreeNode; const S: string;
- Ptr: Pointer): TfcTreeNode;
- begin
- Result := InternalAddObject(Node, S, Ptr, fctaAddFirst);
- end;
- function TfcTreeNodes.AddChild(Node: TfcTreeNode; const S: string): TfcTreeNode;
- begin
- Result := AddChildObject(Node, S, nil);
- end;
- function TfcTreeNodes.AddChildObject(Node: TfcTreeNode; const S: string;
- Ptr: Pointer): TfcTreeNode;
- begin
- Result := InternalAddObject(Node, S, Ptr, fctaAdd);
- end;
- function TfcTreeNodes.AddFirst(Node: TfcTreeNode; const S: string): TfcTreeNode;
- begin
- Result := AddObjectFirst(Node, S, nil);
- end;
- function TfcTreeNodes.AddObjectFirst(Node: TfcTreeNode; const S: string;
- Ptr: Pointer): TfcTreeNode;
- begin
- if Node <> nil then Node := Node.Parent;
- Result := InternalAddObject(Node, S, Ptr, fctaAddFirst);
- end;
- function TfcTreeNodes.Add(Node: TfcTreeNode; const S: string): TfcTreeNode;
- begin
- Result := AddObject(Node, S, nil);
- end;
- procedure TfcTreeNodes.Repaint(Node: TfcTreeNode);
- var
- R: TRect;
- begin
- if FUpdateCount < 1 then
- begin
- while (Node <> nil) and not Node.IsVisible do Node := Node.Parent;
- if Node <> nil then
- begin
- R := Node.DisplayRect(False);
- InvalidateRect(Owner.Handle, @R, True);
- end;
- end;
- end;
- function TfcTreeNodes.AddObject(Node: TfcTreeNode; const S: string;
- Ptr: Pointer): TfcTreeNode;
- begin
- if Node <> nil then Node := Node.Parent;
- Result := InternalAddObject(Node, S, Ptr, fctaAdd);
- end;
- function TfcTreeNodes.Insert(Node: TfcTreeNode; const S: string): TfcTreeNode;
- begin
- Result := InsertObject(Node, S, nil);
- end;
- procedure TfcTreeNodes.AddedNode(Value: TfcTreeNode);
- begin
- if Value <> nil then
- begin
- Value.HasChildren := True;
- Repaint(Value);
- end;
- end;
- function TfcTreeNodes.InsertObject(Node: TfcTreeNode; const S: string;
- Ptr: Pointer): TfcTreeNode;
- var
- Item, ItemId: HTreeItem;
- Parent: TfcTreeNode;
- AddMode: TfcAddMode;
- begin
- Result := Owner.CreateNode;
- try
- Item := nil;
- ItemId := nil;
- Parent := nil;
- AddMode := fctaInsert;
- if Node <> nil then
- begin
- Parent := Node.Parent;
- if Parent <> nil then Item := Parent.ItemId;
- Node := Node.GetPrevSibling;
- if Node <> nil then ItemId := Node.ItemId
- else AddMode := fctaAddFirst;
- end;
- Result.Data := Ptr;
- Result.Text := S;
- Item := AddItem(Item, ItemId, CreateItem(Result), AddMode);
- if Item = nil then
- raise EOutOfResources.Create(sInsertError);
- Result.FItemId := Item;
- AddedNode(Parent);
- if not Owner.MultiSelectCheckboxNeeded(Result) then
- Result.StateIndex:= -1; { 5/15/98 - Required since its not initialized to -1}
- except
- Result.Free;
- raise;
- end;
- end;
- function TfcTreeNodes.InternalAddObject(Node: TfcTreeNode; const S: string;
- Ptr: Pointer; AddMode: TfcAddMode): TfcTreeNode;
- var
- Item: HTreeItem;
- begin
- Result := Owner.CreateNode;
- try
- if Node <> nil then Item := Node.ItemId
- else Item := nil;
- Result.Data := Ptr;
- Result.Text := S;
- Item := AddItem(Item, nil, CreateItem(Result), AddMode);
- if Item = nil then
- raise EOutOfResources.Create(sInsertError);
- Result.FItemId := Item;
- AddedNode(Node);
- if not Owner.MultiSelectCheckboxNeeded(Result) then
- Result.StateIndex:= -1; { 5/15/98 - Required since its not initialized to -1}
- except
- Result.Free;
- raise;
- end;
- end;
- function TfcTreeNodes.CreateItem(Node: TfcTreeNode): TTVItem;
- begin
- Node.FInTree := True;
- with Result do
- begin
- mask := TVIF_TEXT or TVIF_PARAM or TVIF_IMAGE or TVIF_SELECTEDIMAGE;
- lParam := Longint(Node);
- pszText := LPSTR_TEXTCALLBACK;
- iImage := I_IMAGECALLBACK;
- iSelectedImage := I_IMAGECALLBACK;
- end;
- end;
- function TfcTreeNodes.AddItem(Parent, Target: HTreeItem;
- const Item: TTVItem; AddMode: TfcAddMode): HTreeItem;
- var
- InsertStruct: TTVInsertStruct;
- begin
- ClearCache;
- with InsertStruct do
- begin
- hParent := Parent;
- case AddMode of
- fctaAddFirst:
- hInsertAfter := TVI_FIRST;
- fctaAdd:
- hInsertAfter := TVI_LAST;
- fctaInsert:
- hInsertAfter := Target;
- end;
- end;
- InsertStruct.item := Item;
- FOwner.FChangeTimer.Enabled := False;
- Result := TreeView_InsertItem(Handle, InsertStruct);
- end;
- function TfcTreeNodes.GetFirstNode: TfcTreeNode;
- begin
- Result := GetNode(TreeView_GetRoot(Handle));
- end;
- function TfcTreeNodes.GetNodeFromIndex(Index: Integer): TfcTreeNode;
- var
- I: Integer;
- begin
- if Index < 0 then TreeViewError(sInvalidIndex);
- if (FNodeCache.CacheNode <> nil) and (Abs(FNodeCache.CacheIndex - Index) <= 1) then
- begin
- with FNodeCache do
- begin
- if Index = CacheIndex then Result := CacheNode
- else if Index < CacheIndex then Result := CacheNode.GetPrev
- else Result := CacheNode.GetNext;
- end;
- end
- else begin
- Result := GetFirstNode;
- I := Index;
- while (I <> 0) and (Result <> nil) do
- begin
- Result := Result.GetNext;
- Dec(I);
- end;
- end;
- if Result = nil then TreeViewError(sInvalidIndex);
- FNodeCache.CacheNode := Result;
- FNodeCache.CacheIndex := Index;
- end;
- function TfcTreeNodes.GetNode(ItemId: HTreeItem): TfcTreeNode;
- var
- Item: TTVItem;
- begin
- with Item do
- begin
- hItem := ItemId;
- mask := TVIF_PARAM;
- end;
- if TreeView_GetItem(Handle, Item) then Result := TfcTreeNode(Item.lParam)
- else Result := nil;
- end;
- procedure TfcTreeNodes.SetItem(Index: Integer; Value: TfcTreeNode);
- begin
- GetNodeFromIndex(Index).Assign(Value);
- end;
- procedure TfcTreeNodes.BeginUpdate;
- begin
- if FUpdateCount = 0 then SetUpdateState(True);
- Inc(FUpdateCount);
- end;
- procedure TfcTreeNodes.SetUpdateState(Updating: Boolean);
- begin
- SendMessage(Handle, WM_SETREDRAW, Ord(not Updating), 0);
- if not Updating then Owner.Refresh;
- end;
- procedure TfcTreeNodes.EndUpdate;
- begin
- Dec(FUpdateCount);
- if FUpdateCount = 0 then SetUpdateState(False);
- end;
- procedure TfcTreeNodes.Assign(Source: TPersistent);
- var
- TreeNodes: TfcTreeNodes;
- MemStream: TMemoryStream;
- begin
- ClearCache;
- { 12/1/98 (RSW) Clear treeview display }
- SendMessage(Owner.Handle, WM_ERASEBkgnd, Owner.Canvas.Handle, 0);
- if Source is TfcTreeNodes then
- begin
- Owner.FStreamVersion:= 1;
- TreeNodes := TfcTreeNodes(Source);
- Clear;
- MemStream := TMemoryStream.Create;
- try
- TreeNodes.WriteData(MemStream);
- MemStream.Position := 0;
- ReadData(MemStream);
- finally
- MemStream.Free;
- end;
- end
- else inherited Assign(Source);
- if Count>0 then Owner.Selected:= Owner.Items[0];
- Owner.invalidate;
- // RSW - 1/13/99 Make sure some node is selected as the treeview common control
- // has problems in repainting in certain cases if no control has the selection
- end;
- procedure TfcTreeNodes.DefineProperties(Filer: TFiler);
- {
- function WriteNodes: Boolean;
- var
- I: Integer;
- Nodes: TfcTreeNodes;
- begin
- Nodes := TfcTreeNodes(Filer.Ancestor);
- if Nodes = nil then
- Result := Count > 0
- else if Nodes.Count <> Count then
- Result := True
- else
- begin
- Result := False;
- for I := 0 to Count - 1 do
- begin
- Result := not Item[I].IsEqual(Nodes[I]);
- if Result then Break;
- end
- end;
- end;
- }
- begin
- inherited DefineProperties(Filer);
- // Filer.DefineBinaryProperty('Data', ReadData, WriteData, WriteNodes);
- Filer.DefineProperty('StreamVersion',
- ReadStreamVersion, WriteStreamVersion, True);
- Filer.DefineBinaryProperty('Data', ReadData, WriteData, True);
- end;
- procedure TfcTreeNodes.ReadStreamVersion(Reader: TReader);
- begin
- Owner.FStreamVersion:= Reader.ReadInteger;
- end;
- procedure TfcTreeNodes.WriteStreamVersion(Writer: TWriter);
- begin
- Owner.FStreamVersion:= 1;
- Writer.WriteInteger(Owner.StreamVersion)
- end;
- procedure TfcTreeNodes.ReadData(Stream: TStream);
- var
- I, Count: Integer;
- NodeInfo: TfcNodeInfo;
- begin
- FillChar(NodeInfo, SizeOf(TfcNodeInfo), 0);
- Clear;
- Stream.ReadBuffer(Count, SizeOf(Count));
- for I := 0 to Count - 1 do
- Add(nil, '').ReadData(Stream, @NodeInfo);
- Owner.FStreamVersion:= 1;
- end;
- procedure TfcTreeNodes.WriteData(Stream: TStream);
- var
- I: Integer;
- Node: TfcTreeNode;
- NodeInfo: TfcNodeInfo;
- begin
- Owner.FStreamVersion:=1;
- I := 0;
- Node := GetFirstNode;
- while Node <> nil do
- begin
- Inc(I);
- Node := Node.GetNextSibling;
- end;
- Stream.WriteBuffer(I, SizeOf(I));
- Node := GetFirstNode;
- while Node <> nil do
- begin
- Node.WriteData(Stream, @NodeInfo);
- Node := Node.GetNextSibling;
- end;
- end;
- procedure TfcTreeNodes.ClearCache;
- begin
- FNodeCache.CacheNode := nil;
- end;
- {type
- TTreeStrings = class(TStrings)
- private
- FOwner: TfcTreeNodes;
- protected
- function Get(Index: Integer): string; override;
- function GetBufStart(Buffer: PChar; var Level: Integer): PChar;
- function GetCount: Integer; override;
- function GetObject(Index: Integer): TObject; override;
- procedure PutObject(Index: Integer; AObject: TObject); override;
- procedure SetUpdateState(Updating: Boolean); override;
- public
- constructor Create(AOwner: TfcTreeNodes);
- function Add(const S: string): Integer; override;
- procedure Clear; override;
- procedure Delete(Index: Integer); override;
- procedure Insert(Index: Integer; const S: string); override;
- procedure LoadTreeFromStream(Stream: TStream);
- procedure SaveTreeToStream(Stream: TStream);
- property Owner: TfcTreeNodes read FOwner;
- end;
- constructor TTreeStrings.Create(AOwner: TfcTreeNodes);
- begin
- inherited Create;
- FOwner := AOwner;
- end;
- function TTreeStrings.Get(Index: Integer): string;
- const
- TabChar = #9;
- var
- Level, I: Integer;
- Node: TfcTreeNode;
- begin
- Result := '';
- Node := Owner.GetNodeFromIndex(Index);
- Level := Node.Level;
- for I := 0 to Level - 1 do Result := Result + TabChar;
- Result := Result + Node.Text;
- end;
- function TTreeStrings.GetBufStart(Buffer: PChar; var Level: Integer): PChar;
- begin
- Level := 0;
- while Buffer^ in [' ', #9] do
- begin
- Inc(Buffer);
- Inc(Level);
- end;
- Result := Buffer;
- end;
- function TTreeStrings.GetObject(Index: Integer): TObject;
- begin
- Result := Owner.GetNodeFromIndex(Index).Data;
- end;
- procedure TTreeStrings.PutObject(Index: Integer; AObject: TObject);
- begin
- Owner.GetNodeFromIndex(Index).Data := AObject;
- end;
- function TTreeStrings.GetCount: Integer;
- begin
- Result := Owner.Count;
- end;
- procedure TTreeStrings.Clear;
- begin
- Owner.Clear;
- end;
- procedure TTreeStrings.Delete(Index: Integer);
- begin
- Owner.GetNodeFromIndex(Index).Delete;
- end;
- procedure TTreeStrings.SetUpdateState(Updating: Boolean);
- begin
- SendMessage(Owner.Handle, WM_SETREDRAW, Ord(not Updating), 0);
- if not Updating then Owner.Owner.Refresh;
- end;
- function TTreeStrings.Add(const S: string): Integer;
- var
- Level, OldLevel, I: Integer;
- NewStr: string;
- Node: TfcTreeNode;
- begin
- Result := GetCount;
- if (Length(S) = 1) and (S[1] = Chr($1A)) then Exit;
- Node := nil;
- OldLevel := 0;
- NewStr := GetBufStart(PChar(S), Level);
- if Result > 0 then
- begin
- Node := Owner.GetNodeFromIndex(Result - 1);
- OldLevel := Node.Level;
- end;
- if (Level > OldLevel) or (Node = nil) then
- begin
- if Level - OldLevel > 1 then TreeViewError(sInvalidLevel);
- end
- else begin
- for I := OldLevel downto Level do
- begin
- Node := Node.Parent;
- if (Node = nil) and (I - Level > 0) then
- TreeViewError(sInvalidLevel);
- end;
- end;
- Owner.AddChild(Node, NewStr);
- end;
- procedure TTreeStrings.Insert(Index: Integer; const S: string);
- begin
- with Owner do
- Insert(GetNodeFromIndex(Index), S);
- end;
- procedure TTreeStrings.LoadTreeFromStream(Stream: TStream);
- var
- List: TStringList;
- ANode, NextNode: TfcTreeNode;
- ALevel, i: Integer;
- CurrStr: string;
- begin
- List := TStringList.Create;
- Owner.BeginUpdate;
- try
- try
- Clear;
- List.LoadFromStream(Stream);
- ANode := nil;
- for i := 0 to List.Count - 1 do
- begin
- CurrStr := GetBufStart(PChar(List[i]), ALevel);
- if ANode = nil then
- ANode := Owner.AddChild(nil, CurrStr)
- else if ANode.Level = ALevel then
- ANode := Owner.AddChild(ANode.Parent, CurrStr)
- else if ANode.Level = (ALevel - 1) then
- ANode := Owner.AddChild(ANode, CurrStr)
- else if ANode.Level > ALevel then
- begin
- NextNode := ANode.Parent;
- while NextNode.Level > ALevel do
- NextNode := NextNode.Parent;
- ANode := Owner.AddChild(NextNode.Parent, CurrStr);
- end
- else TreeViewErrorFmt(sInvalidLevelEx, [ALevel, CurrStr]);
- end;
- finally
- Owner.EndUpdate;
- List.Free;
- end;
- except
- Owner.Owner.Invalidate; // force repaint on exception
- raise;
- end;
- end;
- procedure TTreeStrings.SaveTreeToStream(Stream: TStream);
- const
- TabChar = #9;
- EndOfLine = #13#10;
- var
- i: Integer;
- ANode: TfcTreeNode;
- NodeStr: string;
- begin
- if Count > 0 then
- begin
- ANode := Owner[0];
- while ANode <> nil do
- begin
- NodeStr := '';
- for i := 0 to ANode.Level - 1 do NodeStr := NodeStr + TabChar;
- NodeStr := NodeStr + ANode.Text + EndOfLine;
- Stream.Write(Pointer(NodeStr)^, Length(NodeStr));
- ANode := ANode.GetNext;
- end;
- end;
- end;
- }
- { TfcCustomTreeView }
- constructor TfcCustomTreeView.Create(AOwner: TComponent);
- begin
- inherited Create(AOwner);
- ControlStyle := ControlStyle - [csCaptureMouse] + [csDisplayDragImage, csReflector];
- Width := 121;
- Height := 97;
- TabStop := True;
- ParentColor := False;
- NodeClass := TfcTreeNode;
- FCanvas := TfcCanvas.Create;
- TControlCanvas(FCanvas).Control := Self;
- FTreeNodes := TfcTreeNodes.Create(Self);
- FBorderStyle := bsSingle;
- // FShowButtons := True;
- // FShowRoot := True;
- // FShowLines := True;
- // FHideSelection := True;
- FOptions:= [tvoExpandOnDblClk, tvoShowButtons, tvoShowRoot,
- tvoShowLines, tvoHideSelection, tvoToolTips];
- FSaveIndent := -1;
- FChangeTimer := TTimer.Create(Self);
- FChangeTimer.Enabled := False;
- FChangeTimer.Interval := 0;
- FChangeTimer.OnTimer := OnChangeTimer;
- // FToolTips := False;
- {$Warnings Off}
- FEditInstance := MakeObjectInstance(EditWndProc);
- {$Warnings On}
- FImageChangeLink := TChangeLink.Create;
- FImageChangeLink.OnChange := ImageListChange;
- FStateChangeLink := TChangeLink.Create;
- FStateChangeLink.OnChange := ImageListChange;
- // FOptions := [tvoExpandOnDblClk];
- FMultiSelectAttributes:= TfcTVMultiSelectAttributes.create(self);
- FMultiSelectList:= TList.create;
- FBorderWidth := GetSystemMetrics(SM_CXBORDER);
- if FFixBugImageList=nil then begin
- FFixBugImageList:= TImageList.create(nil);
- FFixBugImageList.Width:= FixBugImageListSize;
- FFixBugImageList.Height:= FixBugImageListSize;
- end;
- inc(RefCount); { 2/28/00 - Always increment refcount}
- FPaintBitmap:= TBitmap.create;
- FPaintCanvas:= TfcCanvas(FPaintBitmap.Canvas);
- FLineColor:= clBtnShadow;
- FInactiveFocusColor:= clBtnFace;
- FReadOnly:= False;
- Patch:= VarArrayCreate([0, 0], varVariant);
- Patch[0]:= False;
- // Patch[1]:= 0; { Used by TfcTreeNode ReadData }
- end;
- destructor TfcCustomTreeView.Destroy;
- begin
- FPaintBitmap.Free;
- FMultiSelectList.Free;
- FMultiSelectAttributes.Free;
- dec(RefCount);
- if RefCount<=0 then
- begin
- FFixBugImageList.Free;
- FFixBugimageList:=nil;
- end;
- // Items.Free;
- FTreeNodes.Free;
- FTreeNodes:= nil;
- FChangeTimer.Free;
- FSaveItems.Free;
- FDragImage.Free;
- FMemStream.Free;
- {$Warnings Off}
- FreeObjectInstance(FEditInstance);
- {$Warnings On}
- FImageChangeLink.Free;
- FStateChangeLink.Free;
- FCanvas.Free;
- inherited Destroy;
- end;
- procedure TfcCustomTreeView.CreateParams(var Params: TCreateParams);
- const
- TVS_TRACKSELECT = $0200;
- TVS_NOTOOLTIPS = $0080;
- TVS_INFOTIP = $0800;
- TVS_SINGLEEXPAND = $0400;
- BorderStyles: array[TBorderStyle] of DWORD = (0, WS_BORDER);
- LineStyles: array[Boolean] of DWORD = (0, TVS_HASLINES);
- RootStyles: array[Boolean] of DWORD = (0, TVS_LINESATROOT);
- ButtonStyles: array[Boolean] of DWORD = (0, TVS_HASBUTTONS);
- EditStyles: array[Boolean] of DWORD = (TVS_EDITLABELS, 0);
- HideSelections: array[Boolean] of DWORD = (TVS_SHOWSELALWAYS, 0);
- DragStyles: array[TDragMode] of DWORD = (TVS_DISABLEDRAGDROP, 0);
- HotTrackStyles: array[Boolean] of DWORD = (0, TVS_TRACKSELECT);
- ToolTipStyles: array[Boolean] of DWORD = (TVS_NOTOOLTIPS, TVS_NOTOOLTIPS);
- AutoExpandStyles: array[Boolean] of DWORD = (0, TVS_SINGLEEXPAND);
- {$ifdef fcDelphi4Up}
- RTLStyles: array[Boolean] of DWORD = (0, TVS_RTLREADING);
- RowSelectStyles: array[Boolean] of DWORD = (0, TVS_FULLROWSELECT);
- {$endif}
- TVS_NOSCROLL = $2000;
- begin
- InitCommonControl(ICC_TREEVIEW_CLASSES);
- inherited CreateParams(Params);
- CreateSubClass(Params, WC_TREEVIEW);
- with Params do
- begin
- Style := Style or LineStyles[tvoShowLines in Options] or BorderStyles[FBorderStyle] or
- RootStyles[tvoShowRoot in Options] or ButtonStyles[tvoShowButtons in Options] or
- EditStyles[not (tvoEditText in Options)] or HideSelections[not (tvoHideSelection in Options)] or
- DragStyles[DragMode] or
- ToolTipStyles[False] or // FToolTips] or
- HotTrackStyles[tvoHotTrack in Options] or
- AutoExpandStyles[FAutoExpand]
- {$ifdef fcDelphi4Up}
- or
- RTLStyles[UseRightToLeftReading]
- {$endif};
- if Ctl3D and NewStyleControls and (FBorderStyle = bsSingle) then
- begin
- Style := Style and not WS_BORDER;
- ExStyle := Params.ExStyle or WS_EX_CLIENTEDGE;
- end;
- WindowClass.style := WindowClass.style and not (CS_HREDRAW or CS_VREDRAW);
- end;
- Params.Style := Params.Style or TVS_CHECKBOXES;
- end;
- function TreeView_SetBkColor(hwnd: HWND; clr: COLORREF): COLORREF;
- const
- TVM_SETBKCOLOR = TV_FIRST + 29;
- begin
- Result := COLORREF(SendMessage(hwnd, TVM_SETBKCOLOR, 0, LPARAM(clr)));
- end;
- function TreeView_SetTextColor(hwnd: HWND; clr: COLORREF): COLORREF;
- const
- TVM_SETTEXTCOLOR = TV_FIRST + 30;
- begin
- Result := COLORREF(SendMessage(hwnd, TVM_SETTEXTCOLOR, 0, LPARAM(clr)));
- end;
- procedure TfcCustomTreeView.CreateWnd;
- var
- DC: HDC;
- SaveFont: HFont;
- TextSize: TSize;
- begin
- FStateChanging := False;
- inherited CreateWnd;
- TreeView_SetBkColor(Handle, ColorToRGB(Color));
- TreeView_SetTextColor(Handle, ColorToRGB(Font.Color));
- if FMemStream <> nil then
- begin
- Items.ReadData(FMemStream);
- FMemStream.Destroy;
- FMemStream := nil;
- SetTopItem(Items.GetNodeFromIndex(FSaveTopIndex));
- FSaveTopIndex := 0;
- SetSelection(Items.GetNodeFromIndex(FSaveIndex));
- FSaveIndex := 0;
- end;
- if FSaveIndent <> -1 then Indent := FSaveIndent;
- if (Images <> nil) and Images.HandleAllocated then
- SetImageList(Images.Handle, TVSIL_NORMAL);
- if (StateImages <> nil) and StateImages.HandleAllocated then
- SetImageList(StateImages.Handle, TVSIL_STATE);
- { Create StateImageList if not assigned }
- DC := GetDC(0);
- SaveFont := SelectObject(DC, Font.Handle);
- GetTextExtentPoint32(DC, 'A', 1, TextSize);
- SelectObject(DC, SaveFont);
- ReleaseDC(0, DC);
- FFixBugImageList.Width:= fcMin(TextSize.cy+2, FixBugImageListSize);
- FFixBugImageList.Width:= fcMax(FixBugImageListSize, 16); { 2/1/99}
- FFixBugImageList.Height:= FFixBugImageList.Width;
- if HandleAllocated and (StateImages=Nil) then
- TreeView_SetImageList(Handle, FFixBugImageList.Handle, TVSIL_STATE);
- { 5/5/99 - Workaround for TreeView common control problem where this property is reset }
- if not (tvoHideSelection in Options) and HandleAllocated then
- SetComCtlStyle(Self, TVS_SHOWSELALWAYS, True);
- end;
- procedure TfcCustomTreeView.DestroyWnd;
- var
- Node: TfcTreeNode;
- parentIsFrame: boolean;
- begin
- FStateChanging := True;
- {$ifdef fcDelphi5Up}
- parentIsFrame:= parent is TCustomFrame;
- {$else}
- parentIsFrame:= false;
- {$endif}
- if (Items.Count > 0) and
- { 1/5/2000 - Fix TFrame duplicate streaming problem }
- not (parentIsFrame and (csLoading in ComponentState)) then
- begin
- FMemStream := TMemoryStream.Create;
- Items.WriteData(FMemStream);
- FMemStream.Position := 0;
- Node := GetTopItem;
- if Node <> nil then FSaveTopIndex := Node.AbsoluteIndex;
- Node := Selected;
- if Node <> nil then FSaveIndex := Node.AbsoluteIndex;
- end;
- FSaveIndent := Indent;
- inherited DestroyWnd;
- end;
- procedure TfcCustomTreeView.EditWndProc(var Message: TMessage);
- var DisplayRect: TRect;
- begin
- try
- with Message do
- begin
- case Msg of
- WM_WINDOWPOSCHANGED, WM_SIZE:
- begin
- If (EditNode<>Nil) and (Images<>Nil) and (EditNode.imageindex=-2) then
- begin
- DisplayRect:= EditNode.DisplayRect(True);
- SetWindowPos(FEditHandle, 0, fcmax(DisplayRect.Left, 0),DisplayRect.Top,0,0, //sp.x + DisplayRect.Left, sp.y + DisplayRect.Top, 0, 0,
- SWP_NOZORDER OR SWP_NOSIZE OR SWP_NOACTIVATE);
- ValidateRect(Handle, nil);
- // Message.Result:= 1;
- end
- else if (EditNode<>Nil) and (Msg=WM_SIZE) then begin
- if (Patch[0]=False) then
- ValidateRect(Handle, nil) // RSW (4/8/99 } Prevent flicker when edit box size changes
- else Patch[0]:= False;
- end
- end;
- WM_KEYDOWN,
- WM_SYSKEYDOWN: if DoKeyDown(TWMKey(Message)) then Exit;
- WM_CHAR: if DoKeyPress(TWMKey(Message)) then Exit;
- WM_KEYUP,
- WM_SYSKEYUP: if DoKeyUp(TWMKey(Message)) then Exit;
- CN_KEYDOWN,
- CN_CHAR, CN_SYSKEYDOWN,
- CN_SYSCHAR:
- begin
- WndProc(Message);
- Exit;
- end;
- end;
- Result := CallWindowProc(FDefEditProc, FEditHandle, Msg, WParam, LParam);
- end;
- except
- Application.HandleException(Self);
- end;
- end;
- procedure TfcCustomTreeView.CMColorChanged(var Message: TMessage);
- begin
- inherited;
- RecreateWnd;
- end;
- procedure TfcCustomTreeView.CMCtl3DChanged(var Message: TMessage);
- begin
- inherited;
- if FBorderStyle = bsSingle then RecreateWnd;
- end;
- procedure TfcCustomTreeView.CMFontChanged(var Message: TMessage);
- begin
- inherited;
- TreeView_SetTextColor(Handle, ColorToRGB(Font.Color));
- end;
- procedure TfcCustomTreeView.CMSysColorChange(var Message: TMessage);
- begin
- inherited;
- if not (csLoading in ComponentState) then
- begin
- Message.Msg := WM_SYSCOLORCHANGE;
- DefaultHandler(Message);
- end;
- end;
- function TfcCustomTreeView.AlphaSort: Boolean;
- var
- Node: TfcTreeNode;
- begin
- if HandleAllocated then
- begin
- Result := CustomSort(nil, 0);
- Node := FTreeNodes.GetFirstNode;
- while Node <> nil do
- begin
- if Node.HasChildren then Node.AlphaSort;
- Node := Node.GetNext;
- end;
- end
- else
- Result := False;
- end;
- function TfcCustomTreeView.CustomSort(SortProc: TTVCompare; Data: Longint): Boolean;
- var
- SortCB: TTVSortCB;
- // Node: TfcTreeNode;
- begin
- Result := False;
- if HandleAllocated then
- begin
- with SortCB do
- begin
- if not Assigned(SortProc) then lpfnCompare := @DefaultTreeViewSort
- else lpfnCompare := SortProc;
- hParent := TVI_ROOT;
- lParam := Data;
- Result := TreeView_SortChildrenCB(Handle, SortCB, 0);
- end;
- { Node := FTreeNodes.GetFirstNode;
- while Node <> nil do
- begin
- if Node.HasChildren then Node.CustomSort(SortProc, Data);
- Node := Node.GetNext;
- end;}
- Items.ClearCache;
- end;
- end;
- procedure TfcCustomTreeView.SetAutoExpand(Value: Boolean);
- const
- TVS_SINGLEEXPAND = $0400;
- begin
- if FAutoExpand <> Value then
- begin
- FAutoExpand := Value;
- SetComCtlStyle(Self, TVS_SINGLEEXPAND, Value);
- end;
- end;
- {
- procedure TfcCustomTreeView.SetHotTrack(Value: Boolean);
- const
- TVS_TRACKSELECT = $0200;
- begin
- if FHotTrack <> Value then
- begin
- FHotTrack := Value;
- SetComCtlStyle(Self, TVS_TRACKSELECT, Value);
- end;
- end;
- }
- {procedure TfcCustomTreeView.SetRowSelect(Value: Boolean);
- const
- TVS_FULLROWSELECT = $1000;
- begin
- if (tvoRowSelect in Options) <> Value then
- begin
- FRowSelect := Value;
- SetComCtlStyle(Self, TVS_FULLROWSELECT, Value);
- end;
- end;
- }
- {procedure TfcCustomTreeView.SetToolTips(Value: Boolean);
- const TVS_NOTOOLTIPS = $0080;
- begin
- if FToolTips <> Value then
- begin
- FToolTips := Value;
- SetComCtlStyle(Self, TVS_NOTOOLTIPS, not Value);
- end;
- end;
- }
- procedure TfcCustomTreeView.SetSortType(Value: TfcSortType);
- begin
- if SortType <> Value then
- begin
- FSortType := Value;
- if ((SortType in [fcstData, fcstBoth]) and Assigned(OnCompare)) or
- (SortType in [fcstText, fcstBoth]) then
- AlphaSort;
- end;
- end;
- procedure TfcCustomTreeView.SetBorderStyle(Value: TBorderStyle);
- begin
- if BorderStyle <> Value then
- begin
- FBorderStyle := Value;
- RecreateWnd;
- end;
- end;
- procedure TfcCustomTreeView.SetDragMode(Value: TDragMode);
- begin
- if Value <> DragMode then
- SetComCtlStyle(Self, TVS_DISABLEDRAGDROP, Value = dmManual);
- inherited;
- end;
- {
- procedure TfcCustomTreeView.SetButtonStyle(Value: Boolean);
- begin
- if ShowButtons <> Value then
- begin
- FShowButtons := Value;
- SetComCtlStyle(Self, TVS_HASBUTTONS, Value);
- end;
- end;
- }
- {
- procedure TfcCustomTreeView.SetLineStyle(Value: Boolean);
- begin
- if ShowLines <> Value then
- begin
- FShowLines := Value;
- SetComCtlStyle(Self, TVS_HASLINES, Value);
- SetComCtlStyle(Self, TVS_HASBUTTONS, Value);
- end;
- end;
- }
- {
- procedure TfcCustomTreeView.SetRootStyle(Value: Boolean);
- begin
- if ShowRoot <> Value then
- begin
- FShowRoot := Value;
- end;
- end;
- }
- procedure TfcCustomTreeView.SetReadOnly(Value: Boolean);
- begin
- if ReadOnly <> Value then
- begin
- FReadOnly := Value;
- if FReadOnly then
- begin
- if (tvoEditText in Options) then SetComCtlStyle(Self, TVS_EDITLABELS, False);
- end