CustomDriveView.pas 39 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295
  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. // See TCustomDirView.SetDarkMode
  1061. if HandleAllocated then AllowDarkModeForWindow(Self, DarkMode);
  1062. end;
  1063. end;
  1064. function TCustomDriveView.GetTargetPopupMenu: Boolean;
  1065. begin
  1066. if Assigned(FDragDropFilesEx) then Result := FDragDropFilesEx.TargetPopupMenu
  1067. else Result := True;
  1068. end;
  1069. procedure TCustomDriveView.SetTargetPopUpMenu(Value: Boolean);
  1070. begin
  1071. if Assigned(FDragDropFilesEx) then
  1072. FDragDropFilesEx.TargetPopupMenu := Value;
  1073. end; {SetTargetPopUpMenu}
  1074. function TCustomDriveView.GetDirectory: string;
  1075. begin
  1076. if Assigned(Selected) then Result := NodePathName(Selected)
  1077. else Result := '';
  1078. end; {GetDirectory}
  1079. procedure TCustomDriveView.SetDirectory(Value: string);
  1080. var
  1081. NewSelected: TTreeNode;
  1082. Rect: TRect;
  1083. begin
  1084. NewSelected := FindPathNode(Value);
  1085. if Assigned(NewSelected) and (NewSelected <> Selected) then
  1086. begin
  1087. FCanChange := True;
  1088. NewSelected.MakeVisible;
  1089. Rect := NewSelected.DisplayRect(False);
  1090. Selected := NewSelected;
  1091. end
  1092. else
  1093. if csDesigning in ComponentState then
  1094. Selected := nil;
  1095. end; {SetDirectory}
  1096. function TCustomDriveView.DoBusy(Busy: Integer): Boolean;
  1097. begin
  1098. Result := True;
  1099. if Assigned(OnBusy) then
  1100. begin
  1101. OnBusy(Self, Busy, Result);
  1102. end;
  1103. end;
  1104. function TCustomDriveView.StartBusy: Boolean;
  1105. begin
  1106. Result := DoBusy(1);
  1107. end;
  1108. function TCustomDriveView.IsBusy: Boolean;
  1109. begin
  1110. Result := DoBusy(0);
  1111. end;
  1112. procedure TCustomDriveView.EndBusy;
  1113. begin
  1114. DoBusy(-1);
  1115. end;
  1116. end.