update dev300-m58
[ooovba.git] / linguistic / source / lngopt.cxx
blobbb750b2eb7569bfc59e3dd8cb5582c7ee141fe90
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 <unotools/processfactory.hxx>
51 using namespace utl;
52 using namespace osl;
53 using namespace rtl;
54 using namespace com::sun::star;
55 using namespace com::sun::star::container;
56 using namespace com::sun::star::beans;
57 using namespace com::sun::star::lang;
58 using namespace com::sun::star::uno;
59 using namespace com::sun::star::linguistic2;
60 using namespace linguistic;
62 using namespace com::sun::star::registry;
64 ///////////////////////////////////////////////////////////////////////////
67 // static member intialization
68 SvtLinguOptions * LinguOptions::pData = NULL;
69 vos::ORefCount LinguOptions::aRefCount;
72 LinguOptions::LinguOptions()
74 if (!pData)
76 pData = new SvtLinguOptions;
77 SvtLinguConfig aLinguCfg;
78 aLinguCfg.GetOptions( *pData );
81 ++aRefCount;
85 LinguOptions::LinguOptions(const LinguOptions & /*rOpt*/)
87 DBG_ASSERT( pData, "lng : data missing" );
88 ++aRefCount;
92 LinguOptions::~LinguOptions()
94 MutexGuard aGuard( GetLinguMutex() );
96 if (--aRefCount == 0)
98 delete pData; pData = NULL;
103 BOOL LinguOptions::SetLocale_Impl( INT16 &rLanguage, Any &rOld, const Any &rVal)
105 BOOL bRes = FALSE;
107 Locale aNew;
108 rVal >>= aNew;
109 INT16 nNew = LocaleToLanguage( aNew );
110 if (nNew != rLanguage)
112 Locale aLocale( CreateLocale( rLanguage ) );
113 rOld.setValue( &aLocale, ::getCppuType((Locale*)0 ));
114 rLanguage = nNew;
115 bRes = TRUE;
118 return bRes;
122 BOOL LinguOptions::SetValue( Any &rOld, const Any &rVal, INT32 nWID )
124 MutexGuard aGuard( GetLinguMutex() );
126 BOOL bRes = FALSE;
128 INT16 *pnVal = 0;
129 BOOL *pbVal = 0;
131 switch( nWID )
133 case WID_IS_GERMAN_PRE_REFORM : /*! deprecated !*/ break;
134 case WID_IS_USE_DICTIONARY_LIST : pbVal = &pData->bIsUseDictionaryList; break;
135 case WID_IS_IGNORE_CONTROL_CHARACTERS : pbVal = &pData->bIsIgnoreControlCharacters; break;
136 case WID_IS_HYPH_AUTO : pbVal = &pData->bIsHyphAuto; break;
137 case WID_IS_HYPH_SPECIAL : pbVal = &pData->bIsHyphSpecial; break;
138 case WID_IS_SPELL_AUTO : pbVal = &pData->bIsSpellAuto; break;
139 case WID_IS_SPELL_HIDE : /*! deprecated !*/ break;
140 case WID_IS_SPELL_IN_ALL_LANGUAGES :/*! deprecated !*/ break;
141 case WID_IS_SPELL_SPECIAL : pbVal = &pData->bIsSpellSpecial; break;
142 case WID_IS_WRAP_REVERSE : pbVal = &pData->bIsSpellReverse; break;
143 case WID_DEFAULT_LANGUAGE : pnVal = &pData->nDefaultLanguage; break;
144 case WID_IS_SPELL_CAPITALIZATION : pbVal = &pData->bIsSpellCapitalization; break;
145 case WID_IS_SPELL_WITH_DIGITS : pbVal = &pData->bIsSpellWithDigits; break;
146 case WID_IS_SPELL_UPPER_CASE : pbVal = &pData->bIsSpellUpperCase; break;
147 case WID_HYPH_MIN_LEADING : pnVal = &pData->nHyphMinLeading; break;
148 case WID_HYPH_MIN_TRAILING : pnVal = &pData->nHyphMinTrailing; break;
149 case WID_HYPH_MIN_WORD_LENGTH : pnVal = &pData->nHyphMinWordLength; break;
150 case WID_DEFAULT_LOCALE :
152 bRes = SetLocale_Impl( pData->nDefaultLanguage, rOld, rVal );
153 break;
155 case WID_DEFAULT_LOCALE_CJK :
157 bRes = SetLocale_Impl( pData->nDefaultLanguage_CJK, rOld, rVal );
158 break;
160 case WID_DEFAULT_LOCALE_CTL :
162 bRes = SetLocale_Impl( pData->nDefaultLanguage_CTL, rOld, rVal );
163 break;
165 default :
167 DBG_ASSERT( 0,"lng : unknown WID");
168 bRes = FALSE;
172 if (pbVal)
174 BOOL bNew = FALSE;
175 rVal >>= bNew;
176 if (bNew != *pbVal)
178 rOld <<= *pbVal;
179 *pbVal = bNew;
180 bRes = TRUE;
183 if (pnVal)
185 INT16 nNew = 0;
186 rVal >>= nNew;
187 if (nNew != *pnVal)
189 rOld <<= *pnVal;
190 *pnVal = nNew;
191 bRes = TRUE;
195 // if (bRes)
196 // pData->SetModified();
198 return bRes;
201 void LinguOptions::GetValue( Any &rVal, INT32 nWID ) const
203 MutexGuard aGuard( GetLinguMutex() );
205 INT16 *pnVal = 0;
206 BOOL *pbVal = 0;
207 BOOL bDummy = FALSE;
209 switch( nWID )
211 case WID_IS_GERMAN_PRE_REFORM : pbVal = &bDummy; /*! deprecated !*/ break;
212 case WID_IS_USE_DICTIONARY_LIST : pbVal = &pData->bIsUseDictionaryList; break;
213 case WID_IS_IGNORE_CONTROL_CHARACTERS : pbVal = &pData->bIsIgnoreControlCharacters; break;
214 case WID_IS_HYPH_AUTO : pbVal = &pData->bIsHyphAuto; break;
215 case WID_IS_HYPH_SPECIAL : pbVal = &pData->bIsHyphSpecial; break;
216 case WID_IS_SPELL_AUTO : pbVal = &pData->bIsSpellAuto; break;
217 case WID_IS_SPELL_HIDE : pbVal = &bDummy; /*! deprecated !*/ break;
218 case WID_IS_SPELL_IN_ALL_LANGUAGES :pbVal = &bDummy; /*! deprecated !*/ break;
219 case WID_IS_SPELL_SPECIAL : pbVal = &pData->bIsSpellSpecial; break;
220 case WID_IS_WRAP_REVERSE : pbVal = &pData->bIsSpellReverse; break;
221 case WID_DEFAULT_LANGUAGE : pnVal = &pData->nDefaultLanguage; break;
222 case WID_IS_SPELL_CAPITALIZATION : pbVal = &pData->bIsSpellCapitalization; break;
223 case WID_IS_SPELL_WITH_DIGITS : pbVal = &pData->bIsSpellWithDigits; break;
224 case WID_IS_SPELL_UPPER_CASE : pbVal = &pData->bIsSpellUpperCase; break;
225 case WID_HYPH_MIN_LEADING : pnVal = &pData->nHyphMinLeading; break;
226 case WID_HYPH_MIN_TRAILING : pnVal = &pData->nHyphMinTrailing; break;
227 case WID_HYPH_MIN_WORD_LENGTH : pnVal = &pData->nHyphMinWordLength; break;
228 case WID_DEFAULT_LOCALE :
230 Locale aLocale( CreateLocale( pData->nDefaultLanguage ) );
231 rVal.setValue( &aLocale, ::getCppuType((Locale*)0 ));
232 break;
234 case WID_DEFAULT_LOCALE_CJK :
236 Locale aLocale( CreateLocale( pData->nDefaultLanguage_CJK ) );
237 rVal.setValue( &aLocale, ::getCppuType((Locale*)0 ));
238 break;
240 case WID_DEFAULT_LOCALE_CTL :
242 Locale aLocale( CreateLocale( pData->nDefaultLanguage_CTL ) );
243 rVal.setValue( &aLocale, ::getCppuType((Locale*)0 ));
244 break;
246 default :
248 DBG_ASSERT( 0,"lng : unknown WID");
252 if (pbVal)
253 rVal <<= *pbVal;
254 if (pnVal)
255 rVal <<= *pnVal;
259 struct WID_Name
261 INT32 nWID;
262 const char *pPropertyName;
265 //! order of entries is import (see LinguOptions::GetName)
266 //! since the WID is used as index in this table!
267 WID_Name aWID_Name[] =
269 { 0, 0 },
270 { WID_IS_USE_DICTIONARY_LIST, UPN_IS_USE_DICTIONARY_LIST },
271 { WID_IS_IGNORE_CONTROL_CHARACTERS, UPN_IS_IGNORE_CONTROL_CHARACTERS },
272 { WID_IS_SPELL_UPPER_CASE, UPN_IS_SPELL_UPPER_CASE },
273 { WID_IS_SPELL_WITH_DIGITS, UPN_IS_SPELL_WITH_DIGITS },
274 { WID_IS_SPELL_CAPITALIZATION, UPN_IS_SPELL_CAPITALIZATION },
275 { WID_HYPH_MIN_LEADING, UPN_HYPH_MIN_LEADING },
276 { WID_HYPH_MIN_TRAILING, UPN_HYPH_MIN_TRAILING },
277 { WID_HYPH_MIN_WORD_LENGTH, UPN_HYPH_MIN_WORD_LENGTH },
278 { WID_DEFAULT_LOCALE, UPN_DEFAULT_LOCALE },
279 { WID_IS_SPELL_AUTO, UPN_IS_SPELL_AUTO },
280 { 0, 0 },
281 { 0, 0 },
282 { WID_IS_SPELL_SPECIAL, UPN_IS_SPELL_SPECIAL },
283 { WID_IS_HYPH_AUTO, UPN_IS_HYPH_AUTO },
284 { WID_IS_HYPH_SPECIAL, UPN_IS_HYPH_SPECIAL },
285 { WID_IS_WRAP_REVERSE, UPN_IS_WRAP_REVERSE },
286 { 0, 0 },
287 { 0, 0 },
288 { 0, 0 },
289 { 0, 0 },
290 { WID_DEFAULT_LANGUAGE, UPN_DEFAULT_LANGUAGE },
291 { WID_DEFAULT_LOCALE_CJK, UPN_DEFAULT_LOCALE_CJK },
292 { WID_DEFAULT_LOCALE_CTL, UPN_DEFAULT_LOCALE_CTL }
296 OUString LinguOptions::GetName( INT32 nWID )
298 MutexGuard aGuard( GetLinguMutex() );
300 OUString aRes;
302 INT32 nLen = sizeof( aWID_Name ) / sizeof( aWID_Name[0] );
303 if (0 <= nWID && nWID < nLen
304 && aWID_Name[ nWID ].nWID == nWID)
306 aRes = OUString( RTL_CONSTASCII_USTRINGPARAM(
307 aWID_Name[ nWID ].pPropertyName ) );
309 else
311 DBG_ASSERT( 0,"lng : unknown WID");
314 return aRes;
318 ///////////////////////////////////////////////////////////////////////////
320 //! map must be sorted by first entry in alphabetical increasing order.
321 const SfxItemPropertyMapEntry* lcl_GetLinguProps()
323 static const SfxItemPropertyMapEntry aLinguProps[] =
325 { MAP_CHAR_LEN(UPN_DEFAULT_LANGUAGE), WID_DEFAULT_LANGUAGE,
326 &::getCppuType( (sal_Int16*)0 ), 0, 0 },
327 { MAP_CHAR_LEN(UPN_DEFAULT_LOCALE), WID_DEFAULT_LOCALE,
328 &::getCppuType( (Locale* )0), 0, 0 },
329 { MAP_CHAR_LEN(UPN_DEFAULT_LOCALE_CJK), WID_DEFAULT_LOCALE_CJK,
330 &::getCppuType( (Locale* )0), 0, 0 },
331 { MAP_CHAR_LEN(UPN_DEFAULT_LOCALE_CTL), WID_DEFAULT_LOCALE_CTL,
332 &::getCppuType( (Locale* )0), 0, 0 },
333 { MAP_CHAR_LEN(UPN_HYPH_MIN_LEADING), WID_HYPH_MIN_LEADING,
334 &::getCppuType( (sal_Int16*)0 ), 0, 0 },
335 { MAP_CHAR_LEN(UPN_HYPH_MIN_TRAILING), WID_HYPH_MIN_TRAILING,
336 &::getCppuType( (sal_Int16*)0 ), 0, 0 },
337 { MAP_CHAR_LEN(UPN_HYPH_MIN_WORD_LENGTH), WID_HYPH_MIN_WORD_LENGTH,
338 &::getCppuType( (sal_Int16*)0 ), 0, 0 },
339 { MAP_CHAR_LEN(UPN_IS_GERMAN_PRE_REFORM), WID_IS_GERMAN_PRE_REFORM, /*! deprecated !*/
340 &::getBooleanCppuType(), 0, 0 },
341 { MAP_CHAR_LEN(UPN_IS_HYPH_AUTO), WID_IS_HYPH_AUTO,
342 &::getBooleanCppuType(), 0, 0 },
343 { MAP_CHAR_LEN(UPN_IS_HYPH_SPECIAL), WID_IS_HYPH_SPECIAL,
344 &::getBooleanCppuType(), 0, 0 },
345 { MAP_CHAR_LEN(UPN_IS_IGNORE_CONTROL_CHARACTERS), WID_IS_IGNORE_CONTROL_CHARACTERS,
346 &::getBooleanCppuType(), 0, 0 },
347 { MAP_CHAR_LEN(UPN_IS_SPELL_AUTO), WID_IS_SPELL_AUTO,
348 &::getBooleanCppuType(), 0, 0 },
349 { MAP_CHAR_LEN(UPN_IS_SPELL_CAPITALIZATION), WID_IS_SPELL_CAPITALIZATION,
350 &::getBooleanCppuType(), 0, 0 },
351 { MAP_CHAR_LEN(UPN_IS_SPELL_HIDE), WID_IS_SPELL_HIDE, /*! deprecated !*/
352 &::getBooleanCppuType(), 0, 0 },
353 { MAP_CHAR_LEN(UPN_IS_SPELL_IN_ALL_LANGUAGES), WID_IS_SPELL_IN_ALL_LANGUAGES, /*! deprecated !*/
354 &::getBooleanCppuType(), 0, 0 },
355 { MAP_CHAR_LEN(UPN_IS_SPELL_SPECIAL), WID_IS_SPELL_SPECIAL,
356 &::getBooleanCppuType(), 0, 0 },
357 { MAP_CHAR_LEN(UPN_IS_SPELL_UPPER_CASE), WID_IS_SPELL_UPPER_CASE,
358 &::getBooleanCppuType(), 0, 0 },
359 { MAP_CHAR_LEN(UPN_IS_SPELL_WITH_DIGITS), WID_IS_SPELL_WITH_DIGITS,
360 &::getBooleanCppuType(), 0, 0 },
361 { MAP_CHAR_LEN(UPN_IS_USE_DICTIONARY_LIST), WID_IS_USE_DICTIONARY_LIST,
362 &::getBooleanCppuType(), 0, 0 },
363 { MAP_CHAR_LEN(UPN_IS_WRAP_REVERSE), WID_IS_WRAP_REVERSE,
364 &::getBooleanCppuType(), 0, 0 },
365 { 0,0,0,0,0,0 }
367 return aLinguProps;
369 LinguProps::LinguProps() :
370 aEvtListeners (GetLinguMutex()),
371 aPropListeners (GetLinguMutex()),
372 aPropertyMap(lcl_GetLinguProps())
374 bDisposing = FALSE;
377 void LinguProps::launchEvent( const PropertyChangeEvent &rEvt ) const
379 cppu::OInterfaceContainerHelper *pContainer =
380 aPropListeners.getContainer( rEvt.PropertyHandle );
381 if (pContainer)
383 cppu::OInterfaceIteratorHelper aIt( *pContainer );
384 while (aIt.hasMoreElements())
386 Reference< XPropertyChangeListener > xRef( aIt.next(), UNO_QUERY );
387 if (xRef.is())
388 xRef->propertyChange( rEvt );
393 Reference< XInterface > SAL_CALL LinguProps_CreateInstance(
394 const Reference< XMultiServiceFactory > & /*rSMgr*/ )
395 throw(Exception)
397 Reference< XInterface > xService = (cppu::OWeakObject*)new LinguProps;
398 return xService;
401 Reference< XPropertySetInfo > SAL_CALL LinguProps::getPropertySetInfo()
402 throw(RuntimeException)
404 MutexGuard aGuard( GetLinguMutex() );
406 static Reference< XPropertySetInfo > aRef =
407 new SfxItemPropertySetInfo( &aPropertyMap );
408 return aRef;
411 void SAL_CALL LinguProps::setPropertyValue(
412 const OUString& rPropertyName, const Any& rValue )
413 throw(UnknownPropertyException, PropertyVetoException,
414 IllegalArgumentException, WrappedTargetException, RuntimeException)
416 MutexGuard aGuard( GetLinguMutex() );
418 const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
419 if (pCur)
421 Any aOld( aConfig.GetProperty( pCur->nWID ) );
422 if (aOld != rValue && aConfig.SetProperty( pCur->nWID, rValue ))
424 PropertyChangeEvent aChgEvt( (XPropertySet *) this, rPropertyName,
425 FALSE, pCur->nWID, aOld, rValue );
426 launchEvent( aChgEvt );
429 #ifdef LINGU_EXCEPTIONS
430 else
432 throw UnknownPropertyException();
434 #endif
437 Any SAL_CALL LinguProps::getPropertyValue( const OUString& rPropertyName )
438 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
440 MutexGuard aGuard( GetLinguMutex() );
442 Any aRet;
444 const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
445 if(pCur)
447 aRet = aConfig.GetProperty( pCur->nWID );
449 #ifdef LINGU_EXCEPTIONS
450 else
452 throw UnknownPropertyException();
454 #endif
456 return aRet;
459 void SAL_CALL LinguProps::addPropertyChangeListener(
460 const OUString& rPropertyName,
461 const Reference< XPropertyChangeListener >& rxListener )
462 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
464 MutexGuard aGuard( GetLinguMutex() );
466 if (!bDisposing && rxListener.is())
468 const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
469 if(pCur)
470 aPropListeners.addInterface( pCur->nWID, rxListener );
471 #ifdef LINGU_EXCEPTIONS
472 else
474 throw UnknownPropertyException();
476 #endif
480 void SAL_CALL LinguProps::removePropertyChangeListener(
481 const OUString& rPropertyName,
482 const Reference< XPropertyChangeListener >& rxListener )
483 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
485 MutexGuard aGuard( GetLinguMutex() );
487 if (!bDisposing && rxListener.is())
489 const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
490 if(pCur)
491 aPropListeners.removeInterface( pCur->nWID, rxListener );
492 #ifdef LINGU_EXCEPTIONS
493 else
495 throw UnknownPropertyException();
497 #endif
501 void SAL_CALL LinguProps::addVetoableChangeListener(
502 const OUString& /*rPropertyName*/,
503 const Reference< XVetoableChangeListener >& /*xListener*/ )
504 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
506 // MutexGuard aGuard( GetLinguMutex() );
509 void SAL_CALL LinguProps::removeVetoableChangeListener(
510 const OUString& /*rPropertyName*/,
511 const Reference< XVetoableChangeListener >& /*xListener*/ )
512 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
514 // MutexGuard aGuard( GetLinguMutex() );
518 void SAL_CALL LinguProps::setFastPropertyValue( sal_Int32 nHandle, const Any& rValue )
519 throw(UnknownPropertyException, PropertyVetoException,
520 IllegalArgumentException, WrappedTargetException, RuntimeException)
522 MutexGuard aGuard( GetLinguMutex() );
524 Any aOld( aConfig.GetProperty( nHandle ) );
525 if (aOld != rValue && aConfig.SetProperty( nHandle, rValue ))
527 PropertyChangeEvent aChgEvt( (XPropertySet *) this,
528 LinguOptions::GetName( nHandle ), FALSE, nHandle, aOld, rValue );
529 launchEvent( aChgEvt );
534 Any SAL_CALL LinguProps::getFastPropertyValue( sal_Int32 nHandle )
535 throw(UnknownPropertyException, WrappedTargetException, RuntimeException)
537 MutexGuard aGuard( GetLinguMutex() );
539 Any aRes( aConfig.GetProperty( nHandle ) );
540 return aRes;
544 Sequence< PropertyValue > SAL_CALL
545 LinguProps::getPropertyValues()
546 throw(RuntimeException)
548 MutexGuard aGuard( GetLinguMutex() );
550 INT32 nLen = aPropertyMap.getSize();
551 Sequence< PropertyValue > aProps( nLen );
552 PropertyValue *pProp = aProps.getArray();
553 PropertyEntryVector_t aPropEntries = aPropertyMap.getPropertyEntries();
554 PropertyEntryVector_t::const_iterator aIt = aPropEntries.begin();
555 for (INT32 i = 0; i < nLen; ++i, ++aIt)
557 PropertyValue &rVal = pProp[i];
558 Any aAny( aConfig.GetProperty( aIt->nWID ) );
560 rVal.Name = aIt->sName;
561 rVal.Handle = aIt->nWID;
562 rVal.Value = aAny;
563 rVal.State = PropertyState_DIRECT_VALUE ;
565 return aProps;
568 void SAL_CALL
569 LinguProps::setPropertyValues( const Sequence< PropertyValue >& rProps )
570 throw(UnknownPropertyException, PropertyVetoException,
571 IllegalArgumentException, WrappedTargetException, RuntimeException)
573 MutexGuard aGuard( GetLinguMutex() );
575 INT32 nLen = rProps.getLength();
576 const PropertyValue *pVal = rProps.getConstArray();
577 for (INT32 i = 0; i < nLen; ++i)
579 const PropertyValue &rVal = pVal[i];
580 setPropertyValue( rVal.Name, rVal.Value );
584 void SAL_CALL
585 LinguProps::dispose()
586 throw(RuntimeException)
588 MutexGuard aGuard( GetLinguMutex() );
590 if (!bDisposing)
592 bDisposing = TRUE;
594 //! its too late to save the options here!
595 // (see AppExitListener for saving)
596 //aOpt.Save(); // save (possible) changes before exiting
598 EventObject aEvtObj( (XPropertySet *) this );
599 aEvtListeners.disposeAndClear( aEvtObj );
600 aPropListeners.disposeAndClear( aEvtObj );
604 void SAL_CALL
605 LinguProps::addEventListener( const Reference< XEventListener >& rxListener )
606 throw(RuntimeException)
608 MutexGuard aGuard( GetLinguMutex() );
610 if (!bDisposing && rxListener.is())
611 aEvtListeners.addInterface( rxListener );
614 void SAL_CALL
615 LinguProps::removeEventListener( const Reference< XEventListener >& rxListener )
616 throw(RuntimeException)
618 MutexGuard aGuard( GetLinguMutex() );
620 if (!bDisposing && rxListener.is())
621 aEvtListeners.removeInterface( rxListener );
625 ///////////////////////////////////////////////////////////////////////////
626 // Service specific part
629 // XServiceInfo
630 OUString SAL_CALL LinguProps::getImplementationName()
631 throw(RuntimeException)
633 MutexGuard aGuard( GetLinguMutex() );
634 return getImplementationName_Static();
637 // XServiceInfo
638 sal_Bool SAL_CALL LinguProps::supportsService( const OUString& ServiceName )
639 throw(RuntimeException)
641 MutexGuard aGuard( GetLinguMutex() );
643 uno::Sequence< OUString > aSNL = getSupportedServiceNames();
644 const OUString * pArray = aSNL.getConstArray();
645 for( INT32 i = 0; i < aSNL.getLength(); i++ )
646 if( pArray[i] == ServiceName )
647 return TRUE;
648 return FALSE;
651 // XServiceInfo
652 uno::Sequence< OUString > SAL_CALL LinguProps::getSupportedServiceNames()
653 throw(RuntimeException)
655 MutexGuard aGuard( GetLinguMutex() );
656 return getSupportedServiceNames_Static();
659 // ORegistryServiceManager_Static
660 uno::Sequence< OUString > LinguProps::getSupportedServiceNames_Static()
661 throw()
663 MutexGuard aGuard( GetLinguMutex() );
665 uno::Sequence< OUString > aSNS( 1 ); // auch mehr als 1 Service moeglich
666 aSNS.getArray()[0] = A2OU( SN_LINGU_PROPERTIES );
667 return aSNS;
671 sal_Bool SAL_CALL LinguProps_writeInfo( void * /*pServiceManager*/,
672 XRegistryKey * pRegistryKey )
676 String aImpl( '/' );
677 aImpl += LinguProps::getImplementationName_Static().getStr();
678 aImpl.AppendAscii( "/UNO/SERVICES" );
679 Reference< XRegistryKey > xNewKey =
680 pRegistryKey->createKey(aImpl );
681 uno::Sequence< OUString > aServices = LinguProps::getSupportedServiceNames_Static();
682 for( INT32 i = 0; i < aServices.getLength(); i++ )
683 xNewKey->createKey( aServices.getConstArray()[i]);
685 return sal_True;
687 catch(Exception &)
689 return sal_False;
693 void * SAL_CALL LinguProps_getFactory( const sal_Char * pImplName,
694 XMultiServiceFactory *pServiceManager, void * )
696 void * pRet = 0;
697 if ( !LinguProps::getImplementationName_Static().compareToAscii( pImplName ) )
699 Reference< XSingleServiceFactory > xFactory =
700 cppu::createOneInstanceFactory(
701 pServiceManager,
702 LinguProps::getImplementationName_Static(),
703 LinguProps_CreateInstance,
704 LinguProps::getSupportedServiceNames_Static());
705 // acquire, because we return an interface pointer instead of a reference
706 xFactory->acquire();
707 pRet = xFactory.get();
709 return pRet;
712 ///////////////////////////////////////////////////////////////////////////