Lazarus: Wheelscroll not handled by editor

ScaleRichView support and discussion (TRichView add-on for WYSIWYG editing)
Post Reply
luc
Posts: 13
Joined: Wed Jan 12, 2022 9:20 am

Lazarus: Wheelscroll not handled by editor

Post by luc »

AFAIK ScaleRichView editor doesn't handle the Mouse WheelScroll event, nor the Ctrl+WheeScroll event for zooming.
Tested with the ActionTests demo, without changing any properties to the TSRichViewEdit.
Is there any options to turn on or is it an Lazarus specific issue?
standay
Posts: 272
Joined: Fri Jun 18, 2021 3:07 pm

Re: Lazarus: Wheelscroll not handled by editor

Post by standay »

I tried the compiled ActionTests demo I have and there's no mousewheel action in it. I would assume it was compiled in delphi.

I'm using a plain rve (not the scale version), but I found that in the app I'm currently working on that I had the best luck with putting mouse wheel code in the form:

Code: Select all

procedure TForm1.FormMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
var
  WinControl: TWinControl;
  i: Integer;
Begin
  WinControl := nil;
  if FindDragTarget(MousePos,false) is TWinControl then
    WinControl := TWinControl(FindDragTarget(Mouse.CursorPos,false));
  if WinControl <> nil then
  Begin
     if not ((WinControl is TVirtualStringTree) or
       (WinControl is TCustomRichViewEdit)) then exit;

     if WinControl.MouseInClient then
     For i:= 1 To Mouse.WheelScrollLines
     Do
      Begin
       Try
         If WheelDelta > 0
         Then SendMessage(WinControl.Handle,WM_VSCROLL,SB_LINEUP,0)
         Else SendMessage(WinControl.Handle,WM_VSCROLL,SB_LINEDOWN,0);
       Finally
         SendMessage(WinControl.Handle,WM_VSCROLL,SB_ENDSCROLL,0);
       End;
     End;

  End;
...
Then, in my 2 rve's, I added this so they only scroll with the wheel if the mouse is over them:

Code: Select all

procedure TForm1.rveMouseWheel(Sender: TObject; Shift: TShiftState;
  WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
Begin
  Handled := not PtInRect(rvePanel.ClientRect,rvePanel.ScreenToClient(MousePos));
end;
So, you might try adding code to the form and see if that helps.

Stan
luc
Posts: 13
Joined: Wed Jan 12, 2022 9:20 am

Re: Lazarus: Wheelscroll not handled by editor

Post by luc »

Thanks Stan for your help,

I did test your code (deleting TVirtualStringTree) but the Form Event is not fired when the mouse is on SRVE.
Anyway, I ended up with this simple code and it works fine for me:

Code: Select all

procedure TFormTextEditor.SRichViewEdit1MouseWheel(Sender: TObject;
  Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
  var Handled: Boolean);
begin
  if SRichViewEdit1.CanScroll then
    begin
    SRichViewEdit1.ScrollBarV.Position := SRichViewEdit1.ScrollBarV.Position + (WheelDelta*-1);
    Handled := True;
    end;
end;    
Luc
standay
Posts: 272
Joined: Fri Jun 18, 2021 3:07 pm

Re: Lazarus: Wheelscroll not handled by editor

Post by standay »

Makes sense, the srve probably "steals" the mouse message. Glad you got it working!

Stan
luc
Posts: 13
Joined: Wed Jan 12, 2022 9:20 am

Re: Lazarus: Wheelscroll not handled by editor

Post by luc »

Just to give back some code to handle the ctrl+mousewheel to zoom in and out:

Code: Select all

procedure TFormTextEditor.SRichViewEditMouseWheel(Sender: TObject;
  Shift: TShiftState; WheelDelta: Integer; MousePos: TPoint;
  var Handled: Boolean);
begin
  if (ssCtrl in Shift) then
    begin
    SRichViewEdit.ViewProperty.ZoomPercent := SRichViewEdit.ViewProperty.ZoomPercent + (WheelDelta);
    SRichViewEdit.ViewProperty.ZoomMode := rvzmCustom;
    end else
    begin
    if SRichViewEdit.CanScroll then
      begin
      SRichViewEdit.ScrollBarV.Position := SRichViewEdit.ScrollBarV.Position + (WheelDelta*-1);
      Handled := True;
      end;
    end;
end;   
Sergey Tkachenko
Site Admin
Posts: 17520
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: Lazarus: Wheelscroll not handled by editor

Post by Sergey Tkachenko »

Do you mean that mouse wheel scrolling/zooming does not work in TSRichViewEdit in Lazarus?

Sorry, I cannot reproduce this problem (Windows 10, Lazarus 2.2, newest version of TRichView and ScaleRichView)
luc
Posts: 13
Joined: Wed Jan 12, 2022 9:20 am

Re: Lazarus: Wheelscroll not handled by editor

Post by luc »

You are right, the wheelscroll is working with the demo but not when I use a panel as parent for all the demo components (I had to use additional panel as I need to add some more side panels in the form holding SRV).
The wheescroll is working for the thumbnail panel though.

Nothing really annoying since the custom event handler does the job but may be something to look after.

For the record, I use win 8.1 on VM but I don't think it is related.
Post Reply