{**********************************************}
{   TCustomSeries Component Editor Dialog      }
{   Copyright (c) 1996-2020 by Steema Software }
{**********************************************}
unit TeeCustEdit;
{$I TeeDefs.inc}

interface

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

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

     TeeProcs, Chart, Series, TeCanvas, TeePenDlg, TeeEdiGrad;

type
  TCustomSeriesEditor = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabFormat: TTabSheet;
    BLineColor: TButtonColor;
    CBColorEach: TCheckBox;
    CBDark3D: TCheckBox;
    TBTransp: TTrackBar;
    LTransp: TLabel;
    CBEachLine: TCheckBox;
    Label1: TLabel;
    LHeight: TLabel;
    Label2: TLabel;
    GBStair: TGroupBox;
    CBStairs: TCheckBox;
    CBInvStairs: TCheckBox;
    CBSmoothed: TCheckBox;
    CBStack: TComboFlat;
    EHeight: TEdit;
    UDHeight: TUpDown;
    CBClick: TCheckBox;
    CBNulls: TComboFlat;
    Label3: TLabel;
    ETolerance: TEdit;
    UDTolerance: TUpDown;
    TabBorder: TTabSheet;
    TabPattern: TTabSheet;
    TabShadow: TTabSheet;
    TabEmboss: TTabSheet;
    TabOutline: TTabSheet;
    LDrawStyle: TLabel;
    CBDrawStyle: TComboFlat;
    CBDefColor: TCheckBox;
    CBPointerBehind: TCheckBox;
    Panel1: TPanel;
    CBInflate: TCheckBox;
    procedure FormShow(Sender: TObject);
    procedure CBStairsClick(Sender: TObject);
    procedure CBInvStairsClick(Sender: TObject);
    procedure CBColorEachClick(Sender: TObject);
    procedure CBDark3DClick(Sender: TObject);
    procedure CBStackChange(Sender: TObject);
    procedure EHeightChange(Sender: TObject);
    procedure CBClickClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CBEachLineClick(Sender: TObject);
    procedure BLineColorClick(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure CBNullsChange(Sender: TObject);
    procedure TBTranspChange(Sender: TObject);
    procedure CBSmoothedClick(Sender: TObject);
    procedure EToleranceChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure CBDrawStyleChange(Sender: TObject);
    procedure CBDefColorClick(Sender: TObject);
    procedure CBPointerBehindClick(Sender: TObject);
    procedure CBInflateClick(Sender: TObject);
  private
    { Private declarations }
    PointerForm : TCustomForm;
    TheSeries   : TCustomSeries;

    IBorderEditor : TPenDialog;

    procedure CheckDefColor;
  public
    { Public declarations }
  end;

implementation

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

uses
  TeEngine, TeePoEdi, TeeConst, TeeBrushDlg, TeeShadowEditor;

type
  TCustomSeriesAccess=class(TCustomSeries);

procedure TCustomSeriesEditor.FormShow(Sender: TObject);
begin
  TheSeries:=TCustomSeries(Tag);

  if Assigned(TheSeries) then
  begin
    with TheSeries do
    Begin
      CBColorEach.Checked:=ColorEachPoint;
      CBStack.ItemIndex:=Ord(TCustomSeriesAccess(TheSeries).Stacked);
      CBClick.Checked:=ClickableLine;
      CBEachLine.Checked:=ColorEachLine;
      TBTransp.Position:=TheSeries.Transparency;

      CBPointerBehind.Checked:=PointerBehind;
      CBInflate.Checked:=InflateMargins;

      if TheSeries is TLineSeries then
      begin
        CBStairs.Checked:=Stairs;
        CBInvStairs.Checked:=InvertedStairs;
        CBInvStairs.Enabled:=CBStairs.Checked;

        {$IFDEF TEELITEEMB}
        CBSmoothed.Visible:=False;
        {$ELSE}
        CBSmoothed.Checked:=Smoothed;
        CBSmoothed.Enabled:=TheSeries is TLineSeries;
        {$ENDIF}

        CBDark3D.Checked:=Dark3D;
        UDHeight.Position:=LineHeight;
        CBNulls.ItemIndex:=Ord(TreatNulls);

        UDTolerance.Position:=ClickTolerance;

        CBDrawStyle.ItemIndex:=Ord(TheSeries.DrawStyle);
      end
      else
      begin
        TabPattern.TabVisible:=False;
        TabOutline.TabVisible:=False;

        ShowControls(False,[ GBStair,CBDark3D,LHeight,EHeight,UDHeight,
                             CBDrawStyle,LDrawStyle]);
      end;
    end;

    BLineColor.LinkProperty(TheSeries,'SeriesColor'); // Do not localize

    CheckDefColor;

    if Assigned(Parent) and (not Assigned(PointerForm)) then
       PointerForm:=TeeInsertPointerForm(Parent,TheSeries.Pointer,TeeMsg_GalleryPoint);
  end;
end;

procedure TCustomSeriesEditor.CheckDefColor;
begin
  CBDefColor.Checked:=TheSeries.Color=clTeeColor;
  CBDefColor.Enabled:=not CBDefColor.Checked;
end;

procedure TCustomSeriesEditor.CBStairsClick(Sender: TObject);
begin
  TheSeries.Stairs:=CBStairs.Checked;
  CBInvStairs.Enabled:=CBStairs.Checked;
end;

procedure TCustomSeriesEditor.CBInvStairsClick(Sender: TObject);
begin
  TheSeries.InvertedStairs:=CBInvStairs.Checked;
end;

procedure TCustomSeriesEditor.CBColorEachClick(Sender: TObject);
begin
  TheSeries.ColorEachPoint:=CBColorEach.Checked;
end;

procedure TCustomSeriesEditor.CBDark3DClick(Sender: TObject);
begin
  TheSeries.Dark3D:=CBDark3D.Checked;
end;

procedure TCustomSeriesEditor.CBStackChange(Sender: TObject);
begin
  TCustomSeriesAccess(TheSeries).Stacked:=TCustomSeriesStack(CBStack.ItemIndex);
end;

procedure TCustomSeriesEditor.EHeightChange(Sender: TObject);
begin
  if Showing then TheSeries.LineHeight:=UDHeight.Position
end;

procedure TCustomSeriesEditor.CBClickClick(Sender: TObject);
begin
  TheSeries.ClickableLine:=CBClick.Checked
end;

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

procedure TCustomSeriesEditor.CBEachLineClick(Sender: TObject);
begin
  TheSeries.ColorEachLine:=CBEachLine.Checked;
end;

procedure TCustomSeriesEditor.BLineColorClick(Sender: TObject);
begin
  if TheSeries.ParentChart.View3D then
     TheSeries.ResetBrush;

  CheckDefColor;
end;

procedure TCustomSeriesEditor.FormDestroy(Sender: TObject);
begin
  FreeAndNil(PointerForm);
end;

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

procedure TCustomSeriesEditor.TBTranspChange(Sender: TObject);
begin
  TCustomSeriesAccess(TheSeries).Transparency:=TBTransp.Position;
end;

procedure TCustomSeriesEditor.CBSmoothedClick(Sender: TObject);
begin
  {$IFNDEF TEELITEEMB}
  TheSeries.Smoothed:=CBSmoothed.Checked;
  {$ENDIF}
end;

procedure TCustomSeriesEditor.EToleranceChange(Sender: TObject);
begin
  if Showing then TheSeries.ClickTolerance:=UDTolerance.Position
end;

procedure TCustomSeriesEditor.PageControl1Change(Sender: TObject);
begin
  if PageControl1.ActivePage=TabFormat then
     BLineColor.Invalidate
  else
  if PageControl1.ActivePage=TabBorder then
  begin
    if not Assigned(IBorderEditor) then
       IBorderEditor:=TPenDialog.InsertForm(TheSeries.LinePen, TabBorder)
    else
       IBorderEditor.BColor.Invalidate;
  end
  else
  if (PageControl1.ActivePage=TabPattern) and (TabPattern.ControlCount=0) then
     TBrushDialog.AddDialog(TheSeries.Brush,TabPattern)
  else
  if (PageControl1.ActivePage=TabShadow) and (TabShadow.ControlCount=0) then
     TTeeShadowEditor.InsertForm(TheSeries.Shadow,TabShadow)
  else
  if (PageControl1.ActivePage=TabEmboss) and (TabEmboss.ControlCount=0) then
     TTeeShadowEditor.InsertForm(TheSeries.Emboss,TabEmboss)
  else
  if (PageControl1.ActivePage=TabOutline) and (TabOutline.ControlCount=0) then
     TPenDialog.InsertForm(TheSeries.OutLine,TabOutline)
end;

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

type
  TSeriesAccess=class(TChartSeries);

procedure TCustomSeriesEditor.CBDefColorClick(Sender: TObject);
begin
  if CBDefColor.Checked then
  begin
    TSeriesAccess(TheSeries).SetDefaultColor;
    BLineColor.Invalidate;
    CBDefColor.Enabled:=False;
  end;
end;

procedure TCustomSeriesEditor.CBPointerBehindClick(Sender: TObject);
begin
  TheSeries.PointerBehind:=CBPointerBehind.Checked;
end;

procedure TCustomSeriesEditor.CBInflateClick(Sender: TObject);
begin
  TheSeries.InflateMargins:=CBInflate.Checked;
end;

initialization
  RegisterSeriesEditor(TCustomSeriesEditor);
end.
