{**********************************************}
{   TeeChart Margins Editor                    }
{   Copyright (c) 2007-2020 by Steema Software }
{**********************************************}
unit TeeMargins;
{$I TeeDefs.inc}

interface

uses {$IFNDEF LINUX}
     Windows, Messages,
     {$ENDIF}
     SysUtils, Classes,

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

     TeCanvas, TeeProcs, TeEngine;

type
  TMarginsEditor = class(TForm)
    RGUnits: TRadioGroup;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    TBLeft: TTrackBar;
    LLeft: TLabel;
    TBTop: TTrackBar;
    LTop: TLabel;
    TBRight: TTrackBar;
    LRight: TLabel;
    TBBottom: TTrackBar;
    LBottom: TLabel;
    procedure RGUnitsClick(Sender: TObject);
    procedure FormShow(Sender: TObject);
    procedure TBLeftChange(Sender: TObject);
    procedure TBTopChange(Sender: TObject);
    procedure TBRightChange(Sender: TObject);
    procedure TBBottomChange(Sender: TObject);
  private
    { Private declarations }
    Margins : TMargins;
  public
    { Public declarations }
    procedure RefreshControls(const AMargins:TMargins);
  end;

implementation

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

procedure TMarginsEditor.RGUnitsClick(Sender: TObject);
begin
  case RGUnits.ItemIndex of
     0: Margins.Units:=maPercentFont;
     1: Margins.Units:=maPercentSize;
  else
     Margins.Units:=maPixels;
  end;
end;

procedure TMarginsEditor.FormShow(Sender: TObject);
var tmp : TMargins;
begin
  tmp:=TMargins(Tag);

  if Assigned(tmp) then
  begin
    Margins:=tmp;
    RefreshControls(Margins);
  end;

  TeeTranslateControl(Self);  
end;

procedure TMarginsEditor.RefreshControls(const AMargins:TMargins);
begin
  Margins:=AMargins;

  case Margins.Units of
    maPercentFont : RGUnits.ItemIndex:=0;
    maPercentSize : RGUnits.ItemIndex:=1;
  else
     RGUnits.ItemIndex:=2;
  end;

  RGUnitsClick(Self);

  TBLeft.Position:=Margins.Left;
  LLeft.Caption:=IntToStr(TBLeft.Position);

  TBTop.Position:=Margins.Top;
  LTop.Caption:=IntToStr(TBTop.Position);

  TBRight.Position:=Margins.Right;
  LRight.Caption:=IntToStr(TBRight.Position);

  TBBottom.Position:=Margins.Bottom;
  LBottom.Caption:=IntToStr(TBBottom.Position);
end;

procedure TMarginsEditor.TBLeftChange(Sender: TObject);
begin
  if Showing then
  begin
    Margins.Left:=TBLeft.Position;
    LLeft.Caption:=IntToStr(TBLeft.Position);
  end;
end;

procedure TMarginsEditor.TBTopChange(Sender: TObject);
begin
  if Showing then
  begin
    Margins.Top:=TBTop.Position;
    LTop.Caption:=IntToStr(TBTop.Position);
  end;
end;

procedure TMarginsEditor.TBRightChange(Sender: TObject);
begin
  if Showing then
  begin
    Margins.Right:=TBRight.Position;
    LRight.Caption:=IntToStr(TBRight.Position);
  end;
end;

procedure TMarginsEditor.TBBottomChange(Sender: TObject);
begin
  if Showing then
  begin
    Margins.Bottom:=TBBottom.Position;
    LBottom.Caption:=IntToStr(TBBottom.Position);
  end;
end;

end.
