unit FMXTee.Editor.Tools.Gantt;

interface

uses
  System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
  FMX.Types, FMX.Controls, FMX.Forms, FMX.Dialogs, FMXTee.Editor.Tools.Series,
  FMXTee.Procs, FMX.ListBox, FMXTee.Tools.Gantt, FMX.Edit;

type
  TGanttToolEditor = class(TSeriesToolEditor)
    Label5: TLabel;
    UDTolerance: TSpinBox;
    CBAllowDrag: TCheckBox;
    Label2: TLabel;
    CBCursorDrag: TComboBox;
    CBAllowResize: TCheckBox;
    Label3: TLabel;
    CBCursorResize: TComboBox;
    procedure FormActivate(Sender: TObject);
    procedure UDToleranceChange(Sender: TObject);
    procedure CBAllowDragChange(Sender: TObject);
    procedure CBCursorDragChange(Sender: TObject);
    procedure CBCursorResizeChange(Sender: TObject);
    procedure CBAllowResizeChange(Sender: TObject);
  private
    { Private declarations }
    Gantt : TGanttTool;
  public
    { Public declarations }
  end;

implementation

{$R *.fmx}

uses
  System.UIConsts, FMXTee.Series.Gantt, FMXTee.Editor.Stroke;

const
  TeeCursorPrefix='cr';

procedure TGanttToolEditor.CBAllowDragChange(Sender: TObject);
begin
  if Assigned(Gantt) then
    Gantt.AllowDrag:=CBAllowDrag.IsChecked;
end;

procedure TGanttToolEditor.CBAllowResizeChange(Sender: TObject);
begin
  if Assigned(Gantt) then
    Gantt.AllowResize:=CBAllowResize.IsChecked;
end;

procedure TGanttToolEditor.CBCursorDragChange(Sender: TObject);
var tmp : Integer;
begin
  if Assigned(Gantt) then
  with TGanttTool(Gantt) do
    if IdentToCursor(TeeCursorPrefix+CBCursorDrag.Selected.Text,tmp) then
      CursorDrag:=tmp;
end;

procedure TGanttToolEditor.CBCursorResizeChange(Sender: TObject);
var tmp : Integer;
begin
  if Assigned(Gantt) then
  with TGanttTool(Gantt) do
    if IdentToCursor(TeeCursorPrefix+CBCursorResize.Selected.Text,tmp) then
      CursorResize:=tmp;
end;

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

  if not Assigned(Gantt) then
  begin
    Gantt:=TGanttTool(TagObject);

    if Assigned(Gantt) then
    With Gantt do
    begin
      FillSeries(CBSeries,TGanttSeries,Series);

      UDTolerance.Value:=MinPixels;
      CBAllowDrag.IsChecked:=AllowDrag;
      CBAllowResize.IsChecked:=AllowResize;
      TeeFillCursors(CBCursorDrag,CursorDrag);
      TeeFillCursors(CBCursorResize,CursorResize);
    end;
  end;
end;

procedure TGanttToolEditor.UDToleranceChange(Sender: TObject);
begin
  if Assigned(Gantt) then
    Gantt.MinPixels:=Round(UDTolerance.Value);
end;

initialization
  RegisterSeriesEditor(TGanttToolEditor);
end.
