CustomDriveView.pas 37 KB

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