lcl: add TStaticText.Transparent property for Delphi compatibility

win32: implement TStaticText.Transparent same way as groupbox transparency

git-svn-id: trunk@28151 -
This commit is contained in:
paul 2010-11-08 09:07:40 +00:00
parent d49ae27a49
commit f09ed2fb3c
3 changed files with 45 additions and 1 deletions

View File

@ -32,7 +32,8 @@ begin
fAlignment := taLeftJustify;
FShowAccelChar:= true;
FStaticBorderStyle:=sbsNone;
ControlStyle := ControlStyle + [csOpaque, csReplicatable];
ControlStyle := ControlStyle + [csReplicatable];
Transparent := True;
with GetControlClassDefaultSize do
SetInitialBounds(0, 0, CX, CY);
end;
@ -82,6 +83,11 @@ begin
end;
end;
function TCustomStaticText.GetTransparent: Boolean;
begin
Result := not (csOpaque in ControlStyle);
end;
{------------------------------------------------------------------------------
Method: TCustomStaticText.SetFocusControl
Params: Val - new property value
@ -151,6 +157,17 @@ begin
end;
end;
procedure TCustomStaticText.SetTransparent(const AValue: Boolean);
begin
if Transparent = AValue then
Exit;
if AValue then
ControlStyle := ControlStyle - [csOpaque]
else
ControlStyle := ControlStyle + [csOpaque];
Invalidate;
end;
{------------------------------------------------------------------------------
Method: TCustomStaticText.WMActivate
Params: Message: Activation message

View File

@ -1384,6 +1384,28 @@ begin
end;
end;
function StaticTextParentMsgHandler(const AWinControl: TWinControl; Window: HWnd;
Msg: UInt; WParam: Windows.WParam; LParam: Windows.LParam;
var MsgResult: Windows.LResult; var WinProcess: Boolean): Boolean;
var
Info: PWin32WindowInfo;
begin
Result := False;
case Msg of
WM_CTLCOLORSTATIC:
begin
Info := GetWin32WindowInfo(HWND(LParam));
Result := Assigned(Info) and ThemeServices.ThemesAvailable and TCustomStaticText(Info^.WinControl).Transparent;
if Result then
begin
ThemeServices.DrawParentBackground(HWND(LParam), HDC(WParam), nil, False);
MsgResult := GetStockObject(HOLLOW_BRUSH);
WinProcess := False;
SetBkMode(HDC(WParam), TRANSPARENT);
end;
end;
end;
end;
function CalcStaticTextFlags(
const AAlignment: TAlignment;
@ -1423,6 +1445,7 @@ begin
// create window
FinishCreateWindow(AWinControl, Params, false);
Result := Params.Window;
Params.WindowInfo^.ParentMsgHandler := @StaticTextParentMsgHandler;
end;
class procedure TWin32WSCustomStaticText.GetPreferredSize(

View File

@ -967,8 +967,10 @@ type
FFocusControl: TWinControl;
FShowAccelChar: boolean;
FStaticBorderStyle: TStaticBorderStyle;
function GetTransparent: Boolean;
procedure SetAlignment(Value: TAlignment);
procedure SetStaticBorderStyle(Value: TStaticBorderStyle);
procedure SetTransparent(const AValue: Boolean);
procedure WMActivate(var Message: TLMActivate); message LM_ACTIVATE;
protected
class procedure WSRegisterClass; override;
@ -985,6 +987,7 @@ type
property BorderStyle: TStaticBorderStyle read FStaticBorderStyle write SetStaticBorderStyle default sbsNone;
property FocusControl: TWinControl read FFocusControl write SetFocusControl;
property ShowAccelChar: boolean read FShowAccelChar write SetShowAccelChar default true;
property Transparent: Boolean read GetTransparent write SetTransparent default True;
end;
@ -1028,6 +1031,7 @@ type
property ShowHint;
property TabOrder;
property TabStop;
property Transparent;
property Visible;
end;