CustomDriveView.pas 39 KB

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