Ignore:
Timestamp:
Mar 18, 2022, 1:37:03 PM (3 years ago)
Author:
chronos
Message:
  • Modified: Update Common package.
File:
1 edited

Legend:

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

    r122 r131  
    55uses
    66  Classes, SysUtils, Graphics, ComCtrls, Controls, ExtCtrls, Menus, StdCtrls,
    7   Spin, Forms, Contnrs, Grids;
     7  Spin, Forms, fgl, Grids;
    88
    99type
     
    1919  { TThemes }
    2020
    21   TThemes = class(TObjectList)
     21  TThemes = class(TFPGObjectList<TTheme>)
    2222    function AddNew(Name: string): TTheme;
    2323    function FindByName(Name: string): TTheme;
     
    4141    property Theme: TTheme read FTheme write SetTheme;
    4242  end;
     43
     44const
     45  ThemeNameSystem = 'System';
     46  ThemeNameLight = 'Light';
     47  ThemeNameDark = 'Dark';
    4348
    4449procedure Register;
     
    7479procedure TThemes.LoadToStrings(Strings: TStrings);
    7580var
    76   Theme: TTheme;
     81  I: Integer;
    7782begin
    78   Strings.Clear;
    79   for Theme in Self do
    80     Strings.AddObject(Theme.Name, Theme);
     83  Strings.BeginUpdate;
     84  try
     85    while Strings.Count < Count do Strings.Add('');
     86    while Strings.Count > Count do Strings.Delete(Strings.Count - 1);
     87    for I := 0 to Count - 1 do begin
     88      Strings[I] := Items[I].Name;
     89      Strings.Objects[I] := Items[I];
     90    end;
     91  finally
     92    Strings.EndUpdate;
     93  end;
    8194end;
    8295
     
    97110  inherited;
    98111  Themes := TThemes.Create;
    99   with Themes.AddNew('System') do begin
     112  with Themes.AddNew(ThemeNameSystem) do begin
    100113    ColorWindow := clWindow;
    101114    ColorWindowText := clWindowText;
     
    105118  end;
    106119  Theme := TTheme(Themes.First);
    107   with Themes.AddNew('Dark') do begin
     120  with Themes.AddNew(ThemeNameDark) do begin
    108121    ColorWindow := RGBToColor($20, $20, $20);
    109122    ColorWindowText := clWhite;
     
    112125    ColorControlSelected := RGBToColor(96, 125, 155);
    113126  end;
    114   with Themes.AddNew('Light') do begin
     127  with Themes.AddNew(ThemeNameLight) do begin
    115128    ColorWindow := clWhite;
    116129    ColorWindowText := clBlack;
     
    123136destructor TThemeManager.Destroy;
    124137begin
    125   Themes.Free;
    126   inherited Destroy;
     138  FreeAndNil(Themes);
     139  inherited;
    127140end;
    128141
     
    167180procedure TThemeManager.UseTheme(Form: TForm);
    168181begin
    169   if not Used and (FTheme.Name = 'System') then Exit;
     182  if not Used and (FTheme.Name = ThemeNameSystem) then Exit;
    170183  ApplyTheme(Form);
    171184  Used := True;
Note: See TracChangeset for help on using the changeset viewer.