1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: lingucfg.cxx,v $
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_svtools.hxx"
35 #include <com/sun/star/lang/Locale.hpp>
36 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
37 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
38 #include <com/sun/star/container/XNameAccess.hpp>
39 #include <com/sun/star/container/XNameContainer.hpp>
40 #include <com/sun/star/container/XNameReplace.hpp>
41 #include "com/sun/star/util/XMacroExpander.hpp"
42 #include "com/sun/star/beans/XPropertySet.hpp"
43 #include <rtl/uri.hxx>
44 #include <vos/mutex.hxx>
45 #include <i18npool/mslangid.hxx>
46 #include <tools/debug.hxx>
47 #include <vcl/svapp.hxx>
48 #include <svtools/lingucfg.hxx>
49 #include <linguprops.hxx>
51 #include <comphelper/processfactory.hxx>
53 #include <itemholder1.hxx>
56 using namespace com::sun::star
;
58 #define A2OU(x) ::rtl::OUString::createFromAscii( x )
59 #define EXPAND_PROTOCOL "vnd.sun.star.expand:"
60 #define FILE_PROTOCOL "file:///"
62 ///////////////////////////////////////////////////////////////////////////
65 static osl::Mutex
& GetOwnMutex()
67 static osl::Mutex aMutex
;
72 ///////////////////////////////////////////////////////////////////////////
75 static BOOL
lcl_SetLocale( INT16
&rLanguage
, const uno::Any
&rVal
)
80 if (rVal
>>= aNew
) // conversion successful?
82 INT16 nNew
= MsLangId::convertLocaleToLanguage( aNew
);
83 if (nNew
!= rLanguage
)
93 static inline const OUString
lcl_LanguageToCfgLocaleStr( INT16 nLanguage
)
96 if (LANGUAGE_SYSTEM
!= nLanguage
)
97 aRes
= MsLangId::convertLanguageToIsoString( nLanguage
);
102 static INT16
lcl_CfgAnyToLanguage( const uno::Any
&rVal
)
106 return (aTmp
.getLength() == 0) ? LANGUAGE_SYSTEM
: MsLangId::convertIsoStringToLanguage( aTmp
);
110 //////////////////////////////////////////////////////////////////////
112 SvtLinguOptions::SvtLinguOptions()
114 nDefaultLanguage
= LANGUAGE_NONE
;
115 nDefaultLanguage_CJK
= LANGUAGE_NONE
;
116 nDefaultLanguage_CTL
= LANGUAGE_NONE
;
119 bIsUseDictionaryList
=
120 bIsIgnoreControlCharacters
= TRUE
;
123 bIsSpellCapitalization
=
124 bIsSpellSpecial
= TRUE
;
128 bIsSpellUpperCase
= FALSE
;
130 // text conversion options
131 bIsIgnorePostPositionalWord
= TRUE
;
133 bIsShowEntriesRecentlyUsedFirst
=
134 bIsAutoReplaceUniqueEntries
= FALSE
;
135 bIsDirectionToSimplified
= TRUE
;
136 bIsUseCharacterVariants
=
137 bIsTranslateCommonTerms
=
138 bIsReverseMapping
= FALSE
;
140 bROIsDirectionToSimplified
=
141 bROIsUseCharacterVariants
=
142 bROIsTranslateCommonTerms
=
143 bROIsReverseMapping
= FALSE
;
145 // hyphenation options
146 bIsHyphSpecial
= TRUE
;
149 nHyphMinTrailing
= 2;
150 nHyphMinWordLength
= 0;
152 nDataFilesChangedCheckValue
= 0;
155 bIsGrammarAuto
= sal_False
,
156 bIsGrammarInteractive
= sal_False
;
161 //////////////////////////////////////////////////////////////////////
164 class SvtLinguConfigItem
: public utl::ConfigItem
166 SvtLinguOptions aOpt
;
168 // disallow copy-constructor and assignment-operator for now
169 SvtLinguConfigItem( const SvtLinguConfigItem
& );
170 SvtLinguConfigItem
& operator = ( const SvtLinguConfigItem
& );
172 static BOOL
GetHdlByName( INT32
&rnHdl
, const OUString
&rPropertyName
, sal_Bool bFullPropName
= sal_False
);
173 static const uno::Sequence
< OUString
> & GetPropertyNames();
174 BOOL
LoadOptions( const uno::Sequence
< OUString
> &rProperyNames
);
175 BOOL
SaveOptions( const uno::Sequence
< OUString
> &rProperyNames
);
178 SvtLinguConfigItem();
179 virtual ~SvtLinguConfigItem();
182 virtual void Notify( const com::sun::star::uno::Sequence
< rtl::OUString
> &rPropertyNames
);
183 virtual void Commit();
185 // make some protected functions of utl::ConfigItem public
186 using utl::ConfigItem::GetNodeNames
;
187 using utl::ConfigItem::GetProperties
;
188 //using utl::ConfigItem::PutProperties;
189 //using utl::ConfigItem::SetSetProperties;
190 using utl::ConfigItem::ReplaceSetProperties
;
191 //using utl::ConfigItem::GetReadOnlyStates;
194 com::sun::star::uno::Any
195 GetProperty( const rtl::OUString
&rPropertyName
) const;
196 com::sun::star::uno::Any
197 GetProperty( INT32 nPropertyHandle
) const;
199 BOOL
SetProperty( const rtl::OUString
&rPropertyName
,
200 const com::sun::star::uno::Any
&rValue
);
201 BOOL
SetProperty( INT32 nPropertyHandle
,
202 const com::sun::star::uno::Any
&rValue
);
204 BOOL
GetOptions( SvtLinguOptions
&rOptions
) const;
205 BOOL
SetOptions( const SvtLinguOptions
&rOptions
);
207 BOOL
IsReadOnly( const rtl::OUString
&rPropertyName
) const;
208 BOOL
IsReadOnly( INT32 nPropertyHandle
) const;
212 SvtLinguConfigItem::SvtLinguConfigItem() :
213 utl::ConfigItem( String::CreateFromAscii( "Office.Linguistic" ) )
215 LoadOptions( GetPropertyNames() );
218 // request notify events when properties change
219 EnableNotification( GetPropertyNames() );
223 SvtLinguConfigItem::~SvtLinguConfigItem()
225 //! Commit (SaveOptions) will be called by the d-tor of the base called !
229 void SvtLinguConfigItem::Notify( const uno::Sequence
< OUString
> &rPropertyNames
)
231 LoadOptions( rPropertyNames
);
235 void SvtLinguConfigItem::Commit()
237 SaveOptions( GetPropertyNames() );
241 static struct NamesToHdl
243 const char *pFullPropName
; // full qualified name as used in configuration
244 const char *pPropName
; // property name only (atom) of above
245 INT32 nHdl
; // numeric handle representing the property
248 {/* 0 */ "General/DefaultLocale", UPN_DEFAULT_LOCALE
, UPH_DEFAULT_LOCALE
},
249 {/* 1 */ "General/DictionaryList/ActiveDictionaries", UPN_ACTIVE_DICTIONARIES
, UPH_ACTIVE_DICTIONARIES
},
250 {/* 2 */ "General/DictionaryList/IsUseDictionaryList", UPN_IS_USE_DICTIONARY_LIST
, UPH_IS_USE_DICTIONARY_LIST
},
251 {/* 3 */ "General/IsIgnoreControlCharacters", UPN_IS_IGNORE_CONTROL_CHARACTERS
, UPH_IS_IGNORE_CONTROL_CHARACTERS
},
252 {/* 5 */ "General/DefaultLocale_CJK", UPN_DEFAULT_LOCALE_CJK
, UPH_DEFAULT_LOCALE_CJK
},
253 {/* 6 */ "General/DefaultLocale_CTL", UPN_DEFAULT_LOCALE_CTL
, UPH_DEFAULT_LOCALE_CTL
},
255 {/* 7 */ "SpellChecking/IsSpellUpperCase", UPN_IS_SPELL_UPPER_CASE
, UPH_IS_SPELL_UPPER_CASE
},
256 {/* 8 */ "SpellChecking/IsSpellWithDigits", UPN_IS_SPELL_WITH_DIGITS
, UPH_IS_SPELL_WITH_DIGITS
},
257 {/* 9 */ "SpellChecking/IsSpellCapitalization", UPN_IS_SPELL_CAPITALIZATION
, UPH_IS_SPELL_CAPITALIZATION
},
258 {/* 10 */ "SpellChecking/IsSpellAuto", UPN_IS_SPELL_AUTO
, UPH_IS_SPELL_AUTO
},
259 {/* 11 */ "SpellChecking/IsSpellSpecial", UPN_IS_SPELL_SPECIAL
, UPH_IS_SPELL_SPECIAL
},
260 {/* 14 */ "SpellChecking/IsReverseDirection", UPN_IS_WRAP_REVERSE
, UPH_IS_WRAP_REVERSE
},
262 {/* 15 */ "Hyphenation/MinLeading", UPN_HYPH_MIN_LEADING
, UPH_HYPH_MIN_LEADING
},
263 {/* 16 */ "Hyphenation/MinTrailing", UPN_HYPH_MIN_TRAILING
, UPH_HYPH_MIN_TRAILING
},
264 {/* 17 */ "Hyphenation/MinWordLength", UPN_HYPH_MIN_WORD_LENGTH
, UPH_HYPH_MIN_WORD_LENGTH
},
265 {/* 18 */ "Hyphenation/IsHyphSpecial", UPN_IS_HYPH_SPECIAL
, UPH_IS_HYPH_SPECIAL
},
266 {/* 19 */ "Hyphenation/IsHyphAuto", UPN_IS_HYPH_AUTO
, UPH_IS_HYPH_AUTO
},
268 {/* 20 */ "TextConversion/ActiveConversionDictionaries", UPN_ACTIVE_CONVERSION_DICTIONARIES
, UPH_ACTIVE_CONVERSION_DICTIONARIES
},
269 {/* 21 */ "TextConversion/IsIgnorePostPositionalWord", UPN_IS_IGNORE_POST_POSITIONAL_WORD
, UPH_IS_IGNORE_POST_POSITIONAL_WORD
},
270 {/* 22 */ "TextConversion/IsAutoCloseDialog", UPN_IS_AUTO_CLOSE_DIALOG
, UPH_IS_AUTO_CLOSE_DIALOG
},
271 {/* 23 */ "TextConversion/IsShowEntriesRecentlyUsedFirst", UPN_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
, UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
},
272 {/* 24 */ "TextConversion/IsAutoReplaceUniqueEntries", UPN_IS_AUTO_REPLACE_UNIQUE_ENTRIES
, UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
},
273 {/* 25 */ "TextConversion/IsDirectionToSimplified", UPN_IS_DIRECTION_TO_SIMPLIFIED
, UPH_IS_DIRECTION_TO_SIMPLIFIED
},
274 {/* 26 */ "TextConversion/IsUseCharacterVariants", UPN_IS_USE_CHARACTER_VARIANTS
, UPH_IS_USE_CHARACTER_VARIANTS
},
275 {/* 27 */ "TextConversion/IsTranslateCommonTerms", UPN_IS_TRANSLATE_COMMON_TERMS
, UPH_IS_TRANSLATE_COMMON_TERMS
},
276 {/* 28 */ "TextConversion/IsReverseMapping", UPN_IS_REVERSE_MAPPING
, UPH_IS_REVERSE_MAPPING
},
278 {/* 29 */ "ServiceManager/DataFilesChangedCheckValue", UPN_DATA_FILES_CHANGED_CHECK_VALUE
, UPH_DATA_FILES_CHANGED_CHECK_VALUE
},
280 {/* 30 */ "GrammarChecking/IsAutoCheck", UPN_IS_GRAMMAR_AUTO
, UPH_IS_GRAMMAR_AUTO
},
281 {/* 31 */ "GrammarChecking/IsInteractiveCheck", UPN_IS_GRAMMAR_INTERACTIVE
, UPH_IS_GRAMMAR_INTERACTIVE
},
283 /* similar to entry 0 (thus no own configuration entry) but with different property name and type */
284 { NULL
, UPN_DEFAULT_LANGUAGE
, UPH_DEFAULT_LANGUAGE
},
290 const uno::Sequence
< OUString
> & SvtLinguConfigItem::GetPropertyNames()
292 static uno::Sequence
< OUString
> aNames
;
293 static sal_Bool bInitialized
= sal_False
;
297 INT32 nMax
= sizeof(aNamesToHdl
) / sizeof(aNamesToHdl
[0]);
299 aNames
.realloc( nMax
);
300 OUString
*pNames
= aNames
.getArray();
302 for (INT32 i
= 0; i
< nMax
; ++i
)
304 const sal_Char
*pFullPropName
= aNamesToHdl
[i
].pFullPropName
;
306 pNames
[ nIdx
++ ] = A2OU( pFullPropName
);
308 aNames
.realloc( nIdx
);
309 bInitialized
= sal_True
;
315 BOOL
SvtLinguConfigItem::GetHdlByName(
317 const OUString
&rPropertyName
,
318 sal_Bool bFullPropName
)
320 NamesToHdl
*pEntry
= &aNamesToHdl
[0];
324 while (pEntry
&& pEntry
->pFullPropName
!= NULL
)
326 if (0 == rPropertyName
.compareToAscii( pEntry
->pFullPropName
))
328 rnHdl
= pEntry
->nHdl
;
333 return pEntry
&& pEntry
->pFullPropName
!= NULL
;
337 while (pEntry
&& pEntry
->pPropName
!= NULL
)
339 if (0 == rPropertyName
.compareToAscii( pEntry
->pPropName
))
341 rnHdl
= pEntry
->nHdl
;
346 return pEntry
&& pEntry
->pPropName
!= NULL
;
351 uno::Any
SvtLinguConfigItem::GetProperty( const OUString
&rPropertyName
) const
353 osl::MutexGuard
aGuard( GetOwnMutex() );
356 return GetHdlByName( nHdl
, rPropertyName
) ? GetProperty( nHdl
) : uno::Any();
360 uno::Any
SvtLinguConfigItem::GetProperty( INT32 nPropertyHandle
) const
362 osl::MutexGuard
aGuard( GetOwnMutex() );
366 const INT16
*pnVal
= 0;
367 const BOOL
*pbVal
= 0;
368 const INT32
*pnInt32Val
= 0;
370 const SvtLinguOptions
&rOpt
= const_cast< SvtLinguConfigItem
* >(this)->aOpt
;
371 switch (nPropertyHandle
)
373 case UPH_IS_USE_DICTIONARY_LIST
: pbVal
= &rOpt
.bIsUseDictionaryList
; break;
374 case UPH_IS_IGNORE_CONTROL_CHARACTERS
: pbVal
= &rOpt
.bIsIgnoreControlCharacters
; break;
375 case UPH_IS_HYPH_AUTO
: pbVal
= &rOpt
.bIsHyphAuto
; break;
376 case UPH_IS_HYPH_SPECIAL
: pbVal
= &rOpt
.bIsHyphSpecial
; break;
377 case UPH_IS_SPELL_AUTO
: pbVal
= &rOpt
.bIsSpellAuto
; break;
378 case UPH_IS_SPELL_SPECIAL
: pbVal
= &rOpt
.bIsSpellSpecial
; break;
379 case UPH_IS_WRAP_REVERSE
: pbVal
= &rOpt
.bIsSpellReverse
; break;
380 case UPH_DEFAULT_LANGUAGE
: pnVal
= &rOpt
.nDefaultLanguage
; break;
381 case UPH_IS_SPELL_CAPITALIZATION
: pbVal
= &rOpt
.bIsSpellCapitalization
; break;
382 case UPH_IS_SPELL_WITH_DIGITS
: pbVal
= &rOpt
.bIsSpellWithDigits
; break;
383 case UPH_IS_SPELL_UPPER_CASE
: pbVal
= &rOpt
.bIsSpellUpperCase
; break;
384 case UPH_HYPH_MIN_LEADING
: pnVal
= &rOpt
.nHyphMinLeading
; break;
385 case UPH_HYPH_MIN_TRAILING
: pnVal
= &rOpt
.nHyphMinTrailing
; break;
386 case UPH_HYPH_MIN_WORD_LENGTH
: pnVal
= &rOpt
.nHyphMinWordLength
; break;
387 case UPH_ACTIVE_DICTIONARIES
:
389 aRes
<<= rOpt
.aActiveDics
;
392 case UPH_ACTIVE_CONVERSION_DICTIONARIES
:
394 aRes
<<= rOpt
.aActiveConvDics
;
397 case UPH_DEFAULT_LOCALE
:
399 lang::Locale
aLocale( MsLangId::convertLanguageToLocale( rOpt
.nDefaultLanguage
, false ) );
400 aRes
.setValue( &aLocale
, ::getCppuType((lang::Locale
*)0 ));
403 case UPH_DEFAULT_LOCALE_CJK
:
405 lang::Locale
aLocale( MsLangId::convertLanguageToLocale( rOpt
.nDefaultLanguage_CJK
, false ) );
406 aRes
.setValue( &aLocale
, ::getCppuType((lang::Locale
*)0 ));
409 case UPH_DEFAULT_LOCALE_CTL
:
411 lang::Locale
aLocale( MsLangId::convertLanguageToLocale( rOpt
.nDefaultLanguage_CTL
, false ) );
412 aRes
.setValue( &aLocale
, ::getCppuType((lang::Locale
*)0 ));
415 case UPH_IS_IGNORE_POST_POSITIONAL_WORD
: pbVal
= &rOpt
.bIsIgnorePostPositionalWord
; break;
416 case UPH_IS_AUTO_CLOSE_DIALOG
: pbVal
= &rOpt
.bIsAutoCloseDialog
; break;
417 case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
: pbVal
= &rOpt
.bIsShowEntriesRecentlyUsedFirst
; break;
418 case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
: pbVal
= &rOpt
.bIsAutoReplaceUniqueEntries
; break;
420 case UPH_IS_DIRECTION_TO_SIMPLIFIED
: pbVal
= &rOpt
.bIsDirectionToSimplified
; break;
421 case UPH_IS_USE_CHARACTER_VARIANTS
: pbVal
= &rOpt
.bIsUseCharacterVariants
; break;
422 case UPH_IS_TRANSLATE_COMMON_TERMS
: pbVal
= &rOpt
.bIsTranslateCommonTerms
; break;
423 case UPH_IS_REVERSE_MAPPING
: pbVal
= &rOpt
.bIsReverseMapping
; break;
425 case UPH_DATA_FILES_CHANGED_CHECK_VALUE
: pnInt32Val
= &rOpt
.nDataFilesChangedCheckValue
; break;
426 case UPH_IS_GRAMMAR_AUTO
: pbVal
= &rOpt
.bIsGrammarAuto
; break;
427 case UPH_IS_GRAMMAR_INTERACTIVE
: pbVal
= &rOpt
.bIsGrammarInteractive
; break;
429 DBG_ASSERT( 0, "unexpected property handle" );
437 aRes
<<= *pnInt32Val
;
443 BOOL
SvtLinguConfigItem::SetProperty( const OUString
&rPropertyName
, const uno::Any
&rValue
)
445 osl::MutexGuard
aGuard( GetOwnMutex() );
449 if (GetHdlByName( nHdl
, rPropertyName
))
450 bSucc
= SetProperty( nHdl
, rValue
);
455 BOOL
SvtLinguConfigItem::SetProperty( INT32 nPropertyHandle
, const uno::Any
&rValue
)
457 osl::MutexGuard
aGuard( GetOwnMutex() );
460 if (!rValue
.hasValue())
467 INT32
*pnInt32Val
= 0;
469 SvtLinguOptions
&rOpt
= aOpt
;
470 switch (nPropertyHandle
)
472 case UPH_IS_USE_DICTIONARY_LIST
: pbVal
= &rOpt
.bIsUseDictionaryList
; break;
473 case UPH_IS_IGNORE_CONTROL_CHARACTERS
: pbVal
= &rOpt
.bIsIgnoreControlCharacters
; break;
474 case UPH_IS_HYPH_AUTO
: pbVal
= &rOpt
.bIsHyphAuto
; break;
475 case UPH_IS_HYPH_SPECIAL
: pbVal
= &rOpt
.bIsHyphSpecial
; break;
476 case UPH_IS_SPELL_AUTO
: pbVal
= &rOpt
.bIsSpellAuto
; break;
477 case UPH_IS_SPELL_SPECIAL
: pbVal
= &rOpt
.bIsSpellSpecial
; break;
478 case UPH_IS_WRAP_REVERSE
: pbVal
= &rOpt
.bIsSpellReverse
; break;
479 case UPH_DEFAULT_LANGUAGE
: pnVal
= &rOpt
.nDefaultLanguage
; break;
480 case UPH_IS_SPELL_CAPITALIZATION
: pbVal
= &rOpt
.bIsSpellCapitalization
; break;
481 case UPH_IS_SPELL_WITH_DIGITS
: pbVal
= &rOpt
.bIsSpellWithDigits
; break;
482 case UPH_IS_SPELL_UPPER_CASE
: pbVal
= &rOpt
.bIsSpellUpperCase
; break;
483 case UPH_HYPH_MIN_LEADING
: pnVal
= &rOpt
.nHyphMinLeading
; break;
484 case UPH_HYPH_MIN_TRAILING
: pnVal
= &rOpt
.nHyphMinTrailing
; break;
485 case UPH_HYPH_MIN_WORD_LENGTH
: pnVal
= &rOpt
.nHyphMinWordLength
; break;
486 case UPH_ACTIVE_DICTIONARIES
:
488 rValue
>>= rOpt
.aActiveDics
;
492 case UPH_ACTIVE_CONVERSION_DICTIONARIES
:
494 rValue
>>= rOpt
.aActiveConvDics
;
498 case UPH_DEFAULT_LOCALE
:
500 bSucc
= lcl_SetLocale( rOpt
.nDefaultLanguage
, rValue
);
504 case UPH_DEFAULT_LOCALE_CJK
:
506 bSucc
= lcl_SetLocale( rOpt
.nDefaultLanguage_CJK
, rValue
);
510 case UPH_DEFAULT_LOCALE_CTL
:
512 bSucc
= lcl_SetLocale( rOpt
.nDefaultLanguage_CTL
, rValue
);
516 case UPH_IS_IGNORE_POST_POSITIONAL_WORD
: pbVal
= &rOpt
.bIsIgnorePostPositionalWord
; break;
517 case UPH_IS_AUTO_CLOSE_DIALOG
: pbVal
= &rOpt
.bIsAutoCloseDialog
; break;
518 case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
: pbVal
= &rOpt
.bIsShowEntriesRecentlyUsedFirst
; break;
519 case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
: pbVal
= &rOpt
.bIsAutoReplaceUniqueEntries
; break;
521 case UPH_IS_DIRECTION_TO_SIMPLIFIED
: pbVal
= &rOpt
.bIsDirectionToSimplified
; break;
522 case UPH_IS_USE_CHARACTER_VARIANTS
: pbVal
= &rOpt
.bIsUseCharacterVariants
; break;
523 case UPH_IS_TRANSLATE_COMMON_TERMS
: pbVal
= &rOpt
.bIsTranslateCommonTerms
; break;
524 case UPH_IS_REVERSE_MAPPING
: pbVal
= &rOpt
.bIsReverseMapping
; break;
526 case UPH_DATA_FILES_CHANGED_CHECK_VALUE
: pnInt32Val
= &rOpt
.nDataFilesChangedCheckValue
; break;
527 case UPH_IS_GRAMMAR_AUTO
: pbVal
= &rOpt
.bIsGrammarAuto
; break;
528 case UPH_IS_GRAMMAR_INTERACTIVE
: pbVal
= &rOpt
.bIsGrammarInteractive
; break;
530 DBG_ASSERT( 0, "unexpected property handle" );
548 INT16 nNew
= INT16();
561 INT32 nNew
= INT32();
564 if (nNew
!= *pnInt32Val
)
580 BOOL
SvtLinguConfigItem::GetOptions( SvtLinguOptions
&rOptions
) const
582 osl::MutexGuard
aGuard( GetOwnMutex() );
589 BOOL
SvtLinguConfigItem::SetOptions( const SvtLinguOptions
&rOptions
)
591 osl::MutexGuard
aGuard( GetOwnMutex() );
599 BOOL
SvtLinguConfigItem::LoadOptions( const uno::Sequence
< OUString
> &rProperyNames
)
601 osl::MutexGuard
aGuard( GetOwnMutex() );
605 const OUString
*pProperyNames
= rProperyNames
.getConstArray();
606 INT32 nProps
= rProperyNames
.getLength();
608 const uno::Sequence
< uno::Any
> aValues
= GetProperties( rProperyNames
);
609 const uno::Sequence
< sal_Bool
> aROStates
= GetReadOnlyStates( rProperyNames
);
611 if (nProps
&& aValues
.getLength() == nProps
&& aROStates
.getLength() == nProps
)
613 SvtLinguOptions
&rOpt
= aOpt
;
615 const uno::Any
*pValue
= aValues
.getConstArray();
616 const sal_Bool
*pROStates
= aROStates
.getConstArray();
617 for (INT32 i
= 0; i
< nProps
; ++i
)
619 const uno::Any
&rVal
= pValue
[i
];
620 INT32 nPropertyHandle
;
621 GetHdlByName( nPropertyHandle
, pProperyNames
[i
], sal_True
);
622 switch ( nPropertyHandle
)
624 case UPH_DEFAULT_LOCALE
:
625 { rOpt
.bRODefaultLanguage
= pROStates
[i
]; rOpt
.nDefaultLanguage
= lcl_CfgAnyToLanguage( rVal
); } break;
626 case UPH_ACTIVE_DICTIONARIES
:
627 { rOpt
.bROActiveDics
= pROStates
[i
]; rVal
>>= rOpt
.aActiveDics
; } break;
628 case UPH_IS_USE_DICTIONARY_LIST
:
629 { rOpt
.bROIsUseDictionaryList
= pROStates
[i
]; rVal
>>= rOpt
.bIsUseDictionaryList
; } break;
630 case UPH_IS_IGNORE_CONTROL_CHARACTERS
:
631 { rOpt
.bROIsIgnoreControlCharacters
= pROStates
[i
]; rVal
>>= rOpt
.bIsIgnoreControlCharacters
; } break;
632 case UPH_DEFAULT_LOCALE_CJK
:
633 { rOpt
.bRODefaultLanguage_CJK
= pROStates
[i
]; rOpt
.nDefaultLanguage_CJK
= lcl_CfgAnyToLanguage( rVal
); } break;
634 case UPH_DEFAULT_LOCALE_CTL
:
635 { rOpt
.bRODefaultLanguage_CTL
= pROStates
[i
]; rOpt
.nDefaultLanguage_CTL
= lcl_CfgAnyToLanguage( rVal
); } break;
637 case UPH_IS_SPELL_UPPER_CASE
:
638 { rOpt
.bROIsSpellUpperCase
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellUpperCase
; } break;
639 case UPH_IS_SPELL_WITH_DIGITS
:
640 { rOpt
.bROIsSpellWithDigits
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellWithDigits
; } break;
641 case UPH_IS_SPELL_CAPITALIZATION
:
642 { rOpt
.bROIsSpellCapitalization
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellCapitalization
; } break;
643 case UPH_IS_SPELL_AUTO
:
644 { rOpt
.bROIsSpellAuto
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellAuto
; } break;
645 case UPH_IS_SPELL_SPECIAL
:
646 { rOpt
.bROIsSpellSpecial
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellSpecial
; } break;
647 case UPH_IS_WRAP_REVERSE
:
648 { rOpt
.bROIsSpellReverse
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellReverse
; } break;
650 case UPH_HYPH_MIN_LEADING
:
651 { rOpt
.bROHyphMinLeading
= pROStates
[i
]; rVal
>>= rOpt
.nHyphMinLeading
; } break;
652 case UPH_HYPH_MIN_TRAILING
:
653 { rOpt
.bROHyphMinTrailing
= pROStates
[i
]; rVal
>>= rOpt
.nHyphMinTrailing
; } break;
654 case UPH_HYPH_MIN_WORD_LENGTH
:
655 { rOpt
.bROHyphMinWordLength
= pROStates
[i
]; rVal
>>= rOpt
.nHyphMinWordLength
; } break;
656 case UPH_IS_HYPH_SPECIAL
:
657 { rOpt
.bROIsHyphSpecial
= pROStates
[i
]; rVal
>>= rOpt
.bIsHyphSpecial
; } break;
658 case UPH_IS_HYPH_AUTO
:
659 { rOpt
.bROIsHyphAuto
= pROStates
[i
]; rVal
>>= rOpt
.bIsHyphAuto
; } break;
661 case UPH_ACTIVE_CONVERSION_DICTIONARIES
: { rOpt
.bROActiveConvDics
= pROStates
[i
]; rVal
>>= rOpt
.aActiveConvDics
; } break;
663 case UPH_IS_IGNORE_POST_POSITIONAL_WORD
:
664 { rOpt
.bROIsIgnorePostPositionalWord
= pROStates
[i
]; rVal
>>= rOpt
.bIsIgnorePostPositionalWord
; } break;
665 case UPH_IS_AUTO_CLOSE_DIALOG
:
666 { rOpt
.bROIsAutoCloseDialog
= pROStates
[i
]; rVal
>>= rOpt
.bIsAutoCloseDialog
; } break;
667 case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
:
668 { rOpt
.bROIsShowEntriesRecentlyUsedFirst
= pROStates
[i
]; rVal
>>= rOpt
.bIsShowEntriesRecentlyUsedFirst
; } break;
669 case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
:
670 { rOpt
.bROIsAutoReplaceUniqueEntries
= pROStates
[i
]; rVal
>>= rOpt
.bIsAutoReplaceUniqueEntries
; } break;
672 case UPH_IS_DIRECTION_TO_SIMPLIFIED
:
673 { rOpt
.bROIsDirectionToSimplified
= pROStates
[i
];
674 if( ! (rVal
>>= rOpt
.bIsDirectionToSimplified
) )
676 //default is locale dependent:
677 if( rOpt
.nDefaultLanguage_CJK
== LANGUAGE_CHINESE_HONGKONG
678 || rOpt
.nDefaultLanguage_CJK
== LANGUAGE_CHINESE_MACAU
679 || rOpt
.nDefaultLanguage_CJK
== LANGUAGE_CHINESE_TRADITIONAL
)
681 rOpt
.bIsDirectionToSimplified
= FALSE
;
685 rOpt
.bIsDirectionToSimplified
= TRUE
;
689 case UPH_IS_USE_CHARACTER_VARIANTS
:
690 { rOpt
.bROIsUseCharacterVariants
= pROStates
[i
]; rVal
>>= rOpt
.bIsUseCharacterVariants
; } break;
691 case UPH_IS_TRANSLATE_COMMON_TERMS
:
692 { rOpt
.bROIsTranslateCommonTerms
= pROStates
[i
]; rVal
>>= rOpt
.bIsTranslateCommonTerms
; } break;
693 case UPH_IS_REVERSE_MAPPING
:
694 { rOpt
.bROIsReverseMapping
= pROStates
[i
]; rVal
>>= rOpt
.bIsReverseMapping
; } break;
696 case UPH_DATA_FILES_CHANGED_CHECK_VALUE
:
697 { rOpt
.bRODataFilesChangedCheckValue
= pROStates
[i
]; rVal
>>= rOpt
.nDataFilesChangedCheckValue
; } break;
699 case UPH_IS_GRAMMAR_AUTO
:
700 { rOpt
.bROIsGrammarAuto
= pROStates
[i
]; rVal
>>= rOpt
.bIsGrammarAuto
; }
702 case UPH_IS_GRAMMAR_INTERACTIVE
:
703 { rOpt
.bROIsGrammarInteractive
= pROStates
[i
]; rVal
>>= rOpt
.bIsGrammarInteractive
; }
707 DBG_ASSERT( 0, "unexpected case" );
713 DBG_ASSERT( bRes
, "LoadOptions failed" );
719 BOOL
SvtLinguConfigItem::SaveOptions( const uno::Sequence
< OUString
> &rProperyNames
)
724 osl::MutexGuard
aGuard( GetOwnMutex() );
727 const uno::Type
&rBOOL
= ::getBooleanCppuType();
728 const uno::Type
&rINT16
= ::getCppuType( (INT16
*) NULL
);
729 const uno::Type
&rINT32
= ::getCppuType( (INT32
*) NULL
);
731 INT32 nProps
= rProperyNames
.getLength();
732 uno::Sequence
< uno::Any
> aValues( nProps
);
733 uno::Any
*pValue
= aValues
.getArray();
735 if (nProps
&& aValues
.getLength() == nProps
)
737 const SvtLinguOptions
&rOpt
= aOpt
;
739 OUString
aTmp( lcl_LanguageToCfgLocaleStr( rOpt
.nDefaultLanguage
) );
740 *pValue
++ = uno::makeAny( aTmp
); // 0
741 *pValue
++ = uno::makeAny( rOpt
.aActiveDics
); // 1
742 pValue
++->setValue( &rOpt
.bIsUseDictionaryList
, rBOOL
); // 2
743 pValue
++->setValue( &rOpt
.bIsIgnoreControlCharacters
, rBOOL
); // 3
744 aTmp
= lcl_LanguageToCfgLocaleStr( rOpt
.nDefaultLanguage_CJK
);
745 *pValue
++ = uno::makeAny( aTmp
); // 5
746 aTmp
= lcl_LanguageToCfgLocaleStr( rOpt
.nDefaultLanguage_CTL
);
747 *pValue
++ = uno::makeAny( aTmp
); // 6
749 pValue
++->setValue( &rOpt
.bIsSpellUpperCase
, rBOOL
); // 7
750 pValue
++->setValue( &rOpt
.bIsSpellWithDigits
, rBOOL
); // 8
751 pValue
++->setValue( &rOpt
.bIsSpellCapitalization
, rBOOL
); // 9
752 pValue
++->setValue( &rOpt
.bIsSpellAuto
, rBOOL
); // 10
753 pValue
++->setValue( &rOpt
.bIsSpellSpecial
, rBOOL
); // 11
754 pValue
++->setValue( &rOpt
.bIsSpellReverse
, rBOOL
); // 14
756 pValue
++->setValue( &rOpt
.nHyphMinLeading
, rINT16
); // 15
757 pValue
++->setValue( &rOpt
.nHyphMinTrailing
, rINT16
); // 16
758 pValue
++->setValue( &rOpt
.nHyphMinWordLength
, rINT16
); // 17
759 pValue
++->setValue( &rOpt
.bIsHyphSpecial
, rBOOL
); // 18
760 pValue
++->setValue( &rOpt
.bIsHyphAuto
, rBOOL
); // 19
762 *pValue
++ = uno::makeAny( rOpt
.aActiveConvDics
); // 20
764 pValue
++->setValue( &rOpt
.bIsIgnorePostPositionalWord
, rBOOL
); // 21
765 pValue
++->setValue( &rOpt
.bIsAutoCloseDialog
, rBOOL
); // 22
766 pValue
++->setValue( &rOpt
.bIsShowEntriesRecentlyUsedFirst
, rBOOL
); // 23
767 pValue
++->setValue( &rOpt
.bIsAutoReplaceUniqueEntries
, rBOOL
); // 24
769 pValue
++->setValue( &rOpt
.bIsDirectionToSimplified
, rBOOL
); // 25
770 pValue
++->setValue( &rOpt
.bIsUseCharacterVariants
, rBOOL
); // 26
771 pValue
++->setValue( &rOpt
.bIsTranslateCommonTerms
, rBOOL
); // 27
772 pValue
++->setValue( &rOpt
.bIsReverseMapping
, rBOOL
); // 28
774 pValue
++->setValue( &rOpt
.nDataFilesChangedCheckValue
, rINT32
); // 29
775 pValue
++->setValue( &rOpt
.bIsGrammarAuto
, rBOOL
); // 30
776 pValue
++->setValue( &rOpt
.bIsGrammarInteractive
, rBOOL
); // 31
778 bRet
|= PutProperties( rProperyNames
, aValues
);
787 BOOL
SvtLinguConfigItem::IsReadOnly( const rtl::OUString
&rPropertyName
) const
789 osl::MutexGuard
aGuard( GetOwnMutex() );
791 BOOL bReadOnly
= FALSE
;
793 if (GetHdlByName( nHdl
, rPropertyName
))
794 bReadOnly
= IsReadOnly( nHdl
);
798 BOOL
SvtLinguConfigItem::IsReadOnly( INT32 nPropertyHandle
) const
800 osl::MutexGuard
aGuard( GetOwnMutex() );
802 BOOL bReadOnly
= FALSE
;
804 const SvtLinguOptions
&rOpt
= const_cast< SvtLinguConfigItem
* >(this)->aOpt
;
805 switch(nPropertyHandle
)
807 case UPH_IS_USE_DICTIONARY_LIST
: bReadOnly
= rOpt
.bROIsUseDictionaryList
; break;
808 case UPH_IS_IGNORE_CONTROL_CHARACTERS
: bReadOnly
= rOpt
.bROIsIgnoreControlCharacters
; break;
809 case UPH_IS_HYPH_AUTO
: bReadOnly
= rOpt
.bROIsHyphAuto
; break;
810 case UPH_IS_HYPH_SPECIAL
: bReadOnly
= rOpt
.bROIsHyphSpecial
; break;
811 case UPH_IS_SPELL_AUTO
: bReadOnly
= rOpt
.bROIsSpellAuto
; break;
812 case UPH_IS_SPELL_SPECIAL
: bReadOnly
= rOpt
.bROIsSpellSpecial
; break;
813 case UPH_IS_WRAP_REVERSE
: bReadOnly
= rOpt
.bROIsSpellReverse
; break;
814 case UPH_DEFAULT_LANGUAGE
: bReadOnly
= rOpt
.bRODefaultLanguage
; break;
815 case UPH_IS_SPELL_CAPITALIZATION
: bReadOnly
= rOpt
.bROIsSpellCapitalization
; break;
816 case UPH_IS_SPELL_WITH_DIGITS
: bReadOnly
= rOpt
.bROIsSpellWithDigits
; break;
817 case UPH_IS_SPELL_UPPER_CASE
: bReadOnly
= rOpt
.bROIsSpellUpperCase
; break;
818 case UPH_HYPH_MIN_LEADING
: bReadOnly
= rOpt
.bROHyphMinLeading
; break;
819 case UPH_HYPH_MIN_TRAILING
: bReadOnly
= rOpt
.bROHyphMinTrailing
; break;
820 case UPH_HYPH_MIN_WORD_LENGTH
: bReadOnly
= rOpt
.bROHyphMinWordLength
; break;
821 case UPH_ACTIVE_DICTIONARIES
: bReadOnly
= rOpt
.bROActiveDics
; break;
822 case UPH_ACTIVE_CONVERSION_DICTIONARIES
: bReadOnly
= rOpt
.bROActiveConvDics
; break;
823 case UPH_DEFAULT_LOCALE
: bReadOnly
= rOpt
.bRODefaultLanguage
; break;
824 case UPH_DEFAULT_LOCALE_CJK
: bReadOnly
= rOpt
.bRODefaultLanguage_CJK
; break;
825 case UPH_DEFAULT_LOCALE_CTL
: bReadOnly
= rOpt
.bRODefaultLanguage_CTL
; break;
826 case UPH_IS_IGNORE_POST_POSITIONAL_WORD
: bReadOnly
= rOpt
.bROIsIgnorePostPositionalWord
; break;
827 case UPH_IS_AUTO_CLOSE_DIALOG
: bReadOnly
= rOpt
.bROIsAutoCloseDialog
; break;
828 case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
: bReadOnly
= rOpt
.bROIsShowEntriesRecentlyUsedFirst
; break;
829 case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
: bReadOnly
= rOpt
.bROIsAutoReplaceUniqueEntries
; break;
830 case UPH_IS_DIRECTION_TO_SIMPLIFIED
: bReadOnly
= rOpt
.bROIsDirectionToSimplified
; break;
831 case UPH_IS_USE_CHARACTER_VARIANTS
: bReadOnly
= rOpt
.bROIsUseCharacterVariants
; break;
832 case UPH_IS_TRANSLATE_COMMON_TERMS
: bReadOnly
= rOpt
.bROIsTranslateCommonTerms
; break;
833 case UPH_IS_REVERSE_MAPPING
: bReadOnly
= rOpt
.bROIsReverseMapping
; break;
834 case UPH_DATA_FILES_CHANGED_CHECK_VALUE
: bReadOnly
= rOpt
.bRODataFilesChangedCheckValue
; break;
835 case UPH_IS_GRAMMAR_AUTO
: bReadOnly
= rOpt
.bROIsGrammarAuto
; break;
836 case UPH_IS_GRAMMAR_INTERACTIVE
: bReadOnly
= rOpt
.bROIsGrammarInteractive
; break;
838 DBG_ASSERT( 0, "unexpected property handle" );
843 //////////////////////////////////////////////////////////////////////
845 static SvtLinguConfigItem
*pCfgItem
= 0;
846 static sal_Int32 nCfgItemRefCount
= 0;
848 static const rtl::OUString
aG_SupportedDictionaryFormats( A2OU("SupportedDictionaryFormats") );
849 static const rtl::OUString
aG_Dictionaries( A2OU("Dictionaries") );
850 static const rtl::OUString
aG_Locations( A2OU("Locations") );
851 static const rtl::OUString
aG_Format( A2OU("Format") );
852 static const rtl::OUString
aG_Locales( A2OU("Locales") );
853 static const rtl::OUString
aG_DisabledDictionaries( A2OU("DisabledDictionaries") );
854 static const rtl::OUString
aG_LastActiveDictionaries( A2OU("LastActiveDictionaries") );
856 SvtLinguConfig::SvtLinguConfig()
858 // Global access, must be guarded (multithreading)
859 osl::MutexGuard
aGuard( GetOwnMutex() );
864 SvtLinguConfig::~SvtLinguConfig()
866 osl::MutexGuard
aGuard( GetOwnMutex() );
868 if (pCfgItem
&& pCfgItem
->IsModified())
871 if (--nCfgItemRefCount
<= 0)
880 SvtLinguConfigItem
& SvtLinguConfig::GetConfigItem()
882 // Global access, must be guarded (multithreading)
883 osl::MutexGuard
aGuard( GetOwnMutex() );
886 pCfgItem
= new SvtLinguConfigItem
;
887 ItemHolder1::holdConfigItem(E_LINGUCFG
);
893 uno::Sequence
< OUString
> SvtLinguConfig::GetNodeNames( const OUString
&rNode
)
895 return GetConfigItem().GetNodeNames( rNode
);
899 uno::Sequence
< uno::Any
> SvtLinguConfig::GetProperties( const uno::Sequence
< OUString
> &rNames
)
901 return GetConfigItem().GetProperties(rNames
);
905 sal_Bool
SvtLinguConfig::ReplaceSetProperties(
906 const OUString
&rNode
, uno::Sequence
< beans::PropertyValue
> rValues
)
908 return GetConfigItem().ReplaceSetProperties( rNode
, rValues
);
912 uno::Any
SvtLinguConfig::GetProperty( const OUString
&rPropertyName
) const
914 return GetConfigItem().GetProperty( rPropertyName
);
918 uno::Any
SvtLinguConfig::GetProperty( INT32 nPropertyHandle
) const
920 return GetConfigItem().GetProperty( nPropertyHandle
);
924 BOOL
SvtLinguConfig::SetProperty( const OUString
&rPropertyName
, const uno::Any
&rValue
)
926 return GetConfigItem().SetProperty( rPropertyName
, rValue
);
930 BOOL
SvtLinguConfig::SetProperty( INT32 nPropertyHandle
, const uno::Any
&rValue
)
932 return GetConfigItem().SetProperty( nPropertyHandle
, rValue
);
936 BOOL
SvtLinguConfig::GetOptions( SvtLinguOptions
&rOptions
) const
938 return GetConfigItem().GetOptions( rOptions
);
942 BOOL
SvtLinguConfig::SetOptions( const SvtLinguOptions
&rOptions
)
944 return GetConfigItem().SetOptions( rOptions
);
948 BOOL
SvtLinguConfig::IsReadOnly( const rtl::OUString
&rPropertyName
) const
950 return GetConfigItem().IsReadOnly( rPropertyName
);
953 BOOL
SvtLinguConfig::IsReadOnly( INT32 nPropertyHandle
) const
955 return GetConfigItem().IsReadOnly( nPropertyHandle
);
958 BOOL
SvtLinguConfig::GetElementNamesFor(
959 const rtl::OUString
&rNodeName
,
960 uno::Sequence
< rtl::OUString
> &rElementNames
) const
962 bool bSuccess
= false;
965 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
966 xNA
.set( xNA
->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW
);
967 xNA
.set( xNA
->getByName( rNodeName
), uno::UNO_QUERY_THROW
);
968 rElementNames
= xNA
->getElementNames();
971 catch (uno::Exception
&)
977 static uno::Reference
< container::XNameAccess
> GetOrCreateSetEntry_Impl(
978 const uno::Reference
< container::XNameAccess
> &rxSetNameAccess
,
979 const rtl::OUString
&rEntryName
)
981 uno::Reference
< container::XNameAccess
> xResult
;
984 if (!rxSetNameAccess
->hasByName( rEntryName
))
986 uno::Reference
< lang::XSingleServiceFactory
> xFactory( rxSetNameAccess
, uno::UNO_QUERY_THROW
);
987 uno::Reference
< uno::XInterface
> xNewEntry( xFactory
->createInstance() );
988 uno::Reference
< container::XNameContainer
> xNC( rxSetNameAccess
, uno::UNO_QUERY_THROW
);
989 xNC
->insertByName( rEntryName
, makeAny( xNewEntry
) );
991 xResult
.set( rxSetNameAccess
->getByName( rEntryName
), uno::UNO_QUERY_THROW
);
993 catch (uno::Exception
&)
999 BOOL
SvtLinguConfig::GetSupportedDictionaryFormatsFor(
1000 const rtl::OUString
&rSetName
,
1001 const rtl::OUString
&rSetEntry
,
1002 uno::Sequence
< rtl::OUString
> &rFormatList
) const
1004 if (rSetName
.getLength() == 0 || rSetEntry
.getLength() == 0)
1006 bool bSuccess
= false;
1009 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
1010 xNA
.set( xNA
->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW
);
1011 xNA
.set( xNA
->getByName( rSetName
), uno::UNO_QUERY_THROW
);
1012 xNA
.set( xNA
->getByName( rSetEntry
), uno::UNO_QUERY_THROW
);
1013 if (xNA
->getByName( aG_SupportedDictionaryFormats
) >>= rFormatList
)
1015 DBG_ASSERT( rFormatList
.getLength(), "supported dictionary format list is empty" );
1017 catch (uno::Exception
&)
1023 void SvtLinguConfig::SetOrCreateSupportedDictionaryFormatsFor(
1024 const rtl::OUString
&rSetName
,
1025 const rtl::OUString
&rSetEntry
,
1026 const uno::Sequence
< rtl::OUString
> &rFormatList
) const
1028 if (rSetName
.getLength() == 0 || rSetEntry
.getLength() == 0)
1032 DBG_ASSERT( rFormatList
.getLength(), "applying empty format list. Really??" );
1034 uno::Reference
< util::XChangesBatch
> xUpdateAccess( GetMainUpdateAccess() );
1035 uno::Reference
< container::XNameAccess
> xNA( xUpdateAccess
, uno::UNO_QUERY_THROW
);
1036 xNA
.set( xNA
->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW
);
1037 xNA
.set( xNA
->getByName( rSetName
), uno::UNO_QUERY_THROW
);
1038 xNA
= GetOrCreateSetEntry_Impl( xNA
, rSetEntry
);
1040 uno::Reference
< container::XNameReplace
> xNR( xNA
, uno::UNO_QUERY_THROW
);
1041 xNR
->replaceByName( aG_SupportedDictionaryFormats
, uno::makeAny( rFormatList
) );
1043 xUpdateAccess
->commitChanges();
1045 catch (uno::Exception
&)
1051 static uno::WeakReference
< util::XMacroExpander
> aG_xMacroExpander
;
1053 static uno::Reference
< util::XMacroExpander
> lcl_GetMacroExpander()
1055 uno::Reference
< util::XMacroExpander
> xMacroExpander( aG_xMacroExpander
);
1056 if ( !xMacroExpander
.is() )
1058 vos::OGuard
aSolarMutexGuard( Application::GetSolarMutex() );
1060 if ( !xMacroExpander
.is() )
1062 uno::Reference
< uno::XComponentContext
> xContext
;
1063 uno::Reference
< beans::XPropertySet
> xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY
);
1064 xProps
->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xContext
;
1065 if ( xContext
.is() )
1067 aG_xMacroExpander
= uno::Reference
< com::sun::star::util::XMacroExpander
>( xContext
->getValueByName(
1068 OUString( RTL_CONSTASCII_USTRINGPARAM( "/singletons/com.sun.star.util.theMacroExpander"))),
1070 xMacroExpander
= aG_xMacroExpander
;
1075 return xMacroExpander
;
1079 static bool lcl_GetFileUrlFromOrigin(
1080 OUString
/*out*/ &rFileUrl
,
1081 const OUString
&rOrigin
,
1082 uno::Reference
< util::XMacroExpander
> &rxMacroExpander
)
1084 bool bSuccess
= false;
1085 if (rOrigin
.getLength() > 0 && rxMacroExpander
.is())
1087 rtl::OUString
aURL( rOrigin
);
1088 if (( aURL
.compareToAscii( RTL_CONSTASCII_STRINGPARAM( EXPAND_PROTOCOL
)) == 0 ) &&
1089 rxMacroExpander
.is() )
1092 OUString
aMacro( aURL
.copy( sizeof ( EXPAND_PROTOCOL
) -1 ) );
1093 // decode uric class chars
1094 aMacro
= Uri::decode( aMacro
, rtl_UriDecodeWithCharset
, RTL_TEXTENCODING_UTF8
);
1095 // expand macro string
1096 aURL
= rxMacroExpander
->expandMacros( aMacro
);
1098 bool bIsFileUrl
= aURL
.compareToAscii( RTL_CONSTASCII_STRINGPARAM( FILE_PROTOCOL
)) == 0;
1106 DBG_ASSERT( bIsFileUrl
, "not a file URL");
1111 DBG_ASSERT( 0, "failed to get file URL" );
1118 BOOL
SvtLinguConfig::GetDictionaryEntry(
1119 const rtl::OUString
&rNodeName
,
1120 SvtLinguConfigDictionaryEntry
&rDicEntry
) const
1122 if (rNodeName
.getLength() == 0)
1124 bool bSuccess
= false;
1127 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
1128 xNA
.set( xNA
->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW
);
1129 xNA
.set( xNA
->getByName( aG_Dictionaries
), uno::UNO_QUERY_THROW
);
1130 xNA
.set( xNA
->getByName( rNodeName
), uno::UNO_QUERY_THROW
);
1132 // read group data...
1133 uno::Sequence
< rtl::OUString
> aLocations
;
1134 rtl::OUString aFormatName
;
1135 uno::Sequence
< rtl::OUString
> aLocaleNames
;
1136 bSuccess
= (xNA
->getByName( aG_Locations
) >>= aLocations
) &&
1137 (xNA
->getByName( aG_Format
) >>= aFormatName
) &&
1138 (xNA
->getByName( aG_Locales
) >>= aLocaleNames
);
1139 DBG_ASSERT( aLocations
.getLength(), "Dictionary locations not set" );
1140 DBG_ASSERT( aFormatName
.getLength(), "Dictionary format name not set" );
1141 DBG_ASSERT( aLocaleNames
.getLength(), "No locales set for the dictionary" );
1143 // if sucessful continue
1146 // get file URL's for the locations
1147 uno::Reference
< util::XMacroExpander
> xMacroExpander( lcl_GetMacroExpander() );
1148 for (sal_Int32 i
= 0; i
< aLocations
.getLength(); ++i
)
1150 rtl::OUString
&rLocation
= aLocations
[i
];
1151 if (!lcl_GetFileUrlFromOrigin( rLocation
, rLocation
, xMacroExpander
))
1155 // if everything was fine return the result
1158 rDicEntry
.aLocations
= aLocations
;
1159 rDicEntry
.aFormatName
= aFormatName
;
1160 rDicEntry
.aLocaleNames
= aLocaleNames
;
1164 catch (uno::Exception
&)
1170 void SvtLinguConfig::SetOrCreateDictionaryEntry(
1171 const rtl::OUString
&rNodeName
,
1172 const SvtLinguConfigDictionaryEntry
&rDicEntry
) const
1174 if (rNodeName
.getLength() == 0)
1178 uno::Reference
< util::XChangesBatch
> xUpdateAccess( GetMainUpdateAccess() );
1179 uno::Reference
< container::XNameAccess
> xNA( xUpdateAccess
, uno::UNO_QUERY_THROW
);
1180 xNA
.set( xNA
->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW
);
1181 xNA
.set( xNA
->getByName( aG_Dictionaries
), uno::UNO_QUERY_THROW
);
1182 xNA
= GetOrCreateSetEntry_Impl( xNA
, rNodeName
);
1184 DBG_ASSERT( rDicEntry
.aLocations
.getLength(), "Applying empty dictionary locations. Really correct??" );
1185 DBG_ASSERT( rDicEntry
.aFormatName
.getLength(), "Applying empty dictionary format name. Really correct??" );
1186 DBG_ASSERT( rDicEntry
.aLocaleNames
.getLength(), "Applying empty list of locales for the dictionary. Really correct??" );
1188 uno::Reference
< container::XNameReplace
> xNR( xNA
, uno::UNO_QUERY_THROW
);
1189 xNR
->replaceByName( aG_Locations
, uno::makeAny( rDicEntry
.aLocations
) );
1190 xNR
->replaceByName( aG_Format
, uno::makeAny( rDicEntry
.aFormatName
) );
1191 xNR
->replaceByName( aG_Locales
, uno::makeAny( rDicEntry
.aLocaleNames
) );
1193 xUpdateAccess
->commitChanges();
1195 catch (uno::Exception
&)
1200 uno::Sequence
< rtl::OUString
> SvtLinguConfig::GetDisabledDictionaries() const
1202 uno::Sequence
< rtl::OUString
> aResult
;
1205 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
1206 xNA
.set( xNA
->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW
);
1207 xNA
->getByName( aG_DisabledDictionaries
) >>= aResult
;
1209 catch (uno::Exception
&)
1215 void SvtLinguConfig::SetDisabledDictionaries(
1216 const uno::Sequence
< rtl::OUString
> &rDictionaries
) const
1220 uno::Reference
< util::XChangesBatch
> xUpdateAccess( GetMainUpdateAccess() );
1221 uno::Reference
< container::XNameAccess
> xNA( xUpdateAccess
, uno::UNO_QUERY_THROW
);
1222 xNA
.set( xNA
->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW
);
1223 if (xNA
->hasByName( aG_DisabledDictionaries
))
1225 uno::Reference
< container::XNameReplace
> xNR( xNA
, uno::UNO_QUERY_THROW
);
1226 xNR
->replaceByName( aG_DisabledDictionaries
, makeAny( rDictionaries
) );
1230 uno::Reference
< container::XNameContainer
> xNC( xNA
, uno::UNO_QUERY_THROW
);
1231 xNC
->insertByName( aG_DisabledDictionaries
, makeAny( rDictionaries
) );
1234 xUpdateAccess
->commitChanges();
1236 catch (uno::Exception
&)
1241 std::vector
< SvtLinguConfigDictionaryEntry
> SvtLinguConfig::GetActiveDictionariesByFormat(
1242 const rtl::OUString
&rFormatName
)
1244 std::vector
< SvtLinguConfigDictionaryEntry
> aRes
;
1245 if (rFormatName
.getLength() == 0)
1250 uno::Sequence
< rtl::OUString
> aElementNames
;
1251 GetElementNamesFor( aG_Dictionaries
, aElementNames
);
1252 sal_Int32 nLen
= aElementNames
.getLength();
1253 const rtl::OUString
*pElementNames
= aElementNames
.getConstArray();
1255 SvtLinguConfigDictionaryEntry aDicEntry
;
1256 for (sal_Int32 i
= 0; i
< nLen
; ++i
)
1258 // does dictionary match the format we are looking for?
1259 if (GetDictionaryEntry( pElementNames
[i
], aDicEntry
) &&
1260 aDicEntry
.aFormatName
== rFormatName
)
1262 // check if it is active or not
1263 bool bDicIsActive
= true;
1264 const uno::Sequence
< rtl::OUString
> aDisabledDics( GetDisabledDictionaries() );
1265 for (sal_Int32 k
= 0; bDicIsActive
&& k
< aDisabledDics
.getLength(); ++k
)
1267 if (aDisabledDics
[k
] == pElementNames
[i
])
1268 bDicIsActive
= false;
1273 DBG_ASSERT( aDicEntry
.aFormatName
.getLength(),
1274 "FormatName not set" );
1275 DBG_ASSERT( aDicEntry
.aLocations
.getLength(),
1276 "Locations not set" );
1277 DBG_ASSERT( aDicEntry
.aLocaleNames
.getLength(),
1278 "Locales not set" );
1279 aRes
.push_back( aDicEntry
);
1284 catch (uno::Exception
&)
1292 uno::Reference
< util::XChangesBatch
> SvtLinguConfig::GetMainUpdateAccess() const
1294 if (!m_xMainUpdateAccess
.is())
1298 // get configuration provider
1299 uno::Reference
< lang::XMultiServiceFactory
> xConfigurationProvider
;
1300 uno::Reference
< lang::XMultiServiceFactory
> xMgr
= comphelper::getProcessServiceFactory();
1303 xConfigurationProvider
= uno::Reference
< lang::XMultiServiceFactory
> (
1304 xMgr
->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM(
1305 "com.sun.star.configuration.ConfigurationProvider" ) ) ),
1306 uno::UNO_QUERY_THROW
) ;
1309 // get configuration update access
1310 beans::PropertyValue aValue
;
1311 aValue
.Name
= A2OU( "nodepath" );
1312 aValue
.Value
= uno::makeAny( A2OU("org.openoffice.Office.Linguistic") );
1313 uno::Sequence
< uno::Any
> aProps(1);
1314 aProps
[0] <<= aValue
;
1315 m_xMainUpdateAccess
= uno::Reference
< util::XChangesBatch
>(
1316 xConfigurationProvider
->createInstanceWithArguments(
1317 A2OU( "com.sun.star.configuration.ConfigurationUpdateAccess" ), aProps
),
1318 uno::UNO_QUERY_THROW
);
1320 catch (uno::Exception
&)
1325 return m_xMainUpdateAccess
;
1329 rtl::OUString
SvtLinguConfig::GetVendorImageUrl_Impl(
1330 const rtl::OUString
&rServiceImplName
,
1331 const rtl::OUString
&rImageName
) const
1336 uno::Reference
< container::XNameAccess
> xImagesNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
1337 xImagesNA
.set( xImagesNA
->getByName( A2OU("Images") ), uno::UNO_QUERY_THROW
);
1339 uno::Reference
< container::XNameAccess
> xNA( xImagesNA
->getByName( A2OU("ServiceNameEntries") ), uno::UNO_QUERY_THROW
);
1340 xNA
.set( xNA
->getByName( rServiceImplName
), uno::UNO_QUERY_THROW
);
1341 uno::Any
aAny( xNA
->getByName( A2OU("VendorImagesNode") ) );
1342 rtl::OUString aVendorImagesNode
;
1343 if (aAny
>>= aVendorImagesNode
)
1346 xNA
.set( xNA
->getByName( A2OU("VendorImages") ), uno::UNO_QUERY_THROW
);
1347 xNA
.set( xNA
->getByName( aVendorImagesNode
), uno::UNO_QUERY_THROW
);
1348 aAny
= xNA
->getByName( rImageName
);
1352 uno::Reference
< util::XMacroExpander
> xMacroExpander( lcl_GetMacroExpander() );
1353 if (lcl_GetFileUrlFromOrigin( aTmp
, aTmp
, xMacroExpander
))
1358 catch (uno::Exception
&)
1360 DBG_ASSERT( 0, "exception caught. GetVendorImageUrl_Impl failed" );
1366 rtl::OUString
SvtLinguConfig::GetSpellAndGrammarDialogImage(
1367 const rtl::OUString
&rServiceImplName
,
1368 bool bHighContrast
) const
1371 if (rServiceImplName
.getLength() > 0)
1373 rtl::OUString
aImageName( A2OU( bHighContrast
? "SpellAndGrammarDialogImage_HC" : "SpellAndGrammarDialogImage" ));
1374 rtl::OUString
aPath( GetVendorImageUrl_Impl( rServiceImplName
, aImageName
) );
1381 rtl::OUString
SvtLinguConfig::GetSpellAndGrammarContextSuggestionImage(
1382 const rtl::OUString
&rServiceImplName
,
1383 bool bHighContrast
) const
1386 if (rServiceImplName
.getLength() > 0)
1388 rtl::OUString
aImageName( A2OU( bHighContrast
? "SpellAndGrammarContextMenuSuggestionImage_HC" : "SpellAndGrammarContextMenuSuggestionImage" ));
1389 rtl::OUString
aPath( GetVendorImageUrl_Impl( rServiceImplName
, aImageName
) );
1396 rtl::OUString
SvtLinguConfig::GetSpellAndGrammarContextDictionaryImage(
1397 const rtl::OUString
&rServiceImplName
,
1398 bool bHighContrast
) const
1401 if (rServiceImplName
.getLength() > 0)
1403 rtl::OUString
aImageName( A2OU( bHighContrast
? "SpellAndGrammarContextMenuDictionaryImage_HC" : "SpellAndGrammarContextMenuDictionaryImage" ));
1404 rtl::OUString
aPath( GetVendorImageUrl_Impl( rServiceImplName
, aImageName
) );
1411 bool SvtLinguConfig::HasAnyVendorImages() const
1416 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
1417 xNA
.set( xNA
->getByName( A2OU("Images") ), uno::UNO_QUERY_THROW
);
1418 xNA
.set( xNA
->getByName( A2OU("VendorImages") ), uno::UNO_QUERY_THROW
);
1420 uno::Sequence
< rtl::OUString
> aElementNames( xNA
->getElementNames() );
1421 bRes
= aElementNames
.getLength() > 0;
1423 catch (uno::Exception
&)
1425 DBG_ASSERT( 0, "exception caught. HasAnyVendorImages failed" );
1431 bool SvtLinguConfig::HasGrammarChecker() const
1437 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
1438 xNA
.set( xNA
->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW
);
1439 xNA
.set( xNA
->getByName( A2OU("GrammarCheckerList") ), uno::UNO_QUERY_THROW
);
1441 uno::Sequence
< rtl::OUString
> aElementNames( xNA
->getElementNames() );
1442 bRes
= aElementNames
.getLength() > 0;
1444 catch (uno::Exception
&)
1451 //////////////////////////////////////////////////////////////////////