CustomDriveView.pas 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266
  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 WMContextMenu(var Msg: TWMContextMenu); message WM_CONTEXTMENU;
  79. procedure WMKeyDown(var Message: TWMKeyDown); message WM_KEYDOWN;
  80. procedure CMDPIChanged(var Message: TMessage); message CM_DPICHANGED;
  81. procedure Delete(Node: TTreeNode); override;
  82. procedure KeyDown(var Key: Word; Shift: TShiftState); override;
  83. procedure KeyPress(var Key: Char); override;
  84. procedure KeyUp(var Key: Word; Shift: TShiftState); override;
  85. procedure InternalOnDrawItem(Sender: TCustomTreeView; Node: TTreeNode;
  86. State: TCustomDrawState; var DefaultDraw: Boolean);
  87. procedure DDDragEnter(DataObj: IDataObject; KeyState: Longint;
  88. Point: TPoint; var Effect: Longint; var Accept: Boolean);
  89. procedure DDDragLeave;
  90. procedure DDDragOver(KeyState: Longint; Point: TPoint; var Effect: Longint);
  91. procedure DDDrop(DataObj: IDataObject; KeyState: Longint; Point: TPoint;
  92. var Effect: Longint);
  93. procedure DDQueryContinueDrag(EscapePressed: BOOL; KeyState: Longint;
  94. var Result: HResult);
  95. procedure DDDropHandlerSucceeded(Sender: TObject; KeyState: Longint;
  96. Point: TPoint; Effect: Longint);
  97. procedure DDGiveFeedback(Effect: Longint; var Result: HResult);
  98. procedure DDMenuPopup(Sender: TObject; AMenu: HMenu; DataObj: IDataObject;
  99. AMinCustCmd: Integer; grfKeyState: Longint; Point: TPoint);
  100. procedure DDMenuDone(Sender: TObject; AMenu: HMenu);
  101. procedure DDProcessDropped(Sender: TObject; KeyState: Longint;
  102. Point: TPoint; Effect: Longint);
  103. procedure DDError(Error: TDDError); virtual;
  104. procedure DDSpecifyDropTarget(Sender: TObject; DragDropHandler: Boolean;
  105. Point: TPoint; var PIDL: PItemIDList; var Filename: string);
  106. procedure DDDragDetect(KeyState: Longint; DetectStart, Point: TPoint;
  107. DragStatus: TDragDetectStatus); virtual;
  108. procedure PerformDragDropFileOperation(Node: TTreeNode; Effect: Integer); virtual; abstract;
  109. procedure DDChooseEffect(KeyState: Integer; var Effect: Integer); virtual;
  110. function DragCompleteFileList: Boolean; virtual; abstract;
  111. function DDExecute: TDragResult; virtual;
  112. function DDSourceEffects: TDropEffectSet; virtual; abstract;
  113. function NodePath(Node: TTreeNode): string; virtual; abstract;
  114. function NodeIsRecycleBin(Node: TTreeNode): Boolean; virtual;
  115. function NodePathExists(Node: TTreeNode): Boolean; virtual;
  116. function NodeColor(Node: TTreeNode): TColor; virtual; abstract;
  117. function NodeCanDrag(Node: TTreeNode): Boolean; virtual;
  118. function NodeOverlayIndexes(Node: TTreeNode): Word; virtual;
  119. function FindPathNode(Path: string): TTreeNode; virtual; abstract;
  120. procedure ClearDragFileList(FileList: TFileList); virtual;
  121. procedure AddToDragFileList(FileList: TFileList; Node: TTreeNode); virtual;
  122. procedure ValidateDirectoryEx(Node: TTreeNode; Recurse: TRecursiveScan;
  123. NewDirs: Boolean); virtual; abstract;
  124. procedure RebuildTree; virtual; abstract;
  125. procedure DisplayContextMenu(Node: TTreeNode; ScreenPos: TPoint); virtual; abstract;
  126. procedure DisplayPropertiesMenu(Node: TTreeNode); virtual; abstract;
  127. procedure ScrollOnDragOverBeforeUpdate(ObjectToValidate: TObject);
  128. procedure ScrollOnDragOverAfterUpdate;
  129. function DoBusy(Busy: Integer): Boolean;
  130. function StartBusy: Boolean;
  131. procedure EndBusy;
  132. function IsBusy: Boolean;
  133. property ImageList: TImageList read FImageList;
  134. public
  135. constructor Create(AOwner: TComponent); override;
  136. destructor Destroy; override;
  137. procedure ValidateDirectory(Node: TTreeNode);
  138. procedure CenterNode(Node: TTreeNode); virtual;
  139. function SortChildren(ParentNode: TTreeNode; Recurse: Boolean): Boolean;
  140. function IterateSubTree(var StartNode : TTreeNode;
  141. CallBackFunc: TCallBackFunc; Recurse: TRecursiveScan;
  142. ScanStartNode: TScanStartNode; Data: Pointer): Boolean;
  143. function NodePathName(Node: TTreeNode): string; virtual; abstract;
  144. property DragDropFilesEx: TCustomizableDragDropFilesEx read FDragDropFilesEx;
  145. property UseSystemContextMenu: Boolean read FUseSystemContextMenu
  146. write FUseSystemContextMenu default True;
  147. property DimmHiddenDirs: Boolean read FDimmHiddenDirs
  148. write SetDimmHiddenDirs default False;
  149. property ShowHiddenDirs: Boolean read FShowHiddenDirs
  150. write SetShowHiddenDirs default False;
  151. property DDLinkOnExeDrag: Boolean read FDDLinkOnExeDrag write FDDLinkOnExeDrag default True;
  152. {The mouse has entered the component window as a target of a drag&drop operation:}
  153. property OnDDDragEnter: TDDOnDragEnter read FOnDDDragEnter write FOnDDDragEnter;
  154. {The mouse has leaved the component window as a target of a drag&drop operation:}
  155. property OnDDDragLeave: TDDOnDragLeave read FOnDDDragLeave write FOnDDDragLeave;
  156. {The mouse is dragging in the component window as a target of a drag&drop operation:}
  157. property OnDDDragOver: TDDOnDragOver read FOnDDDragOver write FOnDDDragOver;
  158. {The Drag&drop operation is about to be executed:}
  159. property OnDDDrop: TDDOnDrop read FOnDDDrop write FOnDDDrop;
  160. property OnDDQueryContinueDrag: TDDOnQueryContinueDrag read FOnDDQueryContinueDrag write FOnDDQueryContinueDrag;
  161. property OnDDChooseEffect: TDDOnChooseEffect read FOnDDChooseEffect write FOnDDChooseEffect;
  162. property OnDDGiveFeedback: TDDOnGiveFeedback read FOnDDGiveFeedback write FOnDDGiveFeedback;
  163. {A drag&drop operation is about to be initiated whith the components window as the source:}
  164. property OnDDDragDetect: TDDOnDragDetect read FOnDDDragDetect write FOnDDDragDetect;
  165. {The component window is the target of a drag&drop operation:}
  166. property OnDDProcessDropped: TOnProcessDropped read FOnDDProcessDropped write FOnDDProcessDropped;
  167. {An error has occurred during a drag&drop operation:}
  168. property OnDDError: TDDErrorEvent read FOnDDError write FOnDDError;
  169. {The drag&drop operation has been executed:}
  170. property OnDDExecuted: TDDExecutedEvent read FOnDDExecuted write FOnDDExecuted;
  171. {Event is fired just before executing the fileoperation. This event is also fired when
  172. files are pasted from the clipboard:}
  173. property OnDDFileOperation: TDDFileOperationEvent read FOnDDFileOperation write FOnDDFileOperation;
  174. {Event is fired after executing the fileoperation. This event is also fired when
  175. files are pasted from the clipboard:}
  176. property OnDDFileOperationExecuted: TDDFileOperationExecutedEvent read FOnDDFileOperationExecuted write FOnDDFileOperationExecuted;
  177. property OnDDCreateDragFileList: TDDOnCreateDragFileList
  178. read FOnDDCreateDragFileList write FOnDDCreateDragFileList;
  179. property OnDDEnd: TNotifyEvent
  180. read FOnDDEnd write FOnDDEnd;
  181. property OnDDCreateDataObject: TDDOnCreateDataObject
  182. read FOnDDCreateDataObject write FOnDDCreateDataObject;
  183. property OnDDMenuPopup: TOnMenuPopup read FOnDDMenuPopup write FOnDDMenuPopup;
  184. property OnBusy: TDirViewBusy read FOnBusy write FOnBusy;
  185. { Show popupmenu when dropping a file with the right mouse button }
  186. property TargetPopUpMenu: Boolean read GetTargetPopUpMenu write SetTargetPopUpMenu default True;
  187. {Current selected directory:}
  188. property Directory: string read GetDirectory write SetDirectory;
  189. property DragNode: TTreeNode read FDragNode;
  190. property Continue: Boolean read FContinue write FContinue;
  191. property LastDDResult: TDragResult read FLastDDResult;
  192. end;
  193. resourcestring
  194. SDragDropError = 'Drag&drop error: %d';
  195. implementation
  196. uses
  197. SysUtils, ShellApi, ImgList,
  198. IEListView, BaseUtils;
  199. constructor TCustomDriveView.Create(AOwner: TComponent);
  200. begin
  201. inherited;
  202. DragMode := dmAutomatic;
  203. FDragFileList := TStringList.Create;
  204. FDragDrive := #0;
  205. FExeDrag := False;
  206. FDDLinkOnExeDrag := True;
  207. FContextMenu := False;
  208. FCanChange := True;
  209. FUseSystemContextMenu := True;
  210. FContinue := True;
  211. FDragDropFilesEx := TCustomizableDragDropFilesEx.Create(Self);
  212. with FDragDropFilesEx do
  213. begin
  214. AcceptOwnDnd := True;
  215. {MP}
  216. AutoDetectDnD := False;
  217. {/MP}
  218. BringToFront := True;
  219. CompleteFileList := True;
  220. NeedValid := [nvFileName];
  221. RenderDataOn := rdoEnterAndDropSync;
  222. TargetPopUpMenu := True;
  223. OnDragEnter := DDDragEnter;
  224. OnDragLeave := DDDragLeave;
  225. OnDragOver := DDDragOver;
  226. OnDrop := DDDrop;
  227. OnQueryContinueDrag := DDQueryContinueDrag;
  228. OnSpecifyDropTarget := DDSpecifyDropTarget;
  229. OnMenuPopup := DDMenuPopup;
  230. OnMenuDestroy := DDMenuDone;
  231. OnDropHandlerSucceeded := DDDropHandlerSucceeded;
  232. OnGiveFeedback := DDGiveFeedback;
  233. OnProcessDropped := DDProcessDropped;
  234. OnDragDetect := DDDragDetect;
  235. end;
  236. OnCustomDrawItem := InternalOnDrawItem;
  237. FScrollOnDragOver := TTreeViewScrollOnDragOver.Create(Self, False);
  238. FScrollOnDragOver.OnBeforeUpdate := ScrollOnDragOverBeforeUpdate;
  239. FScrollOnDragOver.OnAfterUpdate := ScrollOnDragOverAfterUpdate;
  240. end;
  241. destructor TCustomDriveView.Destroy;
  242. begin
  243. FreeAndNil(FScrollOnDragOver);
  244. FreeAndNil(FImageList);
  245. if Assigned(Images) then
  246. Images.Free;
  247. if Assigned(FDragImageList) then
  248. begin
  249. if GlobalDragImageList = FDragImageList then
  250. GlobalDragImageList := nil;
  251. FDragImageList.Free;
  252. end;
  253. FDragFileList.Destroy;
  254. if Assigned(FDragDropFilesEx) then
  255. FDragDropFilesEx.Free;
  256. inherited Destroy;
  257. end;
  258. procedure TCustomDriveView.NeedImageLists(Recreate: Boolean);
  259. var
  260. MinHeight: Integer;
  261. AImages: TImageList;
  262. begin
  263. if not Assigned(Images) then
  264. begin
  265. Images := TImageList.Create(Self);
  266. Images.BkColor := Color;
  267. end;
  268. AImages := ShellImageListForControl(Self, ilsSmall);
  269. if Images.Handle <> AImages.Handle then
  270. begin
  271. Images.Handle := AImages.Handle;
  272. end;
  273. if (not Assigned(FImageList)) or Recreate then
  274. begin
  275. if Assigned(FImageList) then
  276. FImageList.Free;
  277. FImageList := OverlayImageList(Images.Width);
  278. end;
  279. MinHeight := ScaleByTextHeight(Self, 18);
  280. if TreeView_GetItemHeight(Handle) < MinHeight then
  281. TreeView_SetItemHeight(Handle, MinHeight);
  282. end;
  283. procedure TCustomDriveView.CMDPIChanged(var Message: TMessage);
  284. begin
  285. inherited;
  286. NeedImageLists(True);
  287. end;
  288. procedure TCustomDriveView.CreateWnd;
  289. begin
  290. inherited;
  291. NeedImageLists(False);
  292. if not (csDesigning in ComponentState) then
  293. FDragImageList := TDragImageList.Create(Self);
  294. if not Assigned(GlobalDragImageList) then
  295. GlobalDragImageList := FDragImageList;
  296. FDragDropFilesEx.DragDropControl := Self;
  297. FParentForm := GetParentForm(Self);
  298. end;
  299. procedure TCustomDriveView.Notification(AComponent: TComponent; Operation: TOperation);
  300. begin
  301. inherited;
  302. if Operation = opRemove then
  303. begin
  304. if AComponent = GetCustomDirView then SetCustomDirView(nil);
  305. end;
  306. end;
  307. procedure TCustomDriveView.InternalOnDrawItem(Sender: TCustomTreeView; Node: TTreeNode;
  308. State: TCustomDrawState; var DefaultDraw: Boolean);
  309. var
  310. FItemColor: TColor;
  311. begin
  312. if Assigned(Node) and Assigned(Node.Data) and (Node <> DropTarget) then
  313. begin
  314. if not Node.Selected then
  315. begin
  316. FItemColor := NodeColor(Node);
  317. if (FItemColor <> clDefaultItemColor) and
  318. (Canvas.Font.Color <> FItemColor) then
  319. Canvas.Font.Color := FItemColor;
  320. end
  321. else
  322. if (not Self.Focused) and HideSelection then
  323. begin
  324. Canvas.Brush.Color := clBtnFace;
  325. Canvas.Font.Color := clBtnText;
  326. end;
  327. end;
  328. end; {InternalOnDrawItem}
  329. procedure TCustomDriveView.ScrollOnDragOverBeforeUpdate(ObjectToValidate: TObject);
  330. var
  331. NodeToValidate: TTreeNode;
  332. begin
  333. GlobalDragImageList.HideDragImage;
  334. if Assigned(ObjectToValidate) then
  335. begin
  336. NodeToValidate := (ObjectToValidate as TTreeNode);
  337. if not NodeToValidate.HasChildren then
  338. ValidateDirectory(NodeToValidate);
  339. end;
  340. end;
  341. procedure TCustomDriveView.ScrollOnDragOverAfterUpdate;
  342. begin
  343. GlobalDragImageList.ShowDragImage;
  344. end;
  345. procedure TCustomDriveView.DDDragEnter(DataObj: IDataObject; KeyState: Longint;
  346. Point: TPoint; var Effect: Longint; var Accept: Boolean);
  347. var
  348. Index: Integer;
  349. begin
  350. if (FDragDropFilesEx.FileList.Count > 0) and
  351. (Length(TFDDListItem(FDragDropFilesEx.FileList[0]^).Name) > 0) Then
  352. begin
  353. FDragDrive := Upcase(TFDDListItem(FDragDropFilesEx.FileList[0]^).Name[1]);
  354. FExeDrag := FDDLinkOnExeDrag and
  355. (deLink in DragDropFilesEx.TargetEffects) and
  356. ((DragDropFilesEx.AvailableDropEffects and DropEffect_Link) <> 0);
  357. if FExeDrag then
  358. begin
  359. for Index := 0 to FDragDropFilesEx.FileList.Count - 1 do
  360. if not IsExecutable(TFDDListItem(FDragDropFilesEx.FileList[Index]^).Name) then
  361. begin
  362. FExeDrag := False;
  363. Break;
  364. end;
  365. end;
  366. end
  367. else
  368. begin
  369. FDragDrive := #0;
  370. end;
  371. FScrollOnDragOver.StartDrag;
  372. if Assigned(FOnDDDragEnter) then
  373. FOnDDDragEnter(Self, DataObj, KeyState, Point, Effect, Accept);
  374. end; {DDDragEnter}
  375. procedure TCustomDriveView.DDDragLeave;
  376. begin
  377. if Assigned(DropTarget) then
  378. begin
  379. if GlobalDragImageList.Dragging then
  380. GlobalDragImageList.HideDragImage;
  381. DropTarget := nil;
  382. Update;
  383. end;
  384. if Assigned(FOnDDDragLeave) then
  385. FOnDDDragLeave(Self);
  386. end; {DragLeave}
  387. procedure TCustomDriveView.DDDragOver(KeyState: Longint; Point: TPoint; var Effect: Longint);
  388. var
  389. Node: TTreeNode;
  390. Rect1: TRect;
  391. UpdateImage: Boolean;
  392. LastDragNode: TTreeNode;
  393. begin
  394. if Effect <> DropEffect_None then
  395. begin
  396. Node := GetNodeAt(Point.X, Point.Y);
  397. if Assigned(Node) then
  398. begin
  399. LastDragNode := DropTarget;
  400. UpdateImage := False;
  401. if GlobalDragImageList.Dragging and (LastDragNode <> Node) then
  402. begin
  403. if Assigned(LastDragNode) then
  404. begin
  405. Rect1 := LastDragNode.DisplayRect(True);
  406. if Rect1.Right >= Point.x - GlobalDragImageList.GetHotSpot.X then
  407. begin
  408. GlobalDragImageList.HideDragImage;
  409. UpdateImage := True;
  410. end
  411. else
  412. begin
  413. Rect1 := Node.DisplayRect(True);
  414. if Rect1.Right >= Point.x - GlobalDragImageList.GetHotSpot.X then
  415. begin
  416. GlobalDragImageList.HideDragImage;
  417. UpdateImage := True;
  418. end
  419. end;
  420. end
  421. else
  422. begin
  423. {LastDragNode not assigned:}
  424. GlobalDragImageList.HideDragImage;
  425. UpdateImage := True;
  426. end;
  427. end;
  428. DropTarget := Node;
  429. if UpdateImage then
  430. GlobalDragImageList.ShowDragImage;
  431. {Drop-operation allowed at this location?}
  432. if Assigned(FDragNode) and
  433. (Effect <> DropEffect_Link) and
  434. ((Node = FDragNode) or Node.HasAsParent(FDragNode) or (FDragNode.Parent = Node)) then
  435. Effect := DropEffect_None;
  436. FScrollOnDragOver.DragOver(Point);
  437. end {Assigned(Node)}
  438. else
  439. begin
  440. DropTarget := nil;
  441. end;
  442. end;
  443. DDChooseEffect(KeyState, Effect);
  444. if Assigned(FOnDDDragOver) then
  445. FOnDDDragOver(Self, KeyState, Point, Effect);
  446. if not Assigned(DropTarget) then Effect := DropEffect_None
  447. else
  448. if NodeIsRecycleBin(DropTarget) then
  449. begin
  450. if FDragDropFilesEx.FileNamesAreMapped then Effect := DropEffect_None
  451. else Effect := DropEffect_Move;
  452. end;
  453. end; {DDDragOver}
  454. procedure TCustomDriveView.DDDrop(DataObj: IDataObject; KeyState: Longint;
  455. Point: TPoint; var Effect: Longint);
  456. begin
  457. if GlobalDragImageList.Dragging then
  458. GlobalDragImageList.HideDragImage;
  459. if Effect = DropEffect_None then
  460. DropTarget := nil;
  461. if Assigned(FOnDDDrop) then
  462. FOnDDDrop(Self, DataObj, KeyState, Point, Effect);
  463. end; {DDDrop}
  464. procedure TCustomDriveView.DDQueryContinueDrag(EscapePressed: BOOL; KeyState: Longint;
  465. var Result: HResult);
  466. var
  467. Point: TPoint;
  468. ClientPoint: TPoint;
  469. KnowTime: FILETIME;
  470. begin
  471. if Result = DRAGDROP_S_DROP then
  472. begin
  473. GetSystemTimeAsFileTime(KnowTime);
  474. if ((Int64(KnowTime) - Int64(FDragStartTime)) <= DDDragStartDelay) then
  475. Result := DRAGDROP_S_CANCEL;
  476. end;
  477. if Assigned(FOnDDQueryContinueDrag) then
  478. FOnDDQueryContinueDrag(Self, EscapePressed, KeyState, Result);
  479. if EscapePressed then
  480. begin
  481. if GlobalDragImageList.Dragging then
  482. GlobalDragImageList.HideDragImage;
  483. DropTarget := nil;
  484. end
  485. else
  486. begin
  487. if GlobalDragImageList.Dragging then
  488. begin
  489. GetCursorPos(Point);
  490. {Convert screen coordinates to the parentforms coordinates:}
  491. ClientPoint := FParentForm.ScreenToClient(Point);
  492. {Move the drag image to the new position and show it:}
  493. if not CompareMem(@ClientPoint, @FDragPos, SizeOf(TPoint)) then
  494. begin
  495. FDragPos := ClientPoint;
  496. if PtInRect(FParentForm.BoundsRect, Point) then
  497. begin
  498. GlobalDragImageList.DragMove(ClientPoint.X, ClientPoint.Y);
  499. GlobalDragImageList.ShowDragImage;
  500. end
  501. else GlobalDragImageList.HideDragImage;
  502. end;
  503. end;
  504. end;
  505. end; {DDQueryContinueDrag}
  506. procedure TCustomDriveView.DDMenuPopup(Sender: TObject; AMenu: HMenu;
  507. DataObj: IDataObject; AMinCustCmd: Integer; grfKeyState: Longint; Point: TPoint);
  508. begin
  509. if Assigned(OnDDMenuPopup) then
  510. begin
  511. OnDDMenuPopup(Self, AMenu, DataObj, AMinCustCmd, grfKeyState, Point);
  512. end;
  513. end;
  514. procedure TCustomDriveView.DDMenuDone(Sender: TObject; AMenu: HMenu);
  515. begin
  516. end;
  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 := #0;
  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 := #0;
  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. FCanChange := False;
  744. GetCursorPos(FStartPos);
  745. inherited;
  746. end; {WMLButtonDown}
  747. procedure TCustomDriveView.WMLButtonUp(var Msg: TWMLButtonDown);
  748. begin
  749. FCanChange := True;
  750. if Assigned(DropTarget) and Assigned(DropTarget.Data) then
  751. Selected := DropTarget;
  752. DropTarget := nil;
  753. inherited;
  754. end; {WMLButtonUp}
  755. procedure TCustomDriveView.WMRButtonDown(var Msg: TWMRButtonDown);
  756. begin
  757. GetCursorPos(FStartPos);
  758. if FDragDropFilesEx.DragDetectStatus <> ddsDrag then
  759. FContextMenu := True;
  760. inherited;
  761. end; {WMRButtonDown}
  762. procedure TCustomDriveView.WMContextMenu(var Msg: TWMContextMenu);
  763. var
  764. Node: TTreeNode;
  765. Point: TPoint;
  766. PrevAutoPopup: Boolean;
  767. begin
  768. PrevAutoPopup := False;
  769. try
  770. if Assigned(PopupMenu) then
  771. begin
  772. PrevAutoPopup := PopupMenu.AutoPopup;
  773. PopupMenu.AutoPopup := False;
  774. end;
  775. inherited;
  776. finally
  777. if Assigned(PopupMenu) then
  778. PopupMenu.AutoPopup := PrevAutoPopup;
  779. end;
  780. FStartPos.X := -1;
  781. FStartPos.Y := -1;
  782. try
  783. if FContextMenu then
  784. begin
  785. Point.X := Msg.XPos;
  786. Point.Y := Msg.YPos;
  787. Point := ScreenToClient(Point);
  788. Node := GetNodeAt(Point.X, Point.Y);
  789. if FUseSystemContextMenu and Assigned(Node) then
  790. begin
  791. if Assigned(OnMouseDown) then
  792. OnMouseDown(Self, mbRight, [], Msg.XPos, Msg.YPos);
  793. DisplayContextMenu(Node, Mouse.CursorPos);
  794. end
  795. else
  796. begin
  797. if Assigned(PopupMenu) then
  798. PopupMenu.Popup(Msg.XPos, Msg.YPos);
  799. end;
  800. end;
  801. FContextMenu := False;
  802. finally
  803. DropTarget := nil;
  804. end;
  805. end; {WMContextMenu}
  806. procedure TCustomDriveView.CMRecreateWnd(var Msg: TMessage);
  807. var
  808. HadHandle: Boolean;
  809. begin
  810. HadHandle := HandleAllocated;
  811. inherited;
  812. // If the control is not showing (e.g. because the machine is locked), the handle is not recreated.
  813. // If contents is reloaded (LoadPath) without handle allocated, it crashes
  814. // (as the handle is implicitly created somewhere in the middle of the reload and chaos ensures).
  815. if HadHandle then
  816. begin
  817. HandleNeeded;
  818. end;
  819. end;
  820. procedure TCustomDriveView.Delete(Node: TTreeNode);
  821. begin
  822. if Node = FDragNode then
  823. FDragNode := nil;
  824. if Node = DropTarget then
  825. begin
  826. DropTarget := nil;
  827. Update;
  828. end;
  829. inherited;
  830. end; {OnDelete}
  831. procedure TCustomDriveView.WMKeyDown(var Message: TWMKeyDown);
  832. begin
  833. if not IsBusy then
  834. begin
  835. inherited;
  836. end;
  837. end;
  838. procedure TCustomDriveView.KeyDown(var Key: Word; Shift: TShiftState);
  839. begin
  840. if (Key = VK_RETURN) and (ssAlt in Shift) and (not IsEditing) and
  841. Assigned(Selected) then
  842. begin
  843. DisplayPropertiesMenu(Selected);
  844. Key := 0;
  845. end;
  846. inherited;
  847. end; {KeyDown}
  848. procedure TCustomDriveView.KeyPress(var Key : Char);
  849. begin
  850. if Assigned(Selected) then
  851. begin
  852. if not IsEditing then
  853. begin
  854. case Key of
  855. #13, ' ':
  856. begin
  857. Selected.Expanded := not Selected.Expanded;
  858. Key := #0;
  859. end;
  860. '/':
  861. begin
  862. Selected.Collapse(True);
  863. Selected.MakeVisible;
  864. Key := #0;
  865. end;
  866. '*':
  867. Selected.MakeVisible;
  868. end {Case}
  869. end
  870. end;
  871. inherited;
  872. end; {KeyPress}
  873. procedure TCustomDriveView.KeyUp(var Key: Word; Shift: TShiftState);
  874. var
  875. Point: TPoint;
  876. begin
  877. inherited;
  878. if (Key = VK_APPS) and Assigned(Selected) then
  879. begin
  880. Point := ClientToScreen(Selected.DisplayRect(True).TopLeft);
  881. Inc(Point.Y, 20);
  882. DisplayContextMenu(Selected, Point);
  883. end;
  884. end; {KeyUp}
  885. procedure TCustomDriveView.ValidateDirectory(Node: TTreeNode);
  886. begin
  887. ValidateDirectoryEx(Node, rsRecursiveExisting, False);
  888. end; {ValidateDirectory}
  889. procedure TCustomDriveView.CenterNode(Node: TTreeNode);
  890. var
  891. NodePos: TRect;
  892. ScrollInfo: TScrollInfo;
  893. begin
  894. if Assigned(Node) and (Items.Count > 0) then
  895. begin
  896. Node.MakeVisible;
  897. NodePos := Node.DisplayRect(False);
  898. with ScrollInfo do
  899. begin
  900. cbSize := SizeOf(ScrollInfo);
  901. fMask := SIF_ALL;
  902. nMin := 0;
  903. nMax := 0;
  904. nPage := 0;
  905. end;
  906. GetScrollInfo(Handle, SB_VERT, ScrollInfo);
  907. if ScrollInfo.nMin <> ScrollInfo.nMax then
  908. begin
  909. {Scroll tree up:}
  910. if (NodePos.Top < Height div 4) and (ScrollInfo.nPos > 0) then
  911. begin
  912. ScrollInfo.fMask := SIF_POS;
  913. while (ScrollInfo.nPos > 0) and (NodePos.Top < (Height div 4)) do
  914. begin
  915. Perform(WM_VSCROLL, SB_LINEUP, 0);
  916. GetScrollInfo(Handle, SB_VERT, ScrollInfo);
  917. NodePos := Node.DisplayRect(False);
  918. end;
  919. end
  920. else
  921. if (NodePos.Top > ((Height * 3) div 4)) then
  922. begin
  923. {Scroll tree down:}
  924. ScrollInfo.fMask := SIF_POS;
  925. while (ScrollInfo.nPos + ABS(ScrollInfo.nPage) < ScrollInfo.nMax) and
  926. (NodePos.Top > ((Height * 3) div 4)) and
  927. (ScrollInfo.nPage > 0) do
  928. begin
  929. Perform(WM_VSCROLL, SB_LINEDOWN, 0);
  930. GetScrollInfo(Handle, SB_VERT, ScrollInfo);
  931. NodePos := Node.DisplayRect(False);
  932. end;
  933. end;
  934. NodePos := Node.DisplayRect(True);
  935. end;
  936. if NodePos.Left < 50 then
  937. Perform(WM_HSCROLL, SB_PAGELEFT, 0);
  938. end;
  939. end; {CenterNode}
  940. function TCustomDriveView.SortChildren(ParentNode: TTreeNode; Recurse: Boolean): Boolean;
  941. var
  942. Node: TTreeNode;
  943. begin
  944. Result := False;
  945. if Assigned(ParentNode) and
  946. TreeView_SortChildren(Self.Handle, ParentNode.ItemID, LongBool(0)) then
  947. begin
  948. Result := True;
  949. if Recurse then
  950. begin
  951. Node := ParentNode.GetFirstChild;
  952. while Assigned(Node) do
  953. begin
  954. if Node.HasChildren then
  955. SortChildren(Node, Recurse);
  956. Node := ParentNode.GetNextChild(Node);
  957. end;
  958. end;
  959. end;
  960. end; {SortChildren}
  961. function TCustomDriveView.IterateSubTree(var StartNode : TTreeNode;
  962. CallBackFunc: TCallBackFunc; Recurse: TRecursiveScan;
  963. ScanStartNode: TScanStartNode; Data: Pointer): Boolean;
  964. function ScanSubTree(var StartNode: TTreeNode): Boolean;
  965. var
  966. Node: TTreeNode;
  967. NextNode: TTreeNode;
  968. NodeHasChilds: Boolean;
  969. begin
  970. Result := False;
  971. if not Assigned(StartNode) then Exit;
  972. Node := StartNode.GetFirstChild;
  973. while Assigned(Node) and FContinue do
  974. begin
  975. NextNode := StartNode.GetNextChild(Node);
  976. NodeHasChilds := Node.HasChildren;
  977. if (not FContinue) or (not CallBackFunc(Node, Data)) then Exit;
  978. if Assigned(Node) and
  979. (Recurse = rsRecursiveExisting) and NodeHasChilds then
  980. begin
  981. if (not ScanSubTree(Node)) or (not FContinue) then Exit;
  982. end;
  983. Node := NextNode;
  984. end;
  985. Result := True;
  986. end; {ScanSubTree}
  987. begin {IterateSubTree}
  988. Result := False;
  989. FContinue := True;
  990. if not Assigned(CallBackFunc) then Exit;
  991. if ScanStartNode = coScanStartNode then
  992. CallBackFunc(StartNode, Data);
  993. if Assigned(StartNode) then
  994. if (not FContinue) or (not ScanSubTree(StartNode)) then Exit;
  995. Result := True;
  996. end; {IterateSubTree}
  997. procedure TCustomDriveView.ClearDragFileList(FileList: TFileList);
  998. begin
  999. FileList.Clear;
  1000. end;
  1001. procedure TCustomDriveView.AddToDragFileList(FileList: TFileList; Node: TTreeNode);
  1002. begin
  1003. FileList.AddItem(nil, NodePathName(Node));
  1004. end;
  1005. function TCustomDriveView.NodeCanDrag(Node: TTreeNode): Boolean;
  1006. begin
  1007. Result := True;
  1008. end;
  1009. function TCustomDriveView.NodeOverlayIndexes(Node: TTreeNode): Word;
  1010. begin
  1011. Result := oiNoOverlay;
  1012. end;
  1013. function TCustomDriveView.NodeIsRecycleBin(Node: TTreeNode): Boolean;
  1014. begin
  1015. Result := False;
  1016. end;
  1017. function TCustomDriveView.NodePathExists(Node: TTreeNode): Boolean;
  1018. begin
  1019. Result := True;
  1020. end;
  1021. procedure TCustomDriveView.SetDimmHiddenDirs(Value: Boolean);
  1022. begin
  1023. if Value <> FDimmHiddenDirs then
  1024. begin
  1025. FDimmHiddenDirs := Value;
  1026. Self.Invalidate;
  1027. end;
  1028. end; {SetDimmHiddenDirs}
  1029. procedure TCustomDriveView.SetShowHiddenDirs(Value: Boolean);
  1030. begin
  1031. if Value <> FShowHiddenDirs then
  1032. begin
  1033. FShowHiddenDirs := Value;
  1034. RebuildTree;
  1035. end;
  1036. end; {SetDimmHiddenDirs}
  1037. function TCustomDriveView.GetTargetPopupMenu: Boolean;
  1038. begin
  1039. if Assigned(FDragDropFilesEx) then Result := FDragDropFilesEx.TargetPopupMenu
  1040. else Result := True;
  1041. end;
  1042. procedure TCustomDriveView.SetTargetPopUpMenu(Value: Boolean);
  1043. begin
  1044. if Assigned(FDragDropFilesEx) then
  1045. FDragDropFilesEx.TargetPopupMenu := Value;
  1046. end; {SetTargetPopUpMenu}
  1047. function TCustomDriveView.GetDirectory: string;
  1048. begin
  1049. if Assigned(Selected) then Result := NodePathName(Selected)
  1050. else Result := '';
  1051. end; {GetDirectory}
  1052. procedure TCustomDriveView.SetDirectory(Value: string);
  1053. var
  1054. NewSelected: TTreeNode;
  1055. Rect: TRect;
  1056. begin
  1057. NewSelected := FindPathNode(Value);
  1058. if Assigned(NewSelected) and (NewSelected <> Selected) then
  1059. begin
  1060. FCanChange := True;
  1061. NewSelected.MakeVisible;
  1062. Rect := NewSelected.DisplayRect(False);
  1063. Selected := NewSelected;
  1064. end
  1065. else
  1066. if csDesigning in ComponentState then
  1067. Selected := nil;
  1068. end; {SetDirectory}
  1069. function TCustomDriveView.DoBusy(Busy: Integer): Boolean;
  1070. begin
  1071. Result := True;
  1072. if Assigned(OnBusy) then
  1073. begin
  1074. OnBusy(Self, Busy, Result);
  1075. end;
  1076. end;
  1077. function TCustomDriveView.StartBusy: Boolean;
  1078. begin
  1079. Result := DoBusy(1);
  1080. end;
  1081. function TCustomDriveView.IsBusy: Boolean;
  1082. begin
  1083. Result := DoBusy(0);
  1084. end;
  1085. procedure TCustomDriveView.EndBusy;
  1086. begin
  1087. DoBusy(-1);
  1088. end;
  1089. end.