[go: up one dir, main page]

Menu

[r89]: / rpprintitem.pas  Maximize  Restore  History

Download this file

600 lines (523 with data), 16.8 kB

  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
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
{*******************************************************}
{ }
{ Report Manager }
{ }
{ Rpprintitem }
{ TRpPrintItem: Base class for printable comps }
{ TRpGenTextItem: Base class for text items }
{ }
{ }
{ Copyright (c) 1994-2002 Toni Martir }
{ toni@pala.com }
{ }
{ This file is under the MPL license }
{ If you enhace this file you must provide }
{ source code }
{ }
{ }
{*******************************************************}
unit rpprintitem;
interface
{$I rpconf.inc}
uses Sysutils,Classes,rptypes,
rpeval,
{$IFDEF MSWINDOWS}
Windows,
{$ENDIF}
{$IFDEF USEVARIANTS}
types,
{$ENDIF}
rpmdconsts,rpmetafile;
// Maximum width or height of a element, that is 60 inch
const
MAX_ELEMENT_WIDTH=86400;
MAX_ELEMENT_HEIGHT=86400;
type
TRpCommonComponent=class(TComponent)
private
FHeight:TRpTwips;
FWidth:TRpTwips;
FDoBeforePrint,FDoAfterPrint:widestring;
FPrintCondition:widestring;
FOnBeforePrint:TNotifyEvent;
FVisible:Boolean;
procedure SetWidth(Value:TRpTwips);
procedure SetHeight(Value:TRpTwips);
procedure WritePrintCondition(Writer:TWriter);
procedure ReadPrintCondition(Reader:TReader);
procedure WriteDoBeforePrint(Writer:TWriter);
procedure ReadDoBeforePrint(Reader:TReader);
procedure WriteDoAfterPrint(Writer:TWriter);
procedure ReadDoAfterPrint(Reader:TReader);
protected
procedure DefineProperties(Filer:TFiler);override;
function GetReport:TComponent;
procedure DoPrint(adriver:TRpPrintDriver;
aposx,aposy,newwidth,newheight:integer;metafile:TRpMetafileReport;
MaxExtent:TPoint;var PartialPrint:Boolean);virtual;
public
lastextent:TPoint;
oldowner:TComponent;
PrintWidth,PrintHeight:Integer;
constructor Create(AOwner:TComponent);override;
function GetExtension(adriver:TRpPrintDriver;MaxExtent:TPoint;forcepartial:boolean):TPoint;virtual;
function EvaluatePrintCondition:boolean;
procedure Print(adriver:TRpPrintDriver;aposx,aposy,newwidth,newheight:integer;metafile:TRpMetafileReport;
MaxExtent:TPoint;var PartialPrint:Boolean);
procedure SubReportChanged(newstate:TRpReportChanged;newgroup:string='');virtual;
property Report:TComponent read GetReport;
property OnBeforePrint:TNotifyEvent read FOnBeforePrint write FOnBeforePrint;
property Visible:Boolean read FVisible write FVisible;
property PrintCondition:widestring read FPrintCondition write FPrintCondition;
property DoBeforePrint:widestring read FDoBeforePrint write FDoBeforePrint;
property DoAfterPrint:widestring read FDoAfterPrint write FDoAfterPrint;
published
property Width:TRpTwips read FWidth write SetWidth;
property Height:TRpTwips read FHeight write SetHeight;
end;
TRpCommonPosComponent=class(TRpCommonComponent)
private
FPosY:TRpTwips;
FPosX:TRpTwips;
FAlign:TRpPosAlign;
public
PartialFlag:boolean;
function GetParent:TRpCommonComponent;
published
property PosX:TRpTwips read FPosX write FPosX;
property PosY:TRpTwips read FPosY write FPosY;
property Align:TRpPosAlign read FAlign write FAlign
default rpalnone;
end;
TRpCommonPosClass=class of TRpCommonPosComponent;
TRpCommonListItem=class(TCollectionItem)
private
FComponent:TRpCommonComponent;
procedure SetComponent(Value:TRpCommonComponent);
public
procedure Assign(Source:TPersistent);override;
published
property Component:TRpCommonComponent read FComponent write SetComponent;
end;
TRpCommonList=class(TCollection)
private
FSection:TComponent;
function GetItem(Index:Integer):TRpCommonListItem;
procedure SetItem(index:integer;Value:TRpCommonListItem);
public
function Add:TRpCommonListItem;
function Insert(index:integer):TRpCommonListItem;
function IndexOf(Value:TRpCommonComponent):integer;
property Items[index:integer]:TRpCommonListItem read GetItem write SetItem;default;
constructor Create(sec:TComponent);
end;
TRpGenTextComponent=class(TRpCommonPosComponent)
private
FWFontName:widestring;
FLFontName:widestring;
FFontSize:smallint;
FFontRotation:smallint;
FFontStyle:integer;
FFontColor:integer;
FBackColor:integer;
FTransparent:Boolean;
FCutText:Boolean;
FWordWrap:Boolean;
FWordBreak:Boolean;
FInterLine:Integer;
FAlignMent:integer;
FVAlignMent:integer;
FSingleLine:boolean;
FType1Font:TRpType1Font;
FBidiModes:TStrings;
FMultiPage:Boolean;
FPrintStep:TRpSelectFontStep;
procedure ReadWFontName(Reader:TReader);
procedure WriteWFontName(Writer:TWriter);
procedure ReadLFontName(Reader:TReader);
procedure WriteLFontName(Writer:TWriter);
procedure SetBidiModes(Value:TStrings);
function GetBidiMode:TRpBidiMode;
procedure SetBidiMode(Value:TRpBidiMode);
function GetRightToLeft:Boolean;
function GetPrintAlignMent:integer;
protected
procedure DefineProperties(Filer:TFiler);override;
public
constructor Create(AOwner:TComponent);override;
destructor Destroy;override;
property WFontName:widestring read FWFontName write FWFontName;
property LFontName:widestring read FLFontName write FLFontName;
property BidiMode:TRpBidiMode read GetBidiMode write SetBidiMode;
property RightToLeft:Boolean read GetRightToLeft;
property PrintAlignMent:Integer read GetPrintAlignMent;
published
property Type1Font:TRpType1Font read FType1Font write FType1Font;
property FontSize:smallint read FFontSize write FFontSize default 10;
property FontRotation:smallint read FFontRotation write FFontRotation default 0;
property FontStyle:integer read FFontStyle write FFontStyle default 0;
property FontColor:integer read FFontColor write FFontColor default 0;
property BackColor:integer read FBackColor write FBackColor default $FFFFFF;
property Transparent:Boolean read FTransparent write FTransparent default true;
property CutText:Boolean read FCutText write FCutText default false;
property Alignment:integer read FAlignment write FAlignment default 0;
property VAlignment:integer read FVAlignment write FVAlignment default 0;
property WordWrap:Boolean read FWordWrap write FWordWrap default false;
property WordBreak:Boolean read FWordBreak write FWordBreak default false;
property InterLine:Integer read FInterLine write FInterLine default 0;
property SingleLine:boolean read FSingleLine write FSingleLine default false;
property BidiModes:TStrings read FBidiModes write SetBidiModes;
property MultiPage:Boolean read FMultiPage write FMultiPage default false;
property PrintStep:TRpSelectFontStep read FPrintStep write FPrintStep
default rpselectsize;
end;
implementation
uses rpbasereport,rpsection,rpsubreport;
const
AlignmentFlags_AlignLeft = 1 { $1 };
AlignmentFlags_AlignRight = 2 { $2 };
constructor TRpCommonComponent.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
// The owner must be a report
if Assigned(AOwner) then
if (Not (AOwner is TRpBaseReport)) then
if (Not (AOwner is TRpSection)) then
Raise Exception.Create(SRpOnlyAReportOwner+classname);
FVisible:=True;
FHeight:=0;
FWidth:=0;
end;
procedure TRpCommonComponent.DefineProperties(Filer:TFiler);
begin
inherited;
Filer.DefineProperty('PrintCondition',ReadPrintCondition,WritePrintCondition,True);
Filer.DefineProperty('DoBeforePrint',ReadDoBeforePrint,WriteDoBeforePrint,True);
Filer.DefineProperty('DoAfterPrint',ReadDoAfterPrint,WriteDoAfterPrint,True);
end;
procedure TRpCommonComponent.WritePrintCondition(Writer:TWriter);
begin
WriteWideString(Writer, FPrintCondition);
end;
procedure TRpCommonComponent.ReadPrintCondition(Reader:TReader);
begin
FPrintCondition:=ReadWideString(Reader);
end;
procedure TRpCommonComponent.WriteDoBeforePrint(Writer:TWriter);
begin
WriteWideString(Writer, FDoBeforePrint);
end;
procedure TRpCommonComponent.ReadDoBeforePrint(Reader:TReader);
begin
FDoBeforePrint:=ReadWideString(Reader);
end;
procedure TRpCommonComponent.WriteDoAfterPrint(Writer:TWriter);
begin
WriteWideString(Writer, FDoAfterPrint);
end;
procedure TRpCommonComponent.ReadDoAfterPrint(Reader:TReader);
begin
FDoAfterPrint:=ReadWideString(Reader);
end;
procedure TRpCommonComponent.SetWidth(Value:TRpTwips);
begin
if Value>MAX_ELEMENT_WIDTH then
Value:=MAX_ELEMENT_WIDTH;
if Value<0 then
Value:=0;
FWidth:=Value;
end;
procedure TRpCommonComponent.SetHeight(Value:TRpTwips);
begin
if Value>MAX_ELEMENT_HEIGHT then
Value:=MAX_ELEMENT_HEIGHT;
if Value<0 then
Value:=0;
FHeight:=Value;
end;
function TRpCommonComponent.GetExtension(adriver:TRpPrintDriver;MaxExtent:TPoint;forcepartial:boolean):TPoint;
begin
Result.X:=Width;
Result.Y:=Height;
LastExtent:=Result;
end;
function TRpCommonComponent.EvaluatePrintCondition:boolean;
var
fevaluator:TRpEvaluator;
begin
if Length(Trim(PrintCondition))<1 then
begin
Result:=true;
exit;
end;
try
fevaluator:=TRpBaseREport(GetReport).Evaluator;
fevaluator.Expression:=PrintCondition;
fevaluator.Evaluate;
Result:=Boolean(fevaluator.EvalResult);
except
on E:Exception do
begin
Raise TRpReportException.Create(E.Message+':'+SRpSPrintCondition,self,SRpSPrintCondition);
end;
end;
end;
procedure TRpCommonComponent.DoPrint(adriver:TRpPrintDriver;aposx,aposy,newwidth,newheight:integer;metafile:TRpMetafileReport;
MaxExtent:TPoint;var PartialPrint:Boolean);
begin
// Executes OnBeforePrint
if Assigned(FOnBeforePrint) then
begin
OnBeforePrint(Self);
end;
if newwidth>=0 then
PrintWidth:=newwidth
else
PrintWidth:=Width;
if newheight>=0 then
PrintHeight:=newheight
else
PrintHeight:=Height;
PartialPrint:=False;
end;
function TRpCommonPosComponent.GetParent:TRpCommonComponent;
var
areport:TRpBaseReport;
sec:TRpSection;
subrep:TRpSubReport;
i,j,k:integer;
begin
Result:=nil;
areport:=TRpBaseReport(GetReport);
for i:=0 to areport.Subreports.Count-1 do
begin
subrep:=areport.Subreports.items[i].Subreport;
for j:=0 to subrep.Sections.Count-1 do
begin
sec:=subrep.Sections.Items[j].Section;
for k:=0 to sec.Components.Count-1 do
begin
if sec.Components.Items[k].Component=self then
begin
Result:=sec;
break;
end;
end;
if Assigned(Result) then
break;
end;
if Assigned(Result) then
break;
end;
end;
procedure TRpCommonComponent.Print(adriver:TRpPrintDriver;
aposx,aposy,newwidth,newheight:integer;metafile:TRpMetafileReport;
MaxExtent:TPoint;var PartialPrint:Boolean);
var
fevaluator:TRpEvaluator;
begin
if Not EvaluatePrintCondition then
exit;
// Do Before print and doafter print
if Length(FDoBeforePrint)>0 then
begin
try
fevaluator:=TRpBaseREport(GetReport).Evaluator;
fevaluator.Expression:=FDoBeforePrint;
fevaluator.Evaluate;
except
on E:Exception do
begin
Raise TRpReportException.Create(E.Message+':'+SRpSBeforePrint+' '+Name,self,SRpSBeforePrint);
end;
end;
end;
DoPrint(adriver,aposx,aposy,newwidth,newheight,metafile,MaxExtent,PartialPrint);
if Length(FDoAfterPrint)>0 then
begin
try
fevaluator:=TRpBaseREport(GetReport).Evaluator;
fevaluator.Expression:=FDoAfterPrint;
fevaluator.Evaluate;
except
on E:Exception do
begin
Raise TRpReportException.Create(E.Message+':'+SRpSAfterPrint+' '+Name,self,SRpSAfterPrint);
end;
end;
end;
end;
constructor TrpCOmmonList.Create(sec:TComponent);
begin
inherited Create(TRpCommonListItem);
FSection:=sec;
end;
procedure TRpCommonListItem.SetComponent(Value:TRpCommonComponent);
begin
FComponent:=Value;
Changed(False);
end;
function TRpCommonList.GetItem(Index:Integer):TRpCommonListItem;
begin
Result:=TRpCommonListItem(inherited GetItem(index));
end;
procedure TRpCommonList.SetItem(index:integer;Value:TRpCommonListItem);
begin
inherited SetItem(Index,Value);
end;
procedure TRpCommonListItem.Assign(Source:TPersistent);
begin
if Source is TRpCommonListItem then
begin
FComponent:=TRpCommonListItem(Source).FComponent;
end
else
inherited Assign(Source);
end;
function TRpCommonList.Add:TRpCommonListItem;
begin
Result:=TRpCommonListItem(inherited Add);
end;
function TRpCommonList.Insert(index:integer):TRpCommonListItem;
begin
Result:=TRpCommonListItem(inherited Insert(index));
end;
function TRpCommonList.IndexOf(Value:TRpCommonComponent):integer;
var
i:integer;
begin
Result:=-1;
i:=0;
While i<count do
begin
if items[i].FComponent=Value then
begin
Result:=i;
break;
end;
inc(i);
end;
end;
constructor TRpGenTextComponent.Create(AOwner:TComponent);
begin
inherited Create(AOwner);
FLFontName:='Helvetica';
FWFontName:='Arial';
FontSize:=10;
FontRotation:=0;
FontStyle:=0;
FontColor:=0;
FBackColor:=$FFFFFF;
FTransparent:=true;
FCutText:=false;
FBidiModes:=TStringList.Create;
end;
destructor TRpGenTextComponent.Destroy;
begin
FBidiModes.free;
inherited Destroy;
end;
function TRpGenTextComponent.GetPrintAlignMent:integer;
begin
// Inverse the alignment for BidiMode Full
Result:=FAlignMent;
if BidiMode=rpBidiFull then
begin
if (((FAlignMent AND AlignmentFlags_AlignLEFT)>0) or (FAlignMent=0)) then
Result:=(Result AND (NOT (AlignmentFlags_AlignLEFT)) OR AlignmentFlags_AlignRight)
else
if (FAlignMent AND AlignmentFlags_AlignRight)>0 then
Result:=(Result AND (NOT (AlignmentFlags_AlignRIGHT)) OR AlignmentFlags_AlignLEFT);
end;
end;
function TRpGenTextComponent.GetRightToLeft:Boolean;
begin
Result:=BidiMode<>rpBidiNo;
end;
function TRpGenTextComponent.GetBidiMode:TRpBidiMode;
var
langindex:integer;
begin
Result:=rpBidiNo;
langindex:=TRpBaseReport(GetReport).Language+1;
if langindex<0 then
langindex:=0;
if BidiModes.Count>langindex then
begin
if BidiModes.Strings[langindex]='BidiPartial' then
Result:=rpBidiPartial
else
if BidiModes.Strings[langindex]='BidiFull' then
Result:=rpBidiFull;
end;
end;
procedure TRpGenTextComponent.SetBidiMode(Value:TRpBidiMode);
var
langindex:integer;
begin
langindex:=TRpBaseReport(GetReport).Language+1;
if langindex<0 then
langindex:=0;
while (BidiModes.Count<=langindex) do
begin
BidiModes.Add('BidiNo');
end;
case Value of
rpBidiNo:
BidiModes.Strings[langindex]:='BidiNo';
rpBidiPartial:
BidiModes.Strings[langindex]:='BidiPartial';
rpBidiFull:
BidiModes.Strings[langindex]:='BidiFull';
end;
end;
procedure TRpGenTextComponent.SetBidiModes(Value:TStrings);
begin
FBidiModes.Assign(Value);
end;
function TRpCommonComponent.GetReport:TComponent;
begin
Result:=nil;
if (Owner is TRpBaseReport) then
begin
Result:=Owner;
exit;
end;
if (Owner is TRpSection) then
begin
if (TRpSection(Owner).Owner is TRpBaseReport) then
begin
Result:=TRpSection(Owner).Owner;
exit;
end;
end;
if Assigned(Result) then
Raise Exception.Create(SRpOnlyAReportOwner);
end;
procedure TRpCommonComponent.SubReportChanged(newstate:TRpReportChanged;newgroup:string='');
begin
// Base class does nothing
end;
procedure TRpGenTextComponent.WriteWFontName(Writer:TWriter);
begin
WriteWideString(Writer, FWFontName);
end;
procedure TRpGenTextComponent.WriteLFontName(Writer:TWriter);
begin
WriteWideString(Writer, FLFontName);
end;
procedure TRpGenTextComponent.ReadLFontName(Reader:TReader);
begin
FLFontName:=ReadWideString(Reader);
end;
procedure TRpGenTextComponent.ReadWFontName(Reader:TReader);
begin
FWFontName:=ReadWideString(Reader);
end;
procedure TRpGenTextComponent.DefineProperties(Filer:TFiler);
begin
inherited;
Filer.DefineProperty('WFontName',ReadWFontName,WriteWFontName,True);
Filer.DefineProperty('LFontName',ReadLFontName,WriteLFontName,True);
end;
end.