1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #ifndef INCLUDED_LINGUISTIC_SOURCE_SPELLDSP_HXX
21 #define INCLUDED_LINGUISTIC_SOURCE_SPELLDSP_HXX
24 #include <linguistic/misc.hxx>
25 #include <iprcache.hxx>
27 #include <cppuhelper/implbase.hxx>
28 #include <com/sun/star/beans/PropertyValues.hpp>
29 #include <com/sun/star/linguistic2/XSpellChecker1.hpp>
30 #include <com/sun/star/linguistic2/XSpellChecker.hpp>
31 #include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
35 #include <unotools/charclass.hxx>
40 class SpellCheckerDispatcher
:
41 public cppu::WeakImplHelper
43 css::linguistic2::XSpellChecker1
,
44 css::linguistic2::XSpellChecker
46 public LinguDispatcher
48 typedef std::shared_ptr
< LangSvcEntries_Spell
> LangSvcEntries_Spell_Ptr_t
;
49 typedef std::map
< LanguageType
, LangSvcEntries_Spell_Ptr_t
> SpellSvcByLangMap_t
;
50 SpellSvcByLangMap_t m_aSvcMap
;
52 css::uno::Reference
< css::linguistic2::XLinguProperties
> m_xPropSet
;
53 css::uno::Reference
< css::linguistic2::XSearchableDictionaryList
> m_xDicList
;
56 mutable std::unique_ptr
<linguistic::SpellCache
> m_pCache
; // Spell Cache (holds known words)
57 std::unique_ptr
<CharClass
> m_pCharClass
;
59 SpellCheckerDispatcher(const SpellCheckerDispatcher
&) = delete;
60 SpellCheckerDispatcher
& operator = (const SpellCheckerDispatcher
&) = delete;
62 inline linguistic::SpellCache
& GetCache() const;
64 inline const css::uno::Reference
< css::linguistic2::XLinguProperties
> &
66 inline const css::uno::Reference
< css::linguistic2::XSearchableDictionaryList
> &
69 /// @throws css::uno::RuntimeException
70 /// @throws css::lang::IllegalArgumentException
71 bool isValid_Impl(const OUString
& aWord
, LanguageType nLanguage
,
72 const css::beans::PropertyValues
& aProperties
);
74 /// @throws css::uno::RuntimeException
75 /// @throws css::lang::IllegalArgumentException
77 css::linguistic2::XSpellAlternatives
>
78 spell_Impl(const OUString
& aWord
, LanguageType nLanguage
,
79 const css::beans::PropertyValues
& aProperties
);
82 explicit SpellCheckerDispatcher( LngSvcMgr
&rLngSvcMgr
);
83 virtual ~SpellCheckerDispatcher() override
;
85 // XSupportedLocales (for XSpellChecker)
86 virtual css::uno::Sequence
< css::lang::Locale
> SAL_CALL
getLocales() override
;
87 virtual sal_Bool SAL_CALL
hasLocale( const css::lang::Locale
& aLocale
) override
;
90 virtual sal_Bool SAL_CALL
isValid( const OUString
& aWord
, const css::lang::Locale
& aLocale
, const css::uno::Sequence
< ::css::beans::PropertyValue
>& aProperties
) override
;
91 virtual css::uno::Reference
< css::linguistic2::XSpellAlternatives
> SAL_CALL
spell( const OUString
& aWord
, const css::lang::Locale
& aLocale
, const css::uno::Sequence
< ::css::beans::PropertyValue
>& aProperties
) override
;
93 // XSupportedLanguages
94 virtual css::uno::Sequence
< ::sal_Int16
> SAL_CALL
getLanguages( ) override
;
95 virtual sal_Bool SAL_CALL
hasLanguage( ::sal_Int16 nLanguage
) override
;
98 virtual sal_Bool SAL_CALL
isValid( const OUString
& aWord
, ::sal_Int16 nLanguage
, const css::uno::Sequence
< css::beans::PropertyValue
>& aProperties
) override
;
99 virtual css::uno::Reference
< css::linguistic2::XSpellAlternatives
> SAL_CALL
spell( const OUString
& aWord
, ::sal_Int16 nLanguage
, const css::uno::Sequence
< css::beans::PropertyValue
>& aProperties
) override
;
102 virtual void SetServiceList( const css::lang::Locale
&rLocale
, const css::uno::Sequence
< OUString
> &rSvcImplNames
) override
;
103 virtual css::uno::Sequence
< OUString
> GetServiceList( const css::lang::Locale
&rLocale
) const override
;
105 void FlushSpellCache();
108 void setCharClass(const LanguageTag
& rLanguageTag
);
109 static OUString
makeLowerCase(const OUString
&, CharClass
const *);
113 inline linguistic::SpellCache
& SpellCheckerDispatcher::GetCache() const
116 m_pCache
.reset(new linguistic::SpellCache());
121 inline const css::uno::Reference
< css::linguistic2::XLinguProperties
> &
122 SpellCheckerDispatcher::GetPropSet()
124 if (!m_xPropSet
.is())
125 m_xPropSet
= linguistic::GetLinguProperties();
130 inline const css::uno::Reference
< css::linguistic2::XSearchableDictionaryList
> &
131 SpellCheckerDispatcher::GetDicList()
133 if (!m_xDicList
.is())
134 m_xDicList
= linguistic::GetDictionaryList();
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */