LCL: QuestionDlg: default dialog with memo: make sizable

git-svn-id: trunk@50800 -
This commit is contained in:
mattias 2015-12-14 17:13:32 +00:00
parent 2c3a45ce75
commit 627278054a

View File

@ -621,107 +621,117 @@ var
end; end;
begin begin
FillChar(TextStyle, SizeOf(TTextStyle), 0); BeginAutoSizing;
try
FillChar(TextStyle, SizeOf(TTextStyle), 0);
with TextStyle do with TextStyle do
begin
Clipping := True;
Wordbreak := True;
SystemFont := True;
Opaque := False;
end;
// calculate the width & height we need to display the Message
if MessageTxt = '' then
MessageTxt := ' ';
TextBox := Rect(0, 0, Screen.Width div 2, Screen.Height);
Flags := DT_CalcRect or DT_WordBreak;
SelectObject(Canvas.Handle, Screen.SystemFont.Reference.Handle);
DrawText(Canvas.Handle, PChar(MessageTxt), Length(MessageTxt), TextBox, Flags);
MaxHeight:=200;//Min(Screen.Height-100,(Screen.Height*4) div 5);
if TextBox.Bottom>MaxHeight then
begin
// does not fit onto the screen => use a TMemo
TextBox.Bottom:=MaxHeight;
if FMsgMemo=nil then
begin begin
FMsgMemo:=TMemo.Create(Self); Clipping := True;
with FMsgMemo do Wordbreak := True;
SystemFont := True;
Opaque := False;
end;
// calculate the width & height we need to display the Message
if MessageTxt = '' then
MessageTxt := ' ';
TextBox := Rect(0, 0, Screen.Width div 2, Screen.Height);
Flags := DT_CalcRect or DT_WordBreak;
SelectObject(Canvas.Handle, Screen.SystemFont.Reference.Handle);
DrawText(Canvas.Handle, PChar(MessageTxt), Length(MessageTxt), TextBox, Flags);
MaxHeight:=200;//Min(Screen.Height-100,(Screen.Height*4) div 5);
if TextBox.Bottom>MaxHeight then
begin
// does not fit onto the screen => use a TMemo
TextBox.Bottom:=MaxHeight;
if FMsgMemo=nil then
begin begin
WordWrap:=true; FMsgMemo:=TMemo.Create(Self);
ReadOnly:=true; with FMsgMemo do
ScrollBars:=ssAutoBoth; begin
Text:=MessageTxt; WordWrap:=true;
Parent:=Self; ReadOnly:=true;
ScrollBars:=ssAutoBoth;
Text:=MessageTxt;
Anchors:=[akLeft,akTop,akRight,akBottom];
Parent:=Self;
end;
end; end;
end; FMsgMemo.Visible:=true;
FMsgMemo.Visible:=true; BorderStyle := bsSizeable;
end else if FMsgMemo<>nil then end else if FMsgMemo<>nil then
FMsgMemo.Visible:=false;
// calculate the width we need to display the buttons
MinBtnWidth:=Max(25,MinimumDialogButtonWidth);
MinBtnHeight:=Max(15,MinimumDialogButtonHeight);
reqBtnWidth := 0;
if FButtons <> nil then
for i := 0 to FButtons.Count - 1 do
begin begin
CurButton := TBitBtn(FButtons[i]); FMsgMemo.Visible:=false;
CurBtnSize:=GetButtonSize(CurButton); BorderStyle := bsDialog;
if i > 0 then Inc(reqBtnWidth, cBtnDist);
Inc(reqBtnWidth, CurBtnSize.X);
end; end;
// calculate the width of the dialog // calculate the width we need to display the buttons
if FBitmap <> nil then MinBtnWidth:=Max(25,MinimumDialogButtonWidth);
cMinLeft := cLabelSpacing + max(20, FBitmap.Width) + cLabelSpacing MinBtnHeight:=Max(15,MinimumDialogButtonHeight);
else reqBtnWidth := 0;
cMinLeft := cLabelSpacing;
reqWidth:= reqBtnWidth + 2 * cBtnDist;
if reqWidth < (TextBox.Right + cMinLeft + cLabelSpacing) then
reqWidth:= TextBox.Right + cMinLeft + cLabelSpacing;
ButtonLeft := ((reqWidth - reqBtnWidth) div 2);
// calculate the height of the dialog if FButtons <> nil then
reqHeight:= TextBox.Bottom; for i := 0 to FButtons.Count - 1 do
if (FBitmap <> nil) and (FBitmap.Height > reqHeight) then begin
reqHeight := FBitmap.Height; CurButton := TBitBtn(FButtons[i]);
// ToDo: CurBtnSize may not be initialized. CurBtnSize:=GetButtonSize(CurButton);
inc(reqHeight, CurBtnSize.Y + 3 * cLabelSpacing); if i > 0 then Inc(reqBtnWidth, cBtnDist);
Inc(reqBtnWidth, CurBtnSize.X);
end;
// calculate the text position // calculate the width of the dialog
OffsetRect(TextBox, if FBitmap <> nil then
((reqWidth-cMinLeft-TextBox.Right-cLabelSpacing) div 2) + cMinLeft, cMinLeft := cLabelSpacing + max(20, FBitmap.Width) + cLabelSpacing
cLabelSpacing); else
cMinLeft := cLabelSpacing;
reqWidth:= reqBtnWidth + 2 * cBtnDist;
if reqWidth < (TextBox.Right + cMinLeft + cLabelSpacing) then
reqWidth:= TextBox.Right + cMinLeft + cLabelSpacing;
ButtonLeft := ((reqWidth - reqBtnWidth) div 2);
// calculate the icon position // calculate the height of the dialog
if FBitmap <> nil then reqHeight:= TextBox.Bottom;
begin if (FBitmap <> nil) and (FBitmap.Height > reqHeight) then
FBitmapX := cLabelSpacing; reqHeight := FBitmap.Height;
FBitmapY := (reqHeight - CurBtnSize.Y - FBitmap.Height - cLabelSpacing) div 2; // ToDo: CurBtnSize may not be initialized.
inc(reqHeight, CurBtnSize.Y + 3 * cLabelSpacing);
// calculate the text position
OffsetRect(TextBox,
((reqWidth-cMinLeft-TextBox.Right-cLabelSpacing) div 2) + cMinLeft,
cLabelSpacing);
// calculate the icon position
if FBitmap <> nil then
begin
FBitmapX := cLabelSpacing;
FBitmapY := (reqHeight - CurBtnSize.Y - FBitmap.Height - cLabelSpacing) div 2;
end;
// set size of form
SetBounds((Screen.Width - reqWidth-10) div 2, (Screen.Height - reqHeight-50) div 2,
reqWidth, reqHeight);
// position memo
if (FMsgMemo<>nil) and FMsgMemo.Visible then
FMsgMemo.BoundsRect:=TextBox;
// position buttons
CurBtnPos := ButtonLeft;
if FButtons <> nil then
for i := 0 to FButtons.Count-1 do
begin
CurButton := TBitBtn(Components[i]);
CurBtnSize := GetButtonSize(CurButton);
CurButton.SetBounds(CurBtnPos, ClientHeight - CurBtnSize.Y - cLabelSpacing,
CurBtnSize.X, CurBtnSize.Y);
inc(CurBtnPos, CurButton.Width + cBtnDist);
end;
finally
EndAutoSizing;
end; end;
// set size of form
SetBounds((Screen.Width - reqWidth-10) div 2, (Screen.Height - reqHeight-50) div 2,
reqWidth, reqHeight);
// position memo
if (FMsgMemo<>nil) and FMsgMemo.Visible then
FMsgMemo.BoundsRect:=TextBox;
// position buttons
CurBtnPos := ButtonLeft;
if FButtons <> nil then
for i := 0 to FButtons.Count-1 do
begin
CurButton := TBitBtn(Components[i]);
CurBtnSize := GetButtonSize(CurButton);
CurButton.SetBounds(CurBtnPos, ClientHeight - CurBtnSize.Y - cLabelSpacing,
CurBtnSize.X, CurBtnSize.Y);
inc(CurBtnPos, CurButton.Width + cBtnDist);
end;
end; end;
function TQuestionDlg.ShowModal: TModalResult; function TQuestionDlg.ShowModal: TModalResult;