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, jpeg;
|
---|
39 |
|
---|
40 | type
|
---|
41 | TfrmHunSpell = class(TForm)
|
---|
42 | btnClose: TButton;
|
---|
43 | OpenDialog1: TOpenDialog;
|
---|
44 | SpellCheck1: TskaHunSpellChecker;
|
---|
45 | edtDictionary: TEdit;
|
---|
46 | btnSelectDict: TBitBtn;
|
---|
47 | RichEdit1: TRichEdit;
|
---|
48 | pnlMisSpelled: TPanel;
|
---|
49 | Label1: TLabel;
|
---|
50 | lstSuggestions: TListBox;
|
---|
51 | Label4: TLabel;
|
---|
52 | edtMisSpelt: TEdit;
|
---|
53 | btnReplaceWith: TButton;
|
---|
54 | btnChangeAll: TButton;
|
---|
55 | btnChange: TButton;
|
---|
56 | btnAddToDictionary: TButton;
|
---|
57 | btnIgnoreAll: TButton;
|
---|
58 | btnIgnoreOnce: TButton;
|
---|
59 | btnAbort: TButton;
|
---|
60 | btnAbout: TButton;
|
---|
61 | pnlAbout: TPanel;
|
---|
62 | btnHideAbout: TButton;
|
---|
63 | btnUndo: TButton;
|
---|
64 | cbIgnoreAllCaps: TCheckBox;
|
---|
65 | cbIgnoreDigit: TCheckBox;
|
---|
66 | btnRestat: TButton;
|
---|
67 | cbHyphenatedWord: TCheckBox;
|
---|
68 | StaticText1: TStaticText;
|
---|
69 | StaticText2: TStaticText;
|
---|
70 | StaticText3: TStaticText;
|
---|
71 | Label2: TLabel;
|
---|
72 | StaticText4: TStaticText;
|
---|
73 | Label3: TLabel;
|
---|
74 | StaticText5: TStaticText;
|
---|
75 | StaticText6: TStaticText;
|
---|
76 | Image1: TImage;
|
---|
77 | lblDictionariesURL: TLabel;
|
---|
78 | lblDictionary: TLabel;
|
---|
79 | lblOpenMedURL: TLabel;
|
---|
80 | Label5: TLabel;
|
---|
81 | Label6: TLabel;
|
---|
82 | procedure FormCreate(Sender: TObject);
|
---|
83 | procedure btnIgnoreOnceClick(Sender: TObject);
|
---|
84 | procedure btnIgnoreAllClick(Sender: TObject);
|
---|
85 | procedure btnChangeClick(Sender: TObject);
|
---|
86 | procedure btnChangeAllClick(Sender: TObject);
|
---|
87 | procedure btnCloseClick(Sender: TObject);
|
---|
88 | procedure FormActivate(Sender: TObject);
|
---|
89 | procedure btnSelectDictClick(Sender: TObject);
|
---|
90 | procedure edtDictionaryEnter(Sender: TObject);
|
---|
91 | procedure btnReplaceWithClick(Sender: TObject);
|
---|
92 | procedure btnAddToDictionaryClick(Sender: TObject);
|
---|
93 | procedure FormShow(Sender: TObject);
|
---|
94 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
95 | procedure btnAbortClick(Sender: TObject);
|
---|
96 | procedure lblOpenMedURLClick(Sender: TObject);
|
---|
97 | procedure btnAboutClick(Sender: TObject);
|
---|
98 | procedure btnHideAboutClick(Sender: TObject);
|
---|
99 | procedure btnUndoClick(Sender: TObject);
|
---|
100 | procedure RichEdit1KeyUp(Sender: TObject; var Key: Word;
|
---|
101 | Shift: TShiftState);
|
---|
102 | procedure RichEdit1KeyDown(Sender: TObject; var Key: Word;
|
---|
103 | Shift: TShiftState);
|
---|
104 | procedure lstSuggestionsDblClick(Sender: TObject);
|
---|
105 | procedure SpellCheck1StateChange(const Sender: TObject;
|
---|
106 | const State: TSpellState);
|
---|
107 | procedure SpellCheck1Abort(Sender: TObject);
|
---|
108 | procedure SpellCheck1Start(Sender: TObject);
|
---|
109 | procedure cbIgnoreAllCapsClick(Sender: TObject);
|
---|
110 | procedure cbIgnoreDigitClick(Sender: TObject);
|
---|
111 | procedure FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
---|
112 | procedure btnRestatClick(Sender: TObject);
|
---|
113 | procedure cbHyphenatedWordClick(Sender: TObject);
|
---|
114 | procedure Image1Click(Sender: TObject);
|
---|
115 | procedure Label6Click(Sender: TObject);
|
---|
116 | procedure FormKeyUp(Sender: TObject; var Key: Word; Shift: TShiftState);
|
---|
117 | private
|
---|
118 | { Private declarations }
|
---|
119 | NoEngineOpted: Boolean;
|
---|
120 | FSourceControl: TCustomMemo;
|
---|
121 | procedure GoToURL(const aURL: String);
|
---|
122 | procedure UpdateGUI;
|
---|
123 | public
|
---|
124 | { Public declarations }
|
---|
125 | Showhighlight:boolean;
|
---|
126 | highlightcolor:TColor;
|
---|
127 | HighLightList:TStringlist;
|
---|
128 | OldRichEditWndProc: {integer}pointer;
|
---|
129 | PRichEditWndProc:pointer;
|
---|
130 | class function DoHunSpellCheck(AnEditControl: TCustomMemo): TModalResult; static;
|
---|
131 | end;
|
---|
132 |
|
---|
133 | Resourcestring
|
---|
134 | TX_AFF_NOT_FOUND = 'Correspong AFF file named not found!'
|
---|
135 | + #13
|
---|
136 | + ' Specify dictionary file whose *.aff is also '
|
---|
137 | + 'present in same directory.' ;
|
---|
138 | TX_DIC_FILE_NOT_FOUND = 'Dictionary File for SpellCheck Engine not found!';
|
---|
139 | TX_SPELL_COMPLETE = 'Spell Check Complete';
|
---|
140 | TX_SPELL_CANCELLED = 'Spell Check Aborted'
|
---|
141 | + #13
|
---|
142 | + 'No Changes applied to the original text!';
|
---|
143 |
|
---|
144 | Const
|
---|
145 | DefaultDicFile = '\dict\en_US-large.dic';
|
---|
146 |
|
---|
147 | var
|
---|
148 | frmHunSpell: TfrmHunSpell;
|
---|
149 |
|
---|
150 | implementation
|
---|
151 | {$R *.DFM}
|
---|
152 |
|
---|
153 |
|
---|
154 | class function TfrmHunSpell.DoHunSpellCheck(AnEditControl: TCustomMemo): TModalResult;
|
---|
155 | var
|
---|
156 | frm: TfrmHunSpell;
|
---|
157 | begin
|
---|
158 | Result := mrCancel;
|
---|
159 | frm:= TfrmHunSpell.create(Application);
|
---|
160 | try
|
---|
161 | frm.RichEdit1.Text:= AnEditControl.Text;
|
---|
162 | frm.FSourceControl := AnEditControl;
|
---|
163 | Result := frm.ShowModal;
|
---|
164 | finally
|
---|
165 | frm.Free;
|
---|
166 | end;
|
---|
167 | end;
|
---|
168 |
|
---|
169 | {************ HighLight ***********888}
|
---|
170 | procedure TfrmHunSpell.FormShow(Sender: TObject);
|
---|
171 | begin
|
---|
172 | if SpellCheck1.SpellCheckState = ssReady then
|
---|
173 | SpellCheck1.CheckSpelling;
|
---|
174 | try
|
---|
175 | if lstSuggestions.Count > 0 then
|
---|
176 | btnChange.SetFocus;
|
---|
177 | except
|
---|
178 | end;
|
---|
179 | end;
|
---|
180 |
|
---|
181 | procedure TfrmHunSpell.GoToURL(const aURL: String);
|
---|
182 | begin
|
---|
183 | if length(trim(aURL)) > 4 then
|
---|
184 | ShellExecute(Handle, 'open', PChar(aURL), '', '', SW_NORMAL);
|
---|
185 | end;
|
---|
186 |
|
---|
187 | procedure TfrmHunSpell.Image1Click(Sender: TObject);
|
---|
188 | begin
|
---|
189 | inherited;
|
---|
190 | GoToURL('http://www.healthsevak.com');
|
---|
191 | end;
|
---|
192 |
|
---|
193 | procedure TfrmHunSpell.Label6Click(Sender: TObject);
|
---|
194 | begin
|
---|
195 | inherited;
|
---|
196 | GoToURL('mailto: digitiger@gmail.com');
|
---|
197 | end;
|
---|
198 |
|
---|
199 | procedure TfrmHunSpell.lblOpenMedURLClick(Sender: TObject);
|
---|
200 | begin
|
---|
201 | inherited;
|
---|
202 | GoToURL(TLabel(sender).Caption);
|
---|
203 | end;
|
---|
204 |
|
---|
205 | procedure TfrmHunSpell.lstSuggestionsDblClick(Sender: TObject);
|
---|
206 | begin
|
---|
207 | inherited;
|
---|
208 | btnChangeClick(sender);
|
---|
209 | end;
|
---|
210 |
|
---|
211 | procedure TfrmHunSpell.RichEdit1KeyDown(Sender: TObject; var Key: Word;
|
---|
212 | Shift: TShiftState);
|
---|
213 | begin
|
---|
214 | inherited;
|
---|
215 | if SpellCheck1.SpellCheckState = ssChecking then
|
---|
216 | SpellCheck1.ManualChangeStart;
|
---|
217 | end;
|
---|
218 |
|
---|
219 | procedure TfrmHunSpell.RichEdit1KeyUp(Sender: TObject; var Key: Word;
|
---|
220 | Shift: TShiftState);
|
---|
221 | begin
|
---|
222 | inherited;
|
---|
223 | if SpellCheck1.SpellCheckState in [ssCancelled, ssCompleted] then
|
---|
224 | SpellCheck1.Reopen;
|
---|
225 |
|
---|
226 | if SpellCheck1.SpellCheckState = ssChecking then
|
---|
227 | SpellCheck1.ManualChangeDone;
|
---|
228 | end;
|
---|
229 |
|
---|
230 | procedure TfrmHunSpell.SpellCheck1Abort(Sender: TObject);
|
---|
231 | begin
|
---|
232 | inherited;
|
---|
233 | UpdateGUI;
|
---|
234 | end;
|
---|
235 |
|
---|
236 | procedure TfrmHunSpell.SpellCheck1Start(Sender: TObject);
|
---|
237 | begin
|
---|
238 | inherited;
|
---|
239 | UpdateGUI;
|
---|
240 | end;
|
---|
241 |
|
---|
242 | procedure TfrmHunSpell.SpellCheck1StateChange(const Sender: TObject;
|
---|
243 | const State: TSpellState);
|
---|
244 | begin
|
---|
245 | inherited;
|
---|
246 | if State = ssCompleted then
|
---|
247 | ShowMessage(TX_SPELL_COMPLETE);
|
---|
248 | UpdateGUI;
|
---|
249 | end;
|
---|
250 |
|
---|
251 | procedure TfrmHunSpell.UpdateGUI;
|
---|
252 | var
|
---|
253 | Checking: Boolean;
|
---|
254 | begin
|
---|
255 | if csDestroying in componentstate then
|
---|
256 | exit;
|
---|
257 | Checking := SpellCheck1.SpellCheckState = ssChecking;
|
---|
258 | pnlMisSpelled.Visible := Checking;
|
---|
259 | pnlMisSpelled.Enabled := Checking;
|
---|
260 | btnClose.Visible := not Checking;
|
---|
261 | end;
|
---|
262 |
|
---|
263 | {************* FormCreate **********}
|
---|
264 | procedure TfrmHunSpell.btnAboutClick(Sender: TObject);
|
---|
265 | begin
|
---|
266 | inherited;
|
---|
267 | pnlAbout.Show;
|
---|
268 | pnlAbout.BringToFront;
|
---|
269 | end;
|
---|
270 |
|
---|
271 | procedure TfrmHunSpell.btnAddToDictionaryClick(Sender: TObject);
|
---|
272 | begin
|
---|
273 | SpellCheck1.AddCustomWord;
|
---|
274 | end;
|
---|
275 |
|
---|
276 | procedure TfrmHunSpell.btnReplaceWithClick(Sender: TObject);
|
---|
277 | begin
|
---|
278 | SpellCheck1.CorrectWithMyWord;
|
---|
279 | end;
|
---|
280 |
|
---|
281 | procedure TfrmHunSpell.btnRestatClick(Sender: TObject);
|
---|
282 | begin
|
---|
283 | inherited;
|
---|
284 | SpellCheck1.ReStart
|
---|
285 | end;
|
---|
286 |
|
---|
287 | procedure TfrmHunSpell.btnAbortClick(Sender: TObject);
|
---|
288 | begin
|
---|
289 | if SpellCheck1.AbortSpellCheck(True) then
|
---|
290 | end;
|
---|
291 |
|
---|
292 | procedure TfrmHunSpell.btnChangeAllClick(Sender: TObject);
|
---|
293 | begin
|
---|
294 | SpellCheck1.ChangeAll;
|
---|
295 | end;
|
---|
296 |
|
---|
297 | procedure TfrmHunSpell.btnChangeClick(Sender: TObject);
|
---|
298 | begin
|
---|
299 | SpellCheck1.Change;
|
---|
300 | end;
|
---|
301 |
|
---|
302 | procedure TfrmHunSpell.btnCloseClick(Sender: TObject);
|
---|
303 | begin
|
---|
304 | close;
|
---|
305 | end;
|
---|
306 |
|
---|
307 | procedure TfrmHunSpell.btnIgnoreAllClick(Sender: TObject);
|
---|
308 | begin
|
---|
309 | SpellCheck1.IgnoreAll;
|
---|
310 | end;
|
---|
311 |
|
---|
312 | procedure TfrmHunSpell.btnIgnoreOnceClick(Sender: TObject);
|
---|
313 | begin
|
---|
314 | SpellCheck1.IgnoreOnce;
|
---|
315 | end;
|
---|
316 |
|
---|
317 | procedure TfrmHunSpell.btnSelectDictClick(Sender: TObject);
|
---|
318 | var
|
---|
319 | aff: String;
|
---|
320 | begin
|
---|
321 | if OpenDialog1.Execute then
|
---|
322 | begin
|
---|
323 | if SpellCheck1.DictionaryFileName = OpenDialog1.FileName then
|
---|
324 | exit;
|
---|
325 |
|
---|
326 | aff := ChangeFileExt(OpenDialog1.FileName, '.aff');
|
---|
327 | if not FileExists(aff) then
|
---|
328 | begin
|
---|
329 | ShowMessage(TX_AFF_NOT_FOUND);
|
---|
330 | OpenDialog1.FileName := '';
|
---|
331 | btnSelectDictClick(self);
|
---|
332 | end
|
---|
333 | else
|
---|
334 | begin
|
---|
335 | if SpellCheck1.SpellCheckState = ssChecking then
|
---|
336 | SpellCheck1.AbortSpellCheck(False);
|
---|
337 | edtDictionary.Text := OpenDialog1.FileName;
|
---|
338 | SpellCheck1.DictionaryFileName := edtDictionary.Text;
|
---|
339 | SpellCheck1.AffixFileName := aff;
|
---|
340 | SpellCheck1.Open;
|
---|
341 | end;
|
---|
342 | end;
|
---|
343 | end;
|
---|
344 |
|
---|
345 | procedure TfrmHunSpell.btnUndoClick(Sender: TObject);
|
---|
346 | begin
|
---|
347 | inherited;
|
---|
348 | SpellCheck1.Undo;
|
---|
349 | end;
|
---|
350 |
|
---|
351 | procedure TfrmHunSpell.btnHideAboutClick(Sender: TObject);
|
---|
352 | begin
|
---|
353 | inherited;
|
---|
354 | pnlAbout.hide;
|
---|
355 | end;
|
---|
356 |
|
---|
357 | procedure TfrmHunSpell.cbHyphenatedWordClick(Sender: TObject);
|
---|
358 | begin
|
---|
359 | inherited;
|
---|
360 | if SpellCheck1.HyphenatedWords <> cbHyphenatedWord.Checked then
|
---|
361 | SpellCheck1.HyphenatedWords := cbHyphenatedWord.Checked;
|
---|
362 |
|
---|
363 | if SpellCheck1.SpellCheckState = ssChecking then
|
---|
364 | SpellCheck1.ReStart;
|
---|
365 | end;
|
---|
366 |
|
---|
367 | procedure TfrmHunSpell.cbIgnoreAllCapsClick(Sender: TObject);
|
---|
368 | begin
|
---|
369 | inherited;
|
---|
370 | if SpellCheck1.IgnoreAllCaps <> cbIgnoreAllCaps.Checked then
|
---|
371 | SpellCheck1.IgnoreAllCaps := cbIgnoreAllCaps.Checked;
|
---|
372 |
|
---|
373 | if SpellCheck1.SpellCheckState = ssChecking then
|
---|
374 | SpellCheck1.ReStart;
|
---|
375 | end;
|
---|
376 |
|
---|
377 | procedure TfrmHunSpell.cbIgnoreDigitClick(Sender: TObject);
|
---|
378 | begin
|
---|
379 | inherited;
|
---|
380 | if SpellCheck1.IgnoreWordWithDigits <> cbIgnoreDigit.Checked then
|
---|
381 | SpellCheck1.IgnoreWordWithDigits := cbIgnoreDigit.Checked;
|
---|
382 |
|
---|
383 | if SpellCheck1.SpellCheckState = ssChecking then
|
---|
384 | SpellCheck1.ReStart;
|
---|
385 | end;
|
---|
386 |
|
---|
387 | procedure TfrmHunSpell.edtDictionaryEnter(Sender: TObject);
|
---|
388 | begin
|
---|
389 | btnSelectDict.SetFocus;
|
---|
390 | end;
|
---|
391 |
|
---|
392 | procedure TfrmHunSpell.FormActivate(Sender: TObject);
|
---|
393 | begin
|
---|
394 | if ( not btnRestat.Enabled) and (not NoEngineOpted) then
|
---|
395 | begin
|
---|
396 | btnSelectDictClick(self);
|
---|
397 | NoEngineOpted := True;
|
---|
398 | end;
|
---|
399 | if cbIgnoreAllCaps.Checked <> SpellCheck1.IgnoreAllCaps then
|
---|
400 | cbIgnoreAllCaps.Checked := SpellCheck1.IgnoreAllCaps;
|
---|
401 |
|
---|
402 | if cbIgnoreDigit.Checked <> SpellCheck1.IgnoreWordWithDigits then
|
---|
403 | cbIgnoreDigit.Checked := SpellCheck1.IgnoreWordWithDigits;
|
---|
404 |
|
---|
405 | if cbHyphenatedWord.Checked <> SpellCheck1.HyphenatedWords then
|
---|
406 | cbHyphenatedWord.Checked := SpellCheck1.HyphenatedWords;
|
---|
407 | end;
|
---|
408 |
|
---|
409 | procedure TfrmHunSpell.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
410 | begin
|
---|
411 | if SpellCheck1.SpellCheckState = ssCompleted then
|
---|
412 | begin
|
---|
413 | // ShowMsg(TX_SPELL_COMPLETE, TShow508MessageIcon(1), smbOK) ;
|
---|
414 | if Assigned(FSourceControl) then
|
---|
415 | FSourceControl.Text := RichEdit1.Text;
|
---|
416 | end;
|
---|
417 | {else
|
---|
418 | ShowMsg(TX_SPELL_CANCELLED + CRLF + TX_NO_CORRECTIONS,
|
---|
419 | TShow508MessageIcon(1), smbOK) ;}
|
---|
420 | end;
|
---|
421 |
|
---|
422 | procedure TfrmHunSpell.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
|
---|
423 | begin
|
---|
424 | inherited;
|
---|
425 |
|
---|
426 | CanClose := (SpellCheck1.SpellCheckState <> ssChecking)
|
---|
427 | or (SpellCheck1.AbortSpellCheck(True));
|
---|
428 | if CanClose then
|
---|
429 | ModalResult := mrCancel;
|
---|
430 | end;
|
---|
431 |
|
---|
432 | procedure TfrmHunSpell.FormCreate(Sender: TObject);
|
---|
433 | var
|
---|
434 | dicFile: String;
|
---|
435 | function affFile: String;
|
---|
436 | begin
|
---|
437 | Result := ChangeFileExt(dicFile, '.aff');
|
---|
438 | end;
|
---|
439 | begin
|
---|
440 | dicFile := ExtractFilePath(Application.ExeName)+ DefaultDicFile;
|
---|
441 |
|
---|
442 | if (FileExists(dicFile)) and (FileExists(affFile)) then
|
---|
443 | begin
|
---|
444 | SpellCheck1.AffixFileName := affFile;
|
---|
445 | SpellCheck1.DictionaryFileName := dicFile;
|
---|
446 | edtDictionary.Text := dicFile;
|
---|
447 | end
|
---|
448 | else
|
---|
449 | edtDictionary.Text := TX_Dic_File_Not_Found;
|
---|
450 |
|
---|
451 | if edtDictionary.Text = TX_Dic_File_Not_Found then
|
---|
452 | btnSelectDictClick(self);
|
---|
453 |
|
---|
454 | SpellCheck1.SourceTextControl := RichEdit1;
|
---|
455 | SpellCheck1.SuggestionList := lstSuggestions;
|
---|
456 | SpellCheck1.MisSpeltWord := edtMisSpelt;
|
---|
457 | btnRestat.Enabled := (SpellCheck1.DictionaryFileName <> '')
|
---|
458 | and FileExists(dicFile);
|
---|
459 | end;
|
---|
460 |
|
---|
461 |
|
---|
462 |
|
---|
463 | procedure TfrmHunSpell.FormKeyUp(Sender: TObject; var Key: Word;
|
---|
464 | Shift: TShiftState);
|
---|
465 | begin
|
---|
466 | if (key = 27) and (pnlAbout.Showing) then
|
---|
467 | btnHideAboutClick(self);
|
---|
468 | end;
|
---|
469 |
|
---|
470 | end.
|
---|