[1693] | 1 | unit 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 | *
|
---|
[1715] | 19 | *Special Note:
|
---|
| 20 | * This work has heavily relies upon rather build upon Copyrighted work by
|
---|
| 21 | * Miha Vrhovnik (http://simail.sf.net, http://xcollect.sf.net) which is
|
---|
| 22 | * available at http://sourceforge.net/projects/hunspell/
|
---|
| 23 | *
|
---|
[1693] | 24 | * Alternatively, the content of this file maybe used under the terms of either
|
---|
| 25 | * the GNU General Public License Version 2 or later (the "GPL"), or the GNU
|
---|
| 26 | * Lesser General Public License Version 2.1 or later (the "LGPL"), in which
|
---|
| 27 | * case the provisions of the GPL or the LGPL are applicable instead of those
|
---|
| 28 | * above. If you wish to allow use of your version of this file only under the
|
---|
| 29 | * terms of either the GPL or the LGPL, and not to allow others to use your
|
---|
| 30 | * version of this file under the terms of the MPL, indicate your division by
|
---|
| 31 | * deleting the provisions above and replace them with the notice and other
|
---|
| 32 | * provisions required by the GPL or LGPL. If you do not delete the provisions
|
---|
| 33 | * above, a recipient may use your version of this file under the terms of any
|
---|
| 34 | * one of the MPL, the GPL or the LGPL.
|
---|
| 35 | *
|
---|
| 36 | * *********************** END LICENSE BLOCK *********************************)
|
---|
| 37 |
|
---|
| 38 | interface
|
---|
| 39 |
|
---|
| 40 | uses
|
---|
[1715] | 41 | Windows, Classes, SysUtils, ComCtrls, StdCtrls, Graphics, Forms, Controls;
|
---|
[1693] | 42 |
|
---|
| 43 | const
|
---|
[1715] | 44 | AboutThis = 'A wrapper component developed by Sunil K Arora '
|
---|
| 45 | + '(digitiger@gmail.com) of HealthSevak using OpenSource HanSpell engine';
|
---|
[1693] | 46 | type
|
---|
[1715] | 47 | TSpellState = (ssNoengine, ssInActive, ssReady, ssChecking, ssCancelled,
|
---|
| 48 | ssCompleted);
|
---|
| 49 | TStateChangeEvent = procedure (const Sender : TObject;
|
---|
| 50 | const State : TSpellState) of object;
|
---|
[1693] | 51 |
|
---|
| 52 | TskaHunSpellChecker = class(TComponent)
|
---|
| 53 | private
|
---|
| 54 | FActiveOrLoaded: Boolean;
|
---|
| 55 | FpointerHunLib: Pointer;
|
---|
| 56 | FSourceEdit: TRichEdit;
|
---|
| 57 | FSuggestionList: TListbox;
|
---|
| 58 |
|
---|
| 59 | FAffixFileName: string;
|
---|
| 60 | FDictFileName: string;
|
---|
| 61 | CurrentWord: String;
|
---|
| 62 | CurrentText: String;
|
---|
| 63 | FoundAt: Integer;
|
---|
| 64 | PosOfFirstCharInCurrentLine: integer;
|
---|
| 65 | CurrentLine: Integer;
|
---|
| 66 | FIgnore: TStringList;
|
---|
| 67 | WaitForUser: Boolean;
|
---|
| 68 | WordLength:integer;
|
---|
| 69 | WordPos: Integer;
|
---|
| 70 | PREditorWndProc:pointer;
|
---|
| 71 | FHighlightColor: TColor;
|
---|
| 72 | FUndoList: TStringList;
|
---|
| 73 | FCustDict: TStringList;
|
---|
| 74 | FCustom: String;
|
---|
| 75 | FModified: Boolean;
|
---|
| 76 | FHighlightEdit: TEdit;
|
---|
[1694] | 77 | FTxtBeforeManualEdit: String;
|
---|
[1715] | 78 |
|
---|
| 79 | FStatus: TSpellState;
|
---|
| 80 | FOnStart: TNotifyEvent;
|
---|
| 81 | FOnAbort : TNotifyEvent;
|
---|
| 82 | FOnStateChange : TStateChangeEvent;
|
---|
[1718] | 83 | FIgnoreWordWdigits: boolean;
|
---|
| 84 | FIgnoreCaps: boolean;
|
---|
[1720] | 85 | FOptionsKey: String;
|
---|
[1693] | 86 | function AddCustomWord(aWord: String; isInternal: Boolean = False): Boolean;
|
---|
| 87 | overload; virtual;
|
---|
| 88 | Function CurrentWordDetail(WithPosition: Boolean= True): String;
|
---|
| 89 | function GetActive: Boolean;
|
---|
[1718] | 90 | procedure GetOptions;
|
---|
[1693] | 91 | function GetStatus: TSpellState;
|
---|
| 92 | procedure Initialize;
|
---|
| 93 | procedure SetActive(const Value: Boolean);
|
---|
| 94 | procedure SetAffixFileName(const Value: string);
|
---|
| 95 | procedure SetCustomDict(const Value: String);
|
---|
| 96 | procedure SetDictFileName(const Value: string);
|
---|
| 97 | procedure SetHighLightEdit(const Value: TEdit);
|
---|
[1718] | 98 | procedure SetOptions;
|
---|
[1693] | 99 | procedure SetSourceEdit(const Value: TRichEdit);
|
---|
| 100 | Function ShowMisSpelledWord:boolean;
|
---|
| 101 | procedure Loaded; override;
|
---|
| 102 | procedure ReplaceCurrentWordWith(const aNewWord: String);
|
---|
| 103 | function GetAboutThis: String;
|
---|
[1694] | 104 | procedure SaveForUndo(const Ignoring: Boolean=False);
|
---|
[1715] | 105 | procedure InformStatusChange;
|
---|
[1718] | 106 | procedure SetIgnoreCaps(const Value: boolean);
|
---|
| 107 | procedure SetIgnoreWordWdigits(const Value: boolean);
|
---|
[1693] | 108 | public
|
---|
| 109 | constructor Create(AOwner: TComponent); overload; override;
|
---|
| 110 | constructor Create(AOwner: TComponent; SourceTextRichEdit: TRichedit;
|
---|
| 111 | SuggestList: TListbox); ReIntroduce; overload;
|
---|
| 112 | destructor Destroy; override;
|
---|
| 113 |
|
---|
| 114 | function AbortSpellCheck(Verbose: Boolean = True):Boolean;
|
---|
| 115 | function AddCustomWord: Boolean; overload; virtual;
|
---|
| 116 | procedure Change;
|
---|
| 117 | procedure ChangeAll;
|
---|
| 118 | procedure CheckSpelling;
|
---|
| 119 | procedure Close; virtual;
|
---|
| 120 | procedure CorrectWithMyWord;
|
---|
| 121 | procedure GetSuggestions(const aMisSpeltWord: string;
|
---|
| 122 | const SuggestionList: TStrings); dynamic;
|
---|
| 123 | procedure IgnoreAll;
|
---|
| 124 | procedure IgnoreOnce;
|
---|
| 125 | function IsMisspelled(const AWord: string): Boolean; dynamic;
|
---|
[1694] | 126 | procedure ManualChangeStart;
|
---|
| 127 | procedure ManualChangeDone;
|
---|
[1693] | 128 | function Open:Boolean; virtual;
|
---|
[1715] | 129 | procedure ReOpen;
|
---|
[1693] | 130 | function ReStart: Boolean; virtual;
|
---|
| 131 | function Undo: Boolean;
|
---|
[1715] | 132 | property SpellCheckState: TSpellState read GetStatus default ssInActive;
|
---|
[1693] | 133 | published
|
---|
| 134 | property About: String read GetAboutThis;
|
---|
| 135 | property Active: Boolean read GetActive write SetActive;
|
---|
| 136 | property AffixFileName: string read FAffixFileName write SetAffixFileName;
|
---|
[1718] | 137 | property IgnoreAllCaps: boolean read FIgnoreCaps write SetIgnoreCaps default true;
|
---|
| 138 | property IgnoreWordWithDigits:boolean read FIgnoreWordWdigits write SetIgnoreWordWdigits default true;
|
---|
[1693] | 139 | property CustDictionaryFile: String read FCustom write SetCustomDict;
|
---|
| 140 | property DictionaryFileName:string read FDictFileName write SetDictFileName;
|
---|
[1715] | 141 | property ColorForMisspelled: TColor read FHighlightColor
|
---|
| 142 | write FHighlightColor default clRed;
|
---|
[1693] | 143 | property MisSpeltWord: TEdit read FHighlightEdit write SetHighLightEdit;
|
---|
| 144 | property IsModified: Boolean read FModified;
|
---|
[1715] | 145 | property OnStart : TNotifyEvent read FOnStart write FOnStart;
|
---|
| 146 | property OnStateChange : TStateChangeEvent read FOnStateChange
|
---|
| 147 | write FOnStateChange;
|
---|
| 148 | property OnAbort : TNotifyEvent read FOnAbort write FOnAbort;
|
---|
[1693] | 149 | property SourceTextControl: TRichEdit read FSourceEdit write SetSourceEdit;
|
---|
[1715] | 150 | property SuggestionList:TListbox read FSuggestionList write FSuggestionList;
|
---|
[1693] | 151 |
|
---|
| 152 | end;
|
---|
| 153 |
|
---|
| 154 | procedure Register;
|
---|
| 155 |
|
---|
| 156 | Const
|
---|
| 157 | CompletionMessage = 'Spell Check Complete.';
|
---|
| 158 | CaptionForNewWord = 'New Word Suggestion';
|
---|
| 159 | ConfirmAbort = 'Really abort?';
|
---|
[1715] | 160 | ConfirmComplete = 'If you accept last change than SpellCheck is complete.'
|
---|
| 161 | + #13 + ' To review last change click on "Cancel".';
|
---|
[1693] | 162 | PromptForNewWord = 'Specify the replacement for current mis-spelt word:';
|
---|
| 163 | DLLNotLoaded = 'Failed to load SpellCheck Engine DLL.';
|
---|
| 164 | MisSpeltReplacement = 'The new word specified by you "%s" looks mis-spelt!'
|
---|
| 165 | +' Would you want to still use it? Click NO button '
|
---|
| 166 | +'to specify better replacement word.';
|
---|
[1715] | 167 |
|
---|
[1693] | 168 | var
|
---|
| 169 | OldRichEditWndProc: {integer}pointer;
|
---|
| 170 | CurrentMe: TskaHunSpellChecker;
|
---|
| 171 | implementation
|
---|
[1718] | 172 | uses messages, Dialogs, RichEdit, SHFolder, uHunSpellLib, Registry;
|
---|
[1693] | 173 |
|
---|
| 174 | procedure Register;
|
---|
| 175 | begin
|
---|
| 176 | RegisterComponentsProc('SkA Utility', [TskaHunSpellChecker]);
|
---|
| 177 | end;
|
---|
| 178 |
|
---|
| 179 | { TskaHunSpellChecker }
|
---|
| 180 |
|
---|
| 181 | function TskaHunSpellChecker.AbortSpellCheck(Verbose: Boolean = True): Boolean;
|
---|
| 182 | begin
|
---|
[1712] | 183 | if FStatus <> ssChecking then
|
---|
| 184 | begin
|
---|
| 185 | FStatus := ssCancelled;
|
---|
| 186 | Close;
|
---|
| 187 | exit;
|
---|
| 188 | end;
|
---|
| 189 |
|
---|
[1693] | 190 | Result := (not isModified) or
|
---|
| 191 | (not Verbose) or (MessageDlg(ConfirmAbort, mtConfirmation,
|
---|
| 192 | [mbYes, mbNo],0, mbNo) = 6);
|
---|
| 193 |
|
---|
[1718] | 194 | if Result then
|
---|
[1715] | 195 | begin
|
---|
[1718] | 196 | if FUndoList.Count > 0 then
|
---|
[1715] | 197 | SourceTextControl.Text := FUndoList[0];
|
---|
[1718] | 198 | FUndoList.Clear;
|
---|
| 199 | FUndoList.Add(SourceTextControl.Text);
|
---|
[1715] | 200 | FIgnore.Clear;
|
---|
| 201 | FStatus := ssCancelled;
|
---|
| 202 | SourceTextControl.Invalidate;
|
---|
| 203 | if Assigned(OnAbort) then
|
---|
| 204 | OnAbort(Self);
|
---|
[1718] | 205 | end;
|
---|
[1693] | 206 | end;
|
---|
| 207 |
|
---|
[1715] | 208 | function TskaHunSpellChecker.AddCustomWord(aWord: String;
|
---|
| 209 | isInternal: Boolean = False): Boolean;
|
---|
[1693] | 210 | begin
|
---|
| 211 | Result := False;
|
---|
[1715] | 212 | if (not active) or (trim(aWord) = '') or (SpellCheckState <> ssChecking)
|
---|
| 213 | or (not assigned(SourceTextControl)) or (not assigned(SuggestionList)) then
|
---|
| 214 | begin
|
---|
| 215 | Result := False;
|
---|
| 216 | exit;
|
---|
| 217 | end;
|
---|
[1693] | 218 | uHunSpellLib.hunspell_put_word(FpointerHunLib, PAnsiChar(AnsiString(aWord)));
|
---|
| 219 | Result := True;
|
---|
| 220 | end;
|
---|
| 221 |
|
---|
| 222 | procedure TskaHunSpellChecker.ChangeAll;
|
---|
| 223 | begin
|
---|
[1715] | 224 | if (SpellCheckState <> ssChecking) or (not assigned(SourceTextControl))
|
---|
| 225 | or (not assigned(SuggestionList)) then
|
---|
[1693] | 226 | exit;
|
---|
| 227 | SaveForUndo;
|
---|
| 228 | SourceTextControl.Text := StringReplace(SourceTextControl.Text,
|
---|
| 229 | CurrentWord, SuggestionList.Items[SuggestionList.ItemIndex],
|
---|
| 230 | [rfReplaceAll,rfIgnoreCase]);
|
---|
| 231 | WaitForUser := False;
|
---|
| 232 | FModified := True;
|
---|
| 233 | SourceTextControl.Invalidate;
|
---|
| 234 |
|
---|
| 235 | end;
|
---|
| 236 |
|
---|
| 237 | function TskaHunSpellChecker.AddCustomWord: Boolean;
|
---|
| 238 | begin
|
---|
| 239 | Result := AddCustomWord(CurrentWord, False);
|
---|
| 240 | FCustdict.Add(CurrentWord);
|
---|
| 241 | WaitForUser := False;
|
---|
| 242 | AbortSpellCheck(False);
|
---|
| 243 | Initialize;
|
---|
| 244 | CheckSpelling;
|
---|
| 245 | ShowMisSpelledWord;
|
---|
| 246 | end;
|
---|
| 247 |
|
---|
[1715] | 248 | procedure TskaHunSpellChecker.ReOpen;
|
---|
| 249 | begin
|
---|
| 250 | Close;
|
---|
| 251 | Open;
|
---|
| 252 | end;
|
---|
| 253 |
|
---|
[1693] | 254 | procedure TskaHunSpellChecker.ReplaceCurrentWordWith(const aNewWord: String);
|
---|
| 255 | var
|
---|
| 256 | full: String;
|
---|
| 257 | prefix: string;
|
---|
| 258 | suffix: string;
|
---|
| 259 | begin
|
---|
| 260 | full := SourceTextControl.Lines[CurrentLine];
|
---|
[1715] | 261 | {remember there is one extra space at the start of the line prefixed while
|
---|
| 262 | populating this variable}
|
---|
| 263 | prefix := copy(CurrentText, 2, WordPos-2);
|
---|
[1693] | 264 | Suffix := copy(CurrentText, WordPos+WordLength,
|
---|
| 265 | length(CurrentText));
|
---|
| 266 | SaveForUndo;
|
---|
[1715] | 267 | FModified := True;
|
---|
[1693] | 268 | SourceTextControl.Lines[CurrentLine] :=prefix + aNewWord + suffix;
|
---|
| 269 | WaitForUser := False;
|
---|
| 270 | FStatus := ssChecking;
|
---|
| 271 | FModified := True;
|
---|
| 272 | SourceTextControl.Invalidate;
|
---|
| 273 | end;
|
---|
| 274 |
|
---|
| 275 | function TskaHunSpellChecker.ReStart: Boolean;
|
---|
| 276 | begin
|
---|
| 277 | Close;
|
---|
| 278 | Result := Open;
|
---|
| 279 | Initialize;
|
---|
| 280 | WaitForUser := False;
|
---|
[1715] | 281 | if FStatus <> ssChecking then
|
---|
| 282 | begin
|
---|
| 283 | FStatus := ssChecking;
|
---|
| 284 | InformStatusChange;
|
---|
| 285 | end;
|
---|
[1693] | 286 | SourceTextControl.Invalidate;
|
---|
| 287 | Result := not WaitForUser;
|
---|
| 288 | end;
|
---|
| 289 |
|
---|
| 290 | procedure TskaHunSpellChecker.Change;
|
---|
| 291 |
|
---|
| 292 | begin
|
---|
[1715] | 293 | if (SpellCheckState <> ssChecking) or (not assigned(SourceTextControl))
|
---|
| 294 | or (not assigned(SuggestionList)) then
|
---|
[1693] | 295 | exit;
|
---|
| 296 | ReplaceCurrentWordWith(SuggestionList.Items[SuggestionList.ItemIndex]);
|
---|
| 297 | end;
|
---|
| 298 |
|
---|
| 299 | procedure TskaHunSpellChecker.CheckSpelling;
|
---|
| 300 | begin
|
---|
[1715] | 301 | if (SpellCheckState = ssChecking) or (not assigned(SourceTextControl))
|
---|
| 302 | or (trim(SourceTextControl.Text)= '') or (not assigned(SuggestionList)) then
|
---|
[1693] | 303 | exit;
|
---|
| 304 |
|
---|
| 305 | Initialize;
|
---|
| 306 | FUndoList.Clear;
|
---|
[1715] | 307 | FUndoList.Add(SourceTextControl.Text);
|
---|
| 308 | FIgnore.Clear;
|
---|
[1693] | 309 | WaitForUser := False;
|
---|
| 310 | FStatus := ssChecking;
|
---|
[1715] | 311 | if Assigned(OnStart) then
|
---|
| 312 | OnStart(Self);
|
---|
[1693] | 313 | SourceTextControl.Invalidate;
|
---|
| 314 | end;
|
---|
| 315 |
|
---|
| 316 | procedure TskaHunSpellChecker.Close;
|
---|
| 317 | begin
|
---|
| 318 | if not Active then Exit;
|
---|
[1715] | 319 | uHunSpellLib.hunspell_uninitialize(FpointerHunLib);
|
---|
[1693] | 320 | FpointerHunLib := nil;
|
---|
[1715] | 321 | FStatus := ssInActive;
|
---|
| 322 | InformStatusChange;
|
---|
[1693] | 323 | end;
|
---|
| 324 |
|
---|
| 325 |
|
---|
| 326 | procedure TskaHunSpellChecker.CorrectWithMyWord;
|
---|
| 327 | var
|
---|
| 328 | NewWord: String;
|
---|
| 329 | GotIt: Boolean;
|
---|
| 330 | begin
|
---|
[1715] | 331 | if (SpellCheckState <> ssChecking) or (not assigned(SourceTextControl))
|
---|
| 332 | or (not assigned(SuggestionList)) then
|
---|
[1693] | 333 | exit;
|
---|
| 334 |
|
---|
| 335 | if SuggestionList.Count > 0 then
|
---|
| 336 | NewWord := SuggestionList.Items[0]
|
---|
| 337 | else
|
---|
| 338 | NewWord := CurrentWord;
|
---|
| 339 |
|
---|
| 340 | GotIt := False;
|
---|
| 341 | while not GotIt do
|
---|
| 342 | begin
|
---|
| 343 | if not InputQuery(CaptionForNewWord, PromptForNewWord, NewWord) then
|
---|
| 344 | exit;
|
---|
| 345 |
|
---|
| 346 | GotIt := (not IsMisspelled(NewWord))
|
---|
| 347 | or (MessageDlg(Format(MisSpeltReplacement,[NewWord]),
|
---|
| 348 | mtWarning, [mbYes, mbNo],0, mbNo) =6) ;
|
---|
| 349 | end;
|
---|
| 350 |
|
---|
| 351 | if IsMisspelled(NewWord) then
|
---|
| 352 | AddCustomWord(NewWord, True);
|
---|
| 353 |
|
---|
| 354 | ReplaceCurrentWordWith(NewWord);
|
---|
| 355 | end;
|
---|
| 356 |
|
---|
| 357 | constructor TskaHunSpellChecker.Create(AOwner: TComponent);
|
---|
| 358 | begin
|
---|
| 359 | inherited;
|
---|
| 360 | ColorForMisspelled := clRed;
|
---|
| 361 |
|
---|
| 362 | CurrentMe := Self;
|
---|
| 363 | FIgnore := TStringList.Create;
|
---|
| 364 | FCustDict := TStringList.Create;
|
---|
| 365 |
|
---|
[1715] | 366 | if (trim(CustDictionaryFile)<>'') and (FileExists(CustDictionaryFile)) then
|
---|
[1693] | 367 | try
|
---|
| 368 | FCustDict.LoadFromFile(CustDictionaryFile);
|
---|
| 369 | except
|
---|
| 370 | end;
|
---|
| 371 |
|
---|
| 372 | FUndoList := TStringList.Create;
|
---|
| 373 |
|
---|
[1720] | 374 | FOptionsKey := '\software\'
|
---|
| 375 | + ChangeFileExt(ExtractFileName(Application.ExeName),'')
|
---|
| 376 | + '\skaHunSpellCheckOptions';
|
---|
[1718] | 377 | if csDesigning in componentState then
|
---|
| 378 | begin
|
---|
| 379 | IgnoreAllCaps := True;
|
---|
| 380 | IgnoreWordWithDigits := True;
|
---|
| 381 | end
|
---|
| 382 | else
|
---|
| 383 | GetOptions;
|
---|
| 384 |
|
---|
[1715] | 385 | FStatus := ssInActive;
|
---|
[1693] | 386 | WaitForUser := False;
|
---|
| 387 | WordPos := 0;
|
---|
| 388 | end;
|
---|
| 389 |
|
---|
| 390 | constructor TskaHunSpellChecker.Create(AOwner: TComponent;
|
---|
| 391 | SourceTextRichEdit: TRichedit; SuggestList: TListbox);
|
---|
| 392 | begin
|
---|
| 393 | create(AOwner);
|
---|
| 394 | SourceTextControl := SourceTextRichEdit;
|
---|
| 395 | SuggestionList := SuggestList;
|
---|
| 396 | end;
|
---|
| 397 |
|
---|
| 398 | function TskaHunSpellChecker.CurrentWordDetail(WithPosition: Boolean): String;
|
---|
| 399 | begin
|
---|
| 400 | Result := '$$' + CurrentWord + '$$';
|
---|
| 401 | if WithPosition then
|
---|
[1718] | 402 | Result :='$$' + IntToStr(CurrentLine) + '$$' + IntToStr(FoundAt+1) + Result;
|
---|
[1693] | 403 | end;
|
---|
| 404 |
|
---|
| 405 | destructor TskaHunSpellChecker.Destroy;
|
---|
| 406 | begin
|
---|
| 407 | Close;
|
---|
| 408 | FIgnore.clear;
|
---|
| 409 | FreeAndNil(FIgnore);
|
---|
| 410 | FreeAndNil(FUndoList);
|
---|
| 411 | if not (csDesigning in ComponentState) then
|
---|
| 412 | try
|
---|
| 413 | if FCustDict.Count > 0 then
|
---|
| 414 | try
|
---|
| 415 | FCustDict.SaveToFile(CustDictionaryFile);
|
---|
| 416 | except
|
---|
| 417 | end;
|
---|
[1718] | 418 | SetOptions;
|
---|
[1693] | 419 | finally
|
---|
| 420 | FCustDict.Free;
|
---|
| 421 | end;
|
---|
| 422 | inherited;
|
---|
| 423 | end;
|
---|
| 424 |
|
---|
| 425 | function TskaHunSpellChecker.GetAboutThis: String;
|
---|
| 426 | begin
|
---|
| 427 | Result := AboutThis;
|
---|
| 428 | end;
|
---|
| 429 |
|
---|
| 430 | function TskaHunSpellChecker.GetActive: Boolean;
|
---|
| 431 | begin
|
---|
| 432 | Result := (FpointerHunLib <> nil);
|
---|
| 433 | end;
|
---|
| 434 |
|
---|
[1718] | 435 | procedure TskaHunSpellChecker.GetOptions;
|
---|
| 436 | var
|
---|
| 437 | reg:TRegistry;
|
---|
| 438 | begin
|
---|
| 439 | reg:=TRegistry.Create;
|
---|
| 440 | try
|
---|
| 441 | reg.RootKey := HKEY_CURRENT_USER;
|
---|
| 442 |
|
---|
| 443 | //first get the dicationary file name
|
---|
[1720] | 444 | Reg.OpenKey(FOptionsKey,True);
|
---|
[1718] | 445 | if reg.ValueExists('DicFileName') then
|
---|
| 446 | DictionaryFileName:=Reg.readString('DicFileName')
|
---|
| 447 | else
|
---|
| 448 | Reg.WriteString('DicFileName',DictionaryFileName);
|
---|
| 449 |
|
---|
| 450 | //IgnoreAllCaps ?
|
---|
| 451 | if reg.ValueExists('IgnoreAllCaps') then
|
---|
| 452 | IgnoreAllCaps:=Reg.readBool('IgnoreAllCaps')
|
---|
| 453 | else
|
---|
| 454 | Reg.WriteBool('IgnoreAllCaps',IgnoreAllCaps);
|
---|
| 455 |
|
---|
| 456 |
|
---|
| 457 | //IgnoreWordsWithDigits ?
|
---|
| 458 | if reg.ValueExists('IgnoreWordWithDigits') then
|
---|
| 459 | IgnoreWordWithDigits:=Reg.readBool('IgnoreWordWithDigits')
|
---|
| 460 | else
|
---|
| 461 | Reg.WriteBool('IgnoreWordWithDigits',IgnoreWordWithDigits);
|
---|
| 462 |
|
---|
| 463 | finally
|
---|
| 464 | Reg.Free;
|
---|
| 465 | end;
|
---|
| 466 |
|
---|
| 467 | end;
|
---|
| 468 |
|
---|
[1693] | 469 | function TskaHunSpellChecker.GetStatus: TSpellState;
|
---|
| 470 | begin
|
---|
| 471 | Result := FStatus;
|
---|
| 472 | end;
|
---|
| 473 |
|
---|
| 474 | procedure TskaHunSpellChecker.GetSuggestions(const aMisSpeltWord: string;
|
---|
| 475 | const SuggestionList: TStrings);
|
---|
| 476 | var
|
---|
| 477 | i: Integer;
|
---|
| 478 | pMisSpelt: PAnsiChar;
|
---|
| 479 | suggestions: PPAnsiChar;
|
---|
| 480 | Results: PPAnsiChar;
|
---|
| 481 | Count: Integer;
|
---|
| 482 | begin
|
---|
| 483 | if (not Active) or (not Assigned(SuggestionList)) then
|
---|
| 484 | exit;
|
---|
| 485 |
|
---|
| 486 | pMisSpelt := PAnsiChar(AnsiString(aMisSpeltWord));
|
---|
| 487 |
|
---|
| 488 | if not uHunSpellLib.hunspell_spell(FpointerHunLib, pMisSpelt) then
|
---|
| 489 | uHunSpellLib.hunspell_suggest_auto(FpointerHunLib, pMisSpelt, suggestions);
|
---|
| 490 | begin
|
---|
[1715] | 491 | Count :=uHunSpellLib.hunspell_suggest(FpointerHunLib,pMisSpelt,suggestions);
|
---|
[1693] | 492 | Results := suggestions;
|
---|
| 493 | for i := 1 to Count do
|
---|
| 494 | begin
|
---|
| 495 | SuggestionList.Add(Results^);
|
---|
| 496 | Inc(Integer(Results), SizeOf(Pointer));
|
---|
| 497 | end;
|
---|
| 498 | uHunSpellLib.hunspell_suggest_free(FpointerHunLib, suggestions, Count);
|
---|
| 499 | end;
|
---|
| 500 | end;
|
---|
| 501 |
|
---|
| 502 | function TskaHunSpellChecker.ShowMisSpelledWord: boolean;
|
---|
| 503 | var
|
---|
| 504 | I , l :integer;
|
---|
| 505 | CharPosion:integer;
|
---|
| 506 | FirstVisibleLine, LastVisibleLine:integer;
|
---|
| 507 |
|
---|
| 508 | hndl: hwnd;
|
---|
| 509 | dcForHndl: THandle;
|
---|
| 510 | visrect:Trect;
|
---|
| 511 | vispoint:TPoint;
|
---|
| 512 | procedure ShowMisSpelletWord;
|
---|
| 513 | begin
|
---|
| 514 | if Assigned(FHighlightEdit) then
|
---|
| 515 | begin
|
---|
| 516 | FHighlightEdit.Font.Color := ColorForMisspelled;
|
---|
| 517 | FHighlightEdit.Text := CurrentWord;
|
---|
| 518 | FHighlightEdit.Show;
|
---|
| 519 | end ;
|
---|
| 520 |
|
---|
| 521 | if ((PosOfFirstCharInCurrentLine + FoundAt) < 1) then
|
---|
| 522 | exit;
|
---|
| 523 |
|
---|
[1715] | 524 | SendMessage (SourceTextControl.Handle, EM_POSFROMCHAR, integer(@VisPoint),
|
---|
| 525 | PosOfFirstCharInCurrentLine + FoundAt-1);
|
---|
[1693] | 526 | SetTextColor(dcForHndl, ColorForMisspelled);
|
---|
[1715] | 527 | TextOut(dcForHndl, VisPoint.x, VisPoint.y, pchar(CurrentWord), WordLength);
|
---|
[1693] | 528 | end;
|
---|
[1718] | 529 |
|
---|
| 530 | function WordIsIgnorable: Boolean;
|
---|
| 531 | var
|
---|
| 532 | i: Integer;
|
---|
| 533 | begin
|
---|
[1720] | 534 | Result := False;
|
---|
[1718] | 535 | if IgnoreAllCaps then
|
---|
| 536 | begin
|
---|
| 537 | Result := True;
|
---|
| 538 | for i := 1 to WordLength do
|
---|
| 539 | begin
|
---|
| 540 | Result := Result and (ord(CurrentWord[i]) in [65..90]);
|
---|
| 541 | end;
|
---|
| 542 | if Result then
|
---|
| 543 | exit;
|
---|
| 544 | end;
|
---|
| 545 |
|
---|
| 546 |
|
---|
| 547 |
|
---|
| 548 | if IgnoreWordWithDigits then
|
---|
| 549 | begin
|
---|
| 550 | Result := False;
|
---|
| 551 | for i := 1 to WordLength do
|
---|
| 552 | begin
|
---|
| 553 | Result := Result or (ord(CurrentWord[i]) in [48..57]);
|
---|
| 554 | if Result then
|
---|
| 555 | break;
|
---|
| 556 | end;
|
---|
| 557 | end;
|
---|
| 558 | end;
|
---|
[1693] | 559 | begin
|
---|
| 560 | Result := False;
|
---|
| 561 | if (SpellCheckState <> ssChecking) or (not assigned(SourceTextControl))
|
---|
| 562 | or (not assigned(SuggestionList)) then
|
---|
| 563 | exit;
|
---|
| 564 |
|
---|
| 565 | hndl:=SourceTextControl.Handle;
|
---|
| 566 |
|
---|
| 567 | result:= SendMessage (hndl, EM_GETRECT, 0, integer(@visrect))=0;
|
---|
| 568 |
|
---|
| 569 | dcForHndl := getdc(hndl);
|
---|
| 570 |
|
---|
| 571 | if result then
|
---|
| 572 | begin
|
---|
| 573 | // VisPoint := visrect.BottomRight;
|
---|
| 574 | vispoint.Y := visrect.Bottom;
|
---|
| 575 | vispoint.X := visrect.Right;
|
---|
[1715] | 576 | CharPosion := SendMessage (hndl, EM_CHARFROMPOS, 0, integer(@VisPoint));
|
---|
| 577 | LASTVISIBLELINE := SendMessage (hndl, EM_LINEFROMCHAR, CharPosion, 0);
|
---|
[1693] | 578 | FIRSTVISIBLELINE := SendMessage (hndl, EM_GETFIRSTVISIBLELINE, 0, 0);
|
---|
| 579 |
|
---|
| 580 | SetBkMode (dcForHndl, TRANSPARENT);
|
---|
| 581 | SelectObject(dcForHndl, SourceTextControl.font.Handle);
|
---|
| 582 | i := 0;
|
---|
| 583 |
|
---|
| 584 | if WaitForUser then
|
---|
| 585 | begin
|
---|
| 586 | ShowMisSpelletWord;
|
---|
| 587 | exit;
|
---|
| 588 | end;
|
---|
| 589 |
|
---|
| 590 | For l := 0 to SourceTextControl.Lines.Count -1 do
|
---|
| 591 | begin
|
---|
| 592 | {$R-}
|
---|
| 593 | CurrentLine := l;
|
---|
| 594 | if trim(SourceTextControl.Lines[CurrentLine]) = '' then
|
---|
| 595 | continue;
|
---|
| 596 |
|
---|
| 597 | CurrentText := ' ' + SourceTextControl.Lines[CurrentLine];
|
---|
[1715] | 598 | PosOfFirstCharInCurrentLine := SendMessage (SourceTextControl.Handle,
|
---|
| 599 | EM_LINEINDEX, CurrentLine, 0);
|
---|
[1693] | 600 | i := 0;
|
---|
| 601 |
|
---|
| 602 | While i <= LENgth(CurrentText) do
|
---|
| 603 | begin
|
---|
| 604 | FoundAt := i -1;
|
---|
| 605 | if Assigned(FHighlightEdit) then
|
---|
| 606 | FHighlightEdit.Hide;
|
---|
| 607 |
|
---|
| 608 |
|
---|
| 609 | //SuggestionList.Clear;
|
---|
| 610 | {Any character except these will count as a word delimiter}
|
---|
| 611 | While CurrentText[i] in ['A'..'Z','a'..'z','0'..'9'] do inc(i);
|
---|
| 612 |
|
---|
| 613 | WordLength := i- FoundAt -1;
|
---|
| 614 | WordPos := i-WordLength;
|
---|
| 615 | CurrentWord := copy(CurrentText, WordPos, WordLength);
|
---|
[1718] | 616 | // if WordIsCorrect then
|
---|
| 617 | if (((FIgnore.IndexOf(CurrentWordDetail(True))< 0) //SingelIgnore
|
---|
[1693] | 618 | and (FIgnore.IndexOf(CurrentWordDetail(False))< 0) //IgnoreAll
|
---|
[1718] | 619 | and (IsMisspelled(CurrentWord))))
|
---|
| 620 | and (not WordIsIgnorable) then
|
---|
| 621 |
|
---|
[1693] | 622 | begin
|
---|
| 623 | GetSuggestions(CurrentWord, SuggestionList.Items);
|
---|
| 624 | if SuggestionList.Count > 0 then
|
---|
| 625 | SuggestionList.ItemIndex := 0;
|
---|
| 626 | ShowMisSpelletWord;
|
---|
| 627 | if CurrentLine > LastVisibleLine then
|
---|
[1715] | 628 | SendMessage(SourceTextControl.Handle, EM_LINESCROLL, 0,
|
---|
| 629 | (CurrentLine - lastvisibleLine)+5);
|
---|
[1693] | 630 | WaitForUser := True;
|
---|
| 631 | exit;
|
---|
| 632 | End
|
---|
| 633 | else
|
---|
| 634 | SuggestionList.Clear;
|
---|
| 635 | inc(i);
|
---|
| 636 | end;
|
---|
| 637 | end;
|
---|
[1715] | 638 | if (CurrentLine >= SourceTextControl.Lines.Count-1)
|
---|
| 639 | and (i >= length(CurrentText) +1) then
|
---|
[1693] | 640 | begin
|
---|
[1715] | 641 | if (not FModified)
|
---|
| 642 | or (MessageDlg(ConfirmComplete,mtConfirmation,[mbOK, mbCancel],0)=mrOk)
|
---|
| 643 | then
|
---|
| 644 | begin
|
---|
| 645 | FStatus := ssCompleted;
|
---|
| 646 | InformStatusChange;
|
---|
| 647 | end
|
---|
| 648 | else
|
---|
| 649 | Undo;
|
---|
[1693] | 650 | end;
|
---|
| 651 | {$R+}
|
---|
| 652 | end;
|
---|
| 653 | ReleaseDC(SourceTextControl.Handle, dcForHndl);
|
---|
| 654 |
|
---|
| 655 | End;
|
---|
| 656 |
|
---|
| 657 | function TskaHunSpellChecker.Undo: Boolean;
|
---|
| 658 | var
|
---|
| 659 | tmpStr: String;
|
---|
| 660 | tmpCount: Integer;
|
---|
[1715] | 661 | SrcText: String;
|
---|
[1693] | 662 | begin
|
---|
[1715] | 663 | if FUndoList.Count > 1 then
|
---|
[1693] | 664 | try
|
---|
| 665 | tmpStr := FUndoList.Strings[FUndoList.Count-1];
|
---|
| 666 | if (AnsiPos('$$',tmpStr)=1) and (copy(tmpStr,length(tmpStr)-1,2) = '$$')then
|
---|
[1715] | 667 | //if last action was ignoring word then just remove it from ignore list
|
---|
[1693] | 668 | begin
|
---|
| 669 | tmpCount := strtoInt(StringReplace(tmpStr,'$$','',[rfReplaceAll]));
|
---|
| 670 | while FIgnore.Count > tmpCount do
|
---|
| 671 | FIgnore.Delete(FIgnore.Count -1);
|
---|
| 672 | end
|
---|
| 673 | else
|
---|
| 674 | SourceTextControl.Text := tmpStr;
|
---|
| 675 |
|
---|
| 676 | Result := True;
|
---|
| 677 | FUndoList.Delete(FUndoList.Count-1);
|
---|
| 678 | ReStart;
|
---|
| 679 | except
|
---|
| 680 | Result := False;
|
---|
| 681 | end;
|
---|
| 682 | end;
|
---|
| 683 |
|
---|
| 684 | procedure TskaHunSpellChecker.IgnoreAll;
|
---|
| 685 | begin
|
---|
[1715] | 686 | if (SpellCheckState <> ssChecking) or (not assigned(SourceTextControl))
|
---|
| 687 | or (not assigned(SuggestionList)) then
|
---|
[1693] | 688 | exit;
|
---|
[1715] | 689 |
|
---|
[1693] | 690 | SaveForUndo(True);
|
---|
| 691 | FIgnore.Add(CurrentWordDetail(False)) ;
|
---|
| 692 | WaitForUser := False;
|
---|
| 693 | SourceTextControl.Invalidate;
|
---|
| 694 | end;
|
---|
| 695 |
|
---|
| 696 | procedure TskaHunSpellChecker.IgnoreOnce;
|
---|
| 697 | begin
|
---|
[1715] | 698 | if (SpellCheckState <> ssChecking) or (not assigned(SourceTextControl))
|
---|
| 699 | or (not assigned(SuggestionList)) then
|
---|
[1693] | 700 | exit;
|
---|
[1715] | 701 |
|
---|
[1693] | 702 | if trim(CurrentWord) <> '' then
|
---|
| 703 | begin
|
---|
| 704 | SaveForUndo(True);
|
---|
| 705 | FIgnore.Add(CurrentWordDetail(True)) ;
|
---|
| 706 | end;
|
---|
| 707 | WaitForUser := False;
|
---|
| 708 | SourceTextControl.Invalidate;
|
---|
| 709 | end;
|
---|
| 710 |
|
---|
[1715] | 711 | procedure TskaHunSpellChecker.InformStatusChange;
|
---|
| 712 | begin
|
---|
| 713 | if Assigned(OnStateChange) then
|
---|
| 714 | OnStateChange(Self, FStatus);
|
---|
| 715 | end;
|
---|
| 716 |
|
---|
[1693] | 717 | procedure TskaHunSpellChecker.Initialize;
|
---|
| 718 | begin
|
---|
| 719 | CurrentWord := '';
|
---|
| 720 | WordLength := 0;
|
---|
| 721 | FoundAt := -1;
|
---|
| 722 | CurrentLine := 0;
|
---|
| 723 | WordPos := 0;
|
---|
| 724 | SuggestionList.Clear;
|
---|
| 725 | end;
|
---|
| 726 |
|
---|
| 727 | function TskaHunSpellChecker.IsMisspelled(const AWord: string): Boolean;
|
---|
| 728 | begin
|
---|
| 729 | if (not Active) then
|
---|
| 730 | Result := True
|
---|
| 731 | else
|
---|
[1715] | 732 | Result := not uHunSpellLib.hunspell_spell(FpointerHunLib,
|
---|
| 733 | PAnsiChar(AnsiString(AWord)));
|
---|
[1693] | 734 | end;
|
---|
| 735 |
|
---|
| 736 | procedure TskaHunSpellChecker.Loaded;
|
---|
| 737 | begin
|
---|
| 738 | inherited;
|
---|
| 739 | SetActive(FActiveOrLoaded);
|
---|
| 740 | end;
|
---|
| 741 |
|
---|
[1694] | 742 | procedure TskaHunSpellChecker.ManualChangeDone;
|
---|
| 743 | begin
|
---|
| 744 | if trim(FTxtBeforeManualEdit) = '' then
|
---|
| 745 | exit;
|
---|
| 746 | FUndoList.Add(FTxtBeforeManualEdit);
|
---|
| 747 | ReStart;
|
---|
| 748 | end;
|
---|
| 749 |
|
---|
| 750 | procedure TskaHunSpellChecker.ManualChangeStart;
|
---|
| 751 | begin
|
---|
| 752 | FTxtBeforeManualEdit := FSourceEdit.Text;
|
---|
| 753 | end;
|
---|
| 754 |
|
---|
[1693] | 755 | function TskaHunSpellChecker.Open: Boolean;
|
---|
| 756 | var
|
---|
| 757 | CurrentLine: integer;
|
---|
[1715] | 758 | function GetSpecialFolderPath(folder : integer) : string;
|
---|
| 759 | var
|
---|
| 760 | path: array [0..MAX_PATH] of char;
|
---|
| 761 | begin
|
---|
| 762 | if SUCCEEDED(SHGetFolderPath(0,folder,0,0,@path[0])) then
|
---|
| 763 | Result := path
|
---|
| 764 | else
|
---|
| 765 | Result := '';
|
---|
| 766 | end;
|
---|
[1693] | 767 | begin
|
---|
| 768 | Result := True;
|
---|
| 769 | if Active then Exit;
|
---|
| 770 | Result := False;
|
---|
| 771 | FpointerHunLib := Nil;
|
---|
| 772 | if not uHunSpellLib.LoadLibHunspell('') then
|
---|
| 773 | begin
|
---|
| 774 | MessageDlg(DLLNotLoaded, mtError, [mbOK],0);
|
---|
| 775 | Exit;
|
---|
| 776 | end;
|
---|
[1715] | 777 | FpointerHunLib := uHunSpellLib.hunspell_initialize(
|
---|
| 778 | PAnsiChar(AnsiString(FAffixFileName)),
|
---|
| 779 | PAnsiChar(AnsiString(FDictFileName)));
|
---|
[1693] | 780 | Result := Assigned(FpointerHunLib);
|
---|
| 781 |
|
---|
[1715] | 782 | if Result then
|
---|
| 783 | begin
|
---|
| 784 | FStatus := ssReady;
|
---|
| 785 | InformStatusChange;
|
---|
| 786 | end;
|
---|
| 787 | if trim(CustDictionaryFile) = '' then
|
---|
| 788 | CustDictionaryFile := IncludeTrailingPathDelimiter(
|
---|
| 789 | GetSpecialFolderPath(CSIDL_PERSONAL)) + 'CustomDictionary.txt';
|
---|
[1693] | 790 | if (Result) and (assigned(FCustDict)) then
|
---|
| 791 | for CurrentLine := 0 to FCustDict.Count - 1 do
|
---|
| 792 | AddCustomWord(FCustDict[CurrentLine], True);
|
---|
| 793 | end;
|
---|
| 794 |
|
---|
| 795 | procedure TskaHunSpellChecker.SaveForUndo(const Ignoring: Boolean = False);
|
---|
| 796 | begin
|
---|
| 797 | if Ignoring then
|
---|
| 798 | FUndoList.Add('$$'+ IntToStr(FIgnore.Count)+'$$')
|
---|
| 799 | else
|
---|
| 800 | FUndoList.Add(SourceTextControl.Text);
|
---|
| 801 | end;
|
---|
| 802 |
|
---|
| 803 | procedure TskaHunSpellChecker.SetActive(const Value: Boolean);
|
---|
| 804 | begin
|
---|
| 805 | if (csDesigning in ComponentState) or (csLoading in ComponentState) then
|
---|
| 806 | FActiveOrLoaded := Value
|
---|
| 807 | else
|
---|
| 808 | if Value then
|
---|
| 809 | FActiveOrLoaded := Open
|
---|
| 810 | else
|
---|
| 811 | Close;
|
---|
| 812 | end;
|
---|
| 813 |
|
---|
| 814 | procedure TskaHunSpellChecker.SetAffixFileName(const Value: string);
|
---|
| 815 | begin
|
---|
| 816 | Close;
|
---|
| 817 | FAffixFileName := Value;
|
---|
[1715] | 818 | if (trim(DictionaryFileName) = '') and (trim(value)<>'') then
|
---|
| 819 | DictionaryFileName := ChangeFileExt(value, '.dic');
|
---|
[1693] | 820 | end;
|
---|
| 821 |
|
---|
| 822 | procedure TskaHunSpellChecker.SetCustomDict(const Value: String);
|
---|
| 823 | begin
|
---|
| 824 | FCustom := Value;
|
---|
[1715] | 825 | if (not (csDesigning in componentState))
|
---|
| 826 | and (FileExists(Value)) and assigned(FCustDict) then
|
---|
| 827 | begin
|
---|
| 828 | FCustDict.Clear;
|
---|
| 829 | FCustDict.LoadFromFile(Value);
|
---|
| 830 | end;
|
---|
[1693] | 831 | end;
|
---|
| 832 |
|
---|
| 833 | procedure TskaHunSpellChecker.SetDictFileName(const Value: string);
|
---|
| 834 | begin
|
---|
| 835 | Close;
|
---|
| 836 | FDictFileName := Value;
|
---|
[1715] | 837 | if (trim(AffixFileName) = '') and (trim(value)<>'') then
|
---|
| 838 | AffixFileName := ChangeFileExt(value, '.aff');
|
---|
[1693] | 839 | end;
|
---|
| 840 |
|
---|
| 841 | procedure TskaHunSpellChecker.SetHighLightEdit(const Value: TEdit);
|
---|
| 842 | begin
|
---|
| 843 | if FHighlightEdit = Value then
|
---|
| 844 | exit;
|
---|
| 845 |
|
---|
| 846 | FHighlightEdit := Value;
|
---|
| 847 |
|
---|
| 848 | if Active then
|
---|
| 849 | FHighlightEdit.Text := CurrentWord;
|
---|
| 850 |
|
---|
| 851 |
|
---|
| 852 | end;
|
---|
| 853 |
|
---|
[1718] | 854 | procedure TskaHunSpellChecker.SetIgnoreCaps(const Value: boolean);
|
---|
| 855 | begin
|
---|
| 856 | if (FIgnoreCaps = Value) then
|
---|
| 857 | exit;
|
---|
| 858 |
|
---|
| 859 | FIgnoreCaps := Value;
|
---|
| 860 | if SpellCheckState = ssChecking then
|
---|
| 861 | ReStart;
|
---|
| 862 | end;
|
---|
| 863 |
|
---|
| 864 | procedure TskaHunSpellChecker.SetIgnoreWordWdigits(const Value: boolean);
|
---|
| 865 | begin
|
---|
| 866 | if (FIgnoreWordWdigits = Value) then
|
---|
| 867 | exit;
|
---|
| 868 |
|
---|
| 869 | FIgnoreWordWdigits := Value;
|
---|
| 870 | if SpellCheckState = ssChecking then
|
---|
| 871 | ReStart;
|
---|
| 872 |
|
---|
| 873 | end;
|
---|
| 874 |
|
---|
| 875 | procedure TskaHunSpellChecker.SetOptions;
|
---|
| 876 | var
|
---|
| 877 | reg:TRegistry;
|
---|
| 878 | begin
|
---|
| 879 | reg:=TRegistry.Create;
|
---|
| 880 | try
|
---|
| 881 | reg.RootKey := HKEY_CURRENT_USER;
|
---|
| 882 |
|
---|
| 883 |
|
---|
[1720] | 884 | Reg.OpenKey(FOptionsKey,True);
|
---|
[1718] | 885 |
|
---|
| 886 | //first save the dicationary file name
|
---|
| 887 | Reg.WriteString('DicFileName',DictionaryFileName);
|
---|
| 888 |
|
---|
| 889 | //IgnoreAllCaps ?
|
---|
| 890 | Reg.WriteBool('IgnoreAllCaps',IgnoreAllCaps);
|
---|
| 891 |
|
---|
| 892 |
|
---|
| 893 | //IgnoreWordsWithDigits ?
|
---|
| 894 | Reg.WriteBool('IgnoreWordWithDigits',IgnoreWordWithDigits);
|
---|
| 895 |
|
---|
| 896 | finally
|
---|
| 897 | Reg.Free;
|
---|
| 898 | end;
|
---|
| 899 | end;
|
---|
| 900 |
|
---|
[1715] | 901 | Function RichEditWndProc(handle:HWnd;uMsg,wParam,lParam:longint):longint stdcall;
|
---|
[1693] | 902 | begin
|
---|
[1715] | 903 | Result := CallWindowProc(OldRichEditWndProc, handle, uMsg, wParam, lParam);
|
---|
| 904 | if (uMsg=WM_PAINT) and assigned(CurrentMe) then
|
---|
| 905 | CurrentMe.ShowMisSpelledWord;
|
---|
[1693] | 906 | End;
|
---|
| 907 |
|
---|
| 908 | procedure TskaHunSpellChecker.SetSourceEdit(const Value: TRichEdit);
|
---|
| 909 | begin
|
---|
| 910 | if FSourceEdit = Value then
|
---|
| 911 | exit;
|
---|
| 912 |
|
---|
| 913 | FSourceEdit := Value;
|
---|
| 914 |
|
---|
| 915 | if csDesigning in ComponentState then
|
---|
| 916 | exit;
|
---|
| 917 |
|
---|
| 918 | PREditorWndProc:=@RichEditWndProc;
|
---|
[1715] | 919 | //raise the limit of text which could be inserted into this Richedit
|
---|
| 920 | Value.perform(EM_EXLIMITTEXT, 0, 65535*32);
|
---|
| 921 | OldRichEditWndProc := pointer(SetWindowLong(Value.handle, GWL_WNDPROC,
|
---|
| 922 | longint(@RichEditWndProc)));
|
---|
[1693] | 923 | end;
|
---|
| 924 |
|
---|
| 925 | end.
|
---|