CustomDriveView.pas 38 KB

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