CustomDriveView.pas 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288
  1. unit CustomDriveView;
  2. interface
  3. uses
  4. Classes, ComCtrls, CommCtrl, Windows, Controls, Forms, ShlObj, Messages,
  5. Graphics,
  6. DragDrop, CustomDirView, IEDriveInfo, DragDropFilesEx, PasTools;
  7. type
  8. {Types uses by the function IterateSubTree:}
  9. {TRecursiveScan: determines, wich nodes are scanned by the function IterateSubTree:
  10. rsNoRecursive: Scan startnode only.
  11. rsRecursiveExisting: Scan all subnodes of the startnode but not new created subnodes.}
  12. TRecursiveScan = (rsNoRecursive, rsRecursiveExisting);
  13. {TScanStartnode: determines, wether the startnode should also be scanned:}
  14. TScanStartNode = (coNoScanStartNode, coScanStartNode);
  15. TCallBackFunc = function(var Node: TTreeNode; Data: Pointer): Boolean of object;
  16. type
  17. TCustomDriveView = class(TCustomTreeView)
  18. protected
  19. FParentForm: TCustomForm;
  20. FDragFileList: TStringList;
  21. FDragDropFilesEx: TCustomizableDragDropFilesEx;
  22. FDragImageList: TDragImageList;
  23. FDragDrive: string;
  24. FExeDrag: Boolean;
  25. FDDLinkOnExeDrag: Boolean;
  26. FDragNode: TTreeNode;
  27. FDragStartTime: FILETIME;
  28. FDragPos: TPoint;
  29. FStartPos: TPoint;
  30. FContextMenu: Boolean;
  31. FCanChange: Boolean;
  32. FUseSystemContextMenu: Boolean;
  33. FDimmHiddenDirs: Boolean;
  34. FShowHiddenDirs: Boolean;
  35. FNaturalOrderNumericalSorting: Boolean;
  36. FDarkMode: Boolean;
  37. FContinue: Boolean;
  38. FImageList: TImageList;
  39. FScrollOnDragOver: TTreeViewScrollOnDragOver;
  40. FOnDDDragEnter: TDDOnDragEnter;
  41. FOnDDDragLeave: TDDOnDragLeave;
  42. FOnDDDragOver: TDDOnDragOver;
  43. FOnDDDrop: TDDOnDrop;
  44. FOnDDQueryContinueDrag: TDDOnQueryContinueDrag;
  45. FOnDDChooseEffect: TDDOnChooseEffect;
  46. FOnDDGiveFeedback: TDDOnGiveFeedback;
  47. FOnDDDragDetect: TDDOnDragDetect;
  48. FOnDDProcessDropped: TOnProcessDropped;
  49. FOnDDError: TDDErrorEvent;
  50. FOnDDExecuted: TDDExecutedEvent;
  51. FOnDDFileOperation: TDDFileOperationEvent;
  52. FOnDDFileOperationExecuted: TDDFileOperationExecutedEvent;
  53. FOnDDCreateDragFileList: TDDOnCreateDragFileList;
  54. FOnDDEnd: TNotifyEvent;
  55. FOnDDCreateDataObject: TDDOnCreateDataObject;
  56. FLastDDResult: TDragResult;
  57. FOnBusy: TDirViewBusy;
  58. function GetTargetPopupMenu: Boolean;
  59. procedure SetTargetPopUpMenu(Value: Boolean);
  60. procedure SetDimmHiddenDirs(Value: Boolean);
  61. procedure SetShowHiddenDirs(Value: Boolean);
  62. procedure SetNaturalOrderNumericalSorting(Value: Boolean);
  63. procedure SetDarkMode(Value: Boolean);
  64. function GetDirectory: string; virtual;
  65. procedure SetDirectory(Value: string); virtual;
  66. function GetCustomDirView: TCustomDirView; virtual; abstract;
  67. procedure SetCustomDirView(Value: TCustomDirView); virtual; abstract;
  68. procedure CreateWnd; override;
  69. procedure Notification(AComponent: TComponent; Operation: TOperation); override;
  70. function GetNodeFromHItem(Item: TTVItem): TTreeNode;
  71. function IsCustomDrawn(Target: TCustomDrawTarget; Stage: TCustomDrawStage): Boolean; override;
  72. function CustomDrawItem(Node: TTreeNode; State: TCustomDrawState;
  73. Stage: TCustomDrawStage; var PaintImages: Boolean): Boolean; override;
  74. procedure NeedImageLists(Recreate: Boolean);
  75. procedure DoCompare(Sender: TObject; Node1, Node2: TTreeNode; Data: Integer; var Compare: Integer);
  76. procedure CNNotify(var Msg: TWMNotify); message CN_NOTIFY;
  77. procedure CMColorChanged(var Msg: TMessage); message CM_COLORCHANGED;
  78. procedure CMRecreateWnd(var Msg: TMessage); message CM_RECREATEWND;
  79. procedure WMLButtonDown(var Msg: TWMLButtonDown); message WM_LBUTTONDOWN;
  80. procedure WMLButtonUp(var Msg: TWMLButtonDown); message WM_LBUTTONUP;
  81. procedure WMRButtonDown(var Msg: TWMRButtonDown); message WM_RBUTTONDOWN;
  82. procedure WMLButtonDblClk(var Message: TWMLButtonDblClk); message WM_LBUTTONDBLCLK;
  83. procedure WMContextMenu(var Msg: TWMContextMenu); message WM_CONTEXTMENU;
  84. procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;
  85. procedure CMDPIChanged(var Message: TMessage); message CM_DPICHANGED;
  86. procedure Delete(Node: TTreeNode); override;
  87. procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  88. procedure KeyPress(var Key: Char); override;
  89. procedure KeyUp(var Key: Word; Shift: TShiftState); override;
  90. procedure InternalOnDrawItem(Sender: TCustomTreeView; Node: TTreeNode;
  91. State: TCustomDrawState; var DefaultDraw: Boolean);
  92. procedure DDDragEnter(DataObj: IDataObject; KeyState: Longint;
  93. Point: TPoint; var Effect: Longint; var Accept: Boolean);
  94. procedure DDDragLeave;
  95. procedure DDDragOver(KeyState: Longint; Point: TPoint; var Effect: Longint);
  96. procedure DDDrop(DataObj: IDataObject; KeyState: Longint; Point: TPoint;
  97. var Effect: Longint);
  98. procedure DDQueryContinueDrag(EscapePressed: BOOL; KeyState: Longint;
  99. var Result: HResult);
  100. procedure DDDropHandlerSucceeded(Sender: TObject; KeyState: Longint;
  101. Point: TPoint; Effect: Longint);
  102. procedure DDGiveFeedback(Effect: Longint; var Result: HResult);
  103. procedure DDProcessDropped(Sender: TObject; KeyState: Longint;
  104. Point: TPoint; Effect: Longint);
  105. procedure DDError(Error: TDDError); virtual;
  106. procedure DDSpecifyDropTarget(Sender: TObject; DragDropHandler: Boolean;
  107. Point: TPoint; var PIDL: PItemIDList; var Filename: string);
  108. procedure DDDragDetect(KeyState: Longint; DetectStart, Point: TPoint;
  109. DragStatus: TDragDetectStatus); virtual;
  110. procedure PerformDragDropFileOperation(Node: TTreeNode; Effect: Integer); virtual; abstract;
  111. procedure DDChooseEffect(KeyState: Integer; var Effect: Integer); virtual;
  112. function DragCompleteFileList: Boolean; virtual; abstract;
  113. function DDExecute: TDragResult; virtual;
  114. function DDSourceEffects: TDropEffectSet; virtual; abstract;
  115. function NodePath(Node: TTreeNode): string; virtual; abstract;
  116. function NodeIsRecycleBin(Node: TTreeNode): Boolean; virtual;
  117. function NodePathExists(Node: TTreeNode): Boolean; virtual;
  118. function NodeColor(Node: TTreeNode): TColor; virtual; abstract;
  119. function NodeCanDrag(Node: TTreeNode): Boolean; virtual;
  120. function NodeOverlayIndexes(Node: TTreeNode): Word; virtual;
  121. function FindPathNode(Path: string): TTreeNode; virtual; abstract;
  122. procedure ClearDragFileList(FileList: TFileList); virtual;
  123. procedure AddToDragFileList(FileList: TFileList; Node: TTreeNode); virtual;
  124. procedure ValidateDirectoryEx(Node: TTreeNode; Recurse: TRecursiveScan;
  125. NewDirs: Boolean); virtual; abstract;
  126. procedure RebuildTree; virtual; abstract;
  127. procedure DisplayContextMenu(Node: TTreeNode; ScreenPos: TPoint); virtual; abstract;
  128. procedure DisplayPropertiesMenu(Node: TTreeNode); virtual; abstract;
  129. procedure ScrollOnDragOverBeforeUpdate(ObjectToValidate: TObject);
  130. procedure ScrollOnDragOverAfterUpdate;
  131. function DoBusy(Busy: Integer): Boolean;
  132. function StartBusy: Boolean;
  133. procedure EndBusy;
  134. function IsBusy: Boolean;
  135. property ImageList: TImageList read FImageList;
  136. public
  137. constructor Create(AOwner: TComponent); override;
  138. destructor Destroy; override;
  139. procedure ValidateDirectory(Node: TTreeNode);
  140. procedure CenterNode(Node: TTreeNode); virtual;
  141. function SortChildren(ParentNode: TTreeNode; Recurse: Boolean): Boolean;
  142. function IterateSubTree(var StartNode : TTreeNode;
  143. CallBackFunc: TCallBackFunc; Recurse: TRecursiveScan;
  144. ScanStartNode: TScanStartNode; Data: Pointer): Boolean;
  145. function NodePathName(Node: TTreeNode): string; virtual; abstract;
  146. property DragDropFilesEx: TCustomizableDragDropFilesEx read FDragDropFilesEx;
  147. property UseSystemContextMenu: Boolean read FUseSystemContextMenu
  148. write FUseSystemContextMenu default True;
  149. property DimmHiddenDirs: Boolean read FDimmHiddenDirs
  150. write SetDimmHiddenDirs default False;
  151. property ShowHiddenDirs: Boolean read FShowHiddenDirs
  152. write SetShowHiddenDirs default False;
  153. property NaturalOrderNumericalSorting: Boolean read FNaturalOrderNumericalSorting write SetNaturalOrderNumericalSorting;
  154. property DarkMode: Boolean read FDarkMode write SetDarkMode;
  155. property DDLinkOnExeDrag: Boolean read FDDLinkOnExeDrag write FDDLinkOnExeDrag default True;
  156. {The mouse has entered the component window as a target of a drag&drop operation:}
  157. property OnDDDragEnter: TDDOnDragEnter read FOnDDDragEnter write FOnDDDragEnter;
  158. {The mouse has leaved the component window as a target of a drag&drop operation:}
  159. property OnDDDragLeave: TDDOnDragLeave read FOnDDDragLeave write FOnDDDragLeave;
  160. {The mouse is dragging in the component window as a target of a drag&drop operation:}
  161. property OnDDDragOver: TDDOnDragOver read FOnDDDragOver write FOnDDDragOver;
  162. {The Drag&drop operation is about to be executed:}
  163. property OnDDDrop: TDDOnDrop read FOnDDDrop write FOnDDDrop;
  164. property OnDDQueryContinueDrag: TDDOnQueryContinueDrag read FOnDDQueryContinueDrag write FOnDDQueryContinueDrag;
  165. property OnDDChooseEffect: TDDOnChooseEffect read FOnDDChooseEffect write FOnDDChooseEffect;
  166. property OnDDGiveFeedback: TDDOnGiveFeedback read FOnDDGiveFeedback write FOnDDGiveFeedback;
  167. {A drag&drop operation is about to be initiated whith the components window as the source:}
  168. property OnDDDragDetect: TDDOnDragDetect read FOnDDDragDetect write FOnDDDragDetect;
  169. {The component window is the target of a drag&drop operation:}
  170. property OnDDProcessDropped: TOnProcessDropped read FOnDDProcessDropped write FOnDDProcessDropped;
  171. {An error has occurred during a drag&drop operation:}
  172. property OnDDError: TDDErrorEvent read FOnDDError write FOnDDError;
  173. {The drag&drop operation has been executed:}
  174. property OnDDExecuted: TDDExecutedEvent read FOnDDExecuted write FOnDDExecuted;
  175. {Event is fired just before executing the fileoperation. This event is also fired when
  176. files are pasted from the clipboard:}
  177. property OnDDFileOperation: TDDFileOperationEvent read FOnDDFileOperation write FOnDDFileOperation;
  178. {Event is fired after executing the fileoperation. This event is also fired when
  179. files are pasted from the clipboard:}
  180. property OnDDFileOperationExecuted: TDDFileOperationExecutedEvent read FOnDDFileOperationExecuted write FOnDDFileOperationExecuted;
  181. property OnDDCreateDragFileList: TDDOnCreateDragFileList
  182. read FOnDDCreateDragFileList write FOnDDCreateDragFileList;
  183. property OnDDEnd: TNotifyEvent
  184. read FOnDDEnd write FOnDDEnd;
  185. property OnDDCreateDataObject: TDDOnCreateDataObject
  186. read FOnDDCreateDataObject write FOnDDCreateDataObject;
  187. property OnBusy: TDirViewBusy read FOnBusy write FOnBusy;
  188. { Show popupmenu when dropping a file with the right mouse button }
  189. property TargetPopUpMenu: Boolean read GetTargetPopUpMenu write SetTargetPopUpMenu default True;
  190. {Current selected directory:}
  191. property Directory: string read GetDirectory write SetDirectory;
  192. property DragNode: TTreeNode read FDragNode;
  193. property Continue: Boolean read FContinue write FContinue;
  194. property LastDDResult: TDragResult read FLastDDResult;
  195. end;
  196. resourcestring
  197. SDragDropError = 'Drag&drop error: %d';
  198. implementation
  199. uses
  200. SysUtils, ShellApi, ImgList, ActiveX,
  201. IEListView, BaseUtils;
  202. constructor TCustomDriveView.Create(AOwner: TComponent);
  203. begin
  204. inherited;
  205. DragMode := dmAutomatic;
  206. FDragFileList := TStringList.Create;
  207. FDragDrive := '';
  208. FExeDrag := False;
  209. FDDLinkOnExeDrag := True;
  210. FContextMenu := False;
  211. FCanChange := True;
  212. FUseSystemContextMenu := True;
  213. FContinue := True;
  214. FNaturalOrderNumericalSorting := True;
  215. FDarkMode := False;
  216. OnCompare := DoCompare;
  217. FDragDropFilesEx := TCustomizableDragDropFilesEx.Create(Self);
  218. with FDragDropFilesEx do
  219. begin
  220. AcceptOwnDnd := True;
  221. {MP}
  222. AutoDetectDnD := False;
  223. {/MP}
  224. BringToFront := True;
  225. CompleteFileList := True;
  226. NeedValid := [nvFileName];
  227. RenderDataOn := rdoEnterAndDropSync;
  228. TargetPopUpMenu := True;
  229. OnDragEnter := DDDragEnter;
  230. OnDragLeave := DDDragLeave;
  231. OnDragOver := DDDragOver;
  232. OnDrop := DDDrop;
  233. OnQueryContinueDrag := DDQueryContinueDrag;
  234. OnSpecifyDropTarget := DDSpecifyDropTarget;
  235. OnDropHandlerSucceeded := DDDropHandlerSucceeded;
  236. OnGiveFeedback := DDGiveFeedback;
  237. OnProcessDropped := DDProcessDropped;
  238. OnDragDetect := DDDragDetect;
  239. end;
  240. OnCustomDrawItem := InternalOnDrawItem;
  241. FScrollOnDragOver := TTreeViewScrollOnDragOver.Create(Self, False);
  242. FScrollOnDragOver.OnBeforeUpdate := ScrollOnDragOverBeforeUpdate;
  243. FScrollOnDragOver.OnAfterUpdate := ScrollOnDragOverAfterUpdate;
  244. end;
  245. destructor TCustomDriveView.Destroy;
  246. begin
  247. FreeAndNil(FScrollOnDragOver);
  248. FreeAndNil(FImageList);
  249. if Assigned(Images) then
  250. Images.Free;
  251. if Assigned(FDragImageList) then
  252. begin
  253. if GlobalDragImageList = FDragImageList then
  254. GlobalDragImageList := nil;
  255. FDragImageList.Free;
  256. end;
  257. FDragFileList.Destroy;
  258. if Assigned(FDragDropFilesEx) then
  259. FDragDropFilesEx.Free;
  260. inherited Destroy;
  261. end;
  262. procedure TCustomDriveView.NeedImageLists(Recreate: Boolean);
  263. var
  264. MinHeight: Integer;
  265. AImages: TImageList;
  266. begin
  267. if not Assigned(Images) then
  268. begin
  269. Images := TImageList.Create(Self);
  270. Images.BkColor := Color;
  271. end;
  272. AImages := ShellImageListForControl(Self, ilsSmall);
  273. if Images.Handle <> AImages.Handle then
  274. begin
  275. Images.Handle := AImages.Handle;
  276. end;
  277. if (not Assigned(FImageList)) or Recreate then
  278. begin
  279. if Assigned(FImageList) then
  280. FImageList.Free;
  281. FImageList := OverlayImageList(Images.Width);
  282. end;
  283. MinHeight := ScaleByTextHeight(Self, 18);
  284. if TreeView_GetItemHeight(Handle) < MinHeight then
  285. TreeView_SetItemHeight(Handle, MinHeight);
  286. end;
  287. procedure TCustomDriveView.CMDPIChanged(var Message: TMessage);
  288. begin
  289. inherited;
  290. NeedImageLists(True);
  291. end;
  292. procedure TCustomDriveView.CreateWnd;
  293. begin
  294. inherited;
  295. if DarkMode then AllowDarkModeForWindow(Self, DarkMode);
  296. NeedImageLists(False);
  297. if not (csDesigning in ComponentState) then
  298. FDragImageList := TDragImageList.Create(Self);
  299. if not Assigned(GlobalDragImageList) then
  300. GlobalDragImageList := FDragImageList;
  301. FDragDropFilesEx.DragDropControl := Self;
  302. FParentForm := GetParentForm(Self);
  303. end;
  304. procedure TCustomDriveView.Notification(AComponent: TComponent; Operation: TOperation);
  305. begin
  306. inherited;
  307. if Operation = opRemove then
  308. begin
  309. if AComponent = GetCustomDirView then SetCustomDirView(nil);
  310. end;
  311. end;
  312. procedure TCustomDriveView.InternalOnDrawItem(Sender: TCustomTreeView; Node: TTreeNode;
  313. State: TCustomDrawState; var DefaultDraw: Boolean);
  314. var
  315. FItemColor: TColor;
  316. begin
  317. if Assigned(Node) and Assigned(Node.Data) and (Node <> DropTarget) then
  318. begin
  319. if not Node.Selected then
  320. begin
  321. FItemColor := NodeColor(Node);
  322. if (FItemColor <> clDefaultItemColor) and
  323. (Canvas.Font.Color <> FItemColor) then
  324. Canvas.Font.Color := FItemColor;
  325. end
  326. else
  327. if (not Self.Focused) and HideSelection then
  328. begin
  329. Canvas.Brush.Color := clBtnFace;
  330. Canvas.Font.Color := clBtnText;
  331. end;
  332. end;
  333. end; {InternalOnDrawItem}
  334. procedure TCustomDriveView.ScrollOnDragOverBeforeUpdate(ObjectToValidate: TObject);
  335. var
  336. NodeToValidate: TTreeNode;
  337. begin
  338. GlobalDragImageList.HideDragImage;
  339. if Assigned(ObjectToValidate) then
  340. begin
  341. NodeToValidate := (ObjectToValidate as TTreeNode);
  342. if not NodeToValidate.HasChildren then
  343. ValidateDirectory(NodeToValidate);
  344. end;
  345. end;
  346. procedure TCustomDriveView.ScrollOnDragOverAfterUpdate;
  347. begin
  348. GlobalDragImageList.ShowDragImage;
  349. end;
  350. procedure TCustomDriveView.DDDragEnter(DataObj: IDataObject; KeyState: Longint;
  351. Point: TPoint; var Effect: Longint; var Accept: Boolean);
  352. var
  353. Index: Integer;
  354. begin
  355. if (FDragDropFilesEx.FileList.Count > 0) and
  356. (Length(TFDDListItem(FDragDropFilesEx.FileList[0]^).Name) > 0) Then
  357. begin
  358. try
  359. FDragDrive := DriveInfo.GetDriveKey(TFDDListItem(FDragDropFilesEx.FileList[0]^).Name);
  360. except
  361. // WinRAR gives us only filename on "enter", we get a full path only on "drop".
  362. FDragDrive := '';
  363. end;
  364. FExeDrag := FDDLinkOnExeDrag and
  365. (deLink in DragDropFilesEx.TargetEffects) and
  366. ((DragDropFilesEx.AvailableDropEffects and DROPEFFECT_LINK) <> 0);
  367. if FExeDrag then
  368. begin
  369. for Index := 0 to FDragDropFilesEx.FileList.Count - 1 do
  370. if not IsExecutable(TFDDListItem(FDragDropFilesEx.FileList[Index]^).Name) then
  371. begin
  372. FExeDrag := False;
  373. Break;
  374. end;
  375. end;
  376. end
  377. else
  378. begin
  379. FDragDrive := '';
  380. end;
  381. FScrollOnDragOver.StartDrag;
  382. if Assigned(FOnDDDragEnter) then
  383. FOnDDDragEnter(Self, DataObj, KeyState, Point, Effect, Accept);
  384. end; {DDDragEnter}
  385. procedure TCustomDriveView.DDDragLeave;
  386. begin
  387. if Assigned(DropTarget) then
  388. begin
  389. if GlobalDragImageList.Dragging then
  390. GlobalDragImageList.HideDragImage;
  391. DropTarget := nil;
  392. Update;
  393. end;
  394. if Assigned(FOnDDDragLeave) then
  395. FOnDDDragLeave(Self);
  396. end; {DragLeave}
  397. procedure TCustomDriveView.DDDragOver(KeyState: Longint; Point: TPoint; var Effect: Longint);
  398. var
  399. Node: TTreeNode;
  400. Rect1: TRect;
  401. UpdateImage: Boolean;
  402. LastDragNode: TTreeNode;
  403. begin
  404. if Effect <> DROPEFFECT_NONE then
  405. begin
  406. Node := GetNodeAt(Point.X, Point.Y);
  407. if Assigned(Node) then
  408. begin
  409. LastDragNode := DropTarget;
  410. UpdateImage := False;
  411. if GlobalDragImageList.Dragging and (LastDragNode <> Node) then
  412. begin
  413. if Assigned(LastDragNode) then
  414. begin
  415. Rect1 := LastDragNode.DisplayRect(True);
  416. if Rect1.Right >= Point.x - GlobalDragImageList.GetHotSpot.X then
  417. begin
  418. GlobalDragImageList.HideDragImage;
  419. UpdateImage := True;
  420. end
  421. else
  422. begin
  423. Rect1 := Node.DisplayRect(True);
  424. if Rect1.Right >= Point.x - GlobalDragImageList.GetHotSpot.X then
  425. begin
  426. GlobalDragImageList.HideDragImage;
  427. UpdateImage := True;
  428. end
  429. end;
  430. end
  431. else
  432. begin
  433. {LastDragNode not assigned:}
  434. GlobalDragImageList.HideDragImage;
  435. UpdateImage := True;
  436. end;
  437. end;
  438. DropTarget := Node;
  439. if UpdateImage then
  440. GlobalDragImageList.ShowDragImage;
  441. {Drop-operation allowed at this location?}
  442. if Assigned(FDragNode) and
  443. (Effect <> DROPEFFECT_LINK) and
  444. ((Node = FDragNode) or Node.HasAsParent(FDragNode) or (FDragNode.Parent = Node)) then
  445. Effect := DROPEFFECT_NONE;
  446. FScrollOnDragOver.DragOver(Point);
  447. end {Assigned(Node)}
  448. else
  449. begin
  450. DropTarget := nil;
  451. end;
  452. end;
  453. DDChooseEffect(KeyState, Effect);
  454. if Assigned(FOnDDDragOver) then
  455. FOnDDDragOver(Self, KeyState, Point, Effect);
  456. if not Assigned(DropTarget) then Effect := DROPEFFECT_NONE
  457. else
  458. if NodeIsRecycleBin(DropTarget) then
  459. begin
  460. if FDragDropFilesEx.FileNamesAreMapped then Effect := DROPEFFECT_NONE
  461. else Effect := DROPEFFECT_MOVE;
  462. end;
  463. end; {DDDragOver}
  464. procedure TCustomDriveView.DDDrop(DataObj: IDataObject; KeyState: Longint;
  465. Point: TPoint; var Effect: Longint);
  466. begin
  467. if GlobalDragImageList.Dragging then
  468. GlobalDragImageList.HideDragImage;
  469. if Effect = DROPEFFECT_NONE then
  470. DropTarget := nil;
  471. if Assigned(FOnDDDrop) then
  472. FOnDDDrop(Self, DataObj, KeyState, Point, Effect);
  473. end; {DDDrop}
  474. procedure TCustomDriveView.DDQueryContinueDrag(EscapePressed: BOOL; KeyState: Longint;
  475. var Result: HResult);
  476. var
  477. Point: TPoint;
  478. ClientPoint: TPoint;
  479. KnowTime: FILETIME;
  480. begin
  481. if Result = DRAGDROP_S_DROP then
  482. begin
  483. GetSystemTimeAsFileTime(KnowTime);
  484. if ((Int64(KnowTime) - Int64(FDragStartTime)) <= DDDragStartDelay) then
  485. Result := DRAGDROP_S_CANCEL;
  486. end;
  487. if Assigned(FOnDDQueryContinueDrag) then
  488. FOnDDQueryContinueDrag(Self, EscapePressed, KeyState, Result);
  489. if EscapePressed then
  490. begin
  491. if GlobalDragImageList.Dragging then
  492. GlobalDragImageList.HideDragImage;
  493. DropTarget := nil;
  494. end
  495. else
  496. begin
  497. if GlobalDragImageList.Dragging then
  498. begin
  499. GetCursorPos(Point);
  500. {Convert screen coordinates to the parentforms coordinates:}
  501. ClientPoint := FParentForm.ScreenToClient(Point);
  502. {Move the drag image to the new position and show it:}
  503. if not CompareMem(@ClientPoint, @FDragPos, SizeOf(TPoint)) then
  504. begin
  505. FDragPos := ClientPoint;
  506. if PtInRect(FParentForm.BoundsRect, Point) then
  507. begin
  508. GlobalDragImageList.DragMove(ClientPoint.X, ClientPoint.Y);
  509. GlobalDragImageList.ShowDragImage;
  510. end
  511. else GlobalDragImageList.HideDragImage;
  512. end;
  513. end;
  514. end;
  515. end; {DDQueryContinueDrag}
  516. procedure TCustomDriveView.DDDropHandlerSucceeded(Sender: TObject;
  517. KeyState: Integer; Point: TPoint; Effect: Integer);
  518. begin
  519. DropTarget := nil;
  520. end;
  521. procedure TCustomDriveView.DDChooseEffect(KeyState: Integer; var Effect: Integer);
  522. begin
  523. if Assigned(FOnDDChooseEffect) then
  524. FOnDDChooseEffect(Self, KeyState, Effect);
  525. end;
  526. procedure TCustomDriveView.DDGiveFeedback(Effect: Longint; var Result: HResult);
  527. begin
  528. if Assigned(FOnDDGiveFeedback) then
  529. FOnDDGiveFeedback(Self, Effect, Result);
  530. end; {DDGiveFeedback}
  531. procedure TCustomDriveView.DDProcessDropped(Sender: TObject; KeyState: Longint;
  532. Point: TPoint; Effect: Longint);
  533. begin
  534. try
  535. if Assigned(DropTarget) then
  536. try
  537. if NodePathExists(DropTarget) then
  538. begin
  539. if Assigned(FOnDDProcessDropped) then
  540. FOnDDProcessDropped(Self, KeyState, Point, Effect);
  541. if Effect <> DROPEFFECT_NONE then
  542. begin
  543. PerformDragDropFileOperation(DropTarget, Effect);
  544. if Assigned(FOnDDExecuted) then
  545. FOnDDExecuted(Self, Effect);
  546. end;
  547. end
  548. else
  549. begin
  550. ValidateDirectory(DropTarget);
  551. DDError(DDPathNotFoundError);
  552. end;
  553. finally
  554. DropTarget := nil;
  555. ClearDragFileList(FDragDropFilesEx.FileList);
  556. end;
  557. except
  558. Application.HandleException(Self);
  559. end;
  560. end; {ProcessDropped}
  561. procedure TCustomDriveView.DDError(Error: TDDError);
  562. begin
  563. if Assigned(FOnDDError) then FOnDDError(Self, Error)
  564. else raise Exception.CreateFmt(SDragDropError, [Ord(Error)]);
  565. end; {DDError}
  566. procedure TCustomDriveView.DDSpecifyDropTarget(Sender: TObject;
  567. DragDropHandler: Boolean; Point: TPoint; var PIDL: PItemIDList; var Filename: string);
  568. begin
  569. PIDL := nil;
  570. if DragDropHandler and Assigned(DropTarget) then FileName := NodePathName(DropTarget)
  571. else FileName := EmptyStr;
  572. end; {DDSpecifyDropTarget}
  573. procedure TCustomDriveView.DDDragDetect(KeyState: Longint; DetectStart, Point: TPoint;
  574. DragStatus: TDragDetectStatus);
  575. var
  576. P: TPoint;
  577. ImageList: HImageList;
  578. NodeRect: TRect;
  579. FileListCreated: Boolean;
  580. AvoidDragImage: Boolean;
  581. begin
  582. if (DragStatus = ddsDrag) and (not Assigned(FDragNode)) then
  583. begin
  584. P := ScreenToClient(FStartPos);
  585. FDragNode := GetNodeAt(P.X, P.Y);
  586. end;
  587. if Assigned(FOnDDDragDetect) then
  588. FOnDDDragDetect(Self, KeyState, DetectStart, Point, DragStatus);
  589. if (DragStatus = ddsDrag) and Assigned(FDragNode) then
  590. begin
  591. NodeRect := FDragNode.DisplayRect(True);
  592. Dec(NodeRect.Left, 16);
  593. {Check, wether the mouse cursor was within the nodes display rectangle:}
  594. if (NodeRect.Left > P.X) or (NodeRect.Right < P.X) or
  595. (not NodeCanDrag(FDragNode)) then
  596. begin
  597. FDragNode := nil;
  598. Exit;
  599. end;
  600. FDragDrive := '';
  601. ClearDragFileList(FDragDropFilesEx.FileList);
  602. FDragDropFilesEx.CompleteFileList := DragCompleteFileList;
  603. FileListCreated := False;
  604. AvoidDragImage := False;
  605. if Assigned(OnDDCreateDragFileList) then
  606. begin
  607. OnDDCreateDragFileList(Self, FDragDropFilesEx.FileList, FileListCreated);
  608. if FileListCreated then
  609. AvoidDragImage := True;
  610. end;
  611. if not FileListCreated then
  612. begin
  613. AddToDragFileList(FDragDropFilesEx.FileList, FDragNode);
  614. end;
  615. FDragDropFilesEx.SourceEffects := DDSourceEffects;
  616. if FDragDropFilesEx.FileList.Count > 0 then
  617. try
  618. {Create the dragimage:}
  619. GlobalDragImageList := FDragImageList;
  620. if not AvoidDragImage then
  621. begin
  622. {Hide the selection mark to get a proper dragimage:}
  623. if Selected = FDragNode then
  624. Selected := nil;
  625. ImageList := TreeView_CreateDragImage(Handle, FDragNode.ItemID);
  626. {Show the selection mark if it was hidden:}
  627. if not Assigned(Selected) then
  628. Selected := FDragNode;
  629. if ImageList <> Invalid_Handle_Value then
  630. begin
  631. GlobalDragImageList.Handle := ImageList;
  632. GlobalDragImageList.SetDragImage(0, P.X - NodeRect.TopLeft.X, P.Y - NodeRect.TopLeft.Y);
  633. P := FParentForm.ScreenToClient(Point);
  634. GlobalDragImageList.BeginDrag(FParentForm.Handle, P.X, P.Y);
  635. GlobalDragImageList.HideDragImage;
  636. ShowCursor(True);
  637. end;
  638. end;
  639. DropSourceControl := Self;
  640. GetSystemTimeAsFileTime(FDragStartTime);
  641. {Supress the context menu:}
  642. FContextMenu := False;
  643. {Execute the drag&drop-Operation:}
  644. FLastDDResult := DDExecute;
  645. {the drag&drop operation is finished, so clean up the used drag image:}
  646. GlobalDragImageList.EndDrag;
  647. GlobalDragImageList.Clear;
  648. Application.ProcessMessages;
  649. finally
  650. ClearDragFileList(FDragDropFilesEx.FileList);
  651. FDragDrive := '';
  652. DropTarget := nil;
  653. try
  654. if Assigned(OnDDEnd) then
  655. OnDDEnd(Self);
  656. finally
  657. DropSourceControl := nil;
  658. FDragNode := nil;
  659. end;
  660. end;
  661. end;
  662. end; {(DDDragDetect}
  663. function TCustomDriveView.DDExecute: TDragResult;
  664. var
  665. DataObject: TDataObject;
  666. begin
  667. DataObject := nil;
  668. if Assigned(OnDDCreateDataObject) then
  669. OnDDCreateDataObject(Self, DataObject);
  670. Result := FDragDropFilesEx.Execute(DataObject);
  671. end;
  672. function TCustomDriveView.GetNodeFromHItem(Item: TTVItem): TTreeNode;
  673. begin
  674. Result := nil;
  675. if Items <> nil then
  676. with Item do
  677. if (state and TVIF_PARAM) <> 0 then
  678. Result := Pointer(lParam)
  679. else
  680. Result := Items.GetNode(hItem);
  681. end; {GetNodeFromItem}
  682. function TCustomDriveView.IsCustomDrawn(Target: TCustomDrawTarget;
  683. Stage: TCustomDrawStage): Boolean;
  684. begin
  685. Result := inherited IsCustomDrawn(Target, Stage) or
  686. ((Target = dtItem) and (Stage = cdPostPaint));
  687. end;
  688. function TCustomDriveView.CustomDrawItem(Node: TTreeNode; State: TCustomDrawState;
  689. Stage: TCustomDrawStage; var PaintImages: Boolean): Boolean;
  690. var
  691. Point: TPoint;
  692. Index: Integer;
  693. OverlayIndexes: Word;
  694. OverlayIndex: Word;
  695. Image: Word;
  696. begin
  697. Result := inherited CustomDrawItem(Node, State, Stage, PaintImages);
  698. if Result and (Stage = cdPostPaint) then
  699. begin
  700. Assert(Assigned(Node));
  701. OverlayIndexes := NodeOverlayIndexes(Node);
  702. OverlayIndex := 1;
  703. while OverlayIndexes > 0 do
  704. begin
  705. if (OverlayIndex and OverlayIndexes) <> 0 then
  706. begin
  707. Index := 0;
  708. Image := OverlayIndex;
  709. while Image > 1 do
  710. begin
  711. Inc(Index);
  712. Image := Image shr 1;
  713. end;
  714. Point := Node.DisplayRect(True).TopLeft;
  715. Dec(Point.X, Indent);
  716. ImageList_Draw(ImageList.Handle, Index, Self.Canvas.Handle,
  717. Point.X, Point.Y, ILD_TRANSPARENT);
  718. Dec(OverlayIndexes, OverlayIndex);
  719. end;
  720. OverlayIndex := OverlayIndex shl 1;
  721. end;
  722. end;
  723. end;
  724. procedure TCustomDriveView.CNNotify(var Msg: TWMNotify);
  725. begin
  726. case Msg.NMHdr.code of
  727. TVN_BEGINDRAG: DDDragDetect(MK_LBUTTON, FStartPos, Mouse.CursorPos, ddsDrag);
  728. TVN_BEGINRDRAG: DDDragDetect(MK_RBUTTON, FStartPos, Mouse.CursorPos, ddsDrag);
  729. else
  730. inherited;
  731. end;
  732. end; {CNNotify}
  733. procedure TCustomDriveView.CMColorChanged(var Msg: TMessage);
  734. begin
  735. inherited;
  736. if Assigned(Images) then
  737. Images.BkColor := Color;
  738. ForceColorChange(Self);
  739. end;
  740. procedure TCustomDriveView.WMLButtonDown(var Msg: TWMLButtonDown);
  741. begin
  742. if not IsBusy then
  743. begin
  744. FCanChange := False;
  745. GetCursorPos(FStartPos);
  746. inherited;
  747. end;
  748. end; {WMLButtonDown}
  749. procedure TCustomDriveView.WMLButtonUp(var Msg: TWMLButtonDown);
  750. begin
  751. FCanChange := True;
  752. if Assigned(DropTarget) and Assigned(DropTarget.Data) then
  753. Selected := DropTarget;
  754. DropTarget := nil;
  755. inherited;
  756. end; {WMLButtonUp}
  757. procedure TCustomDriveView.WMRButtonDown(var Msg: TWMRButtonDown);
  758. begin
  759. if not IsBusy then
  760. begin
  761. GetCursorPos(FStartPos);
  762. if FDragDropFilesEx.DragDetectStatus <> ddsDrag then
  763. FContextMenu := True;
  764. inherited;
  765. end;
  766. end; {WMRButtonDown}
  767. procedure TCustomDriveView.WMLButtonDblClk(var Message: TWMLButtonDblClk);
  768. begin
  769. if not IsBusy then
  770. begin
  771. inherited;
  772. end;
  773. end;
  774. procedure TCustomDriveView.WMContextMenu(var Msg: TWMContextMenu);
  775. var
  776. Node: TTreeNode;
  777. Point: TPoint;
  778. PrevAutoPopup: Boolean;
  779. begin
  780. PrevAutoPopup := False;
  781. try
  782. if Assigned(PopupMenu) then
  783. begin
  784. PrevAutoPopup := PopupMenu.AutoPopup;
  785. PopupMenu.AutoPopup := False;
  786. end;
  787. inherited;
  788. finally
  789. if Assigned(PopupMenu) then
  790. PopupMenu.AutoPopup := PrevAutoPopup;
  791. end;
  792. FStartPos.X := -1;
  793. FStartPos.Y := -1;
  794. try
  795. if FContextMenu then
  796. begin
  797. Point.X := Msg.XPos;
  798. Point.Y := Msg.YPos;
  799. Point := ScreenToClient(Point);
  800. Node := GetNodeAt(Point.X, Point.Y);
  801. if FUseSystemContextMenu and Assigned(Node) then
  802. begin
  803. if Assigned(OnMouseDown) then
  804. OnMouseDown(Self, mbRight, [], Msg.XPos, Msg.YPos);
  805. DisplayContextMenu(Node, Mouse.CursorPos);
  806. end
  807. else
  808. begin
  809. if Assigned(PopupMenu) then
  810. PopupMenu.Popup(Msg.XPos, Msg.YPos);
  811. end;
  812. end;
  813. FContextMenu := False;
  814. finally
  815. DropTarget := nil;
  816. end;
  817. end; {WMContextMenu}
  818. procedure TCustomDriveView.CMRecreateWnd(var Msg: TMessage);
  819. var
  820. HadHandle: Boolean;
  821. begin
  822. HadHandle := HandleAllocated;
  823. inherited;
  824. // If the control is not showing (e.g. because the machine is locked), the handle is not recreated.
  825. // If contents is reloaded (LoadPath) without handle allocated, it crashes
  826. // (as the handle is implicitly created somewhere in the middle of the reload and chaos ensures).
  827. if HadHandle then
  828. begin
  829. HandleNeeded;
  830. end;
  831. end;
  832. procedure TCustomDriveView.Delete(Node: TTreeNode);
  833. begin
  834. if Node = FDragNode then
  835. FDragNode := nil;
  836. if Node = DropTarget then
  837. begin
  838. DropTarget := nil;
  839. Update;
  840. end;
  841. inherited;
  842. end; {OnDelete}
  843. procedure TCustomDriveView.WMKeyDown(var Message: TWMKeyDown);
  844. begin
  845. if not IsBusy then
  846. begin
  847. inherited;
  848. end;
  849. end;
  850. procedure TCustomDriveView.KeyDown(var Key: Word; Shift: TShiftState);
  851. begin
  852. if (Key = VK_RETURN) and (ssAlt in Shift) and (not IsEditing) and
  853. Assigned(Selected) then
  854. begin
  855. DisplayPropertiesMenu(Selected);
  856. Key := 0;
  857. end;
  858. inherited;
  859. end; {KeyDown}
  860. procedure TCustomDriveView.KeyPress(var Key : Char);
  861. begin
  862. if Assigned(Selected) then
  863. begin
  864. if not IsEditing then
  865. begin
  866. case Key of
  867. #13, ' ':
  868. begin
  869. Selected.Expanded := not Selected.Expanded;
  870. Key := #0;
  871. end;
  872. '/':
  873. begin
  874. Selected.Collapse(True);
  875. Selected.MakeVisible;
  876. Key := #0;
  877. end;
  878. '*':
  879. Selected.MakeVisible;
  880. end {Case}
  881. end
  882. end;
  883. inherited;
  884. end; {KeyPress}
  885. procedure TCustomDriveView.KeyUp(var Key: Word; Shift: TShiftState);
  886. var
  887. Point: TPoint;
  888. begin
  889. inherited;
  890. if (Key = VK_APPS) and Assigned(Selected) then
  891. begin
  892. Point := ClientToScreen(Selected.DisplayRect(True).TopLeft);
  893. Inc(Point.Y, 20);
  894. DisplayContextMenu(Selected, Point);
  895. end;
  896. end; {KeyUp}
  897. procedure TCustomDriveView.ValidateDirectory(Node: TTreeNode);
  898. begin
  899. ValidateDirectoryEx(Node, rsRecursiveExisting, False);
  900. end; {ValidateDirectory}
  901. procedure TCustomDriveView.CenterNode(Node: TTreeNode);
  902. var
  903. NodePos: TRect;
  904. ScrollInfo: TScrollInfo;
  905. begin
  906. if Assigned(Node) and (Items.Count > 0) then
  907. begin
  908. Node.MakeVisible;
  909. NodePos := Node.DisplayRect(False);
  910. with ScrollInfo do
  911. begin
  912. cbSize := SizeOf(ScrollInfo);
  913. fMask := SIF_ALL;
  914. nMin := 0;
  915. nMax := 0;
  916. nPage := 0;
  917. end;
  918. GetScrollInfo(Handle, SB_VERT, ScrollInfo);
  919. if ScrollInfo.nMin <> ScrollInfo.nMax then
  920. begin
  921. {Scroll tree up:}
  922. if (NodePos.Top < Height div 4) and (ScrollInfo.nPos > 0) then
  923. begin
  924. ScrollInfo.fMask := SIF_POS;
  925. while (ScrollInfo.nPos > 0) and (NodePos.Top < (Height div 4)) do
  926. begin
  927. Perform(WM_VSCROLL, SB_LINEUP, 0);
  928. GetScrollInfo(Handle, SB_VERT, ScrollInfo);
  929. NodePos := Node.DisplayRect(False);
  930. end;
  931. end
  932. else
  933. if (NodePos.Top > ((Height * 3) div 4)) then
  934. begin
  935. {Scroll tree down:}
  936. ScrollInfo.fMask := SIF_POS;
  937. while (ScrollInfo.nPos + ABS(ScrollInfo.nPage) < ScrollInfo.nMax) and
  938. (NodePos.Top > ((Height * 3) div 4)) and
  939. (ScrollInfo.nPage > 0) do
  940. begin
  941. Perform(WM_VSCROLL, SB_LINEDOWN, 0);
  942. GetScrollInfo(Handle, SB_VERT, ScrollInfo);
  943. NodePos := Node.DisplayRect(False);
  944. end;
  945. end;
  946. NodePos := Node.DisplayRect(True);
  947. end;
  948. if NodePos.Left < 50 then
  949. Perform(WM_HSCROLL, SB_PAGELEFT, 0);
  950. end;
  951. end; {CenterNode}
  952. procedure TCustomDriveView.DoCompare(Sender: TObject; Node1, Node2: TTreeNode; Data: Integer; var Compare: Integer);
  953. begin
  954. Compare := CompareLogicalTextPas(Node1.Text, Node2.Text, NaturalOrderNumericalSorting);
  955. end;
  956. function TCustomDriveView.SortChildren(ParentNode: TTreeNode; Recurse: Boolean): Boolean;
  957. begin
  958. Result := Assigned(ParentNode) and ParentNode.AlphaSort(Recurse);
  959. end; {SortChildren}
  960. function TCustomDriveView.IterateSubTree(var StartNode : TTreeNode;
  961. CallBackFunc: TCallBackFunc; Recurse: TRecursiveScan;
  962. ScanStartNode: TScanStartNode; Data: Pointer): Boolean;
  963. function ScanSubTree(var StartNode: TTreeNode): Boolean;
  964. var
  965. Node: TTreeNode;
  966. NextNode: TTreeNode;
  967. NodeHasChilds: Boolean;
  968. begin
  969. Result := False;
  970. if not Assigned(StartNode) then Exit;
  971. Node := StartNode.GetFirstChild;
  972. while Assigned(Node) and FContinue do
  973. begin
  974. NextNode := StartNode.GetNextChild(Node);
  975. NodeHasChilds := Node.HasChildren;
  976. if (not FContinue) or (not CallBackFunc(Node, Data)) then Exit;
  977. if Assigned(Node) and
  978. (Recurse = rsRecursiveExisting) and NodeHasChilds then
  979. begin
  980. if (not ScanSubTree(Node)) or (not FContinue) then Exit;
  981. end;
  982. Node := NextNode;
  983. end;
  984. Result := True;
  985. end; {ScanSubTree}
  986. begin {IterateSubTree}
  987. Result := False;
  988. FContinue := True;
  989. if Assigned(CallBackFunc) then
  990. begin
  991. if ScanStartNode = coScanStartNode then
  992. begin
  993. CallBackFunc(StartNode, Data);
  994. end;
  995. if (not Assigned(StartNode)) or
  996. FContinue and ScanSubTree(StartNode) then
  997. begin
  998. Result := True;
  999. end;
  1000. end;
  1001. end; {IterateSubTree}
  1002. procedure TCustomDriveView.ClearDragFileList(FileList: TFileList);
  1003. begin
  1004. FileList.Clear;
  1005. end;
  1006. procedure TCustomDriveView.AddToDragFileList(FileList: TFileList; Node: TTreeNode);
  1007. begin
  1008. FileList.AddItem(nil, NodePathName(Node));
  1009. end;
  1010. function TCustomDriveView.NodeCanDrag(Node: TTreeNode): Boolean;
  1011. begin
  1012. Result := True;
  1013. end;
  1014. function TCustomDriveView.NodeOverlayIndexes(Node: TTreeNode): Word;
  1015. begin
  1016. Result := oiNoOverlay;
  1017. end;
  1018. function TCustomDriveView.NodeIsRecycleBin(Node: TTreeNode): Boolean;
  1019. begin
  1020. Result := False;
  1021. end;
  1022. function TCustomDriveView.NodePathExists(Node: TTreeNode): Boolean;
  1023. begin
  1024. Result := True;
  1025. end;
  1026. procedure TCustomDriveView.SetDimmHiddenDirs(Value: Boolean);
  1027. begin
  1028. if Value <> FDimmHiddenDirs then
  1029. begin
  1030. FDimmHiddenDirs := Value;
  1031. Self.Invalidate;
  1032. end;
  1033. end; {SetDimmHiddenDirs}
  1034. procedure TCustomDriveView.SetShowHiddenDirs(Value: Boolean);
  1035. begin
  1036. if Value <> FShowHiddenDirs then
  1037. begin
  1038. FShowHiddenDirs := Value;
  1039. RebuildTree;
  1040. end;
  1041. end; {SetDimmHiddenDirs}
  1042. procedure TCustomDriveView.SetNaturalOrderNumericalSorting(Value: Boolean);
  1043. begin
  1044. if NaturalOrderNumericalSorting <> Value then
  1045. begin
  1046. FNaturalOrderNumericalSorting := Value;
  1047. AlphaSort;
  1048. end;
  1049. end;
  1050. procedure TCustomDriveView.SetDarkMode(Value: Boolean);
  1051. begin
  1052. if DarkMode <> Value then
  1053. begin
  1054. FDarkMode := Value;
  1055. RecreateWnd;
  1056. end;
  1057. end;
  1058. function TCustomDriveView.GetTargetPopupMenu: Boolean;
  1059. begin
  1060. if Assigned(FDragDropFilesEx) then Result := FDragDropFilesEx.TargetPopupMenu
  1061. else Result := True;
  1062. end;
  1063. procedure TCustomDriveView.SetTargetPopUpMenu(Value: Boolean);
  1064. begin
  1065. if Assigned(FDragDropFilesEx) then
  1066. FDragDropFilesEx.TargetPopupMenu := Value;
  1067. end; {SetTargetPopUpMenu}
  1068. function TCustomDriveView.GetDirectory: string;
  1069. begin
  1070. if Assigned(Selected) then Result := NodePathName(Selected)
  1071. else Result := '';
  1072. end; {GetDirectory}
  1073. procedure TCustomDriveView.SetDirectory(Value: string);
  1074. var
  1075. NewSelected: TTreeNode;
  1076. Rect: TRect;
  1077. begin
  1078. NewSelected := FindPathNode(Value);
  1079. if Assigned(NewSelected) and (NewSelected <> Selected) then
  1080. begin
  1081. FCanChange := True;
  1082. NewSelected.MakeVisible;
  1083. Rect := NewSelected.DisplayRect(False);
  1084. Selected := NewSelected;
  1085. end
  1086. else
  1087. if csDesigning in ComponentState then
  1088. Selected := nil;
  1089. end; {SetDirectory}
  1090. function TCustomDriveView.DoBusy(Busy: Integer): Boolean;
  1091. begin
  1092. Result := True;
  1093. if Assigned(OnBusy) then
  1094. begin
  1095. OnBusy(Self, Busy, Result);
  1096. end;
  1097. end;
  1098. function TCustomDriveView.StartBusy: Boolean;
  1099. begin
  1100. Result := DoBusy(1);
  1101. end;
  1102. function TCustomDriveView.IsBusy: Boolean;
  1103. begin
  1104. Result := DoBusy(0);
  1105. end;
  1106. procedure TCustomDriveView.EndBusy;
  1107. begin
  1108. DoBusy(-1);
  1109. end;
  1110. end.