1 // -*- C++ -*- 2 /** 3 * \file SpellChecker.h 4 * This file is part of LyX, the document processor. 5 * Licence details can be found in the file COPYING. 6 * 7 * \author unknown 8 * \author John Levon 9 * 10 * Full author contact details are available in file CREDITS. 11 */ 12 13 #ifndef SPELL_BASE_H 14 #define SPELL_BASE_H 15 16 #include "support/strfwd.h" 17 18 19 namespace lyx { 20 21 class BufferParams; 22 class Language; 23 class WordLangTuple; 24 class docstring_list; 25 26 /** 27 * Pure virtual base class of all spellchecker implementations. 28 */ 29 class SpellChecker { 30 public: 31 32 /// the result from checking a single word 33 enum Result { 34 /// word is correct 35 WORD_OK = 1, 36 /// root of given word was found 37 ROOT_FOUND, 38 /// word found through compound formation 39 COMPOUND_WORD, 40 /// word not found 41 UNKNOWN_WORD, 42 /// number of other ignored "word" 43 IGNORED_WORD, 44 /// number of personal dictionary "word" 45 LEARNED_WORD, 46 /// missing dictionary for language 47 NO_DICTIONARY 48 }; 49 SpellChecker()50 SpellChecker() : change_number_(0) {} 51 ~SpellChecker()52 virtual ~SpellChecker() {} 53 54 /// does the spell check failed misspelled(Result res)55 static bool misspelled(Result res) { 56 return res != WORD_OK 57 && res != IGNORED_WORD 58 && res != NO_DICTIONARY 59 && res != LEARNED_WORD; } 60 61 /// check the given word of the given lang code and return the result 62 virtual enum Result check(WordLangTuple const &) = 0; 63 64 /// Gives suggestions. 65 virtual void suggest(WordLangTuple const &, docstring_list & suggestions) = 0; 66 67 /// Lemmatizing: return stem of word (used by Thesaurus). 68 virtual void stem(WordLangTuple const &, docstring_list & suggestions) = 0; 69 70 /// insert the given word into the personal dictionary 71 virtual void insert(WordLangTuple const &) = 0; 72 73 /// remove the given word from the personal dictionary 74 virtual void remove(WordLangTuple const &) = 0; 75 76 /// accept the given word temporarily 77 virtual void accept(WordLangTuple const &) = 0; 78 79 /// check if dictionary exists 80 virtual bool hasDictionary(Language const *) const = 0; 81 82 /// how many valid dictionaries were found 83 virtual int numDictionaries() const = 0; 84 85 /// if speller can spell check whole paragraph return true canCheckParagraph()86 virtual bool canCheckParagraph() const { return false; } 87 88 /// count of misspelled words numMisspelledWords()89 virtual int numMisspelledWords() const { return 0; } 90 91 /// start position and length of misspelled word at index misspelledWord(int,int & start,int & length)92 virtual void misspelledWord( 93 int /* index */, 94 int & start, int & length) const 95 { 96 /// index is used here to make the compiler happy 97 start = 0; 98 length = 0; 99 } 100 101 /// give an error message on messy exit 102 virtual docstring const error() = 0; 103 104 /// spell checker state versioning support 105 typedef unsigned long int ChangeNumber ; changeNumber()106 ChangeNumber changeNumber() const { return change_number_; } changeNumber(ChangeNumber value)107 void changeNumber(ChangeNumber value) { change_number_ = value; } nextChangeNumber()108 void nextChangeNumber() { ++change_number_; } 109 virtual void advanceChangeNumber() = 0; 110 111 private: 112 ChangeNumber change_number_; 113 }; 114 115 /// Access to the singleton SpellChecker. 116 /// Implemented in LyX.cpp 117 SpellChecker * theSpellChecker(); 118 119 /// Set the singleton SpellChecker engine. 120 /// Implemented in LyX.cpp 121 void setSpellChecker(); 122 123 } // namespace lyx 124 125 #endif // SPELL_BASE_H 126