1 | unit fHanSpell;
|
---|
2 | {Copyright © 2008, Gary Darby, www.DelphiForFun.org
|
---|
3 | This program may be used or modified for any non-commercial purpose
|
---|
4 | so long as this original notice remains in place.
|
---|
5 | All other rights are reserved
|
---|
6 | }
|
---|
7 |
|
---|
8 | {A program to quickly highlight a predefined set of words with specified colors
|
---|
9 | in a RichEdit control. Technique to intercept WindowProc is converted from
|
---|
10 | Basic code provided by Emile Tredoux to Delphi.
|
---|
11 | }
|
---|
12 |
|
---|
13 | interface
|
---|
14 |
|
---|
15 | uses
|
---|
16 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
---|
17 | StdCtrls, ComCtrls, RichEdit, Buttons, ExtCtrls, ShellAPI,
|
---|
18 | skaSpellCheck,
|
---|
19 | VA508AccessibilityManager, fBase508Form;
|
---|
20 |
|
---|
21 | type
|
---|
22 | TfrmHunSpell = class(TfrmBase508Form)
|
---|
23 | lblDictionary: TLabel;
|
---|
24 | btnClose: TButton;
|
---|
25 | OpenDialog1: TOpenDialog;
|
---|
26 | SpellCheck1: TskaHunSpellChecker;
|
---|
27 | Edit1: TEdit;
|
---|
28 | btnSelectDict: TBitBtn;
|
---|
29 | Label3: TLabel;
|
---|
30 | Label2: TLabel;
|
---|
31 | RichEdit1: TRichEdit;
|
---|
32 | pnlMisSpelled: TPanel;
|
---|
33 | Label1: TLabel;
|
---|
34 | lstSuggestions: TListBox;
|
---|
35 | Label4: TLabel;
|
---|
36 | Edit2: TEdit;
|
---|
37 | btnAutoCorrect: TButton;
|
---|
38 | btnChangeAll: TButton;
|
---|
39 | btnChange: TButton;
|
---|
40 | btnAddToDictionary: TButton;
|
---|
41 | btnIgnoreAll: TButton;
|
---|
42 | btnIgnoreOnce: TButton;
|
---|
43 | btnCancel: TButton;
|
---|
44 | procedure FormCreate(Sender: TObject);
|
---|
45 | procedure btnIgnoreOnceClick(Sender: TObject);
|
---|
46 | procedure btnIgnoreAllClick(Sender: TObject);
|
---|
47 | procedure btnChangeClick(Sender: TObject);
|
---|
48 | procedure btnChangeAllClick(Sender: TObject);
|
---|
49 | procedure btnCloseClick(Sender: TObject);
|
---|
50 | procedure FormActivate(Sender: TObject);
|
---|
51 | procedure btnSelectDictClick(Sender: TObject);
|
---|
52 | procedure Edit1Enter(Sender: TObject);
|
---|
53 | procedure btnAutoCorrectClick(Sender: TObject);
|
---|
54 | procedure btnAddToDictionaryClick(Sender: TObject);
|
---|
55 | procedure FormShow(Sender: TObject);
|
---|
56 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
57 | procedure btnCancelClick(Sender: TObject);
|
---|
58 | private
|
---|
59 | { Private declarations }
|
---|
60 | NoEngineOpted: Boolean;
|
---|
61 | FSourceControl: TCustomMemo;
|
---|
62 | WaitForUser: Boolean;
|
---|
63 |
|
---|
64 | public
|
---|
65 | { Public declarations }
|
---|
66 | Showhighlight:boolean;
|
---|
67 | highlightcolor:TColor;
|
---|
68 | HighLightList:TStringlist;
|
---|
69 | OldRichEditWndProc: {integer}pointer;
|
---|
70 | PRichEditWndProc:pointer;
|
---|
71 | class function DoHanSpellCheck(AnEditControl: TCustomMemo): TModalResult; static;
|
---|
72 | end;
|
---|
73 |
|
---|
74 | var
|
---|
75 | frmHunSpell: TfrmHunSpell;
|
---|
76 |
|
---|
77 | implementation
|
---|
78 | {$R *.DFM}
|
---|
79 |
|
---|
80 | uses uSpell, VAUtils;
|
---|
81 |
|
---|
82 | class function TfrmHunSpell.DoHanSpellCheck(AnEditControl: TCustomMemo): TModalResult;
|
---|
83 | var
|
---|
84 | frm: TfrmHunSpell;
|
---|
85 | begin
|
---|
86 | Result := mrCancel;
|
---|
87 | frm:= TfrmHunSpell.create(Application);
|
---|
88 | try
|
---|
89 | frm.RichEdit1.Text:= AnEditControl.Text;
|
---|
90 | frm.FSourceControl := AnEditControl;
|
---|
91 | Result := frm.ShowModal;
|
---|
92 | finally
|
---|
93 | frm.Free;
|
---|
94 | end;
|
---|
95 | end;
|
---|
96 |
|
---|
97 | {************ HighLight ***********888}
|
---|
98 | procedure TfrmHunSpell.FormShow(Sender: TObject);
|
---|
99 | begin
|
---|
100 | if SpellCheck1.SpellCheckState = ssNotStarted then
|
---|
101 | SpellCheck1.CheckSpelling;
|
---|
102 | end;
|
---|
103 |
|
---|
104 | {************* FormCreate **********}
|
---|
105 | procedure TfrmHunSpell.btnAddToDictionaryClick(Sender: TObject);
|
---|
106 | begin
|
---|
107 | SpellCheck1.AddCustomWord;
|
---|
108 | end;
|
---|
109 |
|
---|
110 | procedure TfrmHunSpell.btnAutoCorrectClick(Sender: TObject);
|
---|
111 | begin
|
---|
112 | SpellCheck1.CorrectWithMyWord;
|
---|
113 | end;
|
---|
114 |
|
---|
115 | procedure TfrmHunSpell.btnCancelClick(Sender: TObject);
|
---|
116 | begin
|
---|
117 | if SpellCheck1.AbortSpellCheck(True) then
|
---|
118 | Close;
|
---|
119 | end;
|
---|
120 |
|
---|
121 | procedure TfrmHunSpell.btnChangeAllClick(Sender: TObject);
|
---|
122 | begin
|
---|
123 | SpellCheck1.ChangeAll;
|
---|
124 | end;
|
---|
125 |
|
---|
126 | procedure TfrmHunSpell.btnChangeClick(Sender: TObject);
|
---|
127 | begin
|
---|
128 | SpellCheck1.Change;
|
---|
129 | end;
|
---|
130 |
|
---|
131 | procedure TfrmHunSpell.btnCloseClick(Sender: TObject);
|
---|
132 | begin
|
---|
133 | close;
|
---|
134 | end;
|
---|
135 |
|
---|
136 | procedure TfrmHunSpell.btnIgnoreAllClick(Sender: TObject);
|
---|
137 | begin
|
---|
138 | SpellCheck1.IgnoreAll;
|
---|
139 | end;
|
---|
140 |
|
---|
141 | procedure TfrmHunSpell.btnIgnoreOnceClick(Sender: TObject);
|
---|
142 | begin
|
---|
143 | SpellCheck1.IgnoreOnce;
|
---|
144 | end;
|
---|
145 |
|
---|
146 | procedure TfrmHunSpell.btnSelectDictClick(Sender: TObject);
|
---|
147 | var
|
---|
148 | aff: String;
|
---|
149 | begin
|
---|
150 | if OpenDialog1.Execute then
|
---|
151 | begin
|
---|
152 | if SpellCheck1.DictFileName = OpenDialog1.FileName then
|
---|
153 | exit;
|
---|
154 |
|
---|
155 | aff := ChangeFileExt(OpenDialog1.FileName, '.aff');
|
---|
156 | if not FileExists(aff) then
|
---|
157 | begin
|
---|
158 | ShowMessage('Correspong AFF file named "'+ aff + '" not found!' + #13 + ' Specify dictionary file whose *.aff is also present in same directory.');
|
---|
159 | OpenDialog1.FileName := '';
|
---|
160 | btnSelectDictClick(self);
|
---|
161 | end
|
---|
162 | else
|
---|
163 | begin
|
---|
164 | if SpellCheck1.SpellCheckState = ssChecking then
|
---|
165 | SpellCheck1.AbortSpellCheck(False);
|
---|
166 | Edit1.Text := OpenDialog1.FileName;
|
---|
167 | SpellCheck1.DictFileName := OpenDialog1.FileName;
|
---|
168 | SpellCheck1.AffFileName := aff;
|
---|
169 | SpellCheck1.Open;
|
---|
170 | WaitForUser := False;
|
---|
171 | SpellCheck1.CheckSpelling;
|
---|
172 | end;
|
---|
173 | end;
|
---|
174 | end;
|
---|
175 |
|
---|
176 | procedure TfrmHunSpell.Edit1Enter(Sender: TObject);
|
---|
177 | begin
|
---|
178 | btnSelectDict.SetFocus;
|
---|
179 | end;
|
---|
180 |
|
---|
181 | procedure TfrmHunSpell.FormActivate(Sender: TObject);
|
---|
182 | begin
|
---|
183 | if ( not SpellCheck1.Active) and (not NoEngineOpted) then
|
---|
184 | begin
|
---|
185 | btnSelectDictClick(self);
|
---|
186 | NoEngineOpted := True;
|
---|
187 | end;
|
---|
188 | end;
|
---|
189 |
|
---|
190 | procedure TfrmHunSpell.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
191 | begin
|
---|
192 | if SpellCheck1.SpellCheckState = ssCompleted then
|
---|
193 | begin
|
---|
194 | ShowMsg(TX_SPELL_COMPLETE, TShow508MessageIcon(1), smbOK) ;
|
---|
195 | if Assigned(FSourceControl) then
|
---|
196 | FSourceControl.Text := RichEdit1.Text;
|
---|
197 | end
|
---|
198 | else
|
---|
199 | ShowMsg(TX_SPELL_CANCELLED + CRLF + TX_NO_CORRECTIONS,TShow508MessageIcon(1), smbOK) ;
|
---|
200 | end;
|
---|
201 |
|
---|
202 | procedure TfrmHunSpell.FormCreate(Sender: TObject);
|
---|
203 | begin
|
---|
204 | if FileExists(ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.dic')
|
---|
205 | and FileExists(ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.aff') then
|
---|
206 | begin
|
---|
207 | SpellCheck1.AffFileName := ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.aff';
|
---|
208 | SpellCheck1.DictFileName := ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.dic';
|
---|
209 | Edit1.Text := SpellCheck1.DictFileName;
|
---|
210 | SpellCheck1.Active := True;
|
---|
211 | end
|
---|
212 | else
|
---|
213 | Edit1.Text := 'Dictionary File for SpellCheck Engine not found!';
|
---|
214 | SpellCheck1.SourceTextControl := RichEdit1;
|
---|
215 | SpellCheck1.SuggestionList := lstSuggestions;
|
---|
216 | SpellCheck1.HighlightEditControl := Edit2;
|
---|
217 | SpellCheck1.btnClose := btnClose;
|
---|
218 | end;
|
---|
219 |
|
---|
220 |
|
---|
221 |
|
---|
222 | end.
|
---|