diff --git a/lcl/include/customstatictext.inc b/lcl/include/customstatictext.inc index 04a9103287..3031c0239f 100644 --- a/lcl/include/customstatictext.inc +++ b/lcl/include/customstatictext.inc @@ -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 diff --git a/lcl/interfaces/win32/win32wsstdctrls.pp b/lcl/interfaces/win32/win32wsstdctrls.pp index 14fceba1ce..c46c07c86a 100644 --- a/lcl/interfaces/win32/win32wsstdctrls.pp +++ b/lcl/interfaces/win32/win32wsstdctrls.pp @@ -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( diff --git a/lcl/stdctrls.pp b/lcl/stdctrls.pp index 5205834b87..89e634b7db 100644 --- a/lcl/stdctrls.pp +++ b/lcl/stdctrls.pp @@ -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;