Update ooo320-m1
[ooovba.git] / linguistic / source / lngopt.cxx
blobfc6f4c7cc34d1477bf65f066002718973de5f84f
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: lngopt.cxx,v $
10 * $Revision: 1.18 $
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_linguistic.hxx"
34 #include "lngopt.hxx"
35 #include "lngprops.hxx"
36 #include "misc.hxx"
37 #include <tools/debug.hxx>
38 #include <svtools/lingucfg.hxx>
39 #include <vcl/svapp.hxx>
41 #include <uno/lbnames.h> // CPPU_CURRENT_LANGUAGE_BINDING_NAME macro, which specify the environment type
42 #include <cppuhelper/implbase1.hxx> // helper for implementations
44 #include <cppuhelper/factory.hxx> // helper for factories
45 #include <com/sun/star/container/XNameAccess.hpp>
46 #include <com/sun/star/registry/XSimpleRegistry.hpp>
47 #include <com/sun/star/registry/XRegistryKey.hpp>
48 #include <com/sun/star/lang/Locale.hpp>
49 #include <com/sun/star/i18n/ScriptType.hpp>
50 #include <unotools/processfactory.hxx>
51 #include <i18npool/mslangid.hxx>
53 using namespace utl;
54 using namespace osl;
55 using namespace rtl;
56 using namespace com::sun::star;
57 using namespace com::sun::star::container;
58 using namespace com::sun::star::beans;
59 using namespace com::sun::star::lang;
60 using namespace com::sun::star::uno;
61 using namespace com::sun::star::linguistic2;
62 using namespace linguistic;
64 using namespace com::sun::star::registry;
66 ///////////////////////////////////////////////////////////////////////////
69 // static member intialization
70 SvtLinguOptions * LinguOptions::pData = NULL;
71 vos::ORefCount LinguOptions::aRefCount;
74 LinguOptions::LinguOptions()
76 if (!pData)
78 pData = new SvtLinguOptions;
79 SvtLinguConfig aLinguCfg;
80 aLinguCfg.GetOptions( *pData );
83 ++aRefCount;
87 LinguOptions::LinguOptions(const LinguOptions & /*rOpt*/)
89 DBG_ASSERT( pData, "lng : data missing" );
90 ++aRefCount;
94 LinguOptions::~LinguOptions()
96 MutexGuard aGuard( GetLinguMutex() );
98 if (--aRefCount == 0)
100 delete pData; pData = NULL;
105 BOOL LinguOptions::SetLocale_Impl( INT16 &rLanguage, Any &rOld, const Any &rVal, sal_Int16 nType)
107 BOOL bRes = FALSE;
109 Locale aNew;
110 rVal >>= aNew;
111 INT16 nNew = MsLangId::resolveSystemLanguageByScriptType(MsLangId::convertLocaleToLanguage(aNew), nType);
112 if (nNew != rLanguage)
114 Locale aLocale( CreateLocale( rLanguage ) );
115 rOld.setValue( &aLocale, ::getCppuType((Locale*)0 ));
116 rLanguage = nNew;
117 bRes = TRUE;
120 return bRes;
124 BOOL LinguOptions::SetValue( Any &rOld, const Any &rVal, INT32 nWID )
126 MutexGuard aGuard( GetLinguMutex() );
128 BOOL bRes = FALSE;
130 INT16 *pnVal = 0;
131 BOOL *pbVal = 0;
133 switch( nWID )
135 case WID_IS_GERMAN_PRE_REFORM : /*! deprecated !*/ break;
136 case WID_IS_USE_DICTIONARY_LIST : pbVal = &pData->bIsUseDictionaryList; break;
137 case WID_IS_IGNORE_CONTROL_CHARACTERS : pbVal = &pData->bIsIgnoreControlCharacters; break;
138 case WID_IS_HYPH_AUTO : pbVal = &pData->bIsHyphAuto; break;
139 case WID_IS_HYPH_SPECIAL : pbVal = &pData->bIsHyphSpecial; break;
140 case WID_IS_SPELL_AUTO : pbVal = &pData->bIsSpellAuto; break;
141 case WID_IS_SPELL_HIDE : /*! deprecated !*/ break;
142 case WID_IS_SPELL_IN_ALL_LANGUAGES :/*! deprecated !*/ break;
143 case WID_IS_SPELL_SPECIAL : pbVal = &pData->bIsSpellSpecial; break;
144 case WID_IS_WRAP_REVERSE : pbVal = &pData->bIsSpellReverse; break;
145 case WID_DEFAULT_LANGUAGE : pnVal = &pData->nDefaultLanguage; break;
146 case WID_IS_SPELL_CAPITALIZATION : pbVal = &pData->bIsSpellCapitalization; break;
147 case WID_IS_SPELL_WITH_DIGITS : pbVal = &pData->bIsSpellWithDigits; break;
148 case WID_IS_SPELL_UPPER_CASE : pbVal = &pData->bIsSpellUpperCase; break;
149 case WID_HYPH_MIN_LEADING : pnVal = &pData->nHyphMinLeading; break;
150 case WID_HYPH_MIN_TRAILING : pnVal = &pData->nHyphMinTrailing; break;
151 case WID_HYPH_MIN_WORD_LENGTH : pnVal = &pData->nHyphMinWordLength; break;
152 case WID_DEFAULT_LOCALE :
154 bRes = SetLocale_Impl( pData->nDefaultLanguage, rOld, rVal, ::com::sun::star::i18n::ScriptType::LATIN );
155 break;
157 case WID_DEFAULT_LOCALE_CJK :
159 bRes = SetLocale_Impl( pData->nDefaultLanguage_CJK, rOld, rVal, ::com::sun::star::i18n::ScriptType::ASIAN );
160 break;
162 case WID_DEFAULT_LOCALE_CTL :
164 bRes = SetLocale_Impl( pData->nDefaultLanguage_CTL, rOld, rVal, ::com::sun::star::i18n::ScriptType::COMPLEX );
165 break;
167 default :
169 DBG_ASSERT( 0,"lng : unknown WID");
170 bRes = FALSE;
174 if (pbVal)
176 BOOL bNew = FALSE;
177 rVal >>= bNew;
178 if (bNew != *pbVal)
180 rOld <<= *pbVal;
181 *pbVal = bNew;
182 bRes = TRUE;
185 if (pnVal)
187 INT16 nNew = 0;
188 rVal >>= nNew;
189 if (nNew != *pnVal)
191 rOld <<= *pnVal;
192 *pnVal = nNew;
193 bRes = TRUE;
197 // if (bRes)
198 // pData->SetModified();
200 return bRes;
203 void LinguOptions::GetValue( Any &rVal, INT32 nWID ) const
205 MutexGuard aGuard( GetLinguMutex() );
207 INT16 *pnVal = 0;
208 BOOL *pbVal = 0;
209 BOOL bDummy = FALSE;
211 switch( nWID )
213 case WID_IS_GERMAN_PRE_REFORM : pbVal = &bDummy; /*! deprecated !*/ break;
214 case WID_IS_USE_DICTIONARY_LIST : pbVal = &pData->bIsUseDictionaryList; break;
215 case WID_IS_IGNORE_CONTROL_CHARACTERS : pbVal = &pData->bIsIgnoreControlCharacters; break;
216 case WID_IS_HYPH_AUTO : pbVal = &pData->bIsHyphAuto; break;
217 case WID_IS_HYPH_SPECIAL : pbVal = &pData->bIsHyphSpecial; break;
218 case WID_IS_SPELL_AUTO : pbVal = &pData->bIsSpellAuto; break;
219 case WID_IS_SPELL_HIDE : pbVal = &bDummy; /*! deprecated !*/ break;
220 case WID_IS_SPELL_IN_ALL_LANGUAGES :pbVal = &bDummy; /*! deprecated !*/ break;
221 case WID_IS_SPELL_SPECIAL : pbVal = &pData->bIsSpellSpecial; break;
222 case WID_IS_WRAP_REVERSE : pbVal = &pData->bIsSpellReverse; break;
223 case WID_DEFAULT_LANGUAGE : pnVal = &pData->nDefaultLanguage; break;
224 case WID_IS_SPELL_CAPITALIZATION : pbVal = &pData->bIsSpellCapitalization; break;
225 case WID_IS_SPELL_WITH_DIGITS : pbVal = &pData->bIsSpellWithDigits; break;
226 case WID_IS_SPELL_UPPER_CASE : pbVal = &pData->bIsSpellUpperCase; break;
227 case WID_HYPH_MIN_LEADING : pnVal = &pData->nHyphMinLeading; break;
228 case WID_HYPH_MIN_TRAILING : pnVal = &pData->nHyphMinTrailing; break;
229 case WID_HYPH_MIN_WORD_LENGTH : pnVal = &pData->nHyphMinWordLength; break;
230 case WID_DEFAULT_LOCALE :
232 Locale aLocale( MsLangId::convertLanguageToLocale( pData->nDefaultLanguage ) );
233 rVal.setValue( &aLocale, ::getCppuType((Locale*)0 ));
234 break;
236 case WID_DEFAULT_LOCALE_CJK :
238 Locale aLocale( MsLangId::convertLanguageToLocale( pData->nDefaultLanguage_CJK ) );
239 rVal.setValue( &aLocale, ::getCppuType((Locale*)0 ));
240 break;
242 case WID_DEFAULT_LOCALE_CTL :
244 Locale aLocale( MsLangId::convertLanguageToLocale( pData->nDefaultLanguage_CTL ) );
245 rVal.setValue( &aLocale, ::getCppuType((Locale*)0 ));
246 break;
248 default :
250 DBG_ASSERT( 0,"lng : unknown WID");
254 if (pbVal)
255 rVal <<= *pbVal;
256 if (pnVal)
257 rVal <<= *pnVal;
261 struct WID_Name
263 INT32 nWID;
264 const char *pPropertyName;
267 //! order of entries is import (see LinguOptions::GetName)
268 //! since the WID is used as index in this table!
269 WID_Name aWID_Name[] =
271 { 0, 0 },
272 { WID_IS_USE_DICTIONARY_LIST, UPN_IS_USE_DICTIONARY_LIST },
273 { WID_IS_IGNORE_CONTROL_CHARACTERS, UPN_IS_IGNORE_CONTROL_CHARACTERS },
274 { WID_IS_SPELL_UPPER_CASE, UPN_IS_SPELL_UPPER_CASE },
275 { WID_IS_SPELL_WITH_DIGITS, UPN_IS_SPELL_WITH_DIGITS },
276 { WID_IS_SPELL_CAPITALIZATION, UPN_IS_SPELL_CAPITALIZATION },
277 { WID_HYPH_MIN_LEADING, UPN_HYPH_MIN_LEADING },
278 { WID_HYPH_MIN_TRAILING, UPN_HYPH_MIN_TRAILING },
279 { WID_HYPH_MIN_WORD_LENGTH, UPN_HYPH_MIN_WORD_LENGTH },
280 { WID_DEFAULT_LOCALE, UPN_DEFAULT_LOCALE },
281 { WID_IS_SPELL_AUTO, UPN_IS_SPELL_AUTO },
282 { 0, 0 },
283 { 0, 0 },
284 { WID_IS_SPELL_SPECIAL, UPN_IS_SPELL_SPECIAL },
285 { WID_IS_HYPH_AUTO, UPN_IS_HYPH_AUTO },
286 { WID_IS_HYPH_SPECIAL, UPN_IS_HYPH_SPECIAL },
287 { WID_IS_WRAP_REVERSE, UPN_IS_WRAP_REVERSE },
288 { 0, 0 },
289 { 0, 0 },
290 { 0, 0 },
291 { 0, 0 },
292 { WID_DEFAULT_LANGUAGE, UPN_DEFAULT_LANGUAGE },
293 { WID_DEFAULT_LOCALE_CJK, UPN_DEFAULT_LOCALE_CJK },
294 { WID_DEFAULT_LOCALE_CTL, UPN_DEFAULT_LOCALE_CTL }
298 OUString LinguOptions::GetName( INT32 nWID )
300 MutexGuard aGuard( GetLinguMutex() );
302 OUString aRes;
304 INT32 nLen = sizeof( aWID_Name ) / sizeof( aWID_Name[0] );
305 if (0 <= nWID && nWID < nLen
306 && aWID_Name[ nWID ].nWID == nWID)
308 aRes = OUString( RTL_CONSTASCII_USTRINGPARAM(
309 aWID_Name[ nWID ].pPropertyName ) );
311 else
313 DBG_ASSERT( 0,"lng : unknown WID");
316 return aRes;
320 ///////////////////////////////////////////////////////////////////////////
322 //! map must be sorted by first entry in alphabetical increasing order.
323 const SfxItemPropertyMapEntry* lcl_GetLinguProps()
325 static const SfxItemPropertyMapEntry aLinguProps[] =
327 { MAP_CHAR_LEN(UPN_DEFAULT_LANGUAGE), WID_DEFAULT_LANGUAGE,
328 &::getCppuType( (sal_Int16*)0 ), 0, 0 },
329 { MAP_CHAR_LEN(UPN_DEFAULT_LOCALE), WID_DEFAULT_LOCALE,
330 &::getCppuType( (Locale* )0), 0, 0 },
331 { MAP_CHAR_LEN(UPN_DEFAULT_LOCALE_CJK), WID_DEFAULT_LOCALE_CJK,
332 &::getCppuType( (Locale* )0), 0, 0 },
333 { MAP_CHAR_LEN(UPN_DEFAULT_LOCALE_CTL), WID_DEFAULT_LOCALE_CTL,
334 &::getCppuType( (Locale* )0), 0, 0 },
335 { MAP_CHAR_LEN(UPN_HYPH_MIN_LEADING), WID_HYPH_MIN_LEADING,
336 &::getCppuType( (sal_Int16*)0 ), 0, 0 },
337 { MAP_CHAR_LEN(UPN_HYPH_MIN_TRAILING), WID_HYPH_MIN_TRAILING,
338 &::getCppuType( (sal_Int16*)0 ), 0, 0 },
339 { MAP_CHAR_LEN(UPN_HYPH_MIN_WORD_LENGTH), WID_HYPH_MIN_WORD_LENGTH,
340 &::getCppuType( (sal_Int16*)0 ), 0, 0 },
341 { MAP_CHAR_LEN(UPN_IS_GERMAN_PRE_REFORM), WID_IS_GERMAN_PRE_REFORM, /*! deprecated !*/
342 &::getBooleanCppuType(), 0, 0 },
343 { MAP_CHAR_LEN(UPN_IS_HYPH_AUTO), WID_IS_HYPH_AUTO,
344 &::getBooleanCppuType(), 0, 0 },
345 { MAP_CHAR_LEN(UPN_IS_HYPH_SPECIAL), WID_IS_HYPH_SPECIAL,
346 &::getBooleanCppuType(), 0, 0 },
347 { MAP_CHAR_LEN(UPN_IS_IGNORE_CONTROL_CHARACTERS), WID_IS_IGNORE_CONTROL_CHARACTERS,
348 &::getBooleanCppuType(), 0, 0 },
349 { MAP_CHAR_LEN(UPN_IS_SPELL_AUTO), WID_IS_SPELL_AUTO,
350 &::getBooleanCppuType(), 0, 0 },
351 { MAP_CHAR_LEN(UPN_IS_SPELL_CAPITALIZATION), WID_IS_SPELL_CAPITALIZATION,
352 &::getBooleanCppuType(), 0, 0 },
353 { MAP_CHAR_LEN(UPN_IS_SPELL_HIDE), WID_IS_SPELL_HIDE, /*! deprecated !*/
354 &::getBooleanCppuType(), 0, 0 },
355 { MAP_CHAR_LEN(UPN_IS_SPELL_IN_ALL_LANGUAGES), WID_IS_SPELL_IN_ALL_LANGUAGES, /*! deprecated !*/
356 &::getBooleanCppuType(), 0, 0 },
357 { MAP_CHAR_LEN(UPN_IS_SPELL_SPECIAL), WID_IS_SPELL_SPECIAL,
358 &::getBooleanCppuType(), 0, 0 },
359 { MAP_CHAR_LEN(UPN_IS_SPELL_UPPER_CASE), WID_IS_SPELL_UPPER_CASE,
360 &::getBooleanCppuType(), 0, 0 },
361 { MAP_CHAR_LEN(UPN_IS_SPELL_WITH_DIGITS), WID_IS_SPELL_WITH_DIGITS,
362 &::getBooleanCppuType(), 0, 0 },
363 { MAP_CHAR_LEN(UPN_IS_USE_DICTIONARY_LIST), WID_IS_USE_DICTIONARY_LIST,
364 &::getBooleanCppuType(), 0, 0 },
365 { MAP_CHAR_LEN(UPN_IS_WRAP_REVERSE), WID_IS_WRAP_REVERSE,
366 &::getBooleanCppuType(), 0, 0 },
367 { 0,0,0,0,0,0 }
369 return aLinguProps;
371 LinguProps::LinguProps() :
372 aEvtListeners (GetLinguMutex()),
373 aPropListeners (GetLinguMutex()),
374 aPropertyMap(lcl_GetLinguProps())
376 bDisposing = FALSE;
379 void LinguProps::launchEvent( const PropertyChangeEvent &rEvt ) const
381 cppu::OInterfaceContainerHelper *pContainer =
382 aPropListeners.getContainer( rEvt.PropertyHandle );
383 if (pContainer)
385 cppu::OInterfaceIteratorHelper aIt( *pContainer );
386 while (aIt.hasMoreElements())
388 Reference< XPropertyChangeListener > xRef( aIt.next(), UNO_QUERY );
389 if (xRef.is())
390 xRef->propertyChange( rEvt );
395 Reference< XInterface > SAL_CALL LinguProps_CreateInstance(
396 const Reference< XMultiServiceFactory > & /*rSMgr*/ )
397 throw(Exception)
399 Reference< XInterface > xService = (cppu::OWeakObject*)new LinguProps;
400 return xService;
403 Reference< XPropertySetInfo > SAL_CALL LinguProps::getPropertySetInfo()
404 throw(RuntimeException)
406 MutexGuard aGuard( GetLinguMutex() );
408 static Reference< XPropertySetInfo > aRef =
409 new SfxItemPropertySetInfo( &aPropertyMap );
410 return aRef;
413 void SAL_CALL LinguProps::setPropertyValue(
414 const OUString& rPropertyName, const Any& rValue )
415 throw(UnknownPropertyException, PropertyVetoException,
416 IllegalArgumentException, WrappedTargetException, RuntimeException)
418 MutexGuard aGuard( GetLinguMutex() );
420 const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
421 if (pCur)
423 Any aOld( aConfig.GetProperty( pCur->nWID ) );
424 if (aOld != rValue && aConfig.SetProperty( pCur->nWID, rValue ))
426 PropertyChangeEvent aChgEvt( (XPropertySet *) this, rPropertyName,
427 FALSE, pCur->nWID, aOld, rValue );
428 launchEvent( aChgEvt );
431 #ifdef LINGU_EXCEPTIONS
432 else
434 throw UnknownPropertyException();
436 #endif
439 Any SAL_CALL LinguProps::getPropertyValue( const OUString& rPropertyName )
440 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
442 MutexGuard aGuard( GetLinguMutex() );
444 Any aRet;
446 const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
447 if(pCur)
449 aRet = aConfig.GetProperty( pCur->nWID );
451 #ifdef LINGU_EXCEPTIONS
452 else
454 throw UnknownPropertyException();
456 #endif
458 return aRet;
461 void SAL_CALL LinguProps::addPropertyChangeListener(
462 const OUString& rPropertyName,
463 const Reference< XPropertyChangeListener >& rxListener )
464 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
466 MutexGuard aGuard( GetLinguMutex() );
468 if (!bDisposing && rxListener.is())
470 const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
471 if(pCur)
472 aPropListeners.addInterface( pCur->nWID, rxListener );
473 #ifdef LINGU_EXCEPTIONS
474 else
476 throw UnknownPropertyException();
478 #endif
482 void SAL_CALL LinguProps::removePropertyChangeListener(
483 const OUString& rPropertyName,
484 const Reference< XPropertyChangeListener >& rxListener )
485 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
487 MutexGuard aGuard( GetLinguMutex() );
489 if (!bDisposing && rxListener.is())
491 const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
492 if(pCur)
493 aPropListeners.removeInterface( pCur->nWID, rxListener );
494 #ifdef LINGU_EXCEPTIONS
495 else
497 throw UnknownPropertyException();
499 #endif
503 void SAL_CALL LinguProps::addVetoableChangeListener(
504 const OUString& /*rPropertyName*/,
505 const Reference< XVetoableChangeListener >& /*xListener*/ )
506 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
508 // MutexGuard aGuard( GetLinguMutex() );
511 void SAL_CALL LinguProps::removeVetoableChangeListener(
512 const OUString& /*rPropertyName*/,
513 const Reference< XVetoableChangeListener >& /*xListener*/ )
514 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
516 // MutexGuard aGuard( GetLinguMutex() );
520 void SAL_CALL LinguProps::setFastPropertyValue( sal_Int32 nHandle, const Any& rValue )
521 throw(UnknownPropertyException, PropertyVetoException,
522 IllegalArgumentException, WrappedTargetException, RuntimeException)
524 MutexGuard aGuard( GetLinguMutex() );
526 Any aOld( aConfig.GetProperty( nHandle ) );
527 if (aOld != rValue && aConfig.SetProperty( nHandle, rValue ))
529 PropertyChangeEvent aChgEvt( (XPropertySet *) this,
530 LinguOptions::GetName( nHandle ), FALSE, nHandle, aOld, rValue );
531 launchEvent( aChgEvt );
536 Any SAL_CALL LinguProps::getFastPropertyValue( sal_Int32 nHandle )
537 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
539 MutexGuard aGuard( GetLinguMutex() );
541 Any aRes( aConfig.GetProperty( nHandle ) );
542 return aRes;
546 Sequence< PropertyValue > SAL_CALL
547 LinguProps::getPropertyValues()
548 throw(RuntimeException)
550 MutexGuard aGuard( GetLinguMutex() );
552 INT32 nLen = aPropertyMap.getSize();
553 Sequence< PropertyValue > aProps( nLen );
554 PropertyValue *pProp = aProps.getArray();
555 PropertyEntryVector_t aPropEntries = aPropertyMap.getPropertyEntries();
556 PropertyEntryVector_t::const_iterator aIt = aPropEntries.begin();
557 for (INT32 i = 0; i < nLen; ++i, ++aIt)
559 PropertyValue &rVal = pProp[i];
560 Any aAny( aConfig.GetProperty( aIt->nWID ) );
562 rVal.Name = aIt->sName;
563 rVal.Handle = aIt->nWID;
564 rVal.Value = aAny;
565 rVal.State = PropertyState_DIRECT_VALUE ;
567 return aProps;
570 void SAL_CALL
571 LinguProps::setPropertyValues( const Sequence< PropertyValue >& rProps )
572 throw(UnknownPropertyException, PropertyVetoException,
573 IllegalArgumentException, WrappedTargetException, RuntimeException)
575 MutexGuard aGuard( GetLinguMutex() );
577 INT32 nLen = rProps.getLength();
578 const PropertyValue *pVal = rProps.getConstArray();
579 for (INT32 i = 0; i < nLen; ++i)
581 const PropertyValue &rVal = pVal[i];
582 setPropertyValue( rVal.Name, rVal.Value );
586 void SAL_CALL
587 LinguProps::dispose()
588 throw(RuntimeException)
590 MutexGuard aGuard( GetLinguMutex() );
592 if (!bDisposing)
594 bDisposing = TRUE;
596 //! its too late to save the options here!
597 // (see AppExitListener for saving)
598 //aOpt.Save(); // save (possible) changes before exiting
600 EventObject aEvtObj( (XPropertySet *) this );
601 aEvtListeners.disposeAndClear( aEvtObj );
602 aPropListeners.disposeAndClear( aEvtObj );
606 void SAL_CALL
607 LinguProps::addEventListener( const Reference< XEventListener >& rxListener )
608 throw(RuntimeException)
610 MutexGuard aGuard( GetLinguMutex() );
612 if (!bDisposing && rxListener.is())
613 aEvtListeners.addInterface( rxListener );
616 void SAL_CALL
617 LinguProps::removeEventListener( const Reference< XEventListener >& rxListener )
618 throw(RuntimeException)
620 MutexGuard aGuard( GetLinguMutex() );
622 if (!bDisposing && rxListener.is())
623 aEvtListeners.removeInterface( rxListener );
627 ///////////////////////////////////////////////////////////////////////////
628 // Service specific part
631 // XServiceInfo
632 OUString SAL_CALL LinguProps::getImplementationName()
633 throw(RuntimeException)
635 MutexGuard aGuard( GetLinguMutex() );
636 return getImplementationName_Static();
639 // XServiceInfo
640 sal_Bool SAL_CALL LinguProps::supportsService( const OUString& ServiceName )
641 throw(RuntimeException)
643 MutexGuard aGuard( GetLinguMutex() );
645 uno::Sequence< OUString > aSNL = getSupportedServiceNames();
646 const OUString * pArray = aSNL.getConstArray();
647 for( INT32 i = 0; i < aSNL.getLength(); i++ )
648 if( pArray[i] == ServiceName )
649 return TRUE;
650 return FALSE;
653 // XServiceInfo
654 uno::Sequence< OUString > SAL_CALL LinguProps::getSupportedServiceNames()
655 throw(RuntimeException)
657 MutexGuard aGuard( GetLinguMutex() );
658 return getSupportedServiceNames_Static();
661 // ORegistryServiceManager_Static
662 uno::Sequence< OUString > LinguProps::getSupportedServiceNames_Static()
663 throw()
665 MutexGuard aGuard( GetLinguMutex() );
667 uno::Sequence< OUString > aSNS( 1 ); // auch mehr als 1 Service moeglich
668 aSNS.getArray()[0] = A2OU( SN_LINGU_PROPERTIES );
669 return aSNS;
673 sal_Bool SAL_CALL LinguProps_writeInfo( void * /*pServiceManager*/,
674 XRegistryKey * pRegistryKey )
678 String aImpl( '/' );
679 aImpl += LinguProps::getImplementationName_Static().getStr();
680 aImpl.AppendAscii( "/UNO/SERVICES" );
681 Reference< XRegistryKey > xNewKey =
682 pRegistryKey->createKey(aImpl );
683 uno::Sequence< OUString > aServices = LinguProps::getSupportedServiceNames_Static();
684 for( INT32 i = 0; i < aServices.getLength(); i++ )
685 xNewKey->createKey( aServices.getConstArray()[i]);
687 return sal_True;
689 catch(Exception &)
691 return sal_False;
695 void * SAL_CALL LinguProps_getFactory( const sal_Char * pImplName,
696 XMultiServiceFactory *pServiceManager, void * )
698 void * pRet = 0;
699 if ( !LinguProps::getImplementationName_Static().compareToAscii( pImplName ) )
701 Reference< XSingleServiceFactory > xFactory =
702 cppu::createOneInstanceFactory(
703 pServiceManager,
704 LinguProps::getImplementationName_Static(),
705 LinguProps_CreateInstance,
706 LinguProps::getSupportedServiceNames_Static());
707 // acquire, because we return an interface pointer instead of a reference
708 xFactory->acquire();
709 pRet = xFactory.get();
711 return pRet;
714 ///////////////////////////////////////////////////////////////////////////