CustomDriveView.pas 38 KB

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