{********************************************}
{ TScrollPagerTool and Editor Dialog         }
{ Copyright (c) 2012-2020 by Steema Software }
{********************************************}
unit TeeScrollPagerEditor;
{$I TeeDefs.inc}

interface

uses
  {$IFDEF MSWINDOWS}
  Windows, Messages,
  {$ENDIF}

  SysUtils, Classes,

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

  TeCanvas, TeEngine, TeeScrollPagerTool, TeeToolSeriesEdit, TeePenDlg,
  TeeSubChartEditor, TeeColorBandEdit, TeeProcs;

type
  TScrollPagerEditor = class(TSeriesToolEditor)
    PageControl1: TPageControl;
    tsOptions: TTabSheet;
    tsSubChartTool: TTabSheet;
    tsColorBandTool: TTabSheet;
    Label2: TLabel;
    Edit1: TEdit;
    udDivision: TUpDown;
    BHighlight: TButtonColor;
    TabPointers: TTabSheet;
    PagePointers: TPageControl;
    TabStart: TTabSheet;
    TabEnd: TTabSheet;
    CBNoLimitDrag: TCheckBox;
    Label3: TLabel;
    CBAlign: TComboFlat;
    procedure udDivisionClick(Sender: TObject; Button: TUDBtnType);
    procedure FormShow(Sender: TObject);
    procedure PagePointersChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure CBNoLimitDragClick(Sender: TObject);
    procedure CBAlignChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
  private
    { Private declarations }
    Tool : TScrollPagerTool;
    SubChart: TSubChartEditor;
    ColorBand: TColorBandToolEditor;
  public
    { Public declarations }
  end;

implementation

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

uses
  Chart, TeePoEdi;

procedure TScrollPagerEditor.udDivisionClick(Sender: TObject;
  Button: TUDBtnType);
begin
  Tool.DivisionRatio:=StrToFloatDef(Edit1.Text,3);
end;

procedure TScrollPagerEditor.FormShow(Sender: TObject);
begin
  inherited;

  Tool:=TScrollPagerTool(Tag);

  if Assigned(Tool) then
  with Tool do
  begin
    Edit1.Text:=FloatToStr(Tool.DivisionRatio);

    BHighlight.LinkProperty(Tool,'PointerHighlightColor');

    CBAlign.ItemIndex:=Ord(Tool.Align);
    CBNoLimitDrag.Checked:=Tool.NoLimitDrag;
  end;
end;

procedure TScrollPagerEditor.PagePointersChange(Sender: TObject);
begin
  if (PagePointers.ActivePage=TabStart) and (TabStart.ControlCount=0) then
     TSeriesPointerEditor.InsertForm(Tool.StartLinePointer,TabStart)
  else
  if (PagePointers.ActivePage=TabEnd) and (TabEnd.ControlCount=0) then
     TSeriesPointerEditor.InsertForm(Tool.EndLinePointer,TabEnd)
end;

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

  if PageControl1.ActivePage=TabPointers then
     PagePointersChange(Self)
  else
  if (PageControl1.ActivePage=tsSubChartTool) and (tsSubChartTool.ControlCount=0) then
  begin
     SubChart:=TSubChartEditor.Create(Self);
     SubChart.Align:=alClient;
     TeeTranslateControl(SubChart);

     AddFormTo(SubChart,tsSubChartTool, Tool.SubChartTool);
  end
  else
  if (PageControl1.ActivePage=tsColorBandTool) and (tsColorBandTool.ControlCount=0) then
  begin
     ColorBand:=TColorBandToolEditor.Create(Self);
     ColorBand.Align:=alClient;
     TeeTranslateControl(ColorBand);

     AddFormTo(ColorBand,tsColorBandTool, Tool.ColorBandTool);
  end;
end;

procedure TScrollPagerEditor.CBNoLimitDragClick(Sender: TObject);
begin
  Tool.NoLimitDrag:=CBNoLimitDrag.Checked;
end;

procedure TScrollPagerEditor.CBAlignChange(Sender: TObject);
begin
  Tool.Align:=TScrollPagerAlign(CBAlign.ItemIndex);
end;

procedure TScrollPagerEditor.FormCreate(Sender: TObject);
begin
  inherited;
  PageControl1.ActivePage:=tsOptions;
end;

initialization
  RegisterClass(TScrollPagerEditor);
end.
