Changeset 25 for trunk/Packages/Common/UTheme.pas
- Timestamp:
- Sep 10, 2022, 6:54:43 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Packages/Common/UTheme.pas
r16 r25 5 5 uses 6 6 Classes, SysUtils, Graphics, ComCtrls, Controls, ExtCtrls, Menus, StdCtrls, 7 Spin, Forms, Contnrs, Grids;7 Spin, Forms, Generics.Collections, Grids; 8 8 9 9 type … … 19 19 { TThemes } 20 20 21 TThemes = class(TObjectList )21 TThemes = class(TObjectList<TTheme>) 22 22 function AddNew(Name: string): TTheme; 23 23 function FindByName(Name: string): TTheme; … … 42 42 end; 43 43 44 const 45 ThemeNameSystem = 'System'; 46 ThemeNameLight = 'Light'; 47 ThemeNameDark = 'Dark'; 48 44 49 procedure Register; 50 45 51 46 52 implementation … … 74 80 procedure TThemes.LoadToStrings(Strings: TStrings); 75 81 var 76 Theme: TTheme;82 I: Integer; 77 83 begin 78 Strings.Clear; 79 for Theme in Self do 80 Strings.AddObject(Theme.Name, Theme); 84 Strings.BeginUpdate; 85 try 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]; 91 end; 92 finally 93 Strings.EndUpdate; 94 end; 81 95 end; 82 96 … … 97 111 inherited; 98 112 Themes := TThemes.Create; 99 with Themes.AddNew( 'System') do begin113 with Themes.AddNew(ThemeNameSystem) do begin 100 114 ColorWindow := clWindow; 101 115 ColorWindowText := clWindowText; … … 105 119 end; 106 120 Theme := TTheme(Themes.First); 107 with Themes.AddNew( 'Dark') do begin121 with Themes.AddNew(ThemeNameDark) do begin 108 122 ColorWindow := RGBToColor($20, $20, $20); 109 123 ColorWindowText := clWhite; … … 112 126 ColorControlSelected := RGBToColor(96, 125, 155); 113 127 end; 114 with Themes.AddNew( 'Light') do begin128 with Themes.AddNew(ThemeNameLight) do begin 115 129 ColorWindow := clWhite; 116 130 ColorWindowText := clBlack; … … 123 137 destructor TThemeManager.Destroy; 124 138 begin 125 Themes.Free;126 inherited Destroy;139 FreeAndNil(Themes); 140 inherited; 127 141 end; 128 142 … … 132 146 I: Integer; 133 147 begin 134 for I := 0 to Component.ComponentCount - 1 do 135 ApplyTheme(Component.Components[I]); 148 if Component is TWinControl then begin 149 for I := 0 to TWinControl(Component).ControlCount - 1 do 150 ApplyTheme(TWinControl(Component).Controls[I]); 151 end; 136 152 137 153 if Component is TControl then begin … … 139 155 if (Control is TEdit) or (Control is TSpinEdit) or (Control is TComboBox) and 140 156 (Control is TMemo) or (Control is TListView) or (Control is TCustomDrawGrid) or 141 (Control is TCheckBox) then begin157 (Control is TCheckBox) or (Control is TPageControl) or (Control is TRadioButton) then begin 142 158 Control.Color := FTheme.ColorWindow; 143 159 Control.Font.Color := FTheme.ColorWindowText; … … 151 167 (Control as TCustomDrawGrid).Editor.Font.Color := FTheme.ColorWindowText; 152 168 end; 169 170 if Control is TPageControl then begin 171 for I := 0 to TPageControl(Component).PageCount - 1 do 172 ApplyTheme(TPageControl(Component).Pages[I]); 173 end; 174 175 if Control is TCoolBar then begin 176 (Control as TCoolBar).Themed := False; 177 end; 153 178 end; 154 179 end; … … 156 181 procedure TThemeManager.UseTheme(Form: TForm); 157 182 begin 158 if not Used and (FTheme.Name = 'System') then Exit;183 if not Used and (FTheme.Name = ThemeNameSystem) then Exit; 159 184 ApplyTheme(Form); 160 185 Used := True;
Note:
See TracChangeset
for help on using the changeset viewer.