{$INCLUDE Switches.inc}
unit Inp;

interface

uses
  ScreenTools, LCLIntf, LCLType, SysUtils, Classes, DrawDlg, ButtonA,
  {$IFDEF DPI}Dpi.Graphics, Dpi.Controls, Dpi.Forms, Dpi.StdCtrls, System.UITypes{$ELSE}
  Graphics, Controls, Forms, StdCtrls{$ENDIF};

type
  TInputDlg = class(TDrawDlg)
    ButtonOk: TButtonA;
    EditInput: TEdit;
    procedure ButtonOkClick(Sender: TObject);
    procedure FormPaint(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure EInputKeyPress(Sender: TObject; var Key: Char);
    procedure FormShow(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  public
    procedure CenterToRect(Rect: TRect);
  private
    Center: Boolean;
  end;


implementation

{$R *.lfm}

procedure TInputDlg.FormCreate(Sender: TObject);
begin
  Canvas.Font.Assign(UniFont[ftNormal]);
  Canvas.Brush.Style := TBrushStyle.bsClear;
  TitleHeight := Height;
  InitButtons;
  Center := True;
end;

procedure TInputDlg.FormPaint(Sender: TObject);
begin
  PaintBackground(Canvas, 3, 3, Width - 6, Height - 6, Width, Height);
  Frame(Canvas, 0, 0, Width - 1, Height - 1, 0, 0);
  Frame(Canvas, 1, 1, Width - 2, Height - 2,
    MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
  Frame(Canvas, 2, 2, Width - 3, Height - 3,
    MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
  EditFrame(Canvas, EditInput.BoundsRect, MainTexture);
  BtnFrame(Canvas, ButtonOk.BoundsRect, MainTexture);
  RisedTextOut(Canvas, (Width - BiColorTextWidth(Canvas, Caption)) div 2,
    9, Caption);
  { Corner(canvas, 1, 1, 0, MainTexture);
    Corner(Canvas, Width - 9, 1, 1, MainTexture);
    Corner(Canvas, 1, Height - 9, 2, MainTexture);
    Corner(Canvas, Width - 9, Height - 9, 3, MainTexture); }
end;

procedure TInputDlg.ButtonOkClick(Sender: TObject);
begin
  if EditInput.Text = '' then
    ModalResult := mrCancel
  else
    ModalResult := mrOK;
end;

procedure TInputDlg.EInputKeyPress(Sender: TObject; var Key: Char);
begin
  if (Key = #13) and (EditInput.Text <> '') then
  begin
    Key := #0;
    ModalResult := mrOK;
  end
  else if Key = #27 then
  begin
    Key := #0;
    ModalResult := mrCancel;
  end;
end;

procedure TInputDlg.FormShow(Sender: TObject);
begin
  ButtonOk.Caption := Phrases.Lookup('BTN_OK');
  EditInput.Font.Color := MainTexture.ColorMark;
  EditInput.SelStart := 0;
  EditInput.SelLength := Length(EditInput.Text);
  if Center then
    CenterToRect(Screen.PrimaryMonitor.BoundsRect);
  Gtk2DisableControlStyling(EditInput);
end;

procedure TInputDlg.FormClose(Sender: TObject; var Action: TCloseAction);
begin
  Center := True;
end;

procedure TInputDlg.CenterToRect(Rect: TRect);
begin
  Center := False;
  Left := Rect.Left + (Rect.Right - Rect.Left - Width) div 2;
  Top := Rect.Top + (Rect.Bottom - Rect.Top - Height) div 2;
end;

end.
