View Issue Details

IDProjectCategoryView StatusLast Update
0002037JEDI VCL00 JVCL Componentspublic2004-08-08 08:54
ReporteranonymousAssigned Touser72 
PrioritynormalSeverityfeatureReproducibilityalways
Status resolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0002037: Selecting a page on a print preview
DescriptionFrom: Kenneth Todd
Email: kennethtodd@lycos.co.uk

To: Peter Thörnqvist.

Re: TO DO
    * Handle getting/setting SelectedPage (click on page -> select it)

Possible fix:

procedure TPrintPreviewForm.JvPreviewControl1MouseMove(Sender: TObject;
  Shift: TShiftState; X, Y: Integer);
  var
mousePos,pos : TPoint;
whereAtX,whereAtY,areaWidth,areaHeight,pagesWidths,pageWidth : integer;
pagesHeights,pageHeight,widthOffset,heightOffSet : integer;
begin
mousePos.X := X;
mousePos.Y := Y;
//pos := MouseCoord(X,Y);
  if (JvPreviewControl1.Options.ScaleMode = smFullPage) or (JvPreviewControl1.Options.ScaleMode = smPageWidth) then
  begin
  JvPreviewControl1.SelectedPage := JvPreviewControl1.TopRow;
  end
  else
  begin
    if (JvPreviewControl1.VisibleRows <=2) or (JvPreviewControl1.Options.Cols <= 2) then
    begin
      areaWidth := JvPreviewControl1.ClientWidth div JvPreviewControl1.Options.Cols;//JvPreviewControl1.VisibleRows;
      whereAtX := (X div areaWidth);
      areaHeight := JvPreviewControl1.ClientHeight div JvPreviewControl1.VisibleRows;
      whereAtY := (Y div areaHeight)*JvPreviewControl1.VisibleRows;
    end
    else
    begin
    pageWidth := ((JvPreviewControl1.DeviceInfo.PageWidth+JvPreviewControl1.Options.HorzSpacing) div 100)* JvPreviewControl1.Options.Scale;
    pageWidth := pageWidth div (JvPreviewControl1.DeviceInfo.LogPixelsX div Screen.PixelsPerInch);
    pagesWidths := (pageWidth*JvPreviewControl1.Options.Cols);//+(JvPreviewControl1.Options.HorzSpacing*(JvPreviewControl1.Options.Cols));
    widthOffset := (JvPreviewControl1.Width-pagesWidths) div 2;
    whereAtX := (X-widthOffset) div pageWidth;//+JvPreviewControl1.Options.HorzSpacing);
      if whereAtX < 0 then
        whereAtX := 0;
      if whereAtX > JvPreviewControl1.Options.Cols-1 then
         whereAtX := JvPreviewControl1.Options.Cols-1;
    pageHeight := ((JvPreviewControl1.DeviceInfo.PageHeight+JvPreviewControl1.Options.VertSpacing) div 100)*JvPreviewControl1.Options.Scale;
    pageHeight := pageHeight div (JvPreviewControl1.DeviceInfo.LogPixelsY div Screen.PixelsPerInch);
    pagesHeights := (pageHeight *JvPreviewControl1.VisibleRows );
    heightOffset := (JvPreviewControl1.ClientHeight-pagesHeights) div 2;
    whereAtY := ((Y-heightOffset) div pageHeight)*JvPreviewControl1.VisibleRows;
      if whereAtY < 0 then
        whereAtY := 0;
      if whereAtY > (JvPreviewControl1.VisibleRows * (JvPreviewControl1.Options.Cols-1)) then
        whereAtY := (JvPreviewControl1.VisibleRows * (JvPreviewControl1.Options.Cols-1));
    end;
  JvPreviewControl1.SelectedPage := (JvPreviewControl1.TopRow*JvPreviewControl1.Options.Cols) + whereAtX + whereAtY;
    //selectedPage start base 0; PageCount start base 1
    if JvPreviewControl1.SelectedPage >= JvPreviewControl1.PageCount then
      JvPreviewControl1.SelectedPage := JvPreviewControl1.PageCount-1;
  end;
PageIndexLabel.Caption := IntToStr(JvPreviewControl1.SelectedPage+1);
PageCountLabel.Left := PageIndexLabel.Width + 10;
end;

Copyright: Kenneth Todd - Mozilla Public License

//tried and tested 10 different size files, no problems.

Have used your print preview in a freeware text-to-speech editor/word processor for the dyslexia suffer.
Additional InformationQuestion:
  Is there a way to link to a TJvRichEdit as I have to use the original TRichEdit as an interface:

tempStream := TMemoryStream.Create;
Editor.Lines.SaveToStream(tempStream);//Editor = TJvRichEdit
tempStream.Position := 0;
PrintPreviewForm.RichEdit1.Lines.LoadFromStream(tempStream);
tempStream.Free;

Which loose's a lot of the extra functionality such as graphics?


ThankYou
    Kenneth
TagsNo tags attached.

Activities

user72

2004-08-07 02:11

  ~0004957

Thanks for the code. I'll see how to incorporate it.

> Is there a way to link to a TJvRichEdit
> as I have to use the original TRichEdit as an interface

Maybe I misunderstand, but there is a TJvPreviewRenderJvRichEdit component for that purpose.

user72

2004-08-07 14:23

  ~0004965

I tried the code you submitted but it didn't quite work in all circumstances. It did inspire me to implement the functionality, though, so I basically used the same code as is used to draw the pages.

Add this implementation to the existing ItemAtPos (now it just returns -1):

function TJvCustomPreviewControl.ItemAtPos(Pos: TPoint; Existing: Boolean): Integer;
var
  APageRect: TRect;
  ARow, ACol, AOffsetX, AOffsetY: Integer;
begin
  Result := -1;
  // initial top/left offset
  AOffsetX := -FScrollPos.X + Max((ClientWidth - ((FPageWidth + Integer(Options.HorzSpacing)) * TotalCols)) div 2, FOptions.HorzSpacing);
  if IsPageMode then
    AOffsetY := -FScrollPos.Y + Max((ClientHeight - ((FPageHeight + Integer(Options.VertSpacing)) * VisibleRows)) div 2,
      FOptions.VertSpacing)
  else
    AOffsetY := -FScrollPos.Y + Integer(Options.VertSpacing);
  ARow := 0;
  // walk the pages, comparing as we go along
  while true do
  begin
    APageRect := FPreviewRect;
    OffsetRect(APageRect, AOffsetX, AOffsetY + (FPageHeight + Integer(Options.VertSpacing)) * ARow);
    for ACol := 0 to TotalCols - 1 do
    begin
      if PtInRect(APageRect, Pos) then
      begin
        Result := ARow * TotalCols + ACol;
        if Existing and (Result >= PageCount) then
          Result := -1;
        Exit;
      end;
      OffsetRect(APageRect, FPageWidth + Integer(Options.HorzSpacing), 0);
    end;
    Inc(ARow);
    if (APageRect.Left > ClientWidth) or (APageRect.Top > ClientHeight) then
      Exit;
  end;
end;

and then add the following to MouseDown:

procedure TJvCustomPreviewControl.MouseDown(Button: TMouseButton;
  Shift: TShiftState; X, Y: Integer);
var
  i: integer;
begin
  inherited MouseDown(Button, Shift, X, Y);
  if CanFocus then
    SetFocus;
  i := ItemAtPos(Point(X, Y), True);
  if i >= 0 then
    SelectedPage := i;
end;

> Is there a way to link to a TJvRichEdit as
> I have to use the original TRichEdit as an interface:
I think I know now what you mean. No, you can't "coerce" a JvRichEdit into a RichEdit. You will have to change the previewer form to use a JvRichEdit if you need this functionality.

user72

2004-08-08 08:54

  ~0004969

I've just comitted an updated previewer to CVS. Try it out and post here if you have any problems.

Issue History

Date Modified Username Field Change
2004-08-06 14:27 anonymous New Issue
2004-08-07 02:11 user72 Note Added: 0004957
2004-08-07 14:18 user72 Status new => assigned
2004-08-07 14:18 user72 Assigned To => user72
2004-08-07 14:23 user72 Note Added: 0004965
2004-08-08 08:54 user72 Status assigned => resolved
2004-08-08 08:54 user72 Resolution open => fixed
2004-08-08 08:54 user72 Note Added: 0004969