CustomDriveView.pas 39 KB

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