LibreOffice Module linguistic (master) 1
spelldsp.hxx
Go to the documentation of this file.
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#pragma once
21
22#include "defs.hxx"
23#include <linguistic/misc.hxx>
24#include <iprcache.hxx>
25
27#include <com/sun/star/beans/PropertyValues.hpp>
28#include <com/sun/star/linguistic2/XSpellChecker1.hpp>
29#include <com/sun/star/linguistic2/XSpellChecker.hpp>
30#include <com/sun/star/linguistic2/XSearchableDictionaryList.hpp>
31
32#include <map>
33#include <memory>
34#include <optional>
36
37class LngSvcMgr;
38
39
41 public cppu::WeakImplHelper
42 <
43 css::linguistic2::XSpellChecker1,
44 css::linguistic2::XSpellChecker
45 >,
46 public LinguDispatcher
47{
48 typedef std::shared_ptr< LangSvcEntries_Spell > LangSvcEntries_Spell_Ptr_t;
49 typedef std::map< LanguageType, LangSvcEntries_Spell_Ptr_t > SpellSvcByLangMap_t;
51
52 css::uno::Reference< css::linguistic2::XLinguProperties > m_xPropSet;
53 css::uno::Reference< css::linguistic2::XSearchableDictionaryList > m_xDicList;
54
56 mutable std::unique_ptr<linguistic::SpellCache> m_pCache; // Spell Cache (holds known words)
57 std::optional<CharClass> m_oCharClass;
58
61
62 inline linguistic::SpellCache & GetCache() const;
63
64 inline const css::uno::Reference< css::linguistic2::XLinguProperties > &
65 GetPropSet();
66 inline const css::uno::Reference< css::linguistic2::XSearchableDictionaryList > &
67 GetDicList();
68
71 bool isValid_Impl(const OUString& aWord, LanguageType nLanguage,
72 const css::beans::PropertyValues& aProperties);
73
76 css::uno::Reference<
77 css::linguistic2::XSpellAlternatives >
78 spell_Impl(const OUString& aWord, LanguageType nLanguage,
79 const css::beans::PropertyValues& aProperties);
80
81public:
82 explicit SpellCheckerDispatcher( LngSvcMgr &rLngSvcMgr );
83 virtual ~SpellCheckerDispatcher() override;
84
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;
88
89 // XSpellChecker
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;
92
93 // XSupportedLanguages
94 virtual css::uno::Sequence< ::sal_Int16 > SAL_CALL getLanguages( ) override;
95 virtual sal_Bool SAL_CALL hasLanguage( ::sal_Int16 nLanguage ) override;
96
97 // XSpellChecker1
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;
100
101 // LinguDispatcher
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;
104
105 void FlushSpellCache();
106
107private:
108 void setCharClass(const LanguageTag& rLanguageTag);
109 static OUString makeLowerCase(const OUString&, const std::optional<CharClass> &);
110
111};
112
114{
115 if (!m_pCache)
116 m_pCache.reset(new linguistic::SpellCache());
117 return *m_pCache;
118}
119
120
121inline const css::uno::Reference< css::linguistic2::XLinguProperties > &
123{
124 if (!m_xPropSet.is())
126 return m_xPropSet;
127}
128
129
130inline const css::uno::Reference< css::linguistic2::XSearchableDictionaryList > &
132{
133 if (!m_xDicList.is())
135 return m_xDicList;
136}
137
138/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< LangSvcEntries_Spell > LangSvcEntries_Spell_Ptr_t
Definition: spelldsp.hxx:48
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
virtual void SetServiceList(const css::lang::Locale &rLocale, const css::uno::Sequence< OUString > &rSvcImplNames) override
Definition: spelldsp.cxx:756
virtual sal_Bool SAL_CALL hasLocale(const css::lang::Locale &aLocale) override
Definition: spelldsp.cxx:189
std::map< LanguageType, LangSvcEntries_Spell_Ptr_t > SpellSvcByLangMap_t
Definition: spelldsp.hxx:49
linguistic::SpellCache & GetCache() const
Definition: spelldsp.hxx:113
void setCharClass(const LanguageTag &rLanguageTag)
Definition: spelldsp.cxx:814
virtual sal_Bool SAL_CALL isValid(const OUString &aWord, ::sal_Int16 nLanguage, const css::uno::Sequence< css::beans::PropertyValue > &aProperties) override
const css::uno::Reference< css::linguistic2::XLinguProperties > & GetPropSet()
Definition: spelldsp.hxx:122
css::uno::Reference< css::linguistic2::XSearchableDictionaryList > m_xDicList
Definition: spelldsp.hxx:53
const css::uno::Reference< css::linguistic2::XSearchableDictionaryList > & GetDicList()
Definition: spelldsp.hxx:131
SpellSvcByLangMap_t m_aSvcMap
Definition: spelldsp.hxx:50
virtual css::uno::Sequence< css::lang::Locale > SAL_CALL getLocales() override
Definition: spelldsp.cxx:175
std::unique_ptr< linguistic::SpellCache > m_pCache
Definition: spelldsp.hxx:56
LngSvcMgr & m_rMgr
Definition: spelldsp.hxx:55
virtual css::uno::Sequence< ::sal_Int16 > SAL_CALL getLanguages() override
Definition: spelldsp.cxx:719
std::optional< CharClass > m_oCharClass
Definition: spelldsp.hxx:57
css::uno::Reference< css::linguistic2::XLinguProperties > m_xPropSet
Definition: spelldsp.hxx:52
virtual sal_Bool SAL_CALL hasLanguage(::sal_Int16 nLanguage) override
Definition: spelldsp.cxx:728
virtual sal_Bool SAL_CALL isValid(const OUString &aWord, const css::lang::Locale &aLocale, const css::uno::Sequence< ::css::beans::PropertyValue > &aProperties) override
SpellCheckerDispatcher & operator=(const SpellCheckerDispatcher &)=delete
css::uno::Reference< css::linguistic2::XSpellAlternatives > spell_Impl(const OUString &aWord, LanguageType nLanguage, const css::beans::PropertyValues &aProperties)
Definition: spelldsp.cxx:412
virtual ~SpellCheckerDispatcher() override
Definition: spelldsp.cxx:170
static OUString makeLowerCase(const OUString &, const std::optional< CharClass > &)
Definition: spelldsp.cxx:822
bool isValid_Impl(const OUString &aWord, LanguageType nLanguage, const css::beans::PropertyValues &aProperties)
Definition: spelldsp.cxx:249
SpellCheckerDispatcher(const SpellCheckerDispatcher &)=delete
virtual css::uno::Sequence< OUString > GetServiceList(const css::lang::Locale &rLocale) const override
Definition: spelldsp.cxx:791
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
uno::Reference< XSearchableDictionaryList > GetDictionaryList()
Definition: misc.cxx:671
uno::Reference< XLinguProperties > GetLinguProperties()
Definition: misc.cxx:666
unsigned char sal_Bool