unit FMXTee.Editor.Tools.Series;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMX.ListBox,
  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;
    Procedure FillSeries(const ACombo:TComboBox;
                         AClass:TChartSeriesClass;
                         ASeries:TChartSeries;
                         ClearCombo:Boolean=True);
    procedure FillSeriesCombo(ACombo:TComboBox; ASeries:TChartSeries; AChart:TCustomAxisPanel);
  public
    { Public declarations }

    class procedure FillMarksStyle(const AItems: TStrings);
  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;
                                       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(ACombo:TComboBox; ASeries:TChartSeries; 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.
