{**********************************************}
{   TeeChart Legend Scrollbar Tool             }
{   Copyright (c) 2003-2020 by Steema Software }
{**********************************************}
unit TeeLegendScrollBarEditor;
{$I TeeDefs.inc}

interface

uses
  {$IFNDEF LINUX}
  Windows,
  {$ENDIF}

  Forms, Controls, Graphics, ExtCtrls, StdCtrls, ComCtrls, Buttons,
  {$IFDEF D9}
  Types,
  {$ENDIF}

  Classes, SysUtils,
  {$IFDEF LINUX}
  Types,
  {$ENDIF}

  {$IFDEF LCL}
  GraphType,
  {$ENDIF}

  TeEngine, Chart, TeeTools, Series, TeeProcs, TeCanvas, TeePenDlg, TeeEdiGrad;

type
  TScrollbarEditor = class(TForm)
    PageControl1: TPageControl;
    TabFormat: TTabSheet;
    TabSheet2: TTabSheet;
    TabSheet3: TTabSheet;
    Label2: TLabel;
    Label3: TLabel;
    CBAuto: TCheckBox;
    Edit1: TEdit;
    UDSize: TUpDown;
    Edit2: TEdit;
    UDDelay: TUpDown;
    PageControl2: TPageControl;
    TabBorder: TTabSheet;
    TabBack: TTabSheet;
    TabArrows: TTabSheet;
    Panel1: TPanel;
    ButtonColor1: TButtonColor;
    PageThumb: TPageControl;
    TabThumbOptions: TTabSheet;
    TabThumbBorder: TTabSheet;
    LThumbSize: TLabel;
    Label1: TLabel;
    EThumbSize: TEdit;
    UDThumbSize: TUpDown;
    CBBevel: TComboFlat;
    TabDisabled: TTabSheet;
    CBArrows: TCheckBox;
    Label5: TLabel;
    CBStyle: TComboFlat;
    TabThumbPattern: TTabSheet;
    Label6: TLabel;
    ERoundSize: TEdit;
    UDRoundSize: TUpDown;
    procedure FormShow(Sender: TObject);
    procedure CBBevelChange(Sender: TObject);
    procedure CBAutoClick(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure Edit2Change(Sender: TObject);
    procedure EThumbSizeChange(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure PageControl2Change(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
    procedure PageThumbChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CBArrowsClick(Sender: TObject);
    procedure ERoundSizeChange(Sender: TObject);
  private
    { Private declarations }
    TeeScroll : TTeeScrollBar;
  public
    { Public declarations }
    procedure HideThumbSize;
  end;

implementation

uses
  Math, TeeBrushDlg, TeeProCo, TeeFiltersEditor;

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

{ TScrollbarEditor }

procedure TScrollbarEditor.FormShow(Sender: TObject);
begin
  TeeScroll:=TTeeScrollBar(Tag);

  if Assigned(TeeScroll) then
  with TeeScroll do
  begin
    CBBevel.ItemIndex:=Ord(Bevel);
    CBAuto.Checked:=AutoRepeat;
    UDSize.Position:=Size;
    UDDelay.Position:=InitialDelay;
    UDThumbSize.Position:=Thumb.Size;

    ButtonColor1.LinkProperty(TeeScroll,'BackColor'); // Do not localize

    CBStyle.ItemIndex:=Ord(Thumb.Style);
    CBArrows.Checked:=Arrows;
    UDRoundSize.Position:=RoundSize;
  end;
end;

procedure TScrollbarEditor.HideThumbSize;
begin
  LThumbSize.Hide;
  EThumbSize.Hide;
  UDThumbSize.Hide;
end;

procedure TScrollbarEditor.CBBevelChange(Sender: TObject);
begin
  TeeScroll.Bevel:=TPanelBevel(CBBevel.ItemIndex);
end;

procedure TScrollbarEditor.CBAutoClick(Sender: TObject);
begin
  TeeScroll.AutoRepeat:=CBAuto.Checked;
end;

procedure TScrollbarEditor.Edit1Change(Sender: TObject);
begin
  if Showing and Assigned(TeeScroll) then
     TeeScroll.Size:=UDSize.Position;
end;

procedure TScrollbarEditor.Edit2Change(Sender: TObject);
begin
  if Showing and Assigned(TeeScroll) then
     TeeScroll.InitialDelay:=UDDelay.Position;
end;

procedure TScrollbarEditor.EThumbSizeChange(Sender: TObject);
begin
  if Showing and Assigned(TeeScroll) then
     TeeScroll.ThumbSize:=UDThumbSize.Position;
end;

procedure TScrollbarEditor.CBStyleChange(Sender: TObject);
begin
  TeeScroll.Thumb.Style:=TScrollThumbStyle(CBStyle.ItemIndex);
end;

procedure TScrollbarEditor.PageControl2Change(Sender: TObject);
var t : TTabSheet;
begin
  t:=PageControl2.ActivePage;

  if (t=TabBorder) and (t.ControlCount=0) then
     TPenDialog.InsertForm(TeeScroll.Pen,t)
  else
  if (t=TabBack) and (t.ControlCount=0) then
     TBrushDialog.AddDialog(TeeScroll.Brush,t)
  else
  if (t=TabArrows) and (t.ControlCount=0) then
     TBrushDialog.AddDialog(TeeScroll.ArrowBrush,t)
  else
  if (t=TabDisabled) and (t.ControlCount=0) then
     TBrushDialog.AddDialog(TeeScroll.DisabledArrow,t);
end;

procedure TScrollbarEditor.PageControl1Change(Sender: TObject);
begin
  if PageControl1.ActivePage=TabFormat then
     PageControl2Change(Self);
end;

procedure TScrollbarEditor.PageThumbChange(Sender: TObject);
begin
  if (PageThumb.ActivePage=TabThumbBorder) and (TabThumbBorder.ControlCount=0) then
     TPenDialog.InsertForm(TeeScroll.Thumb.Pen,TabThumbBorder)
  else
  if (PageThumb.ActivePage=TabThumbPattern) and (TabThumbPattern.ControlCount=0) then
     TBrushDialog.AddDialog(TeeScroll.Thumb.Brush,TabThumbPattern);
end;

procedure TScrollbarEditor.FormCreate(Sender: TObject);
begin
  PageControl1.ActivePage:=TabSheet3;
  PageControl2.ActivePage:=TabBorder;
  PageThumb.ActivePage:=TabThumbOptions;
end;

procedure TScrollbarEditor.CBArrowsClick(Sender: TObject);
begin
  TeeScroll.Arrows:=CBArrows.Checked;
end;

procedure TScrollbarEditor.ERoundSizeChange(Sender: TObject);
begin
  if Showing then
     TeeScroll.RoundSize:=UDRoundSize.Position;
end;

initialization
  RegisterClass(TScrollbarEditor);
end.
