FreeLaunch

Форк
0
/
SettingsFormModule.pas 
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

26
unit SettingsFormModule;
27

28
interface
29

30
uses
31
  Winapi.Windows, Winapi.Messages,
32
  System.SysUtils, System.Variants, System.Classes, System.IniFiles,
33
  System.Math,
34
  Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls,
35
  Vcl.ComCtrls, Vcl.ExtCtrls, Vcl.Menus, Vcl.Samples.Spin,
36
  FLLanguage, FLFunctions;
37

38
type
39
  TSettingsForm = class(TForm)
40
    pgc: TPageControl;
41
    TabGeneral: TTabSheet;
42
    OKButton: TButton;
43
    CancelButton: TButton;
44
    lblNumofTabs: TLabel;
45
    lblNumofRows: TLabel;
46
    lblNumofCols: TLabel;
47
    AutorunCheckBox: TCheckBox;
48
    TopCheckBox: TCheckBox;
49
    lblWndTitle: TLabel;
50
    TBarBox: TComboBox;
51
    lblTabStyle: TLabel;
52
    TabsBox: TComboBox;
53
    lblPadding: TLabel;
54
    ReloadIconsButton: TButton;
55
    lblBtnW: TLabel;
56
    lblBtnH: TLabel;
57
    StartHideBox: TCheckBox;
58
    lblLang: TLabel;
59
    LanguagesBox: TComboBox;
60
    StatusBarBox: TCheckBox;
61
    PaddingEdit: TSpinEdit;
62
    ColsEdit: TSpinEdit;
63
    RowsEdit: TSpinEdit;
64
    TabsEdit: TSpinEdit;
65
    IWEdit: TSpinEdit;
66
    IHEdit: TSpinEdit;
67
    TabInterface: TTabSheet;
68
    grpBtnSize: TGroupBox;
69
    TabNewButtons: TTabSheet;
70
    grpNewBtns: TGroupBox;
71
    HideCheckBox: TCheckBox;
72
    QoLCheckBox: TCheckBox;
73
    DelLnkCheckBox: TCheckBox;
74
    DateTimeBox: TCheckBox;
75
    WSBox: TComboBox;
76
    lblWState: TLabel;
77
    AdminCheckBox: TCheckBox;
78
    lblPriority: TLabel;
79
    PriorityBox: TComboBox;
80
    DropCheckBox: TCheckBox;
81
    GlassCheckBox: TCheckBox;
82
    ClearCheckBox: TCheckBox;
83
    ThemesBox: TComboBox;
84
    lblTheme: TLabel;
85
    ApplyButton: TButton;
86
    ABlendCheckBox: TCheckBox;
87
    ABlendBar: TTrackBar;
88
    ABOffCheckBox: TCheckBox;
89
    TaskBarBox: TCheckBox;
90
    procedure OKButtonClick(Sender: TObject);
91
    procedure CancelButtonClick(Sender: TObject);
92
    procedure FormShow(Sender: TObject);
93
    procedure ReloadIconsButtonClick(Sender: TObject);
94
    procedure FormCreate(Sender: TObject);
95
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
96
    procedure LanguagesBoxDrawItem(Control: TWinControl; Index: Integer;
97
      Rect: TRect; State: TOwnerDrawState);
98
    procedure StatusBarBoxClick(Sender: TObject);
99
    procedure ApplyButtonClick(Sender: TObject);
100
    procedure pgcChange(Sender: TObject);
101
    procedure ABlendCheckBoxClick(Sender: TObject);
102
    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
103
  public
104
    Langs: array of TLngInfo;
105
    LngFiles: array of string;
106
    NoPopup: TPopupMenu;
107
    procedure ApplyLanguage;
108
    procedure ApplySettings;
109
    procedure ProcLanguage(FileName: string);
110
    procedure ScanLanguagesDir;
111
  end;
112

113
implementation
114

115
uses
116
  FLaunchMainFormModule;
117

118
{$R *.dfm}
119

120
procedure TSettingsForm.ApplyLanguage;
121
var
122
  I: Integer;
123
begin
124
  PriorityBox.Items.Clear;
125
  TabsBox.Items.Clear;
126
  TBarBox.Items.Clear;
127
  ThemesBox.Items.Clear;
128
  WSBox.Items.Clear;
129
  OKButton.Caption := Language.BtnOk;
130
  CancelButton.Caption := Language.BtnCancel;
131
  ApplyButton.Caption := Language.BtnApply;
132
  TabGeneral.Caption := Language.Settings.General;
133
  TabInterface.Caption := Language.Settings.GUIProperties;
134
  TabNewButtons.Caption := Language.Settings.BtnProperties;
135
  Caption := Language.Settings.Caption;
136
  lblNumofTabs.Caption := Language.Settings.NumOfTabs + ':';
137
  lblNumofRows.Caption := Language.Settings.Rows + ':';
138
  lblNumofCols.Caption := Language.Settings.Cols + ':';
139
  lblPadding.Caption := Language.Settings.Padding + ':';
140
  AutorunCheckBox.Caption := Language.Settings.ChbAutorun;
141
  TopCheckBox.Caption := Language.Settings.ChbAlwaysOnTop;
142
  TaskBarBox.Caption := Language.Settings.ChbTaskbar;
143
  StartHideBox.Caption := Language.Settings.ChbStartHide;
144
  StatusBarBox.Caption := Language.Settings.ChbStatusbar;
145
  DateTimeBox.Caption := Language.Settings.ChbDateTime;
146
  HideCheckBox.Caption := Language.Settings.ChbHideAL;
147
  QoLCheckBox.Caption := Language.Settings.ChbQoL;
148
  DelLnkCheckBox.Caption := Language.Settings.ChbDelLnk;
149
  AdminCheckBox.Caption := Language.Settings.ChbAdmin;
150
  DropCheckBox.Caption := Language.Settings.ChbDrop;
151
  GlassCheckBox.Caption := Language.Settings.ChbGlass;
152
  ClearCheckBox.Caption := Language.Settings.ChbClear;
153
  ABlendCheckBox.Caption := Language.Settings.ChbAlphaBlend + ':';
154
  ABOffCheckBox.Caption := Language.Settings.ChbABOff;
155
  lblLang.Caption := Language.Settings.Language + ':';
156
  lblWndTitle.Caption := Language.Settings.Titlebar + ':';
157
  lblTabStyle.Caption := Language.Settings.TabStyle + ':';
158
  grpBtnSize.Caption := Language.Settings.BtnSizes;
159
  lblBtnW.Caption := Language.Settings.BtnWidth + ':';
160
  lblBtnH.Caption := Language.Settings.BtnHeight + ':';
161
  lblWState.Caption := Language.Settings.WState + ':';
162
  lblPriority.Caption := Language.Settings.Priority + ':';
163
  lblTheme.Caption := Language.Settings.Theme + ':';
164
  ReloadIconsButton.Caption := Language.Settings.ReloadIcons;
165
  grpNewBtns.Caption := Language.Settings.NewBtnProperties;
166
  PriorityBox.Items.Add(Language.Settings.PriorityNormal);
167
  PriorityBox.Items.Add(Language.Settings.PriorityHigh);
168
  PriorityBox.Items.Add(Language.Settings.PriorityIdle);
169
  PriorityBox.Items.Add(Language.Settings.PriorityRealTime);
170
  PriorityBox.Items.Add(Language.Settings.PriorityBelowNormal);
171
  PriorityBox.Items.Add(Language.Settings.PriorityAboveNormal);
172
  TabsBox.Items.Add(Language.Settings.TabStylePages);
173
  TabsBox.Items.Add(Language.Settings.TabStyleButtons);
174
  TabsBox.Items.Add(Language.Settings.TabStyleFButtons);
175
  TBarBox.Items.Add(Language.Settings.TitlebarNormal);
176
  TBarBox.Items.Add(Language.Settings.TitlebarMini);
177
  TBarBox.Items.Add(Language.Settings.TitlebarHidden);
178
  WSBox.Items.Add(Language.Settings.WSNormal);
179
  WSBox.Items.Add(Language.Settings.WSMax);
180
  WSBox.Items.Add(Language.Settings.WSMin);
181
  WSBox.Items.Add(Language.Settings.WSHidden);
182
  for i := Low(FLThemes) to High(FLThemes)
183
    do ThemesBox.Items.Add(FLThemes[i].NameForGUI);
184
  PriorityBox.ItemIndex := PriorDef;
185
  TabsBox.ItemIndex := tabsview;
186
  TBarBox.ItemIndex := titlebar;
187
  ThemesBox.ItemIndex := CurrAppTheme;
188
  WSBox.ItemIndex := WStateDef;
189
end;
190

191
procedure TSettingsForm.ApplySettings;
192
var
193
  tabnum: integer;
194
begin
195
  ChPos := True;
196
  FlaunchMainForm.ChWinView(False);
197
  Autorun := AutorunCheckBox.Checked;
198
  AlwaysOnTop := TopCheckBox.Checked;
199
  StartHide := StartHideBox.Checked;
200
  StatusBarVis := StatusBarBox.Checked;
201
  taskbarvis := TaskBarBox.Checked;
202
  dtimeinstbar := DateTimeBox.Checked;
203
  hideafterlaunch := HideCheckBox.Checked;
204
  queryonlaunch := QoLCheckBox.Checked;
205
  deletelnk := DelLnkCheckBox.Checked;
206
  rwar := AdminCheckBox.Checked;
207
  defdrop := DropCheckBox.Checked;
208
  nobgnotabs := GlassCheckBox.Checked;
209
  ClearONF := ClearCheckBox.Checked;
210
  ABlend := ABlendCheckBox.Checked;
211
  ABOffOnHover := ABOffCheckBox.Checked;
212
  ABlendVal := 255 - Round(2.55 * ABlendBar.Position);
213
  WStateDef := WSBox.ItemIndex;
214
  PriorDef := PriorityBox.ItemIndex;
215
  CurrAppTheme := ThemesBox.ItemIndex;
216
  FlaunchMainForm.SetAutorun(Autorun);
217
  if LanguagesBox.ItemIndex >= 0 then
218
    lngfilename := LngFiles[LanguagesBox.ItemIndex];
219
  tabsview := TabsBox.ItemIndex;
220
  titlebar := TBarBox.ItemIndex;
221
  //FlaunchMainForm.MainTabs.SetFocus;
222
  tabnum := FlaunchMainForm.MainTabsNew.TabIndex;
223
  tabscount := TabsEdit.Value;
224
  rowscount := RowsEdit.Value;
225
  colscount := ColsEdit.Value;
226
  lpadding := PaddingEdit.Value;
227
  FlaunchMainForm.GrowTabNames(tabscount);
228
  FlaunchMainForm.SetTabNames;
229
  FlaunchMainForm.FLPanel.ColsCount := colscount;
230
  FlaunchMainForm.FLPanel.RowsCount := rowscount;
231
  if (ButtonWidth <> IWEdit.Value) or (ButtonHeight <> IHEdit.Value)
232
  then
233
  begin
234
    ButtonWidth := IWEdit.Value;
235
    ButtonHeight := IHEdit.Value;
236
    FlaunchMainForm.FLPanel.ButtonWidth := ButtonWidth;
237
    FlaunchMainForm.FLPanel.ButtonHeight := ButtonHeight;
238
    FlaunchMainForm.ReloadIcons;
239
  end;
240
  FlaunchMainForm.FLPanel.Padding := lpadding;
241
  if tabnum < tabscount then
242
    FlaunchMainForm.MainTabsNew.TabIndex := tabnum
243
  else
244
    FlaunchMainForm.MainTabsNew.TabIndex := 0;
245
  Language.Load(lngfilename);
246
  FlaunchMainForm.GenerateWnd;
247
  FlaunchMainForm.ChWinView(true);
248
  ChPos := False;
249
end;
250

251
procedure TSettingsForm.ProcLanguage(FileName: string);
252
var
253
  lngfile: TIniFile;
254
  LangCount: Integer;
255
begin
256
  lngfile := TIniFile.Create(FileName);
257
  try
258
    LangCount := Length(Langs);
259
    SetLength(Langs, LangCount + 1);
260
    SetLength(LngFiles, LangCount + 1);
261
    LngFiles[LangCount] := ExtractFileName(FileName);
262
    Langs[LangCount].Load(lngfile);
263
    LanguagesBox.Items.Add(Langs[LangCount].Name);
264
    if Language.Info.Name = Langs[LangCount].Name then
265
      LanguagesBox.ItemIndex := Pred(LanguagesBox.Items.Count);
266
  finally
267
    lngfile.Free;
268
  end;
269
end;
270

271
procedure TSettingsForm.ScanLanguagesDir;
272
var
273
  SearchRec: TSearchRec;
274
  Dir: string;
275
begin
276
  LanguagesBox.Clear;
277
  Dir := ExtractFilePath(ParamStr(0)) + 'languages\';
278
  if FindFirst(Dir + '*.*', faAnyFile, SearchRec) = 0 then
279
    repeat
280
      if (SearchRec.name = '.') or (SearchRec.name = '..') then
281
        continue;
282
      if (extractfileext(SearchRec.name).ToLower = '.lng') then
283
        ProcLanguage(Dir + SearchRec.name);
284
    until
285
      FindNext(SearchRec) <> 0;
286
  FindClose(SearchRec);
287
  LanguagesBox.Enabled := LanguagesBox.Items.Count > 0;
288
end;
289

290
procedure TSettingsForm.StatusBarBoxClick(Sender: TObject);
291
begin
292
  DateTimeBox.Enabled := StatusBarBox.Checked;
293
end;
294

295
procedure TSettingsForm.ReloadIconsButtonClick(Sender: TObject);
296
begin
297
  FlaunchMainForm.ReloadIcons;
298
end;
299

300
procedure TSettingsForm.CancelButtonClick(Sender: TObject);
301
begin
302
  Close;
303
end;
304

305
procedure TSettingsForm.LanguagesBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
306
var
307
  Multiplier: Double;
308
  FlagRect: TRect;
309
  Image: TBitmap;
310
begin
311
  Image := Langs[Index].Image;
312
  Multiplier := (Rect.Height - 4) / Image.Height;
313
  FlagRect.Left := Rect.Left + 2;
314
  FlagRect.Top := Rect.Top + 2;
315
  FlagRect.Height := Rect.Height - 4;
316
  FlagRect.Width := Round(Image.Width * Multiplier);
317
  LanguagesBox.Canvas.fillrect(rect);
318
  LanguagesBox.Canvas.StretchDraw(FlagRect, Image);
319
  LanguagesBox.Canvas.textout(rect.left + FlagRect.Width + 4, rect.top + 2,
320
    LanguagesBox.items[index]);
321
end;
322

323
procedure TSettingsForm.FormClose(Sender: TObject; var Action: TCloseAction);
324
var
325
  i: integer;
326
begin
327
  NoPopup.Free;
328
  for i := 0 to high(Langs) do
329
    Langs[i].Image.Free;
330
  SetLength(Langs, 0);
331
  settingsshowing := false;
332
  action := CAFree;
333
end;
334

335
procedure TSettingsForm.FormCreate(Sender: TObject);
336
begin
337
  NoPopup := TPopupMenu.Create(nil);
338
  TabsEdit.PopupMenu := NoPopup;
339
  RowsEdit.PopupMenu := NoPopup;
340
  ColsEdit.PopupMenu := NoPopup;
341
  PaddingEdit.PopupMenu := NoPopup;
342
  IWEdit.PopupMenu := NoPopup;
343
  IHEdit.PopupMenu := NoPopup;
344
  TabsEdit.MaxValue := TabsCountMax;
345
  PaddingEdit.MaxValue := PaddingMax;
346
  RowsEdit.MaxValue := RowsCountMax;
347
  ColsEdit.MaxValue := ColsCountMax;
348
  IWEdit.MinValue := MinIconParam;
349
  IWEdit.MaxValue := MaxIconParam;
350
  IWEdit.MinValue := MinIconParam;
351
  IWEdit.MaxValue := MaxIconParam;
352
end;
353

354
procedure TSettingsForm.FormKeyDown(Sender: TObject; var Key: Word;
355
  Shift: TShiftState);
356
begin
357
  if (Key = VK_RETURN) and (ssCtrl in Shift) then OKButton.Click;
358
end;
359

360
procedure TSettingsForm.FormShow(Sender: TObject);
361
begin
362
  if AlwaysOnTop then FormStyle := fsStayOnTop;
363
  ApplyLanguage;
364
  settingsshowing := true;
365
  ScanLanguagesDir;
366
  AutorunCheckBox.Checked := (not IsPortable) and (Autorun);
367
  TopCheckBox.Checked := AlwaysOnTop;
368
  StartHideBox.Checked := StartHide;
369
  StatusBarBox.Checked := StatusBarVis;
370
  TaskBarBox.Checked := taskbarvis;
371
  DateTimeBox.Checked := dtimeinstbar;
372
  DateTimeBox.Enabled := StatusBarBox.Checked;
373
  GlassCheckBox.Checked := nobgnotabs;
374
  ClearCheckBox.Checked := ClearONF;
375
  ABlendCheckBox.Checked := ABlend;
376
  ABOffCheckBox.Checked := ABOffOnHover;
377
  ABOffCheckBox.Enabled := ABlendCheckBox.Checked;
378
  ABlendBar.Enabled := ABlendCheckBox.Checked;
379
  ABlendBar.Position := Round((255 - ABlendVal) / 2.55);
380
  TabsEdit.MaxValue := TabsCountMax;
381
  TabsEdit.Value := tabscount;
382
  RowsEdit.MaxValue := RowsCountMax;
383
  RowsEdit.Value := rowscount;
384
  ColsEdit.MaxValue := ColsCountMax;
385
  ColsEdit.Value := colscount;
386
  PaddingEdit.Value := lpadding;
387
  IWEdit.Value := ButtonWidth;
388
  IHEdit.Value := ButtonHeight;
389
  HideCheckBox.Checked := hideafterlaunch;
390
  QoLCheckBox.Checked := queryonlaunch;
391
  DelLnkCheckBox.Checked := deletelnk;
392
  AdminCheckBox.Checked := rwar;
393
  DropCheckBox.Checked := defdrop;
394
  AutoRunCheckBox.Enabled := not IsPortable;
395
  pgc.ActivePageIndex := IfThen(lotabinsettings in [0..Pred(pgc.PageCount)],
396
                                  lotabinsettings, 0);
397
  pgc.ActivePage.SetFocus;
398
end;
399

400
procedure TSettingsForm.OKButtonClick(Sender: TObject);
401
begin
402
  ApplySettings;
403
  Close;
404
end;
405

406
procedure TSettingsForm.ABlendCheckBoxClick(Sender: TObject);
407
begin
408
  ABOffCheckBox.Enabled := ABlendCheckBox.Checked;
409
  ABlendBar.Enabled := ABlendCheckBox.Checked;
410
end;
411

412
procedure TSettingsForm.ApplyButtonClick(Sender: TObject);
413
begin
414
  ApplySettings;
415
  ApplyLanguage;
416
end;
417

418
procedure TSettingsForm.pgcChange(Sender: TObject);
419
begin
420
  lotabinsettings := pgc.ActivePageIndex;
421
end;
422

423
end.
424

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.