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