0

FocusEffect is displayed as a color in the bitmap style designer however it is not defined in TStyleColor.

I can see from the source that FocusEffect relates to TseStyleColor.ktcFocusEffect and should be able to fetch it with TSeStyle(FSource).Colors[ktcFocusEffect] however to do this requires getting the style source which is not accessible from the style and to make it more difficult all of the Tse* definitions are in the implementation section of vcl.styles and therefore not accessible.

Due to this being a seemingly over complicated attack on the problem I presume I am going about it all wrong and there must be a way to access the custom style stuff without hacking around because if you were to create your own custom style with lots of newly defined colors etc. you would have to hack for each new entry.

I have a solution below but it seems excessive for what should be a trivial task.

unit StyleDirect;

interface

uses
  Winapi.Windows, Vcl.Graphics;

type
  TStyleDirect = class
  public
    class function FocusEffectColor: TColor;
  end;

implementation

uses
  System.Classes, System.SysUtils, Vcl.Direct2D, Winapi.D2D1, System.Types, Vcl.ImgList, Vcl.Consts, ZLib, StrUtils, Vcl.GraphUtil,
  Winapi.Messages, Vcl.Controls, Vcl.Styles, Vcl.Forms, Vcl.Themes;

{$I StyleUtils.inc}
{$I StyleAPI.inc}

type
  TStyleHelper = class helper for TCustomStyle
  public
    function GetSource: TObject;
  end;

function TStyleHelper.GetSource: TObject;
begin
  Result := Self.FSource;
end;

{ TStyleDirect }

class function TStyleDirect.FocusEffectColor: TColor;
begin
  if not TStyleManager.IsCustomStyleActive then
    Exit(GetSysColor(clHighlight));

  var Style := TCustomStyle(TStyleManager.ActiveStyle);
  var Source := Style.GetSource;

  Result:=TSeStyle(Source).Colors[ktcFocusEffect];
end;

end.
Richard Shuck
  • 113
  • 1
  • 10

0 Answers0