xref: /aoo41x/main/linguistic/source/spelldsp.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _LINGUISTIC_SPELLDSP_HXX_
29 #define _LINGUISTIC_SPELLDSP_HXX_
30 
31 #include "lngopt.hxx"
32 #include "linguistic/misc.hxx"
33 #include "iprcache.hxx"
34 
35 #include <uno/lbnames.h>			// CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
36 #include <cppuhelper/implbase1.hxx>
37 #include <cppuhelper/implbase2.hxx>
38 #include <cppuhelper/implbase7.hxx>
39 #include <com/sun/star/lang/XComponent.hpp>
40 #include <com/sun/star/lang/XInitialization.hpp>
41 #include <com/sun/star/lang/XServiceDisplayName.hpp>
42 #include <com/sun/star/beans/XPropertySet.hpp>
43 #include <com/sun/star/beans/PropertyValues.hpp>
44 #include <com/sun/star/lang/XServiceInfo.hpp>
45 #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
46 #include <com/sun/star/linguistic2/XSpellChecker.hpp>
47 #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
48 #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
49 
50 #include <boost/shared_ptr.hpp>
51 #include <map>
52 
53 class LngSvcMgr;
54 
55 ///////////////////////////////////////////////////////////////////////////
56 
57 class SpellCheckerDispatcher :
58     public cppu::WeakImplHelper2
59 	<
60         ::com::sun::star::linguistic2::XSpellChecker1,
61         ::com::sun::star::linguistic2::XSpellChecker
62 	>,
63 	public LinguDispatcher
64 {
65     typedef boost::shared_ptr< LangSvcEntries_Spell >               LangSvcEntries_Spell_Ptr_t;
66     typedef std::map< LanguageType, LangSvcEntries_Spell_Ptr_t >    SpellSvcByLangMap_t;
67     SpellSvcByLangMap_t     aSvcMap;
68     LinguOptions            aOpt;
69 
70 	::com::sun::star::uno::Reference<
71 		::com::sun::star::beans::XPropertySet >						xPropSet;
72 	::com::sun::star::uno::Reference<
73 		::com::sun::star::linguistic2::XSearchableDictionaryList >	xDicList;
74 
75 	LngSvcMgr		   			&rMgr;
76     linguistic::SpellCache      *pCache; // Spell Cache (holds known words)
77 
78 	// disallow copy-constructor and assignment-operator for now
79 	SpellCheckerDispatcher(const SpellCheckerDispatcher &);
80 	SpellCheckerDispatcher & operator = (const SpellCheckerDispatcher &);
81 
82     inline linguistic::SpellCache &  GetCache() const;
83 
84 	inline ::com::sun::star::uno::Reference<
85 		::com::sun::star::beans::XPropertySet >
86 			GetPropSet();
87 	inline ::com::sun::star::uno::Reference<
88 		::com::sun::star::linguistic2::XSearchableDictionaryList >
89 			GetDicList();
90 
91 	void	ClearSvcList();
92 
93     sal_Bool    isValid_Impl(const ::rtl::OUString& aWord, LanguageType nLanguage,
94 					const ::com::sun::star::beans::PropertyValues& aProperties,
95 					sal_Bool bCheckDics)
96 				throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException );
97 
98 	::com::sun::star::uno::Reference<
99 		::com::sun::star::linguistic2::XSpellAlternatives >
100             spell_Impl(const ::rtl::OUString& aWord, LanguageType nLanguage,
101 					const ::com::sun::star::beans::PropertyValues& aProperties,
102 					sal_Bool bCheckDics)
103 				throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException );
104 
105 public:
106 	SpellCheckerDispatcher( LngSvcMgr &rLngSvcMgr );
107 	virtual ~SpellCheckerDispatcher();
108 
109 	// XSupportedLocales (for XSpellChecker)
110     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::lang::Locale > SAL_CALL getLocales() throw(::com::sun::star::uno::RuntimeException);
111     virtual sal_Bool SAL_CALL hasLocale( const ::com::sun::star::lang::Locale& aLocale ) throw(::com::sun::star::uno::RuntimeException);
112 
113 	// XSpellChecker
114     virtual sal_Bool SAL_CALL isValid( const ::rtl::OUString& aWord, const ::com::sun::star::lang::Locale& aLocale, const ::com::sun::star::beans::PropertyValues& aProperties ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
115     virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XSpellAlternatives > SAL_CALL spell( const ::rtl::OUString& aWord, const ::com::sun::star::lang::Locale& aLocale, const ::com::sun::star::beans::PropertyValues& aProperties ) throw(::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
116 
117     // XSupportedLanguages
118     virtual ::com::sun::star::uno::Sequence< ::sal_Int16 > SAL_CALL getLanguages(  ) throw (::com::sun::star::uno::RuntimeException);
119     virtual ::sal_Bool SAL_CALL hasLanguage( ::sal_Int16 nLanguage ) throw (::com::sun::star::uno::RuntimeException);
120 
121     // XSpellChecker1
122     virtual ::sal_Bool SAL_CALL isValid( const ::rtl::OUString& aWord, ::sal_Int16 nLanguage, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProperties ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
123     virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XSpellAlternatives > SAL_CALL spell( const ::rtl::OUString& aWord, ::sal_Int16 nLanguage, const ::com::sun::star::uno::Sequence< ::com::sun::star::beans::PropertyValue >& aProperties ) throw (::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::uno::RuntimeException);
124 
125     // LinguDispatcher
126     virtual void SetServiceList( const ::com::sun::star::lang::Locale &rLocale, const ::com::sun::star::uno::Sequence< rtl::OUString > &rSvcImplNames );
127     virtual ::com::sun::star::uno::Sequence< rtl::OUString > GetServiceList( const ::com::sun::star::lang::Locale &rLocale ) const;
128     virtual DspType GetDspType() const;
129 
130     void    FlushSpellCache();
131 };
132 
133 
134 inline linguistic::SpellCache & SpellCheckerDispatcher::GetCache() const
135 {
136     if (!pCache)
137         ((SpellCheckerDispatcher *) this)->pCache = new linguistic::SpellCache();
138     return *pCache;
139 }
140 
141 
142 inline ::com::sun::star::uno::Reference<
143 	::com::sun::star::beans::XPropertySet >
144 		SpellCheckerDispatcher::GetPropSet()
145 {
146 	return xPropSet.is() ?
147 		xPropSet : xPropSet = linguistic::GetLinguProperties();
148 }
149 
150 
151 inline ::com::sun::star::uno::Reference<
152 	::com::sun::star::linguistic2::XSearchableDictionaryList >
153 		SpellCheckerDispatcher::GetDicList()
154 {
155 	return xDicList.is() ?
156 		xDicList : xDicList = linguistic::GetSearchableDictionaryList();
157 }
158 
159 
160 ///////////////////////////////////////////////////////////////////////////
161 
162 #endif
163 
164