📄 systemtreeview.pas
字号:
{$I DFS.INC} { Defines for all Delphi Free Stuff components }
{$I SYSTEMCONTROLPACK.INC} { Defines specific to these components }
{ -----------------------------------------------------------------------------}
{ TdfsSystemTreeView }
{ -----------------------------------------------------------------------------}
{ A tree view control that acts as the tree in the Windows Explorer. This is }
{ part of the System Control Pack. }
{ }
{ Copyright 2000-2001, Brad Stowers. All Rights Reserved. }
{ }
{ Copyright: }
{ All Delphi Free Stuff (hereafter "DFS") source code is copyrighted by }
{ Bradley D. Stowers (hereafter "author"), and shall remain the exclusive }
{ property of the author. }
{ }
{ Distribution Rights: }
{ You are granted a non-exlusive, royalty-free right to produce and distribute }
{ compiled binary files (executables, DLLs, etc.) that are built with any of }
{ the DFS source code unless specifically stated otherwise. }
{ You are further granted permission to redistribute any of the DFS source }
{ code in source code form, provided that the original archive as found on the }
{ DFS web site (http://www.delphifreestuff.com) is distributed unmodified. For }
{ example, if you create a descendant of TDFSColorButton, you must include in }
{ the distribution package the colorbtn.zip file in the exact form that you }
{ downloaded it from http://www.delphifreestuff.com/mine/files/colorbtn.zip. }
{ }
{ Restrictions: }
{ Without the express written consent of the author, you may not: }
{ * Distribute modified versions of any DFS source code by itself. You must }
{ include the original archive as you found it at the DFS site. }
{ * Sell or lease any portion of DFS source code. You are, of course, free }
{ to sell any of your own original code that works with, enhances, etc. }
{ DFS source code. }
{ * Distribute DFS source code for profit. }
{ }
{ Warranty: }
{ There is absolutely no warranty of any kind whatsoever with any of the DFS }
{ source code (hereafter "software"). The software is provided to you "AS-IS", }
{ and all risks and losses associated with it's use are assumed by you. In no }
{ event shall the author of the softare, Bradley D. Stowers, be held }
{ accountable for any damages or losses that may occur from use or misuse of }
{ the software. }
{ }
{ Support: }
{ Support is provided via the DFS Support Forum, which is a web-based message }
{ system. You can find it at http://www.delphifreestuff.com/discus/ }
{ All DFS source code is provided free of charge. As such, I can not guarantee }
{ any support whatsoever. While I do try to answer all questions that I }
{ receive, and address all problems that are reported to me, you must }
{ understand that I simply can not guarantee that this will always be so. }
{ }
{ Clarifications: }
{ If you need any further information, please feel free to contact me directly.}
{ This agreement can be found online at my site in the "Miscellaneous" section.}
{------------------------------------------------------------------------------}
{ The lateset version of my components are always available on the web at: }
{ http://www.delphifreestuff.com/ }
{ See SCP.txt for notes, known issues, and revision history. }
{ -----------------------------------------------------------------------------}
{ Date last modified: June 28, 2001 }
{ -----------------------------------------------------------------------------}
unit SystemTreeView;
interface
{$IFNDEF DFS_SCP_SYSTREEVIEW}
Error, should not be compiing this unit!
{$ENDIF}
{$R ErrorMsgs.r32}
uses
Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
{$IFDEF DFS_COMPILER_3_UP} ShlObj, ActiveX, {$ELSE} MyShlObj, OLE2, {$ENDIF}
{$IFDEF DFS_STV_FILECHANGES} FileChange, {$ENDIF}
{$IFDEF DFS_DEBUG} MMSystem, {$ENDIF}
SystemControlPack,
PidlHelp, ItemProp, Menus, ComCtrls, StdCtrls, CommCtrl, _Res__IDs;
const
DFS_COMPONENT_TREE_VERSION = 'TdfsSystemTreeView ' + DFS_SCP_VERSION;
{$IFDEF DFS_DELPHI}
{$IFNDEF DFS_DELPHI_4_UP}
const
TVS_CHECKBOXES = $0100;
{$ENDIF}
{$ELSE}
{$IFDEF DFS_CPPB_1}
const
TVS_CHECKBOXES = $0100;
{$ENDIF}
{$ENDIF}
type
// If you change the order of these, you have to change the order of the
// FOLDERID constants below in GetFolderID function.
TRootFolder = (rfDesktop, rfRecycleBin, rfControlPanel, rfDesktopDir,
rfDrives, rfFavoriteURLs, rfFonts, rfNetHood, rfNetHoodDir, rfDocumentDir,
rfPrinters, rfPrograms, rfRecentDir, rfSendTo, rfStartMenu, rfStartup,
rfTemplates, rfFileSystem, rfCustom);
TdfsSystemTreeView = class(TdfsCustomSystemTreeView)
private
FDesktopFolder: IShellFolder;
FLastSelection: string;
FRecreatingWnd: boolean;
FShowErrorsInMsgBox: boolean;
FAutoscroll: boolean;
FRootFolder: TRootFolder;
FShowHiddenDirs: boolean;
FExpandRoot: boolean;
FCheckboxes: boolean;
FCustomDir: string;
FCustomDirCaption: string;
FShowFiles: boolean;
FPopupMenuMethod: TPopupMenuMethod;
FTreeHandle: HWND;
{$IFDEF DFS_STV_FILECHANGES}
ParentThread: TFileChangeThread;
ParentWatchedNode: TTreeNode;
FCThread: TFileChangeThread;
WatchedNode: TTreeNode;
{$ENDIF}
FFileMask: string;
FFileMaskList: TStringList;
FOnPopulated: TTVExpandedEvent;
FDestroyingSelf: boolean;
procedure RestoreChecks;
procedure SaveChecks;
function GetIDFromPath(const ShellFolder: IShellFolder; const APath: string;
var ID: PItemIDList): boolean;
function GetFolderID: integer;
function EnumerateFolders(const ShellFolder: IShellFolder;
const ParentNode: TTreeNode): boolean;
function AddItemData(ItemFolder: IShellFolder; aIDList,
aFQ_IDList: PItemIDList; Attrs: UINT): TFolderItemData;
procedure FreeItemData(Item: TTreeNode);
procedure FreeAllItemData;
function GetSelection: string;
procedure SetSelection(const ASel: string);
function GetItemCheck(Node: TTreeNode): boolean;
procedure SetItemCheck(Node: TTreeNode; Val: boolean);
{$IFDEF DFS_COMPILER_5_UP}
procedure WMContextMenu(var Message: TWMContextMenu); message WM_CONTEXTMENU;
{$ELSE}
procedure WMRButtonUp(var Message: TWMRButtonUp); message WM_RBUTTONUP;
{$ENDIF}
procedure CNNotify(var Message: TWMNotify); message CN_NOTIFY;
protected
procedure TimerEvent; override;
{ Base Class Abstract Implementations }
// Implementation must return the actual ID list. Caller will make a copy
// of it it wants it's own. Implementer owns this one, i.e. it's the "real
// thing". If there isn't one, return NIL.
function GetSelectionPIDL: PItemIDList; override;
function GetSelectionParentFolder: IShellFolder; override;
// Implementation notes: IDList parameter belongs to someone else. If
// needed by this component, a copy must be made of it. This differs from
// the Reset method in that it does not notify linked controls of a change
// because that could result in an endless cycle of notifications. Return
// value indicates success or failure.
function LinkedReset(const ParentFolder: IShellFolder;
const IDList: PItemIDList; ForceUpdate: boolean): boolean; override;
procedure CreateParams(var Params: TCreateParams); override;
procedure CreateWnd; override;
procedure DestroyWnd; override;
procedure Loaded; override;
function CanExpand(Node: TTreeNode): boolean; override;
function CanEdit(Node: TTreeNode): boolean; override;
procedure Edit(const Item: TTVItem); override;
procedure Change(Node: TTreeNode); override;
procedure DoStartDrag(var DragObject: TDragObject); override;
function GetPopupMenu: TPopupMenu; override;
procedure MouseMove(Shift: TShiftState; X, Y: Integer); override;
procedure Compute_TreeMoves(X, Y: integer); dynamic;
procedure Populated(Node: TTreeNode); dynamic;
// Helpers
// Why isn't there one of these in TTreeView????
procedure DeleteItem(Node: TTreeNode); dynamic;
function GetNodeFromItem(const Item: TTVItem): TTreeNode;
function FindNodeFromID(AnID: PItemIDList): TTreeNode;
// event for this?
function AddNode(const ShellFolder: IShellFolder;
FQ_IDList, IDList: PItemIDList; const ParentNode: TTreeNode): TTreeNode;
dynamic;
// Property methods.
procedure SetRootFolder(Val: TRootFolder);
procedure SetCustomDir(const Val: string);
procedure SetCustomDirCaption(const Val: string);
procedure SetShowFiles(Val: boolean);
function GetVersion: string;
procedure SetVersion(const Val: string);
function GetItems: TTreeNodes;
procedure SetCheckboxes(Val: boolean);
procedure SetFileMask(const Val: string);
// These two do the same thing, just take different parameters.
function GetItemData(Index: integer): TFolderItemData;
function GetNodeData(Node: TTreeNode): TFolderItemData;
procedure Expand(Node: TTreeNode); override;
function CustomSort(SortProc: TTVCompare; Data: Longint): Boolean; dynamic;
function AlphaSort: Boolean;
procedure DblClick; override;
public
constructor Create(AOwner: TComponent); override;
destructor Destroy; override;
procedure Reset; override;
function DisplayContextMenu(Node: TTreeNode; Where: TPoint): boolean;
dynamic;
procedure ResetNode(const Node: TTreeNode);
function GetNodePath(const Node: TTreeNode): string;
{$IFDEF DFS_SCP_SYSCOMBOBOX}
procedure ComboBoxSetSelectionPIDL(APIDL: PItemIDList);
{$ENDIF}
// Useful functions for applications. These modify permanently, not just
// the node. i.e. if you rename 'My Computer' to 'Crasher', it is renamed
// system wide, not just in your app. If you delete the 'C:\WINDOWS'
// folder, you are in deep trouble and I deny any responsibility.
function RenameNode(const Node: TTreeNode; const NewName: string): boolean;
function DeleteNode(const Node: TTreeNode): boolean;
function AddNewNode(const ParentNode: TTreeNode; const NodeName: string;
SelectNewNode: boolean): boolean;
// Move up one directory, i.e. "cd .."
procedure ChangeToParent;
{$IFDEF DFS_STV_FILECHANGES}
procedure WatchDirectoryForChanges(const ANode: TTreeNode);
procedure ParentThreadDone(Sender: TObject);
procedure ThreadDone(Sender: TObject);
{$ENDIF}
property ShowErrorsInMsgBox: boolean
read FShowErrorsInMsgBox write FShowErrorsInMsgBox default TRUE;
property Items
read GetItems;
property ItemChecked[Node: TTreeNode]: boolean
read GetItemCheck write SetItemCheck;
property NodeData[Node: TTreeNode]: TFolderItemData
read GetNodeData;
published
{$IFDEF DFS_SCP_SYSLISTVIEW}
property ListView;
{$ENDIF}
{$IFDEF DFS_SCP_SYSCOMBOBOX}
property ComboBox;
{$ENDIF}
property ReadDelay;
property Version: string
read GetVersion
write SetVersion
stored FALSE;
property PopupMenuMethod: TPopupMenuMethod
read FPopupMenuMethod
write FPopupMenuMethod
default pmmContext;
property Selection: string
read GetSelection write SetSelection;
property Directory: string
read GetSelection write SetSelection stored FALSE;
property RootFolder: TRootFolder
read FRootFolder write SetRootFolder default rfDesktop;
property CustomDir: string
read FCustomDir write SetCustomDir;
property CustomDirCaption: string
read FCustomDirCaption write SetCustomDirCaption;
property ShowFiles: boolean
read FShowFiles write SetShowFiles default FALSE;
property ShowHiddenDirs: boolean
read FShowHiddenDirs write FShowHiddenDirs default TRUE;
property ExpandRoot: boolean
read FExpandRoot write FExpandRoot default TRUE;
property Checkboxes: boolean
read FCheckboxes write SetCheckboxes default FALSE;
property Autoscroll: boolean
read FAutoscroll write FAutoscroll default FALSE;
property FileMask: string
read FFileMask write SetFileMask;
property OnPopulated: TTVExpandedEvent
read FOnPopulated write FOnPopulated;
{ Publish protected properties. }
property Align;
{$IFDEF DFS_COMPILER_4_UP}
property Anchors;
property AutoExpand;
property BiDiMode;
{$ENDIF}
property BorderStyle;
{$IFDEF DFS_COMPILER_4_UP}
property BorderWidth;
property ChangeDelay;
{$ENDIF}
property Color;
{$IFDEF DFS_COMPILER_4_UP}
property Constraints;
{$ENDIF}
property Ctl3D;
property DragCursor;
{$IFDEF DFS_COMPILER_4_UP}
property DragKind;
{$ENDIF}
property DragMode;
property Enabled;
property Font;
property HideSelection;
{$IFDEF DFS_COMPILER_4_UP}
property HotTrack;
{$ENDIF}
property Indent;
property OnChange;
property OnChanging;
property OnClick;
property OnCollapsed;
property OnCollapsing;
property OnCompare;
{$IFDEF DFS_COMPILER_4_UP}
property OnCustomDraw;
property OnCustomDrawItem;
{$ENDIF}
property OnDblClick;
property OnDeletion;
property OnDragDrop;
property OnDragOver;
property OnEdited;
property OnEditing;
{$IFDEF DFS_COMPILER_4_UP}
property OnEndDock;
{$ENDIF}
property OnEndDrag;
property OnEnter;
property OnExit;
property OnExpanded;
property OnExpanding;
property OnGetImageIndex;
property OnGetSelectedIndex;
property OnKeyDown;
property OnKeyPress;
property OnKeyUp;
property OnMouseDown;
property OnMouseMove;
property OnMouseUp;
{$IFDEF DFS_COMPILER_4_UP}
property OnStartDock;
{$ENDIF}
property OnStartDrag;
{$IFDEF DFS_COMPILER_4_UP}
property ParentBiDiMode;
{$ENDIF}
{$IFDEF DFS_COMPILER_2}
property ParentColor;
{$ELSE}
property ParentColor default FALSE;
{$ENDIF}
property ParentCtl3D;
property ParentFont;
property ParentShowHint;
property PopupMenu;
property ReadOnly;
{$IFDEF DFS_COMPILER_3_UP}
property RightClickSelect;
{$ENDIF}
{$IFDEF DFS_COMPILER_4_UP}
property RowSelect;
{$ENDIF}
property ShowButtons;
property ShowHint;
property ShowLines;
property ShowRoot default TRUE;
property TabOrder;
property TabStop default True;
{$IFDEF DFS_COMPILER_4_UP}
property ToolTips;
{$ENDIF}
property Visible;
end;
{$IFDEF DFS_COMPILER_2}
const
SHGDFIL_FINDDATA = 1;
SHGDFIL_NETRESOURCE = 2;
SHGDFIL_DESCRIPTIONID = 3;
function SHGetDataFromIDList(psf: IShellFolder; pidl: PItemIDList;
nFormat: Integer; ptr: Pointer; cb: Integer): HResult; stdcall;
{$ENDIF}
implementation
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -