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

interface

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

     Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls, Buttons,
     TeCanvas, TeePenDlg, TeeErrorPoint, ErrorBar, TeePoEdi, TeeConst, TeeProcs;

type
  TErrorPointSeriesEditor = class(TForm)
    PageControl1: TPageControl;
    TabOptions: TTabSheet;
    TabBorders: TTabSheet;
    Label1: TLabel;
    SEBarwidth: TEdit;
    RGWidthUnit: TRadioGroup;
    UDBarWidth: TUpDown;
    CBColorEach: TCheckBox;
    LBBorders: TListBox;
    procedure FormShow(Sender: TObject);
    procedure SEBarwidthChange(Sender: TObject);
    procedure RGWidthUnitClick(Sender: TObject);
    procedure CBColorEachClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure FormDestroy(Sender: TObject);
    procedure LBBordersClick(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
  private
    { Private declarations }
    ErrorPointSeries : TCustomErrorPointSeries;
    FPointForm : TCustomForm;
    IPenEditor : TPenDialog;
  public
    { Public declarations }
  end;

implementation

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

procedure TErrorPointSeriesEditor.FormShow(Sender: TObject);
begin
  ErrorPointSeries:=TCustomErrorPointSeries(Tag);

  if Assigned(ErrorPointSeries) then
  With ErrorPointSeries do
  begin
    UDBarWidth.Position:=Errors.Size;

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

    CBColorEach.Checked:=ColorEachPoint;

    if not Assigned(FPointForm) then
       FPointForm:=TeeInsertPointerForm(Parent,Pointer,TeeMsg_GalleryPoint);
  end;
end;

procedure TErrorPointSeriesEditor.RGWidthUnitClick(Sender: TObject);
begin
  ErrorPointSeries.Errors.SizeUnits:=TErrorWidthUnits(RGWidthUnit.ItemIndex);
end;

procedure TErrorPointSeriesEditor.SEBarwidthChange(Sender: TObject);
begin
  if Showing then
     ErrorPointSeries.Errors.Size:=UDBarWidth.Position;
end;

procedure TErrorPointSeriesEditor.CBColorEachClick(Sender: TObject);
begin
  ErrorPointSeries.ColorEachPoint:=CBColorEach.Checked;
end;

procedure TErrorPointSeriesEditor.FormCreate(Sender: TObject);
begin
  BorderStyle:=TeeBorderStyle;
  LBBorders.ItemIndex:=0;
end;

procedure TErrorPointSeriesEditor.FormDestroy(Sender: TObject);
begin
  FreeAndNil(FPointForm);
end;

procedure TErrorPointSeriesEditor.LBBordersClick(Sender: TObject);
var tmp : TTeePen;
begin
  if Assigned(IPenEditor) then
  begin
    with ErrorPointSeries.Errors.Format do
    case LBBorders.ItemIndex of
      0: tmp:=Left;
      1: tmp:=Top;
      2: tmp:=Right;
    else
      tmp:=Bottom;
    end;

    IPenEditor.RefreshPen(tmp);
  end;
end;

procedure TErrorPointSeriesEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActivePage=TabBorders) and (TabBorders.ControlCount<2) then
  begin
    IPenEditor:=TPenDialog.InsertForm(ErrorPointSeries.Errors.Format.Left,TabBorders);
    LBBordersClick(Self);
  end;
end;

initialization
  RegisterClass(TErrorPointSeriesEditor);
end.
