Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _LINGUISTIC_SPELLDSP_HXX_
30 : : #define _LINGUISTIC_SPELLDSP_HXX_
31 : :
32 : : #include "lngopt.hxx"
33 : : #include "linguistic/misc.hxx"
34 : : #include "iprcache.hxx"
35 : :
36 : : #include <uno/lbnames.h> // CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
37 : : #include <cppuhelper/implbase1.hxx>
38 : : #include <cppuhelper/implbase2.hxx>
39 : : #include <cppuhelper/implbase7.hxx>
40 : : #include <com/sun/star/lang/XComponent.hpp>
41 : : #include <com/sun/star/lang/XInitialization.hpp>
42 : : #include <com/sun/star/lang/XServiceDisplayName.hpp>
43 : : #include <com/sun/star/beans/XPropertySet.hpp>
44 : : #include <com/sun/star/beans/PropertyValues.hpp>
45 : : #include <com/sun/star/lang/XServiceInfo.hpp>
46 : : #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
47 : : #include <com/sun/star/linguistic2/XSpellChecker.hpp>
48 : : #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
49 : : #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
50 : :
51 : : #include <boost/shared_ptr.hpp>
52 : : #include <map>
53 : :
54 : : class LngSvcMgr;
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 : : mutable 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 : 42930 : inline linguistic::SpellCache & SpellCheckerDispatcher::GetCache() const
135 : : {
136 [ + + ]: 42930 : if (!pCache)
137 [ + - ]: 40 : pCache = new linguistic::SpellCache();
138 : 42930 : return *pCache;
139 : : }
140 : :
141 : :
142 : : inline ::com::sun::star::uno::Reference<
143 : : ::com::sun::star::beans::XPropertySet >
144 : 64498 : SpellCheckerDispatcher::GetPropSet()
145 : : {
146 : 64498 : return xPropSet.is() ?
147 [ + - ][ + - ]: 64498 : xPropSet : xPropSet = linguistic::GetLinguProperties();
[ + + ][ # # ]
[ + + ]
148 : : }
149 : :
150 : :
151 : : inline ::com::sun::star::uno::Reference<
152 : : ::com::sun::star::linguistic2::XSearchableDictionaryList >
153 : 32229 : SpellCheckerDispatcher::GetDicList()
154 : : {
155 : 32229 : return xDicList.is() ?
156 [ + - ][ + - ]: 32229 : xDicList : xDicList = linguistic::GetSearchableDictionaryList();
[ + + ][ # # ]
[ + + ]
157 : : }
158 : :
159 : :
160 : :
161 : : #endif
162 : :
163 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|