CustomDriveView.pas 37 KB

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