unit TeeDoubleHorizBarEditor;
{$I TeeDefs.inc}

interface

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

     SysUtils, Classes,
     Graphics, Controls, Forms, Dialogs, ComCtrls, ExtCtrls, StdCtrls,

     TeeDoubleHorizBar, TeeProcs, TeeEdit, TeCanvas;

type
  TDoubleHorizBarEditor = class(TForm)
    PageControl1: TPageControl;
    TabLeft: TTabSheet;
    TabRight: TTabSheet;
    TabChart: TTabSheet;
    ChartEditorPanel1: TChartEditorPanel;
    TabSheet1: TTabSheet;
    Label1: TLabel;
    TBSplit: TTrackBar;
    LSplit: TLabel;
    GroupBox1: TGroupBox;
    CBHoriz: TCheckBox;
    CBVert: TCheckBox;
    GroupBox2: TGroupBox;
    Label2: TLabel;
    Label3: TLabel;
    ELeft: TEdit;
    ERight: TEdit;
    CBHorizAxis: TComboFlat;
    Label4: TLabel;
    procedure PageControl1Change(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBSplitChange(Sender: TObject);
    procedure CBVertClick(Sender: TObject);
    procedure CBHorizClick(Sender: TObject);
    procedure ERightChange(Sender: TObject);
    procedure ELeftChange(Sender: TObject);
    procedure CBHorizAxisChange(Sender: TObject);
  private
    { Private declarations }
    Bar : TDoubleHorizBarSeries;
  public
    { Public declarations }
  end;

implementation

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

uses
  TeEngine, Series, TeeBarEdit, TeePenDlg, TeeEditCha;

procedure TDoubleHorizBarEditor.PageControl1Change(Sender: TObject);

  procedure AddEditor(const ASeries:TCustomBarSeries; const ATab:TTabSheet);
  var tmp : TBarSeriesEditor;
  begin
    tmp:=TBarSeriesEditor.Create(nil);
    tmp.Align:=alClient;
    AddFormTo(tmp,ATab,ASeries);
    TeeTranslateControl(tmp);
  end;

begin
  if PageControl1.ActivePage=TabLeft then
  begin
    if TabLeft.ControlCount=0 then
       AddEditor(Bar.LeftSeries,TabLeft);
  end
  else
  if PageControl1.ActivePage=TabRight then
  begin
    if TabRight.ControlCount=0 then
       AddEditor(Bar,TabRight);
  end
  else
  if PageControl1.ActivePage=TabChart then
  begin
    if ChartEditorPanel1.Chart=nil then
    begin
      ChartEditorPanel1.Editor.Tree.Hide;
      ChartEditorPanel1.Editor.TheHiddenTabs:=[cetMain];
      ChartEditorPanel1.Chart:=Bar.LeftChart;
    end;
  end;
end;

procedure TDoubleHorizBarEditor.FormShow(Sender: TObject);
begin
  Bar:=TDoubleHorizBarSeries(Tag);

  if Assigned(Bar) then
  begin
    TBSplit.Position:=Bar.SplitSize;
    LSplit.Caption:=IntToStr(TBSplit.Position)+' %';

    CBVert.Checked:=Bar.InvertedVert;
    CBHoriz.Checked:=Bar.InvertedHoriz;

    ELeft.Text:=Bar.LeftSeries.GetHorizAxis.Title.Caption;

    if Bar.GetHorizAxis<>nil then
       ERight.Text:=Bar.GetHorizAxis.Title.Caption;

    case Bar.HorizAxis of
      aTopAxis: CBHorizAxis.ItemIndex:=0;
      aBottomAxis: CBHorizAxis.ItemIndex:=1;
    else
      CBHorizAxis.ItemIndex:=2;
    end;
  end;
end;

procedure TDoubleHorizBarEditor.TBSplitChange(Sender: TObject);
begin
  Bar.SplitSize:=TBSplit.Position;
  LSplit.Caption:=IntToStr(TBSplit.Position)+' %';
end;

procedure TDoubleHorizBarEditor.CBVertClick(Sender: TObject);
begin
  Bar.InvertedVert:=CBVert.Checked;
end;

procedure TDoubleHorizBarEditor.CBHorizClick(Sender: TObject);
begin
  Bar.InvertedHoriz:=CBHoriz.Checked;
end;

procedure TDoubleHorizBarEditor.ERightChange(Sender: TObject);
begin
  Bar.GetHorizAxis.Title.Caption:=ERight.Text;
end;

procedure TDoubleHorizBarEditor.ELeftChange(Sender: TObject);
begin
  Bar.LeftSeries.GetHorizAxis.Title.Caption:=ELeft.Text;
end;

procedure TDoubleHorizBarEditor.CBHorizAxisChange(Sender: TObject);
begin
  case CBHorizAxis.ItemIndex of
    0: Bar.HorizAxis:=aTopAxis;
    1: Bar.HorizAxis:=aBottomAxis;
  else
     Bar.HorizAxis:=aBothHorizAxis;
  end;

  Bar.LeftSeries.HorizAxis:=Bar.HorizAxis;

  Bar.LeftSeries.GetHorizAxis.Inverted:=not Bar.GetHorizAxis.Inverted;

  if Bar.HorizAxis=aBothHorizAxis then
     Bar.LeftChart.Axes.Top.Inverted:=not Bar.GetHorizAxis.Inverted;

  ELeftChange(Self);
  ERightChange(Self);
end;

initialization
  RegisterClass(TDoubleHorizBarEditor);
end.
