cxtreeview.pas

来自「胜天进销存源码,国产优秀的进销存」· PAS 代码 · 共 1,527 行 · 第 1/4 页

PAS
1,527
字号

{********************************************************************}
{                                                                    }
{       Developer Express Visual Component Library                   }
{       ExpressEditors                                               }
{                                                                    }
{       Copyright (c) 1998-2008 Developer Express Inc.               }
{       ALL RIGHTS RESERVED                                          }
{                                                                    }
{   The entire contents of this file is protected by U.S. and        }
{   International Copyright Laws. Unauthorized reproduction,         }
{   reverse-engineering, and distribution of all or any portion of   }
{   the code contained in this file is strictly prohibited and may   }
{   result in severe civil and criminal penalties and will be        }
{   prosecuted to the maximum extent possible under the law.         }
{                                                                    }
{   RESTRICTIONS                                                     }
{                                                                    }
{   THIS SOURCE CODE AND ALL RESULTING INTERMEDIATE FILES            }
{   (DCU, OBJ, DLL, ETC.) ARE CONFIDENTIAL AND PROPRIETARY TRADE     }
{   SECRETS OF DEVELOPER EXPRESS INC. THE REGISTERED DEVELOPER IS    }
{   LICENSED TO DISTRIBUTE THE EXPRESSEDITORS AND ALL                }
{   ACCOMPANYING VCL CONTROLS AS PART OF AN EXECUTABLE PROGRAM ONLY. }
{                                                                    }
{   THE SOURCE CODE CONTAINED WITHIN THIS FILE AND ALL RELATED       }
{   FILES OR ANY PORTION OF ITS CONTENTS SHALL AT NO TIME BE         }
{   COPIED, TRANSFERRED, SOLD, DISTRIBUTED, OR OTHERWISE MADE        }
{   AVAILABLE TO OTHER INDIVIDUALS WITHOUT EXPRESS WRITTEN CONSENT   }
{   AND PERMISSION FROM DEVELOPER EXPRESS INC.                       }
{                                                                    }
{   CONSULT THE END USER LICENSE AGREEMENT FOR INFORMATION ON        }
{   ADDITIONAL RESTRICTIONS.                                         }
{                                                                    }
{********************************************************************}

{$DEFINE USETCXSCROLLBAR}

unit cxTreeView;

{$I cxVer.inc}

interface

uses
  Windows, Classes, ComCtrls, CommCtrl, Controls, Forms, ImgList, Menus,
  Messages, StdCtrls, SysUtils, cxClasses, cxContainer, cxControls,
  cxExtEditConsts, cxGraphics, cxLookAndFeels, cxScrollBar;

type
  { TcxCustomInnerTreeView }

  TcxCustomTreeView = class;

  TcxCustomInnerTreeView = class(TTreeView, IUnknown,
    IcxContainerInnerControl)
  private
    FCanvas: TcxCanvas;
    FContainer: TcxCustomTreeView;
    FIsRedrawLocked: Boolean;
    FItemHeight: Integer;
    FLookAndFeel: TcxLookAndFeel;
    function GetControl: TWinControl;
    function GetControlContainer: TcxContainer;
    procedure HScrollHandler(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);
    procedure SetItemHeight(Value: Integer);
    procedure SetLookAndFeel(Value: TcxLookAndFeel);
    procedure VScrollHandler(Sender: TObject; ScrollCode: TScrollCode; var ScrollPos: Integer);
{$IFNDEF DELPHI6}
    function GetScrollWidth: Integer;
    procedure SetScrollWidth(const Value: Integer);
{$ENDIF}
    procedure WMGetDlgCode(var Message: TWMGetDlgCode); message WM_GETDLGCODE;
    procedure WMKillFocus(var Message: TWMKillFocus); message WM_KILLFOCUS;
    procedure WMNCCalcSize(var Message: TWMNCCalcSize); message WM_NCCALCSIZE;
    procedure WMNCPaint(var Message: TWMNCPaint); message WM_NCPAINT;
    procedure WMSetFocus(var Message: TWMSetFocus); message WM_SETFOCUS;
    procedure WMSetRedraw(var Message: TWMSetRedraw); message WM_SETREDRAW;
    procedure WMWindowPosChanged(var Message: TWMWindowPosChanged); message WM_WINDOWPOSCHANGED;
    procedure CMMouseEnter(var Message: TMessage); message CM_MOUSEENTER;
    procedure CMMouseLeave(var Message: TMessage); message CM_MOUSELEAVE;
    procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
    procedure WMFontChange(var Message: TMessage); message WM_FONTCHANGE;
    procedure WMLButtonDown(var Message: TWMLButtonDown); message WM_LBUTTONDOWN;
  protected
    procedure Click; override;
    procedure DblClick; override;
    procedure DestroyWindowHandle; override;
    function DoMouseWheel(Shift: TShiftState; WheelDelta: Integer;
       MousePos: TPoint): Boolean; override;
    procedure DragOver(Source: TObject; X, Y: Integer; State: TDragState;
      var Accept: Boolean); override;
    procedure KeyDown(var Key: Word; Shift: TShiftState); override;
    procedure KeyPress(var Key: Char); override;
    procedure KeyUp(var Key: Word; Shift: TShiftState); override;
    procedure MouseDown(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
    procedure MouseUp(Button: TMouseButton; Shift: TShiftState; X, Y: Integer); override;
    procedure CreateWindowHandle(const Params: TCreateParams); override;
    procedure WndProc(var Message: TMessage); override;
    procedure MouseEnter(AControl: TControl); dynamic;
    procedure MouseLeave(AControl: TControl); dynamic;
    property Container: TcxCustomTreeView read FContainer;
    property LookAndFeel: TcxLookAndFeel read FLookAndFeel write SetLookAndFeel;
    procedure Expand(Node: TTreeNode); override;
    procedure Change(Node: TTreeNode); override;
    procedure Collapse(Node: TTreeNode); override;
    procedure UpdateItemHeight;
    property IsRedrawLocked: Boolean read FIsRedrawLocked;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    procedure DefaultHandler(var Message); override;
    procedure DragDrop(Source: TObject; X, Y: Integer); override;
    property Canvas: TcxCanvas read FCanvas;
    property ItemHeight: Integer read FItemHeight write SetItemHeight default -1;
{$IFNDEF DELPHI6}
    property ScrollWidth: Integer read GetScrollWidth write SetScrollWidth default 0;
{$ENDIF}
  end;

  TcxCustomInnerTreeViewClass = class of TcxCustomInnerTreeView;

  { TcxCustomTreeView }

  TcxCustomTreeView = class(TcxContainer)
  private
    FTreeView: TcxCustomInnerTreeView;
    function GetAutoExpand: Boolean;
    function GetChangeDelay: Integer;
    function GetHideSelection: Boolean;
    function GetHotTrack: Boolean;
    function GetImages: TCustomImageList;
    function GetItemHeight: Integer;
    function GetTreeNodes: TTreeNodes;
    function GetIndent: Integer;
{$IFDEF DELPHI6}
    function GetMultiSelect: Boolean;
    function GetMultiSelectStyle: TMultiSelectStyle;
    function GetOnCreateNodeClass: TTVCreateNodeClassEvent;
    procedure SetMultiSelectStyle(Value: TMultiSelectStyle);
    procedure SetOnCreateNodeClass(Value: TTVCreateNodeClassEvent);
    function GetOnAddition: TTVExpandedEvent;
    function GetOnCancelEdit: TTVChangedEvent;
{$ENDIF}
    function GetReadOnly: Boolean;
    function GetRightClickSelect: Boolean;
    function GetRowSelect: Boolean;
    function GetShowButtons: Boolean;
    function GetShowLines: Boolean;
    function GetShowRoot: Boolean;
    function GetSortType: TSortType;
    function GetStateImages: TCustomImageList;
    function GetToolTips: Boolean;
    function GetTreeViewCanvas: TcxCanvas;
{$IFDEF DELPHI5}
    function GetOnAdvancedCustomDraw: TTVAdvancedCustomDrawEvent;
    function GetOnAdvancedCustomDrawItem: TTVAdvancedCustomDrawItemEvent;
{$ENDIF}
    function GetOnChange: TTVChangedEvent;
    function GetOnChanging: TTVChangingEvent;
    function GetOnCollapsed: TTVExpandedEvent;
    function GetOnCollapsing: TTVCollapsingEvent;
    function GetOnCompare: TTVCompareEvent;
    function GetOnCustomDraw: TTVCustomDrawEvent;
    function GetOnCustomDrawItem: TTVCustomDrawItemEvent;
    function GetOnDeletion: TTVExpandedEvent;
    function GetOnEditing: TTVEditingEvent;
    function GetOnEdited: TTVEditedEvent;
    function GetOnExpanding: TTVExpandingEvent;
    function GetOnExpanded: TTVExpandedEvent;
    function GetOnGetImageIndex: TTVExpandedEvent;
    function GetOnGetSelectedIndex: TTVExpandedEvent;
    function GetDropTarget: TTreeNode;
    function GetSelected: TTreeNode;
    function GetTopItem: TTreeNode;
{$IFDEF DELPHI6}
    function GetSelectionCount: Cardinal;
    function GetSelection(Index: Integer): TTreeNode;
    procedure SetMultiSelect(Value: Boolean);
{$ENDIF}
    procedure SetAutoExpand(Value: Boolean);
    procedure SetChangeDelay(Value: Integer);
    procedure SetHideSelection(Value: Boolean);
    procedure SetHotTrack(Value: Boolean);
    procedure SetImages(Value: TCustomImageList);
    procedure SetTreeNodes(Value: TTreeNodes);
    procedure SetIndent(Value: Integer);
    procedure SetItemHeight(Value: Integer);
    procedure SetRightClickSelect(Value: Boolean);
    procedure SetReadOnly(Value: Boolean);
    procedure SetRowSelect(Value: Boolean);
    procedure SetShowButtons(Value: Boolean);
    procedure SetShowLines(Value: Boolean);
    procedure SetShowRoot(Value: Boolean);
    procedure SetSortType(Value: TSortType);
    procedure SetStateImages(Value: TCustomImageList);
    procedure SetToolTips(Value: Boolean);
{$IFDEF DELPHI6}
    procedure SetOnAddition(Value: TTVExpandedEvent);
    procedure SetOnCancelEdit(Value: TTVChangedEvent);
{$ENDIF}
{$IFDEF DELPHI5}
    procedure SetOnAdvancedCustomDraw(Value: TTVAdvancedCustomDrawEvent);
    procedure SetOnAdvancedCustomDrawItem(Value: TTVAdvancedCustomDrawItemEvent);
{$ENDIF}
    procedure SetOnChange(Value: TTVChangedEvent);
    procedure SetOnChanging(Value: TTVChangingEvent);
    procedure SetOnCollapsed(Value: TTVExpandedEvent);
    procedure SetOnCollapsing(Value: TTVCollapsingEvent);
    procedure SetOnCompare(Value: TTVCompareEvent);
    procedure SetOnCustomDraw(Value: TTVCustomDrawEvent);
    procedure SetOnCustomDrawItem(Value: TTVCustomDrawItemEvent);
    procedure SetOnDeletion(Value: TTVExpandedEvent);
    procedure SetOnEditing(Value: TTVEditingEvent);
    procedure SetOnEdited(Value: TTVEditedEvent);
    procedure SetOnExpanding(Value: TTVExpandingEvent);
    procedure SetOnExpanded(Value: TTVExpandedEvent);
    procedure SetOnGetImageIndex(Value: TTVExpandedEvent);
    procedure SetOnGetSelectedIndex(Value: TTVExpandedEvent);
    procedure SetDropTarget(Value: TTreeNode);
    procedure SetSelected(Value: TTreeNode);
    procedure SetTopItem(Value: TTreeNode);
    procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
  protected
    { Protected declarations }
    function CanResize(var NewWidth, NewHeight: Integer): Boolean; override;
    procedure FontChanged; override;
    function IsReadOnly: Boolean; override;
    function NeedsScrollBars: Boolean; override;
    procedure Scroll(AScrollBarKind: TScrollBarKind; AScrollCode: TScrollCode;
      var AScrollPos: Integer); override;
    procedure SetSize; override;
    procedure WriteState(Writer: TWriter); override;

    function GetInnerTreeView: TcxCustomInnerTreeView; virtual;
    class function GetTreeViewClass: TcxCustomInnerTreeViewClass; virtual;
    procedure InternalInitTreeView; virtual;
    {TreeView}
    function CanEdit(Node: TTreeNode): Boolean;
    function CanChange(Node: TTreeNode): Boolean;
    function CanCollapse(Node: TTreeNode): Boolean;
    function CanExpand(Node: TTreeNode): Boolean;
    procedure Collapse(Node: TTreeNode);
    procedure Expand(Node: TTreeNode);
    property AutoExpand: Boolean read GetAutoExpand write SetAutoExpand;
    property ChangeDelay: Integer read GetChangeDelay write SetChangeDelay default 0;
    property HideSelection: Boolean read GetHideSelection write SetHideSelection default True;
    property HotTrack: Boolean read GetHotTrack write SetHotTrack;
    property Images: TCustomImageList read GetImages write SetImages;
    property ItemHeight: Integer read GetItemHeight write SetItemHeight default -1;
    property Items: TTreeNodes read GetTreeNodes write SetTreeNodes;
    property Indent: Integer read GetIndent write SetIndent default 19;
{$IFDEF DELPHI6}
    property MultiSelect: Boolean read GetMultiSelect write SetMultiSelect;
    property MultiSelectStyle: TMultiSelectStyle read GetMultiSelectStyle
      write SetMultiSelectStyle default [msControlSelect];
{$ENDIF}
    property ReadOnly: Boolean read GetReadOnly write SetReadOnly default False;
    property RightClickSelect: Boolean read GetRightClickSelect write SetRightClickSelect;
    property RowSelect: Boolean read GetRowSelect write SetRowSelect;
    property ShowButtons: Boolean read GetShowButtons write SetShowButtons;
    property ShowLines: Boolean read GetShowLines write SetShowLines;
    property ShowRoot: Boolean read GetShowRoot write SetShowRoot;
    property SortType: TSortType read GetSortType write SetSortType;
    property StateImages: TCustomImageList read GetStateImages write SetStateImages;
    property ToolTips: Boolean read GetToolTips write SetToolTips;
{$IFDEF DELPHI6}
    property OnAddition: TTVExpandedEvent read GetOnAddition write SetOnAddition;
    property OnCancelEdit: TTVChangedEvent read GetOnCancelEdit write SetOnCancelEdit;
{$ENDIF}
{$IFDEF DELPHI5}
    property OnAdvancedCustomDraw: TTVAdvancedCustomDrawEvent read GetOnAdvancedCustomDraw write SetOnAdvancedCustomDraw;
    property OnAdvancedCustomDrawItem: TTVAdvancedCustomDrawItemEvent read GetOnAdvancedCustomDrawItem write SetOnAdvancedCustomDrawItem;
{$ENDIF}
    property OnChange: TTVChangedEvent read GetOnChange write SetOnChange;
    property OnChanging: TTVChangingEvent read GetOnChanging write SetOnChanging;
    property OnCollapsed: TTVExpandedEvent read GetOnCollapsed write SetOnCollapsed;
    property OnCollapsing: TTVCollapsingEvent read GetOnCollapsing write SetOnCollapsing;
    property OnCompare: TTVCompareEvent read GetOnCompare write SetOnCompare;
    property OnCustomDraw: TTVCustomDrawEvent read GetOnCustomDraw write SetOnCustomDraw;
    property OnCustomDrawItem: TTVCustomDrawItemEvent read GetOnCustomDrawItem write SetOnCustomDrawItem;
    property OnDeletion: TTVExpandedEvent read GetOnDeletion write SetOnDeletion;
    property OnEditing: TTVEditingEvent read GetOnEditing write SetOnEditing;
    property OnEdited: TTVEditedEvent read GetOnEdited write SetOnEdited;
    property OnExpanding: TTVExpandingEvent read GetOnExpanding write SetOnExpanding;
    property OnExpanded: TTVExpandedEvent read GetOnExpanded write SetOnExpanded;
    property OnGetImageIndex: TTVExpandedEvent read GetOnGetImageIndex write SetOnGetImageIndex;
    property OnGetSelectedIndex: TTVExpandedEvent read GetOnGetSelectedIndex write SetOnGetSelectedIndex;
{$IFDEF DELPHI6}
    property OnCreateNodeClass: TTVCreateNodeClassEvent read GetOnCreateNodeClass write SetOnCreateNodeClass;
{$ENDIF}
  public
    { Public declarations }
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    function AlphaSort{$IFDEF DELPHI6}(
      ARecurse: Boolean = True){$ENDIF}: Boolean;
    function CustomSort(SortProc: TTVCompare; Data: Longint{$IFDEF DELPHI6};
      ARecurse: Boolean = True{$ENDIF}): Boolean;
    procedure FullCollapse;
    procedure FullExpand;
    function GetHitTestInfoAt(X, Y: Integer): THitTests;
    function GetNodeAt(X, Y: Integer): TTreeNode;
    function IsEditing: Boolean;
    procedure LoadFromFile(const FileName: string);
    procedure LoadFromStream(Stream: TStream);
    procedure SaveToFile(const FileName: string);
    procedure SaveToStream(Stream: TStream);
    procedure SetScrollBarsParameters(AIsScrolling: Boolean = False); override;
    property DropTarget: TTreeNode read GetDropTarget write SetDropTarget;
    property Selected: TTreeNode read GetSelected write SetSelected;
    property TopItem: TTreeNode read GetTopItem write SetTopItem;
    property TreeViewCanvas: TcxCanvas read GetTreeViewCanvas;
{$IFDEF DELPHI6}
    procedure Select(Node: TTreeNode; ShiftState: TShiftState = []); overload; virtual;
    procedure Select(const Nodes: array of TTreeNode); overload; virtual;
    procedure Select(Nodes: TList); overload; virtual;
    procedure Deselect(Node: TTreeNode); virtual;
    procedure Subselect(Node: TTreeNode; Validate: Boolean = False); virtual;
    property SelectionCount: Cardinal read GetSelectionCount;
    property Selections[Index: Integer]: TTreeNode read GetSelection;
    procedure ClearSelection(KeepPrimary: Boolean = False); virtual;
    function GetSelections(AList: TList): TTreeNode;
    function FindNextToSelect: TTreeNode; virtual;
{$ENDIF}
    property InnerTreeView: TcxCustomInnerTreeView read GetInnerTreeView;
  end;

  { TcxTreeView }
  
  TcxTreeView = class(TcxCustomTreeView)
  public
    property TreeViewCanvas;
  published
    property Align;
    property Anchors;
    property BiDiMode;
    property Constraints;
    property DragCursor;
    property DragKind;
    property DragMode;
    property Enabled;
    property Height default 100;
    property ParentBiDiMode;
    property ParentColor default False;
    property ParentFont;
    property ParentShowHint;
    property PopupMenu;
    property ShowHint;
    property Style;
    property StyleDisabled;
    property StyleFocused;
    property StyleHot;
    property TabOrder;
    property TabStop;
    property Visible;
    property Width default 120;
    property OnClick;
    property OnDblClick;
    property OnDragDrop;
    property OnDragOver;
    property OnEndDock;
    property OnEndDrag;
    property OnEnter;
    property OnExit;
    property OnKeyDown;
    property OnKeyPress;
    property OnKeyUp;
    property OnMouseDown;
    property OnMouseMove;
    property OnMouseUp;
    property OnStartDock;
    property OnStartDrag;
{$IFDEF DELPHI5}
    property OnContextPopup;
{$ENDIF}
    property AutoExpand default False;
    property ChangeDelay default 0;
    property HideSelection default True;
    property HotTrack default False;
    property Images;
    property ItemHeight;

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?