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 ProductVersion=1.0.0.0
Comments= Comments=
[Excluded Packages] [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 C:\Program Files\Borland\Indy\D7\dclIndy70.bpl=Internet Direct (Indy) for D7 Property and Component Editors
[HistoryLists\hlUnitAliases] [HistoryLists\hlUnitAliases]
Count=1 Count=1

View File

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

View File

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