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

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
  System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
  {$IFNDEF UPTOXE3}
  FMX.StdCtrls,
  {$ENDIF}
  {$IFDEF D21}
  FMX.SpinBox,
  {$ENDIF}
  FMXTee.Editor.Tools.Axis, FMX.ListBox, FMXTee.Tools,
  FMXTee.Engine, FMX.TabControl, FMXTee.Procs, FMXTee.Editor.Tools.LegendScrollBar,
  FMX.Edit;

type
  TAxisScrollBarEditor = class(TAxisToolEditor)
    TabControl1: TTabControl;
    TabItem1: TTabItem;
    TabItem2: TTabItem;
    CBAllowResize: TCheckBox;
    Label2: TLabel;
    UDMargin: TSpinBox;
    procedure TabControl1Change(Sender: TObject);
    procedure CBAllowResizeChange(Sender: TObject);
    procedure UDMarginChangeTracking(Sender: TObject);
    procedure FormShow(Sender: TObject);
  private
    { Private declarations }
    IEditor : TScrollbarEditor;

  protected
    function GetAxis:TChartAxis; override;
    procedure SetAxis(const AAxis:TChartAxis); override;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Editor.Stroke;

{ TAxisScrollBarEditor }

procedure TAxisScrollBarEditor.CBAllowResizeChange(Sender: TObject);
begin
  if Assigned(AxisTool) then
     TAxisScrollBarTool(AxisTool).AllowResize:=CBAllowResize.IsChecked;
end;

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

  if Assigned(AxisTool) then
  begin
    UDMargin.Value:=TAxisScrollBarTool(AxisTool).Margin;
    CBAllowResize.IsChecked:=TAxisScrollBarTool(AxisTool).AllowResize;
  end;
end;

function TAxisScrollBarEditor.GetAxis: TChartAxis;
begin
  result:=TAxisScrollBarTool(AxisTool).Axis;
end;

procedure TAxisScrollBarEditor.SetAxis(const AAxis: TChartAxis);
begin
  TAxisScrollBarTool(AxisTool).Axis:=AAxis;
end;

procedure TAxisScrollBarEditor.TabControl1Change(Sender: TObject);
begin
  if TabControl1.ActiveTab=TabItem2 then
     if not Assigned(IEditor) then
     begin
       IEditor:=TScrollbarEditor.Create(Self);
       IEditor.TagObject:=AxisTool;

       EmbeddForm(IEditor,TabItem2);

       IEditor.FormActivate(IEditor);
     end;
end;

procedure TAxisScrollBarEditor.UDMarginChangeTracking(Sender: TObject);
begin
  if Assigned(AxisTool) then
     TAxisScrollBarTool(AxisTool).Margin:=Round(UDMargin.Value);
end;

initialization
  RegisterSeriesEditor(TAxisScrollBarEditor);
end.
