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

Added: IndexByName, GraphicByName and PictureByName methods

Changed: shortcut for deleting items in the design-time editor from Del to Ctrl-Del (Clear changed from Ctrl-Del to Ctrl-Shift-Del), it conflicted with using Del in the Name box
This commit is contained in:
Mark van Renswoude 2005-03-26 17:06:08 +00:00
parent 713484f798
commit 8e3fb92a69
4 changed files with 119 additions and 54 deletions

View File

@ -238,6 +238,3 @@ H:\Downloads\commentexpert.bpl=Comment Expert v1.0 Alpha
c:\program files\borland\delphi6\Projects\Bpl\dclIndy60.bpl=Internet Direct (Indy) for D6 Property and Component Editors c:\program files\borland\delphi6\Projects\Bpl\dclIndy60.bpl=Internet Direct (Indy) for D6 Property and Component Editors
C:\WINDOWS\System32\ibevnt60.bpl=Borland Interbase Event Alerter Component C:\WINDOWS\System32\ibevnt60.bpl=Borland Interbase Event Alerter Component
c:\program files\borland\delphi6\Projects\Bpl\PngComponentsDesigntime.bpl=Png components designtime c:\program files\borland\delphi6\Projects\Bpl\PngComponentsDesigntime.bpl=Png components designtime
[HistoryLists\hlUnitAliases]
Count=1
Item0=WinTypes=Windows;WinProcs=Windows;DbiTypes=BDE;DbiProcs=BDE;DbiErrs=BDE;

View File

@ -21,7 +21,6 @@ object frmGraphicsEditor: TfrmGraphicsEditor
Top = 0 Top = 0
Width = 4 Width = 4
Height = 424 Height = 424
Cursor = crHSplit
end end
object pnlImage: TPanel object pnlImage: TPanel
Left = 193 Left = 193
@ -586,7 +585,7 @@ object frmGraphicsEditor: TfrmGraphicsEditor
Caption = '&Delete' Caption = '&Delete'
Hint = 'Delete Graphic' Hint = 'Delete Graphic'
ImageIndex = 1 ImageIndex = 1
ShortCut = 46 ShortCut = 16430
OnExecute = actDeleteExecute OnExecute = actDeleteExecute
end end
object actOpen: TAction object actOpen: TAction
@ -607,7 +606,7 @@ object frmGraphicsEditor: TfrmGraphicsEditor
Caption = '&Clear' Caption = '&Clear'
Hint = 'Clear Graphic' Hint = 'Clear Graphic'
ImageIndex = 4 ImageIndex = 4
ShortCut = 16430 ShortCut = 24622
OnExecute = actClearExecute OnExecute = actClearExecute
end end
object actUp: TAction object actUp: TAction

View File

@ -291,7 +291,7 @@ begin
begin begin
pGraphic.Picture.LoadFromFile(dlgOpen.FileName); pGraphic.Picture.LoadFromFile(dlgOpen.FileName);
if Length(pGraphic.Name) = 0 then if Length(pGraphic.Name) = 0 then
pGraphic.Name := ExtractFileName(dlgOpen.FileName); pGraphic.Name := ChangeFileExt(ExtractFileName(dlgOpen.FileName), '');
UpdatePreview(); UpdatePreview();
end; end;

View File

@ -78,6 +78,9 @@ type
constructor Create(const AContainer: TX2GraphicContainer); constructor Create(const AContainer: TX2GraphicContainer);
function Add(): TX2GraphicCollectionItem; function Add(): TX2GraphicCollectionItem;
function IndexByName(const AName: String): Integer;
function GraphicByName(const AName: String): TX2GraphicCollectionItem;
function PictureByName(const AName: String): TPicture;
property Items[Index: Integer]: TX2GraphicCollectionItem read GetItem property Items[Index: Integer]: TX2GraphicCollectionItem read GetItem
write SetItem; default; write SetItem; default;
@ -106,6 +109,10 @@ type
constructor Create(AOwner: TComponent); override; constructor Create(AOwner: TComponent); override;
destructor Destroy(); override; destructor Destroy(); override;
function IndexByName(const AName: String): Integer;
function GraphicByName(const AName: String): TX2GraphicCollectionItem;
function PictureByName(const AName: String): TPicture;
procedure AssignTo(Dest: TPersistent); override; procedure AssignTo(Dest: TPersistent); override;
published published
property Graphics: TX2GraphicCollection read FGraphics write SetGraphics; property Graphics: TX2GraphicCollection read FGraphics write SetGraphics;
@ -183,7 +190,7 @@ type
{=============== TX2GraphicCollectionItem {=============== TX2GraphicCollectionItem
Initialization Initialization
========================================} ========================================}
constructor TX2GraphicCollectionItem.Create; constructor TX2GraphicCollectionItem.Create(Collection: TCollection);
begin begin
FPicture := TPicture.Create(); FPicture := TPicture.Create();
FPicture.PictureAdapter := Self; FPicture.PictureAdapter := Self;
@ -191,7 +198,7 @@ begin
inherited; inherited;
end; end;
destructor TX2GraphicCollectionItem.Destroy; destructor TX2GraphicCollectionItem.Destroy();
begin begin
FreeAndNil(FPicture); FreeAndNil(FPicture);
@ -199,7 +206,7 @@ begin
end; end;
procedure TX2GraphicCollectionItem.AssignTo; procedure TX2GraphicCollectionItem.AssignTo(Dest: TPersistent);
begin begin
if Dest is TX2GraphicCollectionItem then if Dest is TX2GraphicCollectionItem then
with TX2GraphicCollectionItem(Dest) do with TX2GraphicCollectionItem(Dest) do
@ -209,7 +216,8 @@ begin
end; end;
function TX2GraphicCollectionItem.QueryInterface; function TX2GraphicCollectionItem.QueryInterface(const IID: TGUID;
out Obj): HResult;
begin begin
if GetInterface(IID, Obj) then if GetInterface(IID, Obj) then
Result := 0 Result := 0
@ -217,18 +225,18 @@ begin
Result := E_NOINTERFACE; Result := E_NOINTERFACE;
end; end;
function TX2GraphicCollectionItem._AddRef; function TX2GraphicCollectionItem._AddRef(): Integer;
begin begin
Result := -1; Result := -1;
end; end;
function TX2GraphicCollectionItem._Release; function TX2GraphicCollectionItem._Release(): Integer;
begin begin
Result := -1; Result := -1;
end; end;
function TX2GraphicCollectionItem.GetDisplayName; function TX2GraphicCollectionItem.GetDisplayName(): String;
begin begin
if Length(FName) > 0 then if Length(FName) > 0 then
Result := FName Result := FName
@ -237,18 +245,18 @@ begin
end; end;
procedure TX2GraphicCollectionItem.NotifierChanged; procedure TX2GraphicCollectionItem.NotifierChanged();
begin begin
Changed(False); Changed(False);
end; end;
procedure TX2GraphicCollectionItem.SetName; procedure TX2GraphicCollectionItem.SetName(const Value: String);
begin begin
FName := Value; FName := Value;
Changed(False); Changed(False);
end; end;
procedure TX2GraphicCollectionItem.SetPicture; procedure TX2GraphicCollectionItem.SetPicture(const Value: TPicture);
begin begin
FPicture.Assign(Value); FPicture.Assign(Value);
end; end;
@ -257,7 +265,7 @@ end;
{=================== TX2GraphicCollection {=================== TX2GraphicCollection
Item Management Item Management
========================================} ========================================}
constructor TX2GraphicCollection.Create; constructor TX2GraphicCollection.Create(const AContainer: TX2GraphicContainer);
begin begin
inherited Create(TX2GraphicCollectionItem); inherited Create(TX2GraphicCollectionItem);
@ -265,21 +273,59 @@ begin
end; end;
function TX2GraphicCollection.Add; function TX2GraphicCollection.Add(): TX2GraphicCollectionItem;
begin begin
Result := TX2GraphicCollectionItem(inherited Add()); Result := TX2GraphicCollectionItem(inherited Add());
end; end;
procedure TX2GraphicCollection.Notify; function TX2GraphicCollection.IndexByName(const AName: String): Integer;
var
iIndex: Integer;
begin
Result := -1;
for iIndex := Pred(Count) downto 0 do
if SameText(Items[iIndex].Name, AName) then
begin
Result := iIndex;
break;
end;
end;
function TX2GraphicCollection.GraphicByName(const AName: String): TX2GraphicCollectionItem;
var
iIndex: Integer;
begin
Result := nil;
iIndex := IndexByName(AName);
if iIndex > -1 then
Result := Items[iIndex];
end;
function TX2GraphicCollection.PictureByName(const AName: String): TPicture;
var
pGraphic: TX2GraphicCollectionItem;
begin
Result := nil;
pGraphic := GraphicByName(AName);
if Assigned(pGraphic) then
Result := pGraphic.Picture;
end;
procedure TX2GraphicCollection.Notify(Item: TCollectionItem;
Action: TCollectionNotification);
begin begin
inherited; inherited;
if Assigned(FContainer) then if Assigned(FContainer) then
FContainer.Notify(Item, Action); FContainer.Notify(Item, Action);
end; end;
procedure TX2GraphicCollection.Update; procedure TX2GraphicCollection.Update(Item: TCollectionItem);
begin begin
inherited; inherited;
@ -288,12 +334,12 @@ begin
end; end;
function TX2GraphicCollection.GetItem; function TX2GraphicCollection.GetItem(Index: Integer): TX2GraphicCollectionItem;
begin begin
Result := TX2GraphicCollectionItem(inherited GetItem(Index)); Result := TX2GraphicCollectionItem(inherited GetItem(Index));
end; end;
procedure TX2GraphicCollection.SetItem; procedure TX2GraphicCollection.SetItem(Index: Integer; Value: TX2GraphicCollectionItem);
begin begin
inherited SetItem(Index, Value); inherited SetItem(Index, Value);
end; end;
@ -302,7 +348,7 @@ end;
{==================== TX2GraphicContainer {==================== TX2GraphicContainer
Initialization Initialization
========================================} ========================================}
constructor TX2GraphicContainer.Create; constructor TX2GraphicContainer.Create(AOwner: TComponent);
begin begin
inherited; inherited;
@ -310,7 +356,7 @@ begin
FLists := TList.Create(); FLists := TList.Create();
end; end;
destructor TX2GraphicContainer.Destroy; destructor TX2GraphicContainer.Destroy();
begin begin
FreeAndNil(FGraphics); FreeAndNil(FGraphics);
FreeAndNil(FLists); FreeAndNil(FLists);
@ -319,7 +365,23 @@ begin
end; end;
procedure TX2GraphicContainer.AssignTo; function TX2GraphicContainer.IndexByName(const AName: String): Integer;
begin
Result := FGraphics.IndexByName(AName);
end;
function TX2GraphicContainer.GraphicByName(const AName: String): TX2GraphicCollectionItem;
begin
Result := FGraphics.GraphicByName(AName);
end;
function TX2GraphicContainer.PictureByName(const AName: String): TPicture;
begin
Result := FGraphics.PictureByName(AName);
end;
procedure TX2GraphicContainer.AssignTo(Dest: TPersistent);
begin begin
if Dest is TX2GraphicContainer then if Dest is TX2GraphicContainer then
with TX2GraphicContainer(Dest) do with TX2GraphicContainer(Dest) do
@ -330,7 +392,7 @@ end;
procedure TX2GraphicContainer.Notification; procedure TX2GraphicContainer.Notification(AComponent: TComponent; Operation: TOperation);
begin begin
if not Assigned(FLists) then if not Assigned(FLists) then
exit; exit;
@ -348,7 +410,8 @@ begin
inherited; inherited;
end; end;
procedure TX2GraphicContainer.Notify; procedure TX2GraphicContainer.Notify(Item: TCollectionItem;
Action: TCollectionNotification);
var var
iList: Integer; iList: Integer;
@ -363,7 +426,7 @@ begin
end; end;
end; end;
procedure TX2GraphicContainer.Update; procedure TX2GraphicContainer.Update(Item: TCollectionItem);
var var
iList: Integer; iList: Integer;
@ -377,19 +440,19 @@ begin
end; end;
procedure TX2GraphicContainer.RegisterList; procedure TX2GraphicContainer.RegisterList(const AList: TX2GraphicList);
begin begin
if FLists.IndexOf(AList) = -1 then if FLists.IndexOf(AList) = -1 then
FLists.Add(AList); FLists.Add(AList);
end; end;
procedure TX2GraphicContainer.UnregisterList; procedure TX2GraphicContainer.UnregisterList(const AList: TX2GraphicList);
begin begin
FLists.Remove(AList); FLists.Remove(AList);
end; end;
procedure TX2GraphicContainer.SetGraphics; procedure TX2GraphicContainer.SetGraphics(const Value: TX2GraphicCollection);
begin begin
FGraphics.Assign(Value); FGraphics.Assign(Value);
end; end;
@ -399,7 +462,7 @@ end;
{========================= TX2GraphicList {========================= TX2GraphicList
Initialization Initialization
========================================} ========================================}
constructor TX2GraphicList.Create; constructor TX2GraphicList.Create(AOwner: TComponent);
begin begin
inherited; inherited;
@ -409,14 +472,14 @@ begin
FStretchMode := smCrop; FStretchMode := smCrop;
end; end;
procedure TX2GraphicList.Loaded; procedure TX2GraphicList.Loaded();
begin begin
inherited; inherited;
RebuildImages(); RebuildImages();
end; end;
procedure TX2GraphicList.Change; procedure TX2GraphicList.Change();
begin begin
inherited; inherited;
@ -425,7 +488,7 @@ begin
end; end;
destructor TX2GraphicList.Destroy; destructor TX2GraphicList.Destroy();
begin begin
SetContainer(nil); SetContainer(nil);
@ -433,7 +496,7 @@ begin
end; end;
procedure TX2GraphicList.AssignTo; procedure TX2GraphicList.AssignTo(Dest: TPersistent);
begin begin
if Dest is TX2GraphicList then if Dest is TX2GraphicList then
with TX2GraphicList(Dest) do with TX2GraphicList(Dest) do
@ -452,7 +515,10 @@ end;
{========================= TX2GraphicList {========================= TX2GraphicList
Graphics Graphics
========================================} ========================================}
function TX2GraphicList.DrawGraphic; function TX2GraphicList.DrawGraphic(const AIndex: Integer;
const ACanvas: TCanvas;
const AX, AY: Integer;
const AEnabled: Boolean = True): Boolean;
procedure InternalDrawGraphic(const ADest: TCanvas; procedure InternalDrawGraphic(const ADest: TCanvas;
const ADestX, ADestY: Integer); const ADestX, ADestY: Integer);
var var
@ -588,13 +654,15 @@ begin
Result := True; Result := True;
end; end;
procedure TX2GraphicList.DoDraw; procedure TX2GraphicList.DoDraw(Index: Integer; Canvas: TCanvas; X, Y: Integer;
Style: Cardinal; Enabled: Boolean = True);
begin begin
DrawGraphic(Index, Canvas, X, Y, Enabled); DrawGraphic(Index, Canvas, X, Y, Enabled);
end; end;
procedure TX2GraphicList.CreateImage; procedure TX2GraphicList.CreateImage(const AIndex: Integer;
var AImage, AMask: TBitmap);
function RGBTriple(const AColor: TColor): TRGBTriple; function RGBTriple(const AColor: TColor): TRGBTriple;
var var
cColor: Cardinal; cColor: Cardinal;
@ -723,7 +791,7 @@ begin
end; end;
end; end;
procedure TX2GraphicList.AddImage; procedure TX2GraphicList.AddImage(const AIndex: Integer);
var var
bmpImage: TBitmap; bmpImage: TBitmap;
bmpMask: TBitmap; bmpMask: TBitmap;
@ -753,7 +821,7 @@ begin
end; end;
end; end;
procedure TX2GraphicList.UpdateImage; procedure TX2GraphicList.UpdateImage(const AIndex: Integer);
var var
bmpImage: TBitmap; bmpImage: TBitmap;
bmpMask: TBitmap; bmpMask: TBitmap;
@ -778,7 +846,7 @@ begin
end; end;
end; end;
procedure TX2GraphicList.DeleteImage; procedure TX2GraphicList.DeleteImage(const AIndex: Integer);
begin begin
BeginUpdate(); BeginUpdate();
try try
@ -789,7 +857,7 @@ begin
end; end;
procedure TX2GraphicList.RebuildImages; procedure TX2GraphicList.RebuildImages();
var var
iIndex: Integer; iIndex: Integer;
@ -816,7 +884,7 @@ end;
{========================= TX2GraphicList {========================= TX2GraphicList
Properties Properties
========================================} ========================================}
procedure TX2GraphicList.DefineProperties; procedure TX2GraphicList.DefineProperties(Filer: TFiler);
var var
pType: TClass; pType: TClass;
@ -838,22 +906,23 @@ begin
end; end;
end; end;
procedure TX2GraphicList.Notification; procedure TX2GraphicList.Notification(AComponent: TComponent;
Operation: TOperation);
begin begin
if (Operation = opRemove) and (AComponent = FContainer) then if (Operation = opRemove) and (AComponent = FContainer) then
FContainer := nil; FContainer := nil;
inherited; inherited;
end; end;
procedure TX2GraphicList.SetBackground; procedure TX2GraphicList.SetBackground(const Value: TColor);
begin begin
FBackground := Value; FBackground := Value;
RebuildImages(); RebuildImages();
end; end;
procedure TX2GraphicList.SetContainer; procedure TX2GraphicList.SetContainer(const Value: TX2GraphicContainer);
begin begin
if Assigned(FContainer) then if Assigned(FContainer) then
begin begin
@ -872,25 +941,25 @@ begin
RebuildImages(); RebuildImages();
end; end;
procedure TX2GraphicList.SetEnabled; procedure TX2GraphicList.SetEnabled(const Value: Boolean);
begin begin
FEnabled := Value; FEnabled := Value;
RebuildImages(); RebuildImages();
end; end;
procedure TX2GraphicList.SetStretchMode; procedure TX2GraphicList.SetStretchMode(const Value: TX2GLStretchMode);
begin begin
FStretchMode := Value; FStretchMode := Value;
RebuildImages(); RebuildImages();
end; end;
procedure TX2GraphicList.BeginUpdate; procedure TX2GraphicList.BeginUpdate();
begin 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!');
Dec(FUpdateCount); Dec(FUpdateCount);