source: cprs/branches/HealthSevak-CPRS/CPRS-Chart/fHunSpell.pas@ 1723

Last change on this file since 1723 was 1723, checked in by healthsevak, 9 years ago

Did few minor modifications/Additions related to restarting spell check, changing caption of Close button and adding a new button to re-start the spell check if required, and also removed the confirmation dialog/message while closing the dialog as suggested by Jim Bell

File size: 12.4 KB
Line 
1unit 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
33interface
34
35uses
36 Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
37 StdCtrls, ComCtrls, RichEdit, Buttons, ExtCtrls, ShellAPI,
38 skaSpellCheck,
39 VA508AccessibilityManager, fBase508Form;
40
41type
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
135implementation
136{$R *.DFM}
137
138 uses uSpell, VAUtils;
139
140class function TfrmHunSpell.DoHunSpellCheck(AnEditControl: TCustomMemo): TModalResult;
141var
142 frm: TfrmHunSpell;
143begin
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;
153end;
154
155 {************ HighLight ***********888}
156 procedure TfrmHunSpell.FormShow(Sender: TObject);
157begin
158 if SpellCheck1.SpellCheckState = ssReady then
159 SpellCheck1.CheckSpelling;
160 try
161 if lstSuggestions.Count > 0 then
162 btnChange.SetFocus;
163 except
164 end;
165end;
166
167procedure TfrmHunSpell.GoToURL(const aURL: String);
168begin
169if length(trim(aURL)) > 4 then
170 ShellExecute(Handle, 'open', PChar(aURL), '', '', SW_NORMAL);
171end;
172
173procedure TfrmHunSpell.lblOpenMedURLClick(Sender: TObject);
174begin
175 inherited;
176 GoToURL(TLabel(sender).Caption);
177end;
178
179procedure TfrmHunSpell.lstSuggestionsDblClick(Sender: TObject);
180begin
181 inherited;
182 btnChangeClick(sender);
183end;
184
185procedure TfrmHunSpell.RichEdit1KeyDown(Sender: TObject; var Key: Word;
186 Shift: TShiftState);
187begin
188 inherited;
189 if SpellCheck1.SpellCheckState = ssChecking then
190 SpellCheck1.ManualChangeStart;
191end;
192
193procedure TfrmHunSpell.RichEdit1KeyUp(Sender: TObject; var Key: Word;
194 Shift: TShiftState);
195begin
196 inherited;
197 if SpellCheck1.SpellCheckState in [ssCancelled, ssCompleted] then
198 SpellCheck1.Reopen;
199
200 if SpellCheck1.SpellCheckState = ssChecking then
201 SpellCheck1.ManualChangeDone;
202end;
203
204procedure TfrmHunSpell.SpellCheck1Abort(Sender: TObject);
205begin
206 inherited;
207 UpdateGUI;
208end;
209
210procedure TfrmHunSpell.SpellCheck1Start(Sender: TObject);
211begin
212 inherited;
213 UpdateGUI;
214end;
215
216procedure TfrmHunSpell.SpellCheck1StateChange(const Sender: TObject;
217 const State: TSpellState);
218begin
219 inherited;
220 if State = ssCompleted then
221 ShowMessage(TX_SPELL_COMPLETE);
222 UpdateGUI;
223end;
224
225procedure TfrmHunSpell.UpdateGUI;
226var
227 Checking: Boolean;
228begin
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;
235end;
236
237{************* FormCreate **********}
238procedure TfrmHunSpell.btnAboutClick(Sender: TObject);
239begin
240 inherited;
241 pnlAbout.Show;
242 pnlAbout.BringToFront;
243end;
244
245procedure TfrmHunSpell.btnAddToDictionaryClick(Sender: TObject);
246begin
247 SpellCheck1.AddCustomWord;
248end;
249
250procedure TfrmHunSpell.btnReplaceWithClick(Sender: TObject);
251begin
252 SpellCheck1.CorrectWithMyWord;
253end;
254
255procedure TfrmHunSpell.btnRestatClick(Sender: TObject);
256begin
257 inherited;
258 if SpellCheck1.SpellCheckState = ssChecking then
259 SpellCheck1.ReStart
260 else
261 SpellCheck1.CheckSpelling;
262end;
263
264procedure TfrmHunSpell.btnAbortClick(Sender: TObject);
265begin
266//popup 508 compliant confirmation/warning box if isModified
267 if SpellCheck1.AbortSpellCheck(True) then
268 begin
269 Close;
270 ModalResult := mrCancel;
271 end;
272end;
273
274procedure TfrmHunSpell.btnChangeAllClick(Sender: TObject);
275begin
276 SpellCheck1.ChangeAll;
277end;
278
279procedure TfrmHunSpell.btnChangeClick(Sender: TObject);
280begin
281 SpellCheck1.Change;
282end;
283
284procedure TfrmHunSpell.btnCloseClick(Sender: TObject);
285begin
286 close;
287end;
288
289procedure TfrmHunSpell.btnIgnoreAllClick(Sender: TObject);
290begin
291 SpellCheck1.IgnoreAll;
292end;
293
294procedure TfrmHunSpell.btnIgnoreOnceClick(Sender: TObject);
295begin
296 SpellCheck1.IgnoreOnce;
297end;
298
299procedure TfrmHunSpell.btnSelectDictClick(Sender: TObject);
300var
301 aff: String;
302begin
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;
325end;
326
327procedure TfrmHunSpell.btnUndoClick(Sender: TObject);
328begin
329 inherited;
330 SpellCheck1.Undo;
331end;
332
333procedure TfrmHunSpell.Button1Click(Sender: TObject);
334begin
335 inherited;
336 pnlAbout.hide;
337end;
338
339procedure TfrmHunSpell.cbIgnoreAllCapsClick(Sender: TObject);
340begin
341 inherited;
342 if SpellCheck1.IgnoreAllCaps <> cbIgnoreAllCaps.Checked then
343 SpellCheck1.IgnoreAllCaps := cbIgnoreAllCaps.Checked;
344end;
345
346procedure TfrmHunSpell.cbIgnoreDigitClick(Sender: TObject);
347begin
348 inherited;
349 if SpellCheck1.IgnoreWordWithDigits <> cbIgnoreDigit.Checked then
350 SpellCheck1.IgnoreWordWithDigits := cbIgnoreDigit.Checked;
351end;
352
353procedure TfrmHunSpell.edtDictionaryEnter(Sender: TObject);
354begin
355 btnSelectDict.SetFocus;
356end;
357
358procedure TfrmHunSpell.FormActivate(Sender: TObject);
359begin
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;
370end;
371
372procedure TfrmHunSpell.FormClose(Sender: TObject; var Action: TCloseAction);
373begin
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) ;}
383end;
384
385procedure TfrmHunSpell.FormCloseQuery(Sender: TObject; var CanClose: Boolean);
386begin
387 inherited;
388
389 CanClose := (SpellCheck1.SpellCheckState <> ssChecking)
390 or (SpellCheck1.AbortSpellCheck(True));
391 if CanClose then
392 ModalResult := mrCancel;
393end;
394
395procedure TfrmHunSpell.FormCreate(Sender: TObject);
396var
397 dicFile: String;
398 function affFile: String;
399 begin
400 Result := ChangeFileExt(dicFile, '.aff');
401 end;
402begin
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);
423end;
424
425
426
427end.
Note: See TracBrowser for help on using the repository browser.