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 {
390 Reference< XInterface > xService = (cppu::OWeakObject*)new LinguProps;
391 return xService;
392 }
393
getPropertySetInfo()394 Reference< XPropertySetInfo > SAL_CALL LinguProps::getPropertySetInfo()
395 {
396 MutexGuard aGuard( GetLinguMutex() );
397
398 static Reference< XPropertySetInfo > aRef =
399 new SfxItemPropertySetInfo( &aPropertyMap );
400 return aRef;
401 }
402
setPropertyValue(const OUString & rPropertyName,const Any & rValue)403 void SAL_CALL LinguProps::setPropertyValue(
404 const OUString& rPropertyName, const Any& rValue )
405 {
406 MutexGuard aGuard( GetLinguMutex() );
407
408 const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
409 if (pCur)
410 {
411 Any aOld( aConfig.GetProperty( pCur->nWID ) );
412 if (aOld != rValue && aConfig.SetProperty( pCur->nWID, rValue ))
413 {
414 PropertyChangeEvent aChgEvt( (XPropertySet *) this, rPropertyName,
415 sal_False, pCur->nWID, aOld, rValue );
416 launchEvent( aChgEvt );
417 }
418 }
419 #ifdef LINGU_EXCEPTIONS
420 else
421 {
422 throw UnknownPropertyException();
423 }
424 #endif
425 }
426
getPropertyValue(const OUString & rPropertyName)427 Any SAL_CALL LinguProps::getPropertyValue( const OUString& rPropertyName )
428 {
429 MutexGuard aGuard( GetLinguMutex() );
430
431 Any aRet;
432
433 const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
434 if(pCur)
435 {
436 aRet = aConfig.GetProperty( pCur->nWID );
437 }
438 #ifdef LINGU_EXCEPTIONS
439 else
440 {
441 throw UnknownPropertyException();
442 }
443 #endif
444
445 return aRet;
446 }
447
addPropertyChangeListener(const OUString & rPropertyName,const Reference<XPropertyChangeListener> & rxListener)448 void SAL_CALL LinguProps::addPropertyChangeListener(
449 const OUString& rPropertyName,
450 const Reference< XPropertyChangeListener >& rxListener )
451 {
452 MutexGuard aGuard( GetLinguMutex() );
453
454 if (!bDisposing && rxListener.is())
455 {
456 const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
457 if(pCur)
458 aPropListeners.addInterface( pCur->nWID, rxListener );
459 #ifdef LINGU_EXCEPTIONS
460 else
461 {
462 throw UnknownPropertyException();
463 }
464 #endif
465 }
466 }
467
removePropertyChangeListener(const OUString & rPropertyName,const Reference<XPropertyChangeListener> & rxListener)468 void SAL_CALL LinguProps::removePropertyChangeListener(
469 const OUString& rPropertyName,
470 const Reference< XPropertyChangeListener >& rxListener )
471 {
472 MutexGuard aGuard( GetLinguMutex() );
473
474 if (!bDisposing && rxListener.is())
475 {
476 const SfxItemPropertySimpleEntry* pCur = aPropertyMap.getByName( rPropertyName );
477 if(pCur)
478 aPropListeners.removeInterface( pCur->nWID, rxListener );
479 #ifdef LINGU_EXCEPTIONS
480 else
481 {
482 throw UnknownPropertyException();
483 }
484 #endif
485 }
486 }
487
addVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)488 void SAL_CALL LinguProps::addVetoableChangeListener(
489 const OUString& /*rPropertyName*/,
490 const Reference< XVetoableChangeListener >& /*xListener*/ )
491 {
492 // MutexGuard aGuard( GetLinguMutex() );
493 }
494
removeVetoableChangeListener(const OUString &,const Reference<XVetoableChangeListener> &)495 void SAL_CALL LinguProps::removeVetoableChangeListener(
496 const OUString& /*rPropertyName*/,
497 const Reference< XVetoableChangeListener >& /*xListener*/ )
498 {
499 // MutexGuard aGuard( GetLinguMutex() );
500 }
501
502
setFastPropertyValue(sal_Int32 nHandle,const Any & rValue)503 void SAL_CALL LinguProps::setFastPropertyValue( sal_Int32 nHandle, const Any& rValue )
504 {
505 MutexGuard aGuard( GetLinguMutex() );
506
507 Any aOld( aConfig.GetProperty( nHandle ) );
508 if (aOld != rValue && aConfig.SetProperty( nHandle, rValue ))
509 {
510 PropertyChangeEvent aChgEvt( (XPropertySet *) this,
511 LinguOptions::GetName( nHandle ), sal_False, nHandle, aOld, rValue );
512 launchEvent( aChgEvt );
513 }
514 }
515
516
getFastPropertyValue(sal_Int32 nHandle)517 Any SAL_CALL LinguProps::getFastPropertyValue( sal_Int32 nHandle )
518 {
519 MutexGuard aGuard( GetLinguMutex() );
520
521 Any aRes( aConfig.GetProperty( nHandle ) );
522 return aRes;
523 }
524
525
526 Sequence< PropertyValue > SAL_CALL
getPropertyValues()527 LinguProps::getPropertyValues()
528 {
529 MutexGuard aGuard( GetLinguMutex() );
530
531 sal_Int32 nLen = aPropertyMap.getSize();
532 Sequence< PropertyValue > aProps( nLen );
533 PropertyValue *pProp = aProps.getArray();
534 PropertyEntryVector_t aPropEntries = aPropertyMap.getPropertyEntries();
535 PropertyEntryVector_t::const_iterator aIt = aPropEntries.begin();
536 for (sal_Int32 i = 0; i < nLen; ++i, ++aIt)
537 {
538 PropertyValue &rVal = pProp[i];
539 Any aAny( aConfig.GetProperty( aIt->nWID ) );
540
541 rVal.Name = aIt->sName;
542 rVal.Handle = aIt->nWID;
543 rVal.Value = aAny;
544 rVal.State = PropertyState_DIRECT_VALUE ;
545 }
546 return aProps;
547 }
548
549 void SAL_CALL
setPropertyValues(const Sequence<PropertyValue> & rProps)550 LinguProps::setPropertyValues( const Sequence< PropertyValue >& rProps )
551 {
552 MutexGuard aGuard( GetLinguMutex() );
553
554 sal_Int32 nLen = rProps.getLength();
555 const PropertyValue *pVal = rProps.getConstArray();
556 for (sal_Int32 i = 0; i < nLen; ++i)
557 {
558 const PropertyValue &rVal = pVal[i];
559 setPropertyValue( rVal.Name, rVal.Value );
560 }
561 }
562
563 void SAL_CALL
dispose()564 LinguProps::dispose()
565 {
566 MutexGuard aGuard( GetLinguMutex() );
567
568 if (!bDisposing)
569 {
570 bDisposing = sal_True;
571
572 //! its too late to save the options here!
573 // (see AppExitListener for saving)
574 //aOpt.Save(); // save (possible) changes before exiting
575
576 EventObject aEvtObj( (XPropertySet *) this );
577 aEvtListeners.disposeAndClear( aEvtObj );
578 aPropListeners.disposeAndClear( aEvtObj );
579 }
580 }
581
582 void SAL_CALL
addEventListener(const Reference<XEventListener> & rxListener)583 LinguProps::addEventListener( const Reference< XEventListener >& rxListener )
584 {
585 MutexGuard aGuard( GetLinguMutex() );
586
587 if (!bDisposing && rxListener.is())
588 aEvtListeners.addInterface( rxListener );
589 }
590
591 void SAL_CALL
removeEventListener(const Reference<XEventListener> & rxListener)592 LinguProps::removeEventListener( const Reference< XEventListener >& rxListener )
593 {
594 MutexGuard aGuard( GetLinguMutex() );
595
596 if (!bDisposing && rxListener.is())
597 aEvtListeners.removeInterface( rxListener );
598 }
599
600
601 ///////////////////////////////////////////////////////////////////////////
602 // Service specific part
603 //
604
605 // XServiceInfo
getImplementationName()606 OUString SAL_CALL LinguProps::getImplementationName()
607 {
608 MutexGuard aGuard( GetLinguMutex() );
609 return getImplementationName_Static();
610 }
611
612 // XServiceInfo
supportsService(const OUString & ServiceName)613 sal_Bool SAL_CALL LinguProps::supportsService( const OUString& ServiceName )
614 {
615 MutexGuard aGuard( GetLinguMutex() );
616
617 uno::Sequence< OUString > aSNL = getSupportedServiceNames();
618 const OUString * pArray = aSNL.getConstArray();
619 for( sal_Int32 i = 0; i < aSNL.getLength(); i++ )
620 if( pArray[i] == ServiceName )
621 return sal_True;
622 return sal_False;
623 }
624
625 // XServiceInfo
getSupportedServiceNames()626 uno::Sequence< OUString > SAL_CALL LinguProps::getSupportedServiceNames()
627 {
628 MutexGuard aGuard( GetLinguMutex() );
629 return getSupportedServiceNames_Static();
630 }
631
632 // ORegistryServiceManager_Static
getSupportedServiceNames_Static()633 uno::Sequence< OUString > LinguProps::getSupportedServiceNames_Static()
634 throw()
635 {
636 MutexGuard aGuard( GetLinguMutex() );
637
638 uno::Sequence< OUString > aSNS( 1 ); // auch mehr als 1 Service moeglich
639 aSNS.getArray()[0] = A2OU( SN_LINGU_PROPERTIES );
640 return aSNS;
641 }
642
LinguProps_getFactory(const sal_Char * pImplName,XMultiServiceFactory * pServiceManager,void *)643 void * SAL_CALL LinguProps_getFactory( const sal_Char * pImplName,
644 XMultiServiceFactory *pServiceManager, void * )
645 {
646 void * pRet = 0;
647 if ( !LinguProps::getImplementationName_Static().compareToAscii( pImplName ) )
648 {
649 Reference< XSingleServiceFactory > xFactory =
650 cppu::createOneInstanceFactory(
651 pServiceManager,
652 LinguProps::getImplementationName_Static(),
653 LinguProps_CreateInstance,
654 LinguProps::getSupportedServiceNames_Static());
655 // acquire, because we return an interface pointer instead of a reference
656 xFactory->acquire();
657 pRet = xFactory.get();
658 }
659 return pRet;
660 }
661
662 ///////////////////////////////////////////////////////////////////////////
663