Page 1 of 1

Switching to the next page when end of page has been reached

Posted: Tue Jul 02, 2013 12:41 pm
by cedo
I would like TRichViewEdit control automatically switch to next page when the end of page has been reached. How can I do this ?

Posted: Wed Jul 03, 2013 7:27 am
by Sergey Tkachenko
Sorry, I do not understand. TRichViewEdit does not have pages, how can it switch?

Posted: Wed Jul 03, 2013 8:06 am
by cedo
Sorry. The TRVPrintPreview control has the following methods:
RVPP.Prev;
RVPP.Next;

I would like the method Next() is automatically executed when the end of the page is reached.

Posted: Wed Jul 03, 2013 6:22 pm
by Sergey Tkachenko
But normally, TRVPrint and TRVPrintPreview are not updated when document in TRichViewEdit is changed.

While you display TRVPrintPreview, you must provide that the source TRichViewEdit is not changed.

Posted: Thu Jul 04, 2013 9:14 am
by cedo
I wish I could switch document to the next page by mouse wheel.

Posted: Thu Jul 04, 2013 12:43 pm
by Sergey Tkachenko
You can do it in OnMouseWheel* events.

For example, RichViewActions's print preview dialog scrolls to next/previous page on mouse wheel, and changes zooming on Ctrl + mouse wheel (but only if TRVPrintPreview is not focused; otherwise, mouse wheels scrolls inside the component; but you can implement your own logic)

Posted: Fri Jul 05, 2013 12:09 pm
by cedo
My solution:

Code: Select all

  TRVPrintPreview = class(TCustomRVPrintPreview)
  private
    FVScrollDownAgain: Integer;
    FVScrollUpAgain: Integer;
...
  protected
...
    {$IFDEF RICHVIEWDEF4}
    function DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean; override;
    function DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean; override;
    {$ENDIF}
...
constructor TRVPrintPreview.Create(AOwner: TComponent);
begin
  inherited;
  FCachePageImage := False;
  FVScrollUpAgain := 0;
  FVScrollDownAgain := 0;
end;

function TRVPrintPreview.DoMouseWheelDown(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
  Result := inherited DoMouseWheelDown(Shift, MousePos);
  FVScrollUpAgain := 0;
  if Result and (VScrollPos = VScrollMax) then
  begin
    if (FVScrollDownAgain > 3) and (PageNo < GetPageCount()) then
    begin
      FVScrollDownAgain := 0;
      VScrollPos := 0;
      Next;
    end;
    Inc(FVScrollDownAgain);
  end;
end;

function TRVPrintPreview.DoMouseWheelUp(Shift: TShiftState; MousePos: TPoint): Boolean;
begin
  Result := inherited DoMouseWheelUp(Shift, MousePos);
  FVScrollDownAgain := 0;
  if Result and (VScrollPos = 0) then
  begin
    if (FVScrollUpAgain > 3) and (PageNo > 1) then
    begin
      FVScrollUpAgain := 0;
      VScrollPos := VScrollMax;
      Prev;
    end;
    Inc(FVScrollUpAgain);
  end;
end;