PasTools.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698
  1. unit PasTools;
  2. interface
  3. uses
  4. Windows, Types, Classes, ComCtrls, ExtCtrls, Controls, Dialogs, Forms;
  5. function Construct(ComponentClass: TComponentClass; Owner: TComponent): TComponent;
  6. function IsVistaHard: Boolean;
  7. function IsVista: Boolean;
  8. // Prevent name conflict with C++ IsWin8.
  9. {$HPPEMIT '#define IsWin7 IsWin7Pas'}
  10. {$HPPEMIT END '#undef IsWin7'}
  11. function IsWin7: Boolean;
  12. // Prevent name conflict with C++ IsWin8.
  13. {$HPPEMIT '#define IsWin8 IsWin8Pas'}
  14. {$HPPEMIT END '#undef IsWin8'}
  15. function IsWin8: Boolean;
  16. // Prevent name conflict with C++ CutToChar.
  17. {$HPPEMIT '#define CutToChar CutToCharPas'}
  18. {$HPPEMIT END '#undef CutToChar'}
  19. function CutToChar(var Str: string; Ch: Char; Trim: Boolean): string;
  20. procedure FilterToFileTypes(Filter: string; FileTypes: TFileTypeItems);
  21. // Note that while we based our scaling on pixels-per-inch,
  22. // VCL actually scales based on font size
  23. function LoadDimension(Dimension: Integer; PixelsPerInch: Integer): Integer;
  24. function StrToDimensionDef(Str: string; PixelsPerInch: Integer; Default: Integer): Integer;
  25. function SaveDimension(Dimension: Integer): Integer;
  26. function DimensionToDefaultPixelsPerInch(Dimension: Integer): Integer;
  27. function ScaleByPixelsPerInch(Dimension: Integer): Integer;
  28. function LoadPixelsPerInch(S: string): Integer;
  29. function SavePixelsPerInch: string;
  30. function SaveDefaultPixelsPerInch: string;
  31. function ScaleByTextHeight(Control: TControl; Dimension: Integer): Integer;
  32. function ScaleByTextHeightRunTime(Control: TControl; Dimension: Integer): Integer;
  33. function ControlHasRecreationPersistenceData(Control: TControl): Boolean;
  34. function IsAppIconic: Boolean;
  35. procedure SetAppIconic(Value: Boolean);
  36. procedure SetAppMainForm(Value: TForm);
  37. procedure ForceColorChange(Control: TWinControl);
  38. type
  39. TApiPathEvent = function(Path: string): string;
  40. var
  41. OnApiPath: TApiPathEvent = nil;
  42. // Prevent name conflict with C++ ApiPath.
  43. // We would not want to call this implementation in any case anyway.
  44. {$HPPEMIT '#define ApiPath ApiPathPas'}
  45. {$HPPEMIT END '#undef ApiPath'}
  46. function ApiPath(Path: string): string;
  47. type
  48. TControlScrollBeforeUpdate = procedure(ObjectToValidate: TObject) of object;
  49. TControlScrollAfterUpdate = procedure of object;
  50. TCustomControlScrollOnDragOver = class
  51. private
  52. FOnBeforeUpdate: TControlScrollBeforeUpdate;
  53. FOnAfterUpdate: TControlScrollAfterUpdate;
  54. FDragOverTimer: TTimer;
  55. FControl: TControl;
  56. FDragOverTime: FILETIME;
  57. FLastVScrollTime: FILETIME;
  58. FVScrollCount: Integer;
  59. procedure DragOverTimer(Sender: TObject);
  60. procedure BeforeUpdate(ObjectToValidate: TObject);
  61. procedure AfterUpdate;
  62. public
  63. constructor Create(Control: TControl; ScheduleDragOver: Boolean);
  64. destructor Destroy; override;
  65. procedure StartDrag; virtual;
  66. procedure EndDrag; virtual;
  67. procedure DragOver(Point: TPoint); virtual; abstract;
  68. property OnBeforeUpdate: TControlScrollBeforeUpdate read FOnBeforeUpdate write FOnBeforeUpdate;
  69. property OnAfterUpdate: TControlScrollAfterUpdate read FOnAfterUpdate write FOnAfterUpdate;
  70. end;
  71. TTreeViewScrollOnDragOver = class(TCustomControlScrollOnDragOver)
  72. private
  73. FLastDragNode: TTreeNode;
  74. FLastHScrollTime: FILETIME;
  75. public
  76. procedure StartDrag; override;
  77. procedure DragOver(Point: TPoint); override;
  78. end;
  79. TListViewScrollOnDragOver = class(TCustomControlScrollOnDragOver)
  80. public
  81. procedure DragOver(Point: TPoint); override;
  82. end;
  83. TListBoxScrollOnDragOver = class(TCustomControlScrollOnDragOver)
  84. public
  85. procedure DragOver(Point: TPoint); override;
  86. end;
  87. implementation
  88. uses
  89. SysUtils, Messages, StdCtrls, Graphics;
  90. const
  91. DDExpandDelay = 15000000;
  92. DDMaxSlowCount = 3;
  93. DDVScrollDelay = 2000000;
  94. DDHScrollDelay = 2000000;
  95. DDDragStartDelay = 500000;
  96. function Construct(ComponentClass: TComponentClass; Owner: TComponent): TComponent;
  97. begin
  98. Result := ComponentClass.Create(Owner);
  99. end;
  100. // detects vista, even in compatibility mode
  101. // (GetLocaleInfoEx is available since Vista only)
  102. function IsVistaHard: Boolean;
  103. begin
  104. Result := (GetProcAddress(GetModuleHandle(Kernel32), 'GetLocaleInfoEx') <> nil);
  105. end;
  106. function IsVista: Boolean;
  107. begin
  108. Result := CheckWin32Version(6, 0);
  109. end;
  110. function IsWin7: Boolean;
  111. begin
  112. Result := CheckWin32Version(6, 1);
  113. end;
  114. function IsWin8: Boolean;
  115. begin
  116. Result := CheckWin32Version(6, 2);
  117. end;
  118. function CutToChar(var Str: string; Ch: Char; Trim: Boolean): string;
  119. var
  120. P: Integer;
  121. begin
  122. P := Pos(Ch, Str);
  123. if P > 0 then
  124. begin
  125. Result := Copy(Str, 1, P-1);
  126. Delete(Str, 1, P);
  127. end
  128. else
  129. begin
  130. Result := Str;
  131. Str := '';
  132. end;
  133. if Trim then Result := SysUtils.Trim(Result);
  134. end;
  135. procedure FilterToFileTypes(Filter: string; FileTypes: TFileTypeItems);
  136. var
  137. Item: TFileTypeItem;
  138. begin
  139. while Filter <> '' do
  140. begin
  141. Item := FileTypes.Add();
  142. Item.DisplayName := CutToChar(Filter, '|', True);
  143. Item.FileMask := CutToChar(Filter, '|', True);
  144. end;
  145. end;
  146. function LoadDimension(Dimension: Integer; PixelsPerInch: Integer): Integer;
  147. begin
  148. Result := MulDiv(Dimension, Screen.PixelsPerInch, PixelsPerInch);
  149. end;
  150. function StrToDimensionDef(Str: string; PixelsPerInch: Integer; Default: Integer): Integer;
  151. begin
  152. if TryStrToInt(Str, Result) then
  153. begin
  154. Result := LoadDimension(Result, PixelsPerInch);
  155. end
  156. else
  157. begin
  158. Result := Default;
  159. end;
  160. end;
  161. function SaveDimension(Dimension: Integer): Integer;
  162. begin
  163. // noop
  164. Result := Dimension;
  165. end;
  166. function DimensionToDefaultPixelsPerInch(Dimension: Integer): Integer;
  167. begin
  168. Result := MulDiv(Dimension, USER_DEFAULT_SCREEN_DPI, Screen.PixelsPerInch);
  169. end;
  170. function ScaleByPixelsPerInch(Dimension: Integer): Integer;
  171. begin
  172. Result := MulDiv(Dimension, Screen.PixelsPerInch, USER_DEFAULT_SCREEN_DPI);
  173. end;
  174. function LoadPixelsPerInch(S: string): Integer;
  175. begin
  176. // for backward compatibility with version that did not save the DPI,
  177. // make reasonable assumption that the configuration was saved with
  178. // the same DPI as we run now
  179. Result := StrToIntDef(S, Screen.PixelsPerInch);
  180. end;
  181. function SavePixelsPerInch: string;
  182. begin
  183. Result := IntToStr(Screen.PixelsPerInch);
  184. end;
  185. function SaveDefaultPixelsPerInch: string;
  186. begin
  187. Result := IntToStr(USER_DEFAULT_SCREEN_DPI);
  188. end;
  189. // WORKAROUND
  190. // http://stackoverflow.com/questions/9410485/how-do-i-use-class-helpers-to-access-strict-private-members-of-a-class
  191. type
  192. TFormHelper = class helper for TCustomForm
  193. public
  194. function RetrieveTextHeight: Integer;
  195. function CalculateTextHeight: Integer;
  196. end;
  197. function TFormHelper.RetrieveTextHeight: Integer;
  198. begin
  199. Result := Self.FTextHeight;
  200. end;
  201. function TFormHelper.CalculateTextHeight: Integer;
  202. begin
  203. Result := Self.GetTextHeight;
  204. end;
  205. function ScaleByTextHeightImpl(Control: TControl; Dimension: Integer; TextHeight: Integer): Integer;
  206. var
  207. Form: TCustomForm;
  208. NewTextHeight: Integer;
  209. begin
  210. // RTL_COPY (TCustomForm.ReadState)
  211. Form := ValidParentForm(Control);
  212. NewTextHeight := Form.CalculateTextHeight;
  213. if TextHeight <> NewTextHeight then
  214. begin
  215. Dimension := MulDiv(Dimension, NewTextHeight, TextHeight);
  216. end;
  217. Result := Dimension;
  218. end;
  219. const
  220. OurDesignTimeTextHeight = 13;
  221. function ScaleByTextHeight(Control: TControl; Dimension: Integer): Integer;
  222. var
  223. Form: TCustomForm;
  224. TextHeight: Integer;
  225. begin
  226. // RTL_COPY (TCustomForm.ReadState)
  227. Form := ValidParentForm(Control);
  228. TextHeight := Form.RetrieveTextHeight;
  229. // that's our design text-size, we do not expect any other value
  230. Assert(TextHeight = OurDesignTimeTextHeight);
  231. Result := ScaleByTextHeightImpl(Control, Dimension, TextHeight);
  232. end;
  233. // this differs from ScaleByTextHeight only by enforcing
  234. // constant design-time text height
  235. function ScaleByTextHeightRunTime(Control: TControl; Dimension: Integer): Integer;
  236. begin
  237. Result := ScaleByTextHeightImpl(Control, Dimension, OurDesignTimeTextHeight);
  238. end;
  239. type
  240. TListViewHelper = class helper for TCustomListView
  241. public
  242. function HasMemStream: Boolean;
  243. end;
  244. function TListViewHelper.HasMemStream: Boolean;
  245. begin
  246. Result := Assigned(Self.FMemStream);
  247. end;
  248. type
  249. TTreeViewHelper = class helper for TCustomTreeView
  250. public
  251. function HasMemStream: Boolean;
  252. end;
  253. function TTreeViewHelper.HasMemStream: Boolean;
  254. begin
  255. Result := Assigned(Self.FMemStream);
  256. end;
  257. type
  258. TRichEditHelper = class helper for TCustomRichEdit
  259. public
  260. function HasMemStream: Boolean;
  261. end;
  262. function TRichEditHelper.HasMemStream: Boolean;
  263. begin
  264. Result := Assigned(Self.FMemStream);
  265. end;
  266. function ControlHasRecreationPersistenceData(Control: TControl): Boolean;
  267. begin
  268. // not implemented for this class as we do not use it as of now
  269. Assert(not (Control is TCustomComboBoxEx));
  270. Result :=
  271. ((Control is TCustomListView) and (Control as TCustomListView).HasMemStream) or
  272. ((Control is TCustomTreeView) and (Control as TCustomTreeView).HasMemStream) or
  273. ((Control is TCustomRichEdit) and (Control as TCustomRichEdit).HasMemStream);
  274. end;
  275. type
  276. TApplicationHelper = class helper for TApplication
  277. public
  278. function IsAppIconic: Boolean;
  279. procedure SetAppIconic(Value: Boolean);
  280. procedure SetMainForm(Value: TForm);
  281. end;
  282. function TApplicationHelper.IsAppIconic: Boolean;
  283. begin
  284. Result := Self.FAppIconic;
  285. end;
  286. procedure TApplicationHelper.SetAppIconic(Value: Boolean);
  287. begin
  288. Self.FAppIconic := Value;
  289. end;
  290. procedure TApplicationHelper.SetMainForm(Value: TForm);
  291. begin
  292. Self.FMainForm := Value;
  293. end;
  294. function IsAppIconic: Boolean;
  295. begin
  296. Result := Application.IsAppIconic;
  297. end;
  298. procedure SetAppIconic(Value: Boolean);
  299. begin
  300. Application.SetAppIconic(Value);
  301. end;
  302. procedure SetAppMainForm(Value: TForm);
  303. begin
  304. Application.SetMainForm(Value);
  305. end;
  306. function ApiPath(Path: string): string;
  307. begin
  308. Result := Path;
  309. if Assigned(OnApiPath) then
  310. begin
  311. Result := OnApiPath(Result);
  312. end;
  313. end;
  314. procedure ForceColorChange(Control: TWinControl);
  315. begin
  316. // particularly when changing color back to default (clWindow),
  317. // non-client area (border line) is not redrawn,
  318. // keeping previous color. force redraw here
  319. if Control.HandleAllocated then
  320. begin
  321. RedrawWindow(Control.Handle, nil, 0, RDW_INVALIDATE or RDW_FRAME);
  322. end;
  323. end;
  324. { TCustomControlScrollOnDragOver }
  325. constructor TCustomControlScrollOnDragOver.Create(Control: TControl;
  326. ScheduleDragOver: Boolean);
  327. begin
  328. FControl := Control;
  329. FOnBeforeUpdate := nil;
  330. FOnAfterUpdate := nil;
  331. if ScheduleDragOver then
  332. begin
  333. FDragOverTimer := TTimer.Create(Control);
  334. FDragOverTimer.Enabled := False;
  335. FDragOverTimer.Interval := 50;
  336. FDragOverTimer.OnTimer := DragOverTimer;
  337. end
  338. else FDragOverTimer := nil;
  339. end;
  340. destructor TCustomControlScrollOnDragOver.Destroy;
  341. begin
  342. FreeAndNil(FDragOverTimer);
  343. end;
  344. procedure TCustomControlScrollOnDragOver.DragOverTimer(Sender: TObject);
  345. var
  346. P: TPoint;
  347. begin
  348. P := FControl.ScreenToClient(Mouse.CursorPos);
  349. if (P.X >= 0) and (P.X < FControl.Width) and
  350. (P.Y >= 0) and (P.Y < FControl.Height) then
  351. begin
  352. DragOver(P);
  353. end;
  354. end;
  355. procedure TCustomControlScrollOnDragOver.StartDrag;
  356. begin
  357. GetSystemTimeAsFileTime(FDragOverTime);
  358. GetSystemTimeAsFileTime(FLastVScrollTime);
  359. FVScrollCount := 0;
  360. if Assigned(FDragOverTimer) then
  361. FDragOverTimer.Enabled := True;
  362. end;
  363. procedure TCustomControlScrollOnDragOver.EndDrag;
  364. begin
  365. if Assigned(FDragOverTimer) then
  366. FDragOverTimer.Enabled := False;
  367. end;
  368. type
  369. TPublicControl = class(TControl);
  370. procedure TCustomControlScrollOnDragOver.BeforeUpdate(ObjectToValidate: TObject);
  371. var
  372. DragImages: TDragImageList;
  373. begin
  374. if Assigned(FOnBeforeUpdate) then
  375. FOnBeforeUpdate(ObjectToValidate);
  376. DragImages := TPublicControl(FControl).GetDragImages;
  377. if Assigned(DragImages) then
  378. DragImages.HideDragImage;
  379. end;
  380. procedure TCustomControlScrollOnDragOver.AfterUpdate;
  381. var
  382. DragImages: TDragImageList;
  383. begin
  384. if Assigned(FOnAfterUpdate) then
  385. FOnAfterUpdate;
  386. DragImages := TPublicControl(FControl).GetDragImages;
  387. if Assigned(DragImages) then
  388. DragImages.ShowDragImage;
  389. end;
  390. procedure TTreeViewScrollOnDragOver.StartDrag;
  391. var
  392. KeyBoardState : TKeyBoardState;
  393. begin
  394. inherited;
  395. FLastDragNode := nil;
  396. if (GetKeyState(VK_SPACE) <> 0) and GetKeyboardState(KeyBoardState) then
  397. begin
  398. KeyBoardState[VK_SPACE] := 0;
  399. SetKeyBoardState(KeyBoardState);
  400. end;
  401. GetSystemTimeAsFileTime(FLastHScrollTime);
  402. end;
  403. { TTreeViewScrollOnDragOver }
  404. procedure TTreeViewScrollOnDragOver.DragOver(Point: TPoint);
  405. var
  406. TreeView: TCustomTreeView;
  407. NbPixels: Integer;
  408. KnowTime: TFileTime;
  409. Node: TTreeNode;
  410. TempTopItem: TTreeNode;
  411. ScrollInfo: TScrollInfo;
  412. KeyBoardState : TKeyBoardState;
  413. begin
  414. TreeView := (FControl as TCustomTreeView);
  415. Node := TreeView.GetNodeAt(Point.X, Point.Y);
  416. if Assigned(Node) then
  417. begin
  418. GetSystemTimeAsFileTime(KnowTime);
  419. if GetKeyState(VK_SPACE) = 0 then
  420. begin
  421. {Expand node after 2.5 seconds: }
  422. if not Assigned(FLastDragNode) or (FLastDragNode <> Node) then
  423. begin
  424. {not previous droptarget: start timer}
  425. GetSystemTimeAsFileTime(FDragOverTime);
  426. FLastDragNode := Node
  427. end
  428. else
  429. begin
  430. if ((Int64(KnowTime) - Int64(FDragOverTime)) > DDExpandDelay) then
  431. begin
  432. TempTopItem := TreeView.TopItem;
  433. BeforeUpdate(nil);
  434. Node.Expand(False);
  435. TreeView.TopItem := TempTopItem;
  436. TreeView.Update;
  437. AfterUpdate;
  438. FDragOverTime := KnowTime;
  439. end;
  440. end;
  441. end
  442. else
  443. begin
  444. {restart timer}
  445. GetSystemTimeAsFileTime(FDragOverTime);
  446. if GetKeyboardState(KeyBoardState) then
  447. begin
  448. KeyBoardState[VK_Space] := 0;
  449. SetKeyBoardState(KeyBoardState);
  450. end;
  451. TempTopItem := TreeView.TopItem;
  452. BeforeUpdate(Node);
  453. if Node.Expanded then
  454. begin
  455. if not TreeView.Selected.HasAsParent(Node) then
  456. Node.Collapse(False);
  457. end
  458. else Node.Expand(False);
  459. TreeView.TopItem := TempTopItem;
  460. TreeView.Update;
  461. AfterUpdate;
  462. end;
  463. NbPixels := Abs(TTreeView(FControl).Font.Height);
  464. {Vertical treescrolling:}
  465. if ((Int64(KnowTime) - Int64(FLastVScrollTime)) > DDVScrollDelay) or
  466. ((FVScrollCount > 3) and
  467. ((Int64(KnowTime) - Int64(FLastVScrollTime)) > (DDVScrollDelay Div 4))) then
  468. begin
  469. {Scroll tree up, if droptarget is topitem:}
  470. if Node = TreeView.TopItem then
  471. begin
  472. BeforeUpdate(nil);
  473. TreeView.Perform(WM_VSCROLL, SB_LINEUP, 0);
  474. AfterUpdate;
  475. GetSystemTimeAsFileTime(FLastVScrollTime);
  476. Inc(FVScrollCount);
  477. end
  478. else
  479. {Scroll tree down, if next visible item of droptarget is not visible:}
  480. begin
  481. if Point.Y + 3 * nbPixels > TreeView.Height then
  482. begin
  483. BeforeUpdate(nil);
  484. TreeView.Perform(WM_VSCROLL, SB_LINEDOWN, 0);
  485. AfterUpdate;
  486. GetSystemTimeAsFileTime(FLastVScrollTime);
  487. Inc(FVScrollCount);
  488. end
  489. else
  490. begin
  491. FVScrollCount := 0;
  492. end;
  493. end;
  494. end; {VScrollDelay}
  495. {Horizontal treescrolling:}
  496. {Scroll tree Left}
  497. if ((Int64(KnowTime) - Int64(FLastHScrollTime)) > DDHScrollDelay) then
  498. begin
  499. GetSystemTimeAsFileTime(FLastHScrollTime);
  500. ScrollInfo.cbSize := SizeOf(ScrollInfo);
  501. ScrollInfo.FMask := SIF_ALL;
  502. GetScrollInfo(TreeView.Handle, SB_HORZ, ScrollInfo);
  503. if ScrollInfo.nMin <> ScrollInfo.nMax then
  504. begin
  505. if Point.X < 50 then
  506. begin
  507. if Node.DisplayRect(True).Right + 50 < TreeView.Width then
  508. begin
  509. BeforeUpdate(nil);
  510. TreeView.Perform(WM_HSCROLL, SB_LINELEFT, 0);
  511. AfterUpdate;
  512. end;
  513. end
  514. else
  515. if Point.X > (TreeView.Width - 50) then
  516. begin
  517. if Node.DisplayRect(True).Left > 50 then
  518. begin
  519. BeforeUpdate(nil);
  520. TreeView.Perform(WM_HSCROLL, SB_LINERIGHT, 0);
  521. AfterUpdate;
  522. end;
  523. end;
  524. end;
  525. end;
  526. end;
  527. end;
  528. { TListViewScrollOnDragOver }
  529. procedure TListViewScrollOnDragOver.DragOver(Point: TPoint);
  530. var
  531. ListView: TCustomListView;
  532. KnowTime: TFileTime;
  533. NbPixels: Integer;
  534. WParam: LongInt;
  535. begin
  536. ListView := (FControl as TCustomListView);
  537. GetSystemTimeAsFileTime(KnowTime);
  538. NbPixels := Abs(TListView(ListView).Font.Height);
  539. {Vertical scrolling, if viewstyle = vsReport:}
  540. if (TListView(ListView).ViewStyle = vsReport) and Assigned(ListView.TopItem) and
  541. (((Int64(KnowTime) - Int64(FLastVScrollTime)) > DDVScrollDelay) or
  542. ((FVScrollCount > DDMaxSlowCount) and
  543. ((Int64(KnowTime) - Int64(FLastVScrollTime)) > (DDVScrollDelay div 4)))) then
  544. begin
  545. if (Point.Y - 3 * nbPixels <= 0) and (ListView.TopItem.Index > 0) then WParam := SB_LINEUP
  546. else
  547. if (Point.Y + 3 * nbPixels > ListView.Height) then WParam := SB_LINEDOWN
  548. else WParam := -1;
  549. if WParam >= 0 then
  550. begin
  551. BeforeUpdate(nil);
  552. ListView.Perform(WM_VSCROLL, WParam, 0);
  553. if FVScrollCount > DDMaxSlowCount then
  554. ListView.Perform(WM_VSCROLL, WParam, 0);
  555. if FVScrollCount > DDMaxSlowCount * 3 then
  556. ListView.Perform(WM_VSCROLL, WParam, 0);
  557. ListView.Update;
  558. AfterUpdate;
  559. GetSystemTimeAsFileTime(FLastVScrollTime);
  560. Inc(FVScrollCount);
  561. end
  562. else FVScrollCount := 0;
  563. end;
  564. end;
  565. { TListBoxScrollOnDragOver }
  566. procedure TListBoxScrollOnDragOver.DragOver(Point: TPoint);
  567. var
  568. ListBox: TListBox;
  569. KnowTime: TFileTime;
  570. NbPixels: Integer;
  571. WParam: LongInt;
  572. begin
  573. ListBox := (FControl as TListBox);
  574. GetSystemTimeAsFileTime(KnowTime);
  575. NbPixels := Abs(ListBox.Font.Height);
  576. {Vertical scrolling, if viewstyle = vsReport:}
  577. if (ListBox.Items.Count > 0) and
  578. (((Int64(KnowTime) - Int64(FLastVScrollTime)) > DDVScrollDelay) or
  579. ((FVScrollCount > DDMaxSlowCount) and
  580. ((Int64(KnowTime) - Int64(FLastVScrollTime)) > (DDVScrollDelay div 4)))) then
  581. begin
  582. if (Point.Y - 3 * nbPixels <= 0) and (ListBox.TopIndex > 0) then WParam := SB_LINEUP
  583. else
  584. if (Point.Y + 3 * nbPixels > ListBox.Height) then WParam := SB_LINEDOWN
  585. else WParam := -1;
  586. if WParam >= 0 then
  587. begin
  588. BeforeUpdate(nil);
  589. ListBox.Perform(WM_VSCROLL, WParam, 0);
  590. if FVScrollCount > DDMaxSlowCount then
  591. ListBox.Perform(WM_VSCROLL, WParam, 0);
  592. if FVScrollCount > DDMaxSlowCount * 3 then
  593. ListBox.Perform(WM_VSCROLL, WParam, 0);
  594. ListBox.Update;
  595. AfterUpdate;
  596. GetSystemTimeAsFileTime(FLastVScrollTime);
  597. Inc(FVScrollCount);
  598. end
  599. else FVScrollCount := 0;
  600. end;
  601. end;
  602. end.