sync master with lastest vba changes
[ooovba.git] / lingucomponent / source / thesaurus / libnth / ntprophelp.cxx
blobc939272713401818dfe7d5f946d9d2577fa92c23
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ntprophelp.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_lingucomponent.hxx"
34 #include <linguistic/misc.hxx>
36 #include "ntprophelp.hxx"
37 #include <linguistic/lngprops.hxx>
38 #include <tools/debug.hxx>
40 #include <com/sun/star/linguistic2/LinguServiceEvent.hpp>
41 #include <com/sun/star/linguistic2/LinguServiceEventFlags.hpp>
42 #include <com/sun/star/linguistic2/XLinguServiceEventListener.hpp>
43 #include <com/sun/star/beans/XPropertySet.hpp>
44 #include <osl/mutex.hxx>
46 //using namespace utl;
47 using namespace osl;
48 using namespace rtl;
49 using namespace com::sun::star;
50 using namespace com::sun::star::beans;
51 using namespace com::sun::star::lang;
52 using namespace com::sun::star::uno;
53 using namespace com::sun::star::linguistic2;
54 using namespace linguistic;
57 #define A2OU(x) ::rtl::OUString::createFromAscii( x )
59 ///////////////////////////////////////////////////////////////////////////
62 PropertyChgHelper::PropertyChgHelper(
63 const Reference< XInterface > & rxSource,
64 Reference< XPropertySet > &rxPropSet,
65 const char *pPropNames[], USHORT nPropCount ) :
66 aPropNames (nPropCount),
67 xMyEvtObj (rxSource),
68 aLngSvcEvtListeners (GetLinguMutex()),
69 xPropSet (rxPropSet)
71 OUString *pName = aPropNames.getArray();
72 for (INT32 i = 0; i < nPropCount; ++i)
74 pName[i] = A2OU( pPropNames[i] );
79 /*PropertyChgHelper::PropertyChgHelper( const PropertyChgHelper &rHelper ) :
80 aLngSvcEvtListeners (GetLinguMutex())
82 xPropSet = rHelper.xPropSet;
83 aPropNames = rHelper.aPropNames;
84 AddAsPropListener();
86 xMyEvtObj = rHelper.xMyEvtObj;
87 } */
90 PropertyChgHelper::~PropertyChgHelper()
95 void PropertyChgHelper::AddAsPropListener()
97 if (xPropSet.is())
99 INT32 nLen = aPropNames.getLength();
100 const OUString *pPropName = aPropNames.getConstArray();
101 for (INT32 i = 0; i < nLen; ++i)
103 if (pPropName[i].getLength())
104 xPropSet->addPropertyChangeListener( pPropName[i], this );
109 void PropertyChgHelper::RemoveAsPropListener()
111 if (xPropSet.is())
113 INT32 nLen = aPropNames.getLength();
114 const OUString *pPropName = aPropNames.getConstArray();
115 for (INT32 i = 0; i < nLen; ++i)
117 if (pPropName[i].getLength())
118 xPropSet->removePropertyChangeListener( pPropName[i], this );
124 void PropertyChgHelper::LaunchEvent( const LinguServiceEvent &rEvt )
126 cppu::OInterfaceIteratorHelper aIt( aLngSvcEvtListeners );
127 while (aIt.hasMoreElements())
129 Reference< XLinguServiceEventListener > xRef( aIt.next(), UNO_QUERY );
130 if (xRef.is())
131 xRef->processLinguServiceEvent( rEvt );
136 void SAL_CALL PropertyChgHelper::disposing( const EventObject& rSource )
137 throw(RuntimeException)
139 MutexGuard aGuard( GetLinguMutex() );
140 if (rSource.Source == xPropSet)
142 RemoveAsPropListener();
143 xPropSet = NULL;
144 aPropNames.realloc( 0 );
149 sal_Bool SAL_CALL
150 PropertyChgHelper::addLinguServiceEventListener(
151 const Reference< XLinguServiceEventListener >& rxListener )
152 throw(RuntimeException)
154 MutexGuard aGuard( GetLinguMutex() );
156 BOOL bRes = FALSE;
157 if (rxListener.is())
159 INT32 nCount = aLngSvcEvtListeners.getLength();
160 bRes = aLngSvcEvtListeners.addInterface( rxListener ) != nCount;
162 return bRes;
166 sal_Bool SAL_CALL
167 PropertyChgHelper::removeLinguServiceEventListener(
168 const Reference< XLinguServiceEventListener >& rxListener )
169 throw(RuntimeException)
171 MutexGuard aGuard( GetLinguMutex() );
173 BOOL bRes = FALSE;
174 if (rxListener.is())
176 INT32 nCount = aLngSvcEvtListeners.getLength();
177 bRes = aLngSvcEvtListeners.removeInterface( rxListener ) != nCount;
179 return bRes;
182 ///////////////////////////////////////////////////////////////////////////
184 static const char *aSP[] =
186 UPN_IS_GERMAN_PRE_REFORM,
187 UPN_IS_IGNORE_CONTROL_CHARACTERS,
188 UPN_IS_USE_DICTIONARY_LIST,
192 PropertyHelper_Thes::PropertyHelper_Thes(
193 const Reference< XInterface > & rxSource,
194 Reference< XPropertySet > &rxPropSet ) :
195 PropertyChgHelper ( rxSource, rxPropSet, aSP, sizeof(aSP) / sizeof(aSP[0]) )
197 SetDefault();
198 INT32 nLen = GetPropNames().getLength();
199 if (rxPropSet.is() && nLen)
201 const OUString *pPropName = GetPropNames().getConstArray();
202 for (INT32 i = 0; i < nLen; ++i)
204 BOOL *pbVal = NULL,
205 *pbResVal = NULL;
207 if (A2OU( UPN_IS_GERMAN_PRE_REFORM ) == pPropName[i])
209 pbVal = &bIsGermanPreReform;
210 pbResVal = &bResIsGermanPreReform;
212 else if (A2OU( UPN_IS_IGNORE_CONTROL_CHARACTERS ) == pPropName[i])
214 pbVal = &bIsIgnoreControlCharacters;
215 pbResVal = &bResIsIgnoreControlCharacters;
217 else if (A2OU( UPN_IS_USE_DICTIONARY_LIST ) == pPropName[i])
219 pbVal = &bIsUseDictionaryList;
220 pbResVal = &bResIsUseDictionaryList;
222 if (pbVal && pbResVal)
224 rxPropSet->getPropertyValue( pPropName[i] ) >>= *pbVal;
225 *pbResVal = *pbVal;
232 PropertyHelper_Thes::~PropertyHelper_Thes()
237 void PropertyHelper_Thes::SetDefault()
239 bResIsGermanPreReform = bIsGermanPreReform = FALSE;
240 bResIsIgnoreControlCharacters = bIsIgnoreControlCharacters = TRUE;
241 bResIsUseDictionaryList = bIsUseDictionaryList = TRUE;
245 void SAL_CALL
246 PropertyHelper_Thes::propertyChange( const PropertyChangeEvent& rEvt )
247 throw(RuntimeException)
249 MutexGuard aGuard( GetLinguMutex() );
251 if (GetPropSet().is() && rEvt.Source == GetPropSet())
253 INT16 nLngSvcFlags = 0;
254 BOOL bSCWA = FALSE, // SPELL_CORRECT_WORDS_AGAIN ?
255 bSWWA = FALSE; // SPELL_WRONG_WORDS_AGAIN ?
257 BOOL *pbVal = NULL;
258 switch (rEvt.PropertyHandle)
260 case UPH_IS_IGNORE_CONTROL_CHARACTERS :
262 pbVal = &bIsIgnoreControlCharacters;
263 break;
265 case UPH_IS_GERMAN_PRE_REFORM :
267 pbVal = &bIsGermanPreReform;
268 bSCWA = bSWWA = TRUE;
269 break;
271 case UPH_IS_USE_DICTIONARY_LIST :
273 pbVal = &bIsUseDictionaryList;
274 bSCWA = bSWWA = TRUE;
275 break;
277 default:
278 DBG_ERROR( "unknown property" );
280 if (pbVal)
281 rEvt.NewValue >>= *pbVal;
283 if (bSCWA)
284 nLngSvcFlags |= LinguServiceEventFlags::SPELL_CORRECT_WORDS_AGAIN;
285 if (bSWWA)
286 nLngSvcFlags |= LinguServiceEventFlags::SPELL_WRONG_WORDS_AGAIN;
287 if (nLngSvcFlags)
289 LinguServiceEvent aEvt( GetEvtObj(), nLngSvcFlags );
290 LaunchEvent( aEvt );
296 void PropertyHelper_Thes::SetTmpPropVals( const PropertyValues &rPropVals )
298 // set return value to default value unless there is an
299 // explicitly supplied temporary value
300 bResIsGermanPreReform = bIsGermanPreReform;
301 bResIsIgnoreControlCharacters = bIsIgnoreControlCharacters;
302 bResIsUseDictionaryList = bIsUseDictionaryList;
305 INT32 nLen = rPropVals.getLength();
306 if (nLen)
308 const PropertyValue *pVal = rPropVals.getConstArray();
309 for (INT32 i = 0; i < nLen; ++i)
311 BOOL *pbResVal = NULL;
312 switch (pVal[i].Handle)
314 case UPH_IS_GERMAN_PRE_REFORM : pbResVal = &bResIsGermanPreReform; break;
315 case UPH_IS_IGNORE_CONTROL_CHARACTERS : pbResVal = &bResIsIgnoreControlCharacters; break;
316 case UPH_IS_USE_DICTIONARY_LIST : pbResVal = &bResIsUseDictionaryList; break;
317 default:
318 DBG_ERROR( "unknown property" );
320 if (pbResVal)
321 pVal[i].Value >>= *pbResVal;
326 ///////////////////////////////////////////////////////////////////////////