1 | unit FormEx;
|
---|
2 |
|
---|
3 | interface
|
---|
4 |
|
---|
5 | uses
|
---|
6 | Classes, SysUtils, Forms, PersistentForm, Theme, Translator, ScaleDPI;
|
---|
7 |
|
---|
8 | type
|
---|
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 |
|
---|
33 | procedure Register;
|
---|
34 |
|
---|
35 |
|
---|
36 | implementation
|
---|
37 |
|
---|
38 | procedure Register;
|
---|
39 | begin
|
---|
40 | RegisterNoIcon([TFormEx]);
|
---|
41 | end;
|
---|
42 |
|
---|
43 | { TFormEx }
|
---|
44 |
|
---|
45 | procedure TFormEx.DoShow;
|
---|
46 | begin
|
---|
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 | end;
|
---|
53 | end;
|
---|
54 |
|
---|
55 | procedure TFormEx.DoCreate;
|
---|
56 | begin
|
---|
57 | if not Assigned(PersistentForm) then begin
|
---|
58 | OwnsPersistentForm := True;
|
---|
59 | PersistentForm := TPersistentForm.Create(nil);
|
---|
60 | end;
|
---|
61 | if not Assigned(ThemeManager) then begin
|
---|
62 | OwnsThemeManager := True;
|
---|
63 | ThemeManager := TThemeManager.Create(nil);
|
---|
64 | end;
|
---|
65 | if not Assigned(Translator) then begin
|
---|
66 | Translator := TTranslator.Create(nil);
|
---|
67 | Translator.POFilesFolder := 'Languages';
|
---|
68 | Translator.Language := Translator.Languages.SearchByCode('');
|
---|
69 | OwnsTranslator := True;
|
---|
70 | end;
|
---|
71 | if not Assigned(ScaleDPI) then begin
|
---|
72 | OwnsScaleDPI := True;
|
---|
73 | ScaleDPI := TScaleDPI.Create(nil);
|
---|
74 | end;
|
---|
75 |
|
---|
76 | Translator.TranslateComponentRecursive(Self);
|
---|
77 | ThemeManager.UseTheme(Self);
|
---|
78 | Inc(FCounter);
|
---|
79 | inherited;
|
---|
80 | end;
|
---|
81 |
|
---|
82 | procedure TFormEx.DoClose(var CloseAction: TCloseAction);
|
---|
83 | begin
|
---|
84 | if (not (csDesigning in ComponentState)) then begin
|
---|
85 | PersistentForm.FormFullScreen := FullScreen;
|
---|
86 | PersistentForm.Save(Self);
|
---|
87 | end;
|
---|
88 | inherited;
|
---|
89 | end;
|
---|
90 |
|
---|
91 | procedure TFormEx.DoDestroy;
|
---|
92 | begin
|
---|
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;
|
---|
113 | end;
|
---|
114 |
|
---|
115 | end.
|
---|
116 |
|
---|