• Main Page
  • Related Pages
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

spell_manager.h

Go to the documentation of this file.
00001 /* AbiSuite
00002  * Copyright (C) 2001 Dom Lachowicz <cinamod@hotmail.com>
00003  *
00004  * This program is free software; you can redistribute it and/or
00005  * modify it under the terms of the GNU General Public License
00006  * as published by the Free Software Foundation; either version 2
00007  * of the License, or (at your option) any later version.
00008  *
00009  * This program is distributed in the hope that it will be useful,
00010  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  * GNU General Public License for more details.
00013  *
00014  * You should have received a copy of the GNU General Public License
00015  * along with this program; if not, write to the Free Software
00016  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017  * 02110-1301 USA.
00018  */
00019 
00020 #ifndef SPELL_MANAGER_H
00021 #define SPELL_MANAGER_H
00022 
00023 /* pre-emptive dismissal; ut_types.h is needed by just about everything,
00024  * so even if it's commented out in-file that's still a lot of work for
00025  * the preprocessor to do...
00026  */
00027 #ifndef UT_TYPES_H
00028 #include "ut_types.h"
00029 #endif
00030 #include "ut_string_class.h"
00031 #include "ut_vector.h"
00032 #include "ut_hash.h"
00033 #include "barbarisms.h"
00034 
00035 // forward declaration
00036 class SpellManager;
00037 
00038 struct DictionaryMapping
00039 {
00040     UT_String lang; // the language tag
00041     UT_String dict; // the dictionary for the tag
00042     UT_String enc;  // the encoding of the dictionary
00043 };
00044 
00045 class ABI_EXPORT SpellChecker
00046 {
00047     friend class SpellManager;
00048 
00049 public:
00050 
00051     enum SpellCheckResult
00052     {
00053         LOOKUP_SUCCEEDED = 0, // looking up the word succeeded
00054         LOOKUP_FAILED = 1,    // could not find the word
00055         LOOKUP_ERROR = 2      // internal error
00056     };
00057 
00058     SpellCheckResult    checkWord(const UT_UCSChar* word, size_t len);
00059     UT_GenericVector<UT_UCSChar*>* suggestWord(const UT_UCSChar* word, size_t len);
00060 
00061     // vector of DictionaryMapping*
00062     virtual UT_Vector & getMapping() {return m_vecEmpty;};
00063     virtual bool doesDictionaryExist (const char * /*szLang*/) {return false;};
00064     virtual bool addToCustomDict (const UT_UCSChar *word, size_t len);
00065 
00066     virtual void correctWord (const UT_UCSChar *toCorrect, size_t toCorrectLen,
00067                               const UT_UCSChar *correct, size_t correctLen);
00068 
00069     virtual void ignoreWord (const UT_UCSChar *toCorrect, size_t toCorrectLen) = 0;
00070 
00071     virtual bool isIgnored (const UT_UCSChar * pWord, size_t len) const = 0;
00072 
00073     const UT_String& getLanguage () const
00074     {
00075         return m_sLanguage;
00076     }
00077 
00078     bool requestDictionary (const char * szLang);
00079     bool isDictionaryFound(void)
00080         { return m_bFoundDictionary;}
00081     void setDictionaryFound(bool b)
00082         { m_bFoundDictionary = b;}
00083 
00084 protected:
00085 
00086     SpellChecker();
00087 
00088     virtual ~SpellChecker();
00089 
00090     void setLanguage (const char * lang)
00091     {
00092         m_sLanguage = lang;
00093     }
00094 
00095     static void couldNotLoadDictionary ( const char * szLang );
00096 
00097     UT_String           m_sLanguage;
00098     BarbarismChecker    m_BarbarismChecker;
00099     UT_Vector           m_vecEmpty;
00100 
00101     bool                m_bIsBarbarism;
00102     bool                m_bIsDictionaryWord;
00103     bool                m_bFoundDictionary;
00104 
00105 private:
00106     SpellChecker(const SpellChecker&);      // no impl
00107     void operator=(const SpellChecker&);    // no impl
00108 
00109     virtual bool                _requestDictionary (const char * szLang) = 0;
00110     virtual SpellCheckResult    _checkWord(const UT_UCSChar* word, size_t len) = 0;
00111     virtual UT_GenericVector<UT_UCSChar*> *_suggestWord(const UT_UCSChar* word, size_t len) = 0;
00112 };
00113 
00114 class ABI_EXPORT SpellManager
00115 {
00116 public:
00117     static SpellManager & instance (void);
00118 
00119     virtual ~SpellManager ();
00120 
00121 
00122     virtual SpellChecker * lastDictionary (void) const;
00123     virtual SpellChecker * requestDictionary (const char * szLang);
00124     UT_uint32 numLoadedDicts () const { return m_nLoadedDicts; }
00125 
00126     SpellChecker *  getInstance() const;
00127 
00128 private:
00129     SpellManager ();
00130     SpellManager ( const SpellManager & other );
00131     SpellManager & operator= ( const SpellManager & other );
00132 
00133 
00134     UT_StringPtrMap m_map;
00135     UT_String m_missingHashs;
00136     SpellChecker * m_lastDict;
00137     UT_uint32 m_nLoadedDicts;
00138 };
00139 
00140 #endif /* SPELL_MANAGER_H */

Generated on Sun Feb 14 2021 for AbiWord by  doxygen 1.7.1