CustomDriveView.pas 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281
  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: TDrive;
  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 := #0;
  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 := Upcase(TFDDListItem(FDragDropFilesEx.FileList[0]^).Name[1]);
  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 := #0;
  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 := #0;
  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 := #0;
  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 not Assigned(CallBackFunc) then Exit;
  1005. if ScanStartNode = coScanStartNode then
  1006. CallBackFunc(StartNode, Data);
  1007. if Assigned(StartNode) then
  1008. if (not FContinue) or (not ScanSubTree(StartNode)) then Exit;
  1009. Result := True;
  1010. end; {IterateSubTree}
  1011. procedure TCustomDriveView.ClearDragFileList(FileList: TFileList);
  1012. begin
  1013. FileList.Clear;
  1014. end;
  1015. procedure TCustomDriveView.AddToDragFileList(FileList: TFileList; Node: TTreeNode);
  1016. begin
  1017. FileList.AddItem(nil, NodePathName(Node));
  1018. end;
  1019. function TCustomDriveView.NodeCanDrag(Node: TTreeNode): Boolean;
  1020. begin
  1021. Result := True;
  1022. end;
  1023. function TCustomDriveView.NodeOverlayIndexes(Node: TTreeNode): Word;
  1024. begin
  1025. Result := oiNoOverlay;
  1026. end;
  1027. function TCustomDriveView.NodeIsRecycleBin(Node: TTreeNode): Boolean;
  1028. begin
  1029. Result := False;
  1030. end;
  1031. function TCustomDriveView.NodePathExists(Node: TTreeNode): Boolean;
  1032. begin
  1033. Result := True;
  1034. end;
  1035. procedure TCustomDriveView.SetDimmHiddenDirs(Value: Boolean);
  1036. begin
  1037. if Value <> FDimmHiddenDirs then
  1038. begin
  1039. FDimmHiddenDirs := Value;
  1040. Self.Invalidate;
  1041. end;
  1042. end; {SetDimmHiddenDirs}
  1043. procedure TCustomDriveView.SetShowHiddenDirs(Value: Boolean);
  1044. begin
  1045. if Value <> FShowHiddenDirs then
  1046. begin
  1047. FShowHiddenDirs := Value;
  1048. RebuildTree;
  1049. end;
  1050. end; {SetDimmHiddenDirs}
  1051. function TCustomDriveView.GetTargetPopupMenu: Boolean;
  1052. begin
  1053. if Assigned(FDragDropFilesEx) then Result := FDragDropFilesEx.TargetPopupMenu
  1054. else Result := True;
  1055. end;
  1056. procedure TCustomDriveView.SetTargetPopUpMenu(Value: Boolean);
  1057. begin
  1058. if Assigned(FDragDropFilesEx) then
  1059. FDragDropFilesEx.TargetPopupMenu := Value;
  1060. end; {SetTargetPopUpMenu}
  1061. function TCustomDriveView.GetDirectory: string;
  1062. begin
  1063. if Assigned(Selected) then Result := NodePathName(Selected)
  1064. else Result := '';
  1065. end; {GetDirectory}
  1066. procedure TCustomDriveView.SetDirectory(Value: string);
  1067. var
  1068. NewSelected: TTreeNode;
  1069. Rect: TRect;
  1070. begin
  1071. NewSelected := FindPathNode(Value);
  1072. if Assigned(NewSelected) and (NewSelected <> Selected) then
  1073. begin
  1074. FCanChange := True;
  1075. NewSelected.MakeVisible;
  1076. Rect := NewSelected.DisplayRect(False);
  1077. Selected := NewSelected;
  1078. end
  1079. else
  1080. if csDesigning in ComponentState then
  1081. Selected := nil;
  1082. end; {SetDirectory}
  1083. function TCustomDriveView.DoBusy(Busy: Integer): Boolean;
  1084. begin
  1085. Result := True;
  1086. if Assigned(OnBusy) then
  1087. begin
  1088. OnBusy(Self, Busy, Result);
  1089. end;
  1090. end;
  1091. function TCustomDriveView.StartBusy: Boolean;
  1092. begin
  1093. Result := DoBusy(1);
  1094. end;
  1095. function TCustomDriveView.IsBusy: Boolean;
  1096. begin
  1097. Result := DoBusy(0);
  1098. end;
  1099. procedure TCustomDriveView.EndBusy;
  1100. begin
  1101. DoBusy(-1);
  1102. end;
  1103. end.