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

interface

uses Classes,

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

     Chart, TeCanvas, TeeProcs, TeePenDlg, TeeCustomShapeEditor;

type
  TFormTeeWall = class(TForm)
    TabSubWalls: TTabControl;
    Panel1: TPanel;
    CBView3dWalls: TCheckBox;
    Label2: TLabel;
    EAllSize: TEdit;
    UDAllSize: TUpDown;
    PageControl1: TPageControl;
    TabSheet1: TTabSheet;
    L33: TLabel;
    SEWallSize: TEdit;
    UDWallSize: TUpDown;
    CBDark3D: TCheckBox;
    CBVisible: TCheckBox;
    CBAutoHide: TCheckBox;
    GroupBox1: TGroupBox;
    Label3: TLabel;
    Label4: TLabel;
    Edit2: TEdit;
    UDStart: TUpDown;
    Edit3: TEdit;
    UDEnd: TUpDown;
    BVisual: TButton;
    procedure TabSubWallsChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CBView3dWallsClick(Sender: TObject);
    procedure SEWallSizeChange(Sender: TObject);
    procedure CBDark3DClick(Sender: TObject);
    procedure CBVisibleClick(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CBAutoHideClick(Sender: TObject);
    procedure EAllSizeChange(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure Edit3Change(Sender: TObject);
    procedure BVisualClick(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
  private
    { Private declarations }
    SettingAllSize : Boolean;
    TheWall : TCustomChartWall;
    ShapeForm : TFormTeeShape;

    procedure SetWallControls;
    Function TheChart:TCustomChart;
  public
    { Public declarations }
    Constructor CreateWall(AOwner:TComponent; AWall:TCustomChartWall);

    procedure RefreshControls(Wall:TCustomChartWall);
  end;

implementation

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

Uses
  TeEngine;

Constructor TFormTeeWall.CreateWall(AOwner:TComponent; AWall:TCustomChartWall);
begin
  inherited Create(AOwner);
  TheWall:=AWall;
end;

procedure TFormTeeWall.RefreshControls(Wall:TCustomChartWall);
begin
  TheWall:=Wall;

  With TheChart.Walls do
  if TheWall=Left then TabSubWalls.TabIndex:=0 else
  if TheWall=Right then TabSubWalls.TabIndex:=1 else
  if TheWall=Bottom then TabSubWalls.TabIndex:=2 else
                         TabSubWalls.TabIndex:=3;

  SetWallControls;
end;

procedure TFormTeeWall.TabSubWallsChange(Sender: TObject);
begin
  with TheChart.Walls do
  case TabSubWalls.TabIndex of
    0: TheWall:=Left;
    1: TheWall:=Right;
    2: TheWall:=Bottom;
  else TheWall:=Back;
  end;

  SetWallControls;
end;

procedure TFormTeeWall.FormShow(Sender: TObject);
begin
  if Assigned(TheWall) then
     RefreshControls(TheWall);
end;

procedure TFormTeeWall.CBView3DWallsClick(Sender: TObject);
begin
  TheChart.View3DWalls:=CBView3DWalls.Checked;
end;

procedure TFormTeeWall.SEWallSizeChange(Sender: TObject);
begin
  if Showing then
  begin
    TheWall.Size:=UDWallSize.Position;
    CBDark3D.Enabled:=TheWall.Size>0;
  end;
end;

type
  TWallAccess=class(TCustomChartWall);
  TCustomChartAccess=class(TCustomChart);

procedure TFormTeeWall.SetWallControls;
begin
  CBView3DWalls.Checked:=TheChart.View3DWalls;

  With TheWall do
  begin
    UDWallSize.Position :=Size;
    CBDark3D.Checked    :=Dark3D;
    CBDark3D.Enabled    :=Size>0;
    CBVisible.Checked   :=Visible;
    CBAutoHide.Checked  :=AutoHide;
    UDStart.Position    :=StartPosition;
    UDEnd.Position      :=EndPosition;

    SettingAllSize:=True;
    try
      UDAllSize.Position    :=Size;
    finally
      SettingAllSize:=False;
    end;

    BVisual.Visible:=Assigned(TeeOnChangeVisual) and
                     (TCustomChartAccess(ParentChart).Form3DClass<>nil);
  end;

  // AutoHide not applicable to Bottom Wall.
  CBAutoHide.Visible:=TheWall<>TheChart.Walls.Bottom;

  ShapeForm.RefreshControls(TheWall);

  ShapeForm.TabShadow.TabVisible:=(TheWall=TheChart.Walls.Back);
  ShapeForm.TabEmboss.TabVisible:=ShapeForm.TabShadow.TabVisible;
  ShapeForm.PC1Change(PageControl1);
end;

procedure TFormTeeWall.CBDark3DClick(Sender: TObject);
begin
  TheWall.Dark3D:=CBDark3D.Checked;
end;

function TFormTeeWall.TheChart: TCustomChart;
begin
  result:=TCustomChart(TheWall.ParentChart);
end;

procedure TFormTeeWall.CBVisibleClick(Sender: TObject);
begin
  TheWall.Visible:=CBVisible.Checked;
end;

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

  With TabSubWalls.Tabs do
  begin
    Add('Left'); // Do not localize
    Add('Right'); // Do not localize
    Add('Bottom'); // Do not localize
    Add('Back'); // Do not localize
  end;

  ShapeForm:=InsertTeeObjectForm(PageControl1,nil);
  ShapeForm.TabText.TabVisible:=False; // Walls have no text, and no font
  ShapeForm.TabChildren.TabVisible:=False;
end;

procedure TFormTeeWall.CBAutoHideClick(Sender: TObject);
begin
  TheWall.AutoHide:=CBAutoHide.Checked;
end;

procedure TFormTeeWall.EAllSizeChange(Sender: TObject);
begin
  if Showing and (not SettingAllSize) then
  begin
    TheChart.Walls.Size:=UDAllSize.Position;
    SetWallControls;
  end;
end;

procedure TFormTeeWall.Edit2Change(Sender: TObject);
begin
  if Showing then
     TheWall.StartPosition:=UDStart.Position;
end;

procedure TFormTeeWall.Edit3Change(Sender: TObject);
begin
  if Showing then
     TheWall.EndPosition:=UDEnd.Position;
end;

procedure TFormTeeWall.BVisualClick(Sender: TObject);
begin
  with TWallAccess(TheWall) do
  if Assigned(Visual) then
  begin
    if Assigned(TeeOnEditVisual) then
       TeeOnEditVisual(Self,Visual);
  end
  else
  if Assigned(TeeOnChangeVisual) then
  begin
    Visual:=TeeOnChangeVisual(Self,TheWall.ParentChart,Visual);
    TheWall.Repaint;
  end;
end;

procedure TFormTeeWall.PageControl1Change(Sender: TObject);
begin
  if Assigned(ShapeForm) then
     ShapeForm.PC1Change(PageControl1);
end;

end.

