{********************************************}
{ TeeChart Pro Charting Library              }
{ Copyright (c) 1995-2020 by Steema Software }
{         All Rights Reserved                }
{                                            }
{  Base Function Editor form                 }
{********************************************}
unit TeeBaseFuncEdit;
{$I TeeDefs.inc}

interface

uses {$IFNDEF LINUX}
     Windows, Messages,
     {$ENDIF}
     SysUtils, Classes,

     Graphics, Controls, Forms, Dialogs,
     TeEngine, StdCtrls, ExtCtrls;

type
  TBaseFunctionEditor = class(TForm)
    PanelButtons: TPanel;
    Panel2: TPanel;
    Button1: TButton;
    Button2: TButton;
    procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
  protected
    CreatingForm : Boolean;
    IFunction    : TTeeFunction;
    procedure ApplyFormChanges; virtual;  // dont make abstract (D5 bug)
    procedure EnableApply;
    procedure FillSeries(const Items:TStrings);
    Procedure SetFunction; virtual;   // dont make abstract (D5 bug)
  public
    { Public declarations }
  end;

implementation

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

uses TeeFuncEdit, Chart;

Procedure TBaseFunctionEditor.SetFunction;
begin
end;

Procedure TBaseFunctionEditor.ApplyFormChanges;
begin
end;

procedure TBaseFunctionEditor.EnableApply;
begin
  if Owner is TTeeFuncEditor then
     TTeeFuncEditor(Owner).BApply.Enabled:=True;
end;

procedure TBaseFunctionEditor.FormCloseQuery(Sender: TObject;
  var CanClose: Boolean);

  Function Series:TChartSeries;
  begin
    if Owner is TTeeFuncEditor then
       result:=TTeeFuncEditor(Owner).TheSeries
    else
       result:=nil;
  end;

begin
  if not Assigned(IFunction) then
     IFunction:=CreateNewTeeFunction(Series,TTeeFuncEditor(Owner).FunctionClass);

  With IFunction do
  begin
    BeginUpdate;
    try
      ApplyFormChanges;
    finally
      EndUpdate;
    end;
  end;

  if (Series<>nil) and (not Assigned(Series.FunctionType)) then
     Series.SetFunction(IFunction);

  CanClose:=True;
end;

procedure TBaseFunctionEditor.FormShow(Sender: TObject);
begin
  CreatingForm:=True;
  IFunction:=TTeeFunction(Tag);

  if Assigned(IFunction) then
  begin
    SetFunction;

    if Owner is TTeeFuncEditor then
       TTeeFuncEditor(Owner).BApply.Enabled:=False;
  end;

  CreatingForm:=False;
end;

procedure TBaseFunctionEditor.FillSeries(const Items: TStrings);
begin
  if Assigned(IFunction.ParentSeries) and
     Assigned(IFunction.ParentSeries.ParentChart) then
       FillSeriesItems(Items,IFunction.ParentSeries.ParentChart.SeriesList);
end;

initialization
  RegisterClass(TBaseFunctionEditor);
end.
