source: trunk/Packages/Common/FormEx.pas

Last change on this file was 341, checked in by chronos, 37 hours ago
  • Modified: Improved dark theme support on Windows.
File size: 2.5 KB
Line 
1unit FormEx;
2
3interface
4
5uses
6 Classes, SysUtils, Forms, PersistentForm, Theme, Translator, ScaleDPI;
7
8type
9
10 { TFormEx }
11
12 TFormEx = class(TForm)
13 private
14 FCounter: Integer; static;
15 FFirstShow: Boolean;
16 protected
17 procedure DoShow; override;
18 procedure DoCreate; override;
19 procedure DoClose(var CloseAction: TCloseAction); override;
20 procedure DoDestroy; override;
21 public
22 FullScreen: Boolean;
23 PersistentForm: TPersistentForm; static;
24 ThemeManager: TThemeManager; static;
25 Translator: TTranslator; static;
26 ScaleDPI: TScaleDPI; static;
27 OwnsPersistentForm: Boolean; static;
28 OwnsThemeManager: Boolean; static;
29 OwnsTranslator: Boolean; static;
30 OwnsScaleDPI: Boolean; static;
31 end;
32
33procedure Register;
34
35
36implementation
37
38procedure Register;
39begin
40 RegisterNoIcon([TFormEx]);
41end;
42
43{ TFormEx }
44
45procedure TFormEx.DoShow;
46begin
47 inherited;
48 if not FFirstShow and (not (csDesigning in ComponentState)) then begin
49 FFirstShow := True;
50 PersistentForm.Load(Self);
51 FullScreen := PersistentForm.FormFullScreen;
52 ThemeManager.UseTheme(Self);
53 end;
54end;
55
56procedure TFormEx.DoCreate;
57begin
58 if not Assigned(PersistentForm) then begin
59 OwnsPersistentForm := True;
60 PersistentForm := TPersistentForm.Create(nil);
61 end;
62 if not Assigned(ThemeManager) then begin
63 OwnsThemeManager := True;
64 ThemeManager := TThemeManager.Create(nil);
65 end;
66 if not Assigned(Translator) then begin
67 Translator := TTranslator.Create(nil);
68 Translator.POFilesFolder := 'Languages';
69 Translator.Language := Translator.Languages.SearchByCode('');
70 OwnsTranslator := True;
71 end;
72 if not Assigned(ScaleDPI) then begin
73 OwnsScaleDPI := True;
74 ScaleDPI := TScaleDPI.Create(nil);
75 end;
76
77 Translator.TranslateComponentRecursive(Self);
78 Inc(FCounter);
79 inherited;
80end;
81
82procedure TFormEx.DoClose(var CloseAction: TCloseAction);
83begin
84 if (not (csDesigning in ComponentState)) then begin
85 PersistentForm.FormFullScreen := FullScreen;
86 PersistentForm.Save(Self);
87 end;
88 inherited;
89end;
90
91procedure TFormEx.DoDestroy;
92begin
93 Dec(FCounter);
94 if FCounter <= 0 then begin
95 if OwnsPersistentForm then begin
96 FreeAndNil(PersistentForm);
97 OwnsPersistentForm := False;
98 end;
99 if OwnsThemeManager then begin
100 FreeAndNil(ThemeManager);
101 OwnsThemeManager := False;
102 end;
103 if OwnsTranslator then begin
104 FreeAndNil(Translator);
105 OwnsTranslator := False;
106 end;
107 if OwnsScaleDPI then begin
108 FreeAndNil(ScaleDPI);
109 OwnsScaleDPI := False;
110 end;
111 end;
112 inherited;
113end;
114
115end.
116
Note: See TracBrowser for help on using the repository browser.