6
Classes, SysUtils, Graphics, ComCtrls, Controls, ExtCtrls, Menus, StdCtrls,
7
Spin, Forms, Generics.Collections, Grids;
13
ColorWindowText: TColor;
15
ColorControlText: TColor;
16
ColorControlSelected: TColor;
21
TThemes = class(TObjectList<TTheme>)
22
function AddNew(Name: string): TTheme;
23
function FindByName(Name: string): TTheme;
24
procedure LoadToStrings(Strings: TStrings);
29
TThemeManager = class(TComponent)
32
procedure SetTheme(AValue: TTheme);
33
procedure SetThemeName(AValue: TTheme);
37
procedure ApplyTheme(Component: TComponent);
38
constructor Create(AOwner: TComponent); override;
39
destructor Destroy; override;
40
procedure UseTheme(Form: TForm);
41
property Theme: TTheme read FTheme write SetTheme;
45
ThemeNameSystem = 'System';
46
ThemeNameLight = 'Light';
47
ThemeNameDark = 'Dark';
58
RegisterComponents('Common', [TThemeManager]);
61
function TThemes.AddNew(Name: string): TTheme;
63
Result := TTheme.Create;
68
function TThemes.FindByName(Name: string): TTheme;
74
if Theme.Name = Name then begin
80
procedure TThemes.LoadToStrings(Strings: TStrings);
86
while Strings.Count < Count do Strings.Add('');
87
while Strings.Count > Count do Strings.Delete(Strings.Count - 1);
88
for I := 0 to Count - 1 do begin
89
Strings[I] := Items[I].Name;
90
Strings.Objects[I] := Items[I];
97
procedure TThemeManager.SetThemeName(AValue: TTheme);
99
if FTheme = AValue then Exit;
103
procedure TThemeManager.SetTheme(AValue: TTheme);
105
if FTheme = AValue then Exit;
109
constructor TThemeManager.Create(AOwner: TComponent);
112
Themes := TThemes.Create;
113
with Themes.AddNew(ThemeNameSystem) do begin
114
ColorWindow := clWindow;
115
ColorWindowText := clWindowText;
116
ColorControl := clMenu;
117
ColorControlText := clWindowText;
118
ColorControlSelected := clWindow;
120
Theme := TTheme(Themes.First);
121
with Themes.AddNew(ThemeNameDark) do begin
122
ColorWindow := RGBToColor($20, $20, $20);
123
ColorWindowText := clWhite;
124
ColorControl := RGBToColor($40, $40, $40);
125
ColorControlText := clWhite;
126
ColorControlSelected := RGBToColor(96, 125, 155);
128
with Themes.AddNew(ThemeNameLight) do begin
129
ColorWindow := clWhite;
130
ColorWindowText := clBlack;
131
ColorControl := RGBToColor($e0, $e0, $e0);
132
ColorControlText := clBlack;
133
ColorControlSelected := RGBToColor(196, 225, 255);
137
destructor TThemeManager.Destroy;
143
procedure TThemeManager.ApplyTheme(Component: TComponent);
148
if Component is TWinControl then begin
149
for I := 0 to TWinControl(Component).ControlCount - 1 do
150
ApplyTheme(TWinControl(Component).Controls[I]);
153
if Component is TControl then begin
154
Control := (Component as TControl);
155
if (Control is TEdit) or (Control is TSpinEdit) or (Control is TComboBox) and
156
(Control is TMemo) or (Control is TListView) or (Control is TCustomDrawGrid) or
157
(Control is TCheckBox) or (Control is TPageControl) or (Control is TRadioButton) then begin
158
Control.Color := FTheme.ColorWindow;
159
Control.Font.Color := FTheme.ColorWindowText;
161
Control.Color := FTheme.ColorControl;
162
Control.Font.Color := FTheme.ColorControlText;
165
if Control is TCustomDrawGrid then begin
166
(Control as TCustomDrawGrid).Editor.Color := FTheme.ColorWindow;
167
(Control as TCustomDrawGrid).Editor.Font.Color := FTheme.ColorWindowText;
170
if Control is TPageControl then begin
171
for I := 0 to TPageControl(Component).PageCount - 1 do
172
ApplyTheme(TPageControl(Component).Pages[I]);
175
if Control is TCoolBar then begin
176
(Control as TCoolBar).Themed := False;
181
procedure TThemeManager.UseTheme(Form: TForm);
183
if not Used and (FTheme.Name = ThemeNameSystem) then Exit;