1{
2    This file is part of the Free Component Library.
3    Copyright (c) 2017 Michael Van Canneyt, member of the Free Pascal development team
4
5    Report data component property editor for object inspector.
6
7    See the file COPYING.FPC, included in this distribution,
8    for details about the copyright.
9
10    This program is distributed in the hope that it will be useful,
11    but WITHOUT ANY WARRANTY; without even the implied warranty of
12    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13
14 **********************************************************************}
15unit regfpdesigner;
16
17{$mode objfpc}{$H+}
18
19interface
20
21uses
22  fpttf, Graphics, GraphPropEdits, Classes, SysUtils, dialogs, fpreport, ideintf, propedits, ObjInspStrConsts, frmfpreportmemoedit;
23
24Type
25
26  { TReportFontPropertyEditor }
27
28  TReportFontPropertyEditor = class(TClassPropertyEditor)
29  public
30    procedure Edit; override;
31    function GetAttributes: TPropertyAttributes; override;
32  end;
33
34  { TFPreportColorPropertyEditor }
35
36  TFPreportColorPropertyEditor = Class(TColorPropertyEditor)
37  public
38    function OrdValueToVisualValue(OrdValue: longint): string; override;
39    procedure SetValue(const NewValue: ansistring); override;
40  end;
41  { TReportFontNamePropertyEditor }
42
43  TReportFontNamePropertyEditor = class(TFontNamePropertyEditor)
44  public
45    procedure SetValue(const NewValue: ansistring); override;
46  end;
47
48  { TPaperNamePropertyEditor }
49
50  TPaperNamePropertyEditor = class(TStringPropertyEditor)
51  Public
52    procedure GetValues(Proc: TGetStrProc); override;
53    Function GetAttributes: TPropertyAttributes; override;
54  end;
55
56
57  { TReportComponentPropertyEditor }
58
59  TReportComponentPropertyEditor = class(TComponentPropertyEditor)
60  Protected
61    Function GetReport : TFPCustomReport;
62    Function GetPage : TFPReportCustomPage;
63  end;
64
65  { TDataComponentPropertyEditor }
66
67  TDataComponentPropertyEditor = class(TReportComponentPropertyEditor)
68  Public
69    procedure GetValues(Proc: TGetStrProc); override;
70    procedure SetValue(const NewValue: ansistring); override;
71  end;
72
73  { TReportBandPropertyEditor }
74
75  TReportBandPropertyEditor = class(TReportComponentPropertyEditor)
76  protected
77    function BandAllowed(B: TFPReportCustomBand): Boolean; virtual;
78  Public
79    Function BandTypes : TFPReportBandTypes; virtual;
80    procedure GetValues(Proc: TGetStrProc); override;
81    procedure SetValue(const NewValue: ansistring); override;
82  end;
83
84  { TChildBandPropertyEditor }
85
86  TChildBandPropertyEditor = Class(TReportBandPropertyEditor)
87  Public
88    function BandAllowed(B: TFPReportCustomBand): Boolean; override;
89    Function BandTypes : TFPReportBandTypes; override;
90  end;
91
92  { TDataFooterBandPropertyEditor }
93
94  TDataFooterBandPropertyEditor = Class(TReportBandPropertyEditor)
95  Public
96    Function BandTypes : TFPReportBandTypes; override;
97  end;
98
99  { TDataHeaderBandPropertyEditor }
100
101  TDataHeaderBandPropertyEditor = Class(TReportBandPropertyEditor)
102  Public
103    Function BandTypes : TFPReportBandTypes; override;
104  end;
105
106  { TDataBandPropertyEditor }
107
108  TDataBandPropertyEditor = Class(TReportBandPropertyEditor)
109  Public
110    Function BandTypes : TFPReportBandTypes; override;
111  end;
112
113  { TGroupHeaderBandPropertyEditor }
114
115  TGroupHeaderBandPropertyEditor = Class(TReportBandPropertyEditor)
116  Public
117    Function BandTypes : TFPReportBandTypes; override;
118  end;
119
120  { TGroupFooterBandPropertyEditor }
121
122  TGroupFooterBandPropertyEditor = Class(TReportBandPropertyEditor)
123  Public
124    Function BandTypes : TFPReportBandTypes; override;
125  end;
126
127  { TParentGroupHeaderBandPropertyEditor }
128
129  TParentGroupHeaderBandPropertyEditor = Class(TGroupHeaderBandPropertyEditor)
130  Public
131    function BandAllowed(B: TFPReportCustomBand): Boolean; override;
132  end;
133
134Procedure RegisterFPReportPropEditors;
135
136implementation
137
138uses fpreportlclexport;
139
140Procedure RegisterFPReportPropEditors;
141
142begin
143  RegisterPropertyEditor(TypeInfo(TFPReportData), TFPreportElement, 'Data', TDataComponentPropertyEditor);
144  RegisterPropertyEditor(TypeInfo(TFPReportCustomChildBand), TFPReportCustomBand, 'ChildBand', TChildBandPropertyEditor);
145  RegisterPropertyEditor(TypeInfo(TFPReportCustomDataFooterBand), TFPReportCustomBand, 'FooterBand', TDataFooterBandPropertyEditor);
146  RegisterPropertyEditor(TypeInfo(TFPReportCustomDataHeaderBand), TFPReportCustomBand, 'HeaderBand', TDataHeaderBandPropertyEditor);
147  RegisterPropertyEditor(TypeInfo(TFPReportCustomDataBand), TFPReportCustomBand, 'MasterBand', TDataBandPropertyEditor);
148  RegisterPropertyEditor(TypeInfo(TFPReportCustomGroupHeaderBand),TFPReportCustomGroupHeaderBand, 'ParentGroupHeader', TParentGroupHeaderBandPropertyEditor);
149  RegisterPropertyEditor(TypeInfo(TFPReportCustomGroupHeaderBand),TFPReportCustomGroupFooterBand, 'GroupHeader', TGroupHeaderBandPropertyEditor);
150
151  RegisterPropertyEditor(TypeInfo(TFPReportColor),TFPReportComponent,'Color',TFPreportColorPropertyEditor);
152  RegisterPropertyEditor(TypeInfo(TFPReportColor),TFPReportComponent,'BackgroundColor',TFPreportColorPropertyEditor);
153  RegisterPropertyEditor(TypeInfo(TFPReportColor),TFPReportFrame,'Color',TFPreportColorPropertyEditor);
154  RegisterPropertyEditor(TypeInfo(TFPReportColor),TFPReportFrame,'BackgroundColor',TFPreportColorPropertyEditor);
155  RegisterPropertyEditor(TypeInfo(TFPReportColor),TFPReportFont,'Color',TFPreportColorPropertyEditor);
156  RegisterPropertyEditor(ClassTypeInfo(TFPReportFont), nil,'',TReportFontPropertyEditor);
157  RegisterPropertyEditor(TypeInfo(String),TFPReportFont,'Name',TReportFontNamePropertyEditor);
158end;
159
160{ TReportFontPropertyEditor }
161
162Function PostScriptNameToFontName(N : String) : String;
163
164Var
165  F : TFPFontCacheItem;
166
167begin
168  if (N='default') then
169    N:=ReportDefaultFont;
170  F:=gTTFontCache.Find(N);
171  if Assigned(F) then
172    N:=F.FamilyName;
173  Result:=N;
174end;
175
176Function FontNameToPostScriptName(N : String; ABold,AItalic : Boolean) : String;
177
178Var
179  F : TFPFontCacheItem;
180
181begin
182  if (N='default') then
183    N:=ReportDefaultFont;
184  F:=gTTFontCache.Find(N,aBold,aItalic);
185  if Assigned(F) then
186    N:=F.PostScriptName;
187  Result:=N;
188end;
189
190{ TParentGroupHeaderBandPropertyEditor }
191
192function TParentGroupHeaderBandPropertyEditor.BandAllowed(B: TFPReportCustomBand): Boolean;
193
194Var
195  G,P : TFPReportCustomGroupHeaderBand;
196
197begin
198  Result:=inherited BandAllowed(B);
199  if Result then
200    begin
201    P:=B as TFPReportCustomGroupHeaderBand;
202    G:=GetComponent(0) as TFPReportCustomGroupHeaderBand;
203    While Result and (P<>Nil) do
204      begin
205      Result:=P<>G;
206      P:=TFPReportGroupHeaderBand(P).ParentGroupHeader;
207      end;
208    end;
209end;
210
211
212{ TFPreportColorPropertyEditor }
213
214function TFPreportColorPropertyEditor.OrdValueToVisualValue(OrdValue: longint): string;
215
216Var
217  lclColor : TColor;
218
219begin
220  lclColor:=TFPReportExportCanvas.RGBtoBGR(UInt32(OrdValue));
221  Result:=inherited OrdValueToVisualValue(lclColor);
222end;
223
224procedure TFPreportColorPropertyEditor.SetValue(const NewValue: ansistring);
225
226var
227  CValue: Longint;
228
229begin
230  if IdentToColor(NewValue, CValue) then
231    SetOrdValue(Longint(TFPReportExportCanvas.BGRToRGB(TColor(CValue))))
232  else
233    inherited SetValue(NewValue);
234end;
235
236{ TReportFontNamePropertyEditor }
237
238
239procedure TReportFontNamePropertyEditor.SetValue(const NewValue: ansistring);
240begin
241  inherited SetValue(FontNameToPostScriptName(NewValue,False,False));
242end;
243
244procedure TReportFontPropertyEditor.Edit;
245
246var
247  FontDialog: TFontDialog;
248  R : TFPReportFont;
249
250begin
251  FontDialog := TFontDialog.Create(nil);
252  try
253    R:=TFPReportFont(GetObjectValue(TFPReportFont));
254    FontDialog.Font.Name := PostScriptNameToFontName(R.Name);
255    FontDialog.Font.Size:=R.Size;
256    FontDialog.Font.Color:=TFPReportExportCanvas.RGBtoBGR(R.Color);
257    FontDialog.Options := FontDialog.Options + [fdShowHelp, fdForceFontExist];
258    if FontDialog.Execute then
259      begin
260      R.Name:=FontNameToPostScriptName(FontDialog.Font.Name,FontDialog.Font.Bold,FontDialog.Font.Italic);
261      R.Size:=FontDialog.Font.Size;
262      R.Color:=TFPReportExportCanvas.BGRToRGB(FontDialog.Font.Color);
263      end;
264  finally
265    FontDialog.Free;
266  end;
267end;
268
269function TReportFontPropertyEditor.GetAttributes: TPropertyAttributes;
270begin
271  Result := [paMultiSelect, paSubProperties, paDialog, paReadOnly];
272end;
273
274
275
276{ TPaperNamePropertyEditor }
277
278procedure TPaperNamePropertyEditor.GetValues(Proc: TGetStrProc);
279
280Var
281  I : integer;
282
283begin
284  for I:=0 to PaperManager.PaperCount-1 do
285    Proc(PaperManager.PaperNames[i]);
286end;
287
288function TPaperNamePropertyEditor.GetAttributes: TPropertyAttributes;
289begin
290  Result:=[paValueList, paPickList, paAutoUpdate, paSortList];
291end;
292
293
294{ TGroupFooterBandPropertyEditor }
295
296function TGroupFooterBandPropertyEditor.BandTypes: TFPReportBandTypes;
297begin
298  Result:=[btGroupFooter];
299end;
300
301{ TGroupHeaderBandPropertyEditor }
302
303function TGroupHeaderBandPropertyEditor.BandTypes: TFPReportBandTypes;
304begin
305  Result:=[btGroupHeader];
306end;
307
308{ TDataBandPropertyEditor }
309
310function TDataBandPropertyEditor.BandTypes: TFPReportBandTypes;
311begin
312  Result:=[btDataband];
313end;
314
315{ TDataHeaderBandPropertyEditor }
316
317function TDataHeaderBandPropertyEditor.BandTypes: TFPReportBandTypes;
318begin
319  Result:=[btDataHeader];
320end;
321
322{ TDataFooterBandPropertyEditor }
323
324function TDataFooterBandPropertyEditor.BandTypes: TFPReportBandTypes;
325begin
326  Result:=[btDataFooter];
327end;
328
329{ TChildBandPropertyEditor }
330
331function TChildBandPropertyEditor.BandAllowed(B: TFPReportCustomBand): Boolean;
332
333Var
334  P : TFPReportCustomPage;
335  CB : TFPReportCustomBand;
336  I : Integer;
337
338begin
339  Result:=inherited BandAllowed(B);
340  CB:=TFPReportCustomBand(GetComponent(0));
341  If Result then
342    begin
343    P:=GetPage;
344    I:=P.BandCount-1;
345    While Result and (I>=0) do
346      begin
347      Result:=(P.Bands[i]=CB) or (P.Bands[i].ChildBand<>B);
348      Dec(I)
349      end;
350
351    end;
352end;
353
354function TChildBandPropertyEditor.BandTypes: TFPReportBandTypes;
355begin
356  Result:=[btChild];
357end;
358
359{ TReportBandPropertyEditor }
360
361function TReportBandPropertyEditor.BandTypes: TFPReportBandTypes;
362begin
363  Result:=[]
364end;
365
366Function TReportBandPropertyEditor.BandAllowed(B : TFPReportCustomBand) : Boolean;
367
368Var
369  BT : TFPReportBandTypes;
370
371begin
372  BT:=BandTypes;
373  Result:=(B.Name<>'') and (B<>GetComponent(0));
374  if Result and (BT<>[]) then
375    Result:=B.ReportBandType in BT;
376end;
377
378procedure TReportBandPropertyEditor.GetValues(Proc: TGetStrProc);
379
380Var
381  P : TFPReportCustomPage;
382  I : Integer;
383
384
385begin
386  P:=GetPage;
387  proc(oisNone);
388  if Assigned(P) then
389    For I:=0 to P.BandCount-1 do
390      if BandAllowed(P.Bands[i]) then
391        Proc(P.Bands[i].Name);
392end;
393
394procedure TReportBandPropertyEditor.SetValue(const NewValue: ansistring);
395
396Var
397  P : TFPReportCustomPage;
398  B : TFPReportCustomBand;
399  I : integer;
400
401begin
402  B:=nil;
403  if (NewValue<>oisNone) then
404    begin
405    P:=GetPage;
406    I:=0;
407    if Assigned(P) then
408      While (B=Nil) and (I<P.BandCount) do
409        begin
410        if SameText(NewValue,P.Bands[I].Name) then
411          B:=P.Bands[I];
412        Inc(I);
413        end;
414    end;
415  if Assigned(PropertyHook) then
416    PropertyHook.ObjectReferenceChanged(Self,B);
417  SetPtrValue(B);
418end;
419
420{ TReportComponentPropertyEditor }
421
422Function TReportComponentPropertyEditor.GetPage : TFPReportCustomPage;
423
424Var
425  C : TPersistent;
426begin
427  Result:=Nil;
428  C:=GetComponent(0);
429  // Latest SVN has page
430  if C is TFPReportCustomPage then
431    Result:=C as TFPReportCustomPage
432  else if C is TFPReportCustomBand then
433    Result:=TFPReportCustomBand(C).Page
434  else if C is TFPReportElement then
435    Result:=TFPReportElement(C).Page;
436end;
437
438function TReportComponentPropertyEditor.GetReport: TFPCustomReport;
439Var
440  C : TPersistent;
441begin
442  Result:=Nil;
443  C:=GetComponent(0);
444  if C is TFPCustomReport then
445    Result:=C as TFPCustomReport
446  else if C is TFPReportElement then
447    Result:=TFPReportElement(C).Report;
448end;
449
450{ TDataComponentPropertyEditor }
451
452procedure TDataComponentPropertyEditor.GetValues(Proc: TGetStrProc);
453
454Var
455  Report : TFPCustomReport;
456  I : Integer;
457
458begin
459  Report:=GetReport;
460  proc(oisNone);
461  if Assigned(Report) then
462    For I:=0 to Report.ReportData.Count-1 do
463      Proc(Report.ReportData[i].Data.Name);
464end;
465
466procedure TDataComponentPropertyEditor.SetValue(const NewValue: ansistring);
467
468Var
469  Report:TFPCustomReport;
470  RD : TFPReportData;
471
472begin
473  RD:=nil;
474  if (NewValue<>oisNone) then
475    begin
476    Report:=GetReport;
477    if Assigned(Report) then
478      RD:=Report.ReportData.FindReportData(NewValue);
479    end;
480  if Assigned(PropertyHook) then
481    PropertyHook.ObjectReferenceChanged(Self,RD);
482  SetPtrValue(RD);
483end;
484
485end.
486
487