📄 frxpreviewpages.pas
字号:
Inc(PagesPrinted);
ClearPageCache;
end;
end;
begin
Printer := frxPrinters.Printer;
Report.Terminated := False;
Report.InternalOnProgressStart(ptPrinting);
if Report.ReportOptions.Name <> '' then
Printer.Title := Report.ReportOptions.Name else
Printer.Title := Report.FileName;
if Report.PrintOptions.Copies <= 0 then
Report.PrintOptions.Copies := 1;
MaxCount := Count;
PagePrinted := False;
LastDuplexMode := dmNone;
if Report.PrintOptions.Collate then
for i := 0 to Report.PrintOptions.Copies - 1 do
begin
ACopyNo := i + 1;
case Report.PrintOptions.PrintMode of
pmDefault, pmScale:
PrintPages;
pmSplit:
PrintSplittedPages;
pmJoin:
PrintJoinedPages;
end;
if (LastDuplexMode in [dmVertical, dmHorizontal]) and (PagesPrinted mod 2 <> 0) then
begin
Printer.BeginPage;
Printer.EndPage;
end;
if Report.Terminated then break;
end
else
begin
case Report.PrintOptions.PrintMode of
pmDefault, pmScale:
PrintPages;
pmSplit:
PrintSplittedPages;
pmJoin:
PrintJoinedPages;
end;
end;
if PagePrinted then
Printer.EndDoc;
Report.InternalOnProgressStop(ptPrinting);
end;
begin
Result := True;
if not frxPrinters.HasPhysicalPrinters then
begin
frxErrorMsg(frxResources.Get('clNoPrinters'));
Result := False;
Exit;
end;
FPrintScale := 1;
if Report.DotMatrixReport and (frxDotMatrixExport <> nil) then
begin
Report.SelectPrinter;
frxDotMatrixExport.ShowDialog := Report.PrintOptions.ShowDialog;
frxDotMatrixExport.PageNumbers := Report.PrintOptions.PageNumbers;
Result := Export(frxDotMatrixExport);
Exit;
end;
SavePrintOptions := TfrxPrintOptions.Create;
SavePrintOptions.Assign(Report.PrintOptions);
DuplexMode := dmNone;
Report.SelectPrinter;
if Report.PrintOptions.ShowDialog then
with TfrxPrintDialog.Create(Application) do
begin
AReport := Report;
ADuplexMode := DuplexMode;
ShowModal;
if ModalResult = mrOk then
begin
DuplexMode := ADuplexMode;
Free;
end
else
begin
Free;
FCopyNo := 0;
Result := False;
SavePrintOptions.Free;
Exit;
end;
end;
if Report.PrintOptions.PrintMode <> pmDefault then
begin
if Report.PrintOptions.PrintOnSheet <> 256 then
frxPrinters.Printer.SetViewParams(Report.PrintOptions.PrintOnSheet, 0, 0, poPortrait)
else
frxPrinters.Printer.SetViewParams(Report.PrintOptions.PrintOnSheet, frxPrinters.Printer.PaperWidth,
frxPrinters.Printer.PaperHeight, poPortrait);
SheetWidth := frxPrinters.Printer.PaperWidth;
SheetHeight := frxPrinters.Printer.PaperHeight;
SplitAddX := 3;
SplitAddY := 3;
end;
if Assigned(Report.OnPrintReport) then
Report.OnPrintReport(Report);
Report.DoNotifyEvent(Report, Report.OnReportPrint, not Report.EngineOptions.DestroyForms);
if Report.Preview <> nil then
begin
Report.Preview.Lock;
Report.Preview.Refresh;
end;
pgList := TStringList.Create;
try
if frxPrinters.Printer.Initialized then
begin
frxParsePageNumbers(Report.PrintOptions.PageNumbers, pgList, Count);
ClearPageCache;
DoPrint;
end
else frxErrorMsg('Printer selected is not valid');
finally
if Assigned(Report.OnAfterPrintReport) then
Report.OnAfterPrintReport(Report);
FCopyNo := 0;
Report.PrintOptions.Assign(SavePrintOptions);
SavePrintOptions.Free;
pgList.Free;
end;
end;
function TfrxPreviewPages.Export(Filter: TfrxCustomExportFilter): Boolean;
var
pgList: TStringList;
tempBMP: TBitmap;
procedure ExportPage(Index: Integer);
var
i, j: Integer;
Page: TfrxReportPage;
c: TfrxComponent;
p: TfrxPictureView;
procedure ExportObject(c: TfrxComponent);
begin
if c is TfrxCustomMemoView then
begin
{ set up font if Highlight is active }
if TfrxCustomMemoView(c).Highlight.Active then
TfrxCustomMemoView(c).Font.Assign(TfrxCustomMemoView(c).Highlight.Font);
{ needed for TOTALPAGES, COPYNAME macros }
THackMemoView(c).FTotalPages := Count;
THackMemoView(c).FCopyNo := 1;
THackMemoView(c).ExtractMacros;
{ needed if memo has AutoWidth and Align properties }
if THackMemoView(c).AutoWidth then
THackMemoView(c).Draw(tempBMP.Canvas, 1, 1, 0, 0);
end;
Filter.ExportObject(c);
end;
begin
if Index >= Count then Exit;
if (pgList.Count <> 0) and (pgList.IndexOf(IntToStr(Index + 1)) = -1) then Exit;
Page := GetPage(Index);
if Page = nil then Exit;
if Filter.ShowProgress then
Report.InternalOnProgress(ptExporting, Index + 1);
Filter.StartPage(Page, Index);
try
{ set the offset of the page objects }
if Page.MirrorMargins and (Index mod 2 = 1) then
Page.Left := Page.RightMargin * fr01cm else
Page.Left := Page.LeftMargin * fr01cm;
Page.Top := Page.TopMargin * fr01cm;
{ export the page background picture and frame }
p := TfrxPictureView.Create(nil);
p.Name := '_pagebackground';
p.Color := Page.Color;
p.Frame.Assign(Page.Frame);
p.Picture.Assign(Page.BackPicture);
p.Stretched := True;
p.KeepAspectRatio := False;
try
p.SetBounds(Page.Left, Page.Top,
Page.Width - (Page.LeftMargin + Page.RightMargin) * fr01cm,
Page.Height - (Page.TopMargin + Page.BottomMargin) * fr01cm);
Filter.ExportObject(p);
finally
p.Free;
end;
for i := 0 to Page.Objects.Count - 1 do
begin
c := Page.Objects[i];
if c is TfrxBand then
begin
if c is TfrxPageHeader then
begin
{ suppress a header }
if Filter.SuppressPageHeadersFooters and (Index <> 0) then continue;
end;
if c is TfrxPageFooter then
begin
{ suppress a footer }
if Filter.SuppressPageHeadersFooters and (Index <> Count - 1) then continue;
end;
end;
ExportObject(c);
if c.Objects.Count <> 0 then
for j := 0 to c.Objects.Count - 1 do
ExportObject(c.Objects[j]);
end;
finally
Filter.FinishPage(Page, Index);
end;
if Report.Preview = nil then
ClearPageCache
else
begin
Page.Left := 0;
Page.Top := 0;
end;
end;
procedure DoExport;
var
i: Integer;
begin
if Filter.Start then
try
if Report.Preview <> nil then
begin
Report.Preview.Lock;
Report.Preview.Refresh;
end;
if Filter.ShowProgress then
Report.InternalOnProgressStart(ptExporting);
for i := 0 to Count - 1 do
begin
ExportPage(i);
if Report.Terminated then break;
Application.ProcessMessages;
end;
finally
if Report.Preview <> nil then
begin
TfrxPreview(Report.Preview).HideMessage;
Report.Preview.Refresh;
end;
if Filter.ShowProgress then
Report.InternalOnProgressStop(ptExporting);
Filter.Finish;
end;
end;
begin
Result := False;
FCopyNo := 0;
if Filter = nil then Exit;
Filter.Report := Report;
if (Filter.ShowDialog and (Filter.ShowModal <> mrOk)) then
Exit;
if Filter.CurPage then
if Report.Preview <> nil then
Filter.PageNumbers := IntToStr(CurPreviewPage) else
Filter.PageNumbers := '1';
Result := True;
Report.Terminated := False;
pgList := TStringList.Create;
tempBMP := TBitmap.Create;
try
frxParsePageNumbers(Filter.PageNumbers, pgList, Count);
if Filter = frxDotMatrixExport then
if Assigned(Report.OnPrintReport) then
Report.OnPrintReport(Report);
try
DoExport;
except
on e: Exception do
begin
Result := False;
Report.Errors.Text := e.Message;
frxCommonErrorHandler(Report, frxResources.Get('clErrors') + #13#10 + Report.Errors.Text);
end;
end;
if Filter = frxDotMatrixExport then
if Assigned(Report.OnAfterPrintReport) then
Report.OnAfterPrintReport(Report);
finally
pgList.Free;
tempBMP.Free;
end;
end;
procedure TfrxPreviewPages.ObjectOver(Index: Integer; X, Y: Integer;
Button: TMouseButton; Shift: TShiftState; Scale, OffsetX, OffsetY: Extended;
Click: Boolean; var Cursor: TCursor; DBClick: Boolean);
var
Page: TfrxReportPage;
c: TfrxComponent;
l: TList;
i: Integer;
Flag: Boolean;
v: TfrxView;
drill: TfrxGroupHeader;
drillName: String;
function MouseInView(c: TfrxComponent): Boolean;
var
r: TRect;
begin
with c do
r := Rect(Round(AbsLeft * Scale), Round(AbsTop * Scale),
Round((AbsLeft + Width) * Scale),
Round((AbsTop + Height) * Scale));
OffsetRect(r, Round(OffsetX), Round(OffsetY));
Result := PtInRect(r, Point(X, Y));
end;
procedure SetToAnchor(const Text: String);
var
Item: TfrxXMLItem;
PageN, Top: Integer;
begin
Item := FindAnchor(Text);
if Item <> nil then
begin
PageN := StrToInt(String(Item.Prop['page']));
Top := StrToInt(String(Item.Prop['top']));
TfrxPreview(Report.Preview).SetPosition(PageN + 1, Top);
end;
end;
begin
if (Index < 0) or (Index >= Count) or Engine.Running then Exit;
Page := GetPage(Index);
if Page = nil then Exit;
if Page.MirrorMargins and (Index mod 2 = 1) then
OffsetX := OffsetX + Page.RightMargin * fr01cm * Scale else
OffsetX := OffsetX + Page.LeftMargin * fr01cm * Scale;
OffsetY := OffsetY + Page.TopMargin * fr01cm * Scale;
Report.SetProgressMessage('');
Report.SetProgressMessage('', True);
Page := GetPage(Index); // get page again to ensure it was not cleared during export
if Page = nil then Exit;
drill := nil;
l := Page.AllObjects;
for i := l.Count - 1 downto 0 do
begin
c := l[i];
if (c is TfrxGroupHeader) and MouseInView(c) then
if TfrxGroupHeader(c).DrillDown then
begin
drill := TfrxGroupHeader(c);
break;
end;
if (c is TfrxView) and MouseInView(c) then
begin
v := TfrxView(c);
if (v.Parent is TfrxGroupHeader) and TfrxGroupHeader(v.Parent).DrillDown then
begin
drill := TfrxGroupHeader(v.Parent);
break;
end;
if v.Cursor <> crDefault then
Cursor := v.Cursor;
if v.URL <> '' then
begin
Report.SetProgressMessage(v.URL);
if v.Cursor = crDefault then
Cursor := crHandPoint;
end;
if (v.Hint <> '') and (v.ShowHint) and (Report.Preview.UseReportHints) then
begin
Report.SetProgressMessage(GetLongHint(v.Hint), True);
Report.Preview.Hint := GetShortHint(v.Hint);
Report.Preview.ShowHint := True;
end;
if Click then
begin
if v.URL <> '' then
if Pos('@', v.URL) = 1 then
TfrxPreview(Report.Preview).PageNo := StrToInt(Copy(v.URL, 2, 255))
else if Pos('#', v.URL) = 1 then
SetToAnchor(Copy(v.URL, 2, 255))
else
ShellExecute(GetDesktopWindow, nil, PChar(v.URL), nil, nil, sw_ShowNormal);
Flag := False;
if DBClick then
Report.DoPreviewClick(v, Button, Shift, Flag, True)
else
Report.DoPreviewClick(v, Button, Shift, Flag);
if Flag then
begin
ModifyPage(Index, Page);
Report.Preview.Invalidate;
end;
end
else if Assigned(Report.OnMouseOverObject) then
Report.OnMouseOverObject(v);
break;
end
else if c is TfrxView then
if (TfrxView(c).ShowHint) and (Report.Preview <> nil) and (Report.Preview.UseReportHints) then
Report.Preview.ShowHint := False;
end;
if drill <> nil then
begin
Cursor := crHandPoint;
if Click and (Button = mbLeft) then
begin
drillName := drill.Name + '.' + IntToStr(drill.Tag);
if Report.DrillState.IndexOf(drillName) = -1 then
Report.DrillState.Add(drillName)
else
Report.DrillState.Delete(Report.DrillState.IndexOf(drillName));
Report.Preview.RefreshReport;
end;
end;
end;
end.
//
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -