
{*******************************************************}
{ This unit implements mouse panning for TSRichViewEdit }
{ Required: Delphi 2006 or newer                        }
{*******************************************************}


unit SRVIMouse;

interface

uses
  Windows, Controls, IMouse,
  SclRView;

type
  TSRVPanningWindow = class (TPanningWindow)
  protected
    function GetPanOptions: TPanOptions; override;
    procedure UpdateScroll(Pt: TPoint); override;
  end;

implementation

{============================= TSRVPanningWindow ==============================}
function TSRVPanningWindow.GetPanOptions: TPanOptions;
begin
  if PanControl is TSRichViewEdit then begin
    Result := [];
    if TSRichViewEdit(PanControl).ScrollBarV.Max>0 then
      Include(Result, poVertical);
    if TSRichViewEdit(PanControl).ScrollBarH.Max>0 then
      Include(Result, poHorizontal);
    end
  else
    Result := inherited GetPanOptions;
end;
{------------------------------------------------------------------------------}
procedure TSRVPanningWindow.UpdateScroll(Pt: TPoint);
var
  i, Step: Integer;
begin
  inherited;
  if not (PanControl is TSRichViewEdit) then
    exit;
  if (poHorizontal in PanOptions) and (Pt.X <> 0) then
    TSRichViewEdit(PanControl).ScrollBarH.Position :=
      TSRichViewEdit(PanControl).ScrollBarH.Position + Pt.X div Mouse.DragThreshold;
  if (poVertical in PanOptions) and (Pt.X <> 0) then
    TSRichViewEdit(PanControl).ScrollBarV.Position :=
      TSRichViewEdit(PanControl).ScrollBarV.Position + Pt.Y div Mouse.DragThreshold;
end;

initialization

  Controls.Mouse.PanningWindowClass := TSRVPanningWindow;

end.
