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