unit ElementList;
interface
uses
ExtCtrls, pngimage, graphics, SysUtils, Classes, forms, controls,
contnrs;
type
TElementType = (etText, etImage, etChart, etTable, etCode, etHTML, etMedia);
type
TElementList =
class(TScrollBox)
constructor Create(AOwner: TComponent);
override;
function Add(ElemType: TElementType; Content:
String):Integer;
procedure Refresh;
procedure Move(OldPosition, NewPosition: Integer);
end;
var
Icons:
Array of TImage;
implementation
var
Items: TObjectList;
constructor TElementList.Create(AOwner: TComponent);
begin
inherited Create(AOwner);
BevelInner := bvNone;
BevelKind := bkFlat;
BevelOuter := bvLowered;
BorderStyle := bsNone;
Items := TObjectList.Create;
SetLength(Icons, 7);
Icons[0] := TImage.Create(Self);
Icons[1] := TImage.Create(Self);
Icons[2] := TImage.Create(Self);
Icons[3] := TImage.Create(Self);
Icons[4] := TImage.Create(Self);
Icons[5] := TImage.Create(Self);
Icons[6] := TImage.Create(Self);
end;
procedure TElementList.Move(OldPosition, NewPosition: Integer);
begin
Items.Move(OldPosition, NewPosition);
Refresh;
end;
procedure TElementList.Refresh;
var
i, position: Integer;
begin
position := 0;
for i := 0
to Items.count - 1
do
begin
(Items.Items[i]
as TPanel).Visible := false;
end;
for i := 0
to Items.count - 1
do
begin
(Items.Items[i]
as TPanel).Top := position + 80;
(Items.Items[i]
as TPanel).Visible := true;
end;
end;
function TElementList.Add(ElemType: TElementType; Content:
String):Integer;
var
layer: TPanel;
imgtype: TImage;
begin
layer := TPanel.Create(Self);
with layer
do
begin
BevelInner := bvNone;
BevelKind := bkNone;
BevelOuter := bvNone;
BorderStyle := bsNone;
Align := alTop;
Height := 80;
Parent := Self;
Visible := false;
Color := clBlack;
Result := Items.Add(layer);
end;
imgtype := TImage.Create(layer);
with imgtype
do
begin
Parent := layer;
Visible := true;
Left := 8;
Top := 8;
Height := 28;
Width := 28;
end;
if ElemType = etText
then
begin
imgtype.Picture.graphic := Icons[0].Picture.graphic;
end
else if ElemType = etImage
then
begin
imgtype.Picture.graphic := Icons[1].Picture.graphic;
end
else if ElemType = etChart
then
begin
imgtype.Picture.graphic := Icons[2].Picture.graphic;
end
else if ElemType = etTable
then
begin
imgtype.Picture.graphic := Icons[3].Picture.graphic;
end
else if ElemType = etCode
then
begin
imgtype.Picture.graphic := Icons[4].Picture.graphic;
end
else if ElemType = etHTML
then
begin
imgtype.Picture.graphic := Icons[5].Picture.graphic;
end
else if ElemType = etMedia
then
begin
imgtype.Picture.graphic := Icons[6].Picture.graphic;
end;
end;
end.