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

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Rtti, System.Classes,
  System.Variants, FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs,
  {$IFNDEF UPTOXE3}
  FMX.StdCtrls,
  {$ENDIF}
  {$IFDEF D21}
  FMX.SpinBox,
  {$ENDIF}
  FMXTee.Tools, FMXTee.Editor.TextShape,
  FMXTee.Editor.Tools.Series, FMX.ListBox, FMX.Edit, FMX.TabControl;

type
  TMarksTipToolEdit = class(TSeriesToolEditor)
    TabMarksTip: TTabControl;
    TabOptions: TTabItem;
    TabFormat: TTabItem;
    Label2: TLabel;
    CBStyle: TComboBox;
    Label3: TLabel;
    CBMouse: TComboBox;
    SBDelay: TSpinBox;
    Label4: TLabel;
    Label5: TLabel;
    SBHide: TSpinBox;
    LIMouseMove: TListBoxItem;
    LIMouseClick: TListBoxItem;
    procedure TabMarksTipChange(Sender: TObject);
    procedure SBHideChangeTracking(Sender: TObject);
    procedure SBDelayChangeTracking(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure CBMouseChange(Sender: TObject);
    procedure CBStyleChange(Sender: TObject);
    procedure FormActivate(Sender: TObject);
  private
    { Private declarations }

    IShapeEditor : TTextShapeEditor;
    MarksTool : TMarksTipTool;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  FMXTee.Procs, FMXTee.Constants, FMXTee.Engine;

procedure TMarksTipToolEdit.CBMouseChange(Sender: TObject);
begin
  if Assigned(MarksTool) then
     MarksTool.MouseAction:=TMarkToolMouseAction(CBMouse.ItemIndex);
end;

procedure TMarksTipToolEdit.CBStyleChange(Sender: TObject);
begin
  if Assigned(MarksTool) then
     MarksTool.Style:=TSeriesMarksStyle(CBStyle.ItemIndex);
end;

procedure TMarksTipToolEdit.FormActivate(Sender: TObject);
begin
  inherited;

  if Assigned(Tool) then
  begin
    MarksTool:=TMarksTipTool(Tool);

    { change "none" with "all" }
    CBSeries.Items[0]:=TeeMsg_All;
    CBSeries.ItemIndex:=CBSeries.Items.IndexOfObject(Tool.Series);

    { setup dialog }
    with MarksTool do
    begin
      CBMouse.ItemIndex:=Ord(MouseAction);
      CBStyle.ItemIndex:=Ord(Style);
      SBDelay.Value:=MouseDelay;
      SBHide.Value:=HideDelay;
    end;
  end;
end;

procedure TMarksTipToolEdit.FormCreate(Sender: TObject);
begin
  inherited;
  TSeriesToolEditor.FillMarksStyle(CBStyle.Items);
end;

procedure TMarksTipToolEdit.SBDelayChangeTracking(Sender: TObject);
begin
  if Assigned(MarksTool) then
     MarksTool.MouseDelay:=Round(SBDelay.Value);
end;

procedure TMarksTipToolEdit.SBHideChangeTracking(Sender: TObject);
begin
  if Assigned(MarksTool) then
     MarksTool.HideDelay:=Round(SBHide.Value);
end;

procedure TMarksTipToolEdit.TabMarksTipChange(Sender: TObject);
begin
  if (TabMarksTip.ActiveTab=TabFormat) and (not Assigned(IShapeEditor)) then
  begin
    IShapeEditor:=TTextShapeEditor.InsertForm(MarksTool.Format,TabFormat);
    IShapeEditor.TabText.Visible:=False;

    IShapeEditor.TabControl1.ActiveTab:=TabOptions;
  end;
end;

initialization
  RegisterSeriesEditor(TMarksTipToolEdit);
end.
