{==============================================================================

  Copyright (C) 2000-2001 by Evgeny Kryukov
  All rights reserved

  All contents of this file and all other files included in this archive
  are Copyright (C) 2001 Evgeny Kryukov. Use and/or distribution of
  them requires acceptance of the License Agreement.

  See License.txt for licence information

===============================================================================}

unit EpIIBitmaps;

{$I EpIIVer.Inc}
{$T-,W-,X+,P+}

interface

uses
  Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms,
  KsUtils, KsBitmap, EpIIVersion;

type

{ TEpBitmapList class }

  //  TEpBitmapList component holds collection of bitmaps you can use as
  //  wallpapers, borders for the components and controls. Each visual control
  //  has Bitmaps property that can be assigned to TEpBitmapList so
  //  that its bitmaps can be used as wallpapers or borders.
  TEpBitmapList = class(TComponent)
  private
    FBitmaps: TKsBitmapList;
    procedure ReadData(Stream: TStream);
    procedure WriteData(Stream: TStream);

    function GetVersion: TEpVersion;
    procedure SetVersion(const Value: TEpVersion);
    function GetCount: integer;
  protected
    procedure DefineProperties(Filer: TFiler); override;
  public
    constructor Create(AOwner: TComponent); override;
    destructor Destroy; override;
    { List of bitmaps }
    property Bitmaps: TKsBitmapList read FBitmaps;
    property Count: integer read GetCount; 
  published
    property Version: TEpVersion read GetVersion write SetVersion stored False;
  end;

implementation {===============================================================}

{ TEpBitmapList ===============================================================}

constructor TEpBitmapList.Create(AOwner: TComponent);
begin
  inherited Create(AOwner);
  FBitmaps := TKsBitmapList.Create;
end;

destructor TEpBitmapList.Destroy;
begin
  FBitmaps.Free;
  inherited Destroy;
end;

{ Custom properties }

procedure TEpBitmapList.DefineProperties(Filer: TFiler);
begin
  inherited;
  Filer.DefineBinaryProperty('KSBitmaps', ReadData, WriteData, FBitmaps.Count > 0);
end;

procedure TEpBitmapList.ReadData(Stream: TStream);
var
  Count, i: integer;
  B: TKsBitmap;
begin
  FBitmaps.Clear;
  { Read }
  Stream.Read(Count, SizeOf(Integer));

  for i := 0 to Count-1 do
  begin
    B := TKsBitmap.Create;
    B.LoadFromStream(Stream);
    
    FBitmaps.Add(B);
  end;
end;

procedure TEpBitmapList.WriteData(Stream: TStream);
var
  i: integer;
begin
  { Read }
  Stream.Write(FBitmaps.Count, SizeOf(Integer));

  for i := 0 to FBitmaps.Count-1 do
  begin
    FBitmaps[i].SaveToStream(Stream);
  end;
end;

{ Properties }

function TEpBitmapList.GetVersion: TEpVersion;
begin
  Result := EpVersion;
end;

procedure TEpBitmapList.SetVersion(const Value: TEpVersion);
begin
end;

function TEpBitmapList.GetCount: integer;
begin
  Result := FBitmaps.Count;
end;

end.
