CustomDriveView.pas 39 KB

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