diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2006-06-09 06:48:29 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2006-06-09 06:48:29 +0800 |
commit | 6d84e196d76acdcc56908bc8ec1484f8e3d614b6 (patch) | |
tree | 9c5cc5a936b08273d9bda4d97c616cc2b91362d6 /embed/mozilla | |
parent | 5d74d2227e45c916bbe44289684737a49b2e3c77 (diff) | |
download | gsoc2013-epiphany-6d84e196d76acdcc56908bc8ec1484f8e3d614b6.tar gsoc2013-epiphany-6d84e196d76acdcc56908bc8ec1484f8e3d614b6.tar.gz gsoc2013-epiphany-6d84e196d76acdcc56908bc8ec1484f8e3d614b6.tar.bz2 gsoc2013-epiphany-6d84e196d76acdcc56908bc8ec1484f8e3d614b6.tar.lz gsoc2013-epiphany-6d84e196d76acdcc56908bc8ec1484f8e3d614b6.tar.xz gsoc2013-epiphany-6d84e196d76acdcc56908bc8ec1484f8e3d614b6.tar.zst gsoc2013-epiphany-6d84e196d76acdcc56908bc8ec1484f8e3d614b6.zip |
Check for enchant, and output an overview of the configured options on
2006-06-09 Christian Persch <chpe@cvs.gnome.org>
* configure.ac:
Check for enchant, and output an overview of the configured
options on successful configure.
* data/default-prefs-common.js:
* embed/mozilla/GeckoSpellCheckEngine.cpp:
* embed/mozilla/GeckoSpellCheckEngine.h:
* embed/mozilla/Makefile.am:
* embed/mozilla/MozRegisterComponents.cpp:
* lib/Makefile.am:
* lib/ephy-spell-check.c:
* lib/ephy-spell-check.h:
Spell check support using the gecko 'spellchecker' extension.
No corrections context menu or language switching yet.
Diffstat (limited to 'embed/mozilla')
-rw-r--r-- | embed/mozilla/GeckoSpellCheckEngine.cpp | 201 | ||||
-rw-r--r-- | embed/mozilla/GeckoSpellCheckEngine.h | 52 | ||||
-rw-r--r-- | embed/mozilla/Makefile.am | 7 | ||||
-rw-r--r-- | embed/mozilla/MozRegisterComponents.cpp | 16 |
4 files changed, 276 insertions, 0 deletions
diff --git a/embed/mozilla/GeckoSpellCheckEngine.cpp b/embed/mozilla/GeckoSpellCheckEngine.cpp new file mode 100644 index 000000000..ef652c0d4 --- /dev/null +++ b/embed/mozilla/GeckoSpellCheckEngine.cpp @@ -0,0 +1,201 @@ +/* + * Copyright (C) 2006 Christian Persch + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + */ + +#include "mozilla-config.h" +#include "config.h" + +//#include <bonobo.h> +#include <stdio.h> +#include <stdlib.h> + +#include <nsStringAPI.h> + +#include <mozIPersonalDictionary.h> +#include <nsMemory.h> + +#include "ephy-debug.h" + +#include "GeckoSpellCheckEngine.h" + +GeckoSpellCheckEngine::GeckoSpellCheckEngine () +{ + LOG ("GeckoSpellCheckEngine ctor [%p]", (void*) this); + mSpeller = ephy_spell_check_get_default (); +} + +GeckoSpellCheckEngine::~GeckoSpellCheckEngine () +{ + LOG ("GeckoSpellCheckEngine dtor [%p]", (void*) this); + g_object_unref (mSpeller); +} + +NS_IMPL_ISUPPORTS1 (GeckoSpellCheckEngine, + mozISpellCheckingEngine) + +/* nsISpellCheckEngine implementation */ + +/* attribute wstring dictionary; */ +NS_IMETHODIMP GeckoSpellCheckEngine::GetDictionary (PRUnichar * *aDictionary) +{ + /* Gets the identifier of the current dictionary */ + char *code = ephy_spell_check_get_language (mSpeller); + if (!code) { + return NS_ERROR_FAILURE; + } + + *aDictionary = ToNewUnicode (NS_ConvertUTF8toUTF16 (code)); + g_free (code); + + return NS_OK; +} + +NS_IMETHODIMP GeckoSpellCheckEngine::SetDictionary (const PRUnichar * aDictionary) +{ + return NS_OK; +} + +/* readonly attribute wstring language; */ +NS_IMETHODIMP GeckoSpellCheckEngine::GetLanguage (PRUnichar * *aLanguage) +{ + /* Gets the identifier of the current dictionary */ + char *code = ephy_spell_check_get_language (mSpeller); + if (!code) { + return NS_ERROR_FAILURE; + } + + *aLanguage = ToNewUnicode (NS_ConvertUTF8toUTF16 (code)); + g_free (code); + + return NS_OK; +} + +/* readonly attribute boolean providesPersonalDictionary; */ +NS_IMETHODIMP GeckoSpellCheckEngine::GetProvidesPersonalDictionary (PRBool *aProvidesPersonalDictionary) +{ + *aProvidesPersonalDictionary = PR_FALSE; + return NS_OK; +} + +/* readonly attribute boolean providesWordUtils; */ +NS_IMETHODIMP GeckoSpellCheckEngine::GetProvidesWordUtils (PRBool *aProvidesWordUtils) +{ + *aProvidesWordUtils = PR_FALSE; + return NS_OK; +} + +/* readonly attribute wstring name; */ +NS_IMETHODIMP GeckoSpellCheckEngine::GetName (PRUnichar * *aName) +{ + /* It's fine to leave this unimplemented */ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* readonly attribute wstring copyright; */ +NS_IMETHODIMP GeckoSpellCheckEngine::GetCopyright (PRUnichar * *aCopyright) +{ + /* It's fine to leave this unimplemented */ + return NS_ERROR_NOT_IMPLEMENTED; +} + +/* attribute mozIPersonalDictionary personalDictionary; */ +NS_IMETHODIMP GeckoSpellCheckEngine::GetPersonalDictionary (mozIPersonalDictionary * *aPersonalDictionary) +{ + NS_IF_ADDREF (*aPersonalDictionary = mPersonalDictionary); + return NS_OK; +} + +NS_IMETHODIMP GeckoSpellCheckEngine::SetPersonalDictionary (mozIPersonalDictionary * aPersonalDictionary) +{ + mPersonalDictionary = aPersonalDictionary; + return NS_OK; +} + +/* void getDictionaryList ([array, size_is (count)] out wstring dictionaries, out PRUint32 count); */ +NS_IMETHODIMP +GeckoSpellCheckEngine::GetDictionaryList (PRUnichar ***_dictionaries, + PRUint32 *_count) +{ + *_count = 1; + *_dictionaries = (PRUnichar **)nsMemory::Alloc(sizeof(PRUnichar *)); // only one entry + *_dictionaries[0] = ToNewUnicode (NS_LITERAL_STRING ("en")); + return NS_OK; +} + +/* boolean check (in wstring word); */ +NS_IMETHODIMP GeckoSpellCheckEngine::Check (const PRUnichar *word, + PRBool *_retval) +{ + NS_ENSURE_STATE (mSpeller); + NS_ENSURE_ARG (word); + + NS_ConvertUTF16toUTF8 converted (word); + + gboolean correct = FALSE; + if (!ephy_spell_check_check_word (mSpeller, + converted.get (), + converted.Length (), + &correct)) + return NS_ERROR_FAILURE; + + *_retval = correct != FALSE; + + return NS_OK; +} + +/* void suggest (in wstring word, [array, size_is (count)] out wstring suggestions, out PRUint32 count); */ +NS_IMETHODIMP GeckoSpellCheckEngine::Suggest (const PRUnichar *word, + PRUnichar ***_suggestions, + PRUint32 *_count) +{ +#if 0 + NS_ENSURE_STATE (mSpeller); + NS_ENSURE_ARG (word); + + NS_ConvertUTF16toUTF8 converted (word); + + gsize count; + char **suggestions = ephy_spell_check_get_suggestions (mSpeller, + converted.get (), + converted.Length (), + &count); + + *_count = count; + *_suggestions = nsnull; + + PRUnichar **array = nsnull; + if (count > 0) { + NS_ASSERTION (suggestions, "Count > 0 but suggestions are NULL?"); + array = (PRUnichar **) nsMemory::Alloc (count * sizeof (PRUnichar *)); + if (array) { + *_suggestions = array; + + for (gsize i = 0; i < count; ++i) { + NS_ConvertUTF8toUTF16 sugg (suggestions[i]); + array[i] = ToNewUnicode (sugg); + } + } + + ephy_spell_check_free_suggestions (mSpeller, suggestions); + } + + return array ? NS_OK : NS_ERROR_OUT_OF_MEMORY; +#endif + return NS_ERROR_NOT_IMPLEMENTED; +} diff --git a/embed/mozilla/GeckoSpellCheckEngine.h b/embed/mozilla/GeckoSpellCheckEngine.h new file mode 100644 index 000000000..d31e93603 --- /dev/null +++ b/embed/mozilla/GeckoSpellCheckEngine.h @@ -0,0 +1,52 @@ +/* + * Copyright (C) 2006 Christian Persch + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation; either version 2.1, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * $Id$ + */ + +#ifndef GECKO_SPELL_CHECK_ENGINE_H +#define GECKO_SPELL_CHECK_ENGINE_H + +#include <nsCOMPtr.h> +#include <mozISpellCheckingEngine.h> + +#include "ephy-spell-check.h" + +class mozIPersonalDictionary; + +/* 26948b8b-d136-4a78-a9c5-3a145812b649 */ +#define GECKO_SPELL_CHECK_ENGINE_IID \ +{ 0x26948b8b, 0xd136, 0x4a78, { 0xa9, 0xc5, 0x3a, 0x14, 0x58, 0x12, 0xb6, 0x49 } } + +#define GECKO_SPELL_CHECK_ENGINE_CONTRACTID "@mozilla.org/spellchecker/myspell;1" +#define GECKO_SPELL_CHECK_ENGINE_CLASSNAME "Gecko Print Settings" + +class GeckoSpellCheckEngine : public mozISpellCheckingEngine +{ + public: + GeckoSpellCheckEngine(); + virtual ~GeckoSpellCheckEngine(); + + NS_DECL_ISUPPORTS + NS_DECL_MOZISPELLCHECKINGENGINE + + private: + nsCOMPtr<mozIPersonalDictionary> mPersonalDictionary; + EphySpellCheck *mSpeller; +}; + +#endif /* GECKO_SPELL_CHECK_ENGINE_H */ diff --git a/embed/mozilla/Makefile.am b/embed/mozilla/Makefile.am index 2e0063272..2e25a2a27 100644 --- a/embed/mozilla/Makefile.am +++ b/embed/mozilla/Makefile.am @@ -82,6 +82,12 @@ libephymozillaembed_la_SOURCES += \ mozilla-x509-cert.h endif +if ENABLE_SPELLCHECKER +libephymozillaembed_la_SOURCES += \ + GeckoSpellCheckEngine.cpp \ + GeckoSpellCheckEngine.h +endif + mozilla_include_subdirs = \ . \ caps \ @@ -111,6 +117,7 @@ mozilla_include_subdirs = \ pref \ shistory \ sidebar \ + spellchecker \ uriloader \ uconv \ wallet \ diff --git a/embed/mozilla/MozRegisterComponents.cpp b/embed/mozilla/MozRegisterComponents.cpp index 6c76541a2..b2fb94b02 100644 --- a/embed/mozilla/MozRegisterComponents.cpp +++ b/embed/mozilla/MozRegisterComponents.cpp @@ -61,6 +61,10 @@ #include "FilePicker.h" #endif +#ifdef ENABLE_SPELLCHECKER +#include "GeckoSpellCheckEngine.h" +#endif + #ifdef HAVE_MOZILLA_PSM #include "GtkNSSClientAuthDialogs.h" #include "GtkNSSDialogs.h" @@ -81,6 +85,10 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(MozGlobalHistory) NS_GENERIC_FACTORY_CONSTRUCTOR(GFilePicker) #endif +#ifdef ENABLE_SPELLCHECKER +NS_GENERIC_FACTORY_CONSTRUCTOR(GeckoSpellCheckEngine) +#endif + #ifdef HAVE_MOZILLA_PSM NS_GENERIC_FACTORY_CONSTRUCTOR(GtkNSSClientAuthDialogs) NS_GENERIC_FACTORY_CONSTRUCTOR(GtkNSSDialogs) @@ -246,6 +254,14 @@ static const nsModuleComponentInfo sAppComps[] = { EphyPromptServiceConstructor }, #endif /* HAVE_NSINONBLOCKINGALERTSERVICE_H */ +#ifdef ENABLE_SPELLCHECKER + { + GECKO_SPELL_CHECK_ENGINE_CLASSNAME, + GECKO_SPELL_CHECK_ENGINE_IID, + GECKO_SPELL_CHECK_ENGINE_CONTRACTID, + GeckoSpellCheckEngineConstructor + } +#endif /* ENABLE_SPELLCHECK */ }; gboolean |