| 1 | {$INCLUDE Switches.inc}
|
|---|
| 2 | unit Inp;
|
|---|
| 3 |
|
|---|
| 4 | interface
|
|---|
| 5 |
|
|---|
| 6 | uses
|
|---|
| 7 | ScreenTools, LCLIntf, LCLType, SysUtils, Classes, DrawDlg, ButtonA,
|
|---|
| 8 | {$IFDEF DPI}Dpi.Graphics, Dpi.Controls, Dpi.Forms, Dpi.StdCtrls, System.UITypes{$ELSE}
|
|---|
| 9 | Graphics, Controls, Forms, StdCtrls{$ENDIF};
|
|---|
| 10 |
|
|---|
| 11 | type
|
|---|
| 12 | TInputDlg = class(TDrawDlg)
|
|---|
| 13 | ButtonOk: TButtonA;
|
|---|
| 14 | EditInput: TEdit;
|
|---|
| 15 | procedure ButtonOkClick(Sender: TObject);
|
|---|
| 16 | procedure FormPaint(Sender: TObject);
|
|---|
| 17 | procedure FormCreate(Sender: TObject);
|
|---|
| 18 | procedure EInputKeyPress(Sender: TObject; var Key: Char);
|
|---|
| 19 | procedure FormShow(Sender: TObject);
|
|---|
| 20 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
|---|
| 21 | public
|
|---|
| 22 | procedure CenterToRect(Rect: TRect);
|
|---|
| 23 | private
|
|---|
| 24 | Center: Boolean;
|
|---|
| 25 | end;
|
|---|
| 26 |
|
|---|
| 27 |
|
|---|
| 28 | implementation
|
|---|
| 29 |
|
|---|
| 30 | {$R *.lfm}
|
|---|
| 31 |
|
|---|
| 32 | procedure TInputDlg.FormCreate(Sender: TObject);
|
|---|
| 33 | begin
|
|---|
| 34 | Canvas.Font.Assign(UniFont[ftNormal]);
|
|---|
| 35 | Canvas.Brush.Style := TBrushStyle.bsClear;
|
|---|
| 36 | TitleHeight := Height;
|
|---|
| 37 | InitButtons;
|
|---|
| 38 | Center := True;
|
|---|
| 39 | end;
|
|---|
| 40 |
|
|---|
| 41 | procedure TInputDlg.FormPaint(Sender: TObject);
|
|---|
| 42 | begin
|
|---|
| 43 | PaintBackground(Canvas, 3, 3, Width - 6, Height - 6, Width, Height);
|
|---|
| 44 | Frame(Canvas, 0, 0, Width - 1, Height - 1, 0, 0);
|
|---|
| 45 | Frame(Canvas, 1, 1, Width - 2, Height - 2,
|
|---|
| 46 | MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
|
|---|
| 47 | Frame(Canvas, 2, 2, Width - 3, Height - 3,
|
|---|
| 48 | MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
|
|---|
| 49 | EditFrame(Canvas, EditInput.BoundsRect, MainTexture);
|
|---|
| 50 | BtnFrame(Canvas, ButtonOk.BoundsRect, MainTexture);
|
|---|
| 51 | RisedTextOut(Canvas, (Width - BiColorTextWidth(Canvas, Caption)) div 2,
|
|---|
| 52 | 9, Caption);
|
|---|
| 53 | { Corner(canvas, 1, 1, 0, MainTexture);
|
|---|
| 54 | Corner(Canvas, Width - 9, 1, 1, MainTexture);
|
|---|
| 55 | Corner(Canvas, 1, Height - 9, 2, MainTexture);
|
|---|
| 56 | Corner(Canvas, Width - 9, Height - 9, 3, MainTexture); }
|
|---|
| 57 | end;
|
|---|
| 58 |
|
|---|
| 59 | procedure TInputDlg.ButtonOkClick(Sender: TObject);
|
|---|
| 60 | begin
|
|---|
| 61 | if EditInput.Text = '' then
|
|---|
| 62 | ModalResult := mrCancel
|
|---|
| 63 | else
|
|---|
| 64 | ModalResult := mrOK;
|
|---|
| 65 | end;
|
|---|
| 66 |
|
|---|
| 67 | procedure TInputDlg.EInputKeyPress(Sender: TObject; var Key: Char);
|
|---|
| 68 | begin
|
|---|
| 69 | if (Key = #13) and (EditInput.Text <> '') then
|
|---|
| 70 | begin
|
|---|
| 71 | Key := #0;
|
|---|
| 72 | ModalResult := mrOK;
|
|---|
| 73 | end
|
|---|
| 74 | else if Key = #27 then
|
|---|
| 75 | begin
|
|---|
| 76 | Key := #0;
|
|---|
| 77 | ModalResult := mrCancel;
|
|---|
| 78 | end;
|
|---|
| 79 | end;
|
|---|
| 80 |
|
|---|
| 81 | procedure TInputDlg.FormShow(Sender: TObject);
|
|---|
| 82 | begin
|
|---|
| 83 | ButtonOk.Caption := Phrases.Lookup('BTN_OK');
|
|---|
| 84 | EditInput.Font.Color := MainTexture.ColorMark;
|
|---|
| 85 | EditInput.SelStart := 0;
|
|---|
| 86 | EditInput.SelLength := Length(EditInput.Text);
|
|---|
| 87 | if Center then
|
|---|
| 88 | CenterToRect(Screen.PrimaryMonitor.BoundsRect);
|
|---|
| 89 | Gtk2DisableControlStyling(EditInput);
|
|---|
| 90 | end;
|
|---|
| 91 |
|
|---|
| 92 | procedure TInputDlg.FormClose(Sender: TObject; var Action: TCloseAction);
|
|---|
| 93 | begin
|
|---|
| 94 | Center := True;
|
|---|
| 95 | end;
|
|---|
| 96 |
|
|---|
| 97 | procedure TInputDlg.CenterToRect(Rect: TRect);
|
|---|
| 98 | begin
|
|---|
| 99 | Center := False;
|
|---|
| 100 | Left := Rect.Left + (Rect.Right - Rect.Left - Width) div 2;
|
|---|
| 101 | Top := Rect.Top + (Rect.Bottom - Rect.Top - Height) div 2;
|
|---|
| 102 | end;
|
|---|
| 103 |
|
|---|
| 104 | end.
|
|---|