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

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMXTee.Editor.Tools.Series,
  {$IFNDEF UPTOXE3}
  FMX.StdCtrls,
  {$ENDIF}
  {$IFDEF D21}
  FMX.SpinBox,
  {$ENDIF}
  FMX.ListBox, FMXTee.Tools, FMX.Edit, FMX.TabControl, FMX.Layouts, FMX.Memo,
  FMXTee.Tools.LegendScrollBar, FMX.Colors,
  FMXTee.Editor.Stroke, FMXTee.Editor.Brush, FMXTee.Editor.Gradient,
  FMXTee.Editor.Picture, FMXTee.Procs;

type
  TScrollbarEditor = class(TForm)
    TabControl1: TTabControl;
    TabOptions: TTabItem;
    TabFormat: TTabItem;
    TabThumb: TTabItem;
    CBAuto: TCheckBox;
    Label5: TLabel;
    UDSize: TSpinBox;
    Label4: TLabel;
    UDDelay: TSpinBox;
    CBArrows: TCheckBox;
    Layout1: TLayout;
    CBColor: TComboColorBox;
    Label1: TLabel;
    TabControl2: TTabControl;
    TabBorder: TTabItem;
    TabBack: TTabItem;
    TabArrows: TTabItem;
    TabDisabled: TTabItem;
    TabControl3: TTabControl;
    TabThumbOptions: TTabItem;
    TabThumbBorder: TTabItem;
    TabThumbBrush: TTabItem;
    Label3: TLabel;
    CBBevel: TComboBox;
    ListBoxItem6: TListBoxItem;
    ListBoxItem7: TListBoxItem;
    ListBoxItem8: TListBoxItem;
    Label2: TLabel;
    UDThumbSize: TSpinBox;
    Label6: TLabel;
    UDRoundSize: TSpinBox;
    CBStyle: TComboBox;
    ListBoxItem1: TListBoxItem;
    ListBoxItem2: TListBoxItem;
    ListBoxItem3: TListBoxItem;
    ListBoxItem4: TListBoxItem;
    ListBoxItem5: TListBoxItem;
    Label7: TLabel;
    procedure FormActivate(Sender: TObject);
    procedure UDSizeChange(Sender: TObject);
    procedure CBAutoChange(Sender: TObject);
    procedure UDDelayChange(Sender: TObject);
    procedure CBColorChange(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure UDThumbSizeChange(Sender: TObject);
    procedure CBBevelChange(Sender: TObject);
    procedure CBArrowsChange(Sender: TObject);
    procedure TabControl1Change(Sender: TObject);
    procedure TabControl2Change(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure TabControl3Change(Sender: TObject);
    procedure UDRoundSizeChangeTracking(Sender: TObject);
  private
    { Private declarations }

    Scrollbar : TTeeScrollBar;

    IArrow    : TBrushEditor;
    IBorder   : TStrokeEditor;
    IBack     : TBrushEditor;
    IDisabled : TBrushEditor;
    IThumbBorder : TStrokeEditor;
    IThumbBrush  : TBrushEditor;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

procedure TScrollbarEditor.CBColorChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
     Scrollbar.BackColor:=CBColor.Color;
end;

procedure TScrollbarEditor.CBStyleChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
     Scrollbar.Thumb.Style:=TScrollThumbStyle(CBStyle.ItemIndex);
end;

procedure TScrollbarEditor.CBArrowsChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
     Scrollbar.Arrows:=CBArrows.IsChecked;
end;

procedure TScrollbarEditor.CBAutoChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
     Scrollbar.AutoRepeat:=CBAuto.IsChecked;
end;

procedure TScrollbarEditor.CBBevelChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
     Scrollbar.Bevel:=TPanelBevel(CBStyle.ItemIndex);
end;

procedure TScrollbarEditor.FormActivate(Sender: TObject);
begin
  if not Assigned(Scrollbar) then
  begin
    Scrollbar:=TTeeScrollBar(TagObject);;

    if Assigned(Scrollbar) then
    begin
      With Scrollbar do
      begin
        CBBevel.ItemIndex:=Ord(Bevel);
        CBAuto.IsChecked:=AutoRepeat;
        CBArrows.IsChecked:=Arrows;
        UDSize.Value:=Size;
        UDDelay.Value:=InitialDelay;

        UDThumbSize.Value:=Thumb.Size;
        UDRoundSize.Value:=RoundSize;

        CBColor.Color:=BackColor;

        CBStyle.ItemIndex:=Ord(Thumb.Style);
      end;
    end;
  end;
end;

procedure TScrollbarEditor.FormCreate(Sender: TObject);
begin
  TabControl1.ActiveTab:=TabOptions;
  TabControl2.ActiveTab:=TabBorder;
  TabControl3.ActiveTab:=TabThumbOptions;
end;

procedure TScrollbarEditor.TabControl1Change(Sender: TObject);
begin
  if TabControl1.ActiveTab=TabFormat then
     TabControl2Change(Self)
  else
  if TabControl1.ActiveTab=TabThumb then
     TabControl3Change(Self);
end;

procedure TScrollbarEditor.TabControl2Change(Sender: TObject);
begin
  if (TabControl2.ActiveTab=TabBorder) and (not Assigned(IBorder)) then
     IBorder:=TStrokeEditor.InsertForm(ScrollBar.Pen,TabBorder)
  else
  if (TabControl2.ActiveTab=TabBack) and (not Assigned(IBack)) then
     IBack:=TBrushEditor.InsertForm(ScrollBar.Brush,TabBack)
  else
  if (TabControl2.ActiveTab=TabArrows) and (not Assigned(IArrow)) then
     IArrow:=TBrushEditor.InsertForm(ScrollBar.ArrowBrush,TabArrows)
  else
  if (TabControl2.ActiveTab=TabDisabled) and (not Assigned(IDisabled)) then
     IDisabled:=TBrushEditor.InsertForm(ScrollBar.DisabledArrow,TabDisabled)
end;

procedure TScrollbarEditor.TabControl3Change(Sender: TObject);
begin
  if (TabControl3.ActiveTab=TabThumbBorder) and (not Assigned(IThumbBorder)) then
     IThumbBorder:=TStrokeEditor.InsertForm(ScrollBar.Thumb.Pen,TabThumbBorder)
  else
  if (TabControl3.ActiveTab=TabThumbBrush) and (not Assigned(IThumbBrush)) then
     IThumbBrush:=TBrushEditor.InsertForm(ScrollBar.Thumb.Brush,TabThumbBrush)
end;

procedure TScrollbarEditor.UDSizeChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
    Scrollbar.Size:=Round(UDSize.Value);
end;

procedure TScrollbarEditor.UDThumbSizeChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
    Scrollbar.ThumbSize:=Round(UDThumbSize.Value);
end;

procedure TScrollbarEditor.UDDelayChange(Sender: TObject);
begin
  if Assigned(Scrollbar) then
     Scrollbar.InitialDelay:=Round(UDDelay.Value);
end;

procedure TScrollbarEditor.UDRoundSizeChangeTracking(Sender: TObject);
begin
  if Assigned(Scrollbar) then
     Scrollbar.RoundSize:=Round(UDRoundSize.Value);
end;

initialization
  RegisterSeriesEditor(TScrollbarEditor);
end.
