Page 1 of 1

Lazarus: Wheelscroll not handled by editor

Posted: Tue Jan 18, 2022 9:34 am
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?

Re: Lazarus: Wheelscroll not handled by editor

Posted: Tue Jan 18, 2022 12:55 pm
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

Re: Lazarus: Wheelscroll not handled by editor

Posted: Wed Jan 19, 2022 12:34 pm
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

Re: Lazarus: Wheelscroll not handled by editor

Posted: Wed Jan 19, 2022 2:20 pm
by standay
Makes sense, the srve probably "steals" the mouse message. Glad you got it working!

Stan

Re: Lazarus: Wheelscroll not handled by editor

Posted: Wed Jan 19, 2022 3:01 pm
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;   

Re: Lazarus: Wheelscroll not handled by editor

Posted: Fri Jan 21, 2022 1:04 pm
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)

Re: Lazarus: Wheelscroll not handled by editor

Posted: Mon Jan 24, 2022 10:28 am
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.