1 | unit fHunSpell;
|
---|
2 | (* ***************************** BEGIN LICENSE BLOCK **********************
|
---|
3 | *
|
---|
4 | * Copyright (C) 2015
|
---|
5 | * Sunil Kumar Arora (digitiger@gmail.com sunil@healthsevak.com)
|
---|
6 | * All Rights Reserved.
|
---|
7 | * Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
---|
8 | *
|
---|
9 | * The contents of this file are subject to the Mozilla Public License Version
|
---|
10 | * 1.1 (the "License"); you may not use this file except in compliance with
|
---|
11 | * the License. You may obtain a copy of the License at
|
---|
12 | * http://www.mozilla.org/MPL/
|
---|
13 | *
|
---|
14 | * Software distributed under the License is distributed on an "AS IS" basis,
|
---|
15 | * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
---|
16 | * for the specific language governing rights and limitations under the
|
---|
17 | * License.
|
---|
18 | *
|
---|
19 | * Alternatively, the content of this file maybe used under the terms of either
|
---|
20 | * the GNU General Public License Version 2 or later (the "GPL"), or the GNU
|
---|
21 | * Lesser General Public License Version 2.1 or later (the "LGPL"), in which
|
---|
22 | * case the provisions of the GPL or the LGPL are applicable instead of those
|
---|
23 | * above. If you wish to allow use of your version of this file only under the
|
---|
24 | * terms of either the GPL or the LGPL, and not to allow others to use your
|
---|
25 | * version of this file under the terms of the MPL, indicate your division by
|
---|
26 | * deleting the provisions above and replace them with the notice and other
|
---|
27 | * provisions required by the GPL or LGPL. If you do not delete the provisions
|
---|
28 | * above, a recipient may use your version of this file under the terms of any
|
---|
29 | * one of the MPL, the GPL or the LGPL.
|
---|
30 | *
|
---|
31 | * *********************** END LICENSE BLOCK *********************************)
|
---|
32 |
|
---|
33 | interface
|
---|
34 |
|
---|
35 | uses
|
---|
36 | Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
|
---|
37 | StdCtrls, ComCtrls, RichEdit, Buttons, ExtCtrls, ShellAPI,
|
---|
38 | skaSpellCheck,
|
---|
39 | VA508AccessibilityManager, fBase508Form;
|
---|
40 |
|
---|
41 | type
|
---|
42 | TfrmHunSpell = class(TfrmBase508Form)
|
---|
43 | lblDictionary: TLabel;
|
---|
44 | btnClose: TButton;
|
---|
45 | OpenDialog1: TOpenDialog;
|
---|
46 | SpellCheck1: TskaHunSpellChecker;
|
---|
47 | edtDictionary: TEdit;
|
---|
48 | btnSelectDict: TBitBtn;
|
---|
49 | lblOpenMedURL: TLabel;
|
---|
50 | lblDictionariesURL: TLabel;
|
---|
51 | RichEdit1: TRichEdit;
|
---|
52 | pnlMisSpelled: TPanel;
|
---|
53 | Label1: TLabel;
|
---|
54 | lstSuggestions: TListBox;
|
---|
55 | Label4: TLabel;
|
---|
56 | edtMisSpelt: TEdit;
|
---|
57 | btnReplaceWith: TButton;
|
---|
58 | btnChangeAll: TButton;
|
---|
59 | btnChange: TButton;
|
---|
60 | btnAddToDictionary: TButton;
|
---|
61 | btnIgnoreAll: TButton;
|
---|
62 | btnIgnoreOnce: TButton;
|
---|
63 | btnAbort: TButton;
|
---|
64 | btnAbout: TButton;
|
---|
65 | pnlAbout: TPanel;
|
---|
66 | Button1: TButton;
|
---|
67 | btnUndo: TButton;
|
---|
68 | cbIgnoreAllCaps: TCheckBox;
|
---|
69 | cbIgnoreDigit: TCheckBox;
|
---|
70 | btnRestat: TButton;
|
---|
71 | procedure FormCreate(Sender: TObject);
|
---|
72 | procedure btnIgnoreOnceClick(Sender: TObject);
|
---|
73 | procedure btnIgnoreAllClick(Sender: TObject);
|
---|
74 | procedure btnChangeClick(Sender: TObject);
|
---|
75 | procedure btnChangeAllClick(Sender: TObject);
|
---|
76 | procedure btnCloseClick(Sender: TObject);
|
---|
77 | procedure FormActivate(Sender: TObject);
|
---|
78 | procedure btnSelectDictClick(Sender: TObject);
|
---|
79 | procedure edtDictionaryEnter(Sender: TObject);
|
---|
80 | procedure btnReplaceWithClick(Sender: TObject);
|
---|
81 | procedure btnAddToDictionaryClick(Sender: TObject);
|
---|
82 | procedure FormShow(Sender: TObject);
|
---|
83 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
84 | procedure btnAbortClick(Sender: TObject);
|
---|
85 | procedure lblOpenMedURLClick(Sender: TObject);
|
---|
86 | procedure btnAboutClick(Sender: TObject);
|
---|
87 | procedure Button1Click(Sender: TObject);
|
---|
88 | procedure btnUndoClick(Sender: TObject);
|
---|
89 | procedure RichEdit1KeyUp(Sender: TObject; var Key: Word;
|
---|
90 | Shift: TShiftState);
|
---|
91 | procedure RichEdit1KeyDown(Sender: TObject; var Key: Word;
|
---|
92 | Shift: TShiftState);
|
---|
93 | procedure lstSuggestionsDblClick(Sender: TObject);
|
---|
94 | procedure SpellCheck1StateChange(const Sender: TObject;
|
---|
95 | const State: TSpellState);
|
---|
96 | procedure SpellCheck1Abort(Sender: TObject);
|
---|
97 | procedure SpellCheck1Start(Sender: TObject);
|
---|
98 | procedure cbIgnoreAllCapsClick(Sender: TObject);
|
---|
99 | procedure cbIgnoreDigitClick(Sender: TObject);
|
---|
100 | procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
---|
101 | procedure btnRestatClick(Sender: TObject);
|
---|
102 | private
|
---|
103 | { Private declarations }
|
---|
104 | NoEngineOpted: Boolean;
|
---|
105 | FSourceControl: TCustomMemo;
|
---|
106 | procedure GoToURL(const aURL: String);
|
---|
107 | procedure UpdateGUI;
|
---|
108 | public
|
---|
109 | { Public declarations }
|
---|
110 | Showhighlight:boolean;
|
---|
111 | highlightcolor:TColor;
|
---|
112 | HighLightList:TStringlist;
|
---|
113 | OldRichEditWndProc: {integer}pointer;
|
---|
114 | PRichEditWndProc:pointer;
|
---|
115 | class function DoHunSpellCheck(AnEditControl: TCustomMemo): TModalResult; static;
|
---|
116 | end;
|
---|
117 |
|
---|
118 | Resourcestring
|
---|
119 | TX_AFF_NOT_FOUND = 'Correspong AFF file named not found!'
|
---|
120 | + #13
|
---|
121 | + ' Specify dictionary file whose *.aff is also '
|
---|
122 | + 'present in same directory.' ;
|
---|
123 | TX_DIC_FILE_NOT_FOUND = 'Dictionary File for SpellCheck Engine not found!';
|
---|
124 | TX_SPELL_COMPLETE = 'Spell Check Complete';
|
---|
125 | TX_SPELL_CANCELLED = 'Spell Check Aborted'
|
---|
126 | + #13
|
---|
127 | + 'No Changes applied to the original text!';
|
---|
128 |
|
---|
129 | Const
|
---|
130 | DefaultDicFile = 'dict\en-US-OpenMedSpel.dic';
|
---|
131 |
|
---|
132 | var
|
---|
133 | frmHunSpell: TfrmHunSpell;
|
---|
134 |
|
---|
135 | implementation
|
---|
136 | {$R *.DFM}
|
---|
137 |
|
---|
138 | uses uSpell, VAUtils;
|
---|
139 |
|
---|
140 | class function TfrmHunSpell.DoHunSpellCheck(AnEditControl: TCustomMemo): TModalResult;
|
---|
141 | var
|
---|
142 | frm: TfrmHunSpell;
|
---|
143 | begin
|
---|
144 | Result := mrCancel;
|
---|
145 | frm:= TfrmHunSpell.create(Application);
|
---|
146 | try
|
---|
147 | frm.RichEdit1.Text:= AnEditControl.Text;
|
---|
148 | frm.FSourceControl := AnEditControl;
|
---|
149 | Result := frm.ShowModal;
|
---|
150 | finally
|
---|
151 | frm.Free;
|
---|
152 | end;
|
---|
153 | end;
|
---|
154 |
|
---|
155 | {************ HighLight ***********888}
|
---|
156 | procedure TfrmHunSpell.FormShow(Sender: TObject);
|
---|
157 | begin
|
---|
158 | if SpellCheck1.SpellCheckState = ssReady then
|
---|
159 | SpellCheck1.CheckSpelling;
|
---|
160 | try
|
---|
161 | if lstSuggestions.Count > 0 then
|
---|
162 | btnChange.SetFocus;
|
---|
163 | except
|
---|
164 | end;
|
---|
165 | end;
|
---|
166 |
|
---|
167 | procedure TfrmHunSpell.GoToURL(const aURL: String);
|
---|
168 | begin
|
---|
169 | if length(trim(aURL)) > 4 then
|
---|
170 | ShellExecute(Handle, 'open', PChar(aURL), '', '', SW_NORMAL);
|
---|
171 | end;
|
---|
172 |
|
---|
173 | procedure TfrmHunSpell.lblOpenMedURLClick(Sender: TObject);
|
---|
174 | begin
|
---|
175 | inherited;
|
---|
176 | GoToURL(TLabel(sender).Caption);
|
---|
177 | end;
|
---|
178 |
|
---|
179 | procedure TfrmHunSpell.lstSuggestionsDblClick(Sender: TObject);
|
---|
180 | begin
|
---|
181 | inherited;
|
---|
182 | btnChangeClick(sender);
|
---|
183 | end;
|
---|
184 |
|
---|
185 | procedure TfrmHunSpell.RichEdit1KeyDown(Sender: TObject; var Key: Word;
|
---|
186 | Shift: TShiftState);
|
---|
187 | begin
|
---|
188 | inherited;
|
---|
189 | if SpellCheck1.SpellCheckState = ssChecking then
|
---|
190 | SpellCheck1.ManualChangeStart;
|
---|
191 | end;
|
---|
192 |
|
---|
193 | procedure TfrmHunSpell.RichEdit1KeyUp(Sender: TObject; var Key: Word;
|
---|
194 | Shift: TShiftState);
|
---|
195 | begin
|
---|
196 | inherited;
|
---|
197 | if SpellCheck1.SpellCheckState in [ssCancelled, ssCompleted] then
|
---|
198 | SpellCheck1.Reopen;
|
---|
199 |
|
---|
200 | if SpellCheck1.SpellCheckState = ssChecking then
|
---|
201 | SpellCheck1.ManualChangeDone;
|
---|
202 | end;
|
---|
203 |
|
---|
204 | procedure TfrmHunSpell.SpellCheck1Abort(Sender: TObject);
|
---|
205 | begin
|
---|
206 | inherited;
|
---|
207 | UpdateGUI;
|
---|
208 | end;
|
---|
209 |
|
---|
210 | procedure TfrmHunSpell.SpellCheck1Start(Sender: TObject);
|
---|
211 | begin
|
---|
212 | inherited;
|
---|
213 | UpdateGUI;
|
---|
214 | end;
|
---|
215 |
|
---|
216 | procedure TfrmHunSpell.SpellCheck1StateChange(const Sender: TObject;
|
---|
217 | const State: TSpellState);
|
---|
218 | begin
|
---|
219 | inherited;
|
---|
220 | if State = ssCompleted then
|
---|
221 | ShowMessage(TX_SPELL_COMPLETE);
|
---|
222 | UpdateGUI;
|
---|
223 | end;
|
---|
224 |
|
---|
225 | procedure TfrmHunSpell.UpdateGUI;
|
---|
226 | var
|
---|
227 | Checking: Boolean;
|
---|
228 | begin
|
---|
229 | if csDestroying in componentstate then
|
---|
230 | exit;
|
---|
231 | Checking := SpellCheck1.SpellCheckState = ssChecking;
|
---|
232 | pnlMisSpelled.Visible := Checking;
|
---|
233 | pnlMisSpelled.Enabled := Checking;
|
---|
234 | btnClose.Visible := not Checking;
|
---|
235 | end;
|
---|
236 |
|
---|
237 | {************* FormCreate **********}
|
---|
238 | procedure TfrmHunSpell.btnAboutClick(Sender: TObject);
|
---|
239 | begin
|
---|
240 | inherited;
|
---|
241 | pnlAbout.Show;
|
---|
242 | pnlAbout.BringToFront;
|
---|
243 | end;
|
---|
244 |
|
---|
245 | procedure TfrmHunSpell.btnAddToDictionaryClick(Sender: TObject);
|
---|
246 | begin
|
---|
247 | SpellCheck1.AddCustomWord;
|
---|
248 | end;
|
---|
249 |
|
---|
250 | procedure TfrmHunSpell.btnReplaceWithClick(Sender: TObject);
|
---|
251 | begin
|
---|
252 | SpellCheck1.CorrectWithMyWord;
|
---|
253 | end;
|
---|
254 |
|
---|
255 | procedure TfrmHunSpell.btnRestatClick(Sender: TObject);
|
---|
256 | begin
|
---|
257 | inherited;
|
---|
258 | if SpellCheck1.SpellCheckState = ssChecking then
|
---|
259 | SpellCheck1.ReStart
|
---|
260 | else
|
---|
261 | SpellCheck1.CheckSpelling;
|
---|
262 | end;
|
---|
263 |
|
---|
264 | procedure TfrmHunSpell.btnAbortClick(Sender: TObject);
|
---|
265 | begin
|
---|
266 | //popup 508 compliant confirmation/warning box if isModified
|
---|
267 | if SpellCheck1.AbortSpellCheck(True) then
|
---|
268 | begin
|
---|
269 | Close;
|
---|
270 | ModalResult := mrCancel;
|
---|
271 | end;
|
---|
272 | end;
|
---|
273 |
|
---|
274 | procedure TfrmHunSpell.btnChangeAllClick(Sender: TObject);
|
---|
275 | begin
|
---|
276 | SpellCheck1.ChangeAll;
|
---|
277 | end;
|
---|
278 |
|
---|
279 | procedure TfrmHunSpell.btnChangeClick(Sender: TObject);
|
---|
280 | begin
|
---|
281 | SpellCheck1.Change;
|
---|
282 | end;
|
---|
283 |
|
---|
284 | procedure TfrmHunSpell.btnCloseClick(Sender: TObject);
|
---|
285 | begin
|
---|
286 | close;
|
---|
287 | end;
|
---|
288 |
|
---|
289 | procedure TfrmHunSpell.btnIgnoreAllClick(Sender: TObject);
|
---|
290 | begin
|
---|
291 | SpellCheck1.IgnoreAll;
|
---|
292 | end;
|
---|
293 |
|
---|
294 | procedure TfrmHunSpell.btnIgnoreOnceClick(Sender: TObject);
|
---|
295 | begin
|
---|
296 | SpellCheck1.IgnoreOnce;
|
---|
297 | end;
|
---|
298 |
|
---|
299 | procedure TfrmHunSpell.btnSelectDictClick(Sender: TObject);
|
---|
300 | var
|
---|
301 | aff: String;
|
---|
302 | begin
|
---|
303 | if OpenDialog1.Execute then
|
---|
304 | begin
|
---|
305 | if SpellCheck1.DictionaryFileName = OpenDialog1.FileName then
|
---|
306 | exit;
|
---|
307 |
|
---|
308 | aff := ChangeFileExt(OpenDialog1.FileName, '.aff');
|
---|
309 | if not FileExists(aff) then
|
---|
310 | begin
|
---|
311 | ShowMessage(TX_AFF_NOT_FOUND);
|
---|
312 | OpenDialog1.FileName := '';
|
---|
313 | btnSelectDictClick(self);
|
---|
314 | end
|
---|
315 | else
|
---|
316 | begin
|
---|
317 | if SpellCheck1.SpellCheckState = ssChecking then
|
---|
318 | SpellCheck1.AbortSpellCheck(False);
|
---|
319 | edtDictionary.Text := OpenDialog1.FileName;
|
---|
320 | SpellCheck1.DictionaryFileName := edtDictionary.Text;
|
---|
321 | SpellCheck1.AffixFileName := aff;
|
---|
322 | SpellCheck1.Open;
|
---|
323 | end;
|
---|
324 | end;
|
---|
325 | end;
|
---|
326 |
|
---|
327 | procedure TfrmHunSpell.btnUndoClick(Sender: TObject);
|
---|
328 | begin
|
---|
329 | inherited;
|
---|
330 | SpellCheck1.Undo;
|
---|
331 | end;
|
---|
332 |
|
---|
333 | procedure TfrmHunSpell.Button1Click(Sender: TObject);
|
---|
334 | begin
|
---|
335 | inherited;
|
---|
336 | pnlAbout.hide;
|
---|
337 | end;
|
---|
338 |
|
---|
339 | procedure TfrmHunSpell.cbIgnoreAllCapsClick(Sender: TObject);
|
---|
340 | begin
|
---|
341 | inherited;
|
---|
342 | if SpellCheck1.IgnoreAllCaps <> cbIgnoreAllCaps.Checked then
|
---|
343 | SpellCheck1.IgnoreAllCaps := cbIgnoreAllCaps.Checked;
|
---|
344 | end;
|
---|
345 |
|
---|
346 | procedure TfrmHunSpell.cbIgnoreDigitClick(Sender: TObject);
|
---|
347 | begin
|
---|
348 | inherited;
|
---|
349 | if SpellCheck1.IgnoreWordWithDigits <> cbIgnoreDigit.Checked then
|
---|
350 | SpellCheck1.IgnoreWordWithDigits := cbIgnoreDigit.Checked;
|
---|
351 | end;
|
---|
352 |
|
---|
353 | procedure TfrmHunSpell.edtDictionaryEnter(Sender: TObject);
|
---|
354 | begin
|
---|
355 | btnSelectDict.SetFocus;
|
---|
356 | end;
|
---|
357 |
|
---|
358 | procedure TfrmHunSpell.FormActivate(Sender: TObject);
|
---|
359 | begin
|
---|
360 | if ( not SpellCheck1.Active) and (not NoEngineOpted) then
|
---|
361 | begin
|
---|
362 | btnSelectDictClick(self);
|
---|
363 | NoEngineOpted := True;
|
---|
364 | end;
|
---|
365 | if cbIgnoreAllCaps.Checked <> SpellCheck1.IgnoreAllCaps then
|
---|
366 | cbIgnoreAllCaps.Checked := SpellCheck1.IgnoreAllCaps;
|
---|
367 |
|
---|
368 | if cbIgnoreDigit.Checked <> SpellCheck1.IgnoreWordWithDigits then
|
---|
369 | cbIgnoreDigit.Checked := SpellCheck1.IgnoreWordWithDigits;
|
---|
370 | end;
|
---|
371 |
|
---|
372 | procedure TfrmHunSpell.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
373 | begin
|
---|
374 | if SpellCheck1.SpellCheckState = ssCompleted then
|
---|
375 | begin
|
---|
376 | // ShowMsg(TX_SPELL_COMPLETE, TShow508MessageIcon(1), smbOK) ;
|
---|
377 | if Assigned(FSourceControl) then
|
---|
378 | FSourceControl.Text := RichEdit1.Text;
|
---|
379 | end;
|
---|
380 | {else
|
---|
381 | ShowMsg(TX_SPELL_CANCELLED + CRLF + TX_NO_CORRECTIONS,
|
---|
382 | TShow508MessageIcon(1), smbOK) ;}
|
---|
383 | end;
|
---|
384 |
|
---|
385 | procedure TfrmHunSpell.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
---|
386 | begin
|
---|
387 | inherited;
|
---|
388 |
|
---|
389 | CanClose := (SpellCheck1.SpellCheckState <> ssChecking)
|
---|
390 | or (SpellCheck1.AbortSpellCheck(True));
|
---|
391 | if CanClose then
|
---|
392 | ModalResult := mrCancel;
|
---|
393 | end;
|
---|
394 |
|
---|
395 | procedure TfrmHunSpell.FormCreate(Sender: TObject);
|
---|
396 | var
|
---|
397 | dicFile: String;
|
---|
398 | function affFile: String;
|
---|
399 | begin
|
---|
400 | Result := ChangeFileExt(dicFile, '.aff');
|
---|
401 | end;
|
---|
402 | begin
|
---|
403 | if (SpellCheck1.DictionaryFileName <> '') then
|
---|
404 | dicFile := SpellCheck1.DictionaryFileName
|
---|
405 | else
|
---|
406 | dicFile := ExtractFilePath(Application.ExeName)+ DefaultDicFile;
|
---|
407 |
|
---|
408 | if (FileExists(dicFile)) and (FileExists(affFile)) then
|
---|
409 | begin
|
---|
410 | SpellCheck1.AffixFileName := affFile;
|
---|
411 | edtDictionary.Text := SpellCheck1.DictionaryFileName;
|
---|
412 | end
|
---|
413 | else
|
---|
414 | edtDictionary.Text := TX_Dic_File_Not_Found;
|
---|
415 |
|
---|
416 | if edtDictionary.Text = TX_Dic_File_Not_Found then
|
---|
417 | btnSelectDictClick(self);
|
---|
418 | SpellCheck1.SourceTextControl := RichEdit1;
|
---|
419 | SpellCheck1.SuggestionList := lstSuggestions;
|
---|
420 | SpellCheck1.MisSpeltWord := edtMisSpelt;
|
---|
421 | SpellCheck1.Active := (SpellCheck1.DictionaryFileName <> '')
|
---|
422 | and FileExists(dicFile);
|
---|
423 | end;
|
---|
424 |
|
---|
425 |
|
---|
426 |
|
---|
427 | end.
|
---|