lcl: adjust static text size on border change

win32: implement autosize for TStaticText

git-svn-id: trunk@18416 -
This commit is contained in:
paul 2009-01-24 17:00:13 +00:00
parent 2b5fa9f4a9
commit f22cb37270
2 changed files with 33 additions and 0 deletions

View File

@ -135,7 +135,14 @@ begin
begin
FStaticBorderStyle := Value;
if HandleAllocated then
begin
TWSCustomStaticTextClass(WidgetsetClass).SetStaticBorderStyle(Self, Value);
if AutoSize then
begin
InvalidatePreferredSize;
AdjustSize;
end;
end;
end;
end;

View File

@ -208,6 +208,9 @@ type
published
class function CreateHandle(const AWinControl: TWinControl;
const AParams: TCreateParams): HWND; override;
class procedure GetPreferredSize(const AWinControl: TWinControl;
var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: Boolean); override;
class procedure SetAlignment(const ACustomStaticText: TCustomStaticText; const NewAlignment: TAlignment); override;
class procedure SetStaticBorderStyle(const ACustomStaticText: TCustomStaticText; const NewBorderStyle: TStaticBorderStyle); override;
class procedure SetText(const AWinControl: TWinControl; const AText: String); override;
@ -1329,6 +1332,29 @@ begin
Result := Params.Window;
end;
class procedure TWin32WSCustomStaticText.GetPreferredSize(
const AWinControl: TWinControl; var PreferredWidth, PreferredHeight: integer;
WithThemeSpace: Boolean);
begin
if MeasureText(AWinControl, AWinControl.Caption, PreferredWidth, PreferredHeight) then
begin
Inc(PreferredHeight);
if TCustomStaticText(AWinControl).BorderStyle <> sbsNone then
begin
if ThemeServices.ThemesEnabled and (TCustomStaticText(AWinControl).BorderStyle = sbsSingle) then
begin
inc(PreferredWidth, 4);
inc(PreferredHeight, 4);
end
else
begin
inc(PreferredWidth, 2);
inc(PreferredHeight, 2);
end;
end;
end;
end;
class procedure TWin32WSCustomStaticText.SetAlignment(const ACustomStaticText: TCustomStaticText; const NewAlignment: TAlignment);
begin
if not WSCheckHandleAllocated(ACustomStaticText, 'SetAlignment') then