PasTools.pas 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  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/q/9410485/850848
  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. // runtime form (such as TTBFloatingWindowParent)
  230. if TextHeight = 0 then
  231. begin
  232. Result := ScaleByTextHeightRunTime(Control, Dimension);
  233. end
  234. else
  235. begin
  236. // that's our design text-size, we do not expect any other value
  237. Assert(TextHeight = OurDesignTimeTextHeight);
  238. Result := ScaleByTextHeightImpl(Control, Dimension, TextHeight);
  239. end;
  240. end;
  241. // this differs from ScaleByTextHeight only by enforcing
  242. // constant design-time text height
  243. function ScaleByTextHeightRunTime(Control: TControl; Dimension: Integer): Integer;
  244. begin
  245. Result := ScaleByTextHeightImpl(Control, Dimension, OurDesignTimeTextHeight);
  246. end;
  247. type
  248. TListViewHelper = class helper for TCustomListView
  249. public
  250. function HasMemStream: Boolean;
  251. end;
  252. function TListViewHelper.HasMemStream: Boolean;
  253. begin
  254. Result := Assigned(Self.FMemStream);
  255. end;
  256. type
  257. TTreeViewHelper = class helper for TCustomTreeView
  258. public
  259. function HasMemStream: Boolean;
  260. end;
  261. function TTreeViewHelper.HasMemStream: Boolean;
  262. begin
  263. Result := Assigned(Self.FMemStream);
  264. end;
  265. type
  266. TRichEditHelper = class helper for TCustomRichEdit
  267. public
  268. function HasMemStream: Boolean;
  269. end;
  270. function TRichEditHelper.HasMemStream: Boolean;
  271. begin
  272. Result := Assigned(Self.FMemStream);
  273. end;
  274. function ControlHasRecreationPersistenceData(Control: TControl): Boolean;
  275. begin
  276. // not implemented for this class as we do not use it as of now
  277. Assert(not (Control is TCustomComboBoxEx));
  278. Result :=
  279. ((Control is TCustomListView) and (Control as TCustomListView).HasMemStream) or
  280. ((Control is TCustomTreeView) and (Control as TCustomTreeView).HasMemStream) or
  281. ((Control is TCustomRichEdit) and (Control as TCustomRichEdit).HasMemStream);
  282. end;
  283. type
  284. TApplicationHelper = class helper for TApplication
  285. public
  286. function IsAppIconic: Boolean;
  287. procedure SetAppIconic(Value: Boolean);
  288. procedure SetMainForm(Value: TForm);
  289. end;
  290. function TApplicationHelper.IsAppIconic: Boolean;
  291. begin
  292. Result := Self.FAppIconic;
  293. end;
  294. procedure TApplicationHelper.SetAppIconic(Value: Boolean);
  295. begin
  296. Self.FAppIconic := Value;
  297. end;
  298. procedure TApplicationHelper.SetMainForm(Value: TForm);
  299. begin
  300. Self.FMainForm := Value;
  301. end;
  302. function IsAppIconic: Boolean;
  303. begin
  304. Result := Application.IsAppIconic;
  305. end;
  306. procedure SetAppIconic(Value: Boolean);
  307. begin
  308. Application.SetAppIconic(Value);
  309. end;
  310. procedure SetAppMainForm(Value: TForm);
  311. begin
  312. Application.SetMainForm(Value);
  313. end;
  314. function ApiPath(Path: string): string;
  315. begin
  316. Result := Path;
  317. if Assigned(OnApiPath) then
  318. begin
  319. Result := OnApiPath(Result);
  320. end;
  321. end;
  322. procedure ForceColorChange(Control: TWinControl);
  323. begin
  324. // particularly when changing color back to default (clWindow),
  325. // non-client area (border line) is not redrawn,
  326. // keeping previous color. force redraw here
  327. if Control.HandleAllocated then
  328. begin
  329. RedrawWindow(Control.Handle, nil, 0, RDW_INVALIDATE or RDW_FRAME);
  330. end;
  331. end;
  332. { TCustomControlScrollOnDragOver }
  333. constructor TCustomControlScrollOnDragOver.Create(Control: TControl;
  334. ScheduleDragOver: Boolean);
  335. begin
  336. FControl := Control;
  337. FOnBeforeUpdate := nil;
  338. FOnAfterUpdate := nil;
  339. if ScheduleDragOver then
  340. begin
  341. FDragOverTimer := TTimer.Create(Control);
  342. FDragOverTimer.Enabled := False;
  343. FDragOverTimer.Interval := 50;
  344. FDragOverTimer.OnTimer := DragOverTimer;
  345. end
  346. else FDragOverTimer := nil;
  347. end;
  348. destructor TCustomControlScrollOnDragOver.Destroy;
  349. begin
  350. FreeAndNil(FDragOverTimer);
  351. end;
  352. procedure TCustomControlScrollOnDragOver.DragOverTimer(Sender: TObject);
  353. var
  354. P: TPoint;
  355. begin
  356. P := FControl.ScreenToClient(Mouse.CursorPos);
  357. if (P.X >= 0) and (P.X < FControl.Width) and
  358. (P.Y >= 0) and (P.Y < FControl.Height) then
  359. begin
  360. DragOver(P);
  361. end;
  362. end;
  363. procedure TCustomControlScrollOnDragOver.StartDrag;
  364. begin
  365. GetSystemTimeAsFileTime(FDragOverTime);
  366. GetSystemTimeAsFileTime(FLastVScrollTime);
  367. FVScrollCount := 0;
  368. if Assigned(FDragOverTimer) then
  369. FDragOverTimer.Enabled := True;
  370. end;
  371. procedure TCustomControlScrollOnDragOver.EndDrag;
  372. begin
  373. if Assigned(FDragOverTimer) then
  374. FDragOverTimer.Enabled := False;
  375. end;
  376. type
  377. TPublicControl = class(TControl);
  378. procedure TCustomControlScrollOnDragOver.BeforeUpdate(ObjectToValidate: TObject);
  379. var
  380. DragImages: TDragImageList;
  381. begin
  382. if Assigned(FOnBeforeUpdate) then
  383. FOnBeforeUpdate(ObjectToValidate);
  384. DragImages := TPublicControl(FControl).GetDragImages;
  385. if Assigned(DragImages) then
  386. DragImages.HideDragImage;
  387. end;
  388. procedure TCustomControlScrollOnDragOver.AfterUpdate;
  389. var
  390. DragImages: TDragImageList;
  391. begin
  392. if Assigned(FOnAfterUpdate) then
  393. FOnAfterUpdate;
  394. DragImages := TPublicControl(FControl).GetDragImages;
  395. if Assigned(DragImages) then
  396. DragImages.ShowDragImage;
  397. end;
  398. procedure TTreeViewScrollOnDragOver.StartDrag;
  399. var
  400. KeyBoardState : TKeyBoardState;
  401. begin
  402. inherited;
  403. FLastDragNode := nil;
  404. if (GetKeyState(VK_SPACE) <> 0) and GetKeyboardState(KeyBoardState) then
  405. begin
  406. KeyBoardState[VK_SPACE] := 0;
  407. SetKeyBoardState(KeyBoardState);
  408. end;
  409. GetSystemTimeAsFileTime(FLastHScrollTime);
  410. end;
  411. { TTreeViewScrollOnDragOver }
  412. procedure TTreeViewScrollOnDragOver.DragOver(Point: TPoint);
  413. var
  414. TreeView: TCustomTreeView;
  415. NbPixels: Integer;
  416. KnowTime: TFileTime;
  417. Node: TTreeNode;
  418. TempTopItem: TTreeNode;
  419. ScrollInfo: TScrollInfo;
  420. KeyBoardState : TKeyBoardState;
  421. begin
  422. TreeView := (FControl as TCustomTreeView);
  423. Node := TreeView.GetNodeAt(Point.X, Point.Y);
  424. if Assigned(Node) then
  425. begin
  426. GetSystemTimeAsFileTime(KnowTime);
  427. if GetKeyState(VK_SPACE) = 0 then
  428. begin
  429. {Expand node after 2.5 seconds: }
  430. if not Assigned(FLastDragNode) or (FLastDragNode <> Node) then
  431. begin
  432. {not previous droptarget: start timer}
  433. GetSystemTimeAsFileTime(FDragOverTime);
  434. FLastDragNode := Node
  435. end
  436. else
  437. begin
  438. if ((Int64(KnowTime) - Int64(FDragOverTime)) > DDExpandDelay) then
  439. begin
  440. TempTopItem := TreeView.TopItem;
  441. BeforeUpdate(nil);
  442. Node.Expand(False);
  443. TreeView.TopItem := TempTopItem;
  444. TreeView.Update;
  445. AfterUpdate;
  446. FDragOverTime := KnowTime;
  447. end;
  448. end;
  449. end
  450. else
  451. begin
  452. {restart timer}
  453. GetSystemTimeAsFileTime(FDragOverTime);
  454. if GetKeyboardState(KeyBoardState) then
  455. begin
  456. KeyBoardState[VK_Space] := 0;
  457. SetKeyBoardState(KeyBoardState);
  458. end;
  459. TempTopItem := TreeView.TopItem;
  460. BeforeUpdate(Node);
  461. if Node.Expanded then
  462. begin
  463. if not TreeView.Selected.HasAsParent(Node) then
  464. Node.Collapse(False);
  465. end
  466. else Node.Expand(False);
  467. TreeView.TopItem := TempTopItem;
  468. TreeView.Update;
  469. AfterUpdate;
  470. end;
  471. NbPixels := Abs(TTreeView(FControl).Font.Height);
  472. {Vertical treescrolling:}
  473. if ((Int64(KnowTime) - Int64(FLastVScrollTime)) > DDVScrollDelay) or
  474. ((FVScrollCount > 3) and
  475. ((Int64(KnowTime) - Int64(FLastVScrollTime)) > (DDVScrollDelay Div 4))) then
  476. begin
  477. {Scroll tree up, if droptarget is topitem:}
  478. if Node = TreeView.TopItem then
  479. begin
  480. BeforeUpdate(nil);
  481. TreeView.Perform(WM_VSCROLL, SB_LINEUP, 0);
  482. AfterUpdate;
  483. GetSystemTimeAsFileTime(FLastVScrollTime);
  484. Inc(FVScrollCount);
  485. end
  486. else
  487. {Scroll tree down, if next visible item of droptarget is not visible:}
  488. begin
  489. if Point.Y + 3 * nbPixels > TreeView.Height then
  490. begin
  491. BeforeUpdate(nil);
  492. TreeView.Perform(WM_VSCROLL, SB_LINEDOWN, 0);
  493. AfterUpdate;
  494. GetSystemTimeAsFileTime(FLastVScrollTime);
  495. Inc(FVScrollCount);
  496. end
  497. else
  498. begin
  499. FVScrollCount := 0;
  500. end;
  501. end;
  502. end; {VScrollDelay}
  503. {Horizontal treescrolling:}
  504. {Scroll tree Left}
  505. if ((Int64(KnowTime) - Int64(FLastHScrollTime)) > DDHScrollDelay) then
  506. begin
  507. GetSystemTimeAsFileTime(FLastHScrollTime);
  508. ScrollInfo.cbSize := SizeOf(ScrollInfo);
  509. ScrollInfo.FMask := SIF_ALL;
  510. GetScrollInfo(TreeView.Handle, SB_HORZ, ScrollInfo);
  511. if ScrollInfo.nMin <> ScrollInfo.nMax then
  512. begin
  513. if Point.X < 50 then
  514. begin
  515. if Node.DisplayRect(True).Right + 50 < TreeView.Width then
  516. begin
  517. BeforeUpdate(nil);
  518. TreeView.Perform(WM_HSCROLL, SB_LINELEFT, 0);
  519. AfterUpdate;
  520. end;
  521. end
  522. else
  523. if Point.X > (TreeView.Width - 50) then
  524. begin
  525. if Node.DisplayRect(True).Left > 50 then
  526. begin
  527. BeforeUpdate(nil);
  528. TreeView.Perform(WM_HSCROLL, SB_LINERIGHT, 0);
  529. AfterUpdate;
  530. end;
  531. end;
  532. end;
  533. end;
  534. end;
  535. end;
  536. { TListViewScrollOnDragOver }
  537. procedure TListViewScrollOnDragOver.DragOver(Point: TPoint);
  538. var
  539. ListView: TCustomListView;
  540. KnowTime: TFileTime;
  541. NbPixels: Integer;
  542. WParam: LongInt;
  543. begin
  544. ListView := (FControl as TCustomListView);
  545. GetSystemTimeAsFileTime(KnowTime);
  546. NbPixels := Abs(TListView(ListView).Font.Height);
  547. {Vertical scrolling, if viewstyle = vsReport:}
  548. if (TListView(ListView).ViewStyle = vsReport) and Assigned(ListView.TopItem) and
  549. (((Int64(KnowTime) - Int64(FLastVScrollTime)) > DDVScrollDelay) or
  550. ((FVScrollCount > DDMaxSlowCount) and
  551. ((Int64(KnowTime) - Int64(FLastVScrollTime)) > (DDVScrollDelay div 4)))) then
  552. begin
  553. if (Point.Y - 3 * nbPixels <= 0) and (ListView.TopItem.Index > 0) then WParam := SB_LINEUP
  554. else
  555. if (Point.Y + 3 * nbPixels > ListView.Height) then WParam := SB_LINEDOWN
  556. else WParam := -1;
  557. if WParam >= 0 then
  558. begin
  559. BeforeUpdate(nil);
  560. ListView.Perform(WM_VSCROLL, WParam, 0);
  561. if FVScrollCount > DDMaxSlowCount then
  562. ListView.Perform(WM_VSCROLL, WParam, 0);
  563. if FVScrollCount > DDMaxSlowCount * 3 then
  564. ListView.Perform(WM_VSCROLL, WParam, 0);
  565. ListView.Update;
  566. AfterUpdate;
  567. GetSystemTimeAsFileTime(FLastVScrollTime);
  568. Inc(FVScrollCount);
  569. end
  570. else FVScrollCount := 0;
  571. end;
  572. end;
  573. { TListBoxScrollOnDragOver }
  574. procedure TListBoxScrollOnDragOver.DragOver(Point: TPoint);
  575. var
  576. ListBox: TListBox;
  577. KnowTime: TFileTime;
  578. NbPixels: Integer;
  579. WParam: LongInt;
  580. begin
  581. ListBox := (FControl as TListBox);
  582. GetSystemTimeAsFileTime(KnowTime);
  583. NbPixels := Abs(ListBox.Font.Height);
  584. {Vertical scrolling, if viewstyle = vsReport:}
  585. if (ListBox.Items.Count > 0) and
  586. (((Int64(KnowTime) - Int64(FLastVScrollTime)) > DDVScrollDelay) or
  587. ((FVScrollCount > DDMaxSlowCount) and
  588. ((Int64(KnowTime) - Int64(FLastVScrollTime)) > (DDVScrollDelay div 4)))) then
  589. begin
  590. if (Point.Y - 3 * nbPixels <= 0) and (ListBox.TopIndex > 0) then WParam := SB_LINEUP
  591. else
  592. if (Point.Y + 3 * nbPixels > ListBox.Height) then WParam := SB_LINEDOWN
  593. else WParam := -1;
  594. if WParam >= 0 then
  595. begin
  596. BeforeUpdate(nil);
  597. ListBox.Perform(WM_VSCROLL, WParam, 0);
  598. if FVScrollCount > DDMaxSlowCount then
  599. ListBox.Perform(WM_VSCROLL, WParam, 0);
  600. if FVScrollCount > DDMaxSlowCount * 3 then
  601. ListBox.Perform(WM_VSCROLL, WParam, 0);
  602. ListBox.Update;
  603. AfterUpdate;
  604. GetSystemTimeAsFileTime(FLastVScrollTime);
  605. Inc(FVScrollCount);
  606. end
  607. else FVScrollCount := 0;
  608. end;
  609. end;
  610. end.