From b80c81bf4f410eeb82d5a7bdc3c80db4e0bea9ec Mon Sep 17 00:00:00 2001 From: lazarus Date: Sat, 9 Feb 2002 01:48:16 +0000 Subject: [PATCH] MG: added inputdialog.inc git-svn-id: trunk@1325 - --- .gitattributes | 1 + lcl/include/inputdialog.inc | 103 ++++++++++++++++++++++++++++++++++++ lcl/interfacebase.pp | 18 +++++-- 3 files changed, 119 insertions(+), 3 deletions(-) create mode 100644 lcl/include/inputdialog.inc diff --git a/.gitattributes b/.gitattributes index 2ba4c32049..e9100e76ae 100644 --- a/.gitattributes +++ b/.gitattributes @@ -416,6 +416,7 @@ lcl/include/hintwindow.inc svneol=native#text/pascal lcl/include/hkeys.inc svneol=native#text/pascal lcl/include/image.inc svneol=native#text/pascal lcl/include/imglist.inc svneol=native#text/pascal +lcl/include/inputdialog.inc svneol=native#text/pascal lcl/include/interfacebase.inc svneol=native#text/pascal lcl/include/listitem.inc svneol=native#text/pascal lcl/include/listitems.inc svneol=native#text/pascal diff --git a/lcl/include/inputdialog.inc b/lcl/include/inputdialog.inc new file mode 100644 index 0000000000..8cdf1a9cc7 --- /dev/null +++ b/lcl/include/inputdialog.inc @@ -0,0 +1,103 @@ +// included by dialogs.pp +{ + ***************************************************************************** + * * + * This file is part of the Lazarus Component Library (LCL) * + * * + * See the file COPYING.LCL, included in this distribution, * + * for details about the copyright. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * * + ***************************************************************************** +} + +Function ShowInputDialog(const InputCaption, InputPrompt : String; + MaskInput : Boolean; var Value : String) : Boolean; +Const + AVGBuffer : PChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890()|_ '; +var + Form : TForm; + Prompt : TLabel; + Edit : TEdit; + ButtonTop, ButtonWidth, ButtonHeight : Integer; + Avg : TPoint; +begin + Result := False; + Form := TForm.CreateNew(nil, 0); + With Form do begin + BorderStyle := bsDialog; + Caption := InputCaption; + Prompt := TLabel.Create(Form); + With Prompt do begin + Parent := Form; + Caption := InputPrompt; + Visible := True; + end; + SelectObject(Canvas.Handle, GetStockObject(SYSTEM_FONT)); + GetTextExtentPoint(Canvas.Handle,AVGBuffer,StrLen(AVGBuffer),TSize(AVG)); + AVG.X := AVG.X div 52; + Position := poScreenCenter; + Prompt.Left := (7*AVG.X) div 4; + Prompt.Top := (8*AVG.Y) div 8; + Prompt.Width := AVG.X * Length(InputPrompt) + 1; + ClientWidth := (172*AVG.X) div 4; + ClientHeight := (58*AVG.Y) div 8; + ButtonTop := (39*AVG.Y) div 8; + ButtonWidth := (50*AVG.X) div 4; + ButtonHeight := (13*AVG.Y) div 8; + Edit := TEdit.Create(Form); + With Edit do begin + Parent := Form; + Left := Prompt.Left; + Top := (19*AVG.Y) div 8; + Width := (160*AVG.X) div 4; + Height := (7*AVG.Y) div 4; + Text := Value; + TabStop := True; + Visible := True; + If MaskInput then + EchoMode := emPassword + else + EchoMode := emNormal; + TabOrder := 0; + end; + With TBitBtn.Create(Form) do begin + Parent := Form; + Kind := bkOk; + Default := True; + ModalResult := mrOk; + Left := (37*AVG.X) div 4; + Top := ButtonTop; + Height := ButtonHeight; + Width := ButtonWidth; + TabStop := True; + Visible := True; + TabOrder := 1; + end; + With TBitBtn.Create(Form) do begin + Parent := Form; + Kind := bkCancel; + Cancel := True; + Left := (92*AVG.X) div 4; + Top := ButtonTop; + Height := ButtonHeight; + Width := ButtonWidth; + TabStop := True; + Visible := True; + TabOrder := 2; + end; + Edit.SetFocus; + If ShowModal = mrOk then + begin + Value := Edit.Text; + Result := True; + end; + Form.Free; + end; +end; + +// included by dialogs.pp + diff --git a/lcl/interfacebase.pp b/lcl/interfacebase.pp index edbb7922d6..1a99e39ead 100644 --- a/lcl/interfacebase.pp +++ b/lcl/interfacebase.pp @@ -41,8 +41,8 @@ interface {$endif} uses - SysUtils, LCLLinux, LCLType, VCLGlobals, Classes, LMessages, Controls, - GraphType, GraphicsMath; + SysUtils, LCLStrConsts, LCLLinux, LCLType, LCLProc, VCLGlobals, Classes, + LMessages, Controls, GraphType, GraphicsMath; type @@ -79,23 +79,35 @@ type {$I defaultbitbtnimages.inc} {$I messagedialogpixmaps.inc} +type + TInputDialogFunction = Function (const InputCaption, InputPrompt : String; + MaskInput : Boolean; var Value : String) : Boolean; + +var + InputDialogFunction: TInputDialogFunction; + implementation Uses - LCLStrConsts, Forms, StdCtrls, ExtCtrls, Graphics, Buttons; + Forms, StdCtrls, Graphics, Buttons; {$I interfacebase.inc} initialization + InputDialogFunction:=nil; finalization + InputDialogFunction:=nil; end. { $Log$ + Revision 1.21 2002/10/25 09:47:37 lazarus + MG: added inputdialog.inc + Revision 1.20 2002/10/24 22:10:39 lazarus AJ: More changes for better code reuse between gnome & gtk interfaces