1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259
|
{
This file is part of the Free Component Library.
Copyright (c) 2016 Michael Van Canneyt, member of the Free Pascal development team
FPImage form export - render fpReport to a form.
Simple version, no design time
See the file COPYING.FPC, included in this distribution,
for details about the copyright.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
**********************************************************************}
unit fpreportformexport;
{$mode objfpc}{$H+}
{$DEFINE USEPAINTBOX}
interface
uses
Classes, SysUtils, fpreport, forms, comctrls, extctrls, fpreportlclexport, controls, actnlist;
Type
{ TCustomFPreportPreviewForm }
TCustomFPreportPreviewForm = Class(TForm)
private
FReport: TFPCustomReport;
FReportPages: TFPList;
Protected
function GetEnableHyperLinks: Boolean ; virtual;
procedure SetEnableHyperLinks(AValue: Boolean); virtual;
procedure SetReport(AValue: TFPCustomReport); virtual;
Property ReportPages : TFPList Read FReportPages;
Class Function LoadFromResource : Boolean; virtual;
Public
Property Report : TFPCustomReport Read FReport Write SetReport;
Published
Property EnableHyperLinks : Boolean Read GetEnableHyperLinks Write SetEnableHyperLinks;
end;
TCustomFPreportPreviewFormClass = Class of TCustomFPreportPreviewForm;
{ TFPreportPreviewForm }
// This is a default, minimalistic implementation. It is shown by default.
// For a better implementation, add the fpreportpreview form to your project uses clause.
TFPreportPreviewForm = Class(TCustomFPreportPreviewForm)
Private
FToolBar : TToolbar;
FActions : TActionList;
{$IFDEF USEPAINTBOX}
FPaintBox : TPaintBox;
{$ELSE}
FPaintBox : TPanel;
{$ENDIF}
FRender : TFPReportExportCanvas;
FAClose : TAction;
FBClose : TToolButton;
FAPrevious : TAction;
FBPrevious : TToolButton;
FANext : TAction;
FBNext : TToolButton;
Protected
procedure SetReport(AValue: TFPCustomReport); override;
Public
Constructor CreateNew(AOwner: TComponent; Num: Integer=0); override;
procedure DoCloseAction(Sender: TObject);
procedure DoNextAction(Sender: TObject);
procedure DoPaintReport(Sender: TObject);
procedure DoPreviousAction(Sender: TObject);
procedure UpdateNextAction(Sender: TObject);
procedure UpdatePreviousAction(Sender: TObject);
end;
{ TFPreportPreviewExport }
TFPreportPreviewExport = Class(TFPReportExporter)
Protected
procedure DoExecute(const ARTObjects: TFPList); override;
Public
Class Var
DefaultPreviewFormClass : TCustomFPreportPreviewFormClass;
Class Function Name : String; override;
Class Function Description : String; override;
end;
implementation
{ TCustomFPreportPreviewForm }
procedure TCustomFPreportPreviewForm.SetEnableHyperLinks(AValue: Boolean);
begin
//
end;
function TCustomFPreportPreviewForm.GetEnableHyperLinks: Boolean;
begin
Result:=False;
end;
procedure TCustomFPreportPreviewForm.SetReport(AValue: TFPCustomReport);
begin
if FReport=AValue then Exit;
FReport:=AValue;
end;
class function TCustomFPreportPreviewForm.LoadFromResource: Boolean;
begin
Result:=False;
end;
{ TFPreportPreviewExport }
procedure TFPreportPreviewExport.DoExecute(const ARTObjects: TFPList);
Var
R : TCustomFPreportPreviewFormClass;
F : TCustomFPreportPreviewForm;
begin
R:=Self.DefaultPreviewFormClass;
if R=Nil then
R:=TFPreportPreviewForm;
If R.LoadFromResource then
F:=R.Create(Self)
else
F:=R.CreateNew(Self,0);
With F do
try
Report:=Self.Report;
FReportPages:=ARTObjects;
ShowModal;
finally
Free;
end;
end;
class function TFPreportPreviewExport.Name: String;
begin
Result:='Preview';
end;
class function TFPreportPreviewExport.Description: String;
begin
Result:='Preview on screen';
end;
{ TFPreportPreviewForm }
procedure TFPreportPreviewForm.SetReport(AValue: TFPCustomReport);
begin
inherited SetReport(AValue);
FRender.Report:=AValue;
If Assigned(AValue) then
FRender.Execute;
end;
constructor TFPreportPreviewForm.CreateNew(AOwner: TComponent; Num: Integer);
Var
ButtonLeft : Integer;
Function CreateAction(Const ACaption : STring; AImageIndex : Integer; AOnExecute, AOnUpdate : TNotifyEvent) : TAction;
begin
Result:=Taction.Create(Self);
Result.ActionList:=FActions;
Result.Caption:=ACaption;
Result.OnExecute:=AOnExecute;
Result.OnUpdate:=AOnUpdate;
end;
Function CreateButton(AAction : TAction) : TToolbutton;
begin
Result:=TToolButton.Create(Self);
Result.Parent:=FToolbar;
Result.Top:=0;
Result.Left:=ButtonLeft;
Result.Width:=32;
Result.Height:=FToolbar.ButtonHeight;
Result.Caption:=IntToStr(ButtonLeft);
Result.Action:=AAction;
ButtonLeft:=ButtonLeft+Result.Width+1;
end;
begin
inherited CreateNew(AOwner, Num);
ButtonLeft:=0;
WindowState:=wsMaximized;
FActions:=TActionList.Create(Self);
FToolBar:=TToolbar.Create(Self);
FToolbar.ShowCaptions:=True;
FToolBar.Height:=24;
FToolbar.ButtonHeight:=22;
FToolBar.Parent:=Self;
FToolBar.Align:=alTop;
FToolBar.Flat:=True;
FAClose:=CreateAction('Close',0,@DoCloseAction,Nil);
FBClose:=CreateButton(FAClose);
FAPrevious:=CreateAction('Previous',1,@DoPreviousAction,@UpdatePreviousAction);
FBPrevious:=CreateButton(FAPrevious);
FANext:=CreateAction('Next',1,@DoNextAction,@UpdateNextAction);
FBNext:=CreateButton(FANext);
{$IFDEF USEPAINTBOX}
FPaintBox:=TPaintBox.Create(Self);
{$ELSE}
FPaintBox:=TPanel.Create(Self);
FPaintBox.BevelInner:=bvLowered;
FPaintBox.Caption:='';
{$ENDIF}
FPaintBox.Parent:=Self;
FPaintBox.Align:=alClient;
FPaintBox.OnPaint:=@DoPaintReport;
FRender:=TFPReportExportCanvas.Create(Self);
FRender.Canvas:=FPaintBox.Canvas;
Caption:='fpReport preview';
end;
procedure TFPreportPreviewForm.DoCloseAction(Sender: TObject);
begin
Close;
end;
procedure TFPreportPreviewForm.DoNextAction(Sender: TObject);
begin
FRender.PageIndex:=FRender.PageIndex+1
end;
procedure TFPreportPreviewForm.DoPaintReport(Sender: TObject);
begin
FRender.Execute;
end;
procedure TFPreportPreviewForm.DoPreviousAction(Sender: TObject);
begin
FRender.PageIndex:=FRender.PageIndex-1;
end;
procedure TFPreportPreviewForm.UpdateNextAction(Sender: TObject);
begin
(Sender as TAction).Enabled:=(FRender.PageIndex<ReportPages.Count-1);
end;
procedure TFPreportPreviewForm.UpdatePreviousAction(Sender: TObject);
begin
(Sender as TAction).Enabled:=(FRender.PageIndex>0);
end;
initialization
TFPreportPreviewExport.RegisterExporter;
end.
|