CustomDriveView.pas 39 KB

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