Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_LINGUISTIC_SOURCE_SPELLDSP_HXX
21 : #define INCLUDED_LINGUISTIC_SOURCE_SPELLDSP_HXX
22 :
23 : #include "lngopt.hxx"
24 : #include "linguistic/misc.hxx"
25 : #include "iprcache.hxx"
26 :
27 : #include <cppuhelper/implbase1.hxx>
28 : #include <cppuhelper/implbase2.hxx>
29 : #include <cppuhelper/implbase7.hxx>
30 : #include <com/sun/star/lang/XComponent.hpp>
31 : #include <com/sun/star/lang/XInitialization.hpp>
32 : #include <com/sun/star/lang/XServiceDisplayName.hpp>
33 : #include <com/sun/star/beans/XPropertySet.hpp>
34 : #include <com/sun/star/beans/PropertyValues.hpp>
35 : #include <com/sun/star/lang/XServiceInfo.hpp>
36 : #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
37 : #include <com/sun/star/linguistic2/XSpellChecker.hpp>
38 : #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
39 : #include <com/sun/star/linguistic2/XLinguServiceEventBroadcaster.hpp>
40 :
41 : #include <boost/shared_ptr.hpp>
42 : #include <map>
43 : #include <unotools/charclass.hxx>
44 :
45 : class LngSvcMgr;
46 :
47 :
48 : class SpellCheckerDispatcher :
49 : public cppu::WeakImplHelper2
50 : <
51 : ::com::sun::star::linguistic2::XSpellChecker1,
52 : ::com::sun::star::linguistic2::XSpellChecker
53 : >,
54 : public LinguDispatcher
55 : {
56 : typedef boost::shared_ptr< LangSvcEntries_Spell > LangSvcEntries_Spell_Ptr_t;
57 : typedef std::map< LanguageType, LangSvcEntries_Spell_Ptr_t > SpellSvcByLangMap_t;
58 : SpellSvcByLangMap_t aSvcMap;
59 : LinguOptions aOpt;
60 :
61 : ::com::sun::star::uno::Reference<
62 : ::com::sun::star::linguistic2::XLinguProperties > xPropSet;
63 : ::com::sun::star::uno::Reference<
64 : ::com::sun::star::linguistic2::XSearchableDictionaryList > xDicList;
65 :
66 : LngSvcMgr &rMgr;
67 : mutable linguistic::SpellCache *pCache; // Spell Cache (holds known words)
68 : CharClass * pCharClass;
69 :
70 : SpellCheckerDispatcher(const SpellCheckerDispatcher &) SAL_DELETED_FUNCTION;
71 : SpellCheckerDispatcher & operator = (const SpellCheckerDispatcher &) SAL_DELETED_FUNCTION;
72 :
73 : inline linguistic::SpellCache & GetCache() const;
74 :
75 : inline ::com::sun::star::uno::Reference<
76 : ::com::sun::star::linguistic2::XLinguProperties >
77 : GetPropSet();
78 : inline ::com::sun::star::uno::Reference<
79 : ::com::sun::star::linguistic2::XSearchableDictionaryList >
80 : GetDicList();
81 :
82 : void ClearSvcList();
83 :
84 : bool isValid_Impl(const OUString& aWord, LanguageType nLanguage,
85 : const ::com::sun::star::beans::PropertyValues& aProperties,
86 : bool bCheckDics)
87 : throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException );
88 :
89 : ::com::sun::star::uno::Reference<
90 : ::com::sun::star::linguistic2::XSpellAlternatives >
91 : spell_Impl(const OUString& aWord, LanguageType nLanguage,
92 : const ::com::sun::star::beans::PropertyValues& aProperties,
93 : bool bCheckDics)
94 : throw( ::com::sun::star::uno::RuntimeException, ::com::sun::star::lang::IllegalArgumentException );
95 :
96 : public:
97 : explicit SpellCheckerDispatcher( LngSvcMgr &rLngSvcMgr );
98 : virtual ~SpellCheckerDispatcher();
99 :
100 : // XSupportedLocales (for XSpellChecker)
101 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::lang::Locale > SAL_CALL getLocales() throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
102 : virtual sal_Bool SAL_CALL hasLocale( const ::com::sun::star::lang::Locale& aLocale ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
103 :
104 : // XSpellChecker
105 : virtual sal_Bool SAL_CALL isValid( const 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, std::exception) SAL_OVERRIDE;
106 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XSpellAlternatives > SAL_CALL spell( const 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, std::exception) SAL_OVERRIDE;
107 :
108 : // XSupportedLanguages
109 : virtual ::com::sun::star::uno::Sequence< ::sal_Int16 > SAL_CALL getLanguages( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
110 : virtual sal_Bool SAL_CALL hasLanguage( ::sal_Int16 nLanguage ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
111 :
112 : // XSpellChecker1
113 : virtual sal_Bool SAL_CALL isValid( const 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, std::exception) SAL_OVERRIDE;
114 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::linguistic2::XSpellAlternatives > SAL_CALL spell( const 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, std::exception) SAL_OVERRIDE;
115 :
116 : // LinguDispatcher
117 : virtual void SetServiceList( const ::com::sun::star::lang::Locale &rLocale, const ::com::sun::star::uno::Sequence< OUString > &rSvcImplNames ) SAL_OVERRIDE;
118 : virtual ::com::sun::star::uno::Sequence< OUString > GetServiceList( const ::com::sun::star::lang::Locale &rLocale ) const SAL_OVERRIDE;
119 : virtual DspType GetDspType() const SAL_OVERRIDE;
120 :
121 : void FlushSpellCache();
122 :
123 : private:
124 : void setCharClass(const LanguageTag& rLanguageTag);
125 : static OUString SAL_CALL makeLowerCase(const OUString&, CharClass *);
126 :
127 : };
128 :
129 85384239 : inline linguistic::SpellCache & SpellCheckerDispatcher::GetCache() const
130 : {
131 85384239 : if (!pCache)
132 27 : pCache = new linguistic::SpellCache();
133 85384239 : return *pCache;
134 : }
135 :
136 :
137 : inline ::com::sun::star::uno::Reference<
138 : ::com::sun::star::linguistic2::XLinguProperties >
139 170754619 : SpellCheckerDispatcher::GetPropSet()
140 : {
141 170754619 : return xPropSet.is() ?
142 170754619 : xPropSet : xPropSet = linguistic::GetLinguProperties();
143 : }
144 :
145 :
146 : inline ::com::sun::star::uno::Reference<
147 : ::com::sun::star::linguistic2::XSearchableDictionaryList >
148 85377296 : SpellCheckerDispatcher::GetDicList()
149 : {
150 85377296 : return xDicList.is() ?
151 85377296 : xDicList : xDicList = linguistic::GetDictionaryList();
152 : }
153 :
154 :
155 : #endif
156 :
157 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|