xref: /aoo42x/main/linguistic/source/lngopt.cxx (revision 30acf5e8)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_linguistic.hxx"
26 
27 #include "lngopt.hxx"
28 #include "linguistic/lngprops.hxx"
29 #include "linguistic/misc.hxx"
30 #include <tools/debug.hxx>
31 #include <unotools/lingucfg.hxx>
32 
33 #include <uno/lbnames.h>			// CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
34 #include <cppuhelper/implbase1.hxx>	// helper for implementations
35 
36 #include <cppuhelper/factory.hxx>	// helper for factories
37 #include <com/sun/star/container/XNameAccess.hpp>
38 #include <com/sun/star/registry/XSimpleRegistry.hpp>
39 #include <com/sun/star/registry/XRegistryKey.hpp>
40 #include <com/sun/star/lang/Locale.hpp>
41 #include <com/sun/star/i18n/ScriptType.hpp>
42 #include <unotools/processfactory.hxx>
43 #include <i18npool/mslangid.hxx>
44 
45 using namespace utl;
46 using namespace osl;
47 using namespace rtl;
48 using namespace com::sun::star;
49 using namespace com::sun::star::container;
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;
55 
56 using namespace com::sun::star::registry;
57 
58 ///////////////////////////////////////////////////////////////////////////
59 
60 
61 // static member initialization
62 SvtLinguOptions *	LinguOptions::pData	= NULL;
63 vos::ORefCount		LinguOptions::aRefCount;
64 
65 
LinguOptions()66 LinguOptions::LinguOptions()
67 {
68 	if (!pData)
69 	{
70 		pData = new SvtLinguOptions;
71 		SvtLinguConfig aLinguCfg;
72 		aLinguCfg.GetOptions( *pData );
73 	}
74 
75 	++aRefCount;
76 }
77 
78 
LinguOptions(const LinguOptions &)79 LinguOptions::LinguOptions(const LinguOptions & /*rOpt*/)
80 {
81 	DBG_ASSERT( pData, "lng : data missing" );
82 	++aRefCount;
83 }
84 
85 
~LinguOptions()86 LinguOptions::~LinguOptions()
87 {
88 	MutexGuard	aGuard( GetLinguMutex() );
89 
90 	if (--aRefCount == 0)
91 	{
92 		delete pData;	pData  = NULL;
93 	}
94 }
95 
96 
SetLocale_Impl(sal_Int16 & rLanguage,Any & rOld,const Any & rVal,sal_Int16 nType)97 sal_Bool LinguOptions::SetLocale_Impl( sal_Int16 &rLanguage, Any &rOld, const Any &rVal, sal_Int16 nType)
98 {
99 	sal_Bool bRes = sal_False;
100 
101 	Locale	aNew;
102 	rVal >>= aNew;
103         sal_Int16 nNew = MsLangId::resolveSystemLanguageByScriptType(MsLangId::convertLocaleToLanguage(aNew), nType);
104 	if (nNew != rLanguage)
105 	{
106 		Locale	aLocale( CreateLocale( rLanguage ) );
107 		rOld.setValue( &aLocale, ::getCppuType((Locale*)0 ));
108 		rLanguage = nNew;
109 		bRes = sal_True;
110 	}
111 
112 	return bRes;
113 }
114 
115 
SetValue(Any & rOld,const Any & rVal,sal_Int32 nWID)116 sal_Bool LinguOptions::SetValue( Any &rOld, const Any &rVal, sal_Int32 nWID )
117 {
118 	MutexGuard	aGuard( GetLinguMutex() );
119 
120 	sal_Bool bRes = sal_False;
121 
122 	sal_Int16 *pnVal = 0;
123 	sal_Bool  *pbVal = 0;
124 
125 	switch( nWID )
126 	{
127         case WID_IS_GERMAN_PRE_REFORM :     /*! deprecated !*/ break;
128 		case WID_IS_USE_DICTIONARY_LIST :	pbVal = &pData->bIsUseDictionaryList;	break;
129 		case WID_IS_IGNORE_CONTROL_CHARACTERS :	pbVal = &pData->bIsIgnoreControlCharacters;	break;
130 		case WID_IS_HYPH_AUTO : 			pbVal = &pData->bIsHyphAuto;	break;
131 		case WID_IS_HYPH_SPECIAL : 			pbVal = &pData->bIsHyphSpecial;	break;
132 		case WID_IS_SPELL_AUTO : 			pbVal = &pData->bIsSpellAuto;	break;
133         case WID_IS_SPELL_HIDE :            /*! deprecated !*/ break;
134         case WID_IS_SPELL_IN_ALL_LANGUAGES :/*! deprecated !*/ break;
135 		case WID_IS_SPELL_SPECIAL : 		pbVal = &pData->bIsSpellSpecial;	break;
136 		case WID_IS_WRAP_REVERSE : 			pbVal = &pData->bIsSpellReverse;	break;
137 		case WID_DEFAULT_LANGUAGE :			pnVal = &pData->nDefaultLanguage;	break;
138 		case WID_IS_SPELL_CAPITALIZATION :	pbVal = &pData->bIsSpellCapitalization;		break;
139 		case WID_IS_SPELL_WITH_DIGITS :		pbVal = &pData->bIsSpellWithDigits;	break;
140 		case WID_IS_SPELL_UPPER_CASE :		pbVal = &pData->bIsSpellUpperCase;		break;
141 		case WID_HYPH_MIN_LEADING :			pnVal = &pData->nHyphMinLeading;		break;
142 		case WID_HYPH_MIN_TRAILING :		pnVal = &pData->nHyphMinTrailing;	break;
143 		case WID_HYPH_MIN_WORD_LENGTH :		pnVal = &pData->nHyphMinWordLength;	break;
144 		case WID_DEFAULT_LOCALE :
145 		{
146 			bRes = SetLocale_Impl( pData->nDefaultLanguage, rOld, rVal, ::com::sun::star::i18n::ScriptType::LATIN );
147 			break;
148 		}
149 		case WID_DEFAULT_LOCALE_CJK :
150 		{
151 			bRes = SetLocale_Impl( pData->nDefaultLanguage_CJK, rOld, rVal, ::com::sun::star::i18n::ScriptType::ASIAN );
152 			break;
153 		}
154 		case WID_DEFAULT_LOCALE_CTL :
155 		{
156 			bRes = SetLocale_Impl( pData->nDefaultLanguage_CTL, rOld, rVal, ::com::sun::star::i18n::ScriptType::COMPLEX );
157 			break;
158 		}
159 		default :
160 		{
161             DBG_ASSERT( 0,"lng : unknown WID");
162 			bRes = sal_False;
163 		}
164 	}
165 
166 	if (pbVal)
167 	{
168         sal_Bool bNew = sal_False;
169 		rVal >>= bNew;
170 		if (bNew != *pbVal)
171 		{
172 			rOld <<= *pbVal;
173 			*pbVal = bNew;
174 			bRes = sal_True;
175 		}
176 	}
177 	if (pnVal)
178 	{
179         sal_Int16 nNew = 0;
180 		rVal >>= nNew;
181 		if (nNew != *pnVal)
182 		{
183 			rOld <<= *pnVal;
184 			*pnVal = nNew;
185 			bRes = sal_True;
186 		}
187 	}
188 
189 //	if (bRes)
190 //		pData->SetModified();
191 
192 	return bRes;
193 }
194 
GetValue(Any & rVal,sal_Int32 nWID) const195 void LinguOptions::GetValue( Any &rVal, sal_Int32 nWID ) const
196 {
197 	MutexGuard	aGuard( GetLinguMutex() );
198 
199 	sal_Int16 *pnVal = 0;
200 	sal_Bool  *pbVal = 0;
201     sal_Bool  bDummy = sal_False;
202 
203 	switch( nWID )
204 	{
205         case WID_IS_GERMAN_PRE_REFORM :     pbVal = &bDummy; /*! deprecated !*/ break;
206 		case WID_IS_USE_DICTIONARY_LIST :	pbVal = &pData->bIsUseDictionaryList;	break;
207 		case WID_IS_IGNORE_CONTROL_CHARACTERS :	pbVal = &pData->bIsIgnoreControlCharacters;	break;
208 		case WID_IS_HYPH_AUTO : 			pbVal = &pData->bIsHyphAuto;	break;
209 		case WID_IS_HYPH_SPECIAL : 			pbVal = &pData->bIsHyphSpecial;	break;
210 		case WID_IS_SPELL_AUTO : 			pbVal = &pData->bIsSpellAuto;	break;
211         case WID_IS_SPELL_HIDE :            pbVal = &bDummy; /*! deprecated !*/ break;
212         case WID_IS_SPELL_IN_ALL_LANGUAGES :pbVal = &bDummy; /*! deprecated !*/ break;
213 		case WID_IS_SPELL_SPECIAL : 		pbVal = &pData->bIsSpellSpecial;	break;
214 		case WID_IS_WRAP_REVERSE : 			pbVal = &pData->bIsSpellReverse;	break;
215 		case WID_DEFAULT_LANGUAGE :			pnVal = &pData->nDefaultLanguage;	break;
216 		case WID_IS_SPELL_CAPITALIZATION :	pbVal = &pData->bIsSpellCapitalization;		break;
217 		case WID_IS_SPELL_WITH_DIGITS :		pbVal = &pData->bIsSpellWithDigits;	break;
218 		case WID_IS_SPELL_UPPER_CASE :		pbVal = &pData->bIsSpellUpperCase;		break;
219 		case WID_HYPH_MIN_LEADING :			pnVal = &pData->nHyphMinLeading;		break;
220 		case WID_HYPH_MIN_TRAILING :		pnVal = &pData->nHyphMinTrailing;	break;
221 		case WID_HYPH_MIN_WORD_LENGTH :		pnVal = &pData->nHyphMinWordLength;	break;
222 		case WID_DEFAULT_LOCALE :
223 		{
224 			Locale aLocale( MsLangId::convertLanguageToLocale( pData->nDefaultLanguage ) );
225 			rVal.setValue( &aLocale, ::getCppuType((Locale*)0 ));
226 			break;
227 		}
228 		case WID_DEFAULT_LOCALE_CJK :
229 		{
230 			Locale aLocale( MsLangId::convertLanguageToLocale( pData->nDefaultLanguage_CJK ) );
231 			rVal.setValue( &aLocale, ::getCppuType((Locale*)0 ));
232 			break;
233 		}
234 		case WID_DEFAULT_LOCALE_CTL :
235 		{
236 			Locale aLocale( MsLangId::convertLanguageToLocale( pData->nDefaultLanguage_CTL ) );
237 			rVal.setValue( &aLocale, ::getCppuType((Locale*)0 ));
238 			break;
239 		}
240 		default :
241 		{
242             DBG_ASSERT( 0,"lng : unknown WID");
243 		}
244 	}
245 
246 	if (pbVal)
247 		rVal <<= *pbVal;
248 	if (pnVal)
249 		rVal <<= *pnVal;
250 }
251 
252 
253 struct WID_Name
254 {
255 	sal_Int32		 nWID;
256 	const char	*pPropertyName;
257 };
258 
259 //! order of entries is import (see LinguOptions::GetName)
260 //! since the WID is used as index in this table!
261 WID_Name aWID_Name[] =
262 {
263     { 0,                                  0 },
264     { WID_IS_USE_DICTIONARY_LIST,         UPN_IS_USE_DICTIONARY_LIST },
265     { WID_IS_IGNORE_CONTROL_CHARACTERS,   UPN_IS_IGNORE_CONTROL_CHARACTERS },
266     { WID_IS_SPELL_UPPER_CASE,            UPN_IS_SPELL_UPPER_CASE },
267     { WID_IS_SPELL_WITH_DIGITS,           UPN_IS_SPELL_WITH_DIGITS },
268     { WID_IS_SPELL_CAPITALIZATION,        UPN_IS_SPELL_CAPITALIZATION },
269     { WID_HYPH_MIN_LEADING,               UPN_HYPH_MIN_LEADING },
270     { WID_HYPH_MIN_TRAILING,              UPN_HYPH_MIN_TRAILING },
271     { WID_HYPH_MIN_WORD_LENGTH,           UPN_HYPH_MIN_WORD_LENGTH },
272     { WID_DEFAULT_LOCALE,                 UPN_DEFAULT_LOCALE },
273     { WID_IS_SPELL_AUTO,                  UPN_IS_SPELL_AUTO },
274     { 0,                                  0 },
275     { 0,                                  0 },
276     { WID_IS_SPELL_SPECIAL,               UPN_IS_SPELL_SPECIAL },
277     { WID_IS_HYPH_AUTO,                   UPN_IS_HYPH_AUTO },
278     { WID_IS_HYPH_SPECIAL,                UPN_IS_HYPH_SPECIAL },
279     { WID_IS_WRAP_REVERSE,                UPN_IS_WRAP_REVERSE },
280     { 0,                                  0 },
281     { 0,                                  0 },
282     { 0,                                  0 },
283     { 0,                                  0 },
284     { WID_DEFAULT_LANGUAGE,               UPN_DEFAULT_LANGUAGE },
285     { WID_DEFAULT_LOCALE_CJK,             UPN_DEFAULT_LOCALE_CJK },
286     { WID_DEFAULT_LOCALE_CTL,             UPN_DEFAULT_LOCALE_CTL }
287 };
288 
289 
GetName(sal_Int32 nWID)290 OUString LinguOptions::GetName( sal_Int32 nWID )
291 {
292 	MutexGuard	aGuard( GetLinguMutex() );
293 
294 	OUString aRes;
295 
296 	sal_Int32 nLen = sizeof( aWID_Name ) / sizeof( aWID_Name[0] );
297 	if (0 <= nWID  &&  nWID < nLen
298 		&& aWID_Name[ nWID ].nWID == nWID)
299 	{
300 		aRes = OUString( RTL_CONSTASCII_USTRINGPARAM(
301 				aWID_Name[ nWID ].pPropertyName ) );
302 	}
303 	else
304 	{
305         DBG_ASSERT( 0,"lng : unknown WID");
306 	}
307 
308 	return aRes;
309 }
310 
311 
312 ///////////////////////////////////////////////////////////////////////////
313 
314 //! map must be sorted by first entry in alphabetical increasing order.
lcl_GetLinguProps()315 const SfxItemPropertyMapEntry* lcl_GetLinguProps()
316 {
317     static const SfxItemPropertyMapEntry aLinguProps[] =
318     {
319         { MAP_CHAR_LEN(UPN_DEFAULT_LANGUAGE),           WID_DEFAULT_LANGUAGE,
320                 &::getCppuType( (sal_Int16*)0 ),    0, 0 },
321         { MAP_CHAR_LEN(UPN_DEFAULT_LOCALE),             WID_DEFAULT_LOCALE,
322                 &::getCppuType( (Locale* )0),       0, 0 },
323         { MAP_CHAR_LEN(UPN_DEFAULT_LOCALE_CJK),         WID_DEFAULT_LOCALE_CJK,
324                 &::getCppuType( (Locale* )0),       0, 0 },
325         { MAP_CHAR_LEN(UPN_DEFAULT_LOCALE_CTL),         WID_DEFAULT_LOCALE_CTL,
326                 &::getCppuType( (Locale* )0),       0, 0 },
327         { MAP_CHAR_LEN(UPN_HYPH_MIN_LEADING),           WID_HYPH_MIN_LEADING,
328                 &::getCppuType( (sal_Int16*)0 ),    0, 0 },
329         { MAP_CHAR_LEN(UPN_HYPH_MIN_TRAILING),          WID_HYPH_MIN_TRAILING,
330                 &::getCppuType( (sal_Int16*)0 ),    0, 0 },
331         { MAP_CHAR_LEN(UPN_HYPH_MIN_WORD_LENGTH),       WID_HYPH_MIN_WORD_LENGTH,
332                 &::getCppuType( (sal_Int16*)0 ),    0, 0 },
333         { MAP_CHAR_LEN(UPN_IS_GERMAN_PRE_REFORM),       WID_IS_GERMAN_PRE_REFORM,       /*! deprecated !*/
334                 &::getBooleanCppuType(),            0, 0 },
335         { MAP_CHAR_LEN(UPN_IS_HYPH_AUTO),               WID_IS_HYPH_AUTO,
336                 &::getBooleanCppuType(),            0, 0 },
337         { MAP_CHAR_LEN(UPN_IS_HYPH_SPECIAL),            WID_IS_HYPH_SPECIAL,
338                 &::getBooleanCppuType(),            0, 0 },
339         { MAP_CHAR_LEN(UPN_IS_IGNORE_CONTROL_CHARACTERS),   WID_IS_IGNORE_CONTROL_CHARACTERS,
340                 &::getBooleanCppuType(),            0, 0 },
341         { MAP_CHAR_LEN(UPN_IS_SPELL_AUTO),              WID_IS_SPELL_AUTO,
342                 &::getBooleanCppuType(),            0, 0 },
343         { MAP_CHAR_LEN(UPN_IS_SPELL_CAPITALIZATION),    WID_IS_SPELL_CAPITALIZATION,
344                 &::getBooleanCppuType(),            0, 0 },
345         { MAP_CHAR_LEN(UPN_IS_SPELL_HIDE),              WID_IS_SPELL_HIDE,              /*! deprecated !*/
346                 &::getBooleanCppuType(),            0, 0 },
347         { MAP_CHAR_LEN(UPN_IS_SPELL_IN_ALL_LANGUAGES),  WID_IS_SPELL_IN_ALL_LANGUAGES,  /*! deprecated !*/
348                 &::getBooleanCppuType(),            0, 0 },
349         { MAP_CHAR_LEN(UPN_IS_SPELL_SPECIAL),           WID_IS_SPELL_SPECIAL,
350                 &::getBooleanCppuType(),            0, 0 },
351         { MAP_CHAR_LEN(UPN_IS_SPELL_UPPER_CASE),        WID_IS_SPELL_UPPER_CASE,
352                 &::getBooleanCppuType(),            0, 0 },
353         { MAP_CHAR_LEN(UPN_IS_SPELL_WITH_DIGITS),       WID_IS_SPELL_WITH_DIGITS,
354                 &::getBooleanCppuType(),            0, 0 },
355         { MAP_CHAR_LEN(UPN_IS_USE_DICTIONARY_LIST),     WID_IS_USE_DICTIONARY_LIST,
356                 &::getBooleanCppuType(),            0, 0 },
357         { MAP_CHAR_LEN(UPN_IS_WRAP_REVERSE),            WID_IS_WRAP_REVERSE,
358                 &::getBooleanCppuType(),            0, 0 },
359         { 0,0,0,0,0,0 }
360     };
361     return aLinguProps;
362 }
LinguProps()363 LinguProps::LinguProps() :
364 	aEvtListeners	(GetLinguMutex()),
365 	aPropListeners	(GetLinguMutex()),
366     aPropertyMap(lcl_GetLinguProps())
367 {
368 	bDisposing = sal_False;
369 }
370 
launchEvent(const PropertyChangeEvent & rEvt) const371 void LinguProps::launchEvent( const PropertyChangeEvent &rEvt ) const
372 {
373 	cppu::OInterfaceContainerHelper *pContainer =
374 			aPropListeners.getContainer( rEvt.PropertyHandle );
375 	if (pContainer)
376 	{
377 		cppu::OInterfaceIteratorHelper aIt( *pContainer );
378 		while (aIt.hasMoreElements())
379 		{
380             Reference< XPropertyChangeListener > xRef( aIt.next(), UNO_QUERY );
381 			if (xRef.is())
382 				xRef->propertyChange( rEvt );
383 		}
384 	}
385 }
386 
LinguProps_CreateInstance(const Reference<XMultiServiceFactory> &)387 Reference< XInterface > SAL_CALL LinguProps_CreateInstance(
388             const Reference< XMultiServiceFactory > & /*rSMgr*/ )
389 		throw(Exception)
390 {
391 	Reference< XInterface > xService = (cppu::OWeakObject*)new LinguProps;
392 	return xService;
393 }
394 
getPropertySetInfo()395 Reference< XPropertySetInfo > SAL_CALL LinguProps::getPropertySetInfo()
396 		throw(RuntimeException)
397 {
398 	MutexGuard	aGuard( GetLinguMutex() );
399 
400 	static Reference< XPropertySetInfo > aRef =
401             new SfxItemPropertySetInfo( &aPropertyMap );
402 	return aRef;
403 }
404 
setPropertyValue(const OUString & rPropertyName,const Any & rValue)405 void SAL_CALL LinguProps::setPropertyValue(
406             const OUString& rPropertyName, const Any& rValue )
407 		throw(UnknownPropertyException, PropertyVetoException,
408 			  IllegalArgumentException, WrappedTargetException, RuntimeException)
409 {
410 	MutexGuard	aGuard( GetLinguMutex() );
411 
412     const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
413 	if (pCur)
414 	{
415         Any aOld( aConfig.GetProperty( pCur->nWID ) );
416         if (aOld != rValue && aConfig.SetProperty( pCur->nWID, rValue ))
417 		{
418 			PropertyChangeEvent aChgEvt( (XPropertySet *) this, rPropertyName,
419                     sal_False, pCur->nWID, aOld, rValue );
420 			launchEvent( aChgEvt );
421 		}
422 	}
423 #ifdef LINGU_EXCEPTIONS
424 	else
425 	{
426 		throw UnknownPropertyException();
427 	}
428 #endif
429 }
430 
getPropertyValue(const OUString & rPropertyName)431 Any SAL_CALL LinguProps::getPropertyValue( const OUString& rPropertyName )
432 		throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
433 {
434 	MutexGuard	aGuard( GetLinguMutex() );
435 
436 	Any aRet;
437 
438     const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
439 	if(pCur)
440 	{
441         aRet = aConfig.GetProperty( pCur->nWID );
442 	}
443 #ifdef LINGU_EXCEPTIONS
444 	else
445 	{
446 		throw UnknownPropertyException();
447 	}
448 #endif
449 
450 	return aRet;
451 }
452 
addPropertyChangeListener(const OUString & rPropertyName,const Reference<XPropertyChangeListener> & rxListener)453 void SAL_CALL LinguProps::addPropertyChangeListener(
454 			const OUString& rPropertyName,
455 			const Reference< XPropertyChangeListener >& rxListener )
456 		throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
457 {
458 	MutexGuard	aGuard( GetLinguMutex() );
459 
460 	if (!bDisposing && rxListener.is())
461 	{
462         const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
463 		if(pCur)
464 			aPropListeners.addInterface( pCur->nWID, rxListener );
465 #ifdef LINGU_EXCEPTIONS
466 		else
467 		{
468 			throw UnknownPropertyException();
469 		}
470 #endif
471 	}
472 }
473 
removePropertyChangeListener(const OUString & rPropertyName,const Reference<XPropertyChangeListener> & rxListener)474 void SAL_CALL LinguProps::removePropertyChangeListener(
475 			const OUString& rPropertyName,
476 			const Reference< XPropertyChangeListener >& rxListener )
477 		throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
478 {
479 	MutexGuard	aGuard( GetLinguMutex() );
480 
481 	if (!bDisposing && rxListener.is())
482 	{
483         const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
484 		if(pCur)
485 			aPropListeners.removeInterface( pCur->nWID, rxListener );
486 #ifdef LINGU_EXCEPTIONS
487 		else
488 		{
489 			throw UnknownPropertyException();
490 		}
491 #endif
492 	}
493 }
494 
addVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)495 void SAL_CALL LinguProps::addVetoableChangeListener(
496             const OUString& /*rPropertyName*/,
497             const Reference< XVetoableChangeListener >& /*xListener*/ )
498 		throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
499 {
500 //	MutexGuard	aGuard( GetLinguMutex() );
501 }
502 
removeVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)503 void SAL_CALL LinguProps::removeVetoableChangeListener(
504             const OUString& /*rPropertyName*/,
505             const Reference< XVetoableChangeListener >& /*xListener*/ )
506 		throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
507 {
508 //	MutexGuard	aGuard( GetLinguMutex() );
509 }
510 
511 
setFastPropertyValue(sal_Int32 nHandle,const Any & rValue)512 void SAL_CALL LinguProps::setFastPropertyValue( sal_Int32 nHandle, const Any& rValue )
513 		throw(UnknownPropertyException, PropertyVetoException,
514 			  IllegalArgumentException, WrappedTargetException, RuntimeException)
515 {
516 	MutexGuard	aGuard( GetLinguMutex() );
517 
518     Any aOld( aConfig.GetProperty( nHandle ) );
519     if (aOld != rValue && aConfig.SetProperty( nHandle, rValue ))
520 	{
521 		PropertyChangeEvent aChgEvt( (XPropertySet *) this,
522                 LinguOptions::GetName( nHandle ), sal_False, nHandle, aOld, rValue );
523 		launchEvent( aChgEvt );
524 	}
525 }
526 
527 
getFastPropertyValue(sal_Int32 nHandle)528 Any SAL_CALL LinguProps::getFastPropertyValue( sal_Int32 nHandle )
529 		throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
530 {
531 	MutexGuard	aGuard( GetLinguMutex() );
532 
533     Any aRes( aConfig.GetProperty( nHandle ) );
534 	return aRes;
535 }
536 
537 
538 Sequence< PropertyValue > SAL_CALL
getPropertyValues()539 	LinguProps::getPropertyValues()
540 		throw(RuntimeException)
541 {
542 	MutexGuard	aGuard( GetLinguMutex() );
543 
544     sal_Int32 nLen = aPropertyMap.getSize();
545 	Sequence< PropertyValue > aProps( nLen );
546     PropertyValue *pProp = aProps.getArray();
547     PropertyEntryVector_t aPropEntries = aPropertyMap.getPropertyEntries();
548     PropertyEntryVector_t::const_iterator aIt = aPropEntries.begin();
549     for (sal_Int32 i = 0;  i < nLen;  ++i, ++aIt)
550 	{
551 		PropertyValue &rVal = pProp[i];
552         Any aAny( aConfig.GetProperty( aIt->nWID ) );
553 
554         rVal.Name   = aIt->sName;
555         rVal.Handle = aIt->nWID;
556     	rVal.Value	= aAny;
557     	rVal.State	= PropertyState_DIRECT_VALUE ;
558 	}
559 	return aProps;
560 }
561 
562 void SAL_CALL
setPropertyValues(const Sequence<PropertyValue> & rProps)563 	LinguProps::setPropertyValues( const Sequence< PropertyValue >& rProps )
564 		throw(UnknownPropertyException, PropertyVetoException,
565 			  IllegalArgumentException, WrappedTargetException, RuntimeException)
566 {
567 	MutexGuard	aGuard( GetLinguMutex() );
568 
569 	sal_Int32 nLen = rProps.getLength();
570 	const PropertyValue *pVal = rProps.getConstArray();
571 	for (sal_Int32 i = 0;  i < nLen;  ++i)
572 	{
573         const PropertyValue &rVal = pVal[i];
574         setPropertyValue( rVal.Name, rVal.Value );
575 	}
576 }
577 
578 void SAL_CALL
dispose()579 	LinguProps::dispose()
580 		throw(RuntimeException)
581 {
582 	MutexGuard	aGuard( GetLinguMutex() );
583 
584 	if (!bDisposing)
585 	{
586 		bDisposing = sal_True;
587 
588 		//! its too late to save the options here!
589 		// (see AppExitListener for saving)
590 		//aOpt.Save();	// save (possible) changes before exiting
591 
592 		EventObject	aEvtObj( (XPropertySet *) this );
593 		aEvtListeners.disposeAndClear( aEvtObj );
594 		aPropListeners.disposeAndClear( aEvtObj );
595 	}
596 }
597 
598 void SAL_CALL
addEventListener(const Reference<XEventListener> & rxListener)599 	LinguProps::addEventListener( const Reference< XEventListener >& rxListener )
600 		throw(RuntimeException)
601 {
602 	MutexGuard	aGuard( GetLinguMutex() );
603 
604 	if (!bDisposing && rxListener.is())
605 		aEvtListeners.addInterface( rxListener );
606 }
607 
608 void SAL_CALL
removeEventListener(const Reference<XEventListener> & rxListener)609 	LinguProps::removeEventListener( const Reference< XEventListener >& rxListener )
610 		throw(RuntimeException)
611 {
612 	MutexGuard	aGuard( GetLinguMutex() );
613 
614 	if (!bDisposing && rxListener.is())
615 		aEvtListeners.removeInterface( rxListener );
616 }
617 
618 
619 ///////////////////////////////////////////////////////////////////////////
620 // Service specific part
621 //
622 
623 // XServiceInfo
getImplementationName()624 OUString SAL_CALL LinguProps::getImplementationName()
625 		throw(RuntimeException)
626 {
627 	MutexGuard	aGuard( GetLinguMutex() );
628 	return getImplementationName_Static();
629 }
630 
631 // XServiceInfo
supportsService(const OUString & ServiceName)632 sal_Bool SAL_CALL LinguProps::supportsService( const OUString& ServiceName )
633 		throw(RuntimeException)
634 {
635 	MutexGuard	aGuard( GetLinguMutex() );
636 
637 	uno::Sequence< OUString > aSNL = getSupportedServiceNames();
638 	const OUString * pArray = aSNL.getConstArray();
639 	for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
640 		if( pArray[i] == ServiceName )
641 			return sal_True;
642 	return sal_False;
643 }
644 
645 // XServiceInfo
getSupportedServiceNames()646 uno::Sequence< OUString > SAL_CALL LinguProps::getSupportedServiceNames()
647 		throw(RuntimeException)
648 {
649 	MutexGuard	aGuard( GetLinguMutex() );
650 	return getSupportedServiceNames_Static();
651 }
652 
653 // ORegistryServiceManager_Static
getSupportedServiceNames_Static()654 uno::Sequence< OUString > LinguProps::getSupportedServiceNames_Static()
655 		throw()
656 {
657 	MutexGuard	aGuard( GetLinguMutex() );
658 
659 	uno::Sequence< OUString > aSNS( 1 );	// auch mehr als 1 Service moeglich
660 	aSNS.getArray()[0] = A2OU( SN_LINGU_PROPERTIES );
661 	return aSNS;
662 }
663 
LinguProps_getFactory(const sal_Char * pImplName,XMultiServiceFactory * pServiceManager,void *)664 void * SAL_CALL LinguProps_getFactory( const sal_Char * pImplName,
665 			XMultiServiceFactory *pServiceManager, void * )
666 {
667 	void * pRet = 0;
668 	if ( !LinguProps::getImplementationName_Static().compareToAscii( pImplName ) )
669 	{
670 		Reference< XSingleServiceFactory > xFactory =
671 			cppu::createOneInstanceFactory(
672 				pServiceManager,
673 				LinguProps::getImplementationName_Static(),
674 				LinguProps_CreateInstance,
675 				LinguProps::getSupportedServiceNames_Static());
676 		// acquire, because we return an interface pointer instead of a reference
677 		xFactory->acquire();
678 		pRet = xFactory.get();
679 	}
680 	return pRet;
681 }
682 
683 ///////////////////////////////////////////////////////////////////////////
684 
685