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

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.ListBox,
  {$IFNDEF UPTOXE3}
  FMX.StdCtrls,
  {$ENDIF}
  FMXTee.Procs, FMXTee.Engine, FMXTee.Canvas;

type
  TSeriesToolEditor = class(TForm)
    Panel1: TPanel;
    Label1: TLabel;
    CBSeries: TComboBox;
    procedure CBSeriesChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }

  protected
    Tool : TTeeCustomToolSeries;

    class procedure FillMarksStyle(const AItems: TStrings);

    Procedure FillSeries(const ACombo:TComboBox;
                         AClass:TChartSeriesClass;
                         const ASeries:TChartSeries;
                         ClearCombo:Boolean=True);
    procedure FillSeriesCombo(const ACombo:TComboBox; const ASeries:TChartSeries;
                         const AChart:TCustomAxisPanel);
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

Uses
  FMXTee.Constants, FMXTee.ProConstants, FMXTee.Editor.Series;

procedure TSeriesToolEditor.CBSeriesChange(Sender: TObject);
begin
  if CBSeries.ItemIndex<>-1 then
     Tool.Series:=TChartSeries(CBSeries.Items.Objects[CBSeries.ItemIndex]);
end;

class procedure TSeriesToolEditor.FillMarksStyle(const AItems: TStrings);
var tmp : TSeriesEditor;
begin
  tmp:=TSeriesEditor.Create(nil);
  try
    // Translate form before assigning RGMarkStyle
    TeeTranslateControl(tmp);

    AItems.Assign(tmp.RGMarkStyle.Items);
  finally
    tmp.Free;
  end;
end;

Procedure TSeriesToolEditor.FillSeries(const ACombo:TComboBox;
                                       AClass:TChartSeriesClass;
                                       const ASeries:TChartSeries;
                                       ClearCombo:Boolean=True);
var t : Integer;
begin
  if ClearCombo then
     ACombo.Clear;

  if Assigned(Tool.ParentChart) then
  With Tool.ParentChart do
  for t:=0 to SeriesCount-1 do
  if Series[t] is AClass then
      ACombo.Items.AddObject(SeriesTitleOrName(Series[t]),Series[t]);

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

procedure TSeriesToolEditor.FillSeriesCombo(const ACombo:TComboBox; const ASeries:TChartSeries;
           const AChart:TCustomAxisPanel);
var i : TListBoxItem;
begin
  with ACombo do
  begin
    if Assigned(AChart) then
    begin
      FillSeriesItems(Items,AChart.SeriesList);
      Enabled:=AChart.SeriesCount>0;
    end;

    i:=TListBoxItem.Create(ACombo.Owner);
    i.Text:=TeeMsg_None;
    i.Parent:=ACombo;
    i.Index:=0;

    ItemIndex:=Items.IndexOfObject(ASeries);
  end;
end;

procedure TSeriesToolEditor.FormActivate(Sender: TObject);
begin
  if not Assigned(Tool) then
  begin
    Tool:=TTeeCustomToolSeries(TagObject);

    if Assigned(Tool) then
       FillSeriesCombo(CBSeries,Tool.Series,Tool.ParentChart)
  end;
end;

initialization
  RegisterSeriesEditor(TSeriesToolEditor);
end.
