LCL: use autosizing and anchoring to layout InputDialog (bug #1536)

git-svn-id: trunk@10229 -
This commit is contained in:
vincents 2006-11-22 11:26:28 +00:00
parent 9f21bbf3e6
commit 6bf3603e9e
3 changed files with 43 additions and 31 deletions

View File

@ -16,14 +16,11 @@
Function ShowInputDialog(const InputCaption, InputPrompt : String; Function ShowInputDialog(const InputCaption, InputPrompt : String;
MaskInput : Boolean; var Value : String) : Boolean; MaskInput : Boolean; var Value : String) : Boolean;
Const
AVGBuffer : PChar = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890()|_ ';
var var
Form : TForm; Form : TForm;
Prompt : TLabel; Prompt : TLabel;
Edit : TEdit; Edit : TEdit;
ButtonTop, ButtonWidth, ButtonHeight : Integer; MinEditWidth: integer;
Avg : TPoint;
begin begin
Result := False; Result := False;
Form := TForm.CreateNew(nil, 0); Form := TForm.CreateNew(nil, 0);
@ -32,29 +29,22 @@ begin
Caption := InputCaption; Caption := InputCaption;
Prompt := TLabel.Create(Form); Prompt := TLabel.Create(Form);
With Prompt do begin With Prompt do begin
Parent := Form;
Caption := InputPrompt; Caption := InputPrompt;
Top := 8;
Left := 8;
Visible := True; Visible := True;
AutoSize := True;
Parent := Form;
end; end;
SelectObject(Canvas.Handle, GetStockObject(DEFAULT_GUI_FONT));
GetTextExtentPoint(Canvas.Handle,AVGBuffer,StrLen(AVGBuffer),TSize(AVG));
AVG.X := AVG.X div 52;
Position := poScreenCenter; 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 := 2*AVG.Y;
Edit := TEdit.Create(Form); Edit := TEdit.Create(Form);
With Edit do begin With Edit do begin
Parent := Form; Parent := Form;
Left := Prompt.Left; Left := Prompt.Left;
Top := (19*AVG.Y) div 8; AnchorToNeighbour(akTop,8,Prompt);
Width := (160*AVG.X) div 4; AnchorParallel(akRight,0,Prompt);
Height := (7*AVG.Y) div 4; MinEditWidth := max(160, Screen.Width div 4);
Constraints.MinWidth := MinEditWidth;
Text := Value; Text := Value;
TabStop := True; TabStop := True;
Visible := True; Visible := True;
@ -70,31 +60,37 @@ begin
TabOrder := 0; TabOrder := 0;
end; end;
With TBitBtn.Create(Form) do begin With TBitBtn.Create(Form) do begin
Parent := Form;
Kind := bkOk; Kind := bkOk;
Default := True; Default := True;
ModalResult := mrOk; ModalResult := mrOk;
Left := (37*AVG.X) div 4; Left := MinEditWidth div 4;
Top := ButtonTop; AnchorToNeighbour(akTop,8,Edit);
Height := ButtonHeight; AutoSize := True;
Width := ButtonWidth;
TabStop := True; TabStop := True;
Visible := True; Visible := True;
TabOrder := 1; TabOrder := 1;
Parent := Form;
end; end;
With TBitBtn.Create(Form) do begin With TBitBtn.Create(Form) do begin
Parent := Form;
Kind := bkCancel; Kind := bkCancel;
Cancel := True; Cancel := True;
Left := (92*AVG.X) div 4; AnchorToNeighbour(akTop,8,Edit);
Top := ButtonTop; AnchorSide[akRight].Control := Edit;
Height := ButtonHeight; AnchorSide[akRight].Side := asrRight;
Width := ButtonWidth; BorderSpacing.Right := MinEditWidth div 4;
Anchors := [akTop, akRight];
AutoSize := True;
TabStop := True; TabStop := True;
Visible := True; Visible := True;
TabOrder := 2; TabOrder := 2;
Parent := Form;
end; end;
ChildSizing.TopBottomSpacing := 8;
ChildSizing.LeftRightSpacing := 8;
AutoSize := true;
// upon show, the edit control will be focused for editing, because it's // upon show, the edit control will be focused for editing, because it's
// the first in the tab order // the first in the tab order
If ShowModal = mrOk then If ShowModal = mrOk then

View File

@ -1501,9 +1501,13 @@ begin
if TargetWindow = HWND(nil) then if TargetWindow = HWND(nil) then
exit; exit;
// check if the window is an edit control of a combobox, if so, // check if the window is an edit control of a combobox, if so,
// redirect it to the combobox, not the edit control // redirect it to the combobox, not the edit control
if GetWindowInfo(TargetWindow)^.isComboEdit then if GetWindowInfo(TargetWindow)^.isComboEdit then
begin
TargetWindow := Windows.GetParent(TargetWindow); TargetWindow := Windows.GetParent(TargetWindow);
// Don't send the message to the overlay window, to avoid recursion // Don't send the message to the overlay window, to avoid recursion
if (TargetWindow <> Window) and (TargetWindow<>WindowInfo^.Overlay) then if (TargetWindow <> Window) and (TargetWindow<>WindowInfo^.Overlay) then
@ -1511,6 +1515,8 @@ begin
Result := SendMessage(TargetWindow, WM_MOUSEWHEEL, WParam, LParam); Result := SendMessage(TargetWindow, WM_MOUSEWHEEL, WParam, LParam);
exit; exit;
end; end;
end;
// the mousewheel message is for us // the mousewheel message is for us
// windows handles combobox's mousewheel messages // windows handles combobox's mousewheel messages
@ -1954,6 +1960,12 @@ begin
WinProcess := true; WinProcess := true;
end; end;
LM_MOUSEWHEEL:
begin
if PLMsg^.Result <> 0 then
WinProcess := true;
end;
CN_CHAR, CN_SYSCHAR: CN_CHAR, CN_SYSCHAR:
begin begin
// if key not yet processed, let windows process it // if key not yet processed, let windows process it

View File

@ -504,7 +504,11 @@ begin
end; end;
end; end;
Inc(PreferredWidth, 20); Inc(PreferredWidth, 20);
Inc(PreferredHeight, 12); Inc(PreferredHeight, 4);
if WithThemeSpace then begin
Inc(PreferredWidth, 6);
Inc(PreferredHeight, 6);
end;
end; end;
end; end;