Handle mouse wheel scrolling in any VirtualTree under mouse, without having focus. Fixes issue #447.

This commit is contained in:
Ansgar Becker
2009-12-27 07:06:29 +00:00
parent 02c7c26b9c
commit cfe95db339
2 changed files with 24 additions and 0 deletions

View File

@@ -15,6 +15,7 @@ object MainForm: TMainForm
OnClose = FormClose
OnCloseQuery = FormCloseQuery
OnCreate = FormCreate
OnMouseWheel = FormMouseWheel
OnResize = FormResize
PixelsPerInch = 96
TextHeight = 13

View File

@@ -703,6 +703,8 @@ type
procedure menuQueryHelpersGenerateStatementClick(Sender: TObject);
procedure actDataDuplicateRowExecute(Sender: TObject);
procedure actSelectInverseExecute(Sender: TObject);
procedure FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
var Handled: Boolean);
private
ReachedEOT : Boolean;
FDelimiter: String;
@@ -8837,5 +8839,26 @@ begin
end;
procedure TMainForm.FormMouseWheel(Sender: TObject; Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
var Handled: Boolean);
var
Control: TWinControl;
VT: TBaseVirtualTree;
begin
// Wheel scrolling only works in component which has focus. Help out by doing that by hand at least for any VirtualTree.
// See http://www.delphipraxis.net/viewtopic.php?p=1113607
// TODO: Does not work when a SynMemo has focus, probably related to the broken solution of this issue:
// http://sourceforge.net/tracker/index.php?func=detail&aid=1574059&group_id=3221&atid=103221
Control := FindVCLWindow(MousePos);
if (Control is TBaseVirtualTree) and (not Control.Focused) and PtInRect(Control.ClientRect, Control.ScreenToClient(MousePos)) then begin
VT := Control as TBaseVirtualTree;
VT.OffsetY := VT.OffsetY + (WheelDelta div 2); // Don't know why, but WheelDelta is twice as big as it normally appears
VT.UpdateScrollBars(True);
Handled := True;
end else
Handled := False;
end;
end.