calc: on editing invalidation of view with different zoom is wrong
[LibreOffice.git] / linguistic / workben / sprophelp.cxx
blob41542fec155f19aeb3df8bf52c1896e7c5893d04
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 .
21 #include <sal/macros.h>
22 #include "linguistic/misc.hxx"
24 #include "sprophelp.hxx"
25 #include "linguistic/lngprops.hxx"
27 #include <com/sun/star/linguistic2/LinguServiceEvent.hpp>
28 #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp>
29 #include <com/sun/star/linguistic2/XLinguServiceEventListener.hpp>
30 #include <com/sun/star/beans/XPropertySet.hpp>
31 #include <osl/mutex.hxx>
33 using namespace osl;
34 using namespace com::sun::star;
35 using namespace com::sun::star::beans;
36 using namespace com::sun::star::lang;
37 using namespace com::sun::star::uno;
38 using namespace com::sun::star::linguistic2;
39 using namespace linguistic;
42 PropertyChgHelper::PropertyChgHelper(
43 const Reference< XInterface > & rxSource,
44 Reference< XPropertySet > &rxPropSet,
45 const char *pPropNames[], sal_uInt16 nPropCount )
46 : aPropNames(nPropCount)
47 , xMyEvtObj(rxSource)
48 , aLngSvcEvtListeners(GetLinguMutex())
49 , xPropSet(rxPropSet)
51 OUString *pName = aPropNames.getArray();
52 for (sal_Int32 i = 0; i < nPropCount; ++i)
54 pName[i] = OUString::createFromAscii( pPropNames[i] );
59 PropertyChgHelper::PropertyChgHelper( const PropertyChgHelper &rHelper ) :
60 aPropNames(rHelper.aPropNames),
61 xMyEvtObj(rHelper.xMyEvtObj),
62 aLngSvcEvtListeners (GetLinguMutex()),
63 xPropSet(rHelper.xPropSet)
65 AddAsPropListener();
70 PropertyChgHelper::~PropertyChgHelper()
75 void PropertyChgHelper::AddAsPropListener()
77 if (xPropSet.is())
79 sal_Int32 nLen = aPropNames.getLength();
80 const OUString *pPropName = aPropNames.getConstArray();
81 for (sal_Int32 i = 0; i < nLen; ++i)
83 if (pPropName[i].getLength())
84 xPropSet->addPropertyChangeListener( pPropName[i], this );
89 void PropertyChgHelper::RemoveAsPropListener()
91 if (xPropSet.is())
93 sal_Int32 nLen = aPropNames.getLength();
94 const OUString *pPropName = aPropNames.getConstArray();
95 for (sal_Int32 i = 0; i < nLen; ++i)
97 if (pPropName[i].getLength())
98 xPropSet->removePropertyChangeListener( pPropName[i], this );
104 void PropertyChgHelper::LaunchEvent( const LinguServiceEvent &rEvt )
106 cppu::OInterfaceIteratorHelper aIt( aLngSvcEvtListeners );
107 while (aIt.hasMoreElements())
109 Reference< XLinguServiceEventListener > xRef( aIt.next(), UNO_QUERY );
110 if (xRef.is())
111 xRef->processLinguServiceEvent( rEvt );
116 void SAL_CALL PropertyChgHelper::disposing( const EventObject& rSource )
117 throw(RuntimeException)
119 MutexGuard aGuard( GetLinguMutex() );
120 if (rSource.Source == xPropSet)
122 RemoveAsPropListener();
123 xPropSet = NULL;
124 aPropNames.realloc( 0 );
129 sal_Bool SAL_CALL
130 PropertyChgHelper::addLinguServiceEventListener(
131 const Reference< XLinguServiceEventListener >& rxListener )
132 throw(RuntimeException)
134 MutexGuard aGuard( GetLinguMutex() );
136 sal_Bool bRes = sal_False;
137 if (rxListener.is())
139 sal_Int32 nCount = aLngSvcEvtListeners.getLength();
140 bRes = aLngSvcEvtListeners.addInterface( rxListener ) != nCount;
142 return bRes;
146 sal_Bool SAL_CALL
147 PropertyChgHelper::removeLinguServiceEventListener(
148 const Reference< XLinguServiceEventListener >& rxListener )
149 throw(RuntimeException)
151 MutexGuard aGuard( GetLinguMutex() );
153 sal_Bool bRes = sal_False;
154 if (rxListener.is())
156 sal_Int32 nCount = aLngSvcEvtListeners.getLength();
157 bRes = aLngSvcEvtListeners.removeInterface( rxListener ) != nCount;
159 return bRes;
163 static const char *aSP[] =
165 UPN_IS_GERMAN_PRE_REFORM,
166 UPN_IS_IGNORE_CONTROL_CHARACTERS,
167 UPN_IS_USE_DICTIONARY_LIST,
168 UPN_IS_SPELL_UPPER_CASE,
169 UPN_IS_SPELL_WITH_DIGITS,
170 UPN_IS_SPELL_CAPITALIZATION
174 PropertyHelper_Spell::PropertyHelper_Spell(
175 const Reference< XInterface > & rxSource,
176 Reference< XPropertySet > &rxPropSet ) :
177 PropertyChgHelper ( rxSource, rxPropSet, aSP, SAL_N_ELEMENTS(aSP) )
179 SetDefault();
180 sal_Int32 nLen = GetPropNames().getLength();
181 if (rxPropSet.is() && nLen)
183 const OUString *pPropName = GetPropNames().getConstArray();
184 for (sal_Int32 i = 0; i < nLen; ++i)
186 sal_Bool *pbVal = NULL,
187 *pbResVal = NULL;
189 if (OUString( UPN_IS_GERMAN_PRE_REFORM ) == pPropName[i])
191 pbVal = &bIsGermanPreReform;
192 pbResVal = &bResIsGermanPreReform;
194 else if (OUString( UPN_IS_IGNORE_CONTROL_CHARACTERS ) == pPropName[i])
196 pbVal = &bIsIgnoreControlCharacters;
197 pbResVal = &bResIsIgnoreControlCharacters;
199 else if (OUString( UPN_IS_USE_DICTIONARY_LIST ) == pPropName[i])
201 pbVal = &bIsUseDictionaryList;
202 pbResVal = &bResIsUseDictionaryList;
204 else if (OUString( UPN_IS_SPELL_UPPER_CASE ) == pPropName[i])
206 pbVal = &bIsSpellUpperCase;
207 pbResVal = &bResIsSpellUpperCase;
209 else if (OUString( UPN_IS_SPELL_WITH_DIGITS ) == pPropName[i])
211 pbVal = &bIsSpellWithDigits;
212 pbResVal = &bResIsSpellWithDigits;
214 else if (OUString( UPN_IS_SPELL_CAPITALIZATION ) == pPropName[i])
216 pbVal = &bIsSpellCapitalization;
217 pbResVal = &bResIsSpellCapitalization;
220 if (pbVal && pbResVal)
222 rxPropSet->getPropertyValue( pPropName[i] ) >>= *pbVal;
223 *pbResVal = *pbVal;
230 PropertyHelper_Spell::~PropertyHelper_Spell()
235 void PropertyHelper_Spell::SetDefault()
237 bResIsGermanPreReform = bIsGermanPreReform = sal_False;
238 bResIsIgnoreControlCharacters = bIsIgnoreControlCharacters = sal_True;
239 bResIsUseDictionaryList = bIsUseDictionaryList = sal_True;
240 bResIsSpellUpperCase = bIsSpellUpperCase = sal_False;
241 bResIsSpellWithDigits = bIsSpellWithDigits = sal_False;
242 bResIsSpellCapitalization = bIsSpellCapitalization = sal_True;
246 void SAL_CALL
247 PropertyHelper_Spell::propertyChange( const PropertyChangeEvent& rEvt )
248 throw(RuntimeException)
250 MutexGuard aGuard( GetLinguMutex() );
252 if (GetPropSet().is() && rEvt.Source == GetPropSet())
254 sal_Int16 nLngSvcFlags = 0;
255 sal_Bool bSCWA = sal_False, // SPELL_CORRECT_WORDS_AGAIN ?
256 bSWWA = sal_False; // SPELL_WRONG_WORDS_AGAIN ?
258 sal_Bool *pbVal = NULL;
259 switch (rEvt.PropertyHandle)
261 case UPH_IS_IGNORE_CONTROL_CHARACTERS :
263 pbVal = &bIsIgnoreControlCharacters;
264 break;
266 case UPH_IS_GERMAN_PRE_REFORM :
268 pbVal = &bIsGermanPreReform;
269 bSCWA = bSWWA = sal_True;
270 break;
272 case UPH_IS_USE_DICTIONARY_LIST :
274 pbVal = &bIsUseDictionaryList;
275 bSCWA = bSWWA = sal_True;
276 break;
278 case UPH_IS_SPELL_UPPER_CASE :
280 pbVal = &bIsSpellUpperCase;
281 bSCWA = sal_False == *pbVal; // sal_False->sal_True change?
282 bSWWA = !bSCWA; // sal_True->sal_False change?
283 break;
285 case UPH_IS_SPELL_WITH_DIGITS :
287 pbVal = &bIsSpellWithDigits;
288 bSCWA = sal_False == *pbVal; // sal_False->sal_True change?
289 bSWWA = !bSCWA; // sal_True->sal_False change?
290 break;
292 case UPH_IS_SPELL_CAPITALIZATION :
294 pbVal = &bIsSpellCapitalization;
295 bSCWA = sal_False == *pbVal; // sal_False->sal_True change?
296 bSWWA = !bSCWA; // sal_True->sal_False change?
297 break;
299 default:
300 OSL_FAIL( "unknown property" );
302 if (pbVal)
303 rEvt.NewValue >>= *pbVal;
305 if (bSCWA)
306 nLngSvcFlags |= LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN;
307 if (bSWWA)
308 nLngSvcFlags |= LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN;
309 if (nLngSvcFlags)
311 LinguServiceEvent aEvt( GetEvtObj(), nLngSvcFlags );
312 LaunchEvent( aEvt );
318 void PropertyHelper_Spell::SetTmpPropVals( const PropertyValues &rPropVals )
320 // set return value to default value unless there is an
321 // explicitly supplied temporary value
322 bResIsGermanPreReform = bIsGermanPreReform;
323 bResIsIgnoreControlCharacters = bIsIgnoreControlCharacters;
324 bResIsUseDictionaryList = bIsUseDictionaryList;
325 bResIsSpellUpperCase = bIsSpellUpperCase;
326 bResIsSpellWithDigits = bIsSpellWithDigits;
327 bResIsSpellCapitalization = bIsSpellCapitalization;
329 sal_Int32 nLen = rPropVals.getLength();
330 if (nLen)
332 const PropertyValue *pVal = rPropVals.getConstArray();
333 for (sal_Int32 i = 0; i < nLen; ++i)
335 sal_Bool *pbResVal = NULL;
336 switch (pVal[i].Handle)
338 case UPH_IS_GERMAN_PRE_REFORM : pbResVal = &bResIsGermanPreReform; break;
339 case UPH_IS_IGNORE_CONTROL_CHARACTERS : pbResVal = &bResIsIgnoreControlCharacters; break;
340 case UPH_IS_USE_DICTIONARY_LIST : pbResVal = &bResIsUseDictionaryList; break;
341 case UPH_IS_SPELL_UPPER_CASE : pbResVal = &bResIsSpellUpperCase; break;
342 case UPH_IS_SPELL_WITH_DIGITS : pbResVal = &bResIsSpellWithDigits; break;
343 case UPH_IS_SPELL_CAPITALIZATION : pbResVal = &bResIsSpellCapitalization; break;
344 default:
345 OSL_FAIL( "unknown property" );
347 if (pbResVal)
348 pVal[i].Value >>= *pbResVal;
354 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */