Ignore:
Timestamp:
Sep 10, 2022, 6:54:43 PM (20 months ago)
Author:
chronos
Message:
  • Modified: CoolTranslator replaced by Common package.
  • Modified: Update common package.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/Common/UTheme.pas

    r16 r25  
    55uses
    66  Classes, SysUtils, Graphics, ComCtrls, Controls, ExtCtrls, Menus, StdCtrls,
    7   Spin, Forms, Contnrs, Grids;
     7  Spin, Forms, Generics.Collections, Grids;
    88
    99type
     
    1919  { TThemes }
    2020
    21   TThemes = class(TObjectList)
     21  TThemes = class(TObjectList<TTheme>)
    2222    function AddNew(Name: string): TTheme;
    2323    function FindByName(Name: string): TTheme;
     
    4242  end;
    4343
     44const
     45  ThemeNameSystem = 'System';
     46  ThemeNameLight = 'Light';
     47  ThemeNameDark = 'Dark';
     48
    4449procedure Register;
     50
    4551
    4652implementation
     
    7480procedure TThemes.LoadToStrings(Strings: TStrings);
    7581var
    76   Theme: TTheme;
     82  I: Integer;
    7783begin
    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;
    8195end;
    8296
     
    97111  inherited;
    98112  Themes := TThemes.Create;
    99   with Themes.AddNew('System') do begin
     113  with Themes.AddNew(ThemeNameSystem) do begin
    100114    ColorWindow := clWindow;
    101115    ColorWindowText := clWindowText;
     
    105119  end;
    106120  Theme := TTheme(Themes.First);
    107   with Themes.AddNew('Dark') do begin
     121  with Themes.AddNew(ThemeNameDark) do begin
    108122    ColorWindow := RGBToColor($20, $20, $20);
    109123    ColorWindowText := clWhite;
     
    112126    ColorControlSelected := RGBToColor(96, 125, 155);
    113127  end;
    114   with Themes.AddNew('Light') do begin
     128  with Themes.AddNew(ThemeNameLight) do begin
    115129    ColorWindow := clWhite;
    116130    ColorWindowText := clBlack;
     
    123137destructor TThemeManager.Destroy;
    124138begin
    125   Themes.Free;
    126   inherited Destroy;
     139  FreeAndNil(Themes);
     140  inherited;
    127141end;
    128142
     
    132146  I: Integer;
    133147begin
    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;
    136152
    137153  if Component is TControl then begin
     
    139155    if (Control is TEdit) or (Control is TSpinEdit) or (Control is TComboBox) and
    140156    (Control is TMemo) or (Control is TListView) or (Control is TCustomDrawGrid) or
    141     (Control is TCheckBox) then begin
     157    (Control is TCheckBox) or (Control is TPageControl) or (Control is TRadioButton) then begin
    142158      Control.Color := FTheme.ColorWindow;
    143159      Control.Font.Color := FTheme.ColorWindowText;
     
    151167      (Control as TCustomDrawGrid).Editor.Font.Color := FTheme.ColorWindowText;
    152168    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;
    153178  end;
    154179end;
     
    156181procedure TThemeManager.UseTheme(Form: TForm);
    157182begin
    158   if not Used and (FTheme.Name = 'System') then Exit;
     183  if not Used and (FTheme.Name = ThemeNameSystem) then Exit;
    159184  ApplyTheme(Form);
    160185  Used := True;
Note: See TracChangeset for help on using the changeset viewer.