]> git.lyx.org Git - lyx.git/blob - src/SpellChecker.h
listerrors.lyx : Update a link.
[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
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         };
47
48         virtual ~SpellChecker() {}
49
50         /// does the spell check failed
51         static bool misspelled(Result res) {
52                 return res != WORD_OK
53                         && res != IGNORED_WORD
54                         && res != LEARNED_WORD; }
55
56         /// check the given word of the given lang code and return the result
57         virtual enum Result check(WordLangTuple const &) = 0;
58
59         /// Gives suggestions.
60         virtual void suggest(WordLangTuple const &, docstring_list & suggestions) = 0;
61
62         /// insert the given word into the personal dictionary
63         virtual void insert(WordLangTuple const &) = 0;
64
65         /// remove the given word from the personal dictionary
66         virtual void remove(WordLangTuple const &) = 0;
67
68         /// accept the given word temporarily
69         virtual void accept(WordLangTuple const &) = 0;
70
71         /// check if dictionary exists
72         virtual bool hasDictionary(Language const *) const = 0;
73
74         /// if speller can spell check whole paragraph return true
75         virtual bool canCheckParagraph() const { return false; }
76
77         /// count of misspelled words
78         virtual int numMisspelledWords() const { return 0; }
79
80         /// start position and length of misspelled word at index
81         virtual void misspelledWord(
82                 int /* index */,
83                 int & start, int & length) const
84         {
85                 /// index is used here to make the compiler happy
86                 start = 0;
87                 length = 0;
88         }
89
90         /// give an error message on messy exit
91         virtual docstring const error() = 0;
92
93         /// spell checker state versioning support
94         typedef unsigned long int ChangeNumber ;
95         ChangeNumber changeNumber() const { return change_number_; }
96         void changeNumber(ChangeNumber value) { change_number_ = value; }
97         void nextChangeNumber() { ++change_number_; }
98         virtual void advanceChangeNumber() = 0;
99
100 private:
101         ChangeNumber change_number_;
102 };
103
104 /// Access to the singleton SpellChecker.
105 /// Implemented in LyX.cpp
106 SpellChecker * theSpellChecker();
107
108 /// Set the singleton SpellChecker engine.
109 /// Implemented in LyX.cpp
110 void setSpellChecker();
111
112 } // namespace lyx
113
114 #endif // SPELL_BASE_H