File: Inp.pas

package info (click to toggle)
c-evo-dh 3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,540 kB
  • sloc: pascal: 57,645; xml: 243; makefile: 114; sh: 4
file content (105 lines) | stat: -rw-r--r-- 2,724 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
{$INCLUDE Switches.inc}
unit Inp;

interface

uses
  ScreenTools, LCLIntf, LCLType, SysUtils, Classes, Graphics, Controls, Forms,
  DrawDlg, ButtonA, StdCtrls;

type
  TInputDlg = class(TDrawDlg)
    OKBtn: TButtonA;
    EInput: TEdit;
    procedure OKBtnClick(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;

var
  InputDlg: TInputDlg;


implementation

{$R *.lfm}

procedure TInputDlg.FormCreate(Sender: TObject);
begin
  Canvas.Font.Assign(UniFont[ftNormal]);
  Canvas.Brush.Style := bsClear;
  TitleHeight := Height;
  InitButtons;
  Center := True;
end;

procedure TInputDlg.FormPaint(Sender: TObject);
begin
  PaintBackground(self, 3, 3, ClientWidth - 6, ClientHeight - 6);
  Frame(Canvas, 0, 0, ClientWidth - 1, ClientHeight - 1, 0, 0);
  Frame(Canvas, 1, 1, ClientWidth - 2, ClientHeight - 2,
    MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
  Frame(Canvas, 2, 2, ClientWidth - 3, ClientHeight - 3,
    MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
  EditFrame(Canvas, EInput.BoundsRect, MainTexture);
  BtnFrame(Canvas, OKBtn.BoundsRect, MainTexture);
  RisedTextOut(Canvas, (ClientWidth - BiColorTextWidth(Canvas, Caption)) div 2,
    9, Caption);
  { Corner(canvas,1,1,0,MainTexture);
    Corner(canvas,ClientWidth-9,1,1,MainTexture);
    Corner(canvas,1,ClientHeight-9,2,MainTexture);
    Corner(canvas,ClientWidth-9,ClientHeight-9,3,MainTexture); }
end;

procedure TInputDlg.OKBtnClick(Sender: TObject);
begin
  if EInput.Text = '' then
    ModalResult := mrCancel
  else
    ModalResult := mrOK;
end;

procedure TInputDlg.EInputKeyPress(Sender: TObject; var Key: Char);
begin
  if (Key = #13) and (EInput.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
  OKBtn.Caption := Phrases.Lookup('BTN_OK');
  EInput.Font.Color := MainTexture.ColorMark;
  EInput.SelStart := 0;
  EInput.SelLength := Length(EInput.Text);
  if Center then
    CenterToRect(Rect(0, 0, Screen.Width, Screen.Height));
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.