diff --git a/Keyboard and Spell checker/Classes/clsFileVersion.pas b/Keyboard and Spell checker/Classes/clsFileVersion.pas index f9487de..5b34d16 100644 --- a/Keyboard and Spell checker/Classes/clsFileVersion.pas +++ b/Keyboard and Spell checker/Classes/clsFileVersion.pas @@ -76,6 +76,9 @@ Implementation +Uses + uFileFolderHandling; + {===============================================================================} Constructor TFileVersion.Create(Const AFileName: String = ''); @@ -83,8 +86,11 @@ Inherited Create; If AFileName = '' Then - FFileName := ExtractFilePath(Application.ExeName) + - ExtractFileName(Application.ExeName) + {$IFNDEF SpellCheckerDll} + FFileName := Application.ExeName + {$ELSE} + FFileName := GetDllFullPath + {$ENDIF} Else FFileName := AFileName; @@ -183,3 +189,4 @@ {===============================================================================} End. + diff --git a/Keyboard and Spell checker/SpellChecker/AvroSpell.dpr b/Keyboard and Spell checker/SpellChecker/AvroSpell.dpr new file mode 100644 index 0000000..d64c2b9 --- /dev/null +++ b/Keyboard and Spell checker/SpellChecker/AvroSpell.dpr @@ -0,0 +1,411 @@ +{ + ============================================================================= + ***************************************************************************** + The contents of this file are subject to the Mozilla Public License + Version 1.1 (the "License"); you may not use this file except in + compliance with the License. You may obtain a copy of the License at + http://www.mozilla.org/MPL/ + + Software distributed under the License is distributed on an "AS IS" + basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + License for the specific language governing rights and limitations + under the License. + + The Original Code is Avro Keyboard 5. + + The Initial Developer of the Original Code is + Mehdi Hasan Khan (mhasan@omicronlab.com). + + Copyright (C) OmicronLab (http://www.omicronlab.com). All Rights Reserved. + + + Contributor(s): ______________________________________. + + ***************************************************************************** + ============================================================================= +} + +Library AvroSpell; + + +Uses + SysUtils, + Classes, + Windows, + widestrings, + widestrutils, + StrUtils, + Controls, + Forms, + BanglaChars In '..\Units\BanglaChars.pas', + clsPhoneticRegExBuilder_Spell In 'clsPhoneticRegExBuilder_Spell.pas', + clsReversePhonetic In 'clsReversePhonetic.pas', + clsSpellPhoneticSuggestionBuilder In 'clsSpellPhoneticSuggestionBuilder.pas', + Hashing In 'Hashing.pas', + HashTable In 'HashTable.pas', + Phonetic_RegExp_Constants_Spell In 'Phonetic_RegExp_Constants_Spell.pas', + uCustomDictionary In 'uCustomDictionary.pas', + ufrmSpellOptions In 'ufrmSpellOptions.pas' {frmSpellOptions}, + ufrmSpellPopUp In 'ufrmSpellPopUp.pas' {frmSpellPopUp}, + uRegExPhoneticSearch_Spell In 'uRegExPhoneticSearch_Spell.pas', + uSimilarSort_Spell In 'uSimilarSort_Spell.pas', + uSpellEditDistanceSearch In 'uSpellEditDistanceSearch.pas', + PCRE In '..\Units\PCRE.pas', + pcre_dll In '..\Units\pcre_dll.pas', + cDictionaries In '..\Units\cDictionaries.pas', + cUtils In '..\Units\cUtils.pas', + cTypes In '..\Units\cTypes.pas', + cArrays In '..\Units\cArrays.pas', + cStrings In '..\Units\cStrings.pas', + uFileFolderHandling In '..\Units\uFileFolderHandling.pas', + uDBase In '..\Units\uDBase.pas', + uRegistrySettings In 'uRegistrySettings.pas', + nativexml In '..\Units\nativexml.pas', + ufrmAbout In 'ufrmAbout.pas' {frmAbout}, + clsRegistry_XMLSetting In 'clsRegistry_XMLSetting.pas', + clsFileVersion In '..\Classes\clsFileVersion.pas', + uWindowHandlers In '..\Units\uWindowHandlers.pas'; + +{$R *.res} + + + +Var + Initialized : Boolean; + + + + {===============================================================================} + +Function UnicodeDeNormalize(Const W: WideString): WideString; +Begin + Result := W; + Result := widestrutils.WideReplaceStr(Result, b_B + b_Nukta, b_r); + Result := widestrutils.WideReplaceStr(Result, b_Dd + b_Nukta, b_Rr); + Result := widestrutils.WideReplaceStr(Result, b_Ddh + b_Nukta, b_Rrh); + Result := widestrutils.WideReplaceStr(Result, b_Z + b_Nukta, b_Y); +End; + +{===============================================================================} + +Function CanIgnoreByOption(W: WideString): Boolean; +Var + Spell_IgnoreNumbers, Spell_IgnoreAncient, Spell_IgnoreAssamese, Spell_IgnoreSingle: Boolean; + + theRegex : IRegex; + theMatch : IMatch; + theLocale : ansistring; + RegExOpt : TRegMatchOptions; + RegExCompileOptions : TRegCompileOptions; + + SearchStr : AnsiString; + AnsiW : AnsiString; +Begin + Result := False; + AnsiW := utf8encode(w); + + If IgnoreNumber = 'YES' Then + Spell_IgnoreNumbers := True + Else + Spell_IgnoreNumbers := False; + + If IgnoreAncient = 'YES' Then + Spell_IgnoreAncient := True + Else + Spell_IgnoreAncient := False; + + If IgnoreAssamese = 'YES' Then + Spell_IgnoreAssamese := True + Else + Spell_IgnoreAssamese := False; + + If IgnoreSingle = 'YES' Then + Spell_IgnoreSingle := True + Else + Spell_IgnoreSingle := False; + + + RegExOpt := []; + theLocale := 'C'; + RegExCompileOptions := DecodeRegCompileOptions({PCRE_CASELESS Or}PCRE_UTF8); + + If Spell_IgnoreSingle Then Begin + If Length(W) < 2 Then Begin + Result := True; + exit; + End; + End; + + If Spell_IgnoreNumbers Then Begin + SearchStr := utf8encode('^.*[' + b_0 + b_1 + b_2 + b_3 + b_4 + b_5 + b_6 + b_7 + b_8 + b_9 + '].*$'); + theRegex := Pcre.RegexCreate(SearchStr, RegExCompileOptions, theLocale); + theMatch := theRegex.Match(AnsiW, RegExOpt); + If theMatch.Success Then Begin + Result := True; + exit; + End; + End; + + If Spell_IgnoreAssamese Then Begin + SearchStr := utf8encode('^.*[' + AssamRa + AssamVa + '].*$'); + theRegex := Pcre.RegexCreate(SearchStr, RegExCompileOptions, theLocale); + theMatch := theRegex.Match(AnsiW, RegExOpt); + If theMatch.Success Then Begin + Result := True; + exit; + End; + End; + + If Spell_IgnoreAncient Then Begin + SearchStr := utf8encode('^.*[' + b_Vocalic_L + b_Vocalic_LL + b_Vocalic_RR + b_Vocalic_RR_Kar + b_Vocalic_L_Kar + b_Vocalic_LL_Kar + b_Avagraha + b_LengthMark + b_RupeeMark + b_CurrencyNumerator1 + b_CurrencyNumerator2 + b_CurrencyNumerator3 + b_CurrencyNumerator4 + b_CurrencyNumerator1LessThanDenominator + b_CurrencyDenominator16 + b_CurrencyEsshar + '].*$'); + theRegex := Pcre.RegexCreate(SearchStr, RegExCompileOptions, theLocale); + theMatch := theRegex.Match(AnsiW, RegExOpt); + If theMatch.Success Then Begin + Result := True; + exit; + End; + End; +End; + +{===============================================================================} + +Function SplitSuggestion(w: widestring): WideString; +Var + I, Len : Integer; + part1, part2 : widestring; +Begin + Result := ''; + Len := Length(w); + I := 0; + Repeat + i := i + 1; + part1 := LeftStr(w, i); + part2 := MidStr(w, i + 1, len); + + If (WordPresent(part1) = true) And (WordPresent(part2) = true) Then Begin + Result := part1 + ' ' + part2; + break; + End; + + + Until i > len; +End; + +{===============================================================================} +{===============================================================================} +{===============================================================================} +{===============================================================================} + +Procedure RegisterCallback(mCallback: TCallback); Stdcall; +Begin + Callback := mCallback; +End; + +{===============================================================================} + +Procedure InitSpell; Stdcall; +Begin + LoadWordDatabase; + LoadSettings; + InitSpellCustomDict; + PhoneticSug := TPhoneticSpellSuggestion.Create; + PhoneticResult := TWideStringList.Create; + FuzzyResult := TWideStringList.Create; + OtherResult := TWideStringList.Create; + DetermineZWNJ_ZWJ := ZWJ; + frmSpellPopUp := TfrmSpellPopUp.Create(Nil); + Initialized := True; +End; + +{===============================================================================} + +Function IsWordPresent(Wrd: PWideChar; Var SAction: Integer): Boolean; Stdcall; +Var + mWrd : WideString; +Begin + + If Not Initialized Then Begin + Result := False; + exit; + End; + + mWrd := UnicodeDeNormalize(Wrd); + + //SAction = 0 Default + //SAction = 1 Ignored word + //SAction = 2 Ignored by option + + If CanIgnoreByOption(mWrd) = True Then Begin + SAction := SA_IgnoredByOption; + Result := True; + exit; + End; + + If WordPresentInIgnoreDict(mWrd) Then Begin + SAction := SA_Ignore; + Result := True; + exit; + End; + + If WordPresent(mWrd) Or WordPresentInCustomDict(mWrd) Then Begin + SAction := SA_Default; + Result := True; + exit; + End; + + Result := False; +End; + +{===============================================================================} + +Function WordPresentInChangeAll(Wrd: PWideChar): Boolean; Stdcall; +Var + mWrd : WideString; +Begin + mWrd := UnicodeDeNormalize(Wrd); + Result := SpellChangeDict.HasKey(utf8encode(mWrd)); +End; + +{===============================================================================} + +Procedure GetCorrection(Wrd: PWideChar); Stdcall; +Var + mWrd : WideString; + SplittedWord : WideString; +Begin + + If Not Initialized Then Begin + exit; + End; + + mWrd := UnicodeDeNormalize(Wrd); + + //SAction = 3 Change All + If SpellChangeDict.HasKey(utf8encode(mWrd)) Then Begin + Callback(PWideChar(mWrd), PWideChar(utf8decode(SpellChangeDict.Item[utf8encode(mWrd)])), SA_ReplaceAll); + exit; + End; + + PhoneticResult.Clear; + FuzzyResult.Clear; + OtherResult.Clear; + + //Bisharga to colon + If RightStr(mWrd, 1) = b_bisharga Then Begin + If WordPresent(LeftStr(mWrd, Length(mWrd) - 1)) Then + OtherResult.Add(LeftStr(mWrd, Length(mWrd) - 1) + ':'); + End + Else Begin + //Phonetic errors + PhoneticSug.BuildSuggestion(mWrd, PhoneticResult); + //Suggestion from fuzzy search ("Substitution", "Insertion", "Deletion" errors) + SearchSuggestion(mWrd, FuzzyResult, 1); + End; + + //Splitted suggestion (Words Joined?) + If (PhoneticResult.Count + FuzzyResult.Count) <= 0 Then Begin + SplittedWord := SplitSuggestion(mWrd); + If SplittedWord <> '' Then + OtherResult.Add(SplittedWord); + End; + + //Rest Transposition and OCR errors for next version + { TODO : transposition and OCR errors} + + + frmSpellPopUp.Edit_NotFound.Text := mWrd; + frmSpellPopUp.Show; +End; + +{===============================================================================} + +Procedure SetWordPosInScreen(xPoint, yPoint: Integer); Stdcall; +Begin + MoveToOptimumPos(xPoint, yPoint); +End; + +{===============================================================================} + +Procedure HideSpeller; Stdcall; +Begin + frmSpellPopUp.Hide; +End; + +{===============================================================================} + +Procedure ShowOptions; Stdcall; +Begin + LoadSettings; + frmSpellOptions := TfrmSpellOptions.Create(Nil); + frmSpellOptions.Show; +End; + +{===============================================================================} + +Procedure ShowAbout; Stdcall; +Begin + frmAbout := TfrmAbout.Create(Nil); + frmAbout.Show; +End; + +{===============================================================================} + +Procedure ForgetChangeIgnore; Stdcall; +Begin + If Not Initialized Then exit; + + Try + SpellIgnoreDict.Clear; + SpellChangeDict.Clear; + Except + // + End; +End; + +{===============================================================================} + +Procedure UnloadAll; Stdcall; +Begin + Try + SaveSettings; + + SaveSpellCustomDict; + UnloadWordDatabase; + + FreeAndNil(PhoneticSug); + PhoneticResult.Clear; + FreeAndNil(PhoneticResult); + FuzzyResult.Clear; + FreeAndNil(FuzzyResult); + OtherResult.Clear; + FreeAndNil(OtherResult); + + frmSpellPopUp.Close; + Except + // + End; + Initialized := False; +End; + +{===============================================================================} +{===============================================================================} +{===============================================================================} +{===============================================================================} + + +Exports + InitSpell, + IsWordPresent, + RegisterCallback, + WordPresentInChangeAll, + GetCorrection, + SetWordPosInScreen, + HideSpeller, + ShowOptions, + ShowAbout, + ForgetChangeIgnore, + UnloadAll; +Begin + +End. + diff --git a/Keyboard and Spell checker/SpellChecker/AvroSpell.res b/Keyboard and Spell checker/SpellChecker/AvroSpell.res new file mode 100644 index 0000000..2859dab Binary files /dev/null and b/Keyboard and Spell checker/SpellChecker/AvroSpell.res differ diff --git a/Keyboard and Spell checker/SpellChecker/Avro_Spell_Checker.dpr b/Keyboard and Spell checker/SpellChecker/Avro_Spell_Checker.dpr index 1bda559..aa8b1e7 100644 --- a/Keyboard and Spell checker/SpellChecker/Avro_Spell_Checker.dpr +++ b/Keyboard and Spell checker/SpellChecker/Avro_Spell_Checker.dpr @@ -25,52 +25,31 @@ ============================================================================= } -program Avro_Spell_Checker; +Program Avro_Spell_Checker; uses Forms, clsMemoParser in 'clsMemoParser.pas', - clsPhoneticRegExBuilder_Spell in 'clsPhoneticRegExBuilder_Spell.pas', - clsReversePhonetic in 'clsReversePhonetic.pas', - clsSpellPhoneticSuggestionBuilder in 'clsSpellPhoneticSuggestionBuilder.pas', - Hashing in 'Hashing.pas', - HashTable in 'HashTable.pas', - Phonetic_RegExp_Constants_Spell in 'Phonetic_RegExp_Constants_Spell.pas', uClipboard in 'uClipboard.pas', - uCustomDictionary in 'uCustomDictionary.pas', ufrmSpell in 'ufrmSpell.pas' {frmSpell}, - ufrmSpellOptions in 'ufrmSpellOptions.pas' {frmSpellOptions}, - ufrmSpellPopUp in 'ufrmSpellPopUp.pas' {frmSpellPopUp}, - uRegExPhoneticSearch_Spell in 'uRegExPhoneticSearch_Spell.pas', - uSimilarSort_Spell in 'uSimilarSort_Spell.pas', - uSpellEditDistanceSearch in 'uSpellEditDistanceSearch.pas', BanglaChars in '..\Units\BanglaChars.pas', - PCRE in '..\Units\PCRE.pas', - pcre_dll in '..\Units\pcre_dll.pas', - cDictionaries in '..\Units\cDictionaries.pas', - cUtils in '..\Units\cUtils.pas', - cTypes in '..\Units\cTypes.pas', - cArrays in '..\Units\cArrays.pas', - cStrings in '..\Units\cStrings.pas', uFileFolderHandling in '..\Units\uFileFolderHandling.pas', KeyboardFunctions in '..\Units\KeyboardFunctions.pas', VirtualKeyCode in '..\Units\VirtualKeyCode.pas', - uDBase in '..\Units\uDBase.pas', uRegistrySettings in 'uRegistrySettings.pas', uWindowHandlers in '..\Units\uWindowHandlers.pas', nativexml in '..\Units\nativexml.pas', - ufrmAbout in 'ufrmAbout.pas' {frmAbout}, clsFileVersion in '..\Classes\clsFileVersion.pas', clsRegistry_XMLSetting in 'clsRegistry_XMLSetting.pas', WindowsVersion in '..\Units\WindowsVersion.pas'; {$R *.res} -begin - Application.Initialize; - Application.MainFormOnTaskbar := True; - Application.Title := 'Avro Spell Checker'; - LoadWordDatabase; - Application.CreateForm(TfrmSpell, frmSpell); +Begin + Application.Initialize; + Application.MainFormOnTaskbar := True; + Application.Title := 'Avro Spell Checker'; + Application.CreateForm(TfrmSpell, frmSpell); Application.Run; -end. +End. + diff --git a/Keyboard and Spell checker/SpellChecker/Avro_Spell_Checker.res b/Keyboard and Spell checker/SpellChecker/Avro_Spell_Checker.res index 8a879b7..402f93e 100644 Binary files a/Keyboard and Spell checker/SpellChecker/Avro_Spell_Checker.res and b/Keyboard and Spell checker/SpellChecker/Avro_Spell_Checker.res differ diff --git a/Keyboard and Spell checker/SpellChecker/clsMemoParser.pas b/Keyboard and Spell checker/SpellChecker/clsMemoParser.pas index cdf773a..d51227c 100644 --- a/Keyboard and Spell checker/SpellChecker/clsMemoParser.pas +++ b/Keyboard and Spell checker/SpellChecker/clsMemoParser.pas @@ -35,6 +35,7 @@ TTotalProgress = Procedure(FCurrentProgress: Integer) Of Object; TWordFound = Procedure(FCurrentWord: WideString) Of Object; TCompleteParsing = Procedure Of Object; + TPositionConflict = Procedure Of Object; Type TMemoParser = Class @@ -51,12 +52,14 @@ FTotalProgress: TTotalProgress; FWordFound: TWordFound; FCompleteParsing: TCompleteParsing; + FPositionComflict: TPositionConflict; Public Constructor Create; Procedure BeginPursing; Procedure PausePursing; Procedure SelectWord; + Procedure ResetAll; Procedure ReplaceCurrentWord(Const rWord: WideString; Const PrevWord: WideString); // event properties @@ -66,6 +69,8 @@ Read FWordFound Write FWordFound; Property OnCompleteParsing: TCompleteParsing Read FCompleteParsing Write FCompleteParsing; + Property OnPositionConflict: TPositionConflict + Read FPositionComflict Write FPositionComflict; End; Implementation @@ -83,11 +88,7 @@ Constructor TMemoParser.Create; Begin - SelStart := 0; - SelLength := 0; - CurrentLine := 0; - LinePos := 0; - FStopPursing := False; + ResetAll; FTotalProgress := Nil; FWordFound := Nil; FCompleteParsing := Nil; @@ -205,6 +206,10 @@ FStopPursing := False; TotalLines := frmSpell.MEMO.Lines.Count - 1; + If CurrentLine > (TotalLines+1) Then Begin + If Assigned(FPositionComflict) Then FPositionComflict; + Exit; + End; While CurrentLine <= TotalLines Do Begin @@ -233,7 +238,7 @@ SelLength := length(CurrentWord); FWordFound(CurrentWord); CurrentWord := ''; - If FStopPursing = True Then exit; + exit; End; End; End; @@ -244,7 +249,7 @@ SelLength := length(CurrentWord); FWordFound(CurrentWord); CurrentWord := ''; - If FStopPursing = True Then exit; + exit; End; End; @@ -254,13 +259,18 @@ If Assigned(FCompleteParsing) Then FCompleteParsing; - End; Procedure TMemoParser.ReplaceCurrentWord(Const rWord: WideString; Const PrevWord: WideString); Begin frmSpell.MEMO.SelStart := frmSpell.MEMO.Perform(EM_LINEINDEX, CurrentLine, 0) + SelStart - 1; frmSpell.MEMO.SelLength := SelLength; + + If frmSpell.MEMO.SelText <> PrevWord Then Begin + If Assigned(FPositionComflict) Then FPositionComflict; + Exit; + End; + frmSpell.MEMO.SelText := rWord; If Length(rWord) < SelLength Then Begin @@ -274,6 +284,15 @@ End; +Procedure TMemoParser.ResetAll; +Begin + SelStart := 0; + SelLength := 0; + CurrentLine := 0; + LinePos := 0; + FStopPursing := False; +End; + Procedure TMemoParser.SelectWord; Begin frmSpell.MEMO.SelStart := frmSpell.MEMO.Perform(EM_LINEINDEX, CurrentLine, 0) + SelStart - 1; diff --git a/Keyboard and Spell checker/SpellChecker/clsRegistry_XMLSetting.pas b/Keyboard and Spell checker/SpellChecker/clsRegistry_XMLSetting.pas index 275c474..7290e8a 100644 --- a/Keyboard and Spell checker/SpellChecker/clsRegistry_XMLSetting.pas +++ b/Keyboard and Spell checker/SpellChecker/clsRegistry_XMLSetting.pas @@ -143,11 +143,18 @@ {$HINTS Off} Function TXMLSetting.LoadXMLData(): Boolean; +Var + SettingFileName : String; Begin Result := False; + {$IFNDEF SpellCheckerDll} + SettingFileName := 'Spell Settings.xml'; + {$ELSE} + SettingFileName := 'Spell dll Settings.xml'; + {$ENDIF} Try - If FileExists(ExtractFilePath(Application.ExeName) + 'Spell Settings.xml') = True Then Begin - XML.LoadFromFile(ExtractFilePath(Application.ExeName) + 'Spell Settings.xml'); + If FileExists(GetAvroDataDir + SettingFileName) = True Then Begin + XML.LoadFromFile(GetAvroDataDir + SettingFileName); Result := True; End Else @@ -161,10 +168,17 @@ {===============================================================================} Procedure TXMLSetting.SaveXMLData; +Var + SettingFileName : String; Begin XML.XmlFormat := xfReadable; + {$IFNDEF SpellCheckerDll} + SettingFileName := 'Spell Settings.xml'; + {$ELSE} + SettingFileName := 'Spell dll Settings.xml'; + {$ENDIF} Try - Xml.SaveToFile(GetAvroDataDir + 'Spell Settings.xml'); + Xml.SaveToFile(GetAvroDataDir + SettingFileName); Except On E: Exception Do Begin //Nothing diff --git a/Keyboard and Spell checker/SpellChecker/uCustomDictionary.pas b/Keyboard and Spell checker/SpellChecker/uCustomDictionary.pas index 1821ae5..7cb8ee7 100644 --- a/Keyboard and Spell checker/SpellChecker/uCustomDictionary.pas +++ b/Keyboard and Spell checker/SpellChecker/uCustomDictionary.pas @@ -33,6 +33,7 @@ cDictionaries; Var + FCustomDictLoaded : Boolean; SpellCustomDict : TWideStringList; SpellIgnoreDict : TWideStringList; SpellChangeDict : TStringDictionary; @@ -52,6 +53,9 @@ Var TempList : TWideStringList; Begin + If FCustomDictLoaded Then exit; + + TempList := TWideStringList.Create; SpellCustomDict := TWideStringList.Create; @@ -76,6 +80,7 @@ SpellChangeDict := TStringDictionary.Create; SpellChangeDict.DuplicatesAction := ddIgnore; + FCustomDictLoaded := True; End; Procedure SaveSpellCustomDict; @@ -87,7 +92,7 @@ TempList.Sorted := False; TempList.Insert(0, '// Custom Bangla Dictionary for Avro Spell Checker (Do not remove this line)'); Try - TempList.SaveToFile(GetAvroDataDir + 'CustomSpellingDictionary.dat'); + TempList.SaveToFile(GetAvroDataDir + 'CustomSpellingDictionary.dat'); Except On E: Exception Do Begin //Nothing @@ -104,21 +109,27 @@ SpellChangeDict.Clear; FreeAndNil(SpellChangeDict); + + FCustomDictLoaded := False; End; Function WordPresentInCustomDict(Const w: WideString): Boolean; -var -Dummy:Integer; -begin - Result:=SpellCustomDict.Find(w,Dummy); -end; +Var + Dummy : Integer; +Begin + Result := SpellCustomDict.Find(w, Dummy); +End; Function WordPresentInIgnoreDict(Const w: WideString): Boolean; -var -Dummy:Integer; -begin - Result:=SpellIgnoreDict.Find(w,Dummy); -end; +Var + Dummy : Integer; +Begin + Result := SpellIgnoreDict.Find(w, Dummy); +End; + +//------------------------------------------------------------------------------ +Initialization + FCustomDictLoaded := False; End. diff --git a/Keyboard and Spell checker/SpellChecker/uRegistrySettings.pas b/Keyboard and Spell checker/SpellChecker/uRegistrySettings.pas index 2551402..ba18d36 100644 --- a/Keyboard and Spell checker/SpellChecker/uRegistrySettings.pas +++ b/Keyboard and Spell checker/SpellChecker/uRegistrySettings.pas @@ -40,13 +40,9 @@ forms; Var - //Spellchecker options - IgnoreNumber : String; - IgnoreAncient : String; - IgnoreAssamese : String; - IgnoreSingle : String; - FullSuggestion : String; + + {$IFNDEF SpellCheckerDll} AvroPadHeight : String; AvroPadWidth : String; AvroPadTop : String; @@ -57,7 +53,14 @@ AvroPadWrap : String; LastDirectory : String; - + {$ELSE} + //Spellchecker options + IgnoreNumber : String; + IgnoreAncient : String; + IgnoreAssamese : String; + IgnoreSingle : String; + FullSuggestion : String; + {$ENDIF} Procedure LoadSettings; Procedure ValidateSettings; @@ -109,13 +112,9 @@ Reg := TMyRegistry.create; Reg.RootKey := HKEY_CURRENT_USER; If Reg.OpenKey('Software\OmicronLab\Avro Spell Checker', True) = True Then Begin - IgnoreNumber := UpperCase(REG.ReadStringDef('IgnoreNumber', 'Yes')); - IgnoreAncient := UpperCase(REG.ReadStringDef('IgnoreAncient', 'Yes')); - IgnoreAssamese := UpperCase(REG.ReadStringDef('IgnoreAssamese', 'Yes')); - IgnoreSingle := UpperCase(REG.ReadStringDef('IgnoreSingle', 'Yes')); - FullSuggestion := UpperCase(REG.ReadStringDef('FullSuggestion', 'No')); + {$IFNDEF SpellCheckerDll} AvroPadHeight := REG.ReadStringDef('AvroPadHeight', '314'); AvroPadWidth := REG.ReadStringDef('AvroPadWidth', '507'); AvroPadTop := REG.ReadStringDef('AvroPadTop', '50'); @@ -126,6 +125,13 @@ AvroPadWrap := UpperCase(REG.ReadStringDef('AvroPadWrap', 'Yes')); LastDirectory := REG.ReadStringDef('LastDirectory', GetMyDocumentsFolder); + {$ELSE} + IgnoreNumber := UpperCase(REG.ReadStringDef('IgnoreNumber', 'Yes')); + IgnoreAncient := UpperCase(REG.ReadStringDef('IgnoreAncient', 'Yes')); + IgnoreAssamese := UpperCase(REG.ReadStringDef('IgnoreAssamese', 'Yes')); + IgnoreSingle := UpperCase(REG.ReadStringDef('IgnoreSingle', 'Yes')); + FullSuggestion := UpperCase(REG.ReadStringDef('FullSuggestion', 'No')); + {$ENDIF} End; Reg.Free; End; @@ -139,12 +145,9 @@ XML := TXMLSetting.Create; XML.LoadXMLData; - IgnoreNumber := UpperCase(XML.GetValue('IgnoreNumber', 'Yes')); - IgnoreAncient := UpperCase(XML.GetValue('IgnoreAncient', 'Yes')); - IgnoreAssamese := UpperCase(XML.GetValue('IgnoreAssamese', 'Yes')); - IgnoreSingle := UpperCase(XML.GetValue('IgnoreSingle', 'Yes')); - FullSuggestion := UpperCase(XML.GetValue('FullSuggestion', 'No')); + + {$IFNDEF SpellCheckerDll} AvroPadHeight := XML.GetValue('AvroPadHeight', '314'); AvroPadWidth := XML.GetValue('AvroPadWidth', '507'); AvroPadTop := XML.GetValue('AvroPadTop', '50'); @@ -155,7 +158,13 @@ AvroPadWrap := UpperCase(XML.GetValue('AvroPadWrap', 'Yes')); LastDirectory := XML.GetValue('LastDirectory', GetMyDocumentsFolder); - + {$ELSE} + IgnoreNumber := UpperCase(XML.GetValue('IgnoreNumber', 'Yes')); + IgnoreAncient := UpperCase(XML.GetValue('IgnoreAncient', 'Yes')); + IgnoreAssamese := UpperCase(XML.GetValue('IgnoreAssamese', 'Yes')); + IgnoreSingle := UpperCase(XML.GetValue('IgnoreSingle', 'Yes')); + FullSuggestion := UpperCase(XML.GetValue('FullSuggestion', 'No')); + {$ENDIF} XML.Free; End; @@ -168,15 +177,11 @@ Reg := TMyRegistry.Create; Reg.RootKey := HKEY_CURRENT_USER; If Reg.OpenKey('Software\OmicronLab\Avro Spell Checker', True) = True Then Begin + + {$IFNDEF SpellCheckerDll} REG.WriteString('AppPath', ExtractFileDir(Application.ExeName)); REG.WriteString('AppExeName', ExtractFileName(Application.ExeName)); - REG.WriteString('IgnoreNumber', IgnoreNumber); - REG.WriteString('IgnoreAncient', IgnoreAncient); - REG.WriteString('IgnoreAssamese', IgnoreAssamese); - REG.WriteString('IgnoreSingle', IgnoreSingle); - REG.WriteString('FullSuggestion', FullSuggestion); - REG.WriteString('AvroPadHeight', AvroPadHeight); REG.WriteString('AvroPadWidth', AvroPadWidth); REG.WriteString('AvroPadTop', AvroPadTop); @@ -187,7 +192,13 @@ REG.WriteString('AvroPadWrap', AvroPadWrap); REG.WriteString('LastDirectory', LastDirectory); - + {$ELSE} + REG.WriteString('IgnoreNumber', IgnoreNumber); + REG.WriteString('IgnoreAncient', IgnoreAncient); + REG.WriteString('IgnoreAssamese', IgnoreAssamese); + REG.WriteString('IgnoreSingle', IgnoreSingle); + REG.WriteString('FullSuggestion', FullSuggestion); + {$ENDIF} End; Reg.Free; @@ -202,12 +213,9 @@ XML := TXMLSetting.Create; XML.CreateNewXMLData; - XML.SetValue('IgnoreNumber', IgnoreNumber); - XML.SetValue('IgnoreAncient', IgnoreAncient); - XML.SetValue('IgnoreAssamese', IgnoreAssamese); - XML.SetValue('IgnoreSingle', IgnoreSingle); - XML.SetValue('FullSuggestion', FullSuggestion); + + {$IFNDEF SpellCheckerDll} XML.SetValue('AvroPadHeight', AvroPadHeight); XML.SetValue('AvroPadWidth', AvroPadWidth); XML.SetValue('AvroPadTop', AvroPadTop); @@ -218,7 +226,13 @@ XML.SetValue('AvroPadWrap', AvroPadWrap); XML.SetValue('LastDirectory', LastDirectory); - + {$ELSE} + XML.SetValue('IgnoreNumber', IgnoreNumber); + XML.SetValue('IgnoreAncient', IgnoreAncient); + XML.SetValue('IgnoreAssamese', IgnoreAssamese); + XML.SetValue('IgnoreSingle', IgnoreSingle); + XML.SetValue('FullSuggestion', FullSuggestion); + {$ENDIF} XML.SaveXMLData; XML.Free; @@ -228,12 +242,7 @@ Procedure ValidateSettings; Begin - If Not ((IgnoreNumber = 'YES') Or (IgnoreNumber = 'NO')) Then IgnoreNumber := 'YES'; - If Not ((IgnoreAncient = 'YES') Or (IgnoreAncient = 'NO')) Then IgnoreAncient := 'YES'; - If Not ((IgnoreAssamese = 'YES') Or (IgnoreAssamese = 'NO')) Then IgnoreAssamese := 'YES'; - If Not ((IgnoreSingle = 'YES') Or (IgnoreSingle = 'NO')) Then IgnoreSingle := 'YES'; - If Not ((FullSuggestion = 'YES') Or (FullSuggestion = 'NO')) Then FullSuggestion := 'NO'; - + {$IFNDEF SpellCheckerDll} If Not (strtoint(AvroPadHeight) > 0) Then AvroPadHeight := '314'; If Not (strtoint(AvroPadWidth) > 0) Then AvroPadWidth := '507'; If Not (strtoint(AvroPadTop) > 0) Then AvroPadTop := '50'; @@ -244,7 +253,13 @@ If Not (strtoint(AvroPadFontSize) > 0) Then AvroPadFontSize := '10'; If Not ((AvroPadWrap = 'YES') Or (AvroPadWrap = 'NO')) Then AvroPadWrap := 'YES'; If Not (DirectoryExists(LastDirectory)) Then LastDirectory := GetMyDocumentsFolder; - + {$ELSE} + If Not ((IgnoreNumber = 'YES') Or (IgnoreNumber = 'NO')) Then IgnoreNumber := 'YES'; + If Not ((IgnoreAncient = 'YES') Or (IgnoreAncient = 'NO')) Then IgnoreAncient := 'YES'; + If Not ((IgnoreAssamese = 'YES') Or (IgnoreAssamese = 'NO')) Then IgnoreAssamese := 'YES'; + If Not ((IgnoreSingle = 'YES') Or (IgnoreSingle = 'NO')) Then IgnoreSingle := 'YES'; + If Not ((FullSuggestion = 'YES') Or (FullSuggestion = 'NO')) Then FullSuggestion := 'NO'; + {$ENDIF} End; {===============================================================================} diff --git a/Keyboard and Spell checker/SpellChecker/ufrmAbout.pas b/Keyboard and Spell checker/SpellChecker/ufrmAbout.pas index fc5dd34..170e8fb 100644 --- a/Keyboard and Spell checker/SpellChecker/ufrmAbout.pas +++ b/Keyboard and Spell checker/SpellChecker/ufrmAbout.pas @@ -102,6 +102,7 @@ Version := TFileVersion.Create(); LabelVersion.Caption := Version.AsString{$IFDEF BetaVersion} + ' BETA'{$ENDIF}{$IFDEF PortableOn} + ' (Portable)'{$ENDIF}; Version.Free; + self.Caption:='About Avro Spell Checker'; End; {===============================================================================} diff --git a/Keyboard and Spell checker/SpellChecker/ufrmSpell.pas b/Keyboard and Spell checker/SpellChecker/ufrmSpell.pas index 3137ce1..4843e7b 100644 --- a/Keyboard and Spell checker/SpellChecker/ufrmSpell.pas +++ b/Keyboard and Spell checker/SpellChecker/ufrmSpell.pas @@ -45,7 +45,8 @@ StdCtrls, TntStdCtrls, ComCtrls, - TntComCtrls; + TntComCtrls, + clsMemoParser; Type TfrmSpell = Class(TForm) @@ -100,6 +101,7 @@ Private { Private declarations } + //File handling fFileName: String; MemoChanged: Boolean; @@ -109,8 +111,16 @@ Procedure ShowOpenDialog; Procedure ShowSaveDialog; + + {MemoParser events} + Procedure MP_WordFound(CurrentWord: WideString); + Procedure MP_CompleteParsing; + Procedure MP_PositionConflict; + Procedure MP_TotalProgress(CurrentProgress: Integer); + Public { Public declarations } + MP: TMemoParser; CheckingSpell: Boolean; {Procedure ClipboardCopyPaste;} { Procedure ShowMe;} @@ -121,27 +131,87 @@ Var frmSpell : TfrmSpell; + + + + /////////////////////////////////////////////////////////////////////////////////// + //AvroSpell.dll functions + /////////////////////////////////////////////////////////////////////////////////// + +Procedure InitSpell; Stdcall; external 'AvroSpell.dll' name 'InitSpell'; +Procedure RegisterCallback(mCallback: Pointer); Stdcall; external 'AvroSpell.dll' name 'RegisterCallback'; +Function IsWordPresent(Wrd: PWideChar; Var SAction: Integer): Boolean; Stdcall; external 'AvroSpell.dll' name 'IsWordPresent'; +Function WordPresentInChangeAll(Wrd: PWideChar): Boolean; Stdcall; external 'AvroSpell.dll' name 'WordPresentInChangeAll'; +Procedure GetCorrection(Wrd: PWideChar); Stdcall; external 'AvroSpell.dll' name 'GetCorrection'; +Procedure SetWordPosInScreen(xPoint, yPoint: Integer); Stdcall; external 'AvroSpell.dll' name 'SetWordPosInScreen'; +Procedure HideSpeller; stdcall; external 'AvroSpell.dll' name 'HideSpeller'; +Procedure ShowOptions; stdcall; external 'AvroSpell.dll' name 'ShowOptions'; +Procedure ShowAbout; stdcall; external 'AvroSpell.dll' name 'ShowAbout'; +Procedure ForgetChangeIgnore; stdcall; external 'AvroSpell.dll' name 'ForgetChangeIgnore'; +Procedure UnloadAll; stdcall; external 'AvroSpell.dll' name 'UnloadAll'; +/////////////////////////////////////////////////////////////////////////////////// + +Procedure Callback(Wrd: PWideChar; CWrd: PWideChar; SAction: Integer); stdcall; + Implementation {$R *.dfm} Uses - ufrmSpellPopUp, - uCustomDictionary, - uDBase, - HashTable, KeyboardFunctions, VirtualKeyCode, strutils, uRegistrySettings, - uWindowHandlers, - ufrmSpellOptions, - ufrmAbout; + uWindowHandlers; Const Show_Window_in_Taskbar = True; +Const + SA_Default : Integer = 0; + SA_Ignore : Integer = 1; + SA_Cancel : Integer = -1; + SA_IgnoredByOption : Integer = 2; + SA_ReplaceAll : Integer = 3; + +Procedure Callback(Wrd: PWideChar; CWrd: PWideChar; SAction: Integer); Stdcall; +Begin + If SAction = SA_Cancel Then Begin {User clicked cancel} + ForgetChangeIgnore; + frmSpell.Progress.Visible := False; + frmSpell.CheckingSpell := False; + Exit; + End + Else If (SAction = SA_Default) Or (SAction = SA_ReplaceAll) Then Begin + frmSpell.MP.ReplaceCurrentWord(CWrd, Wrd); + End; + frmSpell.Mp.BeginPursing; +End; - {===============================================================================} +{===============================================================================} + +Procedure TfrmSpell.MP_WordFound(CurrentWord: WideString); +Var + DummySAction : Integer; + PT : TPoint; +Begin + If Not IsWordPresent(PWideChar(CurrentWord), DummySAction) Then Begin + + If WordPresentInChangeAll(PWideChar(CurrentWord)) Then + GetCorrection(PWideChar(CurrentWord)) + Else Begin + GetCorrection(PWideChar(CurrentWord)); + mp.SelectWord; + MEMO.SetFocus; + GetCaretPos(Pt); + Pt := MEMO.ClientToScreen(Pt); + SetWordPosInScreen(Pt.X, Pt.Y); + End; + End + Else + Mp.BeginPursing; +End; + +{===============================================================================} Procedure TfrmSpell.Clearall1Click(Sender: TObject); Begin @@ -277,10 +347,9 @@ AvroPadState := 'NORMAL'; SaveSettings; + UnloadAll; + FreeAndNil(MP); - - SaveSpellCustomDict; - UnloadWordDatabase; Action := caFree; frmSpell := Nil; End; @@ -317,10 +386,10 @@ Procedure TfrmSpell.FormCreate(Sender: TObject); Begin - InitSpellCustomDict; CheckingSpell := False; New1Click(Nil); - + InitSpell; + RegisterCallback(@Callback); LoadSettings; Self.Height := StrToInt(AvroPadHeight); @@ -348,7 +417,11 @@ Self.Show; ForceForegroundWindow(handle); - + MP := TMemoParser.Create; + Mp.OnTotalProgress := MP_TotalProgress; + mp.OnWordFound := MP_WordFound; + mp.OnCompleteParsing := MP_CompleteParsing; + Mp.OnPositionConflict := MP_PositionConflict; End; {===============================================================================} @@ -360,10 +433,46 @@ {===============================================================================} +Procedure TfrmSpell.MP_CompleteParsing; +Begin + Application.MessageBox('Spelling check is complete.', 'Avro Bangla Spell Checker', MB_OK + MB_ICONEXCLAMATION + MB_DEFBUTTON1 + MB_APPLMODAL); + ForgetChangeIgnore; + Progress.Visible := False; + CheckingSpell := False; +End; + +{===============================================================================} + +Procedure TfrmSpell.MP_PositionConflict; +Begin + HideSpeller; + + + Application.MessageBox('Document has been modified above the current spell checking position.' + #10 + + '' + #10 + '' + #10 + 'Avro Pad will resume spell checking from the beginning.', + 'Avro Pad', MB_OK + + MB_ICONEXCLAMATION + + MB_DEFBUTTON1 + + MB_APPLMODAL); + + MP.ResetAll; + CheckingSpell := False; + Startspellchek1Click(Nil); +End; + +{===============================================================================} + +Procedure TfrmSpell.MP_TotalProgress(CurrentProgress: Integer); +Begin + Progress.Position := CurrentProgress; + Application.ProcessMessages; +End; + +{===============================================================================} + Procedure TfrmSpell.N5Click(Sender: TObject); Begin - Application.CreateForm(TfrmAbout, frmAbout); - frmAbout.ShowModal; + ShowAbout; End; {===============================================================================} @@ -602,31 +711,21 @@ Procedure TfrmSpell.Spellcheckoptions1Click(Sender: TObject); Begin - CheckCreateForm(TfrmSpellOptions, frmSpellOptions, 'frmSpellOptions'); - frmSpellOptions.ShowModal; + ShowOptions; End; {===============================================================================} Procedure TfrmSpell.Startspellchek1Click(Sender: TObject); Begin + If CheckingSpell Then exit; + CheckingSpell := True; Progress.Visible := True; - Memo.ReadOnly := True; - Application.CreateForm(TfrmSpellPopUp, frmSpellPopUp); - Try - frmSpellPopUp.ShowModal; - Except - On E: Exception Do Begin - //Nothing - End; - End; Progress.Position := 0; - Progress.Visible := False; - Memo.ReadOnly := False; - - CheckingSpell := False; + mp.ResetAll; + mp.BeginPursing; End; {===============================================================================} diff --git a/Keyboard and Spell checker/SpellChecker/ufrmSpellOptions.pas b/Keyboard and Spell checker/SpellChecker/ufrmSpellOptions.pas index 2eb47fc..fe19cec 100644 --- a/Keyboard and Spell checker/SpellChecker/ufrmSpellOptions.pas +++ b/Keyboard and Spell checker/SpellChecker/ufrmSpellOptions.pas @@ -72,7 +72,7 @@ Procedure TfrmSpellOptions.ButtonCancelClick(Sender: TObject); Begin - ModalResult := mrCancel; + Self.Close; End; Procedure TfrmSpellOptions.ButtonOkClick(Sender: TObject); @@ -102,8 +102,8 @@ Else FullSuggestion := 'NO'; - - ModalResult := mrOk; + SaveSettings; + Self.Close; End; Procedure TfrmSpellOptions.FormClose(Sender: TObject; diff --git a/Keyboard and Spell checker/SpellChecker/ufrmSpellPopUp.dfm b/Keyboard and Spell checker/SpellChecker/ufrmSpellPopUp.dfm index dcd4434..fdbd2ee 100644 --- a/Keyboard and Spell checker/SpellChecker/ufrmSpellPopUp.dfm +++ b/Keyboard and Spell checker/SpellChecker/ufrmSpellPopUp.dfm @@ -3,7 +3,7 @@ object frmSpellPopUp: TfrmSpellPopUp Top = 0 BorderIcons = [] BorderStyle = bsSingle - Caption = 'Bangla Spell Check' + Caption = 'Avro Spell Check' ClientHeight = 282 ClientWidth = 421 Color = clBtnFace @@ -52,6 +52,7 @@ object frmSpellPopUp: TfrmSpellPopUp OldCreateOrder = False OnClose = FormClose OnCreate = FormCreate + OnShow = FormShow PixelsPerInch = 96 TextHeight = 13 object Label1: TLabel diff --git a/Keyboard and Spell checker/SpellChecker/ufrmSpellPopUp.pas b/Keyboard and Spell checker/SpellChecker/ufrmSpellPopUp.pas index 79c214a..9ed024a 100644 --- a/Keyboard and Spell checker/SpellChecker/ufrmSpellPopUp.pas +++ b/Keyboard and Spell checker/SpellChecker/ufrmSpellPopUp.pas @@ -41,7 +41,6 @@ Dialogs, StdCtrls, TntStdCtrls, - clsMemoParser, ComCtrls, clsSpellPhoneticSuggestionBuilder, widestrings; @@ -78,92 +77,215 @@ Procedure ListDblClick(Sender: TObject); Procedure CheckLessPrefferedClick(Sender: TObject); Procedure But_OptionsClick(Sender: TObject); + Procedure FormShow(Sender: TObject); Private { Private declarations } - MP: TMemoParser; - PhoneticSug: TPhoneticSpellSuggestion; - //Suggestions by various methods - PhoneticResult: TWideStringList; - FuzzyResult: TWideStringList; - OtherResult: TWideStringList; - DetermineZWNJ_ZWJ: WideString; - Procedure ShowSuggestion(FullResult: Boolean); - - Function CanIgnoreByOption(W: WideString): Boolean; - Function SplitSuggestion(w: widestring): WideString; - Procedure MP_WordFound(CurrentWord: WideString); - Procedure MP_CompleteParsing; - Procedure Suggest; - Function UnicodeDeNormalize(Const W: WideString): WideString; - Procedure MP_TotalProgress(CurrentProgress: Integer); Public { Public declarations } + Procedure ShowSuggestion(FullResult: Boolean); End; +Type + TCallback = Procedure(Wrd: PWideChar; CWrd: PWideChar; SAction: Integer); stdcall; + +Var + Callback : TCallback; + Var frmSpellPopUp : TfrmSpellPopUp; + //Suggestions by various methods + PhoneticSug : TPhoneticSpellSuggestion; + PhoneticResult : TWideStringList; + FuzzyResult : TWideStringList; + OtherResult : TWideStringList; + + DetermineZWNJ_ZWJ : WideString; + // + WordNotFound, WordSelected: WideString; + +Const + SA_Default : Integer = 0; + SA_Ignore : Integer = 1; + SA_Cancel : Integer = -1; + SA_IgnoredByOption : Integer = 2; + SA_ReplaceAll : Integer = 3; + + Procedure MoveToOptimumPos(T_X, T_Y: Integer); + Implementation {$R *.dfm} Uses - ufrmSpell, - HashTable, uCustomDictionary, - uSpellEditDistanceSearch, widestrutils, BanglaChars, uSimilarSort_Spell, - PCRE, - PCRE_DLL, StrUtils, - uWindowHandlers, ufrmSpellOptions, uRegistrySettings, - WindowsVersion, - uDBase; + uWindowHandlers; + + + Procedure MoveToOptimumPos(T_X, T_Y: Integer); + + Function ValidPosition(f_Point: TPoint): Boolean; + Var + hTaskBar : THandle; + RTaskBar, RDummy, RWindow: TRect; + Begin + result := False; + + //Get taskbar rectangle + hTaskbar := FindWindow('Shell_TrayWnd', Nil); + GetWindowRect(hTaskBar, RTaskBar); + + //Get window rectangle with proposed position + RWindow.Top := f_Point.Y; + RWindow.Left := f_Point.X; + RWindow.Right := RWindow.Left + frmSpellPopUp.Width; + RWindow.Bottom := RWindow.Top + frmSpellPopUp.Height; + + If IntersectRect(RDummy, RWindow, RTaskBar) Then + exit; + + If (f_Point.X < 0) Or (f_Point.y < 0) Then + exit; + + If (RWindow.Right > Screen.Width) Or (RWindow.Bottom > Screen.Height) Then + exit; + + result := True; + End; + +Const + MinDistance : Integer = 20; + WordWidth : Integer = 50; + WordHeight : Integer = 50; +Var + RWord, RWindow, RDummy : TRect; + Intersect : Boolean; + PossiblePOS1, PossiblePOS2, PossiblePOS3, PossiblePOS4: TPoint; +Begin + If (T_X < 0) Or (T_Y < 0) Then + exit; + + + //Check whether current position of Window hides the text + RWord.Left := T_X - MinDistance; + RWord.Top := T_Y - MinDistance; + RWord.Right := T_X + WordWidth + MinDistance; + RWord.Bottom := T_Y + WordHeight + MinDistance; + + RWindow.Left := frmSpellPopUp.Left ; + RWindow.Top := frmSpellPopUp.Top ; + RWindow.Right := RWindow.Left + frmSpellPopUp.Width; + RWindow.Bottom := RWindow.Top + frmSpellPopUp.Height; + + Intersect := IntersectRect(RDummy, RWindow, RWord); + + + If Not Intersect Then + exit; + + + //So, current position of Window hides the text, time to move it + + //Calculate possible positions + PossiblePOS1.X := T_X; + PossiblePOS1.Y := T_Y - MinDistance - frmSpellPopUp.Height; + + PossiblePOS2.X := T_X; + PossiblePOS2.Y := T_Y + MinDistance; + + PossiblePOS3.X := T_X - MinDistance - frmSpellPopUp.Width; + PossiblePOS3.Y := T_Y; + + PossiblePOS4.X := T_X + MinDistance; + PossiblePOS4.Y := T_Y; + + If ValidPosition(PossiblePOS1) Then Begin + frmSpellPopUp.Left := PossiblePOS1.X; + frmSpellPopUp.Top := PossiblePOS1.Y; + exit; + End; + + If ValidPosition(PossiblePOS2) Then Begin + frmSpellPopUp.Left := PossiblePOS2.X; + frmSpellPopUp.Top := PossiblePOS2.Y; + exit; + End; + + If ValidPosition(PossiblePOS3) Then Begin + frmSpellPopUp.Left := PossiblePOS3.X; + frmSpellPopUp.Top := PossiblePOS3.Y; + exit; + End; + + If ValidPosition(PossiblePOS4) Then Begin + frmSpellPopUp.Left := PossiblePOS4.X; + frmSpellPopUp.Top := PossiblePOS4.Y; + exit; + End; +End; + Procedure TfrmSpellPopUp.But_AddToDictClick(Sender: TObject); Begin - SpellCustomDict.Add(Edit_NotFound.Text); - mp.BeginPursing; + WordNotFound := Edit_NotFound.Text; + WordSelected := ''; + SpellCustomDict.Add(WordNotFound); + Self.Hide; + callback(PWideChar(WordNotFound), PWideChar(WordSelected), SA_Ignore); End; Procedure TfrmSpellPopUp.But_CancelClick(Sender: TObject); Begin - Mp.PausePursing; - close; + WordNotFound := ''; + WordSelected := ''; + Self.Hide; + callback(PWideChar(WordNotFound), PWideChar(WordSelected), SA_Cancel); End; Procedure TfrmSpellPopUp.But_ChangeAllClick(Sender: TObject); Begin - mp.ReplaceCurrentWord(Edit_ChangeTo.Text, Edit_NotFound.Text); - SpellChangeDict.Add(utf8encode(Edit_NotFound.Text), utf8encode(Edit_ChangeTo.Text)); - mp.BeginPursing; + WordNotFound := Edit_NotFound.Text; + WordSelected := Edit_ChangeTo.Text; + SpellChangeDict.Add(utf8encode(WordNotFound), utf8encode(WordSelected)); + callback(PWideChar(WordNotFound), PWideChar(WordSelected), SA_ReplaceAll); + Self.Hide; End; Procedure TfrmSpellPopUp.But_ChangeClick(Sender: TObject); Begin - mp.ReplaceCurrentWord(Edit_ChangeTo.Text, Edit_NotFound.Text); - mp.BeginPursing; + WordNotFound := Edit_NotFound.Text; + WordSelected := Edit_ChangeTo.Text; + Self.Hide; + callback(PWideChar(WordNotFound), PWideChar(WordSelected), SA_Default); End; Procedure TfrmSpellPopUp.But_IgnoreAllClick(Sender: TObject); Begin - SpellIgnoreDict.Add(Edit_NotFound.Text); - mp.BeginPursing; + WordNotFound := Edit_NotFound.Text; + WordSelected := ''; + SpellIgnoreDict.Add(WordNotFound); + Self.Hide; + callback(PWideChar(WordNotFound), PWideChar(WordSelected), SA_Ignore); End; Procedure TfrmSpellPopUp.But_IgnoreClick(Sender: TObject); Begin - mp.BeginPursing; + WordNotFound := Edit_NotFound.Text; + WordSelected := ''; + Self.Hide; + callback(PWideChar(WordNotFound), PWideChar(WordSelected), SA_Ignore); End; Procedure TfrmSpellPopUp.But_OptionsClick(Sender: TObject); Begin - CheckCreateForm(TfrmSpellOptions, frmSpellOptions, 'frmSpellOptions'); + frmSpellOptions := TfrmSpellOptions.Create(Nil); frmSpellOptions.ShowModal; If FullSuggestion = 'YES' Then @@ -172,86 +294,6 @@ CheckLessPreffered.Checked := False; End; -Function TfrmSpellPopUp.CanIgnoreByOption(W: WideString): Boolean; -Var - { DONE : Make these registry variable } - Spell_IgnoreNumbers, Spell_IgnoreAncient, Spell_IgnoreAssamese, Spell_IgnoreSingle: Boolean; - - theRegex : IRegex; - theMatch : IMatch; - theLocale : ansistring; - RegExOpt : TRegMatchOptions; - RegExCompileOptions : TRegCompileOptions; - - SearchStr : AnsiString; - AnsiW : AnsiString; -Begin - Result := False; - AnsiW := utf8encode(w); - - If IgnoreNumber = 'YES' Then - Spell_IgnoreNumbers := True - Else - Spell_IgnoreNumbers := False; - - If IgnoreAncient = 'YES' Then - Spell_IgnoreAncient := True - Else - Spell_IgnoreAncient := False; - - If IgnoreAssamese = 'YES' Then - Spell_IgnoreAssamese := True - Else - Spell_IgnoreAssamese := False; - - If IgnoreSingle = 'YES' Then - Spell_IgnoreSingle := True - Else - Spell_IgnoreSingle := False; - - - RegExOpt := []; - theLocale := 'C'; - RegExCompileOptions := DecodeRegCompileOptions({PCRE_CASELESS Or}PCRE_UTF8); - - If Spell_IgnoreSingle Then Begin - If Length(W) < 2 Then Begin - Result := True; - exit; - End; - End; - - If Spell_IgnoreNumbers Then Begin - SearchStr := utf8encode('^.*[' + b_0 + b_1 + b_2 + b_3 + b_4 + b_5 + b_6 + b_7 + b_8 + b_9 + '].*$'); - theRegex := Pcre.RegexCreate(SearchStr, RegExCompileOptions, theLocale); - theMatch := theRegex.Match(AnsiW, RegExOpt); - If theMatch.Success Then Begin - Result := True; - exit; - End; - End; - - If Spell_IgnoreAssamese Then Begin - SearchStr := utf8encode('^.*[' + AssamRa + AssamVa + '].*$'); - theRegex := Pcre.RegexCreate(SearchStr, RegExCompileOptions, theLocale); - theMatch := theRegex.Match(AnsiW, RegExOpt); - If theMatch.Success Then Begin - Result := True; - exit; - End; - End; - - If Spell_IgnoreAncient Then Begin - SearchStr := utf8encode('^.*[' + b_Vocalic_L + b_Vocalic_LL + b_Vocalic_RR + b_Vocalic_RR_Kar + b_Vocalic_L_Kar + b_Vocalic_LL_Kar + b_Avagraha + b_LengthMark + b_RupeeMark + b_CurrencyNumerator1 + b_CurrencyNumerator2 + b_CurrencyNumerator3 + b_CurrencyNumerator4 + b_CurrencyNumerator1LessThanDenominator + b_CurrencyDenominator16 + b_CurrencyEsshar + '].*$'); - theRegex := Pcre.RegexCreate(SearchStr, RegExCompileOptions, theLocale); - theMatch := theRegex.Match(AnsiW, RegExOpt); - If theMatch.Success Then Begin - Result := True; - exit; - End; - End; - -End; Procedure TfrmSpellPopUp.CheckLessPrefferedClick(Sender: TObject); Begin @@ -265,70 +307,41 @@ End; End; -Procedure TfrmSpellPopUp.MP_WordFound(CurrentWord: WideString); -Begin - CurrentWord := UnicodeDeNormalize(CurrentWord); - - If CanIgnoreByOption(CurrentWord) = True Then exit; - - If (WordPresent(CurrentWord) = False) And - (WordPresentInCustomDict(CurrentWord) = False) And - (WordPresentInIgnoreDict(CurrentWord) = False) Then Begin - - If SpellChangeDict.HasKey(utf8encode(CurrentWord)) Then - mp.ReplaceCurrentWord(utf8decode(SpellChangeDict.Item[utf8encode(CurrentWord)]), Edit_NotFound.Text) - Else Begin - Mp.PausePursing; - Edit_NotFound.Text := CurrentWord; - mp.SelectWord; - Suggest; - End; - - End; -End; - Procedure TfrmSpellPopUp.FormClose(Sender: TObject; Var Action: TCloseAction); Begin - FreeAndNil(MP); - FreeAndNil(PhoneticSug); - PhoneticResult.Clear; - FreeAndNil(PhoneticResult); - FuzzyResult.Clear; - FreeAndNil(FuzzyResult); - OtherResult.Create; - FreeAndNil(OtherResult); - Action := caFree; frmSpellPopUp := Nil; End; Procedure TfrmSpellPopUp.FormCreate(Sender: TObject); Begin - MP := TMemoParser.Create; - PhoneticSug := TPhoneticSpellSuggestion.Create; - PhoneticResult := TWideStringList.Create; - FuzzyResult := TWideStringList.Create; - OtherResult := TWideStringList.Create; - Mp.OnTotalProgress := MP_TotalProgress; - mp.OnWordFound := MP_WordFound; - mp.OnCompleteParsing := MP_CompleteParsing; - - If FullSuggestion = 'YES' Then - CheckLessPreffered.Checked := True - Else - CheckLessPreffered.Checked := False; + DetermineZWNJ_ZWJ := ZWJ; + + TOPMOST(self.Handle); +End; - // If IsWinVistaOrLater Then - DetermineZWNJ_ZWJ := ZWJ ; - // Else - // DetermineZWNJ_ZWJ := ZWNJ; +Procedure TfrmSpellPopUp.FormShow(Sender: TObject); +Begin + self.Caption := 'Avro Spell Checker'; + If FullSuggestion = 'YES' Then Begin + CheckLessPreffered.Checked := True; + ShowSuggestion(True); + End + Else Begin + CheckLessPreffered.Checked := False; + ShowSuggestion(False) + End; - mp.BeginPursing; + List.ItemIndex := 0; + List.SetFocus; + ListClick(Nil); End; Procedure TfrmSpellPopUp.ListClick(Sender: TObject); Begin + If List.ItemIndex < 0 Then exit; + If List.Items[List.ItemIndex] = 'More...' Then ShowSuggestion(True) Else If List.Items[List.ItemIndex] = 'No Suggestion' Then @@ -353,18 +366,6 @@ But_ChangeClick(Nil); End; -Procedure TfrmSpellPopUp.MP_CompleteParsing; -Begin - Application.MessageBox('Spelling check is complete.', 'Avro Bangla Spell Checker', MB_OK + MB_ICONEXCLAMATION + MB_DEFBUTTON1 + MB_APPLMODAL); - close; -End; - -Procedure TfrmSpellPopUp.MP_TotalProgress(CurrentProgress: Integer); -Begin - frmSpell.Progress.Position := CurrentProgress; - Application.ProcessMessages; -End; - Procedure TfrmSpellPopUp.ShowSuggestion(FullResult: Boolean); Function Fix_ZWNJ_ZWJ(inp: WideString): WideString; @@ -374,9 +375,6 @@ retVal := WideReplaceStr(inp, b_R + ZWNJ + b_Hasanta + b_Z, b_r + DetermineZWNJ_ZWJ + b_Hasanta + b_Z); - {retVal := WideReplaceStr(inp, b_R + ZWJ + b_Hasanta + b_Z, - b_r + DetermineZWNJ_ZWJ + b_Hasanta + b_Z); } - Result := retVal; End; @@ -450,6 +448,9 @@ list.Items.Add(Fix_ZWNJ_ZWJ(TempList[i])); MoreNumber := TempList.Count; + {SimilarSort resets dupIgnore property, set that again} + TempList.Sorted := True; + TempList.Duplicates := dupIgnore; If FuzzyResult.Count > 0 Then Begin For I := 0 To FuzzyResult.Count - 1 Do TempList.Add(FuzzyResult[i]); @@ -466,79 +467,6 @@ FreeAndNil(TempList); End; -Function TfrmSpellPopUp.SplitSuggestion(w: widestring): WideString; -Var - I, Len : Integer; - part1, part2 : widestring; -Begin - Result := ''; - Len := Length(w); - I := 0; - Repeat - i := i + 1; - part1 := LeftStr(w, i); - part2 := MidStr(w, i + 1, len); - - If (WordPresent(part1) = true) And (WordPresent(part2) = true) Then Begin - Result := part1 + ' ' + part2; - break; - End; - - - Until i > len; -End; - -Procedure TfrmSpellPopUp.Suggest; -Var - SplittedWord : WideString; -Begin - PhoneticResult.Clear; - FuzzyResult.Clear; - OtherResult.Clear; - - //Bisharga to colon - If RightStr(Edit_NotFound.Text, 1) = b_bisharga Then Begin - If WordPresent(LeftStr(Edit_NotFound.Text, Length(Edit_NotFound.Text) - 1)) Then - OtherResult.Add(LeftStr(Edit_NotFound.Text, Length(Edit_NotFound.Text) - 1) + ':'); - End - Else Begin - //Phonetic errors - PhoneticSug.BuildSuggestion(Edit_NotFound.Text, PhoneticResult); - //Suggestion from fuzzy search ("Substitution", "Insertion", "Deletion" errors) - SearchSuggestion(Edit_NotFound.Text, FuzzyResult, 1); - End; - - //Splitted suggestion (Words Joined?) - If (PhoneticResult.Count + FuzzyResult.Count) <= 0 Then Begin - SplittedWord := SplitSuggestion(Edit_NotFound.Text); - If SplittedWord <> '' Then - OtherResult.Add(SplittedWord); - End; - - - //Rest Transposition and OCR errors for next version - { TODO : transposition and OCR errors} - - If CheckLessPreffered.Checked Then - ShowSuggestion(True) - Else - ShowSuggestion(False); - - If List.Count > 0 Then Begin - List.ItemIndex := 0; - ListClick(Nil); - End; -End; - -Function TfrmSpellPopUp.UnicodeDeNormalize(Const W: WideString): WideString; -Begin - Result := W; - Result := widestrutils.WideReplaceStr(Result, b_B + b_Nukta, b_r); - Result := widestrutils.WideReplaceStr(Result, b_Dd + b_Nukta, b_Rr); - Result := widestrutils.WideReplaceStr(Result, b_Ddh + b_Nukta, b_Rrh); - Result := widestrutils.WideReplaceStr(Result, b_Z + b_Nukta, b_Y); -End; - Procedure TfrmSpellPopUp.Edit_ChangeToChange(Sender: TObject); Begin If Edit_ChangeTo.Text = '' Then Begin @@ -559,7 +487,5 @@ But_ChangeClick(Nil); End; - - End. diff --git a/Keyboard and Spell checker/Units/uDBase.pas b/Keyboard and Spell checker/Units/uDBase.pas index c13a6a7..02dc978 100644 --- a/Keyboard and Spell checker/Units/uDBase.pas +++ b/Keyboard and Spell checker/Units/uDBase.pas @@ -435,9 +435,6 @@ BuildOneHashTable(Arr, HArr); Stmt.Free; - - Application.ProcessMessages; - End; //------------------------------------------------------------------------------ diff --git a/Keyboard and Spell checker/Units/uFileFolderHandling.pas b/Keyboard and Spell checker/Units/uFileFolderHandling.pas index 59a76e3..713ed18 100644 --- a/Keyboard and Spell checker/Units/uFileFolderHandling.pas +++ b/Keyboard and Spell checker/Units/uFileFolderHandling.pas @@ -47,6 +47,8 @@ classes; Function GetAvroDataDir(): String; +Function GetDllFolder: String; +Function GetDllFullPath: String; Function MyCopyFile(Const SourceFile, DestinationFile: String; Overwrite: Boolean = False): Boolean; Function MyMoveFile(Const SourceFile, DestinationFile: String; Overwrite: Boolean = False): Boolean; @@ -85,11 +87,37 @@ {===============================================================================} +Function GetDllFullPath: String; +Var + TheFileName : Array[0..MAX_PATH] Of char; +Begin + FillChar(TheFileName, sizeof(TheFileName), #0); + GetModuleFileName(hInstance, TheFileName, sizeof(TheFileName)); + Result := TheFileName; +End; + +{===============================================================================} + +Function GetDllFolder: String; +Var + TheFileName : Array[0..MAX_PATH] Of char; +Begin + FillChar(TheFileName, sizeof(TheFileName), #0); + GetModuleFileName(hInstance, TheFileName, sizeof(TheFileName)); + Result := ExtractFilePath(TheFileName); +End; + +{===============================================================================} + Function GetAvroDataDir(): String; Begin {$IFDEF PortableOn} + {$IFNDEF SpellCheckerDll} Result := ExtractFilePath(Application.ExeName); {$ELSE} + Result := GetDllFolder; + {$ENDIF} + {$ELSE} Result := GetCommonApplicationData + 'Avro Keyboard\'; {$ENDIF} End;