{**********************************************}
{   TeeChart PCX format related functions      }
{   Copyright (c) 2000-2020 by Steema Software }
{   Portions Copyright (c) Davie Reed,         }
{   January 1999. E-Mail:  davie@smatters.com  }
{**********************************************}
unit TeePCX;
{$I TeeDefs.inc}

interface

uses
  Windows, Messages,
  SysUtils, Classes,

  Graphics, Controls, Forms, Dialogs,

  {$IFDEF D9}
  Types,
  {$ENDIF}
  TeeProcs, TeeExport;

type
  TPCXOptions = class(TForm)
  private
    { Private declarations }
  public
    { Public declarations }
  end;

  TPCXExportFormat=class(TTeeExportFormat)
  private
    FProperties : TPCXOptions;

    Procedure CheckProperties;
  protected
    Procedure DoCopyToClipboard; override;
  public
    function Description:String; override;
    function FileExtension:String; override;
    class function FileFilter:String; override;
    Function Options(Check:Boolean=True):TForm; override;
    Procedure SaveToStream(Stream:TStream); override;
  end;

implementation

{$IFNDEF LCL}
{$ELSE}
{$R *.lfm}
{$ENDIF}
{$R *.DFM}

Uses
  Clipbrd, PCX, TeCanvas, TeeConst;

function TPCXExportFormat.Description:String;
begin
  result:=TeeMsg_AsPCX;
end;

class function TPCXExportFormat.FileFilter:String;
begin
  result:=TeeMsg_PCXFilter;
end;

function TPCXExportFormat.FileExtension:String;
begin
  result:='pcx';
end;

Procedure TPCXExportFormat.CheckProperties;
begin
  if not Assigned(FProperties) then FProperties:=TPCXOptions.Create(nil)
end;

Function TPCXExportFormat.Options(Check:Boolean=True):TForm;
begin
  if Check then CheckProperties;
  result:=FProperties;
end;

procedure TPCXExportFormat.SaveToStream(Stream:TStream);
var tmpBitmap : TBitmap;
begin
  CheckProperties;
  CheckSize;

  tmpBitmap:=GetBitmap(TeePixelFormat);
  try
    TeePCXToStream(Stream,tmpBitmap,4);
  finally
    tmpBitmap.Free;
  end;
end;

procedure TPCXExportFormat.DoCopyToClipboard;
var tmp : TBitmap;
begin
  tmp:=GetBitmap(TeePixelFormat);
  try
    Clipboard.Assign(tmp);
  finally
    tmp.Free;
  end;
end;

initialization
  RegisterTeeExportFormat(TPCXExportFormat);
finalization
  UnRegisterTeeExportFormat(TPCXExportFormat);
end.
