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 | Edit1: 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 | Edit2: TEdit;
|
---|
57 | btnReplaceWith: TButton;
|
---|
58 | btnChangeAll: TButton;
|
---|
59 | btnChange: TButton;
|
---|
60 | btnAddToDictionary: TButton;
|
---|
61 | btnIgnoreAll: TButton;
|
---|
62 | btnIgnoreOnce: TButton;
|
---|
63 | btnCancel: TButton;
|
---|
64 | btnAbout: TButton;
|
---|
65 | pnlAbout: TPanel;
|
---|
66 | Button1: TButton;
|
---|
67 | btnUndo: TButton;
|
---|
68 | procedure FormCreate(Sender: TObject);
|
---|
69 | procedure btnIgnoreOnceClick(Sender: TObject);
|
---|
70 | procedure btnIgnoreAllClick(Sender: TObject);
|
---|
71 | procedure btnChangeClick(Sender: TObject);
|
---|
72 | procedure btnChangeAllClick(Sender: TObject);
|
---|
73 | procedure btnCloseClick(Sender: TObject);
|
---|
74 | procedure FormActivate(Sender: TObject);
|
---|
75 | procedure btnSelectDictClick(Sender: TObject);
|
---|
76 | procedure Edit1Enter(Sender: TObject);
|
---|
77 | procedure btnReplaceWithClick(Sender: TObject);
|
---|
78 | procedure btnAddToDictionaryClick(Sender: TObject);
|
---|
79 | procedure FormShow(Sender: TObject);
|
---|
80 | procedure FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
81 | procedure btnCancelClick(Sender: TObject);
|
---|
82 | procedure lblOpenMedURLClick(Sender: TObject);
|
---|
83 | procedure btnAboutClick(Sender: TObject);
|
---|
84 | procedure Button1Click(Sender: TObject);
|
---|
85 | procedure btnUndoClick(Sender: TObject);
|
---|
86 | private
|
---|
87 | { Private declarations }
|
---|
88 | NoEngineOpted: Boolean;
|
---|
89 | FSourceControl: TCustomMemo;
|
---|
90 | WaitForUser: Boolean;
|
---|
91 | procedure GoToURL(const aURL: String);
|
---|
92 | public
|
---|
93 | { Public declarations }
|
---|
94 | Showhighlight:boolean;
|
---|
95 | highlightcolor:TColor;
|
---|
96 | HighLightList:TStringlist;
|
---|
97 | OldRichEditWndProc: {integer}pointer;
|
---|
98 | PRichEditWndProc:pointer;
|
---|
99 | class function DoHunSpellCheck(AnEditControl: TCustomMemo): TModalResult; static;
|
---|
100 | end;
|
---|
101 |
|
---|
102 | var
|
---|
103 | frmHunSpell: TfrmHunSpell;
|
---|
104 |
|
---|
105 | implementation
|
---|
106 | {$R *.DFM}
|
---|
107 |
|
---|
108 | uses uSpell, VAUtils;
|
---|
109 |
|
---|
110 | class function TfrmHunSpell.DoHunSpellCheck(AnEditControl: TCustomMemo): TModalResult;
|
---|
111 | var
|
---|
112 | frm: TfrmHunSpell;
|
---|
113 | begin
|
---|
114 | Result := mrCancel;
|
---|
115 | frm:= TfrmHunSpell.create(Application);
|
---|
116 | try
|
---|
117 | frm.RichEdit1.Text:= AnEditControl.Text;
|
---|
118 | frm.FSourceControl := AnEditControl;
|
---|
119 | Result := frm.ShowModal;
|
---|
120 | finally
|
---|
121 | frm.Free;
|
---|
122 | end;
|
---|
123 | end;
|
---|
124 |
|
---|
125 | {************ HighLight ***********888}
|
---|
126 | procedure TfrmHunSpell.FormShow(Sender: TObject);
|
---|
127 | begin
|
---|
128 | if SpellCheck1.SpellCheckState = ssNotStarted then
|
---|
129 | SpellCheck1.CheckSpelling;
|
---|
130 |
|
---|
131 | try
|
---|
132 | if lstSuggestions.Count > 0 then
|
---|
133 | btnChange.SetFocus;
|
---|
134 | except
|
---|
135 |
|
---|
136 | end;
|
---|
137 | end;
|
---|
138 |
|
---|
139 | procedure TfrmHunSpell.GoToURL(const aURL: String);
|
---|
140 | begin
|
---|
141 | if length(trim(aURL)) > 4 then
|
---|
142 | ShellExecute(Handle, 'open', PChar(aURL), '', '', SW_NORMAL);
|
---|
143 | end;
|
---|
144 |
|
---|
145 | procedure TfrmHunSpell.lblOpenMedURLClick(Sender: TObject);
|
---|
146 | begin
|
---|
147 | inherited;
|
---|
148 | GoToURL(TLabel(sender).Caption);
|
---|
149 | end;
|
---|
150 |
|
---|
151 | {************* FormCreate **********}
|
---|
152 | procedure TfrmHunSpell.btnAboutClick(Sender: TObject);
|
---|
153 | begin
|
---|
154 | inherited;
|
---|
155 | pnlAbout.Show;
|
---|
156 | pnlAbout.BringToFront;
|
---|
157 | end;
|
---|
158 |
|
---|
159 | procedure TfrmHunSpell.btnAddToDictionaryClick(Sender: TObject);
|
---|
160 | begin
|
---|
161 | SpellCheck1.AddCustomWord;
|
---|
162 | end;
|
---|
163 |
|
---|
164 | procedure TfrmHunSpell.btnReplaceWithClick(Sender: TObject);
|
---|
165 | begin
|
---|
166 | SpellCheck1.CorrectWithMyWord;
|
---|
167 | end;
|
---|
168 |
|
---|
169 | procedure TfrmHunSpell.btnCancelClick(Sender: TObject);
|
---|
170 | begin
|
---|
171 | //popup 508 compliant confirmation/warning box if isModified
|
---|
172 | if SpellCheck1.AbortSpellCheck(False) then
|
---|
173 | begin
|
---|
174 | Close;
|
---|
175 | ModalResult := mrCancel;
|
---|
176 | end;
|
---|
177 | end;
|
---|
178 |
|
---|
179 | procedure TfrmHunSpell.btnChangeAllClick(Sender: TObject);
|
---|
180 | begin
|
---|
181 | SpellCheck1.ChangeAll;
|
---|
182 | end;
|
---|
183 |
|
---|
184 | procedure TfrmHunSpell.btnChangeClick(Sender: TObject);
|
---|
185 | begin
|
---|
186 | SpellCheck1.Change;
|
---|
187 | end;
|
---|
188 |
|
---|
189 | procedure TfrmHunSpell.btnCloseClick(Sender: TObject);
|
---|
190 | begin
|
---|
191 | close;
|
---|
192 | end;
|
---|
193 |
|
---|
194 | procedure TfrmHunSpell.btnIgnoreAllClick(Sender: TObject);
|
---|
195 | begin
|
---|
196 | SpellCheck1.IgnoreAll;
|
---|
197 | end;
|
---|
198 |
|
---|
199 | procedure TfrmHunSpell.btnIgnoreOnceClick(Sender: TObject);
|
---|
200 | begin
|
---|
201 | SpellCheck1.IgnoreOnce;
|
---|
202 | end;
|
---|
203 |
|
---|
204 | procedure TfrmHunSpell.btnSelectDictClick(Sender: TObject);
|
---|
205 | var
|
---|
206 | aff: String;
|
---|
207 | begin
|
---|
208 | if OpenDialog1.Execute then
|
---|
209 | begin
|
---|
210 | if SpellCheck1.DictionaryFileName = OpenDialog1.FileName then
|
---|
211 | exit;
|
---|
212 |
|
---|
213 | aff := ChangeFileExt(OpenDialog1.FileName, '.aff');
|
---|
214 | if not FileExists(aff) then
|
---|
215 | begin
|
---|
216 | ShowMessage('Correspong AFF file named "'+ aff + '" not found!' + #13 + ' Specify dictionary file whose *.aff is also present in same directory.');
|
---|
217 | OpenDialog1.FileName := '';
|
---|
218 | btnSelectDictClick(self);
|
---|
219 | end
|
---|
220 | else
|
---|
221 | begin
|
---|
222 | if SpellCheck1.SpellCheckState = ssChecking then
|
---|
223 | SpellCheck1.AbortSpellCheck(False);
|
---|
224 | Edit1.Text := OpenDialog1.FileName;
|
---|
225 | SpellCheck1.DictionaryFileName := OpenDialog1.FileName;
|
---|
226 | SpellCheck1.AffixFileName := aff;
|
---|
227 | SpellCheck1.Open;
|
---|
228 | WaitForUser := False;
|
---|
229 | SpellCheck1.CheckSpelling;
|
---|
230 | end;
|
---|
231 | end;
|
---|
232 | end;
|
---|
233 |
|
---|
234 | procedure TfrmHunSpell.btnUndoClick(Sender: TObject);
|
---|
235 | begin
|
---|
236 | inherited;
|
---|
237 | SpellCheck1.Undo;
|
---|
238 | end;
|
---|
239 |
|
---|
240 | procedure TfrmHunSpell.Button1Click(Sender: TObject);
|
---|
241 | begin
|
---|
242 | inherited;
|
---|
243 | pnlAbout.hide;
|
---|
244 | end;
|
---|
245 |
|
---|
246 | procedure TfrmHunSpell.Edit1Enter(Sender: TObject);
|
---|
247 | begin
|
---|
248 | btnSelectDict.SetFocus;
|
---|
249 | end;
|
---|
250 |
|
---|
251 | procedure TfrmHunSpell.FormActivate(Sender: TObject);
|
---|
252 | begin
|
---|
253 | if ( not SpellCheck1.Active) and (not NoEngineOpted) then
|
---|
254 | begin
|
---|
255 | btnSelectDictClick(self);
|
---|
256 | NoEngineOpted := True;
|
---|
257 | end;
|
---|
258 | end;
|
---|
259 |
|
---|
260 | procedure TfrmHunSpell.FormClose(Sender: TObject; var Action: TCloseAction);
|
---|
261 | begin
|
---|
262 | if SpellCheck1.SpellCheckState = ssCompleted then
|
---|
263 | begin
|
---|
264 | ShowMsg(TX_SPELL_COMPLETE, TShow508MessageIcon(1), smbOK) ;
|
---|
265 | if Assigned(FSourceControl) then
|
---|
266 | FSourceControl.Text := RichEdit1.Text;
|
---|
267 | end
|
---|
268 | else
|
---|
269 | ShowMsg(TX_SPELL_CANCELLED + CRLF + TX_NO_CORRECTIONS,TShow508MessageIcon(1), smbOK) ;
|
---|
270 | end;
|
---|
271 |
|
---|
272 | procedure TfrmHunSpell.FormCreate(Sender: TObject);
|
---|
273 | begin
|
---|
274 | if FileExists(ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.dic')
|
---|
275 | and FileExists(ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.aff') then
|
---|
276 | begin
|
---|
277 | SpellCheck1.AffixFileName := ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.aff';
|
---|
278 | SpellCheck1.DictionaryFileName := ExtractFilePath(Application.ExeName)+'\dict\en-US-OpenMedSpel.dic';
|
---|
279 | Edit1.Text := SpellCheck1.DictionaryFileName;
|
---|
280 | SpellCheck1.Active := True;
|
---|
281 | end
|
---|
282 | else
|
---|
283 | Edit1.Text := 'Dictionary File for SpellCheck Engine not found!';
|
---|
284 |
|
---|
285 | SpellCheck1.SourceTextControl := RichEdit1;
|
---|
286 | SpellCheck1.SuggestionList := lstSuggestions;
|
---|
287 | SpellCheck1.MisSpeltWord := Edit2;
|
---|
288 | SpellCheck1.btnClose := btnClose;
|
---|
289 | end;
|
---|
290 |
|
---|
291 |
|
---|
292 |
|
---|
293 | end.
|
---|