{**********************************************}
{   TeeChart PageNum Tool                      }
{   Copyright (c) 2000-2020 by Steema Software }
{**********************************************}
unit TeePageNumToolEditor;
{$I TeeDefs.inc}

// This unit implements a Chart Tool example:

{
   TPageNumTool

      This tool derives from Annotation tool.
      It is used to display the current chart page number.

      The Chart.Pages.MaxPointsPerPage property should be bigger than zero,
      to divide a chart in pages.

      Can be useful both for screen and print / print preview.

      This tool is automatically used by the Chart Editor dialog at
      "Paging" tab, when this unit is used in your application.
}

interface

Uses {$IFNDEF LINUX}
     Windows,
     {$ENDIF}
     Classes,

     Graphics, Controls, StdCtrls, ComCtrls, ExtCtrls, Buttons,

     TeCanvas, TeEngine, Chart, TeeTools, TeeAnnToolEdit, TeePenDlg;

type
  TPageNumToolEdit=class(TAnnotationToolEdit)
    TagPaging: TTabSheet;
    PageControl4: TPageControl;
    Panel1: TPanel;
    CBButtons: TCheckBox;
    Label20: TLabel;
    EWidth: TEdit;
    UDButtonWidth: TUpDown;
    TabEnabled: TTabSheet;
    TabDisabled: TTabSheet;
    TabButtonPen: TTabSheet;
    procedure EWidthChange(Sender: TObject);
    procedure CBButtonsClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
    procedure PageControl4Change(Sender: TObject);
  public
  end;

implementation

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

uses
  SysUtils, Math, TeePageNumTool, TeeBrushDlg;

procedure TPageNumToolEdit.EWidthChange(Sender: TObject);
begin
  if Showing and Assigned(Tool) then
     TPageNumTool(Tool).ButtonWidth:=UDButtonWidth.Position;
end;

procedure TPageNumToolEdit.CBButtonsClick(Sender: TObject);
begin
  TPageNumTool(Tool).ShowButtons:=CBButtons.Checked;
end;

procedure TPageNumToolEdit.FormShow(Sender: TObject);
begin
  inherited;

  if Assigned(Tool) then
  with TPageNumTool(Tool) do
  begin
    CBButtons.Checked:=ShowButtons;
    UDButtonWidth.Position:=ButtonWidth;

    PageControl4Change(Self);
  end;

  Timer1.Enabled:=True;
end;

procedure TPageNumToolEdit.Timer1Timer(Sender: TObject);
begin
  Timer1.Enabled:=False;
  PageControl1.ActivePage:=TagPaging;
  PageControl1Change(Self);
end;

procedure TPageNumToolEdit.PageControl4Change(Sender: TObject);
begin
  inherited;

  if (PageControl4.ActivePage=TabEnabled) and (TabEnabled.ControlCount=0) then
     TBrushDialog.AddDialog(TPageNumTool(Tool).EnabledBrush,TabEnabled)
  else
  if (PageControl4.ActivePage=TabDisabled) and (TabDisabled.ControlCount=0) then
     TBrushDialog.AddDialog(TPageNumTool(Tool).DisabledBrush,TabDisabled)
  else
  if (PageControl4.ActivePage=TabButtonPen) and (TabButtonPen.ControlCount=0) then
     TPenDialog.InsertForm(TPageNumTool(Tool).ButtonPen,TabButtonPen);
end;

initialization
  RegisterClass(TPageNumToolEdit);
end.
