| 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 | var
|
|---|
| 28 | InputDlg: TInputDlg;
|
|---|
| 29 |
|
|---|
| 30 |
|
|---|
| 31 | implementation
|
|---|
| 32 |
|
|---|
| 33 | {$R *.lfm}
|
|---|
| 34 |
|
|---|
| 35 | procedure TInputDlg.FormCreate(Sender: TObject);
|
|---|
| 36 | begin
|
|---|
| 37 | Canvas.Font.Assign(UniFont[ftNormal]);
|
|---|
| 38 | Canvas.Brush.Style := TBrushStyle.bsClear;
|
|---|
| 39 | TitleHeight := Height;
|
|---|
| 40 | InitButtons;
|
|---|
| 41 | Center := True;
|
|---|
| 42 | end;
|
|---|
| 43 |
|
|---|
| 44 | procedure TInputDlg.FormPaint(Sender: TObject);
|
|---|
| 45 | begin
|
|---|
| 46 | PaintBackground(Canvas, 3, 3, Width - 6, Height - 6, Width, Height);
|
|---|
| 47 | Frame(Canvas, 0, 0, Width - 1, Height - 1, 0, 0);
|
|---|
| 48 | Frame(Canvas, 1, 1, Width - 2, Height - 2,
|
|---|
| 49 | MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
|
|---|
| 50 | Frame(Canvas, 2, 2, Width - 3, Height - 3,
|
|---|
| 51 | MainTexture.ColorBevelLight, MainTexture.ColorBevelShade);
|
|---|
| 52 | EditFrame(Canvas, EditInput.BoundsRect, MainTexture);
|
|---|
| 53 | BtnFrame(Canvas, ButtonOk.BoundsRect, MainTexture);
|
|---|
| 54 | RisedTextOut(Canvas, (Width - BiColorTextWidth(Canvas, Caption)) div 2,
|
|---|
| 55 | 9, Caption);
|
|---|
| 56 | { Corner(canvas, 1, 1, 0, MainTexture);
|
|---|
| 57 | Corner(Canvas, Width - 9, 1, 1, MainTexture);
|
|---|
| 58 | Corner(Canvas, 1, Height - 9, 2, MainTexture);
|
|---|
| 59 | Corner(Canvas, Width - 9, Height - 9, 3, MainTexture); }
|
|---|
| 60 | end;
|
|---|
| 61 |
|
|---|
| 62 | procedure TInputDlg.ButtonOkClick(Sender: TObject);
|
|---|
| 63 | begin
|
|---|
| 64 | if EditInput.Text = '' then
|
|---|
| 65 | ModalResult := mrCancel
|
|---|
| 66 | else
|
|---|
| 67 | ModalResult := mrOK;
|
|---|
| 68 | end;
|
|---|
| 69 |
|
|---|
| 70 | procedure TInputDlg.EInputKeyPress(Sender: TObject; var Key: Char);
|
|---|
| 71 | begin
|
|---|
| 72 | if (Key = #13) and (EditInput.Text <> '') then
|
|---|
| 73 | begin
|
|---|
| 74 | Key := #0;
|
|---|
| 75 | ModalResult := mrOK;
|
|---|
| 76 | end
|
|---|
| 77 | else if Key = #27 then
|
|---|
| 78 | begin
|
|---|
| 79 | Key := #0;
|
|---|
| 80 | ModalResult := mrCancel;
|
|---|
| 81 | end;
|
|---|
| 82 | end;
|
|---|
| 83 |
|
|---|
| 84 | procedure TInputDlg.FormShow(Sender: TObject);
|
|---|
| 85 | begin
|
|---|
| 86 | ButtonOk.Caption := Phrases.Lookup('BTN_OK');
|
|---|
| 87 | EditInput.Font.Color := MainTexture.ColorMark;
|
|---|
| 88 | EditInput.SelStart := 0;
|
|---|
| 89 | EditInput.SelLength := Length(EditInput.Text);
|
|---|
| 90 | if Center then
|
|---|
| 91 | CenterToRect(Rect(0, 0, Screen.Width, Screen.Height));
|
|---|
| 92 | Gtk2DisableControlStyling(EditInput);
|
|---|
| 93 | end;
|
|---|
| 94 |
|
|---|
| 95 | procedure TInputDlg.FormClose(Sender: TObject; var Action: TCloseAction);
|
|---|
| 96 | begin
|
|---|
| 97 | Center := True;
|
|---|
| 98 | end;
|
|---|
| 99 |
|
|---|
| 100 | procedure TInputDlg.CenterToRect(Rect: TRect);
|
|---|
| 101 | begin
|
|---|
| 102 | Center := False;
|
|---|
| 103 | Left := Rect.Left + (Rect.Right - Rect.Left - Width) div 2;
|
|---|
| 104 | Top := Rect.Top + (Rect.Bottom - Rect.Top - Height) div 2;
|
|---|
| 105 | end;
|
|---|
| 106 |
|
|---|
| 107 | end.
|
|---|