unit UCustom67;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Spin, ExtCtrls;

type
  TFCustom = class(TForm)
    BOK: TButton;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    EIdent1: TEdit;
    Label4: TLabel;
    EIdentLeft: TEdit;
    Label5: TLabel;
    EIdentRight: TEdit;
    GroupBox2: TGroupBox;
    ETab: TEdit;
    LBTab: TListBox;
    BTab: TButton;
    RGAlign: TRadioGroup;
    procedure FormShow(Sender: TObject);
    procedure BOKClick(Sender: TObject);
    procedure EIdent1KeyPress(Sender: TObject; var Key: Char);
    procedure LBTabClick(Sender: TObject);
    procedure BTabClick(Sender: TObject);
    procedure ETabKeyUp(Sender: TObject; var Key: Word;
      Shift: TShiftState);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  FCustom: TFCustom;

implementation

uses UEditor67;

{$R *.dfm}

var PixelToPoint, PointToPixel:real;

procedure TFCustom.FormShow(Sender: TObject);
var i: integer;
begin
 PixelToPoint := 72 / Form1.RichEdit1.Font.PixelsPerInch;
 PointToPixel := 1 / PixelToPoint;
 with Form1.RichEdit1.Paragraph do begin
  EIdent1.Text := IntToStr(Round(FirstIndent * PixelToPoint));
  EIdentLeft.Text := IntToStr(Round((FirstIndent + LeftIndent) * PixelToPoint));
  EIdentRight.Text := IntToStr(Round(RightIndent * PixelToPoint));
  LBTab.Clear;
  if TabCount = 0 then TabCount := 1;
  for i:=0 to TabCount - 1 do
   LBTab.Items.Add(IntToStr(Tab[i]));
  LBTab.ItemIndex := 0;
  ETab.Text := LBTab.Items.Strings[0];
  case Alignment of
   taLeftJustify:  RGAlign.ItemIndex := 0;
   taCenter:       RGAlign.ItemIndex := 1;
   taRightJustify: RGAlign.ItemIndex := 2;
  end;
 end;
end;

procedure TFCustom.BOKClick(Sender: TObject);
var i: integer;
begin
 try
  with Form1.RichEdit1.Paragraph do begin
   FirstIndent :=
      Round(StrToInt(EIdent1.Text) * PointToPixel);
   LeftIndent :=
      Round(StrToInt(EIdentLeft.Text) * PointToPixel) - FirstIndent;
   RightIndent :=
      Round(StrToInt(EIdentRight.Text) * PointToPixel);
   TabCount := LBTab.Count;
   for i:=0 to LBTab.Count - 1 do
    Tab[i] := StrToInt(LBTab.Items.Strings[i]);
   case RGAlign.ItemIndex of
    0: Alignment := taLeftJustify;
    1: Alignment := taCenter;
    2: Alignment := taRightJustify;
   end;
   Close;
  end;
 except
    on E: EConvertError do
      Application.MessageBox(PChar(Copy(E.Message,0,Pos('is',E.Message) - 1) +
                       'недопустимое значение'),
                       'Измените данные', MB_ICONSTOP)
 end;
end;

procedure TFCustom.EIdent1KeyPress(Sender: TObject; var Key: Char);
begin
 if not (Key in ['0'..'9', '-', #8]) then Key := #0;
end;

procedure TFCustom.LBTabClick(Sender: TObject);
begin
  ETab.Text := LBTab.Items.Strings[LBTab.ItemIndex];
end;

procedure TFCustom.BTabClick(Sender: TObject);
begin
 LBTab.Items.Add(LBTab.Items[LBTab.Count-1]);
end;

procedure TFCustom.ETabKeyUp(Sender: TObject; var Key: Word;
  Shift: TShiftState);
begin
 LBTab.Items.Strings[LBTab.ItemIndex] := ETab.Text;
end;

end.
