unit U_IncOn;

interface

uses
  Windows, U_LNG, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, cxLookAndFeelPainters, cxControls, cxContainer,
  cxEdit, cxTextEdit, cxButtons, cxMaskEdit, siComp, siLngLnk, cxGraphics,
  cxLookAndFeels, Menus;

type
  TF_IncOn = class(TForm)
    Label1: TLabel;
    bOK: TcxButton;
    bCancel: TcxButton;
    edIncOn: TcxMaskEdit;
    lng_Forms: TsiLangLinked;
    procedure bOKClick(Sender: TObject);
    procedure bCancelClick(Sender: TObject);
    procedure edIncOnKeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
    procedure FormKeyPress(Sender: TObject; var Key: Char);
    procedure edIncOnExit(Sender: TObject);
  private
    { Private declarations }
  public
    CurrentScale: string;
    { Public declarations }
  end;

var
  F_IncOn: TF_IncOn;

implementation
uses USCS_main, U_CAD, U_Common, U_BaseCommon;
{$R *.dfm}

procedure TF_IncOn.bOKClick(Sender: TObject);
var
  Zoom: Integer;
begin
  try
    Zoom := StrToInt(edIncOn.Text);
    if Zoom < 50 then
      Zoom := 50;
    GCadForm.SetZoomScale(Zoom);
    RefreshCAD(GCadForm.PCad);
  except
    on E: Exception do AddExceptionToLogEx('TF_IncOn.bOKClick', E.Message);
  end;
end;

procedure TF_IncOn.bCancelClick(Sender: TObject);
begin
  try
    Close;
  except
    on E: Exception do AddExceptionToLogEx('TF_IncOn.bCancelClick', E.Message);
  end;
end;

procedure TF_IncOn.edIncOnKeyPress(Sender: TObject; var Key: Char);
begin
  try
//    if (Key = '.') or (Key = ',') then
//      if Key <> DecimalSeparator then
//        Key := #0;

    if Key = #13 then
    begin
      bOK.SetFocus;
      bOK.Click;
    end;
  except
    on E: Exception do AddExceptionToLogEx('TF_IncOn.edIncOnKeyPress', E.Message);
  end;
end;


procedure TF_IncOn.FormShow(Sender: TObject);
begin
  try
    // EditMask
    edIncOn.Properties.EditMask := '\d?\d?\d?'; 
    edIncOn.Text := IntToStr(GCadForm.PCad.ZoomScale);
    CurrentScale := edIncOn.Text;
    edIncOn.SetFocus;
    edIncOn.SelStart := 0;
    edIncOn.SelLength := Length(edIncOn.Text) + 1;
  except
    on E: Exception do AddExceptionToLogEx('TF_IncOn.FormShow', E.Message);
  end;
end;

procedure TF_IncOn.FormKeyPress(Sender: TObject; var Key: Char);
begin
  try
    if Key = #27 then
      Close;
  except
    on E: Exception do AddExceptionToLogEx('TF_IncOn.FormKeyPress', E.Message);
  end;
end;

procedure TF_IncOn.edIncOnExit(Sender: TObject);
begin
  try
    if edIncOn.Text = '' then
      edIncOn.Text := CurrentScale;
  except
    on E: Exception do AddExceptionToLogEx('TF_IncOn.edIncOnExit', E.Message);
  end;
end;

end.
