-
Notifications
You must be signed in to change notification settings - Fork 0
/
MainForm.pas
1965 lines (1847 loc) · 91.5 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, Classes, Graphics, Controls, Forms, Dialogs, ImgList, StdCtrls, ExtCtrls, Buttons, Math,
ComCtrls, Registry, CommCtrl, Menus, Clipbrd, MyUtils, Data, Dict;
type
TNeogrammarian = class(TForm)
ColourList: TImageList; HidePanel1: TPanel; Label2: TLabel; SourceTree: TTreeView;
SourceBackPanel: TPanel; SourceLabel: TLabel; DownBtn: TSpeedButton; CharsBox: TListBox;
SourcePanel: TPanel; SourceImage: TPaintBox; TargetBackPanel: TPanel; TargetPanel: TPanel;
TargetImage: TPaintBox; UpBtn: TSpeedButton; Label4: TLabel; CheckBox: TCheckBox;
ComboBox: TComboBox; RemarksBox: TListBox; TargetBtn: TSpeedButton; TargetLangPopup: TPopupMenu;
TargetLabel: TLabel; SourceLangPopup: TPopupMenu; SourceBtn: TSpeedButton; GheWordBtn: TSpeedButton;
HidePanel2: TPanel; Label1: TLabel; TargetBox: TListBox; CopyrightLabel: TLabel;
Image1: TImage; LemizhImage: TImage; CopySourceBtn: TSpeedButton; CopyTargetBtn: TSpeedButton;
VerLabel: TLabel; SmallBtn: TSpeedButton; SourcePopup: TPopupMenu; InsertLetter: TMenuItem;
ToggleAccent1: TMenuItem; HistPopup: TPopupMenu; HistBtn: TBitBtn; N1: TMenuItem;
EscapeWord: TMenuItem; AddToHistory: TMenuItem; PopupImgs: TImageList; CharList: TImageList;
SemBtn: TSpeedButton; ToggleAccent2: TMenuItem; Undo: TMenuItem; AccentWarn: TImage;
LicenseImage: TImage; PopupBtn: TSpeedButton; BtnPopup: TPopupMenu; Copyletterlist: TMenuItem;
Copylettertable: TMenuItem; CopyGreekvoweltable: TMenuItem; DictBtn: TSpeedButton; DictPopup: TPopupMenu;
Showdictionary: TMenuItem; Addcurrwords: TMenuItem; Addallwords: TMenuItem; ToggleHyphen: TMenuItem;
ToggleDiaeresis: TMenuItem; N3: TMenuItem; RemarksPopup: TPopupMenu; CopyRemarks: TMenuItem;
SemMenuitem: TMenuItem; SourceAddImage: TImage; TargetAddImage: TImage; Recalculate1: TMenuItem;
N4: TMenuItem; N5: TMenuItem; InternalSort: TMenuItem; AddPIEparticiple1: TMenuItem;
AddPIEparticiple2: TMenuItem; N6: TMenuItem; ToggleMorphbound: TMenuItem;
procedure FormShow(Sender: TObject);
procedure CharsBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure CharsBoxMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure ImagePaint(Sender: TObject);
procedure UpBtnClick(Sender: TObject);
procedure TargetBoxClick(Sender: TObject);
procedure FormKeyPress(Sender: TObject; var Key: Char);
procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
procedure FormDestroy(Sender: TObject);
procedure RemarksBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure OptBoxesClick(Sender: TObject);
procedure AppActivate(Sender: TObject);
procedure AppDeactivate(Sender: TObject);
procedure SourceTreeChange(Sender: TObject; Node: TTreeNode);
procedure SourceTreeChanging(Sender: TObject; Node: TTreeNode; var AllowChange: Boolean);
procedure SourceTreeClick(Sender: TObject);
procedure TargetBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure DownBtnClick(Sender: TObject);
procedure SmallBtnClick(Sender: TObject);
procedure TargetBtnClick(Sender: TObject);
procedure SourceBtnClick(Sender: TObject);
procedure GheWordBtnClick(Sender: TObject);
procedure CopyBtnClick(Sender: TObject);
procedure SourcePopupClick(Sender: TObject);
procedure SourcePopupPopup(Sender: TObject);
procedure HistBtnClick(Sender: TObject);
procedure SemBtnClick(Sender: TObject);
procedure SourceImageMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
procedure SourceImageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
procedure LicenseImageClick(Sender: TObject);
procedure PopupBtnClick(Sender: TObject);
procedure CopyletterlistClick(Sender: TObject);
procedure CopylettertableClick(Sender: TObject);
procedure CopyGreekvoweltableClick(Sender: TObject);
procedure AddallwordsClick(Sender: TObject);
procedure ShowdictionaryClick(Sender: TObject);
procedure AddcurrwordsClick(Sender: TObject);
procedure DictPopupPopup(Sender: TObject);
procedure DictBtnClick(Sender: TObject);
procedure FormClose(Sender: TObject; var Action: TCloseAction);
procedure CopyRemarksClick(Sender: TObject);
procedure ComboBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
procedure InternalSortClick(Sender: TObject);
procedure AddPIEparticipleClick(Sender: TObject);
private
FWords, FStressDia: array[-MaxHist-1..3] of ByteArray; {0: source, 1: aux, 2: target, 3: dict}
FEnding, FMorphBound: array[-MaxHist-1..3] of Word;
GheGloss: array[-MaxHist-1..0] of string;
FHistLangs: array[0..1, 1..MaxHist+1] of Integer;
HistOpts, HistSourceLetter: array[0..MaxHist+1] of Byte;
Caret: array[0..MaxHist+1, 0..1] of Integer;
CopyBtns: array[0..1] of TSpeedButton;
ComboBoxIndices: array[1..7] of Integer;
Descendants, Loans, LargeWidth, LargeHeight, LargeTargetPanelTop, LargeTargetPanelHeight, DictLang: Integer;
InputNum: Char;
CF_RTF: DWord;
FDictLinkS, FDictLinkT: PDictEntry;
procedure AppShowHint(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
procedure SourceLangPopupClick(Sender: TObject);
procedure TargetLangPopupClick(Sender: TObject);
procedure PopupMeasureItem(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);
procedure LangPopupDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
procedure HistPopupDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
function ShowComboBox(Show: Boolean; Id: Integer): Integer;
function OTroyVFromLast(i, Nr: Integer): Integer;
function OTroyDiph(i: Integer; Ins: Boolean): Integer;
procedure PIEStem(Lang: Byte; assimSPH: Boolean = True);
function GetWords(i, j: Integer): Byte;
procedure SetWords(i, j: Integer; c: Byte);
function GetDrawWords(i, j: Integer): SmallInt;
procedure SetWordsStressDia(i, j: Integer; sd, c: Byte);
function GetWordsB(i, j: Integer): Byte;
procedure SetWordsB(i, j: Integer; c: Byte);
property WordsB[i, j: Integer]: Byte read GetWordsB write SetWordsB;
function GetWordLen(i: Integer): Integer;
procedure SetWordLen(i, v: Integer);
function GetEnding(i: Integer): Word;
procedure SetEnding(i: Integer; v: Word);
function GetMorphBound(i: Integer): Word;
procedure SetMorphBound(i: Integer; v: Word);
procedure WordCut(i, v: Integer);
procedure InsAtCaret(c: Byte);
function GetLangs(i, j: Integer): Integer;
procedure SetLangs(i, j, l: Integer);
function GetStress(i, j: Integer; Sort: TStress): TStress;
function GetDia(i, j: Integer): TDia;
function SortChar(Lang, i: Integer): Byte;
procedure SetDictLinkS(p: PDictEntry);
procedure SetDictLinkT(p: PDictEntry);
function VarCode: Byte;
public
procedure HistPopupClick(Sender: TObject);
procedure Reduplicate(r: Integer; accent: Boolean);
procedure Grade(g: Integer; accent: Boolean);
procedure Add(i: Integer; c: Byte); overload;
procedure Add(i: Integer; c, sd: Byte); overload;
procedure Delete(i, p: Integer);
procedure Insert(i, p, c: Integer);
function GetStressDia(i, j: Integer): Byte;
procedure SetStress(i, j: Integer; Sort: TStress; Toggle: Boolean);
procedure SetDia(i, j: Integer; Toggle: Boolean);
procedure SetCaret(p0, p1: Integer);
property Langs[i, j: Integer]: Integer read GetLangs write SetLangs; {[0..3, 0]: source/target/dict lang; [0..2, 1..MaxHist]: hist langs}
property Words[i, j: Integer]: Byte read GetWords write SetWords;
property WordsStressDia[i, j: Integer; sd: Byte]: Byte write SetWordsStressDia;
property WordLen[i: Integer]: Integer read GetWordLen write SetWordLen;
property Ending[i: Integer]: Word read GetEnding write SetEnding;
property MorphBound[i: Integer]: Word read GetMorphBound write SetMorphBound;
property DrawWords[i, j: Integer]: SmallInt read GetDrawWords;
property DictLinkS: PDictEntry read FDictLinkS write SetDictLinkS;
property DictLinkT: PDictEntry read FDictLinkT write SetDictLinkT;
procedure UpdateWord(UpDict: Boolean; Gloss: string);
function DrawWord(i: Integer; ACanvas: TCanvas; ARect: TRect; ASelected, DrawLang: Boolean; Indent: Integer): string;
procedure DrawUnicode(ACanvas: TCanvas; Rect: TRect; FrontColor, BackColor: TColor; Invert, ConvBrackets: Boolean; S: string);
function MakeWordHTML(i, Start, Stop: Integer; HTMLTag: string; Id: Boolean): string; overload;
function MakeWordHTML(i, Start, Stop: Integer; HTMLTag: string; Id: Boolean; out S: string; out Lem: Boolean): string; overload;
end;
var
Neogrammarian: TNeogrammarian;
implementation
uses GheWord;
{$R *.DFM} {$R Strings.res}
procedure TNeogrammarian.FormShow(Sender: TObject);
const SourceTarg: array[0..1] of string = ('Source', 'Target');
var i, j: Integer;
Node: TTreeNode;
m: TMenuItem;
dt: TDateTime;
buf: array[0..4095] of Byte;
ver: array[0..2] of Byte;
ct: array[0..1] of string;
w: DWord;
P: Pointer;
h: HWnd;
begin
h:=FindWindowEx(0, Handle, 'TNeogrammarian', nil);
if (h<>Handle) and (GetWindowTextLength(h)>0) then begin
SetWindowPos(h, HWnd_Top, Left, Top, 0, 0, SWP_NoSize);
SetForegroundWindow(h);
Close;
end else begin
LargeWidth:=Width;
LargeHeight:=Height;
LargeTargetPanelTop:=TargetBackPanel.Top;
LargeTargetPanelHeight:=TargetBackPanel.Height;
for i:=0 to 1 do CopyBtns[i]:=TSpeedButton(FindComponent('Copy'+SourceTarg[i]+'Btn'));
for i:=0 to Length(LangNs)-1 do begin
Node:=nil;
for j:=0 to SourceTree.Items.Count-1 do if (SourceTree.Items[j].Level=0) and (Integer(SourceTree.Items[j].Data)=Dates[i]) then Node:=SourceTree.Items[j];
if Node=nil then Node:=SourceTree.Items.AddObject(nil, IntToYear(Dates[i]), Pointer(Dates[i]));
SourceTree.Items.AddChildObject(Node, LangNs[i], Pointer(i)).ImageIndex:=i+1;
end;
for i:=0 to SourceTree.Items.Count-1 do begin
m:=TMenuItem.Create(self);
if SourceTree.Items[i].Level=1 then m.Caption:=LongLangNs[Integer(SourceTree.Items[i].Data)] else m.Caption:='-';
m.Tag:=Integer(SourceTree.Items[i].Data);
m.RadioItem:=True;
m.OnClick:=SourceLangPopupClick;
m.OnMeasureItem:=PopupMeasureItem;
m.OnDrawItem:=LangPopupDrawItem;
SourceLangPopup.Items.Add(m);
end;
with SourceTree do for i:=0 to Items.Count-1 do Items[i].SelectedIndex:=Items[i].ImageIndex;
SourceTree.FullExpand;
ToggleAccent1.Caption:=ToggleAccent1.Caption+#9#9',';
ToggleAccent2.Caption:=ToggleAccent2.Caption+#9#9'.';
ToggleDiaeresis.Caption:=ToggleDiaeresis.Caption+#9#9#9':';
ToggleHyphen.Caption:=ToggleHyphen.Caption+#9#9#9'-';
ToggleMorphbound.Caption:=ToggleMorphbound.Caption+#9'/';
with TRegIniFile.Create(Reg) do begin
InternalSort.Checked:=ReadBool('', 'InternalSort', False);
SourceTree.Selected:=SourceTree.Items[1]; {must be after InternalSort.Checked}
for i:=Max(Min(ReadInteger('History', '', 0), MaxHist), 0) downto 0 do begin
if i>0 then OpenKey('\'+Reg+'\History\'+FormatFloat('00', i), False) else OpenKey('\'+Reg, False);
for j:=0 to Length(LangNs)-1 do if LangNs[j]=ReadString('', 'SourceLang', '') then Langs[0,0]:=j;
for j:=0 to Length(LangNs)-1 do if LangNs[j]=ReadString('', 'TargetLang', '') then Langs[2,0]:=j;
for j:=0 to ReadBinaryData('SourceWord', buf, 4096)-1 do if buf[j]<=NrChars[True, Langs[0,0]] then Add(0, buf[j]);
for j:=0 to Min(ReadBinaryData('SourceStress', buf, 4096), WordLen[0])-1 do if buf[j]>=1 then SetStress(0, j, TStress(buf[j]), False);
Ending[0]:=Word(ReadInteger('', 'SourceEnding', -1));
MorphBound[0]:=Word(ReadInteger('', 'SourceMorphBd', -1));
GheGloss[0]:=ReadString('', 'SourceGloss', '');
CharsBox.ItemIndex:=Max(Min(ReadInteger('', 'SourceLetter', 0), CharsBox.Items.Count-1), 0);
Caret[0,0]:=Max(Min(ReadInteger('', 'CaretPos', 0), WordLen[0]), 0);
Caret[0,1]:=Max(Min(ReadInteger('', 'CaretEnd', 0), WordLen[0]), 0);
if i>0 then begin
HistOpts[0]:=ReadInteger('', 'ZOptions', 255);
HistPopupClick(Neogrammarian);
WordLen[0]:=0;
end;
end;
CheckBox.Checked:=ReadBool('', 'CheckBox', False);
for i:=1 to High(ComboBoxIndices) do ComboBoxIndices[i]:=Max(Min(ReadInteger('', 'ComboBox'+IntToStr(i), ComboBoxDef[i]), ComboBoxNrs[i]-1), 0);
SemBtn.Down:=ReadBool('', 'Sememes', False);
SemBtnClick(SemBtn);
SmallBtn.Down:=ReadBool('', 'WinSmall', False);
SmallBtnClick(SmallBtn);
Left:=ReadInteger('', 'WinLeft', 100);
Top:=ReadInteger('', 'WinTop', 100);
if GetFileVersionInfo(PChar(Application.ExeName), 0, GetFileVersionInfoSize(PChar(Application.ExeName), w), @buf) then begin
VerQueryValue(@buf, '\', P, w);
ver[0]:=VS_FixedFileInfo(P^).dwFileVersionMS shr 16;
ver[1]:=VS_FixedFileInfo(P^).dwFileVersionMS and $FF;
ver[2]:=VS_FixedFileInfo(P^).dwFileVersionLS shr 16;
end else for i:=0 to 2 do ver[i]:=0;
VerLabel.Caption:='Version '+IntToStr(ver[0])+'.'+IntToStr(ver[1])+'.'+IntToStr(ver[2]);
dt:=CompileTime(Application.ExeName);
for i:=2*Ord(ver[2]<>0)+Ord((ver[1]<>0) and (ver[2]=0)) to 2 do WriteDate('CompileTime'+IntToStr(i), dt);
for i:=0 to 1 do try ct[i]:=DateToStr(ReadDate('CompileTime'+IntToStr(i))) except ct[i]:='??.??.????' end;
VerLabel.Hint:='Compiled'#13#10'V '+IntToStr(ver[0])+'.'+IntToStr(ver[1])+'.'+IntToStr(ver[2])+': '+DateTimeToStr(dt)
+Copy(#13#10'V '+IntToStr(ver[0])+'.'+IntToStr(ver[1])+'.0: '+ct[1], 1, 1000*Ord((ver[1]<>0) and (ver[2]<>0)))
+Copy(#13#10'V '+IntToStr(ver[0])+'.0.0: '+ct[0], 1, 1000*Ord((ver[1]<>0) or (ver[2]<>0)))
//+#13#10'V 6.0.0: 23.03.2020'
+#13#10'V 5.0.0: 21.11.2011'
+#13#10'V 4.0.0: October 2007'
+#13#10'V 1.0.0: 2006';
CopyrightLabel.Caption:='2006-'+FormatDateTime('yy', dt)+' by';
if ReadBool('Dict', 'WinShow', False) then DictForm.Show;
Free;
end;
CF_RTF:=RegisterClipboardFormat('Rich Text Format');
Application.OnShowHint:=AppShowHint;
Application.HintHidePause:=-1;
Application.OnActivate:=AppActivate;
Application.OnDeactivate:=AppDeactivate;
UpdateWord(False, '');
end;
end; {FormShow}
procedure TNeogrammarian.FormClose(Sender: TObject; var Action: TCloseAction);
begin
if DictForm.Changed then case DictForm.AskDictSave of
idYes: if not DictForm.SaveDict(True) then Action:=caNone;
idCancel: Action:=caNone;
end else if DictForm.ValidFileHandle then if not DictForm.SaveDict(True) then Action:=caNone;
Showdictionary.Tag:=Ord(DictForm.Visible);
end; {FormClose}
procedure TNeogrammarian.FormDestroy(Sender: TObject);
var i, j: Integer;
w: array[0..4095] of Byte;
begin
if SourceTree.Items.Count>0 then with TRegIniFile.Create(Reg) do begin
WriteBool('', 'InternalSort', InternalSort.Checked);
WriteBool('', 'CheckBox', CheckBox.Checked);
for i:=1 to High(ComboBoxIndices) do WriteInteger('', 'ComboBox'+IntToStr(i), ComboBoxIndices[i]);
WriteInteger('', 'ComboBox', ComboBox.ItemIndex);
WriteInteger('', 'WinLeft', Left);
WriteInteger('', 'WinTop', Top);
WriteBool('', 'WinSmall', not HidePanel1.Visible);
WriteBool('', 'Sememes', SemBtn.Down);
WriteInteger('Dict', 'WinShow', Showdictionary.Tag);
EraseSection('History');
WriteInteger('History', '', HistPopup.Items.Count);
for i:=0 to HistPopup.Items.Count do begin
WriteString('', 'SourceLang', LangNs[Langs[0,i]]);
WriteString('', 'TargetLang', LangNs[Langs[2,i]]);
for j:=0 to WordLen[-i]-1 do w[j]:=Words[-i,j];
WriteBinaryData('SourceWord', w, WordLen[-i]);
for j:=0 to WordLen[-i]-1 do w[j]:=Ord(GetStressDia(-i, j));
WriteBinaryData('SourceStress', w, WordLen[-i]);
WriteInteger('', 'SourceEnding', SmallInt(Ending[-i]));
WriteInteger('', 'SourceMorphBd', SmallInt(MorphBound[-i]));
if GheGloss[-i]<>'' then WriteString('', 'SourceGloss', GheGloss[-i]) else DeleteKey('', 'SourceGloss');
if (i>0) and (HistOpts[i]<255) then WriteInteger('', 'ZOptions', HistOpts[i]);
if i=0 then WriteInteger('', 'SourceLetter', CharsBox.ItemIndex) else WriteInteger('', 'SourceLetter', HistSourceLetter[i]);
WriteInteger('', 'CaretPos', Caret[i,0]);
WriteInteger('', 'CaretEnd', Caret[i,1]);
if i<HistPopup.Items.Count then OpenKey('\'+Reg+'\History\'+FormatFloat('00', i+1), True);
end;
Free;
end;
DestroyCaret;
end; {FormDestroy}
procedure TNeogrammarian.AppShowHint(var HintStr: string; var CanShow: Boolean; var HintInfo: THintInfo);
var n, m: Integer;
c: Char;
begin
with HintInfo do if HintControl.Owner=DictForm then DictForm.AppHint(HintStr, HintInfo) else if HintControl=CharsBox then begin
m:=CharsBox.ItemAtPos(CursorPos, True);
CursorRect:=CharsBox.ItemRect(m);
n:=SortChar(Langs[0,0], m);
if n<255 then begin
HintStr:='[no shortcut]';
for c:='Z' downto 'A' do if Map2[Langs[0,0], c]=n then HintStr:='Shift+'+c;
for c:='z' downto 'a' do if Map1[Langs[0,0], c]=n then HintStr:=UpperCase(c);
HintStr:=HintStr+' '+IfThen(n>=10, '#')+IntToStr(n);
end else HintStr:='Navigate with Ctrl + cursor keys';
end;
end; {AppShowHint}
procedure TNeogrammarian.AppActivate(Sender: TObject);
begin
if Active then begin
ActiveControl:=CharsBox;
CreateCaret(SourcePanel.Handle, 0, 2, 16);
SourceImage.Invalidate;
ShowCaret(SourcePanel.Handle);
end;
end; {AppActivate}
procedure TNeogrammarian.AppDeactivate(Sender: TObject);
begin
DestroyCaret;
end; {AppDeactivate}
procedure TNeogrammarian.PopupMeasureItem(Sender: TObject; ACanvas: TCanvas; var Width, Height: Integer);
begin
Height:=Canvas.TextHeight('A')+3;
Width:=(SourcePanel.Width-20) div (1+Ord(TMenuItem(Sender).Parent=SourceLangPopup.Items));
end; {PopupMeasureItem}
{----------------------------------------------------------Source language--------------------------------------------------------------}
procedure TNeogrammarian.SourceTreeChanging(Sender: TObject; Node: TTreeNode; var AllowChange: Boolean);
begin
with SourceTree do AllowChange:=Node.Level>0;
if AllowChange and (DictForm.CheckListBox.Tag=0) then HistPopupClick(nil);
end; {SourceTreeChanging}
procedure TNeogrammarian.SourceTreeChange(Sender: TObject; Node: TTreeNode);
var i: Integer;
m: TMenuItem;
begin
CharsBox.Items.Clear;
for i:=0 to NrChars[InternalSort.Checked, Langs[0,0]]-1 do CharsBox.Items.Add('');
if CharsBox.Items.Count>0 then CharsBox.ItemIndex:=0;
DictLinkS:=nil;
DictLinkT:=nil;
WordLen[0]:=0;
Ending[0]:=Word(-1);
MorphBound[0]:=Word(-1);
GheGloss[0]:='';
TargetBox.Items.Clear;
for i:=0 to Length(LangNs)-1 do if i in Desc[Langs[0,0]] then TargetBox.Items.AddObject(LongLangNs[i]+' (descendant, '+IntToYear(Dates[i])+')', Pointer(i));
Descendants:=TargetBox.Items.Count;
for i:=0 to Length(LangNs)-1 do if (Dates[i]=Dates[Langs[0,0]]) and (i<>Langs[0,0]) then
TargetBox.Items.AddObject(LongLangNs[i]+' (loans, '+IntToYear(Dates[i])+')', Pointer(i));
Loans:=TargetBox.Items.Count;
for i:=0 to Length(LangNs)-1 do if i in LLoans[Langs[0,0]] then TargetBox.Items.AddObject(LongLangNs[i]+' (academic loans, '+IntToYear(Dates[i])+')', Pointer(i));
for i:=0 to TargetLangPopup.Items.Count-1 do TargetLangPopup.Items.Delete(0);
for i:=0 to TargetBox.Items.Count-1 do begin
m:=TMenuItem.Create(self);
m.Caption:=TargetBox.Items[i];
m.RadioItem:=True;
m.Tag:=Integer(TargetBox.Items.Objects[i]);
m.OnClick:=TargetLangPopupClick;
m.OnMeasureItem:=PopupMeasureItem;
m.OnDrawItem:=LangPopupDrawItem;
TargetLangPopup.Items.Add(m);
end;
SourceLabel.Caption:='Source word ('+LongLangNs[Langs[0,0]]+')';
TargetBox.ItemIndex:=0;
if TargetBox.Visible then TargetBoxClick(nil);
for i:=0 to 1 do Caret[0,i]:=0;
DownBtn.Enabled:=not (Langs[0,0] in [lPIE, lGhe]);
DownBtn.Visible:=not (Langs[0,0]=lGhe);
DownBtn.Hint:='Make '+LongLangNs[Langs[0,0]]+' the target language (Cursor down)';
UpBtn.Enabled:=not ((Langs[0,0]=lNLem) and (Langs[2,0]=lModLem));
GheWordBtn.Visible:=Langs[0,0]=lGhe;
for i:=0 to SourceLangPopup.Items.Count-1 do if SourceLangPopup.Items[i].Tag=Integer(SourceTree.Selected.Data) then SourceLangPopup.Items[i].Checked:=True;
end; {SourceTreeChange}
procedure TNeogrammarian.SourceTreeClick(Sender: TObject);
begin
ActiveControl:=CharsBox;
SourceImage.Invalidate;
end; {SourceTreeClick}
procedure TNeogrammarian.SourceBtnClick(Sender: TObject);
var p: TPoint;
begin
p:=SourceBackPanel.ClientToScreen(Point(SourceBtn.Left, SourceBtn.Top+SourceBtn.Height));
SourceLangPopup.Popup(p.X, p.Y);
end; {SourceBtnClick}
procedure TNeogrammarian.SourceLangPopupClick(Sender: TObject);
var i: Integer;
begin
with SourceTree do for i:=0 to Items.Count-1 do if Integer(Items[i].Data)=TMenuItem(Sender).Tag then Selected:=Items[i];
end; {SourceLangPopupClick}
procedure TNeogrammarian.LangPopupDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
var p: Integer;
begin
with ACanvas, TMenuItem(Sender) do begin
Font.Assign(Neogrammarian.Font);
if Selected then begin
Font.Color:=clHighlightText;
Brush.Color:=RGBs[Tag];
end else begin
if Caption='-' then Font.Color:=clGray else Font.Color:=RGBs[Tag];
Brush.Color:=clMenu;
Pen.Color:=clGray;
end;
FillRect(Rect(ARect.Left+16, ARect.Top, ARect.Right, ARect.Bottom));
MoveTo(0, ARect.Bottom-1);
if (Parent=TargetLangPopup.Items) and (MenuIndex+1 in [Descendants, Loans]) and (MenuIndex+1<TargetLangPopup.Items.Count) then LineTo(ARect.Right, ARect.Bottom-1);
if Checked then ColourList.Draw(ACanvas, ARect.Left+2, ARect.Top+2, Tag+1);
if Caption='-' then begin
TextOut(ARect.Left+2, ARect.Top+1, SourceTree.Items[MenuIndex].Text+':');
MoveTo(ARect.Left, ARect.Top);
if MenuIndex>0 then LineTo(ARect.Right, ARect.Top);
end else begin
p:=Pos('(', Caption);
if p=0 then p:=1000;
if (p<1000) and (Caption[p+1]<>'d') then Font.Style:=[fsItalic];
TextOut(ARect.Left+18, ARect.Top+1, Copy(Caption, 1, p-1));
TextOut(ARect.Right div 2, ARect.Top+1, Copy(Caption, p, 1000));
end;
end;
end; {LangPopupDrawItem}
{----------------------------------------------------------Target language--------------------------------------------------------------}
procedure TNeogrammarian.TargetBoxClick(Sender: TObject);
var entry: PDictEntry;
begin
entry:=DictLinkS;
TargetLabel.Caption:='Target word ('+LongLangNs[Langs[2,0]]+')';
CheckBox.Visible:=False;
CheckBox.Checked:=False;
ComboBox.Visible:=False;
Caption:=LangNs[Langs[0,0]]+'>'+LangNs[Langs[2,0]]+' - Neogrammarian';
TargetLangPopup.Items[TargetBox.ItemIndex].Checked:=True;
AccentWarn.Visible:=(Langs[0,0]=lPIE) and (Langs[2,0] in [lEHell, lPrWald, lPrCelt])
or (Langs[0,0]=lEHell) and (Langs[2,0]=lKoi)
or (Langs[0,0]=lKoi) and (Langs[2,0]=lLMLem)
or (Langs[0,0]=lPrWald) and (Langs[2,0]=lElb)
or (Langs[0,0]=lLMLem) and (Langs[2,0]=lNLem);
DictLinkS:=entry;
DictLinkT:=nil;
UpdateWord(False, '¤');
if Addallwords.Checked then AddcurrwordsClick(nil);
end; {TargetBoxClick}
procedure TNeogrammarian.TargetBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
var p: Integer;
begin
with TargetBox do begin
p:=Pos('(', Items[Index]);
if odSelected in State then Canvas.Brush.Color:=RGBs[Integer(Items.Objects[Index])];
Canvas.FillRect(Rect);
if Items[Index][p+1]='d' then Canvas.Font.Style:=[] else Canvas.Font.Style:=[fsItalic];
Canvas.TextOut(Rect.Left+18, Rect.Top, Copy(Items[Index], 1, p-1));
Canvas.TextOut(Rect.Left+Width div 2, Rect.Top, Copy(Items[Index], p, 1000));
Canvas.Brush.Color:=clWindow;
Canvas.FillRect(Classes.Rect(Rect.Left, Rect.Top, Rect.Left+16, Rect.Bottom));
ColourList.Draw(Canvas, Rect.Left+2, Rect.Top+2, Integer(Items.Objects[Index])+1);
end;
end; {TargetBoxDrawItem}
procedure TNeogrammarian.TargetBtnClick(Sender: TObject);
var p: TPoint;
begin
p:=TargetBackPanel.ClientToScreen(Point(TargetBtn.Left, TargetBtn.Top+TargetBtn.Height));
TargetLangPopup.Popup(p.X, p.Y);
end; {TargetBtnClick}
procedure TNeogrammarian.TargetLangPopupClick(Sender: TObject);
begin
TargetBox.ItemIndex:=TMenuItem(Sender).MenuIndex;
TargetBoxClick(nil);
end; {TargetLangPopupClick}
{----------------------------------------------------------Source word--------------------------------------------------------------}
procedure TNeogrammarian.FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
var i: Integer;
c: Char;
begin
if (ActiveControl=CharsBox) and ((Shift=[]) or (Shift=[ssShift]) or (Shift=[ssShift, ssCtrl])) then begin
c:=#8;
case Key of
VK_Left: if ssCtrl in Shift then Caret[0,0]:=0 else Caret[0,0]:=Max(Caret[0,0]-1, 0);
VK_Right: if ssCtrl in Shift then Caret[0,0]:=WordLen[0] else Caret[0,0]:=Min(Caret[0,0]+1, WordLen[0]);
VK_Home: Caret[0,0]:=0;
VK_End: Caret[0,0]:=WordLen[0];
VK_Up: if (Shift=[]) and UpBtn.Enabled then UpBtnClick(nil);
VK_Down: if (Shift=[]) and DownBtn.Enabled then DownBtnClick(nil);
VK_Delete: if Shift=[] then if Caret[0,0]<>Caret[0,1] then FormKeyPress(Sender, c) else if Caret[0,0]<WordLen[0] then begin
Delete(0, Caret[0,0]);
UpdateWord(True, '');
end;
end;
if Key in [VK_Left, VK_Right, VK_Home, VK_End, VK_Up, VK_Down] then begin
if Shift=[] then Caret[0,1]:=Caret[0,0];
SourceImage.Invalidate;
Key:=0;
end;
end;
if ComboBox.Visible and (Shift=[ssAlt]) then with ComboBox do for i:=ItemIndex+1 to 2*Items.Count-2 do if (Items[i mod Items.Count]<>'')
and (Ord(Items[i mod Items.Count][1])=Key) then begin
ComboBox.ItemIndex:=i mod Items.Count;
UpdateWord(False, '¤');
Break;
end;
case Key of
VK_F2: if Shift=[] then SmallBtnClick(nil);
VK_F3: if Shift=[] then GheWordBtnClick(GheWordBtn);
VK_F4: if Shift=[] then SemBtnClick(nil);
VK_F7: if Shift-[ssShift]=[] then if CheckBox.Visible then CheckBox.Checked:=not CheckBox.Checked else if ComboBox.Visible then begin
if Shift=[] then ComboBox.ItemIndex:=(ComboBox.ItemIndex+1) mod ComboBox.Items.Count
else ComboBox.ItemIndex:=(ComboBox.ItemIndex+ComboBox.Items.Count-1) mod ComboBox.Items.Count;
UpdateWord(True, '¤');
end;
65{A}: if Shift=[ssCtrl] then begin
Caret[0,0]:=WordLen[0]; Caret[0,1]:=0;
SourceImage.Invalidate;
end;
67{C}: if ssCtrl in Shift then CopyBtnClick(CopyBtns[Ord(ssShift in Shift)]);
68{D}: if Shift=[ssCtrl] then AddallwordsClick(nil) else if Shift=[ssShift, ssCtrl] then ShowdictionaryClick(nil);
// 73{I}: if ssCtrl in Shift then ChangesBtnClick(ChangesBtn);
end;
end; {FormKeyDown}
procedure TNeogrammarian.FormKeyPress(Sender: TObject; var Key: Char);
var i: Integer;
begin
if ActiveControl=CharsBox then begin
case Key of
'a'..'z': InsAtCaret(Map1[Langs[0,0], Key]);
'A'..'Z': InsAtCaret(Map2[Langs[0,0], Key]);
'0'..'9': if InputNum=#0 then InsAtCaret(StrToInt(Key)) else if InputNum=#1 then InputNum:=Key else InsAtCaret(Max(Min(StrToInt(InputNum+Key), NrChars[True, Langs[0,0]]-1), 0));
'#': if InputNum=#1 then InputNum:=#0 else InputNum:=#1;
',', '.': SetStress(0, Caret[0,0]-1, TStress(Ord(Key='.')+2), True);
':': SetDia(0, Caret[0,0]-1, True);
'-': if Langs[0,0] in HyphenAllowed then if Langs[0,0] in HyphenEndOnly then begin
if Ending[0]=WordLen[0] then Ending[0]:=Word(-1) else Ending[0]:=WordLen[0];
end else begin
if Ending[0]=Caret[0,0] then Ending[0]:=Word(-1) else Ending[0]:=Caret[0,0];
end;
'/': if (FDictLinkS<>nil) then if MorphBound[0]=Caret[0,0] then MorphBound[0]:=Word(-1) else MorphBound[0]:=Caret[0,0];
'+': AddcurrwordsClick(nil);
' ': InsAtCaret(SortChar(Langs[0,0], CharsBox.ItemIndex));
#8: if Caret[0,0]<>Caret[0,1] then begin
HistPopupClick(nil);
for i:=Max(Caret[0,0], Caret[0,1])-1 downto Min(Caret[0,0], Caret[0,1]) do Delete(0, i);
Caret[0,0]:=Min(Caret[0,0], Caret[0,1]);
Caret[0,1]:=Caret[0,0];
end else if Caret[0,0]=Ending[0] then Ending[0]:=Word(-1) else if Caret[0,0]>0 then begin
for i:=0 to 1 do Dec(Caret[0,i]);
Delete(0, Caret[0,0]);
end;
#13: HistPopupClick(nil);
#26{Ctrl+Z}: if HistPopup.Items.Count>0 then HistPopup.Items[0].Click;
#27: if (DictLinkS<>nil) then begin
DictLinkS:=nil;
DictLinkT:=nil;
if Addallwords.Checked then AddallwordsClick(nil);
end else if (WordLen[0]=0) and (Ending[0]=Word(-1)) and (MorphBound[0]=Word(-1)) then begin
if (Langs[0,0]=lPIE) and (Langs[2,0]=lPrLem) then begin
Langs[0,0]:=lGhe; Langs[2,0]:=lMLem;
end else begin
Langs[0,0]:=lPIE; Langs[2,0]:=lPrLem;
end;
end else if Caret[0,0]<>Caret[0,1] then Caret[0,1]:=Caret[0,0] else begin
HistPopupClick(nil);
WordLen[0]:=0;
Ending[0]:=Word(-1);
MorphBound[0]:=Word(-1);
CheckBox.Checked:=False;
end;
end;
if not (Key in ['0'..'9', '#']) then InputNum:=#0;
if Key in ['a'..'z', 'A'..'Z', '0'..'9', ',', '.', ':', '-', '/', ' ', #8, #10{Ctrl+Enter}, #27] then UpdateWord(not (Key in [#10, #27]), '');
end;
end; {FormKeyPress}
procedure TNeogrammarian.SourceImageMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var i, j, w, cp: Integer;
begin
ActiveControl:=CharsBox;
cp:=1; w:=0;
for i:=-1 to WordLen[0] do begin
w:=CharWidth(DrawWords[0,i], i+1=Ending[0], i+1=MorphBound[0]);
if SourcePanel.ScreenToClient(Mouse.CursorPos).X<cp+w div 2 then Break else Inc(cp, w);
end;
if i=-1 then Inc(cp, w);
for j:=0 to 1 do Caret[0,j]:=Min(Max(i, 0), WordLen[0]);
SetCaretPos(cp, 1);
SourceImage.Invalidate;
end; {SourceImageMouseDown}
procedure TNeogrammarian.SourceImageMouseMove(Sender: TObject; Shift: TShiftState; X, Y: Integer);
var i, w, cp: Integer;
begin
if Shift=[ssLeft] then begin
cp:=1;
for i:=-1 to WordLen[0] do begin
w:=CharWidth(DrawWords[0,i], i+1=Ending[0], i+1=MorphBound[0]);
if SourcePanel.ScreenToClient(Mouse.CursorPos).X<cp+w div 2 then Break else Inc(cp, w);
end;
Caret[0,0]:=Min(Max(i, 0), WordLen[0]);
SourceImage.Invalidate;
end;
end; {SourceImageMouseMove}
function TNeogrammarian.DrawWord(i: Integer; ACanvas: TCanvas; ARect: TRect; ASelected, DrawLang: Boolean; Indent: Integer): string;
const lem: array[115..151] of string = ('a', 'à', 'e', 'è', 'y', 'y`', 'i', 'ì', 'o', 'ò', 'ö', 'ö`', 'u', 'ù', 'ü', 'ü`',
'gh', 'zh', 'z', 'dh', 'w', 'x', 'sh', 's', 'th', 'f', 'g', 'd', 'b', 'k', 't', 'p', 'ng', 'm', 'r', 'rh', 'l');
grc: array[61..112] of string = ('a', 'á', 'a:', 'â', 'ã', 'b', 'g', 'd', 'e', 'é', 'e:', 'ê', 'e~', 'w', 'z', 'th', 'i', 'í', 'i:', 'î', 'i~', 'k',
'l', 'l°', 'm', 'n', 'x', 'o', 'ó', 'o:', 'ô', 'õ', 'p', 'q', 'r', 'r°', 'rh', 's', 't', 'u', 'ú', 'u:', 'û', 'u~', 'ph', 'kh', 'ps', 'hw', 's', 'h', '', 'h');
var k, w, dw: Integer;
bmp: TBitmap;
begin
Result:='';
bmp:=TBitmap.Create;
with ACanvas.Brush do if ASelected then Color:=RGBsB[Langs[i,0]] else if i=3 then Color:=clWindow else Color:=cl3DLight;
ACanvas.FillRect(ARect);
ACanvas.CopyMode:=cmMergeCopy;
with ACanvas do w:=ARect.Left+2+TextWidth('m')*Indent;
if DrawLang then with ACanvas do begin
Font.Color:=RGBs[Langs[i,0]];
Font.Style:=[fsItalic];
TextOut(w, ARect.Top+2, LangNs[Langs[i,0]]);
Inc(w, TextWidth('ModLem '));
end;
with ACanvas do for k:=-1 to WordLen[i] do begin
dw:=DrawWords[i,k];
if dw>-1 then begin
CharList.GetBitmap(dw, bmp);
if (i=0) and ((k<Caret[0,0]) xor (k<Caret[0,1])) then CopyMode:=cmNotSrcCopy else CopyMode:=cmMergeCopy;
Draw(w, ARect.Top+1, bmp);
if GetDia(i, k)=diaYes then begin
CharList.GetBitmap(chDiaeresis, bmp);
CopyMode:=cmSrcAnd;
Draw(w+(CharWidth(dw)-CharWidth(chDiaeresis)) div 2, ARect.Top+1, bmp);
end;
end else FillRect(Rect(w, ARect.Top, w+16, ARect.Bottom));
Inc(w, CharWidth(dw, k+1=Ending[i], k+1=MorphBound[i]));
if k+1=MorphBound[i] then begin
CharList.GetBitmap(chMorphBound, bmp);
Draw(w-CharWidth(chMorphBound)-Ord(k+1=Ending[i])*CharWidth(chEnding), ARect.Top+1, bmp);
end;
if k+1=Ending[i] then begin
CharList.GetBitmap(chEnding, bmp);
Draw(w-CharWidth(chEnding), ARect.Top+1, bmp);
end;
if (i=0) and (k=Caret[0,0]-1) then SetCaretPos(w-1, 1);
if Langs[i,0] in [lMLem..lModLem, lKoi, lOTroy, lNTroy] then Result:=Result+IfThen(k=Ending[i], '-')+IfThen(k=MorphBound[i], '/');
if Langs[i,0] in [lMLem..lModLem] then begin
if dw in [Low(lem)..High(lem)] then Result:=Result+lem[dw] else if dw=chFullstop then Result:=Result+'.';
end else if Langs[i,0] in [lKoi, lOTroy, lNTroy] then begin
if (dw=67{gamma}) and (DrawWords[i,k+1] in [67, 82, 87, 106]) then dw:=86{ny};
if dw in [Low(grc)..High(grc)] then Result:=Result+IfThen((GetDia(i, k)=diaYes) and (Ending[i]<>k), '·')+grc[dw];
if (dw=109{sh}) and (Langs[i,0]=lNTroy) then Result:=Result+'h';
end;
end;
bmp.Free;
end; {DrawWord}
procedure TNeogrammarian.ImagePaint(Sender: TObject);
begin
with TPaintBox(Sender) do Hint:=DrawWord(Tag, Canvas, Rect(0, 0, Width, Height), True, False, 0);
end; {ImagePaint}
procedure TNeogrammarian.SourcePopupPopup(Sender: TObject);
const Imgs: array[0..High(LangNs)] of SmallInt = (0, 0, 0, 0, 3, 0, 3, 0, 0, 0, 2, 0, 2, 0, 1, 0, 0, 0, 0);
var i, j: Integer;
begin
ActiveControl:=CharsBox;
if SourcePopup.PopupComponent<>SourceImage then
if SourcePopup.PopupComponent=CharsBox then CharsBox.ItemIndex:=CharsBox.ItemAtPos(CharsBox.ScreenToClient(Mouse.CursorPos), False);
InsertLetter.Bitmap:=nil;
CharList.GetBitmap(CharIds[Langs[0,0], SortChar(Langs[0,0], CharsBox.ItemIndex)], InsertLetter.Bitmap);
for i:=0 to 1 do with TMenuItem(FindComponent('ToggleAccent'+IntToStr(i+1))) do begin
Enabled:=False;
for j:=0 to WordLen[0]-1 do if GetStress(0, j, TStress(i+2))>stCant then Enabled:=True;
if Enabled then ImageIndex:=2*Imgs[Langs[0,0]]+i else ImageIndex:=-1;
end;
ToggleDiaeresis.Enabled:=False;
for j:=0 to WordLen[0]-1 do if GetDia(0, j)>diaCant then ToggleDiaeresis.Enabled:=True;
if ToggleDiaeresis.Enabled then ToggleDiaeresis.ImageIndex:=12+Ord(Langs[0,0] in [lKoi..lNTroy]) else ToggleDiaeresis.ImageIndex:=-1;
ToggleHyphen.Enabled:=Langs[0,0] in HyphenAllowed;
ToggleHyphen.ImageIndex:=12*Ord(ToggleHyphen.Enabled)-1;
ToggleMorphbound.Visible:=FDictLinkS<>nil;
if DictLinkS<>nil then EscapeWord.Caption:='Stop editing dictionary word' else if WordLen[0]>0 then EscapeWord.Caption:='Clear source word'
else if (Langs[0,0]=lPIE) and (Langs[2,0]=lPrLem) then EscapeWord.Caption:='Ghe > MLem' else EscapeWord.Caption:='PIE > PrLem';
EscapeWord.ImageIndex:=7+3*Ord(WordLen[0]=0);
AddToHistory.Enabled:=WordLen[0]>0;
Undo.Enabled:=HistPopup.Items.Count>0;
InternalSort.Visible:=SourcePopup.PopupComponent=CharsBox;
N5.Visible:=InternalSort.Visible;
SourcePopup.PopupComponent:=nil;
end; {SourcePopupPopup}
procedure TNeogrammarian.SourcePopupClick(Sender: TObject);
var ch: Char;
begin
ch:=Char(TMenuItem(Sender).Tag);
FormKeyPress(nil, ch);
end; {SourcePopupClick}
procedure TNeogrammarian.InternalSortClick(Sender: TObject);
var i: Integer;
begin
InternalSort.Checked:=not InternalSort.Checked;
CharsBox.Items.Clear;
for i:=0 to NrChars[InternalSort.Checked, Langs[0,0]]-1 do CharsBox.Items.Add('');
if CharsBox.Items.Count>0 then CharsBox.ItemIndex:=0;
end; {InternalSortClick}
procedure TNeogrammarian.HistBtnClick(Sender: TObject);
var p: TPoint;
begin
p:=SourcePanel.ClientToScreen(Point(0, HistBtn.Height));
HistPopup.Popup(p.X, p.Y);
ActiveControl:=CharsBox;
end; {HistBtnClick}
procedure TNeogrammarian.HistPopupClick(Sender: TObject);
procedure DelHistItem(Nr: Integer);
var i, j: Integer;
begin
for i:=Nr+1 to HistPopup.Items.Count do begin
for j:=0 to 1 do Langs[2*j,i-1]:=Langs[2*j,i];
WordLen[-i+1]:=WordLen[-i];
for j:=0 to WordLen[-i]-1 do WordsStressDia[-i+1, j, GetStressDia(-i, j)]:=Words[-i,j];
Ending[-i+1]:=Ending[-i];
MorphBound[-i+1]:=MorphBound[-i];
GheGloss[-i+1]:=GheGloss[-i];
HistOpts[i-1]:=HistOpts[i];
HistSourceLetter[i-1]:=HistSourceLetter[i];
for j:=0 to 1 do Caret[i-1,j]:=Caret[i,j];
end;
HistPopup.Items.Delete(Nr-1);
HistBtn.Enabled:=HistPopup.Items.Count>0;
end; {DelHistItem}
var i, j, d, n: Integer;
m: TMenuItem;
begin
m:=nil;
if WordLen[0]>0 then begin
HistBtn.Enabled:=True;
for i:=MaxHist downto 0 do begin
for j:=0 to 1 do Langs[2*j,i+1]:=Langs[2*j,i];
WordLen[-i-1]:=WordLen[-i];
for j:=0 to WordLen[-i]-1 do WordsStressDia[-i-1, j, GetStressDia(-i, j)]:=Words[-i,j];
Ending[-i-1]:=Ending[-i];
MorphBound[-i-1]:=MorphBound[-i];
GheGloss[-i-1]:=GheGloss[-i];
if (i>0) or (Sender=Neogrammarian) then HistOpts[i+1]:=HistOpts[i] else if CheckBox.Visible then HistOpts[i+1]:=Ord(CheckBox.Checked) else
if ComboBox.Visible then HistOpts[i+1]:=ComboBox.ItemIndex else HistOpts[i+1]:=255;
if i>0 then HistSourceLetter[i+1]:=HistSourceLetter[i] else HistSourceLetter[i+1]:=CharsBox.ItemIndex;
for j:=0 to 1 do Caret[i+1,j]:=Caret[i,j];
end;
m:=TMenuItem.Create(self);
m.OnClick:=HistPopupClick;
m.OnMeasureItem:=PopupMeasureItem;
m.OnDrawItem:=HistPopupDrawItem;
HistPopup.Items.Insert(0, m);
end;
if (Sender<>nil) and (Sender<>Neogrammarian) then begin
n:=TMenuItem(Sender).MenuIndex+1;
WordLen[0]:=0;
for i:=0 to 1 do Langs[2*i,0]:=Langs[2*i,n];
WordLen[0]:=WordLen[-n];
for i:=0 to WordLen[0]-1 do WordsStressDia[0, i, GetStressDia(-n, i)]:=Words[-n, i];
Ending[0]:=Ending[-n];
MorphBound[0]:=MorphBound[-n];
GheGloss[0]:=GheGloss[-n];
CharsBox.ItemIndex:=HistSourceLetter[n];
for j:=0 to 1 do Caret[0,j]:=Caret[n,j];
if CheckBox.Visible then CheckBox.Checked:=HistOpts[n]=1 else if ComboBox.Visible then ComboBox.ItemIndex:=HistOpts[n];
UpdateWord(False, '¤');
DelHistItem(n);
end;
d:=0;
for i:=2 to HistPopup.Items.Count do begin
if (Langs[0,i]=Langs[0,1]) and (Langs[2,i]=Langs[2,1]) and (WordLen[-i]=WordLen[-1]) and (Ending[-i]=Ending[-1]) and (MorphBound[-i]=MorphBound[-1]) then d:=i;
if d>0 then for j:=0 to WordLen[-i]-1 do if (Words[-i,j]<>Words[-1,j]) or (GetStressDia(-i, j)<>GetStressDia(-1, j)) then d:=0;
if d>0 then Break;
end;
if d>0 then DelHistItem(d);
if (HistPopup.Items.Count>MaxHist) and (m<>nil) then HistPopup.Items.Delete(MaxHist);
end; {HistPopupClick}
procedure TNeogrammarian.HistPopupDrawItem(Sender: TObject; ACanvas: TCanvas; ARect: TRect; Selected: Boolean);
begin
ACanvas.Font.Assign(Font);
DrawWord(-1-TMenuItem(Sender).MenuIndex, ACanvas, ARect, Selected, True, 0);
ACanvas.FillRect(Rect(ARect.Right-ACanvas.TextWidth('> ModLem'), ARect.Top, ARect.Right, ARect.Bottom));
ACanvas.Font.Color:=RGBs[Langs[2, TMenuItem(Sender).MenuIndex+1]];
ACanvas.TextOut(ARect.Right-ACanvas.TextWidth('> ModLem'), ARect.Top+2, '> '+LangNs[Langs[2, TMenuItem(Sender).MenuIndex+1]]);
ACanvas.Font.Color:=clBlack;
ACanvas.Font.Style:=[];
if GheGloss[-1-TMenuItem(Sender).MenuIndex]<>'' then ACanvas.TextOut(ARect.Right div 2, ARect.Top+2, ''+GheGloss[-1-TMenuItem(Sender).MenuIndex]+'');
ACanvas.Brush.Style:=bsClear;
ACanvas.Pen.Color:=clGrayText;
if Selected then with ARect do ACanvas.Rectangle(Left, Top, Right, Bottom);
end; {HistPopupDrawItem}
procedure TNeogrammarian.CharsBoxMouseDown(Sender: TObject; Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var p: Integer;
begin
p:=CharsBox.ItemAtPos(CharsBox.ScreenToClient(Mouse.CursorPos), True);
if (Button=mbLeft) and (p>-1) then begin
InsAtCaret(SortChar(Langs[0,0], CharsBox.ItemIndex));
UpdateWord(True, '');
end;
end; {CharsBoxMouseDown}
procedure TNeogrammarian.CharsBoxDrawItem(Control: TWinControl; Index: Integer; Rect: TRect; State: TOwnerDrawState);
begin
CharsBox.Canvas.Brush.Color:=clWindow;
CharsBox.Canvas.FillRect(Rect);
CharList.Draw(CharsBox.Canvas, Rect.Left+12, Rect.Top, CharIds[Langs[0,0], SortChar(Langs[0,0], Index)]);
end; {CharsBoxDrawItem}
{----------------------------------------------------------Buttons & remarks--------------------------------------------------------------}
procedure TNeogrammarian.DownBtnClick(Sender: TObject);
var l, i: Integer;
begin
l:=Langs[0,0];
for i:=0 to Length(LangNs)-1 do if Langs[0,0] in Desc[i] then Langs[0,0]:=i;
Langs[2,0]:=l;
end; {DownBtnClick}
procedure TNeogrammarian.UpBtnClick(Sender: TObject);
var i, e: Integer;
w, sd: ByteArray;
entry: PDictEntry;
begin
entry:=DictLinkT;
SetLength(w, WordLen[2]);
SetLength(sd, WordLen[2]);
for i:=0 to WordLen[2]-1 do w [i]:=Words[2,i];
for i:=0 to WordLen[2]-1 do sd[i]:=GetStressDia(2, i);
e:=Ending[2];
Langs[0,0]:=Langs[2,0];
WordLen[0]:=Length(w);
for i:=0 to WordLen[0]-1 do WordsStressDia[0, i, sd[i]]:=w[i];
Ending[0]:=e;
MorphBound[0]:=Word(-1);
for i:=0 to 1 do Caret[0,i]:=WordLen[0];
DictLinkS:=entry;
DictLinkT:=nil;
UpdateWord(False, '');
if Addallwords.Checked then AddcurrwordsClick(nil);
end; {UpBtnClick}
procedure TNeogrammarian.GheWordBtnClick(Sender: TObject);
function GheChar(t: Byte; P: array of Real; zero: Real): Byte;
var i: Integer;
r, m: Real;
begin
r:=Min(Random/zero, 1);
Result:=255;
m:=0;
for i:=0 to Length(P)-1 do begin
m:=m+P[i];
if r<m then begin
Result:=t+i;
Break;
end;
end;
end;
const tVowel=0; tCons=12; tModif=20;
glosses: array[0..30] of string =
('zero', 'opposite', 'one', 'ten', 'eleven', 'twelve', 'thirteen', 'fourteen', 'fifteen', 'several', 'each',
'yes', 'no', 'and', 'or', 'xor',
'do', 'make', 'go', 'eat', 'mow',
'cat', 'dog', 'chicken', 'ship', 'meadow', 'identity',
'male', 'female', 'woman', 'green');
translations: array[0..30, 0..3] of Byte =
((0, 15, 24, 99), (18, 99, 99, 99), (16, 21, 99, 99), (1, 15, 22, 99), (1, 2, 13, 24), (13, 21, 99, 99), (2, 17, 15, 99), (1, 12, 22, 99), (18, 23, 99, 99), (16, 23, 99, 99), (19, 22, 99, 99),
(0, 99, 99, 99), (3, 99, 99, 99), (2, 99, 99, 99), (1, 99, 99, 99), (4, 99, 99, 99),
(16, 23, 99, 99), (14, 99, 99, 99), (15, 20, 99, 99), (5, 15, 18, 99), (2, 17, 17, 20),
(0, 19, 24, 99), (1, 19, 13, 22), (1, 14, 18, 99), (0, 18, 19, 99), (3, 13, 13, 22), (2, 14, 22, 99),
(12, 25, 99, 99), (12, 22, 99, 99), (12, 22, 99, 99), (16, 15, 23, 99));
var i, j, l, s: Integer;
b: Boolean;
st: string;
begin
DestroyCaret;
GheWordForm.GlossEdit.Text:='';
GheWordForm.ActiveControl:=GheWordForm.GlossEdit;
if (Langs[0,0]=lGhe) and (GheWordForm.ShowModal=idOK) then begin
DictLinkS:=nil;
DictLinkT:=nil;
st:=LowerCase(GheWordForm.GlossEdit.Text);
l:=0;
b:=True;
for i:=1 to Length(st) do if not (st[i] in ['a'..'z']) then b:=False else if (st[i] in ['a', 'e', 'i', 'o', 'u', 'y']) and
((i=0) or not (st[i-1] in ['a', 'e', 'i', 'o', 'u', 'y'])) and not ((i=Length(st)) and (st[i]='e')) then Inc(l, 2) else Inc(l);
if b then begin
HistPopupClick(nil);
WordLen[0]:=0;
for i:=0 to High(glosses) do if st=glosses[i] then for j:=High(translations[0]) downto 0 do if translations[i,j]<99 then Insert(0, 0, translations[i,j]);
if WordLen[0]=0 then while Length(st)>0 do begin
s:=0;
for i:=1 to Min(7, Length(st)) do s:=27*s+(Ord(st[i])-96);
RandSeed:=s;
Insert(0, 0, GheChar(tModif, [0.1, 0.1, 0.1, 0.1, 0.1, 0.1], 1));
for i:=1 to 3 do Insert(0, 0, GheChar(tCons, [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.1], l/(5+WordLen[0])));
if (Words[0,0] in [tModif..25]) or ((Words[0,0]<255) and (Words[0,0]=Words[0,1]) and (Words[0,1]=Words[0,2])) then Delete(0, 0);
Insert(0, 0, GheChar(tVowel, [0.1, 0.1, 0.1, 0.1, 0.1, 0.1, 0.05, 0.05, 0.05, 0.05, 0.05, 0.05], l/3));
if Random<0.2 then if Words[0,0] in [0..2] then Insert(0, 1, 2) else if Words[0,0] in [3..5] then Insert(0, 1, 5);
st:=Copy(st, Random(WordLen[0])+4, 1000);
l:=Max(l-WordLen[0], 1);
end;
Ending[0]:=WordLen[0];
MorphBound[0]:=Word(-1);
case GheWordForm.SpeechPartGroup.ItemIndex of
0: Add(0, 0);
1: Add(0, 6);
2: Add(0, 8);
3: Add(0, 11);
4: Ending[0]:=Word(-1);
end;
for i:=0 to 1 do Caret[0,i]:=WordLen[0];
UpdateWord(False, '');
GheGloss[0]:=GheWordForm.GlossEdit.Text;
if Addallwords.Checked then AddcurrwordsClick(nil);
end else TangoMessageBox('Invalid character(s)! Only the letters a to z are allowed.', mtError, [mbOK], '');
end;
AppActivate(nil);
end; {GheWordBtnClick}
procedure TNeogrammarian.CopyBtnClick(Sender: TObject);
var a, b, a1, b1, l: Integer;
H: THandle;
RTF, st: string;
lem: Boolean;
P: PChar;
begin
with TSpeedButton(Sender) do if Enabled then with Clipboard do begin
if (Tag=0) and (Caret[0,0]<>Caret[0,1]) then begin
a1:=Caret[0,0];
b1:=Caret[0,1];
a:=Min(a1, b1);
b:=Max(a1, b1)-1;
end else begin
a:=-1; b:=WordLen[Tag];
end;
Open;
Clear;
l:=Langs[Tag, 0];
CopyRTFasUnicode('<abbr title="'+LongLangNs[l]+'">'+LangNs[l]+'</abbr> '+MakeWordHTML(Tag, a, b, 'span', False, st, lem));
RTF:='{\rtf1\ansi{\fonttbl{\f0\fnil\fcharset0 Gentium plus;}{\f2\fnil\fcharset0 Lemizh;}}\pard\fs24\f'+IntToStr(2*Ord(lem))+st+'}';
H:=GlobalAlloc(gmem_Moveable, Length(RTF)+1);
P:=GlobalLock(H);
StrPCopy(P, RTF);
GlobalUnlock(H);
SetAsHandle(CF_RTF, H);
Close;
end;
end; {CopyBtnClick}
procedure TNeogrammarian.DictBtnClick(Sender: TObject);
var p: TPoint;
begin
p:=SourceBackPanel.ClientToScreen(Point(DictBtn.Left, DictBtn.Top+DictBtn.Height));
DictPopup.Popup(p.X, p.Y);
end; {DictBtnClick}
procedure TNeogrammarian.DictPopupPopup(Sender: TObject);
begin
Addcurrwords.Enabled:=(WordLen[0]>0) and (WordLen[2]>0);
AddPIEparticiple1.Visible:=(Langs[0,0]=lPIE) and ComboBox.Visible and (ComboBox.ItemIndex in [0..17, 20..24]);
AddPIEparticiple2.Visible:=AddPIEparticiple1.Visible and not (ComboBox.ItemIndex=24);
end; {DictPopupPopup}
procedure TNeogrammarian.AddallwordsClick(Sender: TObject);