2004-08-31 14:40:07 +00:00
|
|
|
{
|
|
|
|
:: X2CLGraphicList contains a container component for TGraphic
|
|
|
|
:: descendants and a replacement for TImageList.
|
|
|
|
::
|
2004-09-01 11:19:37 +00:00
|
|
|
:: Many thanks to Erik Stok. Before I could even work out the idea, he not
|
|
|
|
:: only had a similar idea, but created TPngImageList and worked out many of
|
|
|
|
:: the problems I thought we would face. His original (Dutch) article can
|
|
|
|
:: be found at:
|
2004-08-31 14:40:07 +00:00
|
|
|
:: http://www.erikstok.net/delphi/artikelen/xpicons.html
|
2009-02-25 11:31:18 +00:00
|
|
|
::
|
2004-08-31 14:40:07 +00:00
|
|
|
:: Last changed: $Date$
|
|
|
|
:: Revision: $Rev$
|
|
|
|
:: Author: $Author$
|
|
|
|
}
|
|
|
|
unit X2CLGraphicList;
|
|
|
|
|
|
|
|
interface
|
|
|
|
uses
|
|
|
|
Windows,
|
|
|
|
|
|
|
|
Classes,
|
|
|
|
Controls,
|
|
|
|
Graphics;
|
|
|
|
|
2004-09-25 16:19:08 +00:00
|
|
|
{$IFDEF VER150}
|
|
|
|
{$WARN UNSAFE_CODE OFF}
|
|
|
|
{$WARN UNSAFE_CAST OFF}
|
2009-02-25 11:31:18 +00:00
|
|
|
{$WARN UNSAFE_TYPE OFF}
|
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
{$IFDEF VER180}
|
|
|
|
{$WARN UNSAFE_CODE OFF}
|
|
|
|
{$WARN UNSAFE_CAST OFF}
|
|
|
|
{$WARN UNSAFE_TYPE OFF}
|
2004-09-25 16:19:08 +00:00
|
|
|
{$ENDIF}
|
|
|
|
|
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
type
|
|
|
|
// Forward declarations
|
|
|
|
TX2GraphicList = class;
|
|
|
|
TX2GraphicContainer = class;
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
|
|
|
|
TX2GLCustomDrawImageProc = function(ACanvas: TCanvas;
|
|
|
|
AGraphicList: TX2GraphicList;
|
|
|
|
AIndex: Integer;
|
|
|
|
AX, AY: Integer;
|
|
|
|
AEnabled: Boolean): Boolean;
|
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
{
|
|
|
|
:$ Holds a single graphic.
|
|
|
|
}
|
2007-01-04 19:47:47 +00:00
|
|
|
TX2GraphicContainerItem = class(TComponent, IChangeNotifier)
|
2004-08-31 14:40:07 +00:00
|
|
|
private
|
2007-01-04 19:47:47 +00:00
|
|
|
FContainer: TX2GraphicContainer;
|
2004-08-31 14:40:07 +00:00
|
|
|
FPicture: TPicture;
|
2007-01-04 19:47:47 +00:00
|
|
|
FPictureName: String;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
function GetIndex: Integer;
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure SetContainer(const Value: TX2GraphicContainer);
|
|
|
|
procedure SetIndex(const Value: Integer);
|
2004-08-31 14:40:07 +00:00
|
|
|
procedure SetPicture(const Value: TPicture);
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure SetPictureName(const Value: String);
|
2004-08-31 14:40:07 +00:00
|
|
|
protected
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure Changed; virtual;
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure InternalSetContainer(const AContainer: TX2GraphicContainer); virtual;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
function GenerateName: String;
|
2004-09-01 17:41:06 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure NotifierChanged;
|
2004-08-31 14:40:07 +00:00
|
|
|
procedure IChangeNotifier.Changed = NotifierChanged;
|
2007-01-04 19:47:47 +00:00
|
|
|
|
|
|
|
procedure ReadState(Reader: TReader); override;
|
|
|
|
procedure SetParentComponent(AParent: TComponent); override;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
|
|
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
2004-08-31 14:40:07 +00:00
|
|
|
public
|
2007-01-04 19:47:47 +00:00
|
|
|
constructor Create(AOwner: TComponent); override;
|
2009-02-25 11:31:18 +00:00
|
|
|
destructor Destroy; override;
|
2004-09-01 11:19:37 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
function GetParentComponent: TComponent; override;
|
|
|
|
function HasParent: Boolean; override;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure AssignTo(Dest: TPersistent); override;
|
2004-08-31 14:40:07 +00:00
|
|
|
public
|
2007-01-04 19:47:47 +00:00
|
|
|
property Container: TX2GraphicContainer read FContainer write SetContainer stored False;
|
|
|
|
property Index: Integer read GetIndex write SetIndex stored False;
|
|
|
|
published
|
|
|
|
property Picture: TPicture read FPicture write SetPicture;
|
|
|
|
property PictureName: String read FPictureName write SetPictureName;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Container object for graphics.
|
|
|
|
|
|
|
|
:: TX2GraphicContainer holds all the original graphic data. Link a container
|
|
|
|
:: to a TX2GraphicList to provide the graphics for various components.
|
|
|
|
}
|
|
|
|
TX2GraphicContainer = class(TComponent)
|
|
|
|
private
|
2007-01-04 19:47:47 +00:00
|
|
|
FConversionRequired: Boolean;
|
|
|
|
FGraphics: TList;
|
|
|
|
FLists: TList;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
function GetGraphicCount: Integer;
|
2007-01-04 19:47:47 +00:00
|
|
|
function GetGraphics(Index: Integer): TX2GraphicContainerItem;
|
|
|
|
procedure SetGraphics(Index: Integer; const Value: TX2GraphicContainerItem);
|
2004-08-31 14:40:07 +00:00
|
|
|
protected
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure GetChildren(Proc: TGetChildProc; Root: TComponent); override;
|
|
|
|
procedure SetChildOrder(Component: TComponent; Order: Integer); override;
|
|
|
|
procedure SetName(const NewName: TComponentName); override;
|
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
2007-01-04 19:47:47 +00:00
|
|
|
|
|
|
|
procedure ConvertGraphics(Reader: TReader);
|
|
|
|
procedure DefineProperties(Filer: TFiler); override;
|
|
|
|
|
|
|
|
procedure AddGraphic(const AGraphic: TX2GraphicContainerItem); virtual;
|
|
|
|
procedure RemoveGraphic(const AGraphic: TX2GraphicContainerItem); virtual;
|
|
|
|
procedure UpdateGraphic(const AGraphic: TX2GraphicContainerItem); virtual;
|
2007-04-02 14:45:31 +00:00
|
|
|
procedure MoveGraphic(const AGraphic: TX2GraphicContainerItem; ANewIndex: Integer); virtual;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
|
|
|
procedure RegisterList(const AList: TX2GraphicList);
|
|
|
|
procedure UnregisterList(const AList: TX2GraphicList);
|
2007-01-04 19:47:47 +00:00
|
|
|
|
|
|
|
property ConversionRequired: Boolean read FConversionRequired write FConversionRequired;
|
|
|
|
|
|
|
|
property GraphicsList: TList read FGraphics;
|
|
|
|
property Lists: TList read FLists;
|
2004-08-31 14:40:07 +00:00
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
2009-02-25 11:31:18 +00:00
|
|
|
destructor Destroy; override;
|
2004-09-01 11:19:37 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure Clear;
|
2007-01-04 19:47:47 +00:00
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
function IndexByName(const AName: String): Integer;
|
2007-01-04 19:47:47 +00:00
|
|
|
function GraphicByName(const AName: String): TX2GraphicContainerItem;
|
2005-03-26 17:06:08 +00:00
|
|
|
function PictureByName(const AName: String): TPicture;
|
|
|
|
|
2004-09-01 11:19:37 +00:00
|
|
|
procedure AssignTo(Dest: TPersistent); override;
|
2007-01-04 19:47:47 +00:00
|
|
|
|
|
|
|
property Graphics[Index: Integer]: TX2GraphicContainerItem read GetGraphics write SetGraphics;
|
|
|
|
property GraphicCount: Integer read GetGraphicCount;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ Defines the various modes for drawing a larger image.
|
|
|
|
}
|
|
|
|
TX2GLStretchMode = (smCrop, smStretch);
|
|
|
|
|
|
|
|
{
|
|
|
|
:$ ImageList replacement for graphics.
|
2005-12-13 15:05:09 +00:00
|
|
|
|
|
|
|
:: If you are only using components which use ImageList.Draw directly
|
|
|
|
:: instead of the ImageList_Draw API (for ex. TMainMenu), set the Convert
|
|
|
|
:: property to False to save some processing.
|
2004-08-31 14:40:07 +00:00
|
|
|
}
|
|
|
|
TX2GraphicList = class(TImageList)
|
|
|
|
private
|
|
|
|
FBackground: TColor;
|
|
|
|
FContainer: TX2GraphicContainer;
|
2005-12-13 15:05:09 +00:00
|
|
|
FConvert: Boolean;
|
2004-08-31 15:02:35 +00:00
|
|
|
FEnabled: Boolean;
|
2004-08-31 14:40:07 +00:00
|
|
|
FStretchMode: TX2GLStretchMode;
|
2004-08-31 15:02:35 +00:00
|
|
|
FUpdateCount: Integer;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
|
|
|
procedure SetBackground(const Value: TColor);
|
|
|
|
procedure SetContainer(const Value: TX2GraphicContainer);
|
2005-12-13 15:05:09 +00:00
|
|
|
procedure SetConvert(const Value: Boolean);
|
2004-08-31 15:02:35 +00:00
|
|
|
procedure SetEnabled(const Value: Boolean);
|
2005-12-13 15:05:09 +00:00
|
|
|
procedure SetStretchMode(const Value: TX2GLStretchMode);
|
2004-08-31 14:40:07 +00:00
|
|
|
protected
|
2010-07-12 07:37:54 +00:00
|
|
|
procedure ReadData(Stream: TStream); override;
|
|
|
|
procedure WriteData(Stream: TStream); override;
|
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
procedure Notification(AComponent: TComponent; Operation: TOperation); override;
|
|
|
|
|
2004-08-31 15:02:35 +00:00
|
|
|
function DrawGraphic(const AIndex: Integer;
|
|
|
|
const ACanvas: TCanvas;
|
|
|
|
const AX, AY: Integer;
|
|
|
|
const AEnabled: Boolean = True): Boolean;
|
|
|
|
|
|
|
|
procedure DoDraw(Index: Integer; Canvas: TCanvas; X, Y: Integer;
|
|
|
|
Style: Cardinal; Enabled: Boolean = True); override;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure BuildImage(const AIndex: Integer; const AImage, AMask: TBitmap); virtual;
|
2004-08-31 14:40:07 +00:00
|
|
|
procedure AddImage(const AIndex: Integer); virtual;
|
|
|
|
procedure UpdateImage(const AIndex: Integer); virtual;
|
|
|
|
procedure DeleteImage(const AIndex: Integer); virtual;
|
2007-04-02 14:45:31 +00:00
|
|
|
procedure MoveImage(const AOldIndex, ANewIndex: Integer); virtual;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
function CanConvert: Boolean;
|
2004-08-31 15:02:35 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure UpdateImageCount; virtual;
|
|
|
|
procedure RebuildImages; virtual;
|
|
|
|
|
|
|
|
procedure BeginUpdate;
|
|
|
|
procedure EndUpdate;
|
2004-08-31 14:40:07 +00:00
|
|
|
public
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
2009-02-25 11:31:18 +00:00
|
|
|
destructor Destroy; override;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2004-09-01 11:19:37 +00:00
|
|
|
procedure AssignTo(Dest: TPersistent); override;
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure Loaded; override;
|
|
|
|
procedure Change; override;
|
2004-08-31 14:40:07 +00:00
|
|
|
published
|
|
|
|
property Background: TColor read FBackground write SetBackground default clBtnFace;
|
|
|
|
property Container: TX2GraphicContainer read FContainer write SetContainer;
|
2005-12-13 15:05:09 +00:00
|
|
|
property Convert: Boolean read FConvert write SetConvert default True;
|
2004-09-01 07:58:26 +00:00
|
|
|
property Enabled: Boolean read FEnabled write SetEnabled default True;
|
2004-08-31 14:40:07 +00:00
|
|
|
property StretchMode: TX2GLStretchMode read FStretchMode write SetStretchMode default smCrop;
|
|
|
|
end;
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
|
|
|
|
procedure X2GLRegisterCustomDrawImageProc(ACustomDrawImageProc: TX2GLCustomDrawImageProc);
|
|
|
|
procedure X2GLUnregisterCustomDrawImageProc(ACustomDrawImageProc: TX2GLCustomDrawImageProc);
|
|
|
|
|
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
implementation
|
|
|
|
uses
|
2009-02-25 11:31:18 +00:00
|
|
|
CommCtrl,
|
2007-01-04 19:47:47 +00:00
|
|
|
Forms,
|
2004-08-31 14:40:07 +00:00
|
|
|
ImgList,
|
|
|
|
SysUtils;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
var
|
|
|
|
CustomDrawImageProcs: TList;
|
|
|
|
|
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
type
|
|
|
|
PClass = ^TClass;
|
|
|
|
|
|
|
|
PRGBTripleArray = ^TRGBTripleArray;
|
|
|
|
TRGBTripleArray = array[Word] of TRGBTriple;
|
|
|
|
|
|
|
|
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
{ Used for conversion purposes from the old collection-based Graphics property
|
|
|
|
to the new TComponent structure. }
|
|
|
|
TDeprecatedGraphicItem = class(TCollectionItem)
|
|
|
|
private
|
|
|
|
FName: String;
|
|
|
|
FPicture: TPicture;
|
|
|
|
|
|
|
|
procedure SetPicture(const Value: TPicture);
|
|
|
|
public
|
|
|
|
constructor Create(Collection: TCollection); override;
|
2009-02-25 11:31:18 +00:00
|
|
|
destructor Destroy; override;
|
2007-01-04 19:47:47 +00:00
|
|
|
published
|
|
|
|
property Name: String read FName write FName;
|
|
|
|
property Picture: TPicture read FPicture write SetPicture;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure X2GLRegisterCustomDrawImageProc(ACustomDrawImageProc: TX2GLCustomDrawImageProc);
|
|
|
|
var
|
|
|
|
procPointer: Pointer absolute ACustomDrawImageProc;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if CustomDrawImageProcs.IndexOf(procPointer) = -1 then
|
|
|
|
CustomDrawImageProcs.Add(procPointer);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure X2GLUnregisterCustomDrawImageProc(ACustomDrawImageProc: TX2GLCustomDrawImageProc);
|
|
|
|
var
|
|
|
|
procPointer: Pointer absolute ACustomDrawImageProc;
|
|
|
|
|
|
|
|
begin
|
|
|
|
CustomDrawImageProcs.Remove(procPointer);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
function CustomDrawImage(ACanvas: TCanvas; AGraphicList: TX2GraphicList;
|
|
|
|
AIndex: Integer; AX, AY: Integer; AEnabled: Boolean): Boolean;
|
|
|
|
var
|
|
|
|
customProcIndex: Integer;
|
|
|
|
customProc: TX2GLCustomDrawImageProc;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
|
|
|
|
for customProcIndex := Pred(CustomDrawImageProcs.Count) downto 0 do
|
|
|
|
begin
|
|
|
|
customProc := TX2GLCustomDrawImageProc(CustomDrawImageProcs[customProcIndex]);
|
|
|
|
|
|
|
|
if customProc(ACanvas, AGraphicList, AIndex, AX, AY, AEnabled) then
|
|
|
|
begin
|
|
|
|
Result := True;
|
|
|
|
Break;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
{================ TX2GraphicContainerItem
|
2004-08-31 14:40:07 +00:00
|
|
|
Initialization
|
|
|
|
========================================}
|
2007-01-04 19:47:47 +00:00
|
|
|
constructor TX2GraphicContainerItem.Create(AOwner: TComponent);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
inherited;
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
FPicture := TPicture.Create;
|
2004-08-31 14:40:07 +00:00
|
|
|
FPicture.PictureAdapter := Self;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
destructor TX2GraphicContainerItem.Destroy;
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
if Assigned(Container) then
|
|
|
|
Container.RemoveGraphic(Self);
|
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
FreeAndNil(FPicture);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TX2GraphicContainerItem.AssignTo(Dest: TPersistent);
|
2004-09-01 11:19:37 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
if Dest is TX2GraphicContainerItem then
|
|
|
|
with TX2GraphicContainerItem(Dest) do
|
|
|
|
begin
|
|
|
|
Picture := Self.Picture;
|
|
|
|
PictureName := Self.PictureName;
|
|
|
|
end
|
2004-09-01 11:19:37 +00:00
|
|
|
else
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure TX2GraphicContainerItem.NotifierChanged;
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2009-02-25 11:31:18 +00:00
|
|
|
Changed;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2GraphicContainerItem.Notification(AComponent: TComponent; Operation: TOperation);
|
|
|
|
begin
|
|
|
|
if (Operation = opRemove) and (AComponent = FContainer) then
|
|
|
|
FContainer := nil;
|
|
|
|
|
|
|
|
inherited;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TX2GraphicContainerItem.InternalSetContainer(const AContainer: TX2GraphicContainer);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2009-02-25 11:31:18 +00:00
|
|
|
if AContainer <> FContainer then
|
|
|
|
begin
|
|
|
|
if Assigned(FContainer) then
|
|
|
|
FContainer.RemoveFreeNotification(Self);
|
|
|
|
|
|
|
|
FContainer := AContainer;
|
|
|
|
|
|
|
|
if Assigned(FContainer) then
|
|
|
|
FContainer.FreeNotification(Self);
|
|
|
|
end;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure TX2GraphicContainerItem.Changed;
|
2004-09-01 17:41:06 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
if Assigned(Container) then
|
|
|
|
Container.UpdateGraphic(Self);
|
2004-09-01 17:41:06 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
function TX2GraphicContainerItem.GetParentComponent: TComponent;
|
2004-09-01 17:41:06 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
if Assigned(Container) then
|
|
|
|
Result := Container
|
|
|
|
else
|
2009-02-25 11:31:18 +00:00
|
|
|
Result := inherited GetParentComponent;
|
2004-09-01 17:41:06 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
function TX2GraphicContainerItem.HasParent: Boolean;
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
if Assigned(Container) then
|
|
|
|
Result := True
|
|
|
|
else
|
2009-02-25 11:31:18 +00:00
|
|
|
Result := inherited HasParent;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
|
|
|
|
procedure TX2GraphicContainerItem.ReadState(Reader: TReader);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
inherited;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
if Assigned(Reader.Parent) and (Reader.Parent is TX2GraphicContainer) then
|
2007-01-04 19:47:47 +00:00
|
|
|
Container := TX2GraphicContainer(Reader.Parent);
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TX2GraphicContainerItem.SetParentComponent(AParent: TComponent);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2009-02-25 11:31:18 +00:00
|
|
|
if (not (csLoading in ComponentState)) and
|
|
|
|
Assigned(AParent) and (AParent is TX2GraphicContainer) then
|
2007-01-04 19:47:47 +00:00
|
|
|
Container := TX2GraphicContainer(AParent);
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
function TX2GraphicContainerItem.GetIndex: Integer;
|
2005-03-26 17:06:08 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
Result := -1;
|
|
|
|
if Assigned(Container) then
|
|
|
|
Result := Container.GraphicsList.IndexOf(Self);
|
2005-03-26 17:06:08 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TX2GraphicContainerItem.SetContainer(const Value: TX2GraphicContainer);
|
2005-03-26 17:06:08 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
if Value <> Container then
|
|
|
|
begin
|
|
|
|
if Assigned(Container) then
|
|
|
|
Container.RemoveGraphic(Self);
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
if Assigned(Value) then
|
|
|
|
Value.AddGraphic(Self);
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
if not (csLoading in ComponentState) then
|
2009-02-25 11:31:18 +00:00
|
|
|
Name := GenerateName;
|
2007-01-04 19:47:47 +00:00
|
|
|
end;
|
2005-03-26 17:06:08 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
procedure TX2GraphicContainerItem.SetIndex(const Value: Integer);
|
2005-03-26 17:06:08 +00:00
|
|
|
begin
|
2007-04-02 14:45:31 +00:00
|
|
|
if Assigned(Container) then
|
|
|
|
Container.MoveGraphic(Self, Value);
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TX2GraphicContainerItem.SetPicture(const Value: TPicture);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
FPicture.Assign(Value);
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TX2GraphicContainerItem.SetPictureName(const Value: String);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
if Value <> FPictureName then
|
|
|
|
begin
|
|
|
|
FPictureName := Value;
|
|
|
|
|
|
|
|
if not (csLoading in ComponentState) then
|
2009-02-25 11:31:18 +00:00
|
|
|
Name := GenerateName;
|
2007-01-04 19:47:47 +00:00
|
|
|
end;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
function TX2GraphicContainerItem.GenerateName: String;
|
2007-01-04 19:47:47 +00:00
|
|
|
function ValidComponentName(const AComponent: TComponent; const AName: String): Boolean;
|
|
|
|
var
|
|
|
|
checkOwner: TComponent;
|
|
|
|
existing: TComponent;
|
|
|
|
|
|
|
|
begin
|
|
|
|
Result := True;
|
|
|
|
checkOwner := AComponent;
|
|
|
|
|
|
|
|
while Assigned(checkOwner) do
|
|
|
|
begin
|
|
|
|
existing := checkOwner.FindComponent(AName);
|
|
|
|
|
|
|
|
if Assigned(existing) and (existing <> Self) then
|
|
|
|
begin
|
|
|
|
Result := False;
|
|
|
|
exit;
|
|
|
|
end;
|
|
|
|
|
|
|
|
checkOwner := checkOwner.Owner;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
const
|
|
|
|
Alpha = ['A'..'Z', 'a'..'z', '_'];
|
|
|
|
AlphaNumeric = Alpha + ['0'..'9'];
|
|
|
|
|
|
|
|
var
|
|
|
|
charIndex: Integer;
|
|
|
|
counter: Integer;
|
|
|
|
resultName: String;
|
|
|
|
|
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
if Assigned(Container) then
|
|
|
|
Result := Container.Name
|
|
|
|
else
|
|
|
|
Result := 'GraphicContainerItem';
|
|
|
|
|
|
|
|
for charIndex := 1 to Length(PictureName) do
|
|
|
|
if PictureName[charIndex] in AlphaNumeric then
|
|
|
|
Result := Result + PictureName[charIndex];
|
|
|
|
|
|
|
|
|
|
|
|
resultName := Result;
|
|
|
|
counter := 0;
|
|
|
|
|
|
|
|
while not ValidComponentName(Self, Result) do
|
|
|
|
begin
|
|
|
|
Inc(counter);
|
|
|
|
Result := resultName + IntToStr(counter);
|
|
|
|
end;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
{==================== TX2GraphicContainer
|
|
|
|
Initialization
|
|
|
|
========================================}
|
2005-03-26 17:06:08 +00:00
|
|
|
constructor TX2GraphicContainer.Create(AOwner: TComponent);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
FGraphics := TList.Create;
|
|
|
|
FLists := TList.Create;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
destructor TX2GraphicContainer.Destroy;
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2009-02-25 11:31:18 +00:00
|
|
|
Clear;
|
2007-01-04 19:47:47 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
FreeAndNil(FGraphics);
|
|
|
|
FreeAndNil(FLists);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2004-09-01 11:19:37 +00:00
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
function TX2GraphicContainer.IndexByName(const AName: String): Integer;
|
2007-01-04 19:47:47 +00:00
|
|
|
var
|
|
|
|
graphicIndex: Integer;
|
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
Result := -1;
|
|
|
|
|
|
|
|
for graphicIndex := Pred(GraphicCount) downto 0 do
|
2010-07-20 10:04:45 +00:00
|
|
|
if SameText(Graphics[graphicIndex].PictureName, AName) then
|
2007-01-04 19:47:47 +00:00
|
|
|
begin
|
|
|
|
Result := graphicIndex;
|
|
|
|
break;
|
|
|
|
end;
|
2005-03-26 17:06:08 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
function TX2GraphicContainer.GraphicByName(const AName: String): TX2GraphicContainerItem;
|
|
|
|
var
|
|
|
|
graphicIndex: Integer;
|
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
Result := nil;
|
|
|
|
graphicIndex := IndexByName(AName);
|
|
|
|
if graphicIndex > -1 then
|
|
|
|
Result := Graphics[graphicIndex];
|
2005-03-26 17:06:08 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
function TX2GraphicContainer.PictureByName(const AName: String): TPicture;
|
2007-01-04 19:47:47 +00:00
|
|
|
var
|
|
|
|
graphic: TX2GraphicContainerItem;
|
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
Result := nil;
|
|
|
|
graphic := GraphicByName(AName);
|
|
|
|
if Assigned(graphic) then
|
|
|
|
Result := graphic.Picture;
|
2005-03-26 17:06:08 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2GraphicContainer.AssignTo(Dest: TPersistent);
|
2007-01-04 19:47:47 +00:00
|
|
|
var
|
|
|
|
destContainer: TX2GraphicContainer;
|
|
|
|
graphicIndex: Integer;
|
|
|
|
|
2004-09-01 11:19:37 +00:00
|
|
|
begin
|
|
|
|
if Dest is TX2GraphicContainer then
|
2007-01-04 19:47:47 +00:00
|
|
|
begin
|
|
|
|
destContainer := TX2GraphicContainer(Dest);
|
2009-02-25 11:31:18 +00:00
|
|
|
destContainer.Clear;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
for graphicIndex := 0 to Pred(Self.GraphicCount) do
|
|
|
|
with TX2GraphicContainerItem.Create(destContainer) do
|
|
|
|
begin
|
|
|
|
Assign(Self.Graphics[graphicIndex]);
|
|
|
|
Container := destContainer;
|
|
|
|
end;
|
|
|
|
end
|
2004-09-01 11:19:37 +00:00
|
|
|
else
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure TX2GraphicContainer.Clear;
|
2007-01-04 19:47:47 +00:00
|
|
|
begin
|
|
|
|
while GraphicsList.Count > 0 do
|
2009-02-25 11:31:18 +00:00
|
|
|
TX2GraphicContainerItem(GraphicsList.Last).Free;
|
2007-01-04 19:47:47 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2GraphicContainer.GetChildren(Proc: TGetChildProc; Root: TComponent);
|
|
|
|
var
|
|
|
|
graphicIndex: Integer;
|
|
|
|
graphic: TX2GraphicContainerItem;
|
|
|
|
|
|
|
|
begin
|
|
|
|
for graphicIndex := 0 to Pred(GraphicCount) do
|
|
|
|
begin
|
|
|
|
graphic := Graphics[graphicIndex];
|
|
|
|
Proc(graphic);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TX2GraphicContainer.SetChildOrder(Component: TComponent; Order: Integer);
|
|
|
|
begin
|
|
|
|
if GraphicsList.IndexOf(Component) >= 0 then
|
|
|
|
(Component as TX2GraphicContainerItem).Index := Order;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2GraphicContainer.SetName(const NewName: TComponentName);
|
|
|
|
var
|
|
|
|
oldName: String;
|
|
|
|
graphicIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
oldName := Self.Name;
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
if Self.Name <> oldName then
|
|
|
|
begin
|
|
|
|
{ Re-generate names for graphic components }
|
|
|
|
for graphicIndex := 0 to Pred(GraphicCount) do
|
2009-02-25 11:31:18 +00:00
|
|
|
Graphics[graphicIndex].Name := Graphics[graphicIndex].GenerateName;
|
2007-01-04 19:47:47 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
procedure TX2GraphicContainer.Notification(AComponent: TComponent; Operation: TOperation);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
inherited;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
case Operation of
|
|
|
|
opInsert:
|
|
|
|
{ In design-time, if a TX2GraphicList is added and it doesn't yet have
|
|
|
|
a container, assign ourselves to it for lazy programmers (such as me :)) }
|
|
|
|
if (csDesigning in ComponentState) and
|
|
|
|
(AComponent is TX2GraphicList) and
|
|
|
|
(not Assigned(TX2GraphicList(AComponent).Container)) then
|
|
|
|
TX2GraphicList(AComponent).Container := Self;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
opRemove:
|
|
|
|
begin
|
2012-05-02 13:59:12 +00:00
|
|
|
if (AComponent is TX2GraphicContainerItem) and
|
|
|
|
(TX2GraphicContainerItem(AComponent).Container = Self) then
|
|
|
|
begin
|
|
|
|
RemoveGraphic(TX2GraphicContainerItem(AComponent));
|
2012-05-02 14:45:55 +00:00
|
|
|
end
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
else if AComponent is TX2GraphicList then
|
|
|
|
Lists.Remove(AComponent);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
|
|
|
|
procedure TX2GraphicContainer.DefineProperties(Filer: TFiler);
|
|
|
|
begin
|
2004-08-31 14:40:07 +00:00
|
|
|
inherited;
|
2007-01-04 19:47:47 +00:00
|
|
|
|
|
|
|
{ Previous versions used a Collection to hold the container items. As this
|
|
|
|
wasn't Visual Inheritance-friendly, container items are now TComponents.
|
|
|
|
This will convert the deprecated Graphics property. }
|
|
|
|
Filer.DefineProperty('Graphics', ConvertGraphics, nil, False);
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
|
|
|
|
procedure TX2GraphicContainer.ConvertGraphics(Reader: TReader);
|
2004-08-31 14:40:07 +00:00
|
|
|
var
|
2007-01-04 19:47:47 +00:00
|
|
|
graphics: TCollection;
|
|
|
|
graphicIndex: Integer;
|
|
|
|
graphicItem: TDeprecatedGraphicItem;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
graphics := TCollection.Create(TDeprecatedGraphicItem);
|
|
|
|
try
|
|
|
|
if Reader.NextValue = vaCollection then
|
|
|
|
begin
|
|
|
|
FConversionRequired := True;
|
|
|
|
Clear;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
Reader.ReadValue;
|
|
|
|
Reader.ReadCollection(graphics);
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
for graphicIndex := 0 to Pred(graphics.Count) do
|
|
|
|
begin
|
|
|
|
graphicItem := TDeprecatedGraphicItem(graphics.Items[graphicIndex]);
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
{ Note: this create the item just fine, but won't add a line to the
|
|
|
|
form's definition; the designer can take care of that. }
|
|
|
|
with TX2GraphicContainerItem.Create(Self) do
|
|
|
|
begin
|
|
|
|
Picture := graphicItem.Picture;
|
|
|
|
PictureName := graphicItem.Name;
|
|
|
|
Container := Self;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FreeAndNil(graphics);
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
|
|
|
|
procedure TX2GraphicContainer.AddGraphic(const AGraphic: TX2GraphicContainerItem);
|
2004-08-31 14:40:07 +00:00
|
|
|
var
|
2007-01-04 19:47:47 +00:00
|
|
|
graphicIndex: Integer;
|
|
|
|
listIndex: Integer;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
graphicIndex := GraphicsList.Add(AGraphic);
|
|
|
|
AGraphic.InternalSetContainer(Self);
|
|
|
|
AGraphic.FreeNotification(Self);
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
for listIndex := Pred(Lists.Count) downto 0 do
|
|
|
|
TX2GraphicList(Lists[listIndex]).AddImage(graphicIndex);
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TX2GraphicContainer.RemoveGraphic(const AGraphic: TX2GraphicContainerItem);
|
|
|
|
var
|
|
|
|
graphicIndex: Integer;
|
|
|
|
listIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
graphicIndex := AGraphic.Index;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
if graphicIndex > -1 then
|
|
|
|
begin
|
2010-07-12 08:01:32 +00:00
|
|
|
if not (csDestroying in ComponentState) then
|
|
|
|
begin
|
|
|
|
for listIndex := Pred(Lists.Count) downto 0 do
|
|
|
|
TX2GraphicList(Lists[listIndex]).DeleteImage(graphicIndex);
|
|
|
|
end;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
GraphicsList.Delete(graphicIndex);
|
|
|
|
AGraphic.InternalSetContainer(nil);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TX2GraphicContainer.UpdateGraphic(const AGraphic: TX2GraphicContainerItem);
|
|
|
|
var
|
|
|
|
graphicIndex: Integer;
|
|
|
|
listIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
graphicIndex := AGraphic.Index;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
if graphicIndex > -1 then
|
|
|
|
begin
|
|
|
|
for listIndex := Pred(Lists.Count) downto 0 do
|
|
|
|
TX2GraphicList(Lists[listIndex]).UpdateImage(graphicIndex);
|
|
|
|
end;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
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;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
if AGraphic.Container <> Self then
|
|
|
|
begin
|
|
|
|
AGraphic.Container.MoveGraphic(AGraphic, ANewIndex);
|
|
|
|
Exit;
|
|
|
|
end;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
curIndex := AGraphic.Index;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
if curIndex > -1 then
|
|
|
|
begin
|
|
|
|
count := GraphicsList.Count;
|
|
|
|
newIndex := ANewIndex;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
if newIndex < 0 then
|
|
|
|
newIndex := 0;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
if newIndex >= count then
|
|
|
|
newIndex := Pred(count);
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
if newIndex <> curIndex then
|
|
|
|
begin
|
|
|
|
GraphicsList.Move(curIndex, newIndex);
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
for listIndex := Pred(Lists.Count) downto 0 do
|
|
|
|
TX2GraphicList(Lists[listIndex]).MoveImage(curIndex, newIndex);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
procedure TX2GraphicContainer.RegisterList(const AList: TX2GraphicList);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
if Lists.IndexOf(AList) = -1 then
|
|
|
|
begin
|
|
|
|
Lists.Add(AList);
|
|
|
|
AList.FreeNotification(Self);
|
|
|
|
end;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
procedure TX2GraphicContainer.UnregisterList(const AList: TX2GraphicList);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
if Lists.Remove(AList) > -1 then
|
2007-04-02 14:45:31 +00:00
|
|
|
AList.RemoveFreeNotification(Self);
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
function TX2GraphicContainer.GetGraphicCount: Integer;
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2007-01-04 19:47:47 +00:00
|
|
|
Result := GraphicsList.Count;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
function TX2GraphicContainer.GetGraphics(Index: Integer): TX2GraphicContainerItem;
|
|
|
|
begin
|
|
|
|
Result := TX2GraphicContainerItem(GraphicsList[Index]);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TX2GraphicContainer.SetGraphics(Index: Integer; const Value: TX2GraphicContainerItem);
|
|
|
|
begin
|
|
|
|
TX2GraphicContainerItem(GraphicsList[Index]).Assign(Value);
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{========================= TX2GraphicList
|
|
|
|
Initialization
|
|
|
|
========================================}
|
2005-03-26 17:06:08 +00:00
|
|
|
constructor TX2GraphicList.Create(AOwner: TComponent);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
FBackground := clBtnFace;
|
2004-08-31 18:46:34 +00:00
|
|
|
BkColor := clNone;
|
2005-12-13 15:05:09 +00:00
|
|
|
FConvert := True;
|
2004-09-01 07:58:26 +00:00
|
|
|
FEnabled := True;
|
2004-08-31 14:40:07 +00:00
|
|
|
FStretchMode := smCrop;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure TX2GraphicList.Loaded;
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
RebuildImages;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure TX2GraphicList.Change;
|
2004-08-31 15:02:35 +00:00
|
|
|
begin
|
|
|
|
inherited;
|
|
|
|
|
|
|
|
if FUpdateCount = 0 then
|
2009-02-25 11:31:18 +00:00
|
|
|
RebuildImages;
|
2004-08-31 15:02:35 +00:00
|
|
|
end;
|
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
destructor TX2GraphicList.Destroy;
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
|
|
|
SetContainer(nil);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
procedure TX2GraphicList.AssignTo(Dest: TPersistent);
|
2004-09-01 11:19:37 +00:00
|
|
|
begin
|
|
|
|
if Dest is TX2GraphicList then
|
|
|
|
with TX2GraphicList(Dest) do
|
|
|
|
begin
|
|
|
|
Background := Self.Background;
|
|
|
|
Container := Self.Container;
|
|
|
|
Enabled := Self.Enabled;
|
|
|
|
StretchMode := Self.StretchMode;
|
|
|
|
end
|
|
|
|
else
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
|
|
|
|
{========================= TX2GraphicList
|
|
|
|
Graphics
|
|
|
|
========================================}
|
2005-03-26 17:06:08 +00:00
|
|
|
function TX2GraphicList.DrawGraphic(const AIndex: Integer;
|
|
|
|
const ACanvas: TCanvas;
|
|
|
|
const AX, AY: Integer;
|
|
|
|
const AEnabled: Boolean = True): Boolean;
|
2004-09-01 17:41:06 +00:00
|
|
|
procedure InternalDrawGraphic(const ADest: TCanvas;
|
|
|
|
const ADestX, ADestY: Integer);
|
2004-08-31 14:40:07 +00:00
|
|
|
var
|
2004-08-31 18:46:34 +00:00
|
|
|
bmpTemp: TBitmap;
|
|
|
|
iHeight: Integer;
|
|
|
|
iWidth: Integer;
|
2004-08-31 14:40:07 +00:00
|
|
|
rDest: TRect;
|
2004-08-31 18:46:34 +00:00
|
|
|
rSource: TRect;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
with FContainer.Graphics[AIndex].Picture do
|
2004-08-31 18:46:34 +00:00
|
|
|
if (Width <= Self.Width) and (Height <= Self.Height) then
|
2004-09-01 17:41:06 +00:00
|
|
|
ADest.Draw(ADestX, ADestY, Graphic)
|
2004-08-31 14:40:07 +00:00
|
|
|
else
|
|
|
|
begin
|
2004-08-31 18:46:34 +00:00
|
|
|
iWidth := Width;
|
|
|
|
iHeight := Height;
|
|
|
|
|
|
|
|
if iWidth > Self.Width then
|
|
|
|
iWidth := Self.Width;
|
|
|
|
|
|
|
|
if iHeight > Self.Height then
|
|
|
|
iHeight := Self.Height;
|
|
|
|
|
2004-09-01 17:41:06 +00:00
|
|
|
rDest := Rect(ADestX, ADestY,
|
|
|
|
ADestX + iWidth, ADestY + iHeight);
|
2004-08-31 18:46:34 +00:00
|
|
|
rSource := Rect(0, 0, iWidth, iHeight);
|
|
|
|
|
|
|
|
case FStretchMode of
|
|
|
|
smCrop:
|
|
|
|
begin
|
2009-02-25 11:31:18 +00:00
|
|
|
bmpTemp := TBitmap.Create;
|
2004-08-31 18:46:34 +00:00
|
|
|
try
|
|
|
|
with bmpTemp do
|
|
|
|
begin
|
|
|
|
Width := iWidth;
|
|
|
|
Height := iHeight;
|
|
|
|
PixelFormat := pf24bit;
|
|
|
|
|
|
|
|
// Copy existing content
|
|
|
|
Canvas.CopyRect(rSource, ADest, rDest);
|
|
|
|
|
|
|
|
// Overlay graphic
|
|
|
|
Canvas.Draw(0, 0, Graphic);
|
|
|
|
|
|
|
|
// Copy back
|
|
|
|
ADest.CopyRect(rDest, Canvas, rDest);
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FreeAndNil(bmpTemp);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
smStretch:
|
|
|
|
// Note: some TGraphic's don't support StretchDraw and will
|
|
|
|
// always crop. Nothing we can do about that...
|
|
|
|
ADest.StretchDraw(rDest, Graphic);
|
|
|
|
end;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
2004-08-31 15:02:35 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
bmpBackground: TBitmap;
|
|
|
|
bmpBlend: TBitmap;
|
2004-09-01 07:58:26 +00:00
|
|
|
iX: Integer;
|
|
|
|
iY: Integer;
|
|
|
|
pBackground: PRGBTripleArray;
|
|
|
|
pBlend: PRGBTripleArray;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2004-08-31 15:02:35 +00:00
|
|
|
begin
|
|
|
|
Result := False;
|
2004-10-07 19:34:57 +00:00
|
|
|
if not Assigned(FContainer) then
|
2004-10-07 18:21:44 +00:00
|
|
|
exit;
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
if (AIndex < 0) or (AIndex >= FContainer.GraphicCount) then
|
2004-10-07 19:34:57 +00:00
|
|
|
exit;
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
if (not Assigned(FContainer.Graphics[AIndex].Picture)) or
|
|
|
|
(not Assigned(FContainer.Graphics[AIndex].Picture.Graphic)) or
|
2004-08-31 18:46:34 +00:00
|
|
|
(FContainer.Graphics[AIndex].Picture.Graphic.Empty) then
|
2004-08-31 15:02:35 +00:00
|
|
|
exit;
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
{ First see if any custom draw handlers want to draw the image }
|
|
|
|
if not CustomDrawImage(ACanvas, Self, AIndex, AX, AY, AEnabled) then
|
2004-08-31 15:02:35 +00:00
|
|
|
begin
|
2009-02-25 11:31:18 +00:00
|
|
|
if AEnabled then
|
|
|
|
{ Enabled, simply draw the graphic }
|
|
|
|
InternalDrawGraphic(ACanvas, AX, AY)
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
{ Disabled, need to draw the image using 50% transparency. There's only
|
|
|
|
one problem; not all TGraphic's support that, and neither is there a
|
|
|
|
generic way of determining a pixel's transparency. So instead, we
|
|
|
|
blend the background with a copy of the background with the graphic
|
|
|
|
painted on it... }
|
|
|
|
bmpBackground := TBitmap.Create;
|
|
|
|
bmpBlend := TBitmap.Create;
|
|
|
|
try
|
|
|
|
{ Get background from canvas }
|
|
|
|
with bmpBackground do
|
|
|
|
begin
|
|
|
|
Width := Self.Width;
|
|
|
|
Height := Self.Height;
|
|
|
|
PixelFormat := pf24bit;
|
|
|
|
Canvas.CopyRect(Rect(0, 0, Width, Height), ACanvas,
|
|
|
|
Rect(AX, AY, AX + Width, AY + Height));
|
|
|
|
end;
|
|
|
|
|
|
|
|
bmpBlend.Assign(bmpBackground);
|
|
|
|
InternalDrawGraphic(bmpBlend.Canvas, 0, 0);
|
|
|
|
|
|
|
|
{ Blend graphic with background at 50% }
|
|
|
|
for iY := 0 to bmpBackground.Height - 1 do
|
|
|
|
begin
|
|
|
|
pBackground := bmpBackground.ScanLine[iY];
|
|
|
|
pBlend := bmpBlend.ScanLine[iY];
|
|
|
|
|
|
|
|
for iX := 0 to bmpBackground.Width - 1 do
|
|
|
|
with pBlend^[iX] do
|
|
|
|
begin
|
|
|
|
rgbtBlue := ((pBackground^[iX].rgbtBlue shl 7) +
|
|
|
|
(rgbtBlue shl 7)) shr 8;
|
|
|
|
rgbtGreen := ((pBackground^[iX].rgbtGreen shl 7) +
|
|
|
|
(rgbtGreen shl 7)) shr 8;
|
|
|
|
rgbtRed := ((pBackground^[iX].rgbtRed shl 7) +
|
|
|
|
(rgbtRed shl 7)) shr 8;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
{ Copy blended graphic back }
|
|
|
|
ACanvas.Draw(AX, AY, bmpBlend);
|
|
|
|
finally
|
|
|
|
FreeAndNil(bmpBlend);
|
|
|
|
FreeAndNil(bmpBackground);
|
2004-09-01 07:58:26 +00:00
|
|
|
end;
|
2004-08-31 15:02:35 +00:00
|
|
|
end;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
2004-08-31 15:02:35 +00:00
|
|
|
Result := True;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
procedure TX2GraphicList.DoDraw(Index: Integer; Canvas: TCanvas; X, Y: Integer;
|
|
|
|
Style: Cardinal; Enabled: Boolean = True);
|
2004-08-31 15:02:35 +00:00
|
|
|
begin
|
|
|
|
DrawGraphic(Index, Canvas, X, Y, Enabled);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TX2GraphicList.BuildImage(const AIndex: Integer;
|
|
|
|
const AImage, AMask: TBitmap);
|
2004-08-31 14:40:07 +00:00
|
|
|
function RGBTriple(const AColor: TColor): TRGBTriple;
|
|
|
|
var
|
|
|
|
cColor: Cardinal;
|
|
|
|
|
|
|
|
begin
|
|
|
|
cColor := ColorToRGB(AColor);
|
|
|
|
|
|
|
|
with Result do
|
|
|
|
begin
|
|
|
|
rgbtBlue := GetBValue(cColor);
|
|
|
|
rgbtGreen := GetGValue(cColor);
|
|
|
|
rgbtRed := GetRValue(cColor);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function SameColor(const AColor1, AColor2: TRGBTriple): Boolean;
|
|
|
|
begin
|
|
|
|
Result := CompareMem(@AColor1, @AColor2, SizeOf(TRGBTriple));
|
|
|
|
end;
|
|
|
|
|
|
|
|
var
|
|
|
|
bmpCompare: TBitmap;
|
|
|
|
bOk: Boolean;
|
|
|
|
cImage: TRGBTriple;
|
|
|
|
cMask: TRGBTriple;
|
|
|
|
iBit: Integer;
|
|
|
|
iPosition: Integer;
|
|
|
|
iX: Integer;
|
|
|
|
iY: Integer;
|
|
|
|
pCompare: PRGBTripleArray;
|
|
|
|
pImage: PRGBTripleArray;
|
|
|
|
pMask: PByteArray;
|
|
|
|
|
|
|
|
begin
|
|
|
|
// Technique used here: draw the image twice, once on the background color,
|
|
|
|
// once on black. Loop through the two images, check if a pixel is the
|
|
|
|
// background color on one image and black on the other; if so then it's
|
|
|
|
// fully transparent. This doesn't eliminate all problems with alpha images,
|
|
|
|
// but it's the best option (at least for pre-XP systems).
|
|
|
|
//
|
|
|
|
// Note that components using ImageList.Draw will have full alpha support,
|
|
|
|
// this routine only ensures compatibility with ImageList_Draw components.
|
|
|
|
// TMenu is among the first, TToolbar and similar are amongst the latter.
|
|
|
|
with AImage do
|
|
|
|
begin
|
|
|
|
Width := Self.Width;
|
|
|
|
Height := Self.Height;
|
|
|
|
PixelFormat := pf24bit;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
with Canvas do
|
|
|
|
begin
|
|
|
|
Brush.Color := FBackground;
|
|
|
|
FillRect(Rect(0, 0, Width, Height));
|
2004-08-31 15:02:35 +00:00
|
|
|
bOk := DrawGraphic(AIndex, Canvas, 0, 0, FEnabled);
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
end;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
with AMask do
|
|
|
|
begin
|
|
|
|
Width := Self.Width;
|
|
|
|
Height := Self.Height;
|
|
|
|
PixelFormat := pf1bit;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
with Canvas do
|
|
|
|
begin
|
|
|
|
Brush.Color := clBlack;
|
|
|
|
FillRect(Rect(0, 0, Width, Height));
|
|
|
|
end;
|
|
|
|
end;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
// No point in looping through the
|
|
|
|
// images if they're blank anyways...
|
|
|
|
if not bOk then
|
|
|
|
exit;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
|
|
|
bmpCompare := TBitmap.Create;
|
2004-08-31 14:40:07 +00:00
|
|
|
try
|
|
|
|
with bmpCompare do
|
|
|
|
begin
|
|
|
|
Width := Self.Width;
|
|
|
|
Height := Self.Height;
|
|
|
|
PixelFormat := pf24bit;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
with Canvas do
|
|
|
|
begin
|
|
|
|
Brush.Color := clBlack;
|
|
|
|
FillRect(Rect(0, 0, Width, Height));
|
2004-08-31 15:02:35 +00:00
|
|
|
DrawGraphic(AIndex, Canvas, 0, 0, FEnabled);
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
end;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
cImage := RGBTriple(FBackground);
|
|
|
|
cMask := RGBTriple(clBlack);
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
for iY := 0 to AImage.Height - 1 do
|
|
|
|
begin
|
|
|
|
pImage := AImage.ScanLine[iY];
|
|
|
|
pCompare := bmpCompare.ScanLine[iY];
|
|
|
|
pMask := AMask.ScanLine[iY];
|
|
|
|
iPosition := 0;
|
|
|
|
iBit := 128;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
for iX := 0 to AImage.Width - 1 do
|
|
|
|
begin
|
|
|
|
if iBit = 128 then
|
|
|
|
pMask^[iPosition] := 0;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
if SameColor(pImage^[iX], cImage) and
|
|
|
|
SameColor(pCompare^[iX], cMask) then
|
|
|
|
begin
|
|
|
|
// Transparent pixel
|
|
|
|
FillChar(pImage^[iX], SizeOf(TRGBTriple), $00);
|
|
|
|
pMask^[iPosition] := pMask^[iPosition] or iBit;
|
|
|
|
end;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
iBit := iBit shr 1;
|
|
|
|
if iBit < 1 then
|
|
|
|
begin
|
|
|
|
iBit := 128;
|
|
|
|
Inc(iPosition);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
finally
|
|
|
|
FreeAndNil(bmpCompare);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
procedure TX2GraphicList.AddImage(const AIndex: Integer);
|
2004-08-31 14:40:07 +00:00
|
|
|
var
|
|
|
|
bmpImage: TBitmap;
|
|
|
|
bmpMask: TBitmap;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if csLoading in ComponentState then
|
|
|
|
exit;
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
if CanConvert then
|
|
|
|
begin
|
|
|
|
BeginUpdate;
|
2004-08-31 15:02:35 +00:00
|
|
|
try
|
2009-02-25 11:31:18 +00:00
|
|
|
bmpImage := TBitmap.Create;
|
|
|
|
bmpMask := TBitmap.Create;
|
|
|
|
try
|
|
|
|
BuildImage(AIndex, bmpImage, bmpMask);
|
|
|
|
Assert(AIndex <= Self.Count, 'AAAH! Images out of sync! *panics*');
|
|
|
|
|
|
|
|
if AIndex = Self.Count then
|
|
|
|
Add(bmpImage, bmpMask)
|
|
|
|
else
|
|
|
|
Insert(AIndex, bmpImage, bmpMask);
|
|
|
|
finally
|
|
|
|
FreeAndNil(bmpMask);
|
|
|
|
FreeAndNil(bmpImage);
|
|
|
|
end;
|
2004-08-31 15:02:35 +00:00
|
|
|
finally
|
2009-02-25 11:31:18 +00:00
|
|
|
EndUpdate;
|
2004-08-31 15:02:35 +00:00
|
|
|
end;
|
2009-02-25 11:31:18 +00:00
|
|
|
end else
|
|
|
|
UpdateImageCount;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
procedure TX2GraphicList.UpdateImage(const AIndex: Integer);
|
2004-08-31 14:40:07 +00:00
|
|
|
var
|
|
|
|
bmpImage: TBitmap;
|
|
|
|
bmpMask: TBitmap;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if csLoading in ComponentState then
|
|
|
|
exit;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
|
|
|
if not CanConvert then
|
|
|
|
Exit;
|
|
|
|
|
2005-12-13 15:49:17 +00:00
|
|
|
if (AIndex < 0) or (AIndex >= Count) then
|
|
|
|
exit;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
|
|
|
BeginUpdate;
|
2004-08-31 14:40:07 +00:00
|
|
|
try
|
2009-02-25 11:31:18 +00:00
|
|
|
bmpImage := TBitmap.Create;
|
|
|
|
bmpMask := TBitmap.Create;
|
2004-08-31 15:02:35 +00:00
|
|
|
try
|
2007-01-04 19:47:47 +00:00
|
|
|
BuildImage(AIndex, bmpImage, bmpMask);
|
2004-08-31 15:02:35 +00:00
|
|
|
Replace(AIndex, bmpImage, bmpMask);
|
|
|
|
finally
|
|
|
|
FreeAndNil(bmpMask);
|
|
|
|
FreeAndNil(bmpImage);
|
|
|
|
end;
|
2004-08-31 14:40:07 +00:00
|
|
|
finally
|
2009-02-25 11:31:18 +00:00
|
|
|
EndUpdate;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
procedure TX2GraphicList.DeleteImage(const AIndex: Integer);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
2012-05-02 13:59:12 +00:00
|
|
|
if CanConvert then
|
|
|
|
begin
|
|
|
|
BeginUpdate;
|
|
|
|
try
|
|
|
|
Delete(AIndex);
|
|
|
|
finally
|
|
|
|
EndUpdate;
|
|
|
|
end;
|
|
|
|
end else
|
|
|
|
UpdateImageCount;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
procedure TX2GraphicList.MoveImage(const AOldIndex, ANewIndex: Integer);
|
|
|
|
begin
|
2012-05-02 13:59:12 +00:00
|
|
|
if CanConvert then
|
|
|
|
begin
|
|
|
|
BeginUpdate;
|
|
|
|
try
|
|
|
|
Move(AOldIndex, ANewIndex);
|
|
|
|
finally
|
|
|
|
EndUpdate;
|
|
|
|
end;
|
2007-04-02 14:45:31 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure TX2GraphicList.UpdateImageCount;
|
|
|
|
begin
|
|
|
|
if not Assigned(Container) then
|
|
|
|
Clear
|
|
|
|
else
|
|
|
|
ImageList_SetImageCount(Self.Handle, Container.GraphicCount);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
procedure TX2GraphicList.RebuildImages;
|
2004-08-31 14:40:07 +00:00
|
|
|
var
|
|
|
|
iIndex: Integer;
|
|
|
|
|
|
|
|
begin
|
|
|
|
if (csLoading in ComponentState) or
|
|
|
|
(Width = 0) or (Height = 0) then
|
2009-02-25 11:31:18 +00:00
|
|
|
Exit;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
BeginUpdate;
|
2004-08-31 15:02:35 +00:00
|
|
|
try
|
|
|
|
if not Assigned(FContainer) then
|
2009-02-25 11:31:18 +00:00
|
|
|
begin
|
|
|
|
Clear;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
UpdateImageCount;
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
if CanConvert then
|
|
|
|
begin
|
|
|
|
for iIndex := 0 to Pred(FContainer.GraphicCount) do
|
|
|
|
UpdateImage(iIndex);
|
|
|
|
end;
|
|
|
|
end;
|
2004-08-31 15:02:35 +00:00
|
|
|
finally
|
2009-02-25 11:31:18 +00:00
|
|
|
EndUpdate;
|
|
|
|
inherited Change;
|
2004-08-31 15:02:35 +00:00
|
|
|
end;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
function TX2GraphicList.CanConvert: Boolean;
|
|
|
|
begin
|
|
|
|
Result := FConvert or (csDesigning in ComponentState);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
{========================= TX2GraphicList
|
|
|
|
Properties
|
|
|
|
========================================}
|
2010-07-12 07:37:54 +00:00
|
|
|
procedure TX2GraphicList.ReadData(Stream: TStream);
|
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
|
2010-07-12 07:37:54 +00:00
|
|
|
procedure TX2GraphicList.WriteData(Stream: TStream);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
procedure TX2GraphicList.Notification(AComponent: TComponent;
|
|
|
|
Operation: TOperation);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
|
|
|
if (Operation = opRemove) and (AComponent = FContainer) then
|
2010-07-12 07:37:54 +00:00
|
|
|
SetContainer(nil);
|
2005-03-26 17:06:08 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
procedure TX2GraphicList.SetBackground(const Value: TColor);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
|
|
|
FBackground := Value;
|
2009-02-25 11:31:18 +00:00
|
|
|
RebuildImages;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
procedure TX2GraphicList.SetContainer(const Value: TX2GraphicContainer);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
|
|
|
if Assigned(FContainer) then
|
2004-08-31 18:46:34 +00:00
|
|
|
begin
|
2004-08-31 14:40:07 +00:00
|
|
|
FContainer.UnregisterList(Self);
|
2004-08-31 18:46:34 +00:00
|
|
|
FContainer.RemoveFreeNotification(Self);
|
|
|
|
end;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
FContainer := Value;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
2004-08-31 14:40:07 +00:00
|
|
|
if Assigned(FContainer) then
|
2004-08-31 18:46:34 +00:00
|
|
|
begin
|
|
|
|
FContainer.FreeNotification(Self);
|
2004-08-31 14:40:07 +00:00
|
|
|
FContainer.RegisterList(Self);
|
2004-08-31 18:46:34 +00:00
|
|
|
end;
|
2009-02-25 11:31:18 +00:00
|
|
|
|
|
|
|
RebuildImages;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2005-12-13 15:05:09 +00:00
|
|
|
procedure TX2GraphicList.SetConvert(const Value: Boolean);
|
|
|
|
begin
|
|
|
|
if Value <> FConvert then
|
|
|
|
begin
|
|
|
|
FConvert := Value;
|
2009-02-25 11:31:18 +00:00
|
|
|
RebuildImages;
|
2005-12-13 15:05:09 +00:00
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
procedure TX2GraphicList.SetEnabled(const Value: Boolean);
|
2004-08-31 15:02:35 +00:00
|
|
|
begin
|
|
|
|
FEnabled := Value;
|
2009-02-25 11:31:18 +00:00
|
|
|
RebuildImages;
|
2004-08-31 15:02:35 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2005-03-26 17:06:08 +00:00
|
|
|
procedure TX2GraphicList.SetStretchMode(const Value: TX2GLStretchMode);
|
2004-08-31 14:40:07 +00:00
|
|
|
begin
|
|
|
|
FStretchMode := Value;
|
2009-02-25 11:31:18 +00:00
|
|
|
RebuildImages;
|
2004-08-31 14:40:07 +00:00
|
|
|
end;
|
|
|
|
|
2004-08-31 15:02:35 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure TX2GraphicList.BeginUpdate;
|
2004-08-31 15:02:35 +00:00
|
|
|
begin
|
|
|
|
Inc(FUpdateCount);
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
procedure TX2GraphicList.EndUpdate;
|
2004-08-31 15:02:35 +00:00
|
|
|
begin
|
|
|
|
Assert(FUpdateCount > 0, 'EndUpdate without matching BeginUpdate!');
|
|
|
|
Dec(FUpdateCount);
|
|
|
|
end;
|
|
|
|
|
2005-12-13 15:05:09 +00:00
|
|
|
|
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
{ TDeprecatedGraphicItem }
|
|
|
|
constructor TDeprecatedGraphicItem.Create(Collection: TCollection);
|
|
|
|
begin
|
|
|
|
inherited;
|
2005-12-13 15:05:09 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
FPicture := TPicture.Create;
|
2007-01-04 19:47:47 +00:00
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2009-02-25 11:31:18 +00:00
|
|
|
destructor TDeprecatedGraphicItem.Destroy;
|
2007-01-04 19:47:47 +00:00
|
|
|
begin
|
|
|
|
FreeAndNil(FPicture);
|
|
|
|
|
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2007-04-02 14:45:31 +00:00
|
|
|
|
2007-01-04 19:47:47 +00:00
|
|
|
procedure TDeprecatedGraphicItem.SetPicture(const Value: TPicture);
|
|
|
|
begin
|
|
|
|
FPicture.Assign(Value);
|
|
|
|
end;
|
|
|
|
|
|
|
|
|
|
|
|
initialization
|
|
|
|
RegisterClass(TX2GraphicContainerItem);
|
2009-02-25 11:31:18 +00:00
|
|
|
CustomDrawImageProcs := TList.Create;
|
|
|
|
|
|
|
|
finalization
|
|
|
|
FreeAndNil(CustomDrawImageProcs);
|
2007-01-04 19:47:47 +00:00
|
|
|
|
|
|
|
end.
|