xref: /aoo41x/main/linguistic/source/spelldsp.hxx (revision 63ce064a)
1*63ce064aSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*63ce064aSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*63ce064aSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*63ce064aSAndrew Rist  * distributed with this work for additional information
6*63ce064aSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*63ce064aSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*63ce064aSAndrew Rist  * "License"); you may not use this file except in compliance
9*63ce064aSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*63ce064aSAndrew Rist  *
11*63ce064aSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*63ce064aSAndrew Rist  *
13*63ce064aSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*63ce064aSAndrew Rist  * software distributed under the License is distributed on an
15*63ce064aSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*63ce064aSAndrew Rist  * KIND, either express or implied.  See the License for the
17*63ce064aSAndrew Rist  * specific language governing permissions and limitations
18*63ce064aSAndrew Rist  * under the License.
19*63ce064aSAndrew Rist  *
20*63ce064aSAndrew Rist  *************************************************************/
21*63ce064aSAndrew Rist 
22*63ce064aSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _LINGUISTIC_SPELLDSP_HXX_
25cdf0e10cSrcweir #define _LINGUISTIC_SPELLDSP_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "lngopt.hxx"
28cdf0e10cSrcweir #include "linguistic/misc.hxx"
29cdf0e10cSrcweir #include "iprcache.hxx"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <uno/lbnames.h>			// CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
32cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx>
33cdf0e10cSrcweir #include <cppuhelper/implbase2.hxx>
34cdf0e10cSrcweir #include <cppuhelper/implbase7.hxx>
35cdf0e10cSrcweir #include <com/sun/star/lang/XComponent.hpp>
36cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp>
37cdf0e10cSrcweir #include <com/sun/star/lang/XServiceDisplayName.hpp>
38cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp>
39cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValues.hpp>
40cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
41cdf0e10cSrcweir #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
42cdf0e10cSrcweir #include <com/sun/star/linguistic2/XSpellChecker.hpp>
43cdf0e10cSrcweir #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
44cdf0e10cSrcweir #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include <boost/shared_ptr.hpp>
47cdf0e10cSrcweir #include <map>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir class LngSvcMgr;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
52cdf0e10cSrcweir 
53cdf0e10cSrcweir class SpellCheckerDispatcher :
54cdf0e10cSrcweir     public cppu::WeakImplHelper2
55cdf0e10cSrcweir 	<
56cdf0e10cSrcweir         ::com::sun::star::linguistic2::XSpellChecker1,
57cdf0e10cSrcweir         ::com::sun::star::linguistic2::XSpellChecker
58cdf0e10cSrcweir 	>,
59cdf0e10cSrcweir 	public LinguDispatcher
60cdf0e10cSrcweir {
61cdf0e10cSrcweir     typedef boost::shared_ptr< LangSvcEntries_Spell >               LangSvcEntries_Spell_Ptr_t;
62cdf0e10cSrcweir     typedef std::map< LanguageType, LangSvcEntries_Spell_Ptr_t >    SpellSvcByLangMap_t;
63cdf0e10cSrcweir     SpellSvcByLangMap_t     aSvcMap;
64cdf0e10cSrcweir     LinguOptions            aOpt;
65cdf0e10cSrcweir 
66cdf0e10cSrcweir 	::com::sun::star::uno::Reference<
67cdf0e10cSrcweir 		::com::sun::star::beans::XPropertySet >						xPropSet;
68cdf0e10cSrcweir 	::com::sun::star::uno::Reference<
69cdf0e10cSrcweir 		::com::sun::star::linguistic2::XSearchableDictionaryList >	xDicList;
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	LngSvcMgr		   			&rMgr;
72cdf0e10cSrcweir     linguistic::SpellCache      *pCache; // Spell Cache (holds known words)
73cdf0e10cSrcweir 
74cdf0e10cSrcweir 	// disallow copy-constructor and assignment-operator for now
75cdf0e10cSrcweir 	SpellCheckerDispatcher(const SpellCheckerDispatcher &);
76cdf0e10cSrcweir 	SpellCheckerDispatcher & operator = (const SpellCheckerDispatcher &);
77cdf0e10cSrcweir 
78cdf0e10cSrcweir     inline linguistic::SpellCache &  GetCache() const;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir 	inline ::com::sun::star::uno::Reference<
81cdf0e10cSrcweir 		::com::sun::star::beans::XPropertySet >
82cdf0e10cSrcweir 			GetPropSet();
83cdf0e10cSrcweir 	inline ::com::sun::star::uno::Reference<
84cdf0e10cSrcweir 		::com::sun::star::linguistic2::XSearchableDictionaryList >
85cdf0e10cSrcweir 			GetDicList();
86cdf0e10cSrcweir 
87cdf0e10cSrcweir 	void	ClearSvcList();
88cdf0e10cSrcweir 
89cdf0e10cSrcweir     sal_Bool    isValid_Impl(const ::rtl::OUString& aWord, LanguageType nLanguage,
90cdf0e10cSrcweir 					const ::com::sun::star::beans::PropertyValues& aProperties,
91cdf0e10cSrcweir 					sal_Bool bCheckDics)
92cdf0e10cSrcweir 				throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException );
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	::com::sun::star::uno::Reference<
95cdf0e10cSrcweir 		::com::sun::star::linguistic2::XSpellAlternatives >
96cdf0e10cSrcweir             spell_Impl(const ::rtl::OUString& aWord, LanguageType nLanguage,
97cdf0e10cSrcweir 					const ::com::sun::star::beans::PropertyValues& aProperties,
98cdf0e10cSrcweir 					sal_Bool bCheckDics)
99cdf0e10cSrcweir 				throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException );
100cdf0e10cSrcweir 
101cdf0e10cSrcweir public:
102cdf0e10cSrcweir 	SpellCheckerDispatcher( LngSvcMgr &rLngSvcMgr );
103cdf0e10cSrcweir 	virtual ~SpellCheckerDispatcher();
104cdf0e10cSrcweir 
105cdf0e10cSrcweir 	// XSupportedLocales (for XSpellChecker)
106cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::lang::Locale > SAL_CALL getLocales() throw(::com::sun::star::uno::RuntimeException);
107cdf0e10cSrcweir     virtual sal_Bool SAL_CALL hasLocale( const ::com::sun::star::lang::Locale& aLocale ) throw(::com::sun::star::uno::RuntimeException);
108cdf0e10cSrcweir 
109cdf0e10cSrcweir 	// XSpellChecker
110cdf0e10cSrcweir     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);
111cdf0e10cSrcweir     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);
112cdf0e10cSrcweir 
113cdf0e10cSrcweir     // XSupportedLanguages
114cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< ::sal_Int16 > SAL_CALL getLanguages(  ) throw (::com::sun::star::uno::RuntimeException);
115cdf0e10cSrcweir     virtual ::sal_Bool SAL_CALL hasLanguage( ::sal_Int16 nLanguage ) throw (::com::sun::star::uno::RuntimeException);
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     // XSpellChecker1
118cdf0e10cSrcweir     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);
119cdf0e10cSrcweir     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);
120cdf0e10cSrcweir 
121cdf0e10cSrcweir     // LinguDispatcher
122cdf0e10cSrcweir     virtual void SetServiceList( const ::com::sun::star::lang::Locale &rLocale, const ::com::sun::star::uno::Sequence< rtl::OUString > &rSvcImplNames );
123cdf0e10cSrcweir     virtual ::com::sun::star::uno::Sequence< rtl::OUString > GetServiceList( const ::com::sun::star::lang::Locale &rLocale ) const;
124cdf0e10cSrcweir     virtual DspType GetDspType() const;
125cdf0e10cSrcweir 
126cdf0e10cSrcweir     void    FlushSpellCache();
127cdf0e10cSrcweir };
128cdf0e10cSrcweir 
129cdf0e10cSrcweir 
GetCache() const130cdf0e10cSrcweir inline linguistic::SpellCache & SpellCheckerDispatcher::GetCache() const
131cdf0e10cSrcweir {
132cdf0e10cSrcweir     if (!pCache)
133cdf0e10cSrcweir         ((SpellCheckerDispatcher *) this)->pCache = new linguistic::SpellCache();
134cdf0e10cSrcweir     return *pCache;
135cdf0e10cSrcweir }
136cdf0e10cSrcweir 
137cdf0e10cSrcweir 
138cdf0e10cSrcweir inline ::com::sun::star::uno::Reference<
139cdf0e10cSrcweir 	::com::sun::star::beans::XPropertySet >
GetPropSet()140cdf0e10cSrcweir 		SpellCheckerDispatcher::GetPropSet()
141cdf0e10cSrcweir {
142cdf0e10cSrcweir 	return xPropSet.is() ?
143cdf0e10cSrcweir 		xPropSet : xPropSet = linguistic::GetLinguProperties();
144cdf0e10cSrcweir }
145cdf0e10cSrcweir 
146cdf0e10cSrcweir 
147cdf0e10cSrcweir inline ::com::sun::star::uno::Reference<
148cdf0e10cSrcweir 	::com::sun::star::linguistic2::XSearchableDictionaryList >
GetDicList()149cdf0e10cSrcweir 		SpellCheckerDispatcher::GetDicList()
150cdf0e10cSrcweir {
151cdf0e10cSrcweir 	return xDicList.is() ?
152cdf0e10cSrcweir 		xDicList : xDicList = linguistic::GetSearchableDictionaryList();
153cdf0e10cSrcweir }
154cdf0e10cSrcweir 
155cdf0e10cSrcweir 
156cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
157cdf0e10cSrcweir 
158cdf0e10cSrcweir #endif
159cdf0e10cSrcweir 
160