{********************************************}
{ TDragPointTool and Editor Dialog           }
{ Copyright (c) 2000-2020 by Steema Software }
{********************************************}
unit TeeDragPointEditor;
{$I TeeDefs.inc}

interface

uses {$IFDEF LINUX}
     //Libc,
     {$ELSE}
     Windows, Messages,
     {$ENDIF}
     SysUtils, Classes,

     Graphics, Controls, Forms, Dialogs, StdCtrls, ExtCtrls, Buttons,

     TeeToolSeriesEdit, TeEngine, TeeTools, TeCanvas, TeeDragPoint, TeeProcs;


{ DragPoint: A TeeChart Tool example.

  This tool component can be used to allow the end-user to
  drag points of any Chart Series by using the mouse.

  This unit also includes a Form that is used as the editor dialog
  for the tool. This form automatically shows at the Tools tab of the
  TeeChart editor.

  Installation / use:

  1) Add this unit to a project or to a design-time package.

  2) Then, edit a Chart1 and go to "Tools" tab and Add a DragPoint tool.

  3) Set the tool Series property to a existing series (eg: Series1 ).

  4) Fill the series with points as usually.

  5) At run-time, use the left mouse button to click and drag a
     Series point.

}

type
  { The Tool editor dialog }
  TDragPointToolEdit = class(TSeriesToolEditor)
    RGStyle: TRadioGroup;
    Label2: TLabel;
    CBCursor: TComboFlat;
    SpeedButton1: TSpeedButton;
    procedure FormShow(Sender: TObject);
    procedure RGStyleClick(Sender: TObject);
    procedure CBSeriesChange(Sender: TObject);
    procedure CBCursorChange(Sender: TObject);
    procedure SpeedButton1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

implementation

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

uses
  Chart, TeeProCo, TeePenDlg, TeeMouseCursor;

procedure TDragPointToolEdit.FormShow(Sender: TObject);
var tmpCursor : TCursor;
begin
  inherited;

  tmpCursor:=crDefault;

  CBCursor.Enabled:=False;

  if Assigned(Tool) then
  begin
    Case TDragPointTool(Tool).DragStyle of
      dsX : RGStyle.ItemIndex:=0;
      dsY : RGStyle.ItemIndex:=1;
    else
      RGStyle.ItemIndex:=2;
    end;

    if TheSeries<>nil then
    begin
      tmpCursor:=TheSeries.Cursor;
      CBCursor.Enabled:=True;
    end;
  end;

  TeeFillCursors(CBCursor,tmpCursor);
end;

procedure TDragPointToolEdit.RGStyleClick(Sender: TObject);
begin
  With TDragPointTool(Tool) do
  Case RGStyle.ItemIndex of
    0: DragStyle:=dsX;
    1: DragStyle:=dsY;
  else
     DragStyle:=dsBoth;
  end;
end;

{ register both the tool and the tool editor dialog form }
procedure TDragPointToolEdit.CBSeriesChange(Sender: TObject);
begin
  inherited;
  CBCursor.Enabled:=TheSeries<>nil;
end;

procedure TDragPointToolEdit.CBCursorChange(Sender: TObject);
begin
  if Assigned(Tool) and (TheSeries<>nil) then
  with TheSeries do
       Cursor:=TeeSetCursor(Cursor,CBCursor.CurrentItem);
end;

procedure TDragPointToolEdit.SpeedButton1Click(Sender: TObject);
begin
  with TheSeries do
       Cursor:=TMouseCursorEdit.Choose(TheSeries,Cursor);
end;

initialization
  RegisterClass(TDragPointToolEdit);
end.
