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

interface

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

     {$IFDEF D16}
     System.UITypes,
     {$ENDIF}

     Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls,
     Chart, Series, ErrorBar, TeCanvas, TeePenDlg, TeeProcs;

type
  TErrorSeriesEditor = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabBorder: TTabSheet;
    Label1: TLabel;
    SEBarwidth: TEdit;
    RGWidthUnit: TRadioGroup;
    UDBarWidth: TUpDown;
    RGStyle: TRadioGroup;
    CBColorEach: TCheckBox;
    BColor: TButtonColor;
    procedure FormShow(Sender: TObject);
    procedure SEBarwidthChange(Sender: TObject);
    procedure RGWidthUnitClick(Sender: TObject);
    procedure RGStyleClick(Sender: TObject);
    procedure CBColorEachClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure BColorClick(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
  private
    { Private declarations }
    ErrorSeries : TCustomErrorSeries;
    FBarForm : TCustomForm;
    IPenEditor : TPenDialog;

    procedure ChangedPen(Sender: TObject);
  public
    { Public declarations }
  end;

implementation

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

Uses
  TeeBrushDlg, TeeBarEdit, TeeConst, TeeEdiSeri;

procedure TErrorSeriesEditor.FormShow(Sender: TObject);
begin
  ErrorSeries:=TCustomErrorSeries(Tag);

  if Assigned(ErrorSeries) then
  With ErrorSeries do
  begin
    UDBarWidth.Position:=ErrorWidth;

    if ErrorWidthUnits=ewuPercent then RGWidthUnit.ItemIndex:=0
                                  else RGWidthUnit.ItemIndex:=1;

    if ErrorSeries is TErrorBarSeries then
    begin
      RGStyle.Items.Delete(0);
      RGStyle.Items.Delete(0);
      RGStyle.Items.Delete(0);
    end;

    RGStyle.Enabled:=RGStyle.Visible;

    if ErrorSeries is TErrorBarSeries then
      RGStyle.ItemIndex:=Ord(ErrorStyle)-3
    else
      RGStyle.ItemIndex:=Ord(ErrorStyle);

    CBColorEach.Checked:=ColorEachPoint;
  end;

  if (ErrorSeries is TErrorBarSeries) and (not Assigned(FBarForm)) then
     FBarForm:=TFormTeeSeries.InsertSeriesForm(Parent,TBarSeriesEditor,
                                                     1,TeeMsg_GalleryBar,
                                                     ErrorSeries);
end;

procedure TErrorSeriesEditor.SEBarwidthChange(Sender: TObject);
begin
  if Showing then
     ErrorSeries.ErrorWidth:=UDBarWidth.Position;
end;

procedure TErrorSeriesEditor.ChangedPen(Sender: TObject);
begin
  if not (ErrorSeries is TErrorBarSeries) then
     ErrorSeries.SeriesColor:=ErrorSeries.ErrorPen.Color;
end;

procedure TErrorSeriesEditor.RGWidthUnitClick(Sender: TObject);
begin
  ErrorSeries.ErrorWidthUnits:=TErrorWidthUnits(RGWidthUnit.ItemIndex);
end;

procedure TErrorSeriesEditor.RGStyleClick(Sender: TObject);
begin
  if Showing then
     if ErrorSeries is TErrorBarSeries then
        ErrorSeries.ErrorStyle:=TErrorSeriesStyle(RGStyle.ItemIndex+3)
     else
        ErrorSeries.ErrorStyle:=TErrorSeriesStyle(RGStyle.ItemIndex);
end;

procedure TErrorSeriesEditor.CBColorEachClick(Sender: TObject);
begin
  ErrorSeries.ColorEachPoint:=CBColorEach.Checked;
end;

procedure TErrorSeriesEditor.FormCreate(Sender: TObject);
begin
  BorderStyle:=TeeBorderStyle;
end;

procedure TErrorSeriesEditor.FormDestroy(Sender: TObject);
begin
  FreeAndNil(FBarForm);
end;

procedure TErrorSeriesEditor.BColorClick(Sender: TObject);
begin
  if Assigned(IPenEditor) then
     IPenEditor.BColor.Invalidate;
end;

procedure TErrorSeriesEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActivePage=TabBorder) and (TabBorder.ControlCount=0) then
  begin
    IPenEditor:=TPenDialog.InsertForm(ErrorSeries.ErrorPen,TabBorder);
    IPenEditor.OnChangedPen:=ChangedPen;
  end;
end;

initialization
  RegisterClass(TErrorSeriesEditor);
end.
