LCL: fixed TLabel to override CalculatePreferredSize instead of DoAutoSize

git-svn-id: trunk@12925 -
This commit is contained in:
mattias 2007-11-19 20:00:42 +00:00
parent e4ed360ac1
commit 5141dd53bc
4 changed files with 21 additions and 11 deletions

View File

@ -974,6 +974,7 @@ end;
procedure TCustomForm.DoAutoSize;
begin
//DebugLn(['TCustomForm.DoAutoSize ',DbgSName(Self),' ',WindowState=wsNormal,' ',fsDisableAutoSize in FFormState,' ',dbgs(BoundsRect),' ',dbgs(ClientRect)]);
if (WindowState=wsNormal) and (not (fsDisableAutoSize in FFormState)) then
inherited DoAutoSize;
end;
@ -1946,9 +1947,9 @@ begin
FFormHandlers[fhtFirstShow].CallNotifyEvents(Self);
end;
{------------------------------------------------------------------------------}
{ TCustomForm ShowModal }
{------------------------------------------------------------------------------}
{------------------------------------------------------------------------------
TCustomForm ShowModal
------------------------------------------------------------------------------}
Function TCustomForm.ShowModal: Integer;
procedure RaiseShowModalImpossible;

View File

@ -26,7 +26,8 @@
}
procedure TCustomLabel.CalcSize(var AWidth, AHeight: integer);
procedure TCustomLabel.CalculatePreferredSize(
var PreferredWidth, PreferredHeight: integer; WithThemeSpace: Boolean);
// assumes: (Parent <> nil) and Parent.HandleAllocated
var
R : TRect;
@ -35,6 +36,7 @@ var
OldFont: HGDIOBJ;
LabelText: string;
begin
if (Parent=nil) or (not Parent.HandleAllocated) then exit;
DC := GetDC(Parent.Handle);
try
R := Rect(0,0, Width, Height);
@ -50,8 +52,8 @@ begin
DrawText(DC, PChar(LabelText), Length(LabelText), R, Flags);
SelectObject(DC, OldFont);
// add one to be able to display disabled label
AWidth := R.Right - R.Left + 1;
AHeight := R.Bottom - R.Top + 1;
PreferredWidth := R.Right - R.Left + 1;
PreferredHeight := R.Bottom - R.Top + 1;
finally
ReleaseDC(Parent.Handle, DC);
end;
@ -93,7 +95,7 @@ begin
exit;
BeginAutoSizing;
try
CalcSize(NewWidth, NewHeight);
GetPreferredSize(NewWidth, NewHeight);
//debugln('TCustomLabel.DoAutoSize ',dbgsName(Self),' Nice ',dbgs(Left),',',dbgs(Top),',w=',dbgs(NewWidth),',h=',dbgs(NewHeight),' Caption="',dbgstr(Caption),'"');
CurAnchors:=[];
if Align in [alLeft,alRight,alBottom,alTop,alClient] then
@ -198,7 +200,7 @@ begin
TextTop := 0;
end else
begin
CalcSize(lTextWidth, lTextHeight);
GetPreferredSize(lTextWidth, lTextHeight);
case Layout of
tlCenter: TextTop := (Height - lTextHeight) div 2;
tlBottom: TextTop := Height - lTextHeight;

View File

@ -3763,8 +3763,13 @@ begin
//DebugLn(['TWinControl.UpdateShowing ',DbgSName(Self),' FShowing=',FShowing,' AutoSizeDelayed=',AutoSizeDelayed]);
if FShowing then
begin
ResizeDelayedAutoSizeChildren;
AdjustSize;
DisableAlign;
try
ResizeDelayedAutoSizeChildren;
AdjustSize;
finally
EnableAlign;
end;
end;
end;

View File

@ -1357,7 +1357,9 @@ type
procedure DoMeasureTextPosition(var TextTop: integer;
var TextLeft: integer); virtual;
function HasMultiLine : boolean;
procedure CalcSize(var AWidth, AHeight: integer);
procedure CalculatePreferredSize(
var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: Boolean); override;
procedure DoAutoSize; override;
function DialogChar(var Message: TLMKey): boolean; override;
procedure TextChanged; override;