function TfmLibItemEditor.DrawIconFromBlock(AItem: TDgrLibraryItem): boolean;
const
ICONSIZE = 24;
var
dgr: TatDiagram;
str: TStringStream;
i,j: integer;
function FitBlockRect(AWidth, AHeight: number): TSquare;
var
x, y, x1, y1: double;
begin
if AWidth > AHeight then
begin
y := ICONSIZE / AWidth * AHeight;
x := ICONSIZE;
end
else
begin
x := ICONSIZE / AHeight * AWidth;
y := ICONSIZE;
end;
x1 := ICONSIZE / 2 - x / 2;
y1 := ICONSIZE / 2 - y / 2;
result := Square(x1, y1, x1 + x, y1 + y);
end;
procedure Calc_Height_text(ADControl:TTextBlock);
var curLineStrLst:TStringList;
begin
curLineStrLst := TStringList.create;
curLineStrLst.strictdelimiter := true;
curLineStrLst.delimiter := char(13);
ADControl.WordWrap := false;
curLineStrLst.DelimitedText := ADControl.TextCells.Items[0].Text;
//In case the currentlist count is zero...
if curLineStrLst.Count > 0 then
TTextBlock(ADControl).TextCells.Items[0].font.Height := - Variant(ADControl.Height / curLineStrLst.Count);
FreeAndNil(CurLineStrLst);
end;
begin
result := False;
if AItem.Data > '' then
begin
dgr := TatDiagram.Create(Self);
str := TStringStream.Create(AItem.Data);
try
dgr.Visible := False;
dgr.Parent := Self;
dgr.LoadFromStream(str, True);
dgr.SetBounds(0, 0, ICONSIZE, ICONSIZE);
for i:=dgr.DControlCount-1 downto 0 do
begin
//gse added for groupblocks
if dgr.DControls is TGroupBlock then
begin
TGroupBlock(dgr.DControls).BoundsRect := Square(0, 0, ICONSIZE, ICONSIZE);
for j := 0 to TGroupblock(dgr.DControls).members.Count - 1 do
begin
if TGroupBlock(dgr.DControls).Members.Items[j].DControl is TTextBlock then
begin
Calc_Height_text(TTextBlock(TGroupBlock(dgr.DControls).Members.Items[j].DControl));
end;
end;
end
else if dgr.DControls is TTextBlock then
begin
Calc_Height_text(TTextBlock(dgr.DControls));
end;
//end gse
if dgr.DControls is TCustomDiagramBlock then
begin
with TCustomDiagramBlock(dgr.DControls) do
begin
if (Width > 0) and (Height > 0) then
BoundsRect := FitBlockRect(Width, Height);
if (dgr.DControls) is TTextBlock then
Calc_Height_text(TTextBlock(dgr.DControls));
end;
dgr.PaintToBitmap(imIcon.Picture.Bitmap);
imIcon.Picture.Bitmap.Width := ICONSIZE+1;
imIcon.Picture.Bitmap.Height := ICONSIZE+1;
result := True;
break;
end;
end;
finally
dgr.Free;
str.Free;
end;
end;
end;