FreeLaunch
423 строки · 14.5 Кб
1{
2##########################################################################
3# FreeLaunch is a free links manager for Microsoft Windows #
4# #
5# Copyright (C) 2023 Alexey Tatuyko <feedback@ta2i4.ru> #
6# Copyright (C) 2019 Mykola Petrivskiy #
7# Copyright (C) 2010 Joker-jar <joker-jar@yandex.ru> #
8# #
9# This file is part of FreeLaunch. #
10# #
11# FreeLaunch is free software: you can redistribute it and/or modify #
12# it under the terms of the GNU General Public License as published by #
13# the Free Software Foundation, either version 3 of the License, or #
14# (at your option) any later version. #
15# #
16# FreeLaunch is distributed in the hope that it will be useful, #
17# but WITHOUT ANY WARRANTY; without even the implied warranty of #
18# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
19# GNU General Public License for more details. #
20# #
21# You should have received a copy of the GNU General Public License #
22# along with FreeLaunch. If not, see <http://www.gnu.org/licenses/>. #
23##########################################################################
24}
25
26unit SettingsFormModule;
27
28interface
29
30uses
31Winapi.Windows, Winapi.Messages,
32System.SysUtils, System.Variants, System.Classes, System.IniFiles,
33System.Math,
34Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
35Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.Menus, Vcl.Samples.Spin,
36FLLanguage, FLFunctions;
37
38type
39TSettingsForm = class(TForm)
40pgc: TPageControl;
41TabGeneral: TTabSheet;
42OKButton: TButton;
43CancelButton: TButton;
44lblNumofTabs: TLabel;
45lblNumofRows: TLabel;
46lblNumofCols: TLabel;
47AutorunCheckBox: TCheckBox;
48TopCheckBox: TCheckBox;
49lblWndTitle: TLabel;
50TBarBox: TComboBox;
51lblTabStyle: TLabel;
52TabsBox: TComboBox;
53lblPadding: TLabel;
54ReloadIconsButton: TButton;
55lblBtnW: TLabel;
56lblBtnH: TLabel;
57StartHideBox: TCheckBox;
58lblLang: TLabel;
59LanguagesBox: TComboBox;
60StatusBarBox: TCheckBox;
61PaddingEdit: TSpinEdit;
62ColsEdit: TSpinEdit;
63RowsEdit: TSpinEdit;
64TabsEdit: TSpinEdit;
65IWEdit: TSpinEdit;
66IHEdit: TSpinEdit;
67TabInterface: TTabSheet;
68grpBtnSize: TGroupBox;
69TabNewButtons: TTabSheet;
70grpNewBtns: TGroupBox;
71HideCheckBox: TCheckBox;
72QoLCheckBox: TCheckBox;
73DelLnkCheckBox: TCheckBox;
74DateTimeBox: TCheckBox;
75WSBox: TComboBox;
76lblWState: TLabel;
77AdminCheckBox: TCheckBox;
78lblPriority: TLabel;
79PriorityBox: TComboBox;
80DropCheckBox: TCheckBox;
81GlassCheckBox: TCheckBox;
82ClearCheckBox: TCheckBox;
83ThemesBox: TComboBox;
84lblTheme: TLabel;
85ApplyButton: TButton;
86ABlendCheckBox: TCheckBox;
87ABlendBar: TTrackBar;
88ABOffCheckBox: TCheckBox;
89TaskBarBox: TCheckBox;
90procedure OKButtonClick(Sender: TObject);
91procedure CancelButtonClick(Sender: TObject);
92procedure FormShow(Sender: TObject);
93procedure ReloadIconsButtonClick(Sender: TObject);
94procedure FormCreate(Sender: TObject);
95procedure FormClose(Sender: TObject; var Action: TCloseAction);
96procedure LanguagesBoxDrawItem(Control: TWinControl; Index: Integer;
97Rect: TRect; State: TOwnerDrawState);
98procedure StatusBarBoxClick(Sender: TObject);
99procedure ApplyButtonClick(Sender: TObject);
100procedure pgcChange(Sender: TObject);
101procedure ABlendCheckBoxClick(Sender: TObject);
102procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
103public
104Langs: array of TLngInfo;
105LngFiles: array of string;
106NoPopup: TPopupMenu;
107procedure ApplyLanguage;
108procedure ApplySettings;
109procedure ProcLanguage(FileName: string);
110procedure ScanLanguagesDir;
111end;
112
113implementation
114
115uses
116FLaunchMainFormModule;
117
118{$R *.dfm}
119
120procedure TSettingsForm.ApplyLanguage;
121var
122I: Integer;
123begin
124PriorityBox.Items.Clear;
125TabsBox.Items.Clear;
126TBarBox.Items.Clear;
127ThemesBox.Items.Clear;
128WSBox.Items.Clear;
129OKButton.Caption := Language.BtnOk;
130CancelButton.Caption := Language.BtnCancel;
131ApplyButton.Caption := Language.BtnApply;
132TabGeneral.Caption := Language.Settings.General;
133TabInterface.Caption := Language.Settings.GUIProperties;
134TabNewButtons.Caption := Language.Settings.BtnProperties;
135Caption := Language.Settings.Caption;
136lblNumofTabs.Caption := Language.Settings.NumOfTabs + ':';
137lblNumofRows.Caption := Language.Settings.Rows + ':';
138lblNumofCols.Caption := Language.Settings.Cols + ':';
139lblPadding.Caption := Language.Settings.Padding + ':';
140AutorunCheckBox.Caption := Language.Settings.ChbAutorun;
141TopCheckBox.Caption := Language.Settings.ChbAlwaysOnTop;
142TaskBarBox.Caption := Language.Settings.ChbTaskbar;
143StartHideBox.Caption := Language.Settings.ChbStartHide;
144StatusBarBox.Caption := Language.Settings.ChbStatusbar;
145DateTimeBox.Caption := Language.Settings.ChbDateTime;
146HideCheckBox.Caption := Language.Settings.ChbHideAL;
147QoLCheckBox.Caption := Language.Settings.ChbQoL;
148DelLnkCheckBox.Caption := Language.Settings.ChbDelLnk;
149AdminCheckBox.Caption := Language.Settings.ChbAdmin;
150DropCheckBox.Caption := Language.Settings.ChbDrop;
151GlassCheckBox.Caption := Language.Settings.ChbGlass;
152ClearCheckBox.Caption := Language.Settings.ChbClear;
153ABlendCheckBox.Caption := Language.Settings.ChbAlphaBlend + ':';
154ABOffCheckBox.Caption := Language.Settings.ChbABOff;
155lblLang.Caption := Language.Settings.Language + ':';
156lblWndTitle.Caption := Language.Settings.Titlebar + ':';
157lblTabStyle.Caption := Language.Settings.TabStyle + ':';
158grpBtnSize.Caption := Language.Settings.BtnSizes;
159lblBtnW.Caption := Language.Settings.BtnWidth + ':';
160lblBtnH.Caption := Language.Settings.BtnHeight + ':';
161lblWState.Caption := Language.Settings.WState + ':';
162lblPriority.Caption := Language.Settings.Priority + ':';
163lblTheme.Caption := Language.Settings.Theme + ':';
164ReloadIconsButton.Caption := Language.Settings.ReloadIcons;
165grpNewBtns.Caption := Language.Settings.NewBtnProperties;
166PriorityBox.Items.Add(Language.Settings.PriorityNormal);
167PriorityBox.Items.Add(Language.Settings.PriorityHigh);
168PriorityBox.Items.Add(Language.Settings.PriorityIdle);
169PriorityBox.Items.Add(Language.Settings.PriorityRealTime);
170PriorityBox.Items.Add(Language.Settings.PriorityBelowNormal);
171PriorityBox.Items.Add(Language.Settings.PriorityAboveNormal);
172TabsBox.Items.Add(Language.Settings.TabStylePages);
173TabsBox.Items.Add(Language.Settings.TabStyleButtons);
174TabsBox.Items.Add(Language.Settings.TabStyleFButtons);
175TBarBox.Items.Add(Language.Settings.TitlebarNormal);
176TBarBox.Items.Add(Language.Settings.TitlebarMini);
177TBarBox.Items.Add(Language.Settings.TitlebarHidden);
178WSBox.Items.Add(Language.Settings.WSNormal);
179WSBox.Items.Add(Language.Settings.WSMax);
180WSBox.Items.Add(Language.Settings.WSMin);
181WSBox.Items.Add(Language.Settings.WSHidden);
182for i := Low(FLThemes) to High(FLThemes)
183do ThemesBox.Items.Add(FLThemes[i].NameForGUI);
184PriorityBox.ItemIndex := PriorDef;
185TabsBox.ItemIndex := tabsview;
186TBarBox.ItemIndex := titlebar;
187ThemesBox.ItemIndex := CurrAppTheme;
188WSBox.ItemIndex := WStateDef;
189end;
190
191procedure TSettingsForm.ApplySettings;
192var
193tabnum: integer;
194begin
195ChPos := True;
196FlaunchMainForm.ChWinView(False);
197Autorun := AutorunCheckBox.Checked;
198AlwaysOnTop := TopCheckBox.Checked;
199StartHide := StartHideBox.Checked;
200StatusBarVis := StatusBarBox.Checked;
201taskbarvis := TaskBarBox.Checked;
202dtimeinstbar := DateTimeBox.Checked;
203hideafterlaunch := HideCheckBox.Checked;
204queryonlaunch := QoLCheckBox.Checked;
205deletelnk := DelLnkCheckBox.Checked;
206rwar := AdminCheckBox.Checked;
207defdrop := DropCheckBox.Checked;
208nobgnotabs := GlassCheckBox.Checked;
209ClearONF := ClearCheckBox.Checked;
210ABlend := ABlendCheckBox.Checked;
211ABOffOnHover := ABOffCheckBox.Checked;
212ABlendVal := 255 - Round(2.55 * ABlendBar.Position);
213WStateDef := WSBox.ItemIndex;
214PriorDef := PriorityBox.ItemIndex;
215CurrAppTheme := ThemesBox.ItemIndex;
216FlaunchMainForm.SetAutorun(Autorun);
217if LanguagesBox.ItemIndex >= 0 then
218lngfilename := LngFiles[LanguagesBox.ItemIndex];
219tabsview := TabsBox.ItemIndex;
220titlebar := TBarBox.ItemIndex;
221//FlaunchMainForm.MainTabs.SetFocus;
222tabnum := FlaunchMainForm.MainTabsNew.TabIndex;
223tabscount := TabsEdit.Value;
224rowscount := RowsEdit.Value;
225colscount := ColsEdit.Value;
226lpadding := PaddingEdit.Value;
227FlaunchMainForm.GrowTabNames(tabscount);
228FlaunchMainForm.SetTabNames;
229FlaunchMainForm.FLPanel.ColsCount := colscount;
230FlaunchMainForm.FLPanel.RowsCount := rowscount;
231if (ButtonWidth <> IWEdit.Value) or (ButtonHeight <> IHEdit.Value)
232then
233begin
234ButtonWidth := IWEdit.Value;
235ButtonHeight := IHEdit.Value;
236FlaunchMainForm.FLPanel.ButtonWidth := ButtonWidth;
237FlaunchMainForm.FLPanel.ButtonHeight := ButtonHeight;
238FlaunchMainForm.ReloadIcons;
239end;
240FlaunchMainForm.FLPanel.Padding := lpadding;
241if tabnum < tabscount then
242FlaunchMainForm.MainTabsNew.TabIndex := tabnum
243else
244FlaunchMainForm.MainTabsNew.TabIndex := 0;
245Language.Load(lngfilename);
246FlaunchMainForm.GenerateWnd;
247FlaunchMainForm.ChWinView(true);
248ChPos := False;
249end;
250
251procedure TSettingsForm.ProcLanguage(FileName: string);
252var
253lngfile: TIniFile;
254LangCount: Integer;
255begin
256lngfile := TIniFile.Create(FileName);
257try
258LangCount := Length(Langs);
259SetLength(Langs, LangCount + 1);
260SetLength(LngFiles, LangCount + 1);
261LngFiles[LangCount] := ExtractFileName(FileName);
262Langs[LangCount].Load(lngfile);
263LanguagesBox.Items.Add(Langs[LangCount].Name);
264if Language.Info.Name = Langs[LangCount].Name then
265LanguagesBox.ItemIndex := Pred(LanguagesBox.Items.Count);
266finally
267lngfile.Free;
268end;
269end;
270
271procedure TSettingsForm.ScanLanguagesDir;
272var
273SearchRec: TSearchRec;
274Dir: string;
275begin
276LanguagesBox.Clear;
277Dir := ExtractFilePath(ParamStr(0)) + 'languages\';
278if FindFirst(Dir + '*.*', faAnyFile, SearchRec) = 0 then
279repeat
280if (SearchRec.name = '.') or (SearchRec.name = '..') then
281continue;
282if (extractfileext(SearchRec.name).ToLower = '.lng') then
283ProcLanguage(Dir + SearchRec.name);
284until
285FindNext(SearchRec) <> 0;
286FindClose(SearchRec);
287LanguagesBox.Enabled := LanguagesBox.Items.Count > 0;
288end;
289
290procedure TSettingsForm.StatusBarBoxClick(Sender: TObject);
291begin
292DateTimeBox.Enabled := StatusBarBox.Checked;
293end;
294
295procedure TSettingsForm.ReloadIconsButtonClick(Sender: TObject);
296begin
297FlaunchMainForm.ReloadIcons;
298end;
299
300procedure TSettingsForm.CancelButtonClick(Sender: TObject);
301begin
302Close;
303end;
304
305procedure TSettingsForm.LanguagesBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
306var
307Multiplier: Double;
308FlagRect: TRect;
309Image: TBitmap;
310begin
311Image := Langs[Index].Image;
312Multiplier := (Rect.Height - 4) / Image.Height;
313FlagRect.Left := Rect.Left + 2;
314FlagRect.Top := Rect.Top + 2;
315FlagRect.Height := Rect.Height - 4;
316FlagRect.Width := Round(Image.Width * Multiplier);
317LanguagesBox.Canvas.fillrect(rect);
318LanguagesBox.Canvas.StretchDraw(FlagRect, Image);
319LanguagesBox.Canvas.textout(rect.left + FlagRect.Width + 4, rect.top + 2,
320LanguagesBox.items[index]);
321end;
322
323procedure TSettingsForm.FormClose(Sender: TObject; var Action: TCloseAction);
324var
325i: integer;
326begin
327NoPopup.Free;
328for i := 0 to high(Langs) do
329Langs[i].Image.Free;
330SetLength(Langs, 0);
331settingsshowing := false;
332action := CAFree;
333end;
334
335procedure TSettingsForm.FormCreate(Sender: TObject);
336begin
337NoPopup := TPopupMenu.Create(nil);
338TabsEdit.PopupMenu := NoPopup;
339RowsEdit.PopupMenu := NoPopup;
340ColsEdit.PopupMenu := NoPopup;
341PaddingEdit.PopupMenu := NoPopup;
342IWEdit.PopupMenu := NoPopup;
343IHEdit.PopupMenu := NoPopup;
344TabsEdit.MaxValue := TabsCountMax;
345PaddingEdit.MaxValue := PaddingMax;
346RowsEdit.MaxValue := RowsCountMax;
347ColsEdit.MaxValue := ColsCountMax;
348IWEdit.MinValue := MinIconParam;
349IWEdit.MaxValue := MaxIconParam;
350IWEdit.MinValue := MinIconParam;
351IWEdit.MaxValue := MaxIconParam;
352end;
353
354procedure TSettingsForm.FormKeyDown(Sender: TObject; var Key: Word;
355Shift: TShiftState);
356begin
357if (Key = VK_RETURN) and (ssCtrl in Shift) then OKButton.Click;
358end;
359
360procedure TSettingsForm.FormShow(Sender: TObject);
361begin
362if AlwaysOnTop then FormStyle := fsStayOnTop;
363ApplyLanguage;
364settingsshowing := true;
365ScanLanguagesDir;
366AutorunCheckBox.Checked := (not IsPortable) and (Autorun);
367TopCheckBox.Checked := AlwaysOnTop;
368StartHideBox.Checked := StartHide;
369StatusBarBox.Checked := StatusBarVis;
370TaskBarBox.Checked := taskbarvis;
371DateTimeBox.Checked := dtimeinstbar;
372DateTimeBox.Enabled := StatusBarBox.Checked;
373GlassCheckBox.Checked := nobgnotabs;
374ClearCheckBox.Checked := ClearONF;
375ABlendCheckBox.Checked := ABlend;
376ABOffCheckBox.Checked := ABOffOnHover;
377ABOffCheckBox.Enabled := ABlendCheckBox.Checked;
378ABlendBar.Enabled := ABlendCheckBox.Checked;
379ABlendBar.Position := Round((255 - ABlendVal) / 2.55);
380TabsEdit.MaxValue := TabsCountMax;
381TabsEdit.Value := tabscount;
382RowsEdit.MaxValue := RowsCountMax;
383RowsEdit.Value := rowscount;
384ColsEdit.MaxValue := ColsCountMax;
385ColsEdit.Value := colscount;
386PaddingEdit.Value := lpadding;
387IWEdit.Value := ButtonWidth;
388IHEdit.Value := ButtonHeight;
389HideCheckBox.Checked := hideafterlaunch;
390QoLCheckBox.Checked := queryonlaunch;
391DelLnkCheckBox.Checked := deletelnk;
392AdminCheckBox.Checked := rwar;
393DropCheckBox.Checked := defdrop;
394AutoRunCheckBox.Enabled := not IsPortable;
395pgc.ActivePageIndex := IfThen(lotabinsettings in [0..Pred(pgc.PageCount)],
396lotabinsettings, 0);
397pgc.ActivePage.SetFocus;
398end;
399
400procedure TSettingsForm.OKButtonClick(Sender: TObject);
401begin
402ApplySettings;
403Close;
404end;
405
406procedure TSettingsForm.ABlendCheckBoxClick(Sender: TObject);
407begin
408ABOffCheckBox.Enabled := ABlendCheckBox.Checked;
409ABlendBar.Enabled := ABlendCheckBox.Checked;
410end;
411
412procedure TSettingsForm.ApplyButtonClick(Sender: TObject);
413begin
414ApplySettings;
415ApplyLanguage;
416end;
417
418procedure TSettingsForm.pgcChange(Sender: TObject);
419begin
420lotabinsettings := pgc.ActivePageIndex;
421end;
422
423end.
424