{**************************************************}
{   TCustomLegendTool Component and Editor Dialog  }
{   Copyright (c) 2003-2020 by Steema Software     }
{**************************************************}
unit TeeCustomLegendToolEditor;
{$I TeeDefs.inc}

interface

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

  Controls, Graphics, StdCtrls, ComCtrls, ExtCtrls, Forms, Menus, Buttons, Grids, ImgList,

  {$IFDEF D6}
  Types,
  {$ENDIF}

  TeeAnnToolEdit, TeCanvas, TeeProcs, TeEngine, Chart, TeeTools, TeePenDlg,
  TeeCustomLegendTool;

type
  TCustomLegendToolEditor = class(TAnnotationToolEdit)
    CBDrag1: TCheckBox;
    CBResize1: TCheckBox;
    TabGrid: TTabSheet;
    Label18: TLabel;
    Label19: TLabel;
    Label24: TLabel;
    EColCount: TEdit;
    UDColCount: TUpDown;
    Label17: TLabel;
    Label20: TLabel;
    Label21: TLabel;
    ERowCount: TEdit;
    UDRowCount: TUpDown;
    EFixedCols: TEdit;
    UDFixedCols: TUpDown;
    EFixedRows: TEdit;
    UDFixedRows: TUpDown;
    Label22: TLabel;
    Label23: TLabel;
    EGridWidth: TEdit;
    UDGridWidth: TUpDown;
    EGridHeight: TEdit;
    UDGridHeight: TUpDown;
    procedure FormShow(Sender: TObject);
    procedure CBDrag1Click(Sender: TObject);
    procedure CBResize1Click(Sender: TObject);
    procedure EColCountChange(Sender: TObject);
    procedure Edit1Change(Sender: TObject);
    procedure EFixedColsChange(Sender: TObject);
    procedure EFixedRowsChange(Sender: TObject);
    procedure EGridWidthChange(Sender: TObject);
    procedure EGridHeightChange(Sender: TObject);

  private
    { Private declarations }
  public
    { Public declarations }
    CustomLegend : TCustomLegendTool;
  end;

implementation

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

uses
  SysUtils, Math,
  TeeConst, TeeProCo, TeeMouseCursor;

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

  CustomLegend:=TCustomLegendTool(Tag);
  Tool := CustomLegend;

  if Assigned(CustomLegend) then
  with CustomLegend do
  begin
    CBDrag1.Checked:=AllowDrag;
    CBResize1.Checked:=AllowResize;
    UDColCount.Position:=Grid.ColCount;
    UDRowCount.Position:=Grid.RowCount;
    UDFixedCols.Position:=Grid.FixedCols;
    UDFixedRows.Position:=Grid.FixedRows;
    UDGridWidth.Position:=Grid.Width;
    UDGridHeight.Position:=Grid.Height;
  end;

  TabGrid.TabVisible:=Assigned(CustomLegend) and
                      (not (csDesigning in CustomLegend.ComponentState));
end;

procedure TCustomLegendToolEditor.CBDrag1Click(Sender: TObject);
begin
  CustomLegend.AllowDrag:=CBDrag1.Checked;
end;

procedure TCustomLegendToolEditor.CBResize1Click(Sender: TObject);
begin
  CustomLegend.AllowResize:=CBResize1.Checked;
end;

procedure TCustomLegendToolEditor.EColCountChange(Sender: TObject);
begin
  CustomLegend.Grid.ColCount := UDColCount.Position;
  CustomLegend.Repaint;
end;

procedure TCustomLegendToolEditor.Edit1Change(Sender: TObject);
begin
  CustomLegend.Grid.RowCount := UDRowCount.Position;
  CustomLegend.Repaint;
end;

procedure TCustomLegendToolEditor.EFixedColsChange(Sender: TObject);
begin
  CustomLegend.Grid.FixedCols := UDFixedCols.Position;
  CustomLegend.Repaint;
end;

procedure TCustomLegendToolEditor.EFixedRowsChange(Sender: TObject);
begin
  CustomLegend.Grid.FixedRows := UDFixedRows.Position;
  CustomLegend.Repaint;
end;

procedure TCustomLegendToolEditor.EGridWidthChange(Sender: TObject);
begin
  CustomLegend.Grid.Width:=UDGridWidth.Position;
  CustomLegend.Repaint;
end;

procedure TCustomLegendToolEditor.EGridHeightChange(Sender: TObject);
begin
  CustomLegend.Grid.Height:=UDGridHeight.Position;
  CustomLegend.Repaint;
end;

initialization
  RegisterClass(TCustomLegendToolEditor);
end.
