-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
MainForm.pas
2399 lines (2158 loc) · 76.9 KB
/
MainForm.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
unit MainForm;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, ComCtrls, ExtCtrls, Spin, Menus, ActnList, XPMan,
ItemFrame, UpdateForm,
InflatablesList_Manager;
type
// interposer to intercept scrolling
TListBox = class(StdCtrls.TListBox)
private
fOnScroll: TNotifyEvent;
protected
procedure WndProc(var Msg: TMessage); override;
public
property OnScroll: TNotifyEvent read fOnScroll write fOnScroll;
end;
TfMainForm = class(TForm)
mmMainMenu: TMainMenu;
mniMM_File: TMenuItem;
mniMMF_ListCompress: TMenuItem;
mniMMF_ListEncrypt: TMenuItem;
mniMMF_ListPassword: TMenuItem;
mniMMF_Backups: TMenuItem;
N1: TMenuItem;
mniMMF_SaveOnClose: TMenuItem;
mniMMF_Save: TMenuItem;
N2: TMenuItem;
mniMMF_Exit: TMenuItem;
mniMM_List: TMenuItem;
mniMML_Add: TMenuItem;
mniMML_AddCopy: TMenuItem;
mniMML_AddSplitOutCopy: TMenuItem;
mniMML_Remove: TMenuItem;
mniMML_Clear: TMenuItem;
N3: TMenuItem;
mniMML_GoToItemNum: TMenuItem;
mniMML_PrevItem: TMenuItem;
mniMML_NextItem: TMenuItem;
N4: TMenuItem;
mniMML_Rename: TMenuItem;
mniMML_Notes: TMenuItem;
mniMM_Item: TMenuItem;
mniMMI_ItemPictures: TMenuItem;
mniMMI_ItemShops: TMenuItem;
N5: TMenuItem;
mniMMI_ItemExport: TMenuItem;
mniMMI_ItemExportMulti: TMenuItem;
mniMMI_ItemImport: TMenuItem;
N6: TMenuItem;
mniMMI_Encrypted: TMenuItem;
mniMMI_Decrypt: TMenuItem;
mniMMI_DecryptAll: TMenuItem;
mniMMI_ChangeItemsPswd: TMenuItem;
N7: TMenuItem;
mniMMI_MoveBeginning: TMenuItem;
mniMMI_MoveUpBy: TMenuItem;
mniMMI_MoveUp: TMenuItem;
mniMMI_MoveDown: TMenuItem;
mniMMI_MoveDownBy: TMenuItem;
mniMMI_MoveEnd: TMenuItem;
mniMM_Search: TMenuItem;
mniMMS_Find: TMenuItem;
mniMMS_FindPrev: TMenuItem;
mniMMS_FindNext: TMenuItem;
mniMMS_AdvSearch: TMenuItem;
N8: TMenuItem;
mniMMS_FindPrevValue: TMenuItem;
mniMMS_FindNextValue: TMenuItem;
mniMM_Sorting: TMenuItem;
mniMMO_SortSett: TMenuItem;
mniMMO_SortRev: TMenuItem;
mniMMO_SortCase: TMenuItem;
mniMMO_Sort: TMenuItem;
mniMMO_SortBy: TMenuItem;
mniMMO_SB_Default: TMenuItem;
mniMMO_SB_Actual: TMenuItem;
N1_1: TMenuItem;
mniMM_Update: TMenuItem;
mniMMU_UpdateItem: TMenuItem;
mniMMU_UpdateAll: TMenuItem;
mniMMU_UpdateWanted: TMenuItem;
mniMMU_UpdateSelected: TMenuItem;
N9: TMenuItem;
mniMMU_UpdateItemShopHistory: TMenuItem;
mniMMU_UpdateShopsHistory: TMenuItem;
mniMM_Tools: TMenuItem;
mniMMT_Sums: TMenuItem;
mniMMT_Overview: TMenuItem;
N10: TMenuItem;
mniMMT_Selection: TMenuItem;
mniMMT_ItemShopTable: TMenuItem;
mniMMT_ShopByItems: TMenuItem;
N11: TMenuItem;
mniMMT_Specials: TMenuItem;
N12: TMenuItem;
mniMMT_ExportAllPics: TMenuItem;
mniMMT_ExportAllThumbs: TMenuItem;
mniMMT_CleanUpPicAutoFolder: TMenuItem;
mniMMT_CleanUpBackupFolder: TMenuItem;
mniMM_Help: TMenuItem;
mniMMH_ResMarkLegend: TMenuItem;
mniMMH_SettingsLegend: TMenuItem;
N13: TMenuItem;
mniMMH_About: TMenuItem;
// ---
diaItemsImport: TOpenDialog;
diaItemsExport: TSaveDialog;
oXPManifest: TXPManifest;
lbList: TListBox;
eSearchFor: TEdit;
btnFindPrev: TButton;
btnFindNext: TButton;
gbDetails: TGroupBox;
shpListFiller: TShape;
sbStatusBar: TStatusBar;
frmItemFrame: TfrmItemFrame;
procedure FormCreate(Sender: TObject);
procedure FormDestroy(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure FormResize(Sender: TObject);
procedure FormMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
// ---
procedure mniMM_FileClick(Sender: TObject);
procedure mniMMF_ListCompressClick(Sender: TObject);
procedure mniMMF_ListEncryptClick(Sender: TObject);
procedure mniMMF_ListPasswordClick(Sender: TObject);
procedure mniMMF_BackupsClick(Sender: TObject);
procedure mniMMF_SaveOnCloseClick(Sender: TObject);
procedure mniMMF_SaveClick(Sender: TObject);
procedure mniMMF_ExitClick(Sender: TObject);
// ---
procedure mniMM_ListClick(Sender: TObject);
procedure mniMML_AddClick(Sender: TObject);
procedure mniMML_AddCopyClick(Sender: TObject);
procedure mniMML_AddSplitOutCopyClick(Sender: TObject);
procedure mniMML_RemoveClick(Sender: TObject);
procedure mniMML_ClearClick(Sender: TObject);
procedure mniMML_GoToItemNumClick(Sender: TObject);
procedure mniMML_PrevItemClick(Sender: TObject);
procedure mniMML_NextItemClick(Sender: TObject);
procedure mniMML_NotesClick(Sender: TObject);
procedure mniMML_RenameClick(Sender: TObject);
// ---
procedure mniMM_ItemClick(Sender: TObject);
procedure mniMMI_ItemPicturesClick(Sender: TObject);
procedure mniMMI_ItemShopsClick(Sender: TObject);
procedure mniMMI_ItemExportClick(Sender: TObject);
procedure mniMMI_ItemExportMultiClick(Sender: TObject);
procedure mniMMI_ItemImportClick(Sender: TObject);
procedure mniMMI_EncryptedClick(Sender: TObject);
procedure mniMMI_DecryptClick(Sender: TObject);
procedure mniMMI_DecryptAllClick(Sender: TObject);
procedure mniMMI_ChangeItemsPswdClick(Sender: TObject);
procedure mniMMI_MoveBeginningClick(Sender: TObject);
procedure mniMMI_MoveUpByClick(Sender: TObject);
procedure mniMMI_MoveUpClick(Sender: TObject);
procedure mniMMI_MoveDownClick(Sender: TObject);
procedure mniMMI_MoveDownByClick(Sender: TObject);
procedure mniMMI_MoveEndClick(Sender: TObject);
// ---
procedure mniMM_SearchClick(Sender: TObject);
procedure mniMMS_FindClick(Sender: TObject);
procedure mniMMS_FindPrevClick(Sender: TObject);
procedure mniMMS_FindNextClick(Sender: TObject);
procedure mniMMS_AdvSearchClick(Sender: TObject);
procedure mniMMS_FindPrevValueClick(Sender: TObject);
procedure mniMMS_FindNextValueClick(Sender: TObject);
// ---
procedure mniMM_SortingClick(Sender: TObject);
procedure mniMMO_SortCommon(Profile: Integer);
procedure mniMMO_SortSettClick(Sender: TObject);
procedure mniMMO_SortRevClick(Sender: TObject);
procedure mniMMO_SortCaseClick(Sender: TObject);
procedure mniMMO_SortClick(Sender: TObject);
procedure mniMMO_SortByClick(Sender: TObject);
// ---
procedure mniMM_UpdateClick(Sender: TObject);
procedure mniMMU_UpdateCommon(UpdateList: TILItemShopUpdateList);
procedure mniMMU_UpdateItemClick(Sender: TObject);
procedure mniMMU_UpdateAllClick(Sender: TObject);
procedure mniMMU_UpdateWantedClick(Sender: TObject);
procedure mniMMU_UpdateSelectedClick(Sender: TObject);
procedure mniMMU_UpdateItemShopHistoryClick(Sender: TObject);
procedure mniMMU_UpdateShopsHistoryClick(Sender: TObject);
// ---
procedure mniMM_ToolsClick(Sender: TObject);
procedure mniMMT_SumsClick(Sender: TObject);
procedure mniMMT_OverviewClick(Sender: TObject);
procedure mniMMT_SelectionClick(Sender: TObject);
procedure mniMMT_ItemShopTableClick(Sender: TObject);
procedure mniMMT_ShopByItemsClick(Sender: TObject);
procedure mniMMT_SpecialsClick(Sender: TObject);
procedure mniMMT_ExportAllPicsClick(Sender: TObject);
procedure mniMMT_ExportAllThumbsClick(Sender: TObject);
procedure mniMMT_CleanUpPicAutoFolderClick(Sender: TObject);
procedure mniMMT_CleanUpBackupFolderClick(Sender: TObject);
// ---
procedure mniMM_HelpClick(Sender: TObject);
procedure mniMMH_ResMarkLegendClick(Sender: TObject);
procedure mniMMH_SettingsLegendClick(Sender: TObject);
procedure mniMMH_AboutClick(Sender: TObject);
// ---
procedure lbListClick(Sender: TObject);
procedure lbListDblClick(Sender: TObject);
procedure lbListMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
procedure lbListDrawItem(Control: TWinControl; Index: Integer;
Rect: TRect; State: TOwnerDrawState);
procedure lbListScroll(Sender: TObject);
procedure eSearchForEnter(Sender: TObject);
procedure eSearchForExit(Sender: TObject);
procedure eSearchForKeyPress(Sender: TObject; var Key: Char);
procedure btnFindPrevClick(Sender: TObject);
procedure btnFindNextClick(Sender: TObject);
procedure sbStatusBarDrawPanel(StatusBar: TStatusBar;
Panel: TStatusPanel; const Rect: TRect);
procedure sbStatusBarMouseDown(Sender: TObject; Button: TMouseButton;
Shift: TShiftState; X, Y: Integer);
private
// resizing
fInitialFormWidth: Integer;
fInitialFrameHeight: Integer;
fInitialPanelWidth: Integer;
fFirstResize: Boolean;
// others
fDrawBuffer: TBitmap;
fInitialized: Boolean;
fILManager: TILManager;
fSaveOnExit: Boolean;
fWrongPswdMessage: String;
fDirExport: String; // last directory for pictures export
fOnRestartProgram: TNotifyEvent;
protected
procedure WndProc(var Msg: TMessage); override; // Delphi 7 VCL bug workaround
procedure RePositionMainForm;
procedure ReSizeMainForm;
procedure BuildSortBySubmenu;
procedure FillCopyright;
procedure FillListFileName;
procedure FillListName;
procedure UpdateIndexAndCount;
procedure UpdateIndices;
Function SaveList: Boolean;
// event handlers
procedure RestartProgram(Sender: TObject); // backups form event
procedure DeferredRedraw(Sender: TObject; var Done: Boolean); // Application.OnIdle, transient
procedure ShowSelectedItem(Sender: TObject); // item frame event
procedure FocusList(Sender: TObject); // item frame event
procedure InvalidateList(Sender: TObject); // manager event
procedure SettingsChange(Sender: TObject); // manager event
procedure ItemsPasswordRequest(Sender: TObject); // manager event
// init/finals
procedure InitializeOtherForms;
procedure FinalizeOtherForms;
procedure Finalize;
public
procedure Initialize(ILManager: TILManager);
property OnRestartProgram: TNotifyEvent read fOnRestartProgram write fOnRestartProgram;
end;
var
fMainForm: TfMainForm;
implementation
uses
CommCtrl, Math,
PromptForm, TextEditForm, SplashForm, SaveForm, BackupsForm, ItemPicturesForm,
ItemSelectForm, ShopsForm, ParsingForm,TemplatesForm, ItemsSelectForm,
AdvancedSearchForm, SortForm, SumsForm, OverviewForm, ShopSelectForm,
ItemShopTableForm, ShopByItemsForm, SpecialsForm, UpdResLegendForm,
SettingsLegendForm, AboutForm,
WinFileInfo, BitOps, StrRect, CountedDynArrayInteger,
InflatablesList_Types,
InflatablesList_Utils,
InflatablesList_Encryption,
InflatablesList_Backup;
{$R *.dfm}
const
IL_STATUSBAR_PANEL_IDX_INDEX = 0;
IL_STATUSBAR_PANEL_IDX_INDICES = 1;
IL_STATUSBAR_PANEL_IDX_STATIC_SETT = 2;
IL_STATUSBAR_PANEL_IDX_DYNAMIC_SETT = 3;
IL_STATUSBAR_PANEL_IDX_FILENAME = 4;
IL_STATUSBAR_PANEL_IDX_COPYRIGHT = 5;
//==============================================================================
procedure TListBox.WndProc(var Msg: TMessage);
begin
inherited;
If (Msg.Msg = WM_VSCROLL) or (Msg.Msg = WM_HSCROLL) or (Msg.Msg = WM_PRINT) or
(Msg.Msg = WM_PAINT) or (Msg.Msg = WM_PRINTCLIENT) then
fOnScroll(Self);
end;
//==============================================================================
procedure TfMainform.WndProc(var Msg: TMessage);
begin
If Msg.Msg = WM_DRAWITEM then
begin
If PDrawItemStruct(Msg.LParam)^.CtlID = sbStatusBar.Handle then
PDrawItemStruct(Msg.LParam)^.CtlType := 0;
end;
inherited;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.RePositionMainForm;
var
WorkRect: TRect;
WorkRectSize: TPoint;
procedure PositionOnX;
begin
If Width > WorkRectSize.X then
Left := WorkRect.Left
else
Left := WorkRect.Left + (WorkRectSize.X - Width) div 2;
end;
begin
WorkRect := Screen.MonitorFromWindow(Application.Handle).WorkAreaRect;
WorkRectSize := Point(WorkRect.Right - WorkRect.Left,WorkRect.Bottom - WorkRect.Top);
If Height > WorkRectSize.Y then
begin
Position := poDesigned;
PositionOnX;
Top := WorkRect.Top;
end
else If BoundsRect.Bottom > WorkRect.Bottom then
begin
Position := poDesigned;
PositionOnX;
Top := WorkRect.Top + (WorkRectSize.Y - Height) div 2;
end;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.ReSizeMainForm;
begin
{
do NOT call anything Client* on gbDetails - it causes problems
}
// redraw items for new listbox size
If Assigned(fILManager) then
begin
// redraw only visible
fILManager.ReinitMainDrawSize(lbList,True);
lbList.Invalidate;
// deffer redraw of ivisible item
Application.OnIdle := DeferredRedraw;
end;
// rearrange search editbox
eSearchFor.Top := lbList.BoundsRect.Bottom + 5;
btnFindPrev.Top := eSearchFor.Top;
btnFindNext.Top := eSearchFor.Top;
// listbox filler
shpListFiller.Top := eSearchFor.BoundsRect.Bottom + 8;
shpListFiller.Width := lbList.Width;
shpListFiller.Height := gbDetails.BoundsRect.Bottom - shpListFiller.Top;
shpListFiller.Visible := shpListFiller.Height >= 4;
// item frame is resized automatically
// resize status bar panels
sbStatusBar.Panels[IL_STATUSBAR_PANEL_IDX_FILENAME].Width :=
fInitialPanelWidth + (Width - fInitialFormWidth);
FillListFileName;
sbStatusBar.Invalidate;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.BuildSortBySubmenu;
var
i: Integer;
MITemp: TMenuItem;
begin
// remove menu items
For i := Pred(mniMMO_SortBy.Count) downto 0 do
If mniMMO_SortBy[i].Tag >= 0 then
begin
MITemp := mniMMO_SortBy[i];
mniMMO_SortBy.Delete(i);
FreeAndNil(MITemp);
end;
For i := 0 to Pred(fILManager.SortingProfileCount) do
begin
MITemp := TMenuItem.Create(Self);
MITemp.Name := IL_Format('mniMM_SB_Profile%d',[i]);
MITemp.Caption := fILManager.SortingProfiles[i].Name;
MITemp.OnClick := mniMMO_SortByClick;
MITemp.Tag := i;
If i <= 9 then
MITemp.ShortCut := ShortCut(Ord('0') + ((i + 1) mod 10),[ssCtrl]);
mniMMO_SortBy.Add(MITemp);
end;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.FillCopyright;
begin
with TWinFileInfo.Create(WFI_LS_LoadVersionInfo or WFI_LS_LoadFixedFileInfo or WFI_LS_DecodeFixedFileInfo) do
try
sbStatusBar.Panels[IL_STATUSBAR_PANEL_IDX_COPYRIGHT].Text := IL_Format('%s, version %d.%d.%d %s%s #%d %s',[
VersionInfoValues[VersionInfoTranslations[0].LanguageStr,'LegalCopyright'],
VersionInfoFixedFileInfoDecoded.FileVersionMembers.Major,
VersionInfoFixedFileInfoDecoded.FileVersionMembers.Minor,
VersionInfoFixedFileInfoDecoded.FileVersionMembers.Release,
{$IFDEF FPC}'L'{$ELSE}'D'{$ENDIF},{$IFDEF x64}'64'{$ELSE}'32'{$ENDIF},
VersionInfoFixedFileInfoDecoded.FileVersionMembers.Build,
{$IFDEF Debug}'debug'{$ELSE}'release'{$ENDIF}]);
finally
Free;
end;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.FillListFileName;
begin
If sbStatusBar.Canvas.TextWidth(fILManager.StaticSettings.ListFile) >
(sbStatusBar.Panels[IL_STATUSBAR_PANEL_IDX_FILENAME].Width -
(2 * GetSystemMetrics(SM_CXFIXEDFRAME))) then
begin
sbStatusBar.Panels[IL_STATUSBAR_PANEL_IDX_FILENAME].Text :=
IL_MinimizeName(fILManager.StaticSettings.ListFile,sbStatusBar.Canvas,
sbStatusBar.Panels[IL_STATUSBAR_PANEL_IDX_FILENAME].Width -
(2 * GetSystemMetrics(SM_CXFIXEDFRAME)));
end
else sbStatusBar.Panels[IL_STATUSBAR_PANEL_IDX_FILENAME].Text := fILManager.StaticSettings.ListFile;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.FillListName;
begin
If Length(fILManager.ListName) > 0 then
Caption := IL_Format('Inflatables List - %s',[fILManager.ListName])
else
Caption := 'Inflatables List';
end;
//------------------------------------------------------------------------------
procedure TfMainForm.UpdateIndexAndCount;
begin
If lbList.ItemIndex < 0 then
begin
If fILManager.ItemCount > 0 then
sbStatusBar.Panels[IL_STATUSBAR_PANEL_IDX_INDEX].Text := IL_Format('-/%d',[fILManager.ItemCount])
else
sbStatusBar.Panels[IL_STATUSBAR_PANEL_IDX_INDEX].Text := '-/-';
end
else sbStatusBar.Panels[IL_STATUSBAR_PANEL_IDX_INDEX].Text := IL_Format('%d/%d',[lbList.ItemIndex + 1,fILManager.ItemCount]);
UpdateIndices;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.UpdateIndices;
begin
If (lbList.Count > 0) and (lbList.TopIndex >= 0) then
begin
If lbList.TopIndex + (lbList.ClientHeight div lbList.ItemHeight) > lbList.Count then
sbStatusBar.Panels[IL_STATUSBAR_PANEL_IDX_INDICES].Text := Format('%d-%d',
[lbList.TopIndex + 1,lbList.Count])
else
sbStatusBar.Panels[IL_STATUSBAR_PANEL_IDX_INDICES].Text := Format('%d-%d',
[lbList.TopIndex + 1,lbList.TopIndex + (lbList.ClientHeight div lbList.ItemHeight)]);
end
else sbStatusBar.Panels[IL_STATUSBAR_PANEL_IDX_INDICES].Text := '-'
end;
//------------------------------------------------------------------------------
Function TfMainForm.SaveList: Boolean;
begin
Result := False;
frmItemFrame.Save;
If not fILManager.StaticSettings.NoSave then
begin
If fILManager.SlowSaving then
fSaveForm.ShowAndPerformSave
else
fILManager.SaveToFile; // backup is done automatically here
FillListFileName;
Result := True;
end;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.RestartProgram(Sender: TObject);
begin
If Assigned(fOnRestartProgram) then
fOnRestartProgram(Self);
fSaveOnExit := False;
Close;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.DeferredRedraw(Sender: TObject; var Done: Boolean);
begin
Done := True;
Application.OnIdle := nil; // de-assign this routine
fILManager.ReinitMainDrawSize(lbList,False);
lbList.Invalidate;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.ShowSelectedItem(Sender: TObject);
begin
If lbList.ItemIndex >= 0 then
begin
If (lbList.ItemIndex < lbList.TopIndex) then
lbList.TopIndex := lbList.ItemIndex
else If lbList.ItemIndex >= (lbList.TopIndex + (lbList.ClientHeight div lbList.ItemHeight)) then
lbList.TopIndex := Succ(lbList.ItemIndex - (lbList.ClientHeight div lbList.ItemHeight));
lbList.SetFocus;
end;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.FocusList(Sender: TObject);
begin
lbList.SetFocus;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.InvalidateList(Sender: TObject);
begin
lbList.Invalidate;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.SettingsChange(Sender: TObject);
begin
sbStatusBar.Invalidate;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.ItemsPasswordRequest(Sender: TObject);
var
Password: String;
begin
Password := '';
If IL_InputQuery('Items password','Enter items password (can be empty):',Password,'*') then
try
fILManager.ItemsPassword := Password;
except
on E: EILWrongPassword do
begin
If Length(fWrongPswdMessage) > 0 then
MessageDlg(fWrongPswdMessage,mtError,[mbOk],0)
else
MessageDlg('Wrong password.',mtError,[mbOk],0);
end
else raise;
end;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.InitializeOtherForms;
begin
fTextEditForm.Initialize(fILManager);
fShopsForm.Initialize(fILManager);
fParsingForm.Initialize(fILManager);
fTemplatesForm.Initialize(fILManager);
fSortForm.Initialize(fILManager);
fSumsForm.Initialize(fILManager);
fSpecialsForm.Initialize(fILManager);
fOverviewForm.Initialize(fILManager);
fShopSelectForm.Initialize(fIlManager);
fUpdateForm.Initialize(fILManager);
fItemsSelectForm.Initialize(fIlManager);
fBackupsForm.Initialize(fILManager);
fBackupsForm.OnRestartRequired := RestartProgram;
fUpdResLegendForm.Initialize(fIlManager);
fSettingsLegendForm.Initialize(fIlManager);
fAboutForm.Initialize(fIlManager);
fSplashForm.Initialize(fIlManager);
fSaveForm.Initialize(fIlManager);
fAdvancedSearchForm.Initialize(fIlManager);
fShopByItemsForm.Initialize(fIlManager);
fItemPicturesForm.Initialize(fIlManager);
fItemShopTableForm.Initialize(fILManager);
fItemSelectForm.Initialize(fILManager);
end;
//------------------------------------------------------------------------------
procedure TfMainForm.FinalizeOtherForms;
begin
fTextEditForm.Finalize;
fShopsForm.Finalize;
fParsingForm.Finalize;
fTemplatesForm.Finalize;
fSortForm.Finalize;
fSumsForm.Finalize;
fSpecialsForm.Finalize;
fOverviewForm.Finalize;
fShopSelectForm.Finalize;
fUpdateForm.Finalize;
fItemsSelectForm.Finalize;
fBackupsForm.Finalize;
fUpdResLegendForm.Finalize;
fSettingsLegendForm.Finalize;
fAboutForm.Finalize;
fSplashForm.Finalize;
fSaveForm.Finalize;
fAdvancedSearchForm.Finalize;
fShopByItemsForm.Finalize;
fItemPicturesForm.Finalize;
fItemShopTableForm.Finalize;
fItemSelectForm.Finalize;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.Finalize;
begin
If fSaveOnExit and mniMMF_SaveOnClose.Checked then
SaveList;
If fInitialized then
begin
// finalize item frame
frmItemFrame.SetItem(nil,False);
frmItemFrame.OnShowSelectedItem := nil;
frmItemFrame.OnFocusList := nil;
frmItemFrame.Finalize;
// deassign event handlers
fILManager.OnMainListUpdate := nil;
fILManager.OnSettingsChange := nil;
// others
FinalizeOtherForms;
end;
end;
//==============================================================================
procedure TfMainForm.Initialize(ILManager: TILManager);
var
i: Integer;
begin
// the list is already loaded at this point
// fill some texts
FillCopyright;
eSearchFor.OnExit(nil);
// prepare variables/fields/objects
fInitialFormWidth := Width;
fInitialFrameHeight := frmItemFrame.Height;
fInitialPanelWidth := sbStatusBar.Panels[IL_STATUSBAR_PANEL_IDX_FILENAME].Width;
fFirstResize := True;
fInitialized := True;
fILManager := ILManager;
fILManager.OnMainListUpdate := InvalidateList;
fILManager.OnSettingsChange := SettingsChange;
fILManager.OnItemsPasswordRequest := ItemsPasswordRequest;
fSaveOnExit := True;
fWrongPswdMessage := '';
fDirExport := IL_ExcludeTrailingPathDelimiter(fILManager.StaticSettings.DefaultPath);
// prepare item frame
frmItemFrame.Initialize(fILManager);
frmItemFrame.OnShowSelectedItem := ShowSelectedItem;
frmItemFrame.OnFocusList := FocusList;
// fill list
lbList.Items.Clear;
If fILManager.ItemCount > 0 then
begin
lbList.Items.BeginUpdate;
try
For i := 0 to Pred(fILManager.ItemCount) do
lbList.Items.Add(IntToStr(i));
finally
lbList.Items.EndUpdate;
end;
lbList.ItemIndex := 0;
lbList.OnClick(nil);
end
else frmItemFrame.SetItem(nil,True);
// load other things from manager
mniMMF_SaveOnClose.Checked := True;
mniMMO_SortRev.Checked := fILManager.ReversedSort;
mniMMO_SortCase.Checked := fILManager.CaseSensitiveSort;
mniMMF_ListCompress.Checked := fILManager.Compressed;
mniMMF_ListEncrypt.Checked := fILManager.Encrypted;
// position the window
RePositionMainForm;
// build some things and final touches
sbStatusBar.Invalidate; // to show settings
UpdateIndexAndCount;
BuildSortBySubmenu;
FillListFileName;
FillListName;
InitializeOtherForms;
end;
//==============================================================================
procedure TfMainForm.FormCreate(Sender: TObject);
begin
fInitialized := False;
// prepare form
lbList.DoubleBuffered := True;
sbStatusBar.DoubleBuffered := True;
// build shortcuts
mniMML_AddCopy.ShortCut := ShortCut(VK_INSERT,[ssCtrl,ssShift]);
mniMML_AddSplitOutCopy.ShortCut := ShortCut(VK_INSERT,[ssCtrl,ssAlt]);
mniMML_Clear.ShortCut := ShortCut(VK_DELETE,[ssCtrl,ssShift]);
mniMML_PrevItem.ShortCut := ShortCut(VK_TAB,[ssCtrl,ssShift]);
mniMML_NextItem.ShortCut := ShortCut(VK_TAB,[ssCtrl]);
mniMMI_MoveBeginning.ShortCut := ShortCut(VK_UP,[ssCtrl,ssAlt]);
mniMMI_MoveUpBy.ShortCut := ShortCut(VK_UP,[ssShift,ssCtrl]);
mniMMI_MoveUp.ShortCut := ShortCut(VK_UP,[ssCtrl]);
mniMMI_MoveDown.ShortCut := ShortCut(VK_DOWN,[ssCtrl]);
mniMMI_MoveDownBy.ShortCut := ShortCut(VK_DOWN,[ssShift,ssCtrl]);
mniMMI_MoveEnd.ShortCut := ShortCut(VK_DOWN,[ssCtrl,ssAlt]);
mniMMO_SortSett.ShortCut := ShortCut(Ord('O'),[ssCtrl,ssShift]);
mniMMO_SortCase.ShortCut := ShortCut(Ord('R'),[ssCtrl,ssShift]);
mniMMU_UpdateWanted.ShortCut := ShortCut(Ord('U'),[ssCtrl,ssShift]);
mniMMU_UpdateSelected.ShortCut := ShortCut(Ord('U'),[ssAlt,ssShift]);
// prepare draw buffer
fDrawBuffer := TBitmap.Create;
fDrawBuffer.PixelFormat := pf24bit;
fDrawBuffer.Canvas.Font.Assign(sbStatusBar.Font);
// assign custom events
lbList.OnScroll := lbListScroll;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.FormDestroy(Sender: TObject);
begin
FreeAndNil(fDrawBuffer);
end;
//------------------------------------------------------------------------------
procedure TfMainForm.FormShow(Sender: TObject);
begin
// first drawing
fILManager.ReinitMainDrawSize(lbList);
fILManager.ReinitSmallDrawSize(fShopSelectForm.lbItems);
fILManager.ReinitMiniDrawSize(IL_ITEMSHOPTABLE_ITEMCELL_WIDTH,
IL_ITEMSHOPTABLE_ITEMCELL_HEIGHT,fItemShopTableForm.dgTable.Font);
end;
//------------------------------------------------------------------------------
procedure TfMainForm.FormClose(Sender: TObject; var Action: TCloseAction);
begin
Finalize; // must not be called from OnDestroy event
end;
//------------------------------------------------------------------------------
procedure TfMainForm.FormResize(Sender: TObject);
begin
If Visible then
ReSizeMainForm;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.FormMouseWheel(Sender: TObject; Shift: TShiftState;
WheelDelta: Integer; MousePos: TPoint; var Handled: Boolean);
var
Control: TControl;
LinesToScroll: UINT;
NewTopIndex: Integer;
begin
// scroll list when not focused but cursor is above it
Control := ControlAtPos(ScreenToClient(MousePos),False,True);
If (Control = lbList) and not(lbList.Focused) then
begin
If SystemParametersInfo(SPI_GETWHEELSCROLLLINES,0,@LinesToScroll,0) then
begin
NewTopIndex := lbList.TopIndex - Integer(LinesToScroll) * (WheelDelta div WHEEL_DELTA);
If NewTopIndex < 0 then
NewTopIndex := 0
else If NewTopIndex + (lbList.ClientHeight div lbList.ItemHeight) > lbList.Count then
NewTopIndex := lbList.Count - (lbList.ClientHeight div lbList.ItemHeight);
lbList.TopIndex := NewTopIndex;
Handled := True;
end;
end;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.mniMM_FileClick(Sender: TObject);
begin
mniMMF_ListPassword.Enabled := fILManager.Encrypted;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.mniMMF_ListCompressClick(Sender: TObject);
begin
mniMMF_ListCompress.Checked := not mniMMF_ListCompress.Checked;
fIlManager.Compressed := mniMMF_ListCompress.Checked;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.mniMMF_ListEncryptClick(Sender: TObject);
var
Password: String;
begin
If not fIlManager.Encrypted then
begin
If IL_InputQuery('List password','Enter list password (can be empty):',Password,'*') then
begin
fIlManager.ListPassword := Password;
fIlManager.Encrypted := True;
end;
end
else fIlManager.Encrypted := False;
mniMMF_ListEncrypt.Checked := fIlManager.Encrypted;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.mniMMF_ListPasswordClick(Sender: TObject);
var
Password: String;
begin
If fIlManager.Encrypted then
If IL_InputQuery('List password','Enter list password (can be empty):',Password,'*') then
fIlManager.ListPassword := Password;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.mniMMF_BackupsClick(Sender: TObject);
begin
fBackupsForm.ShowBackups;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.mniMMF_SaveOnCloseClick(Sender: TObject);
begin
mniMMF_SaveOnClose.Checked := not mniMMF_SaveOnClose.Checked;
sbStatusBar.Invalidate;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.mniMMF_SaveClick(Sender: TObject);
begin
Screen.Cursor := crHourGlass;
try
If not SaveList then
Beep;
finally
Screen.Cursor := crDefault;
end;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.mniMMF_ExitClick(Sender: TObject);
begin
If MessageDlg('Are you sure you want to exit without saving?',mtConfirmation,[mbYes,mbNo],0) = mrYes then
begin
fSaveOnExit := False;
Close;
end;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.mniMM_ListClick(Sender: TObject);
begin
If lbList.ItemIndex >= 0 then
begin
mniMML_AddCopy.Enabled := fILManager[lbList.ItemIndex].DataAccessible;
mniMML_AddSplitOutCopy.Enabled := fILManager[lbList.ItemIndex].DataAccessible and
(fILManager[lbList.ItemIndex].Pieces > 1);
end
else
begin
mniMML_AddCopy.Enabled := False;
mniMML_AddSplitOutCopy.Enabled := False;
end;
mniMML_Remove.Enabled := lbList.ItemIndex >= 0;
mniMML_Clear.Enabled := lbList.Count > 0;
mniMML_GoToItemNum.Enabled := lbList.Count > 0;
mniMML_PrevItem.Enabled := lbList.ItemIndex > 0;
mniMML_NextItem.Enabled := (lbList.Count > 0) and (lbList.ItemIndex < Pred(lbList.Count));
end;
//------------------------------------------------------------------------------
procedure TfMainForm.mniMML_AddClick(Sender: TObject);
begin
frmItemFrame.Save;
lbList.Items.Add(IntToStr(lbList.Count));
lbList.ItemIndex := fILManager.ItemAddEmpty(Succ(lbList.ItemIndex));
// following will also redraw new item and update the list
fILManager.ReinitMainDrawSize(lbList);
fILManager.ReinitSmallDrawSize(fShopSelectForm.lbItems);
fILManager.ReinitMiniDrawSize(IL_ITEMSHOPTABLE_ITEMCELL_WIDTH,
IL_ITEMSHOPTABLE_ITEMCELL_HEIGHT,fItemShopTableForm.dgTable.Font);
lbList.OnClick(nil); // also calls UpdateIndexAndCount
end;
//------------------------------------------------------------------------------
procedure TfMainForm.mniMML_AddCopyClick(Sender: TObject);
var
Index: Integer;
begin
If lbList.ItemIndex >= 0 then
If fILManager[lbList.ItemIndex].DataAccessible then
begin
frmItemFrame.Save; // save unsaved data for copying
frmItemFrame.SetItem(nil,False);
Index := lbList.ItemIndex;
lbList.Items.Add(IntToStr(lbList.Count));
lbList.ItemIndex := fILManager.ItemAddCopy(Index,Succ(lbList.ItemIndex));
fILManager.ReinitMainDrawSize(lbList);
fILManager.ReinitSmallDrawSize(fShopSelectForm.lbItems);
fILManager.ReinitMiniDrawSize(IL_ITEMSHOPTABLE_ITEMCELL_WIDTH,
IL_ITEMSHOPTABLE_ITEMCELL_HEIGHT,fItemShopTableForm.dgTable.Font);
lbList.OnClick(nil);
end;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.mniMML_AddSplitOutCopyClick(Sender: TObject);
var
Index: Integer;
begin
If lbList.ItemIndex >= 0 then
If fILManager[lbList.ItemIndex].DataAccessible and (fILManager[lbList.ItemIndex].Pieces > 1) then
begin
frmItemFrame.Save; // save unsaved data for copying
frmItemFrame.SetItem(nil,False);
Index := lbList.ItemIndex;
lbList.Items.Add(IntToStr(lbList.Count));
lbList.ItemIndex := fILManager.ItemAddSplitOutCopy(Index,Succ(lbList.ItemIndex));
fILManager.ReinitMainDrawSize(lbList);
fILManager.ReinitSmallDrawSize(fShopSelectForm.lbItems);
fILManager.ReinitMiniDrawSize(IL_ITEMSHOPTABLE_ITEMCELL_WIDTH,
IL_ITEMSHOPTABLE_ITEMCELL_HEIGHT,fItemShopTableForm.dgTable.Font);
lbList.OnClick(nil);
end;
end;
//------------------------------------------------------------------------------
procedure TfMainForm.mniMML_RemoveClick(Sender: TObject);
var
Index: Integer;
begin
frmItemFrame.Save;
If lbList.ItemIndex >= 0 then
If MessageDlg(IL_Format('Are you sure you want to remove the item "%s"?',
[fILManager[lbList.ItemIndex].TitleStr]),mtConfirmation,[mbYes,mbNo],0) = mrYes then
begin
frmItemFrame.SetItem(nil,False); // the item will be deleted, so unbind it
Index := lbList.ItemIndex;
fILManager.ItemDelete(Index);
lbList.Items.Delete(Index);
fILManager.ReinitMainDrawSize(lbList);
fILManager.ReinitSmallDrawSize(fShopSelectForm.lbItems);
fILManager.ReinitMiniDrawSize(IL_ITEMSHOPTABLE_ITEMCELL_WIDTH,
IL_ITEMSHOPTABLE_ITEMCELL_HEIGHT,fItemShopTableForm.dgTable.Font);
If lbList.Count > 0 then
begin
If Index < lbList.Count then
lbList.ItemIndex := Index
else
lbList.ItemIndex := Pred(lbList.Count);
end
else lbList.ItemIndex := -1;
lbList.OnClick(nil);