{**********************************************}
{    TeeChart ColorLine Tool Editor            }
{   Copyright (c) 2000-2020 by Steema Software }
{**********************************************}
unit TeeColorLineEditor;
{$I TeeDefs.inc}

interface

uses {$IFNDEF LINUX}
     Windows, Messages,
     {$ENDIF}
     SysUtils, Classes,
     Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls,
     TeeAxisToolEdit, TeeProcs, TeCanvas, TeeTools, TeePenDlg;

type
  TColorLineToolEditor = class(TAxisToolEditor)
    PageControl1: TPageControl;
    TabValue: TTabSheet;
    Label2: TLabel;
    EValue: TEdit;
    TabOptions: TTabSheet;
    CBAllowDrag: TCheckBox;
    CBDragRepaint: TCheckBox;
    CBNoLimitDrag: TCheckBox;
    CBDrawBehind: TCheckBox;
    CBDraw3D: TCheckBox;
    Label3: TLabel;
    CBStyle: TComboFlat;
    TabBorder: TTabSheet;
    TabAnnotation: TTabSheet;
    Timer1: TTimer;
    CBAnnValue: TCheckBox;
    procedure EValueChange(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure CBAllowDragClick(Sender: TObject);
    procedure CBDragRepaintClick(Sender: TObject);
    procedure CBNoLimitDragClick(Sender: TObject);
    procedure CBDrawBehindClick(Sender: TObject);
    procedure CBDraw3DClick(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure PageControl1GetImageIndex(Sender: TObject; TabIndex: Integer;
      var ImageIndex: Integer);
    procedure Timer1Timer(Sender: TObject);
    procedure CBAnnValueClick(Sender: TObject);
  private
    { Private declarations }
    CreatingForm  : Boolean;
    ColorLineTool : TColorLineTool;
  public
    { Public declarations }
    procedure HideTabs;
  end;

implementation

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

uses
  TeeAnnToolEdit;

procedure TColorLineToolEditor.EValueChange(Sender: TObject);
begin
  if not CreatingForm then
     with ColorLineTool do Value:=StrToFloatDef(EValue.Text,Value);
end;

procedure TColorLineToolEditor.FormShow(Sender: TObject);
begin
  inherited;
  ColorLineTool:=TColorLineTool(Tag);

  if Assigned(ColorLineTool) then
  with ColorLineTool do
  begin
    EValue.Text:=FloatToStr(Value);
    CBAllowDrag.Checked:=AllowDrag;
    CBDragRepaint.Checked:=DragRepaint;
    CBNoLimitDrag.Checked:=NoLimitDrag;
    CBDraw3D.Checked:=Draw3D;
    CBDrawBehind.Checked:=DrawBehind;
    CBStyle.ItemIndex:=Ord(Style);
    EValue.Enabled:=Style=clCustom;
    CBAnnValue.Checked:=AnnotationValue;
  end;

  CreatingForm:=False;
end;

procedure TColorLineToolEditor.CBAllowDragClick(Sender: TObject);
begin
  ColorLineTool.AllowDrag:=CBAllowDrag.Checked
end;

procedure TColorLineToolEditor.CBDragRepaintClick(Sender: TObject);
begin
  ColorLineTool.DragRepaint:=CBDragRepaint.Checked;
end;

procedure TColorLineToolEditor.CBNoLimitDragClick(Sender: TObject);
begin
  ColorLineTool.NoLimitDrag:=CBNoLimitDrag.Checked;
end;

procedure TColorLineToolEditor.CBDrawBehindClick(Sender: TObject);
begin
  ColorLineTool.DrawBehind:=CBDrawBehind.Checked;
end;

procedure TColorLineToolEditor.CBDraw3DClick(Sender: TObject);
begin
  ColorLineTool.Draw3D:=CBDraw3D.Checked;
end;

procedure TColorLineToolEditor.CBStyleChange(Sender: TObject);
begin
  if not CreatingForm then
  begin
    ColorLineTool.Style:=TColorLineStyle(CBStyle.ItemIndex);
    EValue.Enabled:=ColorLineTool.Style=clCustom;
  end;
end;

procedure TColorLineToolEditor.FormCreate(Sender: TObject);
begin
  CreatingForm:=True;
  inherited;
end;

procedure TColorLineToolEditor.PageControl1Change(Sender: TObject);
begin
  inherited;

  if PageControl1.ActivePage=TabBorder then
  begin
    if TabBorder.ControlCount=0 then
       TPenDialog.InsertForm(ColorLineTool.Pen,TabBorder);
  end
  else
  if PageControl1.ActivePage=TabAnnotation then
     if TabAnnotation.ControlCount=0 then
        TAnnotationToolEdit.InsertForm(ColorLineTool.Annotation,TabAnnotation);
end;

procedure TColorLineToolEditor.PageControl1GetImageIndex(Sender: TObject;
  TabIndex: Integer; var ImageIndex: Integer);
begin
  inherited;
  // Dummy
end;

procedure TColorLineToolEditor.HideTabs;
begin
  PanelTop.Hide;
  TabValue.TabVisible:=False;
  TabOptions.TabVisible:=False;

  // Workaround:
  Timer1.Enabled:=True;
end;

procedure TColorLineToolEditor.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled:=False;
  PageControl1.ActivePage:=TabBorder;
  PageControl1Change(Self);
end;

procedure TColorLineToolEditor.CBAnnValueClick(Sender: TObject);
begin
  if not CreatingForm then
     ColorLineTool.AnnotationValue:=CBAnnValue.Checked;
end;

initialization
  RegisterClass(TColorLineToolEditor);
end.
