Back to index

lightning-sunbird  0.9+nobinonly
mozMySpell.h
Go to the documentation of this file.
00001 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
00002 /* ***** BEGIN LICENSE BLOCK *****
00003  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
00004  *
00005  * The contents of this file are subject to the Mozilla Public License Version
00006  * 1.1 (the "License"); you may not use this file except in compliance with
00007  * the License. You may obtain a copy of the License at
00008  * http://www.mozilla.org/MPL/
00009  *
00010  * Software distributed under the License is distributed on an "AS IS" basis,
00011  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
00012  * for the specific language governing rights and limitations under the
00013  * License.
00014  *
00015  * The Original Code is Mozilla Spellchecker Component.
00016  *
00017  * The Initial Developer of the Original Code is
00018  * David Einstein.
00019  * Portions created by the Initial Developer are Copyright (C) 2001
00020  * the Initial Developer. All Rights Reserved.
00021  *
00022  * Contributor(s): David Einstein <Deinst@world.std.com>
00023  *                 Kevin Hendricks <kevin.hendricks@sympatico.ca>
00024  *
00025  * Alternatively, the contents of this file may be used under the terms of
00026  * either the GNU General Public License Version 2 or later (the "GPL"), or
00027  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
00028  * in which case the provisions of the GPL or the LGPL are applicable instead
00029  * of those above. If you wish to allow use of your version of this file only
00030  * under the terms of either the GPL or the LGPL, and not to allow others to
00031  * use your version of this file under the terms of the MPL, indicate your
00032  * decision by deleting the provisions above and replace them with the notice
00033  * and other provisions required by the GPL or the LGPL. If you do not delete
00034  * the provisions above, a recipient may use your version of this file under
00035  * the terms of any one of the MPL, the GPL or the LGPL.
00036  *
00037  *  This spellchecker is based on the MySpell spellchecker made for Open Office
00038  *  by Kevin Hendricks.  Although the algorithms and code, have changed 
00039  *  slightly, the architecture is still the same. The Mozilla implementation
00040  *  is designed to be compatible with the Open Office dictionaries.
00041  *  Please do not make changes to the affix or dictionary file formats 
00042  *  without attempting to coordinate with Kevin.  For more information 
00043  *  on the original MySpell see 
00044  *  http://whiteboard.openoffice.org/source/browse/whiteboard/lingucomponent/source/spellcheck/myspell/
00045  *
00046  *  A special thanks and credit goes to Geoff Kuenning
00047  * the creator of ispell.  MySpell's affix algorithms were
00048  * based on those of ispell which should be noted is
00049  * copyright Geoff Kuenning et.al. and now available
00050  * under a BSD style license. For more information on ispell
00051  * and affix compression in general, please see:
00052  * http://www.cs.ucla.edu/ficus-members/geoff/ispell.html
00053  * (the home page for ispell)
00054  *
00055  * ***** END LICENSE BLOCK ***** */
00056 #ifndef mozMySpell_h__
00057 #define mozMySpell_h__
00058 
00059 #include "myspell.hxx"
00060 #include "mozISpellCheckingEngine.h"
00061 #include "mozIPersonalDictionary.h"
00062 #include "nsString.h"
00063 #include "nsCOMPtr.h"
00064 #include "nsIObserver.h"
00065 #include "nsIUnicodeEncoder.h"
00066 #include "nsIUnicodeDecoder.h"
00067 #include "nsInterfaceHashtable.h"
00068 #include "nsWeakReference.h"
00069 
00070 #define MOZ_MYSPELL_CONTRACTID "@mozilla.org/spellchecker/myspell;1"
00071 #define MOZ_MYSPELL_CID         \
00072 { /* D1EE1205-3F96-4a0f-ABFE-09E8C54C9E9A} */  \
00073 0xD1EE1205, 0x3F96, 0x4a0f,                    \
00074 { 0xAB, 0xFE, 0x09, 0xE8, 0xC5, 0x4C, 0x9E, 0x9A} }
00075 
00076 class mozMySpell : public mozISpellCheckingEngine,
00077                    public nsIObserver,
00078                    public nsSupportsWeakReference
00079 {
00080 public:
00081   NS_DECL_ISUPPORTS
00082   NS_DECL_MOZISPELLCHECKINGENGINE
00083   NS_DECL_NSIOBSERVER
00084 
00085   mozMySpell() : mMySpell(nsnull) { }
00086   virtual ~mozMySpell();
00087 
00088   nsresult Init();
00089 
00090   void LoadDictionaryList();
00091   void LoadDictionariesFromDir(nsIFile* aDir);
00092 
00093   // helper method for converting a word to the charset of the dictionary
00094   nsresult ConvertCharset(const PRUnichar* aStr, char ** aDst);
00095 
00096 protected:
00097  
00098   nsCOMPtr<mozIPersonalDictionary> mPersonalDictionary;
00099   nsCOMPtr<nsIUnicodeEncoder>      mEncoder; 
00100   nsCOMPtr<nsIUnicodeDecoder>      mDecoder; 
00101 
00102   // Hashtable matches dictionary name to .aff file
00103   nsInterfaceHashtable<nsStringHashKey, nsIFile> mDictionaries;
00104   nsString  mDictionary;
00105   nsString  mLanguage;
00106 
00107   MySpell  *mMySpell;
00108 };
00109 
00110 #endif