LibreOffice Module linguistic (master) 1
iprcache.cxx
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
21#include <iprcache.hxx>
22#include <linguistic/misc.hxx>
23
24#include <com/sun/star/linguistic2/DictionaryListEventFlags.hpp>
25#include <osl/mutex.hxx>
27
28using namespace osl;
29using namespace com::sun::star;
30using namespace com::sun::star::beans;
31using namespace com::sun::star::lang;
32using namespace com::sun::star::uno;
33using namespace com::sun::star::linguistic2;
34
35
36namespace linguistic
37{
38
39
40#define NUM_FLUSH_PROPS 8
41
42const struct
43{
44 OUString aPropName;
45 sal_Int32 nPropHdl;
47{
55};
56
57
60 Reference< XLinguProperties > const &rPropSet )
61{
62 if (xListener.is() && rPropSet.is())
63 {
64 for (auto& aFlushProperty : aFlushProperties)
65 {
66 rPropSet->addPropertyChangeListener(
67 aFlushProperty.aPropName, xListener );
68 }
69 }
70}
71
72
75 Reference< XLinguProperties > const &rPropSet )
76{
77 if (xListener.is() && rPropSet.is())
78 {
79 for (auto& aFlushProperty : aFlushProperties)
80 {
81 rPropSet->removePropertyChangeListener(
82 aFlushProperty.aPropName, xListener );
83 }
84 }
85}
86
87
88static bool lcl_IsFlushProperty( sal_Int32 nHandle )
89{
90 int i;
91 for (i = 0; i < NUM_FLUSH_PROPS; ++i)
92 {
94 break;
95 }
96 return i < NUM_FLUSH_PROPS;
97}
98
99
101{
102 MutexGuard aGuard( GetLinguMutex() );
103
104 if (xDicList != rDL)
105 {
106 if (xDicList.is())
107 xDicList->removeDictionaryListEventListener( this );
108
109 xDicList = rDL;
110 if (xDicList.is())
111 xDicList->addDictionaryListEventListener( this, false );
112 }
113}
114
115
117{
118 MutexGuard aGuard( GetLinguMutex() );
119
120 if (xPropSet != rPS)
121 {
122 if (xPropSet.is())
124
125 xPropSet = rPS;
126 if (xPropSet.is())
128 }
129}
130
131
132void SAL_CALL FlushListener::disposing( const EventObject& rSource )
133{
134 MutexGuard aGuard( GetLinguMutex() );
135
136 if (xDicList.is() && rSource.Source == xDicList)
137 {
138 xDicList->removeDictionaryListEventListener( this );
139 xDicList = nullptr;
140 }
141 if (xPropSet.is() && rSource.Source == xPropSet)
142 {
144 xPropSet = nullptr;
145 }
146}
147
148
150 const DictionaryListEvent& rDicListEvent )
151{
152 MutexGuard aGuard( GetLinguMutex() );
153
154 if (rDicListEvent.Source != xDicList)
155 return;
156
157 sal_Int16 nEvt = rDicListEvent.nCondensedEvent;
158 sal_Int16 const nFlushFlags =
159 DictionaryListEventFlags::ADD_NEG_ENTRY |
160 DictionaryListEventFlags::DEL_POS_ENTRY |
161 DictionaryListEventFlags::ACTIVATE_NEG_DIC |
162 DictionaryListEventFlags::DEACTIVATE_POS_DIC;
163 bool bFlush = 0 != (nEvt & nFlushFlags);
164
165 if (bFlush)
167}
168
169
171 const PropertyChangeEvent& rEvt )
172{
173 MutexGuard aGuard( GetLinguMutex() );
174
175 if (rEvt.Source == xPropSet)
176 {
177 bool bFlush = lcl_IsFlushProperty( rEvt.PropertyHandle );
178
179 if (bFlush)
181 }
182}
183
184
186{
187 mxFlushLstnr = new FlushListener( *this );
189 mxFlushLstnr->SetDicList( aDictionaryList );
191 mxFlushLstnr->SetPropSet( aPropertySet );
192}
193
195{
198 mxFlushLstnr->SetDicList( aEmptyList );
199 mxFlushLstnr->SetPropSet( aEmptySet );
200}
201
203{
204 MutexGuard aGuard( GetLinguMutex() );
205 // clear word list
207}
208
209bool SpellCache::CheckWord( const OUString& rWord, LanguageType nLang )
210{
211 MutexGuard aGuard( GetLinguMutex() );
212 WordList_t &rList = aWordLists[ nLang ];
213 const WordList_t::const_iterator aIt = rList.find( rWord );
214 return aIt != rList.end();
215}
216
217void SpellCache::AddWord( const OUString& rWord, LanguageType nLang )
218{
219 MutexGuard aGuard( GetLinguMutex() );
220 WordList_t & rList = aWordLists[ nLang ];
221 // occasional clean-up...
222 if (rList.size() > 500)
223 rList.clear();
224 rList.insert( rWord );
225}
226
227} // namespace linguistic
228
229/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL processDictionaryListEvent(const css::linguistic2::DictionaryListEvent &rDicListEvent) override
Definition: iprcache.cxx:149
virtual void SAL_CALL disposing(const css::lang::EventObject &rSource) override
Definition: iprcache.cxx:132
SpellCache & mrSpellCache
Definition: iprcache.hxx:51
css::uno::Reference< css::linguistic2::XLinguProperties > xPropSet
Definition: iprcache.hxx:50
css::uno::Reference< css::linguistic2::XSearchableDictionaryList > xDicList
Definition: iprcache.hxx:49
void SetDicList(css::uno::Reference< css::linguistic2::XSearchableDictionaryList > const &rDL)
Definition: iprcache.cxx:100
virtual void SAL_CALL propertyChange(const css::beans::PropertyChangeEvent &rEvt) override
Definition: iprcache.cxx:170
void SetPropSet(css::uno::Reference< css::linguistic2::XLinguProperties > const &rPS)
Definition: iprcache.cxx:116
LangWordList_t aWordLists
Definition: iprcache.hxx:79
void AddWord(const OUString &rWord, LanguageType nLang)
Definition: iprcache.cxx:217
std::map< LanguageType, WordList_t > LangWordList_t
Definition: iprcache.hxx:78
rtl::Reference< FlushListener > mxFlushLstnr
Definition: iprcache.hxx:75
bool CheckWord(const OUString &rWord, LanguageType nLang)
Definition: iprcache.cxx:209
std::set< OUString > WordList_t
Definition: iprcache.hxx:77
#define NUM_FLUSH_PROPS
Definition: iprcache.cxx:40
#define UPH_IS_SPELL_WITH_DIGITS
#define UPH_IS_SPELL_CLOSED_COMPOUND
constexpr OUStringLiteral UPN_IS_SPELL_UPPER_CASE
#define UPH_IS_SPELL_HYPHENATED_COMPOUND
constexpr OUStringLiteral UPN_IS_SPELL_CLOSED_COMPOUND
constexpr OUStringLiteral UPN_IS_USE_DICTIONARY_LIST
constexpr OUStringLiteral UPN_IS_SPELL_WITH_DIGITS
constexpr OUStringLiteral UPN_IS_SPELL_HYPHENATED_COMPOUND
#define UPH_IS_SPELL_UPPER_CASE
constexpr OUStringLiteral UPN_IS_IGNORE_CONTROL_CHARACTERS
#define UPH_IS_USE_DICTIONARY_LIST
#define UPH_IS_SPELL_CAPITALIZATION
constexpr OUStringLiteral UPN_IS_SPELL_CAPITALIZATION
#define UPH_IS_IGNORE_CONTROL_CHARACTERS
int i
static void lcl_AddAsPropertyChangeListener(const Reference< XPropertyChangeListener > &xListener, Reference< XLinguProperties > const &rPropSet)
Definition: iprcache.cxx:58
static void lcl_RemoveAsPropertyChangeListener(const Reference< XPropertyChangeListener > &xListener, Reference< XLinguProperties > const &rPropSet)
Definition: iprcache.cxx:73
static bool lcl_IsFlushProperty(sal_Int32 nHandle)
Definition: iprcache.cxx:88
const struct linguistic::@0 aFlushProperties[NUM_FLUSH_PROPS]
uno::Reference< XSearchableDictionaryList > GetDictionaryList()
Definition: misc.cxx:671
sal_Int32 nPropHdl
Definition: iprcache.cxx:45
uno::Reference< XLinguProperties > GetLinguProperties()
Definition: misc.cxx:666
OUString aPropName
Definition: iprcache.cxx:44
osl::Mutex & GetLinguMutex()
! multi-thread safe mutex for all platforms !!
Definition: misc.cxx:60
sal_Int32 nHandle