| 1 |
/* AbiSuite |
| 2 |
* Copyright (C) 2001 Dom Lachowicz <[email protected]> |
| 3 |
* |
| 4 |
* This program is free software; you can redistribute it and/or |
| 5 |
* modify it under the terms of the GNU General Public License |
| 6 |
* as published by the Free Software Foundation; either version 2 |
| 7 |
* of the License, or (at your option) any later version. |
| 8 |
* |
| 9 |
* This program is distributed in the hope that it will be useful, |
| 10 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 |
* GNU General Public License for more details. |
| 13 |
* |
| 14 |
* You should have received a copy of the GNU General Public License |
| 15 |
* along with this program; if not, write to the Free Software |
| 16 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
| 17 |
* 02110-1301 USA. |
| 18 |
*/ |
| 19 |
|
| 20 |
#ifndef SPELL_MANAGER_H |
| 21 |
#define SPELL_MANAGER_H |
| 22 |
|
| 23 |
/* pre-emptive dismissal; ut_types.h is needed by just about everything, |
| 24 |
* so even if it's commented out in-file that's still a lot of work for |
| 25 |
* the preprocessor to do... |
| 26 |
*/ |
| 27 |
#ifndef UT_TYPES_H |
| 28 |
#include "ut_types.h" |
| 29 |
#endif |
| 30 |
#include "ut_string_class.h" |
| 31 |
#include "ut_vector.h" |
| 32 |
#include "ut_hash.h" |
| 33 |
#include "barbarisms.h" |
| 34 |
|
| 35 |
// forward declaration |
| 36 |
class SpellManager; |
| 37 |
|
| 38 |
struct DictionaryMapping |
| 39 |
{ |
| 40 |
UT_String lang; // the language tag |
| 41 |
UT_String dict; // the dictionary for the tag |
| 42 |
UT_String enc; // the encoding of the dictionary |
| 43 |
}; |
| 44 |
|
| 45 |
class ABI_EXPORT SpellChecker |
| 46 |
{ |
| 47 |
friend class SpellManager; |
| 48 |
|
| 49 |
public: |
| 50 |
|
| 51 |
enum SpellCheckResult |
| 52 |
{ |
| 53 |
LOOKUP_SUCCEEDED = 0, // looking up the word succeeded |
| 54 |
LOOKUP_FAILED = 1, // could not find the word |
| 55 |
LOOKUP_ERROR = 2 // internal error |
| 56 |
}; |
| 57 |
|
| 58 |
SpellCheckResult checkWord(const UT_UCSChar* word, size_t len); |
| 59 |
UT_GenericVector<UT_UCSChar*>* suggestWord(const UT_UCSChar* word, size_t len); |
| 60 |
|
| 61 |
// vector of DictionaryMapping* |
| 62 |
virtual UT_Vector & getMapping() {return m_vecEmpty;}; |
| 63 |
virtual bool doesDictionaryExist (const char * /*szLang*/) {return false;}; |
| 64 |
virtual bool addToCustomDict (const UT_UCSChar *word, size_t len); |
| 65 |
|
| 66 |
virtual void correctWord (const UT_UCSChar *toCorrect, size_t toCorrectLen, |
| 67 |
const UT_UCSChar *correct, size_t correctLen); |
| 68 |
|
| 69 |
virtual void ignoreWord (const UT_UCSChar *toCorrect, size_t toCorrectLen) = 0; |
| 70 |
|
| 71 |
virtual bool isIgnored (const UT_UCSChar * pWord, size_t len) const = 0; |
| 72 |
|
| 73 |
const UT_String& getLanguage () const |
| 74 |
{ |
| 75 |
return m_sLanguage; |
| 76 |
} |
| 77 |
|
| 78 |
bool requestDictionary (const char * szLang); |
| 79 |
bool isDictionaryFound(void) |
| 80 |
{ return m_bFoundDictionary;} |
| 81 |
void setDictionaryFound(bool b) |
| 82 |
{ m_bFoundDictionary = b;} |
| 83 |
|
| 84 |
protected: |
| 85 |
|
| 86 |
SpellChecker(); |
| 87 |
|
| 88 |
virtual ~SpellChecker(); |
| 89 |
|
| 90 |
void setLanguage (const char * lang) |
| 91 |
{ |
| 92 |
m_sLanguage = lang; |
| 93 |
} |
| 94 |
|
| 95 |
static void couldNotLoadDictionary ( const char * szLang ); |
| 96 |
|
| 97 |
UT_String m_sLanguage; |
| 98 |
BarbarismChecker m_BarbarismChecker; |
| 99 |
UT_Vector m_vecEmpty; |
| 100 |
|
| 101 |
bool m_bIsBarbarism; |
| 102 |
bool m_bIsDictionaryWord; |
| 103 |
bool m_bFoundDictionary; |
| 104 |
|
| 105 |
private: |
| 106 |
SpellChecker(const SpellChecker&); // no impl |
| 107 |
void operator=(const SpellChecker&); // no impl |
| 108 |
|
| 109 |
virtual bool _requestDictionary (const char * szLang) = 0; |
| 110 |
virtual SpellCheckResult _checkWord(const UT_UCSChar* word, size_t len) = 0; |
| 111 |
virtual UT_GenericVector<UT_UCSChar*> *_suggestWord(const UT_UCSChar* word, size_t len) = 0; |
| 112 |
}; |
| 113 |
|
| 114 |
class ABI_EXPORT SpellManager |
| 115 |
{ |
| 116 |
public: |
| 117 |
static SpellManager & instance (void); |
| 118 |
|
| 119 |
virtual ~SpellManager (); |
| 120 |
|
| 121 |
|
| 122 |
virtual SpellChecker * lastDictionary (void) const; |
| 123 |
virtual SpellChecker * requestDictionary (const char * szLang); |
| 124 |
UT_uint32 numLoadedDicts () const { return m_nLoadedDicts; } |
| 125 |
|
| 126 |
SpellChecker * getInstance() const; |
| 127 |
|
| 128 |
private: |
| 129 |
SpellManager (); |
| 130 |
SpellManager ( const SpellManager & other ); |
| 131 |
SpellManager & operator= ( const SpellManager & other ); |
| 132 |
|
| 133 |
|
| 134 |
UT_StringPtrMap m_map; |
| 135 |
UT_String m_missingHashs; |
| 136 |
SpellChecker * m_lastDict; |
| 137 |
UT_uint32 m_nLoadedDicts; |
| 138 |
}; |
| 139 |
|
| 140 |
#endif /* SPELL_MANAGER_H */ |