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