* Allow registering of an icon for custom elements

git-svn-id: trunk@38821 -
This commit is contained in:
michael 2018-04-23 11:24:44 +00:00
parent af8348fba4
commit 6a30410f7b
3 changed files with 123 additions and 30 deletions

View File

@ -2147,19 +2147,26 @@ type
TFPReportClassMapping = class(TObject)
private
FEditorClass: TFPReportElementEditorClass;
FIConData: TBytes;
FImageRenderCallBack: TFPReportImageRenderCallBack;
FMappingName: string;
FReportElementClass: TFPReportElementClass;
FRenderers : TFPReportElementRendererArray;
FStandard: Boolean;
public
Function IndexOfExportRenderer(AClass : TFPReportExporterClass) : Integer;
constructor Create(const AMappingName: string; AElementClass: TFPReportElementClass);
Procedure SetIconFromBytes(B : Array of Byte);
Function IndexOfExportRenderer(AClass : TFPReportExporterClass) : Integer;
Function AddRenderer(aExporterClass : TFPReportExporterClass; aCallback : TFPReportElementExporterCallBack) : TFPReportElementExporterCallBack;
Function FindRenderer(aClass : TFPReportExporterClass) : TFPReportElementExporterCallBack;
property MappingName: string read FMappingName;
Property ImageRenderCallback : TFPReportImageRenderCallBack Read FImageRenderCallBack Write FImageRenderCallBack;
property ReportElementClass: TFPReportElementClass read FReportElementClass;
// Class to edit the element visually
property EditorClass : TFPReportElementEditorClass Read FEditorClass Write FEditorClass;
// element Icon data in PNG format, will be shown in menu editor.
property IconData : TBytes Read FIConData Write FIconData;
Property Standard : Boolean Read FStandard;
end;
@ -2171,10 +2178,10 @@ type
private
FList: TFPObjectList;
function GetM(Aindex : integer): TFPReportClassMapping;
function GetMappingCount: Integer;
Protected
function IndexOfElementClass(const AElementClass: TFPReportElementClass): Integer;
Function IndexOfElementName(const AElementName: string) : Integer;
Property Mappings[Aindex : integer] : TFPReportClassMapping read GetM;
public
constructor Create;
destructor Destroy; override;
@ -2186,12 +2193,14 @@ type
procedure RegisterEditorClass(AReportElementClass: TFPReportElementClass; AEditorClass: TFPReportElementEditorClass);
procedure UnRegisterEditorClass(const AElementName: string; AEditorClass: TFPReportElementEditorClass);
procedure UnRegisterEditorClass(AReportElementClass: TFPReportElementClass; AEditorClass: TFPReportElementEditorClass);
procedure RegisterClass(const AElementName: string; AReportElementClass: TFPReportElementClass);
Function RegisterClass(const AElementName: string; AReportElementClass: TFPReportElementClass) : TFPReportClassMapping;
procedure RemoveClass(const AElementName: string);
function CreateInstance(const AElementName: string; AOwner: TComponent): TFPReportElement; overload;
Function FindEditorClassForInstance(AInstance : TFPReportElement) : TFPReportElementEditorClass;
Function FindEditorClassForInstance(AClass : TFPReportElementClass) : TFPReportElementEditorClass ;
procedure AssignReportElementTypes(AStrings: TStrings);
Property Mappings[Aindex : integer] : TFPReportClassMapping read GetM;
Property MappingCount : Integer Read GetMappingCount;
end;
{ TFPReportBandFactory }
@ -9993,8 +10002,12 @@ Var
Img : TFPCustomImage;
H,W : Integer;
R : TFPReportRect;
L : TFPReportLayout;
begin
L:=aElement.RTLayout;
if (L=Nil) then
L:=aElement.Layout;
// Actually, this could be cached using propertyhash...
C:=gElementFactory.FindRenderer(TFPReportExporterClass(self.ClassType),TFPReportElementClass(aElement.ClassType));
if (C<>Nil) then
@ -10006,15 +10019,15 @@ begin
IC:=gElementFactory.FindImageRenderer(TFPReportElementClass(aElement.ClassType));
if Assigned(IC) then
begin
H := Round(aElement.RTLayout.Height * (aDPI / cMMperInch));
W := Round(aElement.RTLayout.Width * (aDPI / cMMperInch));
H := Round(L.Height * (aDPI / cMMperInch));
W := Round(L.Width * (aDPI / cMMperInch));
Img:=TFPCompactImgRGBA8Bit.Create(W,H);
try
IC(aElement,Img);
R.Left:=aBasePos.Left+AElement.RTLayout.Left;
R.Top:=aBasePos.Top+AElement.RTLayout.Top;
R.Width:=AElement.RTLayout.Width;
R.Height:=AElement.RTLayout.Height;
R.Left:=aBasePos.Left+L.Left;
R.Top:=aBasePos.Top+L.Top;
R.Width:=L.Width;
R.Height:=L.Height;
RenderImage(R,Img);
finally
Img.Free;
@ -10635,6 +10648,12 @@ begin
FReportElementClass := AElementClass;
end;
procedure TFPReportClassMapping.SetIconFromBytes(B: array of Byte);
begin
SetLength(FIConData,Length(B));
Move(B[0],FIconData[0],Length(B));
end;
function TFPReportClassMapping.AddRenderer(aExporterClass: TFPReportExporterClass; aCallback: TFPReportElementExporterCallBack ): TFPReportElementExporterCallBack;
Var
@ -10674,6 +10693,11 @@ begin
Result:=TFPReportClassMapping(FList[AIndex]);
end;
function TFPReportElementFactory.GetMappingCount: Integer;
begin
Result:=FList.Count;
end;
function TFPReportElementFactory.IndexOfElementName(const AElementName: string): Integer;
begin
@ -10805,13 +10829,16 @@ begin
Mappings[i].EditorClass:=nil;
end;
procedure TFPReportElementFactory.RegisterClass(const AElementName: string; AReportElementClass: TFPReportElementClass);
function TFPReportElementFactory.RegisterClass(const AElementName: string; AReportElementClass: TFPReportElementClass
): TFPReportClassMapping;
var
i: integer;
begin
I:=IndexOfElementName(AElementName);
if I<>-1 then exit;
FList.Add(TFPReportClassMapping.Create(AElementName, AReportElementClass));
if I<>-1 then
exit;
Result:=TFPReportClassMapping.Create(AElementName, AReportElementClass);
FList.Add(Result);
end;
procedure TFPReportElementFactory.RemoveClass(const AElementName: string);
@ -12214,25 +12241,36 @@ begin
DefaultBandRectangleColors[i] := fpgDarker(DefaultBandColors[i], 70);
end;
Procedure RegisterStandardReportClasses;
Procedure DoReg(N : String; C : TFPReportElementClass);
begin
gElementFactory.RegisterClass(N,C).FStandard:=true;
end;
begin
DoReg('ReportTitleBand', TFPReportTitleBand);
DoReg('ReportSummaryBand', TFPReportSummaryBand);
DoReg('GroupHeaderBand', TFPReportGroupHeaderBand);
DoReg('GroupFooterBand', TFPReportGroupFooterBand);
DoReg('DataBand', TFPReportDataBand);
DoReg('ChildBand', TFPReportChildBand);
DoReg('PageHeaderBand', TFPReportPageHeaderBand);
DoReg('PageFooterBand', TFPReportPageFooterBand);
DoReg('DataHeaderBand', TFPReportDataHeaderBand);
DoReg('DataFooterBand', TFPReportDataFooterBand);
DoReg('ColumnHeaderBand', TFPReportColumnHeaderBand);
DoReg('ColumnFooterBand', TFPReportColumnFooterBand);
DoReg('Memo', TFPReportMemo);
DoReg('Image', TFPReportImage);
DoReg('Checkbox', TFPReportCheckbox);
DoReg('Shape', TFPReportShape);
end;
initialization
uElementFactory := nil;
gElementFactory.RegisterClass('ReportTitleBand', TFPReportTitleBand);
gElementFactory.RegisterClass('ReportSummaryBand', TFPReportSummaryBand);
gElementFactory.RegisterClass('GroupHeaderBand', TFPReportGroupHeaderBand);
gElementFactory.RegisterClass('GroupFooterBand', TFPReportGroupFooterBand);
gElementFactory.RegisterClass('DataBand', TFPReportDataBand);
gElementFactory.RegisterClass('ChildBand', TFPReportChildBand);
gElementFactory.RegisterClass('PageHeaderBand', TFPReportPageHeaderBand);
gElementFactory.RegisterClass('PageFooterBand', TFPReportPageFooterBand);
gElementFactory.RegisterClass('DataHeaderBand', TFPReportDataHeaderBand);
gElementFactory.RegisterClass('DataFooterBand', TFPReportDataFooterBand);
gElementFactory.RegisterClass('ColumnHeaderBand', TFPReportColumnHeaderBand);
gElementFactory.RegisterClass('ColumnFooterBand', TFPReportColumnFooterBand);
gElementFactory.RegisterClass('Memo', TFPReportMemo);
gElementFactory.RegisterClass('Image', TFPReportImage);
gElementFactory.RegisterClass('Checkbox', TFPReportCheckbox);
gElementFactory.RegisterClass('Shape', TFPReportShape);
RegisterStandardReportClasses;
SetupBandRectColors;
finalization

View File

@ -175,8 +175,53 @@ end;
Procedure RegisterReportBarcode;
Const
icon : Array[0..687] of byte = (
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0,
0, 0, 16, 0, 0, 0, 16, 8, 6, 0, 0, 0, 31,243,255, 97, 0,
0, 2,119, 73, 68, 65, 84,120,156,141,147,189, 74, 92, 81, 20,133,
191,243,115,255,207,140,137,131, 78, 52, 97, 16, 11, 13, 72, 82, 72,
8, 24, 27, 11,155,188,131,149,181,146,202,135, 8, 41,132,188,129,
32,216, 8,118,226, 3,164, 21,196, 46, 54,153, 66, 13, 99, 38,113,
254,238,157,153,123,199,123, 82, 56,115, 73, 37, 89,176,224,176, 89,
103,237,195,222,103, 9,198, 56, 56, 56, 88, 95, 92, 92,124, 45,165,
20, 60, 1,107,173,173,215,235,223,183,182,182,190, 21,197,163,163,
163,207, 73,146,228, 73,146,216,255,100,126,120,120,248, 5, 64,108,
111,111,191, 92, 93, 93,173,135, 97,168,141, 49, 52, 26, 13,142,143,
143, 57, 61, 61,101,125,125,157, 82,169,196,206,206, 14,215,215,215,
156,156,156,176,187,187,203,205,205, 13,211,211,211, 15,151,151,151,
11,186, 82,169, 84,227, 56,214,214, 90,164,148,116,187, 93,126,253,
106, 2,112,119,119,199,112, 56, 36, 73, 18,226, 56,166,217,108,210,
235,245,136,227, 24,223,247, 85,181, 90,125, 33,133, 16, 76, 40,165,
68,107,141,235,186, 40,165,240, 60, 15,207,243, 80, 74,161,181,198,
113,156, 66, 7, 32,165, 20, 18, 40,138, 82,170,177,129, 83, 24,185,
174,139,214,186, 48,208, 90, 35,165, 66, 74,137,181, 22, 41, 30,157,
198, 93, 84,209, 77, 8, 81, 92, 82,106, 82,159,156,229,248, 21, 22,
141, 16,204,164, 41,230,247,111, 76,154,162, 90, 45,222,102, 25,226,
231, 79,222,141, 70,148, 71, 35,102, 91, 45,242, 78,135, 55, 89, 74,
165,217,100,116,127,143,137, 34,218, 8,180, 16,130, 56,138, 40, 55,
155, 68, 74, 97, 7, 3, 94,229, 57,162,223,103,193, 90, 76,158, 83,
74, 83,134, 89,198,124,158, 19,245,251,136, 52, 37, 14, 67, 72,146,
71, 3,171, 53,237, 90,141, 40,203,200,178,140,196,243,160, 82,161,
231,121, 8,207, 99, 84, 46,147,117,187,244, 93,151,254,212, 51,254,
184, 46,211, 74, 33,192, 74, 38, 51,240,125,226,106,149, 81,185, 76,
26,134, 48, 53,197, 32, 8, 24,134, 33,185, 49, 60, 24, 67, 28, 69,
244,102,103,208,227, 45, 33, 4, 18, 40,134,164, 28,135,158, 49, 12,
130, 0,164,100, 16, 4,164, 97,200,131,235, 50,116, 93, 26,229, 50,
74,235, 66,111,173, 69,118, 58,157,252,113,133,143,204,181,166, 21,
69, 0,164, 65, 64, 26, 4,228,142, 67,223,247, 17,142,195,191,218,
118,187,253,160, 47, 46, 46,126,172,172,172, 52,150,151,151,171, 65,
16, 96,140,225,253,135, 15, 0,172,110,108, 96, 74, 37,158,207,207,
99,125,159,181,181, 53,230,230,230,240, 60,143,219,219,219,198,249,
249,249, 15, 1,176,185,185,249,113,111,111,239,235,210,210,210,252,
83, 73,156,224,234,234,234,118,127,127,255,211,217,217,217,105, 17,
221, 90,173, 22,229,121,254,124,242, 77,159,136, 51, 74,169,251,122,
189, 30, 3,252, 5,131, 89, 18, 55,201,190,160,207, 0, 0, 0, 0,
73, 69, 78, 68,174, 66, 96,130);
begin
gElementFactory.RegisterClass('Barcode',TFPReportBarcode);
gElementFactory.RegisterClass('Barcode',TFPReportBarcode).SetIconFromBytes(Icon);
// Fallback renderer
gElementFactory.RegisterImageRenderer(TFPReportBarcode,@RenderBarcode);
end;

View File

@ -197,9 +197,19 @@ end;
Procedure RegisterReportQRCode;
Const
icon : Array[0..123] of byte = (
137, 80, 78, 71, 13, 10, 26, 10, 0, 0, 0, 13, 73, 72, 68, 82, 0,
0, 0, 16, 0, 0, 0, 16, 1, 3, 0, 0, 0, 37, 61,109, 34, 0,
0, 0, 6, 80, 76, 84, 69, 0, 0, 0,255,255,255,165,217,159,221,
0, 0, 0, 49, 73, 68, 65, 84, 8,215, 99, 96,108, 96,168,221,199,
224,186, 8,138,128,108,160,200,255,255, 12,255,101, 24, 24, 69, 24,
106,191, 48,184,178, 48,184,202, 48,184, 62, 97,168,149, 96, 96,148,
0, 0, 95, 30, 13, 78,141,201,223,244, 0, 0, 0, 0, 73, 69, 78,
68,174, 66, 96,130);
begin
gElementFactory.RegisterClass('QRCode',TFPReportQRCode);
gElementFactory.RegisterClass('QRCode',TFPReportQRCode).SetIconFromBytes(Icon);
// Fallback renderer
gElementFactory.RegisterImageRenderer(TFPReportQRCode,@RenderQRCode);
end;