source: cprs/branches/HealthSevak-CPRS/CPRS-Lib/Hans SpellCheck/skaSpellCheck.pas@ 1694

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

Did few modifications related to manual modifications by user inside RichEdit while spellcheck running

File size: 21.4 KB
Line 
1unit skaSpellCheck;
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, Classes, SysUtils, ComCtrls, StdCtrls, Graphics;
37
38 const
39 AboutThis = 'A wrapper component developed by Sunil K Arora (digitiger@gmail.com) of HealthSevak using OpenSource HanSpell engine';
40type
41 TSpellState = (ssNotStarted, ssChecking, ssCancelled, ssCompleted);
42
43 TskaHunSpellChecker = class(TComponent)
44 private
45 FActiveOrLoaded: Boolean;
46 FpointerHunLib: Pointer;
47 FSourceEdit: TRichEdit;
48 FSuggestionList: TListbox;
49
50 FAffixFileName: string;
51 FDictFileName: string;
52 CurrentWord: String;
53 CurrentText: String;
54 FoundAt: Integer;
55 PosOfFirstCharInCurrentLine: integer;
56 CurrentLine: Integer;
57 FIgnore: TStringList;
58 WaitForUser: Boolean;
59 WordLength:integer;
60 WordPos: Integer;
61 PREditorWndProc:pointer;
62 FHighlightColor: TColor;
63 FShowCompletion: Boolean;
64 FpointerSpellComplete: String;
65 FStatus: TSpellState;
66 FUndoList: TStringList;
67 FCustDict: TStringList;
68 FCustom: String;
69 FModified: Boolean;
70 FHighlightEdit: TEdit;
71 FbtnClose: TButton;
72 FTxtBeforeManualEdit: String;
73 function AddCustomWord(aWord: String; isInternal: Boolean = False): Boolean;
74 overload; virtual;
75 Function CurrentWordDetail(WithPosition: Boolean= True): String;
76 function GetActive: Boolean;
77 function GetStatus: TSpellState;
78 procedure Initialize;
79 procedure SetActive(const Value: Boolean);
80 procedure SetAffixFileName(const Value: string);
81 procedure SetbtnClose(const Value: TButton);
82 procedure SetCustomDict(const Value: String);
83 procedure SetDictFileName(const Value: string);
84 procedure SetHighLightEdit(const Value: TEdit);
85 procedure SetSourceEdit(const Value: TRichEdit);
86 Function ShowMisSpelledWord:boolean;
87 procedure Loaded; override;
88 procedure ReplaceCurrentWordWith(const aNewWord: String);
89 function GetAboutThis: String;
90 procedure SaveForUndo(const Ignoring: Boolean=False);
91 public
92 constructor Create(AOwner: TComponent); overload; override;
93 constructor Create(AOwner: TComponent; SourceTextRichEdit: TRichedit;
94 SuggestList: TListbox); ReIntroduce; overload;
95 destructor Destroy; override;
96
97 function AbortSpellCheck(Verbose: Boolean = True):Boolean;
98 function AddCustomWord: Boolean; overload; virtual;
99 procedure Change;
100 procedure ChangeAll;
101 procedure CheckSpelling;
102 procedure Close; virtual;
103 procedure CorrectWithMyWord;
104 procedure GetSuggestions(const aMisSpeltWord: string;
105 const SuggestionList: TStrings); dynamic;
106 procedure IgnoreAll;
107 procedure IgnoreOnce;
108 function IsMisspelled(const AWord: string): Boolean; dynamic;
109 procedure ManualChangeStart;
110 procedure ManualChangeDone;
111 function Open:Boolean; virtual;
112 function ReStart: Boolean; virtual;
113
114 function Undo: Boolean;
115
116
117 property SpellCheckState: TSpellState read GetStatus default ssNotStarted;
118 published
119 property About: String read GetAboutThis;
120 property Active: Boolean read GetActive write SetActive;
121 property AffixFileName: string read FAffixFileName write SetAffixFileName;
122 property btnClose: TButton read FbtnClose write SetbtnClose;
123 property CustDictionaryFile: String read FCustom write SetCustomDict;
124 property DictionaryFileName:string read FDictFileName write SetDictFileName;
125 property ColorForMisspelled: TColor read FHighlightColor write FHighlightColor default clRed;
126 property MisSpeltWord: TEdit read FHighlightEdit write SetHighLightEdit;
127 property IsModified: Boolean read FModified;
128 property ShowCompletionMessage: Boolean read FShowCompletion write FShowCompletion default True;
129 property SourceTextControl: TRichEdit read FSourceEdit write SetSourceEdit;
130 property SpellCheckCompletionMessage: String read FpointerSpellComplete write FpointerSpellComplete;
131 property SuggestionList: TListbox read FSuggestionList write FSuggestionList;
132
133 end;
134
135 procedure Register;
136
137 Const
138 CompletionMessage = 'Spell Check Complete.';
139 CaptionForNewWord = 'New Word Suggestion';
140 ConfirmAbort = 'Really abort?';
141 PromptForNewWord = 'Specify the replacement for current mis-spelt word:';
142 DLLNotLoaded = 'Failed to load SpellCheck Engine DLL.';
143 MisSpeltReplacement = 'The new word specified by you "%s" looks mis-spelt!'
144 +' Would you want to still use it? Click NO button '
145 +'to specify better replacement word.';
146 var
147 OldRichEditWndProc: {integer}pointer;
148 CurrentMe: TskaHunSpellChecker;
149implementation
150 uses messages, Dialogs, RichEdit, SHFolder, Forms, uHunSpellLib;
151
152procedure Register;
153begin
154 RegisterComponentsProc('SkA Utility', [TskaHunSpellChecker]);
155end;
156
157{ TskaHunSpellChecker }
158
159function TskaHunSpellChecker.AbortSpellCheck(Verbose: Boolean = True): Boolean;
160begin
161 Result := (not isModified) or
162 (not Verbose) or (MessageDlg(ConfirmAbort, mtConfirmation,
163 [mbYes, mbNo],0, mbNo) = 6);
164
165 if Result then
166 FStatus := ssCancelled;
167end;
168
169function TskaHunSpellChecker.AddCustomWord(aWord: String; isInternal: Boolean = False): Boolean;
170begin
171 Result := False;
172 if (trim(aWord) = '') or (not assigned(SourceTextControl)) or (not assigned(SuggestionList)) then
173
174
175 Result := False;
176 if (not Active) then Exit;
177 uHunSpellLib.hunspell_put_word(FpointerHunLib, PAnsiChar(AnsiString(aWord)));
178 Result := True;
179end;
180
181procedure TskaHunSpellChecker.ChangeAll;
182begin
183 if (SpellCheckState <> ssChecking) or (not assigned(SourceTextControl)) or (not assigned(SuggestionList)) then
184 exit;
185 SaveForUndo;
186 SourceTextControl.Text := StringReplace(SourceTextControl.Text,
187 CurrentWord, SuggestionList.Items[SuggestionList.ItemIndex],
188 [rfReplaceAll,rfIgnoreCase]);
189 WaitForUser := False;
190 FModified := True;
191 SourceTextControl.Invalidate;
192
193end;
194
195function TskaHunSpellChecker.AddCustomWord: Boolean;
196begin
197 Result := AddCustomWord(CurrentWord, False);
198 FCustdict.Add(CurrentWord);
199 WaitForUser := False;
200 AbortSpellCheck(False);
201 Initialize;
202 CheckSpelling;
203 ShowMisSpelledWord;
204end;
205
206procedure TskaHunSpellChecker.ReplaceCurrentWordWith(const aNewWord: String);
207var
208 full: String;
209 prefix: string;
210 suffix: string;
211begin
212 full := SourceTextControl.Lines[CurrentLine];
213 prefix := copy(CurrentText, 1, WordPos-1);
214 Suffix := copy(CurrentText, WordPos+WordLength,
215 length(CurrentText));
216 SaveForUndo;
217 SourceTextControl.Lines[CurrentLine] :=prefix + aNewWord + suffix;
218 WaitForUser := False;
219 FStatus := ssChecking;
220 FModified := True;
221 SourceTextControl.Invalidate;
222end;
223
224function TskaHunSpellChecker.ReStart: Boolean;
225begin
226 Close;
227 Result := Open;
228 Initialize;
229 WaitForUser := False;
230 SourceTextControl.Invalidate;
231 Result := not WaitForUser;
232end;
233
234procedure TskaHunSpellChecker.Change;
235
236begin
237 if (SpellCheckState <> ssChecking) or (not assigned(SourceTextControl)) or (not assigned(SuggestionList)) then
238 exit;
239 ReplaceCurrentWordWith(SuggestionList.Items[SuggestionList.ItemIndex]);
240end;
241
242procedure TskaHunSpellChecker.CheckSpelling;
243begin
244 if (SpellCheckState = ssChecking) or (not assigned(SourceTextControl)) or (not assigned(SuggestionList)) then
245 exit;
246
247 Initialize;
248 FUndoList.Clear;
249 WaitForUser := False;
250 FStatus := ssChecking;
251 SourceTextControl.Invalidate;
252 //SourceTextControl.Invalidate;
253end;
254
255procedure TskaHunSpellChecker.Close;
256begin
257 if not Active then Exit;
258 uHunSpellLib.hunspell_uninitialize(FpointerHunLib);
259 FpointerHunLib := nil;
260end;
261
262
263procedure TskaHunSpellChecker.CorrectWithMyWord;
264var
265 NewWord: String;
266 GotIt: Boolean;
267begin
268 if (SpellCheckState <> ssChecking) or (not assigned(SourceTextControl)) or (not assigned(SuggestionList)) then
269 exit;
270
271 if SuggestionList.Count > 0 then
272 NewWord := SuggestionList.Items[0]
273 else
274 NewWord := CurrentWord;
275
276 GotIt := False;
277 while not GotIt do
278 begin
279 if not InputQuery(CaptionForNewWord, PromptForNewWord, NewWord) then
280 exit;
281
282 GotIt := (not IsMisspelled(NewWord))
283 or (MessageDlg(Format(MisSpeltReplacement,[NewWord]),
284 mtWarning, [mbYes, mbNo],0, mbNo) =6) ;
285 end;
286
287 if IsMisspelled(NewWord) then
288 AddCustomWord(NewWord, True);
289
290 ReplaceCurrentWordWith(NewWord);
291end;
292
293constructor TskaHunSpellChecker.Create(AOwner: TComponent);
294 function GetSpecialFolderPath(folder : integer) : string;
295 var
296 path: array [0..MAX_PATH] of char;
297 begin
298 if SUCCEEDED(SHGetFolderPath(0,folder,0,0,@path[0])) then
299 Result := path
300 else
301 Result := '';
302 end;
303begin
304 inherited;
305
306 ColorForMisspelled := clRed;
307 ShowCompletionMessage := True;
308 SpellCheckCompletionMessage := CompletionMessage;
309
310
311
312 CurrentMe := Self;
313 FIgnore := TStringList.Create;
314 FCustDict := TStringList.Create;
315
316 CustDictionaryFile := IncludeTrailingPathDelimiter(GetSpecialFolderPath(CSIDL_PERSONAL)) + 'CustomDictionary.txt';
317 if FileExists(CustDictionaryFile) then
318 try
319 FCustDict.LoadFromFile(CustDictionaryFile);
320 except
321 end;
322
323 FUndoList := TStringList.Create;
324
325 FStatus := ssNotStarted;
326 WaitForUser := False;
327 WordPos := 0;
328end;
329
330constructor TskaHunSpellChecker.Create(AOwner: TComponent;
331 SourceTextRichEdit: TRichedit; SuggestList: TListbox);
332begin
333 create(AOwner);
334 SourceTextControl := SourceTextRichEdit;
335 SuggestionList := SuggestList;
336end;
337
338function TskaHunSpellChecker.CurrentWordDetail(WithPosition: Boolean): String;
339begin
340 Result := '$$' + CurrentWord + '$$';
341 if WithPosition then
342 Result := '$$' + IntToStr(FoundAt+1) + Result;
343end;
344
345destructor TskaHunSpellChecker.Destroy;
346begin
347 Close;
348 FIgnore.clear;
349 FreeAndNil(FIgnore);
350 FreeAndNil(FUndoList);
351 if not (csDesigning in ComponentState) then
352 try
353 if FCustDict.Count > 0 then
354 try
355 FCustDict.SaveToFile(CustDictionaryFile);
356 except
357 end;
358 finally
359 FCustDict.Free;
360 end;
361 inherited;
362end;
363
364function TskaHunSpellChecker.GetAboutThis: String;
365begin
366 Result := AboutThis;
367end;
368
369function TskaHunSpellChecker.GetActive: Boolean;
370begin
371 Result := (FpointerHunLib <> nil);
372end;
373
374function TskaHunSpellChecker.GetStatus: TSpellState;
375begin
376 Result := FStatus;
377end;
378
379procedure TskaHunSpellChecker.GetSuggestions(const aMisSpeltWord: string;
380 const SuggestionList: TStrings);
381var
382 i: Integer;
383 pMisSpelt: PAnsiChar;
384 suggestions: PPAnsiChar;
385 Results: PPAnsiChar;
386 Count: Integer;
387begin
388 if (not Active) or (not Assigned(SuggestionList)) then
389 exit;
390
391 pMisSpelt := PAnsiChar(AnsiString(aMisSpeltWord));
392
393 if not uHunSpellLib.hunspell_spell(FpointerHunLib, pMisSpelt) then
394 uHunSpellLib.hunspell_suggest_auto(FpointerHunLib, pMisSpelt, suggestions);
395 begin
396 Count := uHunSpellLib.hunspell_suggest(FpointerHunLib, pMisSpelt, suggestions);
397 Results := suggestions;
398 for i := 1 to Count do
399 begin
400 SuggestionList.Add(Results^);
401 Inc(Integer(Results), SizeOf(Pointer));
402 end;
403 uHunSpellLib.hunspell_suggest_free(FpointerHunLib, suggestions, Count);
404 end;
405end;
406
407function TskaHunSpellChecker.ShowMisSpelledWord: boolean;
408var
409 I , l :integer;
410 CharPosion:integer;
411 FirstVisibleLine, LastVisibleLine:integer;
412
413 hndl: hwnd;
414 dcForHndl: THandle;
415 visrect:Trect;
416 vispoint:TPoint;
417 procedure ShowMisSpelletWord;
418 begin
419 if Assigned(FHighlightEdit) then
420 begin
421 FHighlightEdit.Font.Color := ColorForMisspelled;
422 FHighlightEdit.Text := CurrentWord;
423 FHighlightEdit.Show;
424 end ;
425
426 if ((PosOfFirstCharInCurrentLine + FoundAt) < 1) then
427 exit;
428
429 SendMessage (SourceTextControl.Handle, EM_POSFROMCHAR, integer(@VisPoint), PosOfFirstCharInCurrentLine + FoundAt-1);
430 SetTextColor(dcForHndl, ColorForMisspelled);
431 TextOut(dcForHndl, VisPoint.x, VisPoint.y, pchar(CurrentWord), WordLength);
432 end;
433begin
434 Result := False;
435 if (SpellCheckState <> ssChecking) or (not assigned(SourceTextControl))
436 or (not assigned(SuggestionList)) then
437 exit;
438
439 hndl:=SourceTextControl.Handle;
440
441 result:= SendMessage (hndl, EM_GETRECT, 0, integer(@visrect))=0;
442
443 dcForHndl := getdc(hndl);
444
445 if result then
446 begin
447 // VisPoint := visrect.BottomRight;
448 vispoint.Y := visrect.Bottom;
449 vispoint.X := visrect.Right;
450 CharPosion := SendMessage (hndl, EM_CHARFROMPOS, 0, integer(@VisPoint));
451 LASTVISIBLELINE := SendMessage (hndl, EM_LINEFROMCHAR, CharPosion, 0);
452 FIRSTVISIBLELINE := SendMessage (hndl, EM_GETFIRSTVISIBLELINE, 0, 0);
453
454 SetBkMode (dcForHndl, TRANSPARENT);
455 SelectObject(dcForHndl, SourceTextControl.font.Handle);
456 i := 0;
457
458 if WaitForUser then
459 begin
460 ShowMisSpelletWord;
461 exit;
462 end;
463
464 For l := 0 to SourceTextControl.Lines.Count -1 do
465 begin
466 {$R-}
467 CurrentLine := l;
468 if trim(SourceTextControl.Lines[CurrentLine]) = '' then
469 continue;
470
471 CurrentText := ' ' + SourceTextControl.Lines[CurrentLine];
472 PosOfFirstCharInCurrentLine := SendMessage (SourceTextControl.Handle, EM_LINEINDEX, CurrentLine, 0);
473 i := 0;
474
475 While i <= LENgth(CurrentText) do
476 begin
477 FoundAt := i -1;
478 if Assigned(FHighlightEdit) then
479 FHighlightEdit.Hide;
480
481
482 //SuggestionList.Clear;
483 {Any character except these will count as a word delimiter}
484 While CurrentText[i] in ['A'..'Z','a'..'z','0'..'9'] do inc(i);
485
486 WordLength := i- FoundAt -1;
487 WordPos := i-WordLength;
488 CurrentWord := copy(CurrentText, WordPos, WordLength);
489 If ((FIgnore.IndexOf(CurrentWordDetail(True))< 0) //SingelIgnore
490 and (FIgnore.IndexOf(CurrentWordDetail(False))< 0) //IgnoreAll
491 and (IsMisspelled(CurrentWord))) Then
492 begin
493 GetSuggestions(CurrentWord, SuggestionList.Items);
494 if SuggestionList.Count > 0 then
495 SuggestionList.ItemIndex := 0;
496 ShowMisSpelletWord;
497 if CurrentLine > LastVisibleLine then
498 SendMessage(SourceTextControl.Handle, EM_LINESCROLL, 0, (CurrentLine - lastvisibleLine)+5);
499 WaitForUser := True;
500 exit;
501 End
502 else
503 SuggestionList.Clear;
504 inc(i);
505 end;
506 end;
507 if (CurrentLine >= SourceTextControl.Lines.Count-1) and (i >= length(CurrentText) +1) then
508 begin
509 FStatus := ssCompleted;
510 if Assigned(btnClose) then
511 btnClose.Click;
512 end;
513 {$R+}
514 end;
515 ReleaseDC(SourceTextControl.Handle, dcForHndl);
516
517End;
518
519function TskaHunSpellChecker.Undo: Boolean;
520var
521 tmpStr: String;
522 tmpCount: Integer;
523begin
524 if FUndoList.Count > 0 then
525 try
526 tmpStr := FUndoList.Strings[FUndoList.Count-1];
527 { showmessage(inttostr(AnsiPos('$$',tmpStr)) + #13 + inttostr(length(tmpstr)) + #13 +
528 copy(tmpStr,length(tmpStr)-2,2)); }
529 if (AnsiPos('$$',tmpStr)=1) and (copy(tmpStr,length(tmpStr)-1,2) = '$$')then
530 begin
531 tmpCount := strtoInt(StringReplace(tmpStr,'$$','',[rfReplaceAll]));
532 while FIgnore.Count > tmpCount do
533 FIgnore.Delete(FIgnore.Count -1);
534 end
535 else
536 SourceTextControl.Text := tmpStr;
537
538 Result := True;
539 FUndoList.Delete(FUndoList.Count-1);
540 ReStart;
541 except
542 Result := False;
543 end;
544end;
545
546procedure TskaHunSpellChecker.IgnoreAll;
547begin
548 if (SpellCheckState <> ssChecking) or (not assigned(SourceTextControl)) or (not assigned(SuggestionList)) then
549 exit;
550 SaveForUndo(True);
551 FIgnore.Add(CurrentWordDetail(False)) ;
552 WaitForUser := False;
553 SourceTextControl.Invalidate;
554end;
555
556procedure TskaHunSpellChecker.IgnoreOnce;
557begin
558 if (SpellCheckState <> ssChecking) or (not assigned(SourceTextControl)) or (not assigned(SuggestionList)) then
559 exit;
560 if trim(CurrentWord) <> '' then
561 begin
562 SaveForUndo(True);
563 FIgnore.Add(CurrentWordDetail(True)) ;
564 end;
565 WaitForUser := False;
566 SourceTextControl.Invalidate;
567end;
568
569procedure TskaHunSpellChecker.Initialize;
570begin
571 CurrentWord := '';
572 WordLength := 0;
573 FoundAt := -1;
574 CurrentLine := 0;
575 WordPos := 0;
576 SuggestionList.Clear;
577end;
578
579function TskaHunSpellChecker.IsMisspelled(const AWord: string): Boolean;
580begin
581 if (not Active) then
582 Result := True
583 else
584 Result := not uHunSpellLib.hunspell_spell(FpointerHunLib, PAnsiChar(AnsiString(AWord)));
585end;
586
587procedure TskaHunSpellChecker.Loaded;
588begin
589 inherited;
590 SetActive(FActiveOrLoaded);
591end;
592
593procedure TskaHunSpellChecker.ManualChangeDone;
594begin
595 if trim(FTxtBeforeManualEdit) = '' then
596 exit;
597 FUndoList.Add(FTxtBeforeManualEdit);
598 ReStart;
599end;
600
601procedure TskaHunSpellChecker.ManualChangeStart;
602begin
603 FTxtBeforeManualEdit := FSourceEdit.Text;
604end;
605
606function TskaHunSpellChecker.Open: Boolean;
607var
608 CurrentLine: integer;
609begin
610 Result := True;
611 if Active then Exit;
612 Result := False;
613 FpointerHunLib := Nil;
614 if not uHunSpellLib.LoadLibHunspell('') then
615 begin
616 MessageDlg(DLLNotLoaded, mtError, [mbOK],0);
617 Exit;
618 end;
619 FpointerHunLib := uHunSpellLib.hunspell_initialize(PAnsiChar(AnsiString(FAffixFileName)), PAnsiChar(AnsiString(FDictFileName)));
620 Result := Assigned(FpointerHunLib);
621
622 if (Result) and (assigned(FCustDict)) then
623 for CurrentLine := 0 to FCustDict.Count - 1 do
624 AddCustomWord(FCustDict[CurrentLine], True);
625end;
626
627procedure TskaHunSpellChecker.SaveForUndo(const Ignoring: Boolean = False);
628begin
629 if Ignoring then
630 FUndoList.Add('$$'+ IntToStr(FIgnore.Count)+'$$')
631 else
632 FUndoList.Add(SourceTextControl.Text);
633end;
634
635procedure TskaHunSpellChecker.SetActive(const Value: Boolean);
636begin
637 if (csDesigning in ComponentState) or (csLoading in ComponentState) then
638 FActiveOrLoaded := Value
639 else
640 if Value then
641 FActiveOrLoaded := Open
642 else
643 Close;
644end;
645
646procedure TskaHunSpellChecker.SetAffixFileName(const Value: string);
647begin
648 Close;
649 FAffixFileName := Value;
650end;
651
652procedure TskaHunSpellChecker.SetbtnClose(const Value: TButton);
653begin
654 if btnClose = Value then
655 exit;
656 FbtnClose := Value;
657 FbtnClose.ModalResult := 1; //mrOK
658end;
659
660procedure TskaHunSpellChecker.SetCustomDict(const Value: String);
661begin
662 FCustom := Value;
663 if not (csDesigning in componentState) then
664 if Active and (FileExists(Value)) then
665 FCustDict.LoadFromFile(Value);
666end;
667
668procedure TskaHunSpellChecker.SetDictFileName(const Value: string);
669begin
670 Close;
671 FDictFileName := Value;
672end;
673
674procedure TskaHunSpellChecker.SetHighLightEdit(const Value: TEdit);
675begin
676 if FHighlightEdit = Value then
677 exit;
678
679 FHighlightEdit := Value;
680
681 if Active then
682 FHighlightEdit.Text := CurrentWord;
683
684
685end;
686
687Function RichEditWndProc (handle:HWnd;uMsg,wParam,lParam:longint): longint stdcall;
688begin
689 Result := CallWindowProc(OldRichEditWndProc, handle, uMsg, wParam, lParam);
690 if (uMsg=WM_PAINT) and assigned(CurrentMe) then CurrentMe.ShowMisSpelledWord;
691End;
692
693procedure TskaHunSpellChecker.SetSourceEdit(const Value: TRichEdit);
694begin
695 if FSourceEdit = Value then
696 exit;
697
698 FSourceEdit := Value;
699
700 if csDesigning in ComponentState then
701 exit;
702
703 PREditorWndProc:=@RichEditWndProc;
704 Value.perform(EM_EXLIMITTEXT, 0, 65535*32); //raise the limit of text which could be inserted into this Richedit
705 OldRichEditWndProc := pointer(SetWindowLong(Value.handle, GWL_WNDPROC, longint(@RichEditWndProc)));
706
707end;
708
709end.
Note: See TracBrowser for help on using the repository browser.