2004-09-02 10:36:24 +00:00
|
|
|
{
|
|
|
|
:: Contains the dialog presented for the Container's Graphics property
|
|
|
|
::
|
|
|
|
:: Last changed: $Date$
|
|
|
|
:: Revision: $Rev$
|
|
|
|
:: Author: $Author$
|
|
|
|
}
|
|
|
|
unit X2CLGraphicsEditor;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
ActnList,
|
|
|
|
Classes,
|
|
|
|
ComCtrls,
|
|
|
|
Controls,
|
2007-01-04 19:47:47 +00:00
|
|
|
DesignIntf,
|
2004-09-02 10:36:24 +00:00
|
|
|
Dialogs,
|
|
|
|
ExtCtrls,
|
|
|
|
ExtDlgs,
|
|
|
|
Forms,
|
|
|
|
ImgList,
|
|
|
|
StdCtrls,
|
|
|
|
ToolWin,
|
|
|
|
|
|
|
|
X2CLGraphicList;
|
|
|
|
|
|
|
|
type
|
|
|
|
TfrmGraphicsEditor = class(TForm)
|
|
|
|
actAdd: TAction;
|
|
|
|
actClear: TAction;
|
|
|
|
actDelete: TAction;
|
|
|
|
actDown: TAction;
|
|
|
|
actOpen: TAction;
|
|
|
|
actSave: TAction;
|
|
|
|
actUp: TAction;
|
|
|
|
alGraphics: TActionList;
|
|
|
|
dlgOpen: TOpenPictureDialog;
|
|
|
|
dlgSave: TSavePictureDialog;
|
|
|
|
ilsIcons: TImageList;
|
|
|
|
imgPreview: TImage;
|
|
|
|
lblName: TLabel;
|
|
|
|
lstGraphics: TListBox;
|
|
|
|
pnlGraphics: TPanel;
|
|
|
|
pnlImage: TPanel;
|
|
|
|
pnlProperties: TPanel;
|
|
|
|
sbImage: TScrollBox;
|
|
|
|
spltGraphics: TSplitter;
|
|
|
|
tbClear: TToolButton;
|
|
|
|
tbDelete: TToolButton;
|
|
|
|
tbDown: TToolButton;
|
|
|
|
tbGraphics: TToolBar;
|
|
|
|
tbImage: TToolBar;
|
|
|
|
tbNew: TToolButton;
|
|
|
|
tbOpen: TToolButton;
|
|
|
|
tbSave: TToolButton;
|
|
|
|
tbSep1: TToolButton;
|
|
|
|
tbUp: TToolButton;
|
|
|
|
txtName: TEdit;
|
|
|
|
|
|
|
|
procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
|
|
|
procedure lstGraphicsClick(Sender: TObject);
|
|
|
|
procedure txtNameChange(Sender: TObject);
|
|
|
|
procedure actAddExecute(Sender: TObject);
|
|
|
|
procedure actDeleteExecute(Sender: TObject);
|
|
|
|
procedure actUpExecute(Sender: TObject);
|
|
|
|
procedure actDownExecute(Sender: TObject);
|
|
|
|
procedure actOpenExecute(Sender: TObject);
|
|
|
|
procedure actSaveExecute(Sender: TObject);
|
|
|
|
procedure actClearExecute(Sender: TObject);
|
|
|
|
private
|
|
|
|
FComponent: TX2GraphicContainer;
|
2007-01-04 19:47:47 +00:00
|
|
|
FComponentDesigner: IDesigner;
|
2004-09-02 10:36:24 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure InternalExecute(const AComponent: TComponent; const ADesigner: IDesigner);
|
2004-09-02 10:36:24 +00:00
|
|
|
procedure Administrate();
|
|
|
|
procedure UpdatePreview();
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
function Active(out AIndex: Integer; out AGraphic: TX2GraphicContainerItem): Boolean;
|
|
|
|
protected
|
|
|
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
2004-09-02 10:36:24 +00:00
|
|
|
public
|
2007-01-04 19:47:47 +00:00
|
|
|
class procedure Execute(const AComponent: TComponent; const ADesigner: IDesigner);
|
2004-09-02 10:36:24 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
implementation
|
|
|
|
uses
|
|
|
|
Graphics,
|
|
|
|
SysUtils;
|
|
|
|
|
|
|
|
var
|
|
|
|
GEditor: TfrmGraphicsEditor;
|
|
|
|
|
|
|
|
|
|
|
|
{$R *.dfm}
|
|
|
|
|
|
|
|
|
|
|
|
{===================== TfrmGraphicsEditor
|
|
|
|
Initialization
|
|
|
|
========================================}
|
2007-01-04 19:47:47 +00:00
|
|
|
class procedure TfrmGraphicsEditor.Execute(const AComponent: TComponent; const ADesigner: IDesigner);
|
2004-09-02 10:36:24 +00:00
|
|
|
begin
|
|
|
|
if not Assigned(GEditor) then
|
|
|
|
GEditor := TfrmGraphicsEditor.Create(Application);
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
GEditor.InternalExecute(AComponent, ADesigner);
|
2004-09-02 10:36:24 +00:00
|
|
|
end;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TfrmGraphicsEditor.InternalExecute(const AComponent: TComponent; const ADesigner: IDesigner);
|
2004-09-02 10:36:24 +00:00
|
|
|
var
|
|
|
|
iGraphic: Integer;
|
|
|
|
|
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
FComponent := TX2GraphicContainer(AComponent);
|
|
|
|
FComponent.FreeNotification(Self);
|
|
|
|
|
|
|
|
FComponentDesigner := ADesigner;
|
|
|
|
Caption := Format('%s Graphics', [FComponent.Name]);
|
2004-09-02 10:36:24 +00:00
|
|
|
|
|
|
|
// Fill graphics list
|
|
|
|
with lstGraphics.Items do
|
|
|
|
begin
|
|
|
|
BeginUpdate();
|
|
|
|
try
|
|
|
|
Clear();
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
for iGraphic := 0 to FComponent.GraphicCount - 1 do
|
|
|
|
AddObject(FComponent.Graphics[iGraphic].PictureName,
|
2004-09-02 10:36:24 +00:00
|
|
|
FComponent.Graphics[iGraphic]);
|
|
|
|
finally
|
|
|
|
EndUpdate();
|
|
|
|
end;
|
|
|
|
|
|
|
|
lstGraphics.ItemIndex := 0;
|
|
|
|
UpdatePreview();
|
|
|
|
end;
|
|
|
|
|
|
|
|
Administrate();
|
|
|
|
Show();
|
|
|
|
end;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TfrmGraphicsEditor.FormClose(Sender: TObject; var Action: TCloseAction);
|
2004-09-02 10:36:24 +00:00
|
|
|
begin
|
|
|
|
Action := caFree;
|
|
|
|
GEditor := nil;
|
2007-01-04 19:47:47 +00:00
|
|
|
|
|
|
|
if Assigned(FComponent) then
|
|
|
|
FComponent.RemoveFreeNotification(Self);
|
2004-09-02 10:36:24 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TfrmGraphicsEditor.Administrate();
|
2004-09-02 10:36:24 +00:00
|
|
|
var
|
|
|
|
bEnabled: Boolean;
|
|
|
|
iIndex: Integer;
|
2007-01-04 19:47:47 +00:00
|
|
|
pGraphic: TX2GraphicContainerItem;
|
2004-09-02 10:36:24 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
bEnabled := Active(iIndex, pGraphic);
|
|
|
|
actDelete.Enabled := bEnabled;
|
|
|
|
actOpen.Enabled := bEnabled;
|
|
|
|
|
|
|
|
if bEnabled then
|
|
|
|
bEnabled := Assigned(pGraphic.Picture.Graphic)
|
|
|
|
else
|
|
|
|
bEnabled := False;
|
|
|
|
|
|
|
|
actSave.Enabled := bEnabled;
|
|
|
|
actClear.Enabled := bEnabled;
|
|
|
|
|
|
|
|
actUp.Enabled := bEnabled and (iIndex > 0);
|
|
|
|
actDown.Enabled := bEnabled and (iIndex < lstGraphics.Items.Count - 1);
|
|
|
|
end;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TfrmGraphicsEditor.UpdatePreview();
|
2004-09-02 10:36:24 +00:00
|
|
|
var
|
|
|
|
iIndex: Integer;
|
2007-01-04 19:47:47 +00:00
|
|
|
pGraphic: TX2GraphicContainerItem;
|
2004-09-02 10:36:24 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if Active(iIndex, pGraphic) then
|
|
|
|
begin
|
|
|
|
imgPreview.Picture.Assign(pGraphic.Picture);
|
2007-01-04 19:47:47 +00:00
|
|
|
txtName.Text := pGraphic.PictureName;
|
2004-09-02 10:36:24 +00:00
|
|
|
Administrate();
|
2007-01-04 19:47:47 +00:00
|
|
|
|
|
|
|
if Assigned(FComponentDesigner) then
|
|
|
|
FComponentDesigner.SelectComponent(pGraphic);
|
|
|
|
end else
|
|
|
|
if Assigned(FComponentDesigner) then
|
|
|
|
FComponentDesigner.SelectComponent(FComponent);
|
2004-09-02 10:36:24 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{===================== TfrmGraphicsEditor
|
|
|
|
Graphic Management
|
|
|
|
========================================}
|
2007-01-04 19:47:47 +00:00
|
|
|
function TfrmGraphicsEditor.Active(out AIndex: Integer; out AGraphic: TX2GraphicContainerItem): Boolean;
|
2004-09-02 10:36:24 +00:00
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
AIndex := lstGraphics.ItemIndex;
|
|
|
|
if AIndex = -1 then
|
|
|
|
exit;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
AGraphic := TX2GraphicContainerItem(lstGraphics.Items.Objects[AIndex]);
|
2004-09-02 10:36:24 +00:00
|
|
|
Result := Assigned(AGraphic);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TfrmGraphicsEditor.lstGraphicsClick(Sender: TObject);
|
2004-09-02 10:36:24 +00:00
|
|
|
begin
|
|
|
|
UpdatePreview();
|
|
|
|
end;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TfrmGraphicsEditor.txtNameChange(Sender: TObject);
|
2004-09-02 10:36:24 +00:00
|
|
|
var
|
|
|
|
iIndex: Integer;
|
2007-01-04 19:47:47 +00:00
|
|
|
pGraphic: TX2GraphicContainerItem;
|
2004-09-02 10:36:24 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if Active(iIndex, pGraphic) then
|
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
pGraphic.PictureName := txtName.Text;
|
|
|
|
lstGraphics.Items[iIndex] := pGraphic.PictureName;
|
2004-09-02 10:36:24 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TfrmGraphicsEditor.actAddExecute(Sender: TObject);
|
2004-09-02 10:36:24 +00:00
|
|
|
var
|
|
|
|
iIndex: Integer;
|
2007-01-04 19:47:47 +00:00
|
|
|
pGraphic: TX2GraphicContainerItem;
|
2004-09-02 10:36:24 +00:00
|
|
|
|
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
if Assigned(FComponentDesigner) then
|
|
|
|
begin
|
|
|
|
pGraphic := TX2GraphicContainerItem(FComponentDesigner.CreateComponent(TX2GraphicContainerItem, nil, 0, 0, 0, 0));
|
2004-09-02 10:36:24 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
if Assigned(pGraphic) then
|
|
|
|
begin
|
|
|
|
pGraphic.Container := FComponent;
|
|
|
|
iIndex := lstGraphics.Items.AddObject(pGraphic.PictureName,
|
|
|
|
pGraphic);
|
|
|
|
|
|
|
|
lstGraphics.ItemIndex := iIndex;
|
|
|
|
UpdatePreview();
|
|
|
|
|
|
|
|
actOpen.Execute();
|
|
|
|
end else
|
|
|
|
raise Exception.Create('Failed to create TX2GraphicContainerItem!');
|
|
|
|
end else
|
|
|
|
raise Exception.Create('Designer not found!');
|
2004-09-02 10:36:24 +00:00
|
|
|
end;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TfrmGraphicsEditor.actDeleteExecute(Sender: TObject);
|
2004-09-02 10:36:24 +00:00
|
|
|
var
|
|
|
|
iIndex: Integer;
|
2007-01-04 19:47:47 +00:00
|
|
|
pGraphic: TX2GraphicContainerItem;
|
2004-09-02 10:36:24 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if Active(iIndex, pGraphic) then
|
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
{ First attempt to remove the component; this will raise an exception
|
|
|
|
if it's not allowed, for example due to it being introduced in
|
|
|
|
an ancestor. }
|
|
|
|
pGraphic.Free();
|
2004-09-02 10:36:24 +00:00
|
|
|
lstGraphics.Items.Delete(iIndex);
|
|
|
|
|
|
|
|
if iIndex > lstGraphics.Items.Count - 1 then
|
|
|
|
iIndex := lstGraphics.Items.Count - 1;
|
|
|
|
|
|
|
|
lstGraphics.ItemIndex := iIndex;
|
|
|
|
UpdatePreview();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TfrmGraphicsEditor.actUpExecute(Sender: TObject);
|
2004-09-02 10:36:24 +00:00
|
|
|
var
|
|
|
|
iIndex: Integer;
|
2007-01-04 19:47:47 +00:00
|
|
|
pGraphic: TX2GraphicContainerItem;
|
2004-09-02 10:36:24 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if Active(iIndex, pGraphic) then
|
|
|
|
if iIndex > 0 then
|
|
|
|
begin
|
|
|
|
lstGraphics.Items.Move(iIndex, iIndex - 1);
|
|
|
|
pGraphic.Index := iIndex - 1;
|
|
|
|
lstGraphics.ItemIndex := iIndex - 1;
|
|
|
|
Administrate();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TfrmGraphicsEditor.actDownExecute(Sender: TObject);
|
2004-09-02 10:36:24 +00:00
|
|
|
var
|
|
|
|
iIndex: Integer;
|
2007-01-04 19:47:47 +00:00
|
|
|
pGraphic: TX2GraphicContainerItem;
|
2004-09-02 10:36:24 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if Active(iIndex, pGraphic) then
|
|
|
|
if iIndex < lstGraphics.Items.Count - 1 then
|
|
|
|
begin
|
|
|
|
lstGraphics.Items.Move(iIndex, iIndex + 1);
|
|
|
|
pGraphic.Index := iIndex + 1;
|
|
|
|
lstGraphics.ItemIndex := iIndex + 1;
|
|
|
|
Administrate();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TfrmGraphicsEditor.actOpenExecute(Sender: TObject);
|
2004-09-02 10:36:24 +00:00
|
|
|
var
|
|
|
|
iIndex: Integer;
|
2007-01-04 19:47:47 +00:00
|
|
|
pGraphic: TX2GraphicContainerItem;
|
2004-09-02 10:36:24 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if Active(iIndex, pGraphic) then
|
|
|
|
begin
|
|
|
|
dlgOpen.Filter := GraphicFilter(TGraphic);
|
|
|
|
if dlgOpen.Execute() then
|
|
|
|
begin
|
|
|
|
pGraphic.Picture.LoadFromFile(dlgOpen.FileName);
|
2007-01-04 19:47:47 +00:00
|
|
|
if Length(pGraphic.PictureName) = 0 then
|
|
|
|
pGraphic.PictureName := ChangeFileExt(ExtractFileName(dlgOpen.FileName), '');
|
2004-09-02 10:36:24 +00:00
|
|
|
|
|
|
|
UpdatePreview();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TfrmGraphicsEditor.actSaveExecute(Sender: TObject);
|
2004-09-02 10:36:24 +00:00
|
|
|
var
|
|
|
|
iIndex: Integer;
|
|
|
|
pClass: TGraphicClass;
|
2007-01-04 19:47:47 +00:00
|
|
|
pGraphic: TX2GraphicContainerItem;
|
2004-09-02 10:36:24 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if Active(iIndex, pGraphic) then
|
|
|
|
if Assigned(pGraphic.Picture.Graphic) then begin
|
|
|
|
pClass := TGraphicClass(pGraphic.Picture.Graphic.ClassType);
|
|
|
|
dlgSave.Filter := GraphicFilter(pClass);
|
2007-01-04 19:47:47 +00:00
|
|
|
dlgSave.FileName := ChangeFileExt(pGraphic.PictureName, '.' + GraphicExtension(pClass));
|
2004-09-02 10:36:24 +00:00
|
|
|
|
|
|
|
if dlgSave.Execute() then
|
|
|
|
pGraphic.Picture.SaveToFile(dlgSave.FileName);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TfrmGraphicsEditor.actClearExecute(Sender: TObject);
|
2004-09-02 10:36:24 +00:00
|
|
|
var
|
|
|
|
iIndex: Integer;
|
2007-01-04 19:47:47 +00:00
|
|
|
pGraphic: TX2GraphicContainerItem;
|
2004-09-02 10:36:24 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
if Active(iIndex, pGraphic) then
|
|
|
|
begin
|
|
|
|
pGraphic.Picture.Assign(nil);
|
|
|
|
UpdatePreview();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
|
|
|
|
procedure TfrmGraphicsEditor.Notification(AComponent: TComponent; Operation: TOperation);
|
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
if (Operation = opRemove) and (AComponent = FComponent) then
|
|
|
|
begin
|
|
|
|
FComponent := nil;
|
|
|
|
Close();
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2004-09-02 10:36:24 +00:00
|
|
|
end.
|