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

General TRichView support forum. Please post your questions here
Post Reply
cedo
Posts: 10
Joined: Wed Nov 28, 2012 10:16 am

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

Post 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 ?
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post by Sergey Tkachenko »

Sorry, I do not understand. TRichViewEdit does not have pages, how can it switch?
cedo
Posts: 10
Joined: Wed Nov 28, 2012 10:16 am

Post 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.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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.
cedo
Posts: 10
Joined: Wed Nov 28, 2012 10:16 am

Post by cedo »

I wish I could switch document to the next page by mouse wheel.
Sergey Tkachenko
Site Admin
Posts: 17569
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Post 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)
cedo
Posts: 10
Joined: Wed Nov 28, 2012 10:16 am

Post 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;
Post Reply