From e78acde725a0a6c3b249e8df9ec3cd76f1e29287 Mon Sep 17 00:00:00 2001 From: lazarus Date: Fri, 30 Aug 2002 10:06:07 +0000 Subject: [PATCH] Fixed alignment of multiline TLabel. Simplified and prettified MessageBoxen. git-svn-id: trunk@3264 - --- examples/messagedialogs.pp | 6 ++- lcl/include/customlabel.inc | 7 ++- lcl/include/messagedialogs.inc | 93 ++++++++++++++-------------------- 3 files changed, 48 insertions(+), 58 deletions(-) diff --git a/examples/messagedialogs.pp b/examples/messagedialogs.pp index 1fa4f82d1a..671d042832 100644 --- a/examples/messagedialogs.pp +++ b/examples/messagedialogs.pp @@ -72,7 +72,7 @@ begin ShowMessage ('First simple test!'); MessageDlg ('Caption', 'Two buttons now...', mtError, [mbOK,mbCancel], 0); MessageDlg ('Warning, not fully implemented', mtWarning, [mbYes, mbNo, mbOK,mbCancel], 0); - ShowMessageFmt ('The show will end now'+#13+'%s', [MainForm.Caption]); + ShowMessageFmt ('The show will end now'+#13+'%s'+#13+'Good bye!!!', [MainForm.Caption]); close; end; @@ -84,6 +84,10 @@ begin end. { $Log$ + Revision 1.4 2002/08/30 10:06:07 lazarus + Fixed alignment of multiline TLabel. + Simplified and prettified MessageBoxen. + Revision 1.3 2002/05/10 06:57:50 lazarus MG: updated licenses diff --git a/lcl/include/customlabel.inc b/lcl/include/customlabel.inc index 3e48b0e195..1cade2577a 100644 --- a/lcl/include/customlabel.inc +++ b/lcl/include/customlabel.inc @@ -91,9 +91,8 @@ constructor TCustomLabel.Create(AOwner : TComponent); begin inherited Create(AOwner); fCompStyle := csLabel; - FLayout := tlBottom; + FLayout := tlTop; ControlStyle := ControlStyle + [csOpaque, csReplicatable]; - SetBounds(0, 0, 65, 17); end; @@ -102,6 +101,10 @@ end; { ============================================================================= $Log$ + Revision 1.4 2002/08/30 10:06:07 lazarus + Fixed alignment of multiline TLabel. + Simplified and prettified MessageBoxen. + Revision 1.3 2002/05/10 06:05:52 lazarus MG: changed license to LGPL diff --git a/lcl/include/messagedialogs.inc b/lcl/include/messagedialogs.inc index 00408e4f8c..cf660ecf4c 100644 --- a/lcl/include/messagedialogs.inc +++ b/lcl/include/messagedialogs.inc @@ -38,11 +38,12 @@ type Internal class used to build a MessageBox. } - TMessageBox = class (TForm) + TMessageBox = class(TForm) procedure MessageBoxKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState); private FBitmap : TBitmap; + FLabel : TLabel; FDlgType : TMsgDlgType; FButtons : TMsgDlgButtons; FRelayoutNeeded: boolean; @@ -91,6 +92,11 @@ begin inherited Create (AOwner); FMsgLines := TStringList.Create; + FLabel := TLabel.Create(Self); + FLabel.Alignment:= taLeftJustify; + FLabel.Parent:= Self; + FLabel.Visible:= true; + ControlStyle:= ControlStyle-[csSetCaption]; BorderStyle := bsDialog; Position := poScreenCenter; @@ -114,6 +120,7 @@ end; ------------------------------------------------------------------------------} destructor TMessageBox.Destroy; begin + FLabel.Free; FBitmap.Free; FMsgLines.Free; inherited Destroy; @@ -173,7 +180,7 @@ end; ------------------------------------------------------------------------------} function TMessageBox.LineHeight: integer; begin - Result:=Canvas.TextHeight('ABCDEFGHIJKLMNOPQRSTUVWXYZgp09')+8; + Result:=Canvas.TextHeight('ABCDEFGHIJKLMNOPQRSTUVWXYZgp09') + 4; end; {------------------------------------------------------------------------------ @@ -200,7 +207,7 @@ end; Sets the Text in MessageBox ------------------------------------------------------------------------------} -procedure TMessageBox.SetMessage (const Value : string); +procedure TMessageBox.SetMessage(const Value : string); begin if Value=FMsgLines.Text then exit; FMsgLines.Text:=Value; @@ -267,9 +274,9 @@ end; ------------------------------------------------------------------------------} procedure TMessageBox.ReLayout; const - cBtnWidth = 85; //TODO: Take into account different languages; button width may vary! - cBtnDist = cBtnWidth + 25; - cBtnHeight = 32; + cBtnWidth = 90; //TODO: Take into account different languages; button width may vary! + cBtnHeight = 25; + cBtnDist = cBtnWidth + 4; cMinLeft = cBitmapX + cBitmapWidth + cLabelSpacing; var aButton : TBitBtn; // temp. variable to create buttons @@ -278,23 +285,21 @@ var ButtonLeft : integer; // left position of button(s) LabelLeft : integer; // left position of labels reqBtnWidth : integer; // width neccessary to display buttons - reqWidth : integer; // width neccessary to display all + reqWidth, reqHeight : integer; // width and height neccessary to display all LabelWidth : integer; // max width of labels LabelHeight : integer; - TempLabel : TLabel; // temporary label components - LabelIndex : integer; - i, j : integer; + i, j : integer; ButtonIndex : integer; begin if FUpdateCounter>0 then exit; // calculate label width - LabelWidth:=0; + LabelWidth:= 0; for i:=0 to FMsgLines.Count-1 do begin j:=LineWidth(i); - if j>LabelWidth then LabelWidth:=j; + if j > LabelWidth then LabelWidth:= j; end; - LabelHeight:=LineHeight; + LabelHeight:= LineHeight * FMsgLines.Count; // destroy old BitBtns for i:=ComponentCount-1 downto 0 do @@ -303,51 +308,27 @@ begin // calculate the width we need to display the buttons reqBtnWidth := 0; - for curBtn := low (TMsgDlgBtn) to high (TMsgDlgBtn) do + for curBtn := Low(TMsgDlgBtn) to High(TMsgDlgBtn) do if curBtn in FButtons then inc(reqBtnWidth, cBtnDist); + if reqBtnWidth > 0 then Dec(reqBtnWidth, 4); // patch positions to center label and buttons - reqWidth:=reqBtnWidth; - if reqWidth < LabelWidth then reqWidth:=LabelWidth; - LabelLeft := ((reqWidth - LabelWidth) div 2) + cMinLeft; - ButtonLeft := cMinLeft + ((reqWidth - reqBtnWidth) div 2) + (25 div 2); + reqWidth:= reqBtnWidth; + if reqWidth < (LabelWidth + cMinLeft) then reqWidth:= LabelWidth + cMinLeft; + + LabelLeft := ((reqWidth - cMinLeft - LabelWidth) div 2) + cMinLeft; + ButtonLeft := ((reqWidth - reqBtnWidth) div 2) + cLabelSpacing; + + reqHeight:= LabelHeight; + if reqHeight < cBitmapHeight then reqHeight:= cBitmapHeight; // set size of form - SetBounds(Left,Top,reqWidth+cMinLeft+cLabelSpacing, - 4*cLabelSpacing+FMsgLines.Count*(LabelHeight+cLabelSpacing)+cBtnHeight); + SetBounds(Left, Top, reqWidth + 2 * cLabelSpacing, + 3 * cLabelSpacing + reqHeight + cBtnHeight); - // create and position the labels - i:=0; - LabelIndex:=0; - while (i