{********************************************}
{ TeeChart. Smith Series Editor              }
{ Copyright (c) 1996-2020 by Steema Software }
{********************************************}
unit TeeSmithEdit;
{$I TeeDefs.inc}

interface

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

     Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons,

     TeeSmith, TeCanvas, TeePenDlg, TeeProcs, TeEngine, TeeBrushDlg;

type
  TSmithSeriesEdit = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabPointer: TTabSheet;
    TabBorder: TTabSheet;
    TabBack: TTabSheet;
    TabCircle: TTabSheet;
    Label1: TLabel;
    CBC: TCheckBox;
    CBR: TCheckBox;
    BCPen: TButtonPen;
    BRPen: TButtonPen;
    CBColorEach: TCheckBox;
    BCFont: TButton;
    BRFont: TButton;
    EImag: TEdit;
    TabOptions: TTabSheet;
    Label2: TLabel;
    Label3: TLabel;
    LTransp: TLabel;
    CBNulls: TComboFlat;
    TBTransp: TTrackBar;
    CBPointerBehind: TCheckBox;
    LDrawStyle: TLabel;
    CBDrawStyle: TComboFlat;
    CBEachLine: TCheckBox;
    procedure FormShow(Sender: TObject);
    procedure CBCClick(Sender: TObject);
    procedure CBRClick(Sender: TObject);
    procedure CBColorEachClick(Sender: TObject);
    procedure BCFontClick(Sender: TObject);
    procedure BRFontClick(Sender: TObject);
    procedure EImagChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
    procedure CBNullsChange(Sender: TObject);
    procedure CBPointerBehindClick(Sender: TObject);
    procedure CBDrawStyleChange(Sender: TObject);
    procedure CBEachLineClick(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
    CircledForm : TCustomForm;
    Smith       : TSmithSeries;
  end;

implementation

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

uses
  TeeEdiSeri, TeePoEdi, TeeCircledEdit, TeeConst, TeeEdiFont, Series;

procedure TSmithSeriesEdit.FormShow(Sender: TObject);
begin
  Smith:=TSmithSeries(Tag);

  if Assigned(Smith) then
  begin
    With Smith do
    begin
      CBC.Checked:=CLabels;
      CBR.Checked:=RLabels;
      BCPen.LinkPen(CCirclePen);
      BRPen.LinkPen(RCirclePen);

      CBColorEach.Checked:=ColorEachPoint;
      CBEachLine.Checked:=ColorEachLine;
      CBEachLine.Enabled:=ColorEachPoint;
      
      EImag.Text:=ImagSymbol;

      TBTransp.Position     :=Transparency;
      TBTranspChange(Self);

      CBPointerBehind.Checked:=PointerBehind;
      CBNulls.ItemIndex     :=Ord(TreatNulls);
      CBDrawStyle.ItemIndex :=Ord(DrawStyle);
    end;

    if not Assigned(CircledForm) then
       CircledForm:=TCircledSeriesEditor.CreateForm(Self, Smith);
  end;
end;

procedure TSmithSeriesEdit.CBCClick(Sender: TObject);
begin
  Smith.CLabels:=CBC.Checked;
end;

procedure TSmithSeriesEdit.CBRClick(Sender: TObject);
begin
  Smith.RLabels:=CBR.Checked;
end;

procedure TSmithSeriesEdit.CBColorEachClick(Sender: TObject);
begin
  Smith.ColorEachPoint:=CBColorEach.Checked;
  CBEachLine.Enabled:=CBColorEach.Checked;
end;

procedure TSmithSeriesEdit.BCFontClick(Sender: TObject);
begin
  EditTeeFontEx(Self,Smith.CLabelsFont);
end;

procedure TSmithSeriesEdit.BRFontClick(Sender: TObject);
begin
  EditTeeFontEx(Self,Smith.RLabelsFont);
end;

procedure TSmithSeriesEdit.EImagChange(Sender: TObject);
begin
  Smith.ImagSymbol:=EImag.Text;
end;

procedure TSmithSeriesEdit.FormCreate(Sender: TObject);
begin
  Align:=alClient;
end;

procedure TSmithSeriesEdit.FormDestroy(Sender: TObject);
begin
  FreeAndNil(CircledForm);
end;

procedure TSmithSeriesEdit.PageControl1Change(Sender: TObject);
begin
  if PageControl1.ActivePage.ControlCount=0 then
    if PageControl1.ActivePage=TabPointer then
       TSeriesPointerEditor.InsertForm(Smith.Pointer,TabPointer)
    else
    if PageControl1.ActivePage=TabBorder then
       TPenDialog.InsertForm(Smith.Pen,TabBorder)
    else
    if PageControl1.ActivePage=TabCircle then
       TPenDialog.InsertForm(Smith.CirclePen,TabCircle)
    else
    if PageControl1.ActivePage=TabBack then
       TBrushDialog.AddDialog(Smith.CircleBrush,TabBack);
end;

procedure TSmithSeriesEdit.TBTranspChange(Sender: TObject);
begin
  Smith.Transparency:=TBTransp.Position;
  LTransp.Caption:=IntToStr(TBTransp.Position);
end;

procedure TSmithSeriesEdit.CBNullsChange(Sender: TObject);
begin
  Smith.TreatNulls:=TTreatNullsStyle(CBNulls.ItemIndex);
end;

procedure TSmithSeriesEdit.CBPointerBehindClick(Sender: TObject);
begin
  Smith.PointerBehind:=CBPointerBehind.Checked;
end;

procedure TSmithSeriesEdit.CBDrawStyleChange(Sender: TObject);
begin
  if Showing then
  case CBDrawStyle.ItemIndex of
    0: Smith.DrawStyle:=dsSegments;
    1: Smith.DrawStyle:=dsAll;
  else
    Smith.DrawStyle:=dsCurve;
  end;
end;

procedure TSmithSeriesEdit.CBEachLineClick(Sender: TObject);
begin
  Smith.ColorEachLine:=CBEachLine.Checked;
end;

initialization
  RegisterClass(TSmithSeriesEdit);
end.
