{*********************************************}
{  TeeChart Charting Library for FireMonkey   }
{  Copyright (c) 2012-2020 by Steema Software }
{  All Rights Reserved                        }
{*********************************************}
unit FMXTee.Editor.Tools.ScrollPager;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
  System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
  FMX.StdCtrls, FMXTee.Editor.Tools.Series, FMX.TabControl, FMX.ListBox,
  FMX.Colors, FMX.Edit, FMXTee.Editor.Series.Pointer, FMXTee.Tools.ScrollPager,
  FMXTee.Editor.Tools.SubChart, FMXTee.Editor.Tools.ColorBand;

type
  TScrollPagerEditor = class(TSeriesToolEditor)
    PageControl1: TTabControl;
    TabOptions: TTabItem;
    TabSubChart: TTabItem;
    TabColorBand: TTabItem;
    TabPointers: TTabItem;
    PagePointers: TTabControl;
    TabStart: TTabItem;
    TabEnd: TTabItem;
    Label2: TLabel;
    Label3: TLabel;
    UDDivision: TEdit;
    CBNoLimitDrag: TCheckBox;
    CBAlign: TComboBox;
    BHighLight: TComboColorBox;
    Label4: TLabel;
    procedure CBAlignChange(Sender: TObject);
    procedure CBNoLimitDragChange(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure PagePointersChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure UDDivisionChangeTracking(Sender: TObject);
    procedure UDDivisionChange(Sender: TObject);
    procedure BHighLightChange(Sender: TObject);
  private
    { Private declarations }
    IStart,
    IEnd : TSeriesPointerEditor;

    Tool : TScrollPagerTool;
    SubChart: TSubChartEditor;
    ColorBand: TColorBandToolEditor;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Editor.Stroke, FMXTee.Procs;

procedure TScrollPagerEditor.BHighLightChange(Sender: TObject);
begin
  Tool.PointerHighlightColor:=BHighLight.Color;
end;

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

procedure TScrollPagerEditor.CBNoLimitDragChange(Sender: TObject);
begin
  Tool.NoLimitDrag:=CBNoLimitDrag.IsChecked;
end;

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

  if Assigned(TagObject) and (TagObject is TScrollPagerTool) then
     Tool:=TScrollPagerTool(TagObject);

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

     BHighlight.Color:=Tool.PointerHighlightColor;

     SubChart:=TSubChartEditor.Create(Self);
     TeeTranslateControl(SubChart);

     SubChart.TagObject:=Tool.SubChartTool;
     EmbeddForm(SubChart,TabSubChart);

     SubChart.FormActivate(SubChart);

     ColorBand:=TColorBandToolEditor.Create(Self);
     TeeTranslateControl(ColorBand);

     ColorBand.TagObject:=Tool.ColorBandTool;
     EmbeddForm(ColorBand,TabColorBand);

     ColorBand.FormActivate(ColorBand);

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

     TabOptions.SetFocus;
  end;
end;

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

  if PageControl1.ActiveTab=TabPointers then
     PagePointersChange(Self);
end;

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

  if (PagePointers.ActiveTab=TabStart) and (not Assigned(IStart)) then
     IStart:=TSeriesPointerEditor.InsertForm(Tool.StartLinePointer,TabStart)
  else
  if (PagePointers.ActiveTab=TabEnd) and (not Assigned(IEnd)) then
     IEnd:=TSeriesPointerEditor.InsertForm(Tool.EndLinePointer,TabEnd)
end;

procedure TScrollPagerEditor.UDDivisionChange(Sender: TObject);
begin
  Tool.DivisionRatio:=StrToFloatDef(UDDivision.Text,3);
end;

procedure TScrollPagerEditor.UDDivisionChangeTracking(Sender: TObject);
begin
  UDDivisionChange(Sender);
end;

initialization
  RegisterClass(TScrollPagerEditor);
end.
