mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-12-06 14:54:42 +01:00
Fixed alignment of multiline TLabel.
Simplified and prettified MessageBoxen. git-svn-id: trunk@3264 -
This commit is contained in:
parent
77006e3b51
commit
e78acde725
@ -72,7 +72,7 @@ begin
|
|||||||
ShowMessage ('First simple test!');
|
ShowMessage ('First simple test!');
|
||||||
MessageDlg ('Caption', 'Two buttons now...', mtError, [mbOK,mbCancel], 0);
|
MessageDlg ('Caption', 'Two buttons now...', mtError, [mbOK,mbCancel], 0);
|
||||||
MessageDlg ('Warning, not fully implemented', mtWarning, [mbYes, mbNo, 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;
|
close;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -84,6 +84,10 @@ begin
|
|||||||
end.
|
end.
|
||||||
{
|
{
|
||||||
$Log$
|
$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
|
Revision 1.3 2002/05/10 06:57:50 lazarus
|
||||||
MG: updated licenses
|
MG: updated licenses
|
||||||
|
|
||||||
|
|||||||
@ -91,9 +91,8 @@ constructor TCustomLabel.Create(AOwner : TComponent);
|
|||||||
begin
|
begin
|
||||||
inherited Create(AOwner);
|
inherited Create(AOwner);
|
||||||
fCompStyle := csLabel;
|
fCompStyle := csLabel;
|
||||||
FLayout := tlBottom;
|
FLayout := tlTop;
|
||||||
ControlStyle := ControlStyle + [csOpaque, csReplicatable];
|
ControlStyle := ControlStyle + [csOpaque, csReplicatable];
|
||||||
|
|
||||||
SetBounds(0, 0, 65, 17);
|
SetBounds(0, 0, 65, 17);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
@ -102,6 +101,10 @@ end;
|
|||||||
{ =============================================================================
|
{ =============================================================================
|
||||||
|
|
||||||
$Log$
|
$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
|
Revision 1.3 2002/05/10 06:05:52 lazarus
|
||||||
MG: changed license to LGPL
|
MG: changed license to LGPL
|
||||||
|
|
||||||
|
|||||||
@ -38,11 +38,12 @@ type
|
|||||||
|
|
||||||
Internal class used to build a MessageBox.
|
Internal class used to build a MessageBox.
|
||||||
}
|
}
|
||||||
TMessageBox = class (TForm)
|
TMessageBox = class(TForm)
|
||||||
procedure MessageBoxKeyDown(Sender: TObject; var Key: Word;
|
procedure MessageBoxKeyDown(Sender: TObject; var Key: Word;
|
||||||
Shift: TShiftState);
|
Shift: TShiftState);
|
||||||
private
|
private
|
||||||
FBitmap : TBitmap;
|
FBitmap : TBitmap;
|
||||||
|
FLabel : TLabel;
|
||||||
FDlgType : TMsgDlgType;
|
FDlgType : TMsgDlgType;
|
||||||
FButtons : TMsgDlgButtons;
|
FButtons : TMsgDlgButtons;
|
||||||
FRelayoutNeeded: boolean;
|
FRelayoutNeeded: boolean;
|
||||||
@ -91,6 +92,11 @@ begin
|
|||||||
inherited Create (AOwner);
|
inherited Create (AOwner);
|
||||||
|
|
||||||
FMsgLines := TStringList.Create;
|
FMsgLines := TStringList.Create;
|
||||||
|
FLabel := TLabel.Create(Self);
|
||||||
|
FLabel.Alignment:= taLeftJustify;
|
||||||
|
FLabel.Parent:= Self;
|
||||||
|
FLabel.Visible:= true;
|
||||||
|
|
||||||
ControlStyle:= ControlStyle-[csSetCaption];
|
ControlStyle:= ControlStyle-[csSetCaption];
|
||||||
BorderStyle := bsDialog;
|
BorderStyle := bsDialog;
|
||||||
Position := poScreenCenter;
|
Position := poScreenCenter;
|
||||||
@ -114,6 +120,7 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
destructor TMessageBox.Destroy;
|
destructor TMessageBox.Destroy;
|
||||||
begin
|
begin
|
||||||
|
FLabel.Free;
|
||||||
FBitmap.Free;
|
FBitmap.Free;
|
||||||
FMsgLines.Free;
|
FMsgLines.Free;
|
||||||
inherited Destroy;
|
inherited Destroy;
|
||||||
@ -173,7 +180,7 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
function TMessageBox.LineHeight: integer;
|
function TMessageBox.LineHeight: integer;
|
||||||
begin
|
begin
|
||||||
Result:=Canvas.TextHeight('ABCDEFGHIJKLMNOPQRSTUVWXYZgp09')+8;
|
Result:=Canvas.TextHeight('ABCDEFGHIJKLMNOPQRSTUVWXYZgp09') + 4;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{------------------------------------------------------------------------------
|
{------------------------------------------------------------------------------
|
||||||
@ -200,7 +207,7 @@ end;
|
|||||||
|
|
||||||
Sets the Text in MessageBox
|
Sets the Text in MessageBox
|
||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
procedure TMessageBox.SetMessage (const Value : string);
|
procedure TMessageBox.SetMessage(const Value : string);
|
||||||
begin
|
begin
|
||||||
if Value=FMsgLines.Text then exit;
|
if Value=FMsgLines.Text then exit;
|
||||||
FMsgLines.Text:=Value;
|
FMsgLines.Text:=Value;
|
||||||
@ -267,9 +274,9 @@ end;
|
|||||||
------------------------------------------------------------------------------}
|
------------------------------------------------------------------------------}
|
||||||
procedure TMessageBox.ReLayout;
|
procedure TMessageBox.ReLayout;
|
||||||
const
|
const
|
||||||
cBtnWidth = 85; //TODO: Take into account different languages; button width may vary!
|
cBtnWidth = 90; //TODO: Take into account different languages; button width may vary!
|
||||||
cBtnDist = cBtnWidth + 25;
|
cBtnHeight = 25;
|
||||||
cBtnHeight = 32;
|
cBtnDist = cBtnWidth + 4;
|
||||||
cMinLeft = cBitmapX + cBitmapWidth + cLabelSpacing;
|
cMinLeft = cBitmapX + cBitmapWidth + cLabelSpacing;
|
||||||
var
|
var
|
||||||
aButton : TBitBtn; // temp. variable to create buttons
|
aButton : TBitBtn; // temp. variable to create buttons
|
||||||
@ -278,23 +285,21 @@ var
|
|||||||
ButtonLeft : integer; // left position of button(s)
|
ButtonLeft : integer; // left position of button(s)
|
||||||
LabelLeft : integer; // left position of labels
|
LabelLeft : integer; // left position of labels
|
||||||
reqBtnWidth : integer; // width neccessary to display buttons
|
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
|
LabelWidth : integer; // max width of labels
|
||||||
LabelHeight : integer;
|
LabelHeight : integer;
|
||||||
TempLabel : TLabel; // temporary label components
|
|
||||||
LabelIndex : integer;
|
|
||||||
i, j : integer;
|
i, j : integer;
|
||||||
ButtonIndex : integer;
|
ButtonIndex : integer;
|
||||||
begin
|
begin
|
||||||
if FUpdateCounter>0 then exit;
|
if FUpdateCounter>0 then exit;
|
||||||
|
|
||||||
// calculate label width
|
// calculate label width
|
||||||
LabelWidth:=0;
|
LabelWidth:= 0;
|
||||||
for i:=0 to FMsgLines.Count-1 do begin
|
for i:=0 to FMsgLines.Count-1 do begin
|
||||||
j:=LineWidth(i);
|
j:=LineWidth(i);
|
||||||
if j>LabelWidth then LabelWidth:=j;
|
if j > LabelWidth then LabelWidth:= j;
|
||||||
end;
|
end;
|
||||||
LabelHeight:=LineHeight;
|
LabelHeight:= LineHeight * FMsgLines.Count;
|
||||||
|
|
||||||
// destroy old BitBtns
|
// destroy old BitBtns
|
||||||
for i:=ComponentCount-1 downto 0 do
|
for i:=ComponentCount-1 downto 0 do
|
||||||
@ -303,51 +308,27 @@ begin
|
|||||||
|
|
||||||
// calculate the width we need to display the buttons
|
// calculate the width we need to display the buttons
|
||||||
reqBtnWidth := 0;
|
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 curBtn in FButtons then inc(reqBtnWidth, cBtnDist);
|
||||||
|
if reqBtnWidth > 0 then Dec(reqBtnWidth, 4);
|
||||||
|
|
||||||
// patch positions to center label and buttons
|
// patch positions to center label and buttons
|
||||||
reqWidth:=reqBtnWidth;
|
reqWidth:= reqBtnWidth;
|
||||||
if reqWidth < LabelWidth then reqWidth:=LabelWidth;
|
if reqWidth < (LabelWidth + cMinLeft) then reqWidth:= LabelWidth + cMinLeft;
|
||||||
LabelLeft := ((reqWidth - LabelWidth) div 2) + cMinLeft;
|
|
||||||
ButtonLeft := cMinLeft + ((reqWidth - reqBtnWidth) div 2) + (25 div 2);
|
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
|
// set size of form
|
||||||
SetBounds(Left,Top,reqWidth+cMinLeft+cLabelSpacing,
|
SetBounds(Left, Top, reqWidth + 2 * cLabelSpacing,
|
||||||
4*cLabelSpacing+FMsgLines.Count*(LabelHeight+cLabelSpacing)+cBtnHeight);
|
3 * cLabelSpacing + reqHeight + cBtnHeight);
|
||||||
|
|
||||||
// create and position the labels
|
// set up labels
|
||||||
i:=0;
|
FLabel.SetBounds(LabelLeft, cLabelSpacing, LabelWidth, LabelHeight);
|
||||||
LabelIndex:=0;
|
Flabel.Caption:= Trim(FMsgLines.Text);
|
||||||
while (i<ComponentCount) and (LabelIndex<FMsgLines.Count) do begin
|
|
||||||
if (Components[i] is TLabel) then begin
|
|
||||||
TempLabel:=TLabel(Components[i]);
|
|
||||||
with TempLabel do begin
|
|
||||||
SetBounds(LabelLeft,
|
|
||||||
cLabelSpacing+(cLabelSpacing+LabelHeight)*LabelIndex,
|
|
||||||
LabelWidth,LabelHeight);
|
|
||||||
Caption:=FMsgLines[LabelIndex];
|
|
||||||
Visible:=true;
|
|
||||||
end;
|
|
||||||
inc(LabelIndex);
|
|
||||||
end else
|
|
||||||
inc(i);
|
|
||||||
end;
|
|
||||||
while (i<ComponentCount) do
|
|
||||||
if (Components[i] is TLabel) then Components[i].Free;
|
|
||||||
while LabelIndex<FMsgLines.Count do begin
|
|
||||||
TempLabel:=TLabel.Create(Self);
|
|
||||||
with TempLabel do begin
|
|
||||||
Parent := Self;
|
|
||||||
Name:='MsgLabel'+IntToStr(LabelIndex);
|
|
||||||
SetBounds(LabelLeft,
|
|
||||||
cLabelSpacing+(cLabelSpacing+LabelHeight)*LabelIndex,
|
|
||||||
LabelWidth,LabelHeight);
|
|
||||||
Caption:=FMsgLines[LabelIndex];
|
|
||||||
Visible:=true;
|
|
||||||
end;
|
|
||||||
inc(LabelIndex);
|
|
||||||
end;
|
|
||||||
|
|
||||||
// create the buttons
|
// create the buttons
|
||||||
ButtonIndex := -1;
|
ButtonIndex := -1;
|
||||||
@ -357,9 +338,7 @@ begin
|
|||||||
aButton := TBitBtn.Create(self);
|
aButton := TBitBtn.Create(self);
|
||||||
With aButton do begin
|
With aButton do begin
|
||||||
Parent := Self;
|
Parent := Self;
|
||||||
SetBounds (ButtonLeft,
|
SetBounds (ButtonLeft, 2 * cLabelSpacing + reqHeight, cBtnWidth, cBtnHeight);
|
||||||
3*cLabelSpacing+(cLabelSpacing+LabelHeight)*FMsgLines.Count,
|
|
||||||
cBtnWidth, cBtnHeight);
|
|
||||||
inc(ButtonLeft, cBtnDist);
|
inc(ButtonLeft, cBtnDist);
|
||||||
Layout := blGlyphLeft;
|
Layout := blGlyphLeft;
|
||||||
// ToDo: when TBitmap streaming is working, load image from resource
|
// ToDo: when TBitmap streaming is working, load image from resource
|
||||||
@ -495,6 +474,10 @@ end;
|
|||||||
|
|
||||||
{
|
{
|
||||||
$Log$
|
$Log$
|
||||||
|
Revision 1.12 2002/08/30 10:06:07 lazarus
|
||||||
|
Fixed alignment of multiline TLabel.
|
||||||
|
Simplified and prettified MessageBoxen.
|
||||||
|
|
||||||
Revision 1.11 2002/07/29 13:39:07 lazarus
|
Revision 1.11 2002/07/29 13:39:07 lazarus
|
||||||
MG: removed ambigious TBitmap from LCLType and added Escape key to MessageDlgs
|
MG: removed ambigious TBitmap from LCLType and added Escape key to MessageDlgs
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user