Ignore:
Timestamp:
Jun 7, 2024, 11:59:43 AM (5 months ago)
Author:
chronos
Message:
  • Modified: Updated Common package.
File:
1 moved

Legend:

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

    r84 r85  
    1 unit UTheme;
     1unit Theme;
    22
    33interface
     
    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
     
    167181procedure TThemeManager.UseTheme(Form: TForm);
    168182begin
    169   if not Used and (FTheme.Name = 'System') then Exit;
     183  if not Used and (FTheme.Name = ThemeNameSystem) then Exit;
    170184  ApplyTheme(Form);
    171185  Used := True;
    172186end;
    173187
    174 
    175188end.
Note: See TracChangeset for help on using the changeset viewer.