{**********************************************}
{   THistogramSeries Component Editor Dialog   }
{   Copyright (c) 2000-2020 by Steema Software }
{**********************************************}
unit TeeHistoEdit;
{$I TeeDefs.inc}

interface

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

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

     Chart, TeCanvas, TeePenDlg, TeeProcs, StatChar;

type
  THistogramSeriesEditor = class(TForm)
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    TabBorder: TTabSheet;
    TabLines: TTabSheet;
    TabPattern: TTabSheet;
    Label1: TLabel;
    GroupBox1: TGroupBox;
    CBColorEach: TCheckBox;
    BAreaColor: TButtonColor;
    Edit1: TEdit;
    UDTransp: TUpDown;
    GroupBox3: TGroupBox;
    Label2: TLabel;
    CBUseOrigin: TCheckBox;
    EOrigin: TEdit;
    UDOrigin: TUpDown;
    procedure FormShow(Sender: TObject);
    procedure CBColorEachClick(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CBUseOriginClick(Sender: TObject);
    procedure EOriginChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
  private
    { Private declarations }
    CreatingForm : Boolean;
    TheSeries    : THistogramSeries;
    Procedure EnableOrigin;
  public
    { Public declarations }
  end;

implementation

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

Uses
  TeEngine, TeeBrushDlg, TeePoEdi;

procedure THistogramSeriesEditor.FormShow(Sender: TObject);
begin
  TheSeries:=THistogramSeries(Tag);

  if Assigned(TheSeries) then
  begin
    With TheSeries do
    begin
      CBColorEach.Checked   :=ColorEachPoint;
      UDTransp.Position:=Transparency;
      CBUseOrigin.Checked   :=UseYOrigin;
      UDOrigin.Position     :=Round(YOrigin);
    end;

    With BAreaColor do
    begin
      LinkProperty(TheSeries,'SeriesColor'); // Do not localize
      Enabled:=not TheSeries.ColorEachPoint;
    end;
  end;

  EnableOrigin;

  CreatingForm:=False;
end;

procedure THistogramSeriesEditor.CBColorEachClick(Sender: TObject);
begin
  TheSeries.ColorEachPoint:=CBColorEach.Checked;
  BAreaColor.Enabled:=not TheSeries.ColorEachPoint;
end;

procedure THistogramSeriesEditor.Edit1Change(Sender: TObject);
begin
  if Showing and (not CreatingForm) then
     TheSeries.Transparency:=UDTransp.Position;
end;

procedure THistogramSeriesEditor.FormCreate(Sender: TObject);
begin
  CreatingForm:=True;
  BorderStyle:=TeeBorderStyle;
end;

procedure THistogramSeriesEditor.CBUseOriginClick(Sender: TObject);
begin
  TheSeries.UseYOrigin:=CBUseOrigin.Checked;
  EnableOrigin;
end;

procedure THistogramSeriesEditor.EOriginChange(Sender: TObject);
begin
  if Showing and Assigned(TheSeries) then
     TheSeries.YOrigin:=UDOrigin.Position
end;

procedure THistogramSeriesEditor.EnableOrigin;
begin
  EOrigin.Enabled:=CBUseOrigin.Checked;
  UDOrigin.Enabled:=EOrigin.Enabled;
end;

procedure THistogramSeriesEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActivePage=TabBorder) and (TabBorder.ControlCount=0) then
     TPenDialog.InsertForm(TheSeries.Pen,TabBorder)
  else
  if (PageControl1.ActivePage=TabLines) and (TabLines.ControlCount=0) then
     TPenDialog.InsertForm(TheSeries.LinesPen,TabLines)
  else
  if (PageControl1.ActivePage=TabPattern) and (TabPattern.ControlCount=0) then
     TBrushDialog.AddDialog(TheSeries.Brush,TabPattern);
end;

initialization
  RegisterClass(THistogramSeriesEditor);
end.
