-
Notifications
You must be signed in to change notification settings - Fork 14
/
rpclxreport.pas
382 lines (349 loc) · 9.35 KB
/
rpclxreport.pas
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
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
{*******************************************************}
{ }
{ Report Manager }
{ }
{ rpclxreport }
{ Report component for clx and vcl applications }
{ supports drivers qt and gdi in Windows }
{ }
{ }
{ Copyright (c) 1994-2019 Toni Martir }
{ toni@reportman.es }
{ }
{ This file is under the MPL license }
{ If you enhace this file you must provide }
{ source code }
{ }
{ }
{*******************************************************}
unit rpclxreport;
interface
{$I rpconf.inc}
uses Classes,Sysutils,rpreport,
rpmdconsts,rpcompobase,rptypes,rpmetafile,rptextdriver,rppreviewcontrolclx,
QPrinters,rpqtdriver,rppreview,rprfparams,rpgraphutils,
{$IFDEF VCLANDCLX}
rpgdidriver,Printers,Dialogs,rprfvparams,rpvpreview,rpfmainmetaviewvcl,
rppagesetupvcl,
{$ENDIF}
{$IFDEF LINUX}
Libc,
{$ENDIF}
rpalias,rpfmainmetaview,rppagesetup,rppdfdriver;
type
// rpDriverGDI is ignored in Linux
TRpPrintDriver=(rpDriverQt,rpDriverGDI);
TCLXReport=class(TCBaseReport)
private
FUseSystemPrintDialog:boolean;
FDriver:TRpPrintDriver;
{$IFDEF LINUX}
usekprinter:Boolean;
{$ENDIF}
protected
procedure InternalExecuteRemote(metafile:TRpMetafileReport);override;
public
function Execute:boolean;override;
procedure PrinterSetup;override;
function ShowParams:boolean;override;
procedure SaveToPDF(filename:string;compressed:boolean=false);
procedure SaveToMetafile(filename:string);
procedure SaveToText(filename:string;textdriver:String='');override;
constructor Create(AOwner:TComponent);override;
function PrintRange(frompage:integer;topage:integer;
copies:integer;collate:boolean):boolean;override;
procedure PageSetup;
published
property Filename;
property Preview;
property ShowProgress;
property Title;
property ShowPrintDialog;
property AliasList;
property Language;
property UseSystemPrintDialog:Boolean read
FUseSystemPrintDialog write FUseSystemPrintDialog default true;
property Driver:TRpPrintDriver read FDriver write FDriver
default rpDriverGDI;
end;
implementation
uses rpprintdia;
constructor TCLXReport.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
FUseSystemPrintDialog:=true;
FDriver:=rpDriverGDI;
{$IFDEF LINUX}
usekprinter:=GetEnvironmentVariable('REPMANUSEKPRINTER')='true';
{$ENDIF}
end;
procedure TCLXReport.PrinterSetup;
{$IFDEF VCLANDCLX}
var
dia:TPrinterSetupDialog;
{$ENDIF}
begin
{$IFDEF VCLANDCLX}
if FDriver=rpDriverGDI then
begin
dia:=TPrinterSetupDialog.Create(nil);
try
dia.Execute;
finally
dia.free;
end;
exit;
end;
{$ENDIF}
QPrinters.Printer.ExecuteSetup;
end;
function TCLXReport.ShowParams:boolean;
begin
CheckLoaded;
{$IFDEF VCLANDCLX}
if FDriver=rpDriverGDI then
begin
Result:=rprfvparams.ShowUserParams(report.params);
exit;
end;
{$ENDIF}
Result:=rprfparams.ShowUserParams(report.params);
end;
function TCLXReport.Execute:boolean;
var
allpages,collate,modified:boolean;
frompage,topage,copies:integer;
dook:boolean;
{$IFDEF LINUX}
metafile:TRpMEtafileReport;
memstream:TMemoryStream;
{$ENDIF}
prcontrol:TRpPreviewControlCLX;
begin
inherited Execute;
if Preview then
begin
{$IFDEF VCLANDCLX}
if FDriver=rpDriverGDI then
begin
Result:=rpvpreview.ShowPreview(report,Title,modified);
exit;
end;
{$ENDIF}
prcontrol:=TRpPreviewControlCLX.Create(nil);
try
prcontrol.Report:=Report;
Result:=ShowPreview(prcontrol,Title,FUseSystemPrintDialog);
finally
prcontrol.free;
end;
end
else
begin
allpages:=true;
collate:=report.CollateCopies;
frompage:=1; topage:=999999;
copies:=report.Copies;
{$IFDEF HORZPAPERBUG}
if report.PageOrientation=rpOrientationPortrait then
begin
printer.Orientation:=poPortrait;
end
else
if report.PageOrientation=rpOrientationLandscape then
begin
printer.Orientation:=poLandscape;
end;
{$ENDIF}
if ShowPrintDialog then
begin
{$IFDEF VCLANDCLX}
if FDriver=rpDriverGDI then
begin
if rpgdidriver.DoShowPrintDialog(allpages,frompage,topage,copies,collate) then
begin
Result:=rpgdidriver.PrintReport(report,Title,Showprogress,allpages,frompage,
topage,copies,collate);
end
else
Result:=false;
exit;
end;
{$ENDIF}
{$IFDEF LINUX}
if usekprinter then
begin
metafile:=TRpMetafileReport.Create(nil);
try
memstream:=tmemoryStream.Create;
try
rppdfdriver.PrintReportMetafileStream(report,'',false,true,1,9999,1,memstream,false,false);
memstream.Seek(0,soFromBeginning);
metafile.LoadFromStream(memstream);
finally
memstream.free;
end;
// Use kprinter to print the file
PrintMetafileUsingKPrinter(metafile);
finally
metafile.free;
end;
end
else
{$ENDIF}
begin
if FUseSystemPrintDialog then
dook:=rpqtdriver.DoShowPrintDialog(allpages,frompage,topage,copies,collate)
else
dook:=rpprintdia.DoShowPrintDialog(allpages,frompage,topage,copies,collate);
if dook then
begin
Result:=rpqtdriver.PrintReport(report,Title,Showprogress,allpages,frompage,
topage,copies,collate);
end
else
Result:=false;
end;
end
else
begin
{$IFDEF VCLANDCLX}
if FDriver=rpDriverGDI then
begin
Result:=rpgdidriver.PrintReport(report,Title,Showprogress,true,1,
9999999,report.copies,report.collatecopies);
exit;
end;
{$ENDIF}
Result:=rpqtdriver.PrintReport(report,Title,Showprogress,true,1,
9999999,report.copies,report.collatecopies);
end;
end;
end;
procedure TCLXReport.SaveToPDF(filename:string;compressed:boolean=false);
begin
CheckLoaded;
{$IFDEF VCLANDCLX}
if FDriver=rpDriverGDI then
begin
rpgdidriver.ExportReportToPDF(report,filename,ShowProgress,true,1,999999,1,
false,filename,compressed,false);
exit;
end;
{$ENDIF}
rpqtdriver.ExportReportToPDF(report,filename,ShowProgress,true,1,999999,1,
false,filename,compressed,false)
end;
procedure TCLXReport.SaveToMetafile(filename:string);
begin
CheckLoaded;
{$IFDEF VCLANDCLX}
if FDriver=rpDriverGDI then
begin
rpgdidriver.ExportReportToPDF(report,filename,ShowProgress,true,1,999999,1,
false,filename,false,true);
exit;
end;
{$ENDIF}
rpqtdriver.ExportReportToPDF(report,filename,ShowProgress,true,1,999999,1,
false,filename,false,true)
end;
function TCLXReport.PrintRange(frompage:integer;topage:integer;
copies:integer;collate:boolean):boolean;
begin
{$IFDEF VCLANDCLX}
if FDriver=rpDriverGDI then
begin
Result:=rpgdidriver.PrintReport(Report,Title,ShowProgress,false,
frompage,topage,copies,collate);
exit;
end;
{$ENDIF}
Result:=rpqtdriver.PrintReport(Report,Title,ShowProgress,false,
frompage,topage,copies,collate);
end;
procedure TCLXReport.InternalExecuteRemote(metafile:TRpMetafileReport);
var
allpages,collate,dook:boolean;
frompage,topage,copies:integer;
begin
inherited InternalExecuteRemote(metafile);
if Preview then
begin
{$IFDEF VCLANDCLX}
if FDriver=rpDriverGDI then
begin
rpfmainmetaviewvcl.PreviewMetafile(metafile,nil,true,true);
exit;
end;
{$ENDIF}
rpfmainmetaview.PreviewMetafile(metafile,nil,true,true);
exit;
end;
allpages:=true;
collate:=false;
frompage:=1; topage:=999999;
copies:=1;
{$IFDEF HORZPAPERBUG}
if metafile.Orientation=rpOrientationPortrait then
begin
printer.Orientation:=poPortrait;
end
else
if metafile.Orientation=rpOrientationLandscape then
begin
printer.Orientation:=poLandscape;
end;
{$ENDIF}
if ShowPrintDialog then
begin
{$IFDEF VCLANDCLX}
if FDriver=rpDriverGDI then
begin
if rpgdidriver.DoShowPrintDialog(allpages,frompage,topage,copies,collate) then
begin
rpgdidriver.PrintMetafile(metafile,Title,ShowProgress,allpages,frompage,topage,copies,collate,GetDeviceFontsOption(metafile.PrinterSelect),metafile.PrinterSelect)
end;
exit;
end;
{$ENDIF}
if FUseSystemPrintDialog then
dook:=rpqtdriver.DoShowPrintDialog(allpages,frompage,topage,copies,collate)
else
dook:=rpprintdia.DoShowPrintDialog(allpages,frompage,topage,copies,collate);
if dook then
begin
rpqtdriver.PrintMetafile(metafile,Title,ShowProgress,allpages,frompage,topage,copies,collate,metafile.PrinterSelect)
end;
exit;
end
else
begin
{$IFDEF VCLANDCLX}
if FDriver=rpDriverGDI then
begin
rpgdidriver.PrintMetafile(metafile,Title,ShowProgress,allpages,frompage,topage,copies,collate,GetDeviceFontsOption(metafile.PrinterSelect),metafile.PrinterSelect);
exit;
end;
{$ENDIF}
rpqtdriver.PrintReport(report,Title,Showprogress,true,1,
9999999,report.copies,report.collatecopies);
end;
end;
procedure TCLXReport.SaveToText(filename:string;textdriver:String='');
begin
rptextdriver.PrintReportToText(report,'',false,true,1,999,
1,filename,true,true,textdriver);
end;
procedure TCLXReport.PageSetup;
begin
{$IFDEF VCLANDCLX}
if FDriver=rpDriverGDI then
begin
rppagesetupvcl.ExecutePageSetup(Report);
exit;
end;
{$ENDIF}
rppagesetup.ExecutePageSetup(Report);
end;
end.