{********************************************}
{   TeeChart Pie Series Tool                 }
{ Copyright (c) 2001-2020 by Steema Software }
{        All Rights Reserved                 }
{********************************************}
unit TeePieToolEditor;
{$I TeeDefs.inc}

interface

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

     Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, ComCtrls,

     TeeTools, TeCanvas, TeEngine, Chart, TeePenDlg, TeePieTool, TeeProcs;

type
  TPieToolEditor = class(TForm)
    PageControl1: TPageControl;
    TabOptions: TTabSheet;
    TabBorder: TTabSheet;
    Label1: TLabel;
    CBPieSeries: TComboFlat;
    RGStyle: TRadioGroup;
    procedure FormShow(Sender: TObject);
    procedure CBPieSeriesChange(Sender: TObject);
    procedure RGStyleClick(Sender: TObject);
    procedure PageControl1Change(Sender: TObject);
  private
    { Private declarations }
    Tool : TPieTool;
  public
    { Public declarations }
  end;

implementation

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

Uses
  TeeConst, TeeProCo, Series;

procedure TPieToolEditor.FormShow(Sender: TObject);

  Procedure FillPieSeries(const AItems:TStrings);
  var t : Integer;
  begin
    if Assigned(Tool.ParentChart) then
    With Tool.ParentChart do
    for t:=0 to SeriesCount-1 do
    if Series[t] is TPieSeries then
        AItems.AddObject(SeriesTitleOrName(Series[t],True),Series[t]);
  end;

begin
  Tool:=TPieTool(Tag);

  if Assigned(Tool) then
  begin
    FillPieSeries(CBPieSeries.Items);

    with CBPieSeries do
    begin
      Enabled:=Items.Count>0;
      ItemIndex:=Items.IndexOfObject(Tool.Series);
    end;

    RGStyle.ItemIndex:=Ord(Tool.Style);
  end;

  Label1.Caption:=TeeMsg_GalleryPie;
end;

procedure TPieToolEditor.CBPieSeriesChange(Sender: TObject);
begin
  Tool.Series:=TPieSeries(CBPieSeries.SelectedObject);
end;

procedure TPieToolEditor.RGStyleClick(Sender: TObject);
begin
  Tool.Style:=TPieToolStyle(RGStyle.ItemIndex);
end;

procedure TPieToolEditor.PageControl1Change(Sender: TObject);
begin
  if (PageControl1.ActivePage=TabBorder) and (TabBorder.ControlCount=0) then
     TPenDialog.InsertForm(Tool.Pen,TabBorder);
end;

initialization
  RegisterClass(TPieToolEditor);
end.
