1
0
mirror of synced 2024-11-22 01:53:50 +00:00

Fixed: designtime editor updates properly

Fixed: moving images in a graphiclist
This commit is contained in:
Mark van Renswoude 2007-04-02 14:45:31 +00:00
parent ced0de69b1
commit 669cf750dc
3 changed files with 132 additions and 38 deletions

View File

@ -135,6 +135,7 @@ ProductName=
ProductVersion=1.0.0.0
Comments=
[Excluded Packages]
P:\Algemeen\components\X2CL\Lib\D7\X2CLGLD.bpl=X²CL GraphicList (Designtime)
C:\Program Files\Borland\Indy\D7\dclIndy70.bpl=Internet Direct (Indy) for D7 Property and Component Editors
[HistoryLists\hlUnitAliases]
Count=1

View File

@ -74,6 +74,8 @@ type
procedure InternalExecute(const AComponent: TComponent; const ADesigner: IDesigner);
procedure LoadGraphic(AIndex: Integer; AGraphic: TX2GraphicContainerItem; const AFileName: string);
procedure ItemChanged(AUpdatePreview: Boolean = True);
procedure UpdateUI();
procedure UpdatePreview();
@ -153,6 +155,17 @@ begin
end;
procedure TGraphicsEditorForm.LoadGraphic(AIndex: Integer; AGraphic: TX2GraphicContainerItem; const AFileName: string);
begin
AGraphic.Picture.LoadFromFile(AFileName);
if Length(AGraphic.PictureName) = 0 then
begin
AGraphic.PictureName := ChangeFileExt(ExtractFileName(AFileName), '');
lstGraphics.Items[AIndex] := AGraphic.PictureName;
end;
end;
procedure TGraphicsEditorForm.ItemChanged(AUpdatePreview: Boolean);
begin
if Assigned(FComponentDesigner) then
@ -201,6 +214,11 @@ begin
begin
imgPreview.Picture.Assign(graphic.Picture);
txtName.Text := graphic.PictureName;
lstGraphics.Items[index] := graphic.PictureName;
end else
begin
imgPreview.Picture.Assign(nil);
txtName.Text := '';
end;
finally
FUpdating := False;
@ -251,24 +269,33 @@ procedure TGraphicsEditorForm.actAddExecute(Sender: TObject);
var
index: Integer;
graphic: TX2GraphicContainerItem;
fileIndex: Integer;
begin
if Assigned(FComponentDesigner) then
begin
dlgOpen.Filter := GraphicFilter(TGraphic);
dlgOpen.Options := dlgOpen.Options + [ofAllowMultiSelect];
if dlgOpen.Execute() then
begin
for fileIndex := 0 to Pred(dlgOpen.Files.Count) do
begin
graphic := TX2GraphicContainerItem(FComponentDesigner.CreateComponent(TX2GraphicContainerItem, nil, 0, 0, 0, 0));
if Assigned(graphic) then
begin
graphic.Container := FComponent;
index := lstGraphics.Items.AddObject(graphic.PictureName,
graphic);
index := lstGraphics.Items.AddObject('', graphic);
lstGraphics.ItemIndex := index;
ItemChanged();
actOpen.Execute();
LoadGraphic(index, graphic, dlgOpen.Files[fileIndex]);
end else
raise Exception.Create('Failed to create TX2GraphicContainerItem!');
end;
ItemChanged();
end;
end else
raise Exception.Create('Designer not found!');
end;
@ -343,12 +370,11 @@ begin
if Active(index, graphic) then
begin
dlgOpen.Filter := GraphicFilter(TGraphic);
dlgOpen.Options := dlgOpen.Options - [ofAllowMultiSelect];
if dlgOpen.Execute() then
begin
graphic.Picture.LoadFromFile(dlgOpen.FileName);
if Length(graphic.PictureName) = 0 then
graphic.PictureName := ChangeFileExt(ExtractFileName(dlgOpen.FileName), '');
LoadGraphic(index, graphic, dlgOpen.FileName);
ItemChanged();
end;
end;

View File

@ -101,6 +101,7 @@ type
procedure AddGraphic(const AGraphic: TX2GraphicContainerItem); virtual;
procedure RemoveGraphic(const AGraphic: TX2GraphicContainerItem); virtual;
procedure UpdateGraphic(const AGraphic: TX2GraphicContainerItem); virtual;
procedure MoveGraphic(const AGraphic: TX2GraphicContainerItem; ANewIndex: Integer); virtual;
procedure RegisterList(const AList: TX2GraphicList);
procedure UnregisterList(const AList: TX2GraphicList);
@ -167,6 +168,7 @@ type
procedure AddImage(const AIndex: Integer); virtual;
procedure UpdateImage(const AIndex: Integer); virtual;
procedure DeleteImage(const AIndex: Integer); virtual;
procedure MoveImage(const AOldIndex, ANewIndex: Integer); virtual;
procedure RebuildImages(); virtual;
@ -194,6 +196,7 @@ uses
ImgList,
SysUtils;
type
PClass = ^TClass;
@ -231,6 +234,7 @@ begin
FPicture.PictureAdapter := Self;
end;
destructor TX2GraphicContainerItem.Destroy();
begin
if Assigned(Container) then
@ -284,6 +288,7 @@ begin
Result := inherited GetParentComponent();
end;
function TX2GraphicContainerItem.HasParent(): Boolean;
begin
if Assigned(Container) then
@ -302,6 +307,7 @@ begin
Container := TX2GraphicContainer(Reader.Parent);
end;
procedure TX2GraphicContainerItem.SetParentComponent(AParent: TComponent);
begin
if not (csLoading in ComponentState) and (AParent is TX2GraphicContainer) then
@ -316,6 +322,7 @@ begin
Result := Container.GraphicsList.IndexOf(Self);
end;
procedure TX2GraphicContainerItem.SetContainer(const Value: TX2GraphicContainer);
begin
if Value <> Container then
@ -331,31 +338,14 @@ begin
end;
end;
procedure TX2GraphicContainerItem.SetIndex(const Value: Integer);
var
count: Integer;
curIndex: Integer;
newIndex: Integer;
begin
curIndex := GetIndex();
if curIndex > -1 then
begin
count := Container.GraphicsList.Count;
newIndex := Value;
if newIndex < 0 then
newIndex := 0;
if newIndex >= count then
newIndex := Pred(count);
if newIndex <> curIndex then
Container.GraphicsList.Move(curIndex, newIndex);
end;
if Assigned(Container) then
Container.MoveGraphic(Self, Value);
end;
procedure TX2GraphicContainerItem.SetPicture(const Value: TPicture);
begin
FPicture.Assign(Value);
@ -442,6 +432,7 @@ begin
FLists := TList.Create();
end;
destructor TX2GraphicContainer.Destroy();
begin
Clear();
@ -468,6 +459,7 @@ begin
end;
end;
function TX2GraphicContainer.GraphicByName(const AName: String): TX2GraphicContainerItem;
var
graphicIndex: Integer;
@ -479,6 +471,7 @@ begin
Result := Graphics[graphicIndex];
end;
function TX2GraphicContainer.PictureByName(const AName: String): TPicture;
var
graphic: TX2GraphicContainerItem;
@ -535,6 +528,7 @@ begin
end;
end;
procedure TX2GraphicContainer.SetChildOrder(Component: TComponent; Order: Integer);
begin
if GraphicsList.IndexOf(Component) >= 0 then
@ -648,6 +642,7 @@ begin
TX2GraphicList(Lists[listIndex]).AddImage(graphicIndex);
end;
procedure TX2GraphicContainer.RemoveGraphic(const AGraphic: TX2GraphicContainerItem);
var
graphicIndex: Integer;
@ -666,6 +661,7 @@ begin
end;
end;
procedure TX2GraphicContainer.UpdateGraphic(const AGraphic: TX2GraphicContainerItem);
var
graphicIndex: Integer;
@ -682,6 +678,49 @@ begin
end;
procedure TX2GraphicContainer.MoveGraphic(const AGraphic: TX2GraphicContainerItem; ANewIndex: Integer);
var
count: Integer;
curIndex: Integer;
newIndex: Integer;
listIndex: Integer;
begin
if not Assigned(AGraphic.Container) then
Exit;
if AGraphic.Container <> Self then
begin
AGraphic.Container.MoveGraphic(AGraphic, ANewIndex);
Exit;
end;
curIndex := AGraphic.Index;
if curIndex > -1 then
begin
count := GraphicsList.Count;
newIndex := ANewIndex;
if newIndex < 0 then
newIndex := 0;
if newIndex >= count then
newIndex := Pred(count);
if newIndex <> curIndex then
begin
GraphicsList.Move(curIndex, newIndex);
for listIndex := Pred(Lists.Count) downto 0 do
TX2GraphicList(Lists[listIndex]).MoveImage(curIndex, newIndex);
end;
end;
end;
procedure TX2GraphicContainer.RegisterList(const AList: TX2GraphicList);
begin
if Lists.IndexOf(AList) = -1 then
@ -691,6 +730,7 @@ begin
end;
end;
procedure TX2GraphicContainer.UnregisterList(const AList: TX2GraphicList);
begin
if Lists.Remove(AList) > -1 then
@ -704,6 +744,7 @@ begin
Result := GraphicsList.Count;
end;
function TX2GraphicContainer.GetGraphics(Index: Integer): TX2GraphicContainerItem;
begin
Result := TX2GraphicContainerItem(GraphicsList[Index]);
@ -730,6 +771,7 @@ begin
FStretchMode := smCrop;
end;
procedure TX2GraphicList.Loaded();
begin
inherited;
@ -737,6 +779,7 @@ begin
RebuildImages();
end;
procedure TX2GraphicList.Change();
begin
inherited;
@ -912,6 +955,7 @@ begin
Result := True;
end;
procedure TX2GraphicList.DoDraw(Index: Integer; Canvas: TCanvas; X, Y: Integer;
Style: Cardinal; Enabled: Boolean = True);
begin
@ -1060,6 +1104,7 @@ begin
end;
end;
procedure TX2GraphicList.AddImage(const AIndex: Integer);
var
bmpImage: TBitmap;
@ -1090,6 +1135,7 @@ begin
end;
end;
procedure TX2GraphicList.UpdateImage(const AIndex: Integer);
var
bmpImage: TBitmap;
@ -1118,6 +1164,7 @@ begin
end;
end;
procedure TX2GraphicList.DeleteImage(const AIndex: Integer);
begin
BeginUpdate();
@ -1129,6 +1176,17 @@ begin
end;
procedure TX2GraphicList.MoveImage(const AOldIndex, ANewIndex: Integer);
begin
BeginUpdate();
try
Move(AOldIndex, ANewIndex);
finally
EndUpdate();
end;
end;
procedure TX2GraphicList.RebuildImages();
var
iIndex: Integer;
@ -1178,6 +1236,7 @@ begin
end;
end;
procedure TX2GraphicList.Notification(AComponent: TComponent;
Operation: TOperation);
begin
@ -1194,6 +1253,7 @@ begin
RebuildImages();
end;
procedure TX2GraphicList.SetContainer(const Value: TX2GraphicContainer);
begin
if Assigned(FContainer) then
@ -1213,6 +1273,7 @@ begin
RebuildImages();
end;
procedure TX2GraphicList.SetConvert(const Value: Boolean);
begin
if Value <> FConvert then
@ -1222,12 +1283,14 @@ begin
end;
end;
procedure TX2GraphicList.SetEnabled(const Value: Boolean);
begin
FEnabled := Value;
RebuildImages();
end;
procedure TX2GraphicList.SetStretchMode(const Value: TX2GLStretchMode);
begin
FStretchMode := Value;
@ -1240,6 +1303,7 @@ begin
Inc(FUpdateCount);
end;
procedure TX2GraphicList.EndUpdate();
begin
Assert(FUpdateCount > 0, 'EndUpdate without matching BeginUpdate!');
@ -1256,6 +1320,7 @@ begin
FPicture := TPicture.Create();
end;
destructor TDeprecatedGraphicItem.Destroy();
begin
FreeAndNil(FPicture);
@ -1263,12 +1328,14 @@ begin
inherited;
end;
procedure TDeprecatedGraphicItem.SetPicture(const Value: TPicture);
begin
FPicture.Assign(Value);
end;
initialization
RegisterClass(TX2GraphicContainerItem);