home *** CD-ROM | disk | FTP | other *** search
- (* EDSSPELL.PAS - Copyright (c) 1995-1996, Eminent Domain Software *)
-
- unit EDSSpell;
- {-Component Wrapper for Spell Dialog}
-
- {$I SpellDef.PAS}
- {-defines for EDSSpell component}
-
- interface
- uses
- SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
- Forms, Dialogs, StdCtrls, Buttons, Menus, ExtCtrls,
- SpellGbl, AbsBuff, AbsSpell, LexDCT, WPSpell,
- {$IFNDEF Shareware}
- MSSpell, W96Spell,
- {$ENDIF}
- {$IFDEF SupportOrpheus}
- OvcEdit, OvcEF, OvcBuff,
- {$ENDIF}
- {$IFDEF SupportTXText}
- TXBuff, Tx4vb,
- {$ENDIF}
- {$IFDEF SupportWPTools}
- WPRich, WPBuff,
- {$ENDIF}
- SpellInt;
-
- type
- {Dialog Component Wrapper}
- TSpellDlg = class (TComponent)
- private
- FPath: TFileName;
- FDictionary: TFileName;
- FDicType: TLanguages;
- FLanguage: TLanguages;
- FDialogType: TDialogTypes;
- FSpellWin: TAbsSpellDialog;
- FSuggestions: Byte;
- FIcons: TAccentSet;
- FAutoSuggest: Boolean;
- FAutoShift: Boolean;
- FHelpContext: THelpContext;
- FUserDCT: TFileName;
- {Lists of words}
- FSkipList: TStringList; {List of words to skip}
- FReplaceList: TStringList; {List of words to auto-replace}
- FReplacer: TStringList; {List of words to replace above list with}
- FReplaceNum: integer; {index of word in replace list}
- procedure SetDicType (NewType: TLanguages);
- {-sets the new dictionary type}
- procedure SetLanguage (NewLanguage: TLanguages);
- {-sets the language for the label}
- procedure SetDialogType (NewType: TDialogTypes);
- {-sets the dailog type}
- procedure SetSuggestions (Num: Byte);
- {-sets the number of suggestions}
- procedure SetIconSet (IconSet: TAccentSet);
- {-sets the icons to be visible}
- procedure SetHelpContext (HelpID: THelpContext);
- {-sets the help context for the spell component}
- function CheckBuffer (ABuffer: TAbsBuffer): Integer;
- {-checks the buffer}
- public
- constructor Create (AOwner: TComponent); override;
- {-initializes object}
- destructor Destroy; override;
- {-destroys object}
- function Open: Boolean;
- {-opens the dictionary}
- procedure Close;
- {-closes the dictionary and removes the dialog}
- procedure ClearLists;
- {-clears the SkipList, ReplaceList, and Replacer List}
- procedure MoveDialog (YPos: Integer);
- {-moves the dialog so that it does not highlighted word}
- procedure EnableSkipButtons;
- {-enables the skip buttons on the dialog}
- procedure DisableSkipButtons;
- {-disables the skip buttons on the dialog}
- procedure Show;
- {-displays the dialog}
- function CheckWord (var AWord: String): Integer;
- {-checks the word (see AbsSpell for CheckWord results)}
- function CheckCustomEdit (ACustomEdit: TCustomEdit): Integer;
- {-checks a custom edit control}
- function CheckMemo (AMemo: TMemo): Integer;
- {-checks the memo}
- (* function CheckDBMemo (ADBMemo: TDBMemo): Integer; *)
- (* -use CheckCustomEdit instead: *)
- (* CheckCustomEdit (DBMemo1); *)
- function CheckEdit (AnEdit: TEdit): Integer;
- {-checks a TEdit control}
- {$IFDEF SupportOrpheus}
- function CheckOvcEditor (AnOvcEdit: TOvcCustomEditor): Integer;
- {-checks an Orpheus editor component}
- function CheckOvcField (AnOvcField: TOvcBaseEntryField): Integer;
- {-checks an Orpheus field component}
- {$ENDIF}
- {$IFDEF SupportTXText}
- function CheckTXControl (ATXControl: TTextControl): Integer;
- {-checks a TXTextControl}
- {$ENDIF}
- {$IFDEF SupportWPTools}
- function CheckWPText (AWPRichText: TWPRichText): Integer;
- {-checks a WPTools RTF Component}
- {$ENDIF}
- function CheckAllFields (AForm: TForm; DisplayMsg: Boolean): Integer;
- {-checks all of the edit fields on the form}
-
- {---- Word Counters ----}
- procedure CustomEdit_WordCount (ACustomEdit: TCustomEdit; var NumWords, UniqueWords: Longint);
- {-returns the number of words in a TCustomEdit}
- procedure Memo_WordCount (AMemo: TMemo; var NumWords, UniqueWords: Longint);
- {-returns the number of words in a TMemo}
- procedure Edit_WordCount (AnEdit: TEdit; var NumWords, UniqueWords: Longint);
- {-returns the number of words in a TEdit}
- {$IFDEF SupportOrpheus}
- procedure OvcEdit_WordCount (AnOvcEdit: TOvcCustomEditor;
- var NumWords, UniqueWords: Longint);
- {-returns the number of words in a TOvcCustomEditor}
- procedure OvcField_WordCount (AnOvcField: TOvcBaseEntryField;
- var NumWords, UniqueWords: Longint);
- {-returns the number of words in a TOvcBaseEntryField}
- {$ENDIF}
- {$IFDEF SupportTXText}
- procedure TXText_WordCount (ATXControl: TTextControl;
- var NumWords, UniqueWords: Longint);
- {-returns the number of words in a TX Text-Control}
- {$ENDIF}
-
-
- {---- Internal Routines (No Dialog) ----}
- function OpenDictionary: Boolean;
- {-opens the dictionary}
- procedure CloseDictionary;
- {-closes the dictionary}
- function AddWord (AWord: string): Boolean;
- {-adds a word to the dictionary, returns TRUE if successful}
- function InDictionary (AWord: String): Boolean;
- {-checks to see if the word is in the dictionary (no dialog)}
- function SuggestWords (AWord: String; NumToList: Byte): TStringList;
- {-suggests words}
- {Lists of words}
- property SkipList: TStringList read FSkipList write FSkipList;
- property ReplaceList: TStringList read FReplaceList write FReplaceList;
- property Replacer: TStringList read FReplacer write FReplacer;
- published
- property AccentIcons: TAccentSet read FIcons write SetIconSet;
- property AutoShift: Boolean read FAutoShift write FAutoShift;
- property AutoSuggest: Boolean read FAutoSuggest write FAutoSuggest;
- property DialogStyle: TDialogTypes read FDialogType write SetDialogType;
- property DictionaryName: TFileName read FDictionary write FDictionary;
- property DictionaryPath: TFileName read FPath write FPath;
- property DictionaryType: TLanguages read FDicType write SetDicType;
- property LabelLanguage: TLanguages read FLanguage write SetLanguage;
- property Suggestions: Byte read FSuggestions write SetSuggestions;
- property HelpContext: THelpContext read FHelpContext write SetHelpContext;
- property UserDictionary: TFileName read FUserDCT write FUserDCT;
- end; { TSpellDlg }
-
- procedure Register;
-
- implementation
-
- {---- TSpellDlg.Wrapper ----}
- constructor TSpellDlg.Create (AOwner: TComponent);
- begin
- inherited Create (AOwner);
- FSpellWin := nil;
- FDialogType := dtWordPerfect;
- FIcons := [];
- FAutoShift := TRUE;
- FAutoSuggest := FALSE;
- FDictionary := '';
- FPath := 'APPLICATIONPATH';
- FUserDCT := 'USERDCT.TXT';
- FDicType := lgEnglish;
- FLanguage := lgEnglish;
- SetDialogType (FDialogType);
- Suggestions := 10;
- end; { TSpellDlg.Create }
-
- destructor TSpellDlg.Destroy;
- begin
- CloseDictionary;
- {FSpellWin is automatically destroyed by parent}
- {FSpellWin.Destroy implied}
- inherited Destroy;
- end; { TSpellDlg.Destroy }
-
- procedure TSpellDlg.SetDicType (NewType: TLanguages);
- {-sets the new dictionary type}
- begin
- FDicType := NewType;
- case FDicType of
- lgSpanish: Include (FIcons, acSpanish);
- end; { case }
- end; { TSpellDlg.SetDicType }
-
- procedure TSpellDlg.SetLanguage (NewLanguage: TLanguages);
- {-sets the language for the label}
- var
- LangMesg: string;
- begin
- FLanguage := NewLanguage;
- if FSpellWin <> nil then
- FSpellWin.Language := FLanguage;
- end; { TSpellDlg.SetLanguage }
-
- procedure TSpellDlg.SetDialogType (NewType: TDialogTypes);
- {-sets the dailog type}
- var
- dtMesg: string;
- begin
- if csDesigning in ComponentState then
- begin
- {$IFDEF Shareware}
- if NewType in [dtMSWord, dtWordPro96] then
- begin
- MessageDlg ('MSWord and WordPro96 dialogs are not'+#13+
- 'supported in shareware version.', mtInformation,
- [mbOk], 0);
- end {:} else
- FDialogType := NewType;
- {$ELSE}
- FDialogType := NewType;
- {$ENDIF}
- end {:} else
- begin
- FDialogType := NewType;
- if FSpellWin<>nil then
- begin
- FSpellWin.Free;
- FSpellWin := nil;
- end; { if... }
- case FDialogType of
- dtWordPerfect: FSpellWin := TWPSpellDlg.Create (Owner);
- {$IFNDEF Shareware}
- dtMSWord: FSpellWin := TMSSpellDlg.Create (Owner);
- dtWordPro96: FSpellWin := TW96SpellDlg.Create (Owner);
- {$ENDIF}
- end; { case }
- FSpellWin.SetAccentSet (FIcons);
- end; { if... }
- end; { TSpellDlg.SetDialogType }
-
- procedure TSpellDlg.SetSuggestions (Num: Byte);
- begin
- if Num>255 then
- begin
- MessageDlg ('Maximum limit suggestions is 255.',
- mtInformation, [mbOk], 0);
- FSuggestions := 255;
- end {:} else
- if Num<1 then
- begin
- MessageDlg ('Invlid number of suggestions.',
- mtInformation, [mbOk], 0);
- FSuggestions := 1;
- end {:} else
- FSuggestions := Num;
- if FSpellWin <> nil then
- FSpellWin.Suggestions := FSuggestions;
- end; { TSpellDlg.SetSuggestions }
-
- procedure TSpellDlg.SetIconSet (IconSet: TAccentSet);
- begin
- FIcons := IconSet;
- if FSpellWin <> nil then
- FSpellWin.SetAccentSet (FIcons);
- end; { TSpellDlg.SetIconSet }
-
- procedure TSpellDlg.SetHelpContext (HelpID: THelpContext);
- {-sets the help context for the spell component}
- begin
- FHelpContext := HelpID;
- if FSpellWin<>nil then
- FSpellWin.HelpContext := FHelpContext;
- end; { TSpellDlg.SetHelpContext }
-
- function TSpellDlg.Open: Boolean;
- {-opens the dictionary and prepares dialog}
- begin
- Result := TRUE; {assume success}
- SkipList := TStringList.Create;
- ReplaceList := TStringList.Create;
- Replacer := TStringList.Create;
- if not OpenDictionary then
- begin
- MessageDlg ('Error opening dictionary '+ FPath + FDictionary,
- mtError, [mbOk], 0);
- Close;
- Result := FALSE;
- end; { if... }
- end; { TSpellDlg.Open }
-
- procedure TSpellDlg.Close;
- {-closes the dictionary and removes the dialog}
- begin
- SkipList.Free;
- ReplaceList.Free;
- Replacer.Free;
- if FSpellWin <> nil then
- FSpellWin.Hide;
- CloseDictionary;
- end; { TSpellDlg.Close }
-
- procedure TSpellDlg.ClearLists;
- {-clears the SkipList, ReplaceList, and Replacer List}
- begin
- SkipList.Clear;
- ReplaceList.Clear;
- Replacer.Clear;
- end; { TSpellDlg.ClearLists }
-
- procedure TSpellDlg.MoveDialog (YPos: integer);
- {-moves the dialog so that it does not highlighted word}
- var
- CenterY: integer;
- begin
- if YPos <> 0 then
- begin
- CenterY := Screen.Height div 2;
- if YPos > CenterY
- then FSpellWin.Top := Margin
- else FSpellWin.Top := Screen.Height - FSpellWin.Height - Margin;
- end; { if... }
- end; { TSpellDlg.MoveDialog }
-
- procedure TSpellDlg.EnableSkipButtons;
- {-enables the skip buttons on the dialog}
- begin
- if FSpellWin <> nil then
- FSpellWin.EnableSkipButtons;
- end; { TSpellDlg.EnableSkipButtons }
-
- procedure TSpellDlg.DisableSkipButtons;
- {-disables the skip buttons on the dialog}
- begin
- if FSpellWin <> nil then
- FSpellWin.DisableSkipButtons;
- end; { TSpellDlg.DisableSkipButtons }
-
- procedure TSpellDlg.Show;
- {-displays the dialog}
- begin
- {Set up window}
- FSpellWin.Left := (Screen.Width div 2) - (FSpellWin.Width div 2);
- if AutoShift then MoveDialog (Margin);
- FSpellWin.Show;
- end; { TSpellDlg.Show }
-
- function TSpellDlg.CheckBuffer (ABuffer: TAbsBuffer): Integer;
- {-checks the buffer}
- var
- WordSt: string; {current word}
- MessageSt: string; {message string}
- CloseWin: Boolean; {TRUE if close window at end}
- NoErrors: Boolean; {TRUE if all words are spelled correctly}
- WinResult: Byte; {Result from ShowModal call}
- WordAdded: Boolean; {TRUE if a word was added}
- WordChanged: Boolean; {TRUE if a word was changed on the memo}
- sModified: Boolean; {saves current Modified status of buffer}
- begin
- Result := mrNone;
- sModified := ABuffer.Modified;
- WordAdded := FALSE;
- WordChanged := FALSE;
- CloseWin := FALSE;
- if not Open then Exit;
- if not FSpellWin.Visible then
- begin
- Show;
- CloseWin := TRUE;
- end {:} else
- if AutoShift then MoveDialog (ABuffer.YPos);
- with ABuffer do
- begin
- {calculate the upper most bounds for the memo}
- {assume entire document for now}
- FSpellWin.SpellDlgResult := mrNone;
- FSpellWin.ClearSuggestList;
- NoErrors := TRUE;
- repeat
- if Modified then
- begin
- WordChanged := TRUE;
- UpdateBuffer;
- MoveBackOneWord;
- Modified := FALSE;
- end; { if... }
- WordSt := GetNextWord;
- if (Length (WordSt) > 1) and (not AllNumbers) and
- (not InDictionary (WordSt)) then
- begin
- FReplaceNum := ReplaceList.IndexOf (LowerCase (WordSt));
- if FReplaceNum <> (-1) then
- begin
- {word in replace list}
- SetSelectedText;
- if AutoShift then MoveDialog (YPos);
- ReplaceWord (Replacer[FReplaceNum]);
- end {:} else
- if SkipList.IndexOf (LowerCase (WordSt)) = (-1) then
- begin
- {word not in skip list}
- NoErrors := FALSE;
- SetSelectedText;
- if AutoShift then MoveDialog (YPos);
- FSpellWin.SetNotFoundPrompt (NotFoundPhrase[FLanguage]);
-
- FSpellWin.SetNotFoundCaption (WordSt);
- FSpellWin.SetEditWord (WordSt);
- Application.ProcessMessages;
- if FAutoSuggest then
- FSpellWin.MakeSuggestions;
- FSpellWin.SpellDlgResult := 0;
- FSpellWin.SetEditAsActive;
- repeat
- if Application.Active then FSpellWin.Show;
- Application.ProcessMessages;
- until (FSpellWin.SpellDlgResult <> 0) or (not FSpellWin.Visible);
- if not FSpellWin.Visible
- then WinResult := mrCancel
- else WinResult := FSpellWin.SpellDlgResult;
- case WinResult of
- mrReplace:
- begin
- WordSt := LowerCase (WordSt);
- if WordSt <> LowerCase (FSpellWin.GetEditWord) then
- begin
- ReplaceWord (FSpellWin.GetEditWord);
- FSpellWin.SetEditWord ('');
- end; { if... }
- end; { Replace }
- mrAdd:
- begin
- {Add to dictionary}
- WordSt := FSpellWin.GetEditWord;
- if not InDictionary (WordSt) then
- begin
- case FLanguage of
- lgEnglish: MessageSt := 'Add "' + WordSt + '" to dictionary?';
- lgSpanish: MessageSt := '┐Quieres a±adir "' + WordSt + '" al diccionario?';
- lgItalian: MessageSt := '┐Quieres a±adir "' + WordSt + '" al diccionario?';
- lgDutch: MessageSt := 'Add "' + WordSt + '" to dictionary?';
- end; { case }
- if MessageDlg (MessageSt, mtConfirmation, [mbYes, mbNo], 0) = mrYes then
- DCT.AddWord (WordSt);
- WordAdded := TRUE;
- end {:} else
- begin
- case FLanguage of
- lgEnglish: MessageSt := '"' + WordSt + '" already in dictionary.';
- lgSpanish: MessageSt := '"' + WordSt + '" ya esta en el diccionario.';
- lgItalian: MessageSt := '┐Quieres a±adir "' + WordSt + '" al diccionario?';
- lgDutch: MessageSt := '"' + WordSt + '" already in dictionary.';
- end; { case }
- MessageDlg (MessageSt, mtInformation, [mbOk], 0);
- end; { else }
- FSpellWin.SetEditAsActive;
- end; { Add }
- mrSkipOnce: {do nothing};
- mrSkipAll:
- begin
- {add word to skiplist}
- WordSt := LowerCase (WordSt);
- SkipList.Add (WordSt);
- end; { SkipAll }
- mrReplaceAll:
- begin
- {add word to replacelist}
- WordSt := LowerCase (WordSt);
- if WordSt <> LowerCase (FSpellWin.GetEditWord) then
- begin
- ReplaceList.Add (WordSt); {the bad word}
- Replacer.Add (FSpellWin.GetEditWord);
- ReplaceWord (FSpellWin.GetEditWord);
- FSpellWin.SetEditWord ('');
- end; { if... }
- end; { ReplaceAll }
- mrCancel:
- begin
- WinResult := mrCancel;
- break;
- end; { Cancel }
- end; { case }
- end; { if... }
- FSpellWin.ClearSuggestList;
- end {:} else
- begin
- FSpellWin.SetNotFoundPrompt (FoundPhrase[FLanguage]);
- FSpellWin.SetNotFoundCaption (WordSt);
- Application.ProcessMessages;
- if FSpellWin.SpellDlgResult = mrCancel then
- begin
- {I said stop!}
- WinResult := mrCancel;
- Break;
- end; { if... }
- end; { else }
- until WordSt='';
- if CloseWin then FSpellWin.Hide;
- Modified := WordChanged or sModified;
- if DCT.Open then DCT.CloseDictionary;
- end; { with }
- if WinResult=mrCancel then
- begin
- MessageSt := AbortedMesg[FLanguage];
- Result := mrCancel;
- end {:} else
- if NoErrors then
- begin
- MessageSt := NoErrorsMesg[FLanguage];
- Result := mrNone;
- end {:} else
- begin
- MessageSt := CompleteMesg[FLanguage];
- Result := mrOk;
- end; { else }
- if CloseWin then
- MessageDlg (MessageSt, mtInformation, [mbOk], 0);
- end; { TSpellDlg.CheckBuffer }
-
- function TSpellDlg.CheckWord (var AWord: String): Integer;
- {-checks the word (see AbsSpell for CheckWord results)}
- var
- LabelSt: string;
- begin
- if not FSpellWin.Visible then
- Open ; {-open current dictionary}
- {Set up window}
- FSpellWin.Left := (Screen.Width div 2) - (FSpellWin.Width div 2);
- {FSpellWin.FormStyle := fsStayOnTop;}
- {if AutoShift then MoveDialog (AMemo);}
- FSpellWin.SetNotFoundCaption (AWord);
- FSpellWin.SetEditWord (AWord);
- if InDictionary (AWord) then
- begin
- FSpellWin.SetNotFoundPrompt (FoundPhrase[FLanguage]);
- end {:} else
- begin
- FSpellWin.SetNotFoundPrompt (NotFoundPhrase[FLanguage]);
- if FAutoSuggest then
- FSpellWin.MakeSuggestions;
- FSpellWin.SpellDlgResult := 0;
- repeat
- Show;
- Application.ProcessMessages;
- until (FSpellWin.SpellDlgResult <> 0) or (not FSpellWin.Visible);
- if not FSpellWin.Visible
- then Result := mrReplace
- else Result := FSpellWin.SpellDlgResult;
- if Result = mrReplace
- then AWord := FSpellWin.GetEditWord;
- end; { else }
- end; { TSpellDlg.CheckWord }
-
- function TSpellDlg.CheckCustomEdit (ACustomEdit: TCustomEdit): Integer;
- var
- CEBuf: TCEBuffer; {buffer manager for memo}
- sSelStart: Longint; {saves the current attributes of Memo}
- sSelLength: Longint; { '' }
- sHideSel: Boolean; { '' }
- begin
- sSelStart := ACustomEdit.SelStart;
- sSelLength := ACustomEdit.SelLength;
- if ACustomEdit is TMemo then
- with ACustomEdit as TMemo do
- begin
- sHideSel := HideSelection;
- HideSelection := FALSE;
- end
- else
- if ACustomEdit is TEdit then
- with ACustomEdit as TEdit do
- begin
- sHideSel := HideSelection;
- HideSelection := FALSE;
- end; { with }
- CEBuf := TCEBuffer.Create (ACustomEdit);
- Result := CheckBuffer (CEBuf);
- CEBuf.Free;
- ACustomEdit.SelStart := sSelStart;
- ACustomEdit.SelLength := sSelLength;
- if ACustomEdit is TMemo then
- with ACustomEdit as TMemo do
- HideSelection := sHideSel
- else
- if ACustomEdit is TEdit then
- with ACustomEdit as TEdit do
- HideSelection := sHideSel;
- end; { TSpellDlg.CheckCustomEdit }
-
- function TSpellDlg.CheckMemo (AMemo: TMemo): Integer;
- begin
- Result := CheckCustomEdit (AMemo);
- end; { TSpellDlg.CheckMemo }
-
- function TSpellDlg.CheckEdit (AnEdit: TEdit): Integer;
- begin
- Result := CheckCustomEdit (AnEdit);
- end; { TSpellDlg.CheckEdit }
-
- {$IFDEF SupportOrpheus}
- function TSpellDlg.CheckOvcEditor (AnOvcEdit: TOvcCustomEditor): Integer;
- {-checks an Orpheus editor component}
- var
- OvcBuf: TOrpheusEditor;
- sLine1, sLine2: Longint;
- sCol1, sCol2: Integer;
- cLine: Longint;
- cCol: Integer;
- sCursorPos: Integer;
- sHideSel: Boolean;
- begin
- with AnOvcEdit do
- begin
- sHideSel := HideSelection; {save hide selection setting}
- HideSelection := FALSE;
- cLine := AnOvcEdit.GetCaretPosition (cCol); {save caret pos}
- GetSelection (sLine1, sCol1, sLine2, sCol2); {save select info}
- OvcBuf := TOrpheusEditor.Create (AnOvcEdit);
- Result := CheckBuffer (OvcBuf);
- OvcBuf.Free;
- {set all settings back}
- SetSelection (sLine1, sCol1, sLine2, sCol2, FALSE);
- SetCaretPosition (cLine, cCol);
- HideSelection := sHideSel;
- end; { with }
- end; { TSpellDlg.CheckOvcEditor }
-
- function TSpellDlg.CheckOvcField (AnOvcField: TOvcBaseEntryField): Integer;
- {-checks an Orpheus field component}
- var
- OvcBuf: TOrpheusField;
- sSelStart: Longint; {saves the current attributes of Field}
- sSelLength: Longint; { '' }
- sHideSel: Boolean; { '' }
- sCursorPos: Longint; { '' }
- begin
- with AnOvcField do {save field attributes}
- begin
- sSelStart := SelectionStart;
- sSelLength := SelectionLength;
- sCursorPos := CurrentPos;
- end; { with }
- OvcBuf := TOrpheusField.Create (AnOvcField);
- Result := CheckBuffer (OvcBuf);
- OvcBuf.Free;
- with AnOvcField do {restore field attributes}
- begin
- SelectionStart := sSelStart;
- SelectionLength := sSelLength;
- CurrentPos := sCursorPos;
- end; { with }
- end; { TSpellDlg.CheckOvcField }
- {$ENDIF}
-
- {$IFDEF SupportTXText}
- function TSpellDlg.CheckTXControl (ATXControl: TTextControl): Integer;
- {-checks a TXTextControl}
- var
- TXBuf: TTXTextBuf; {buffer manager for text control}
- sSelStart: Longint; {saves the current attributes of Memo}
- sSelLength: Longint; { '' }
- sHideSel: Boolean; { '' }
- begin
- sSelStart := ATXControl.SelStart;
- sSelLength := ATXControl.SelLength;
- with ATXControl as TTextControl do
- begin
- sHideSel := HideSelection;
- HideSelection := FALSE;
- end; { with }
- TXBuf := TTXTextBuf.Create (ATXControl);
- Result := CheckBuffer (TXBuf);
- TXBuf.Free;
- ATXControl.SelStart := sSelStart;
- ATXControl.SelLength := sSelLength;
- with ATXControl as TTextControl do
- HideSelection := sHideSel;
- end; { TSpellDlg.CheckTXControl }
- {$ENDIF}
-
- {$IFDEF SupportWPTools}
- function TSpellDlg.CheckWPText (AWPRichText: TWPRichText): Integer;
- {-checks a WPTools RTF Component}
- var
- WPBuf: TWPBuf; {buffer manager for WpTools}
- sSelStart: Longint; {saves the current attributes of Memo}
- sSelLength: Longint; { '' }
- begin
- sSelStart := AWPRichText.SelStart;
- sSelLength := AWPRichText.SelLength;
- WPBuf := TWPBuf.Create (AWPRichText);
- Result := CheckBuffer (WPBuf);
- WPBuf.Free;
- AWPRichText.SelStart := sSelStart;
- AWPRichText.SelLength := sSelLength;
- end; { TSpellDlg.CheckWPText }
- {$ENDIF}
-
- function TSpellDlg.CheckAllFields (AForm: TForm; DisplayMsg: Boolean): Integer;
- {-checks all of the edit fields on the form}
- var
- SpellResult: integer;
- NoErrors: Boolean;
- MessageSt: string;
- i: integer;
- begin
- {find the form's spell dialog}
- SpellResult := mrNone;
- NoErrors := TRUE;
- Open;
- Show;
- for i := 0 to AForm.ComponentCount - 1 do
- begin
- if (AForm.Components[i] is TCustomEdit) then
- SpellResult := CheckCustomEdit (TCustomEdit (AForm.Components[i]))
- {$IFDEF SupportOrpheus}
- else
- if (AForm.Components[i] is TOvcCustomEditor) then
- SpellResult := CheckOvcEditor (TOvcCustomEditor (AForm.Components[i]))
- else
- if (AForm.Components[i] is TOvcBaseEntryField) then
- SpellResult := CheckOvcField (TOvcBaseEntryField (AForm.Components[i]))
- {$ENDIF}
- {$IFDEF SupportTXText}
- else
- if (AForm.Components[i] is TCustomEdit) then
- SpellResult := CheckTXControl (TTextControl (AForm.Components[i]))
- {$ENDIF}
- {$IFDEF SupportWpTools}
- else
- if (AForm.Components[i] is TCustomEdit) then
- SpellResult := CheckWPText (TWPRichText (AForm.Components[i]))
- {$ENDIF};
- if SpellResult = mrCancel then
- Break
- else
- if SpellResult = mrOk then
- NoErrors := FALSE;
- end; { next i }
- Close;
- if (SpellResult = mrNone) and (not NoErrors) then
- SpellResult := mrOk;
- if DisplayMsg then
- begin
- case SpellResult of
- mrNone: MessageSt := NoErrorsMesg[FLanguage];
- mrCancel: MessageSt := AbortedMesg[FLanguage];
- mrOk: MessageSt := CompleteMesg[FLanguage];
- end; { case }
- MessageDlg (MessageSt, mtInformation, [mbOk], 0);
- end; { if... }
- Result := SpellResult;
- end; { TForm1.CheckAllFields }
-
- {---- Word Counters ----}
- procedure TSpellDlg.CustomEdit_WordCount (ACustomEdit: TCustomEdit; var NumWords, UniqueWords: Longint);
- {-returns the number of words in a TCustomEdit}
- var
- CEBuf: TCEBuffer;
- begin
- CEBuf := TCEBuffer.Create (ACustomEdit);
- CEBuf.WordCount (NumWords, UniqueWords);
- CEBuf.Free;
- end; { TSpellDlg.CustomEdit_WordCount }
-
- procedure TSpellDlg.Memo_WordCount (AMemo: TMemo; var NumWords, UniqueWords: Longint);
- {-returns the number of words in a TMemo}
- begin
- CustomEdit_WordCount (AMemo, NumWords, UniqueWords);
- end; { TSpellDlg.Memo_WordCount }
-
- procedure TSpellDlg.Edit_WordCount (AnEdit: TEdit; var NumWords, UniqueWords: Longint);
- {-returns the number of words in a TEdit}
- begin
- CustomEdit_WordCount (AnEdit, NumWords, UniqueWords);
- end; { TSpellDlg.Edit_WordCount }
-
- {$IFDEF SupportOrpheus}
- procedure TSpellDlg.OvcEdit_WordCount (AnOvcEdit: TOvcCustomEditor;
- var NumWords, UniqueWords: Longint);
- {-returns the number of words in a TOvcCustomEditor}
- var
- OvcEditBuf: TOrpheusEditor;
- begin
- OvcEditBuf := TOrpheusEditor.Create (AnOvcEdit);
- OvcEditBuf.WordCount (NumWords, UniqueWords);
- OvcEditBuf.Free;
- end; { TSpellDlg.OvcEdit_WordCount }
-
- procedure TSpellDlg.OvcField_WordCount (AnOvcField: TOvcBaseEntryField;
- var NumWords, UniqueWords: Longint);
- {-returns the number of words in a TOvcBaseEntryField}
- var
- OvcFieldBuf: TOrpheusField;
- begin
- OvcFieldBuf := TOrpheusField.Create (AnOvcField);
- OvcFieldBuf.WordCount (NumWords, UniqueWords);
- OvcFieldBuf.Free;
- end; { TSpellDlg.OvcField_WordCount }
- {$ENDIF}
-
- {$IFDEF SupportTXText}
- procedure TSpellDlg.TXText_WordCount (ATXControl: TTextControl;
- var NumWords, UniqueWords: Longint);
- {-returns the number of words in a TX Text-Control}
- var
- TXBuf: TTXTextBuf;
- begin
- TXBuf := TTXTextBuf.Create (ATXControl);
- TXBuf.WordCount (NumWords, UniqueWords);
- TXBuf.Free;
- end; { TSpellDlg.TXText_WordCount }
- {$ENDIF}
- {---- Internal Routines (No Dialog) ----}
-
- function TSpellDlg.OpenDictionary: Boolean;
- {-opens the dictionary; returns TRUE if successful}
- begin
- Result := TRUE; {assume dictionary opens fine}
- if DictionaryName='' then
- DictionaryName := UpperCase (Dictionaries[DictionaryType] + DCTExt);
- DictionaryPath := UpperCase (DictionaryPath);
- if DictionaryPath = 'APPLICATIONPATH' then
- DictionaryPath := ExtractFilePath (Application.ExeName)
- else
- if Length (DictionaryPath)>0 then
- if DictionaryPath[Length(DictionaryPath)]<>'\' then
- DictionaryPath := DictionaryPath + '\';
- if DCT = nil then
- DCT := TDictionary.Create;
- if not DCT.OpenDictionary (DictionaryPath + DictionaryName,
- UserDictionary) then
- begin
- Result := FALSE;
- DCT.Free;
- DCT := nil;
- end; { if... }
- end; { TSpellDlg.OpenDictionary }
-
- procedure TSpellDlg.CloseDictionary;
- {-closes the dictionary}
- begin
- if DCT <> nil then
- begin
- DCT.CloseDictionary;
- DCT.Free;
- DCT := nil;
- end; { if... }
- end; { TSpellDlg.CloseDictionary }
-
- function TSpellDlg.AddWord (AWord: string): Boolean;
- {-adds a word to the dictionary, returns TRUE if successful}
- begin
- Result := DCT.AddWord (AWord);
- end; { TSpellDlg.AddWord }
-
- function TSpellDlg.InDictionary (AWord: String): Boolean;
- {-checks to see if the word is in the dictionary (no dialog)}
- begin
- Result := DCT.InDictionary (AWord);
- end; { TSpellDlg.InDictionary }
-
- function TSpellDlg.SuggestWords (AWord: String; NumToList: Byte): TStringList;
- {-suggests words}
- begin
- Result := DCT.SuggestWords (AWord, NumToList);
- end; { TSpellDlg.SuggestWords }
-
- procedure Register;
- begin
- RegisterComponents('Domain', [TSpellDlg]);
- end; { Register }
-
- end. { EDSSpell }
-