1*b5088357SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*b5088357SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*b5088357SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*b5088357SAndrew Rist  * distributed with this work for additional information
6*b5088357SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*b5088357SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*b5088357SAndrew Rist  * "License"); you may not use this file except in compliance
9*b5088357SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*b5088357SAndrew Rist  *
11*b5088357SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*b5088357SAndrew Rist  *
13*b5088357SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*b5088357SAndrew Rist  * software distributed under the License is distributed on an
15*b5088357SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b5088357SAndrew Rist  * KIND, either express or implied.  See the License for the
17*b5088357SAndrew Rist  * specific language governing permissions and limitations
18*b5088357SAndrew Rist  * under the License.
19*b5088357SAndrew Rist  *
20*b5088357SAndrew Rist  *************************************************************/
21*b5088357SAndrew Rist 
22*b5088357SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_unotools.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <com/sun/star/lang/Locale.hpp>
29cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp>
30cdf0e10cSrcweir #include <com/sun/star/lang/XSingleServiceFactory.hpp>
31cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
32cdf0e10cSrcweir #include <com/sun/star/container/XNameContainer.hpp>
33cdf0e10cSrcweir #include <com/sun/star/container/XNameReplace.hpp>
34cdf0e10cSrcweir #include "com/sun/star/util/XMacroExpander.hpp"
35cdf0e10cSrcweir #include "com/sun/star/beans/XPropertySet.hpp"
36cdf0e10cSrcweir #include <rtl/uri.hxx>
37cdf0e10cSrcweir #include <vos/mutex.hxx>
38cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
39cdf0e10cSrcweir #include <tools/debug.hxx>
40cdf0e10cSrcweir #include <tools/string.hxx>
41cdf0e10cSrcweir #include <unotools/lingucfg.hxx>
42cdf0e10cSrcweir #include <unotools/linguprops.hxx>
43cdf0e10cSrcweir 
44cdf0e10cSrcweir #include <comphelper/processfactory.hxx>
45cdf0e10cSrcweir 
46cdf0e10cSrcweir #include <itemholder1.hxx>
47cdf0e10cSrcweir 
48cdf0e10cSrcweir using namespace rtl;
49cdf0e10cSrcweir using namespace com::sun::star;
50cdf0e10cSrcweir 
51cdf0e10cSrcweir #define A2OU(x)        ::rtl::OUString::createFromAscii( x )
52cdf0e10cSrcweir #define EXPAND_PROTOCOL     "vnd.sun.star.expand:"
53cdf0e10cSrcweir #define FILE_PROTOCOL       "file:///"
54cdf0e10cSrcweir 
55cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
56cdf0e10cSrcweir 
57cdf0e10cSrcweir 
GetOwnMutex()58cdf0e10cSrcweir static osl::Mutex &  GetOwnMutex()
59cdf0e10cSrcweir {
60cdf0e10cSrcweir     static osl::Mutex aMutex;
61cdf0e10cSrcweir     return aMutex;
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 
65cdf0e10cSrcweir ///////////////////////////////////////////////////////////////////////////
66cdf0e10cSrcweir 
67cdf0e10cSrcweir 
lcl_SetLocale(sal_Int16 & rLanguage,const uno::Any & rVal)68cdf0e10cSrcweir static sal_Bool lcl_SetLocale( sal_Int16 &rLanguage, const uno::Any &rVal )
69cdf0e10cSrcweir {
70cdf0e10cSrcweir     sal_Bool bSucc = sal_False;
71cdf0e10cSrcweir 
72cdf0e10cSrcweir     lang::Locale aNew;
73cdf0e10cSrcweir     if (rVal >>= aNew)	// conversion successful?
74cdf0e10cSrcweir     {
75cdf0e10cSrcweir         sal_Int16 nNew = MsLangId::convertLocaleToLanguage( aNew );
76cdf0e10cSrcweir         if (nNew != rLanguage)
77cdf0e10cSrcweir         {
78cdf0e10cSrcweir             rLanguage = nNew;
79cdf0e10cSrcweir             bSucc = sal_True;
80cdf0e10cSrcweir         }
81cdf0e10cSrcweir     }
82cdf0e10cSrcweir     return bSucc;
83cdf0e10cSrcweir }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir 
lcl_LanguageToCfgLocaleStr(sal_Int16 nLanguage)86cdf0e10cSrcweir static inline const OUString lcl_LanguageToCfgLocaleStr( sal_Int16 nLanguage )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir     OUString aRes;
89cdf0e10cSrcweir     if (LANGUAGE_SYSTEM != nLanguage)
90cdf0e10cSrcweir         aRes = MsLangId::convertLanguageToIsoString( nLanguage );
91cdf0e10cSrcweir     return aRes;
92cdf0e10cSrcweir }
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 
lcl_CfgAnyToLanguage(const uno::Any & rVal)95cdf0e10cSrcweir static sal_Int16 lcl_CfgAnyToLanguage( const uno::Any &rVal )
96cdf0e10cSrcweir {
97cdf0e10cSrcweir     OUString aTmp;
98cdf0e10cSrcweir     rVal >>= aTmp;
99cdf0e10cSrcweir     return (aTmp.getLength() == 0) ? LANGUAGE_SYSTEM : MsLangId::convertIsoStringToLanguage( aTmp );
100cdf0e10cSrcweir }
101cdf0e10cSrcweir 
102cdf0e10cSrcweir 
103cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
104cdf0e10cSrcweir 
SvtLinguOptions()105cdf0e10cSrcweir SvtLinguOptions::SvtLinguOptions()
106cdf0e10cSrcweir {
107cdf0e10cSrcweir     nDefaultLanguage = LANGUAGE_NONE;
108cdf0e10cSrcweir 	nDefaultLanguage_CJK = LANGUAGE_NONE;
109cdf0e10cSrcweir 	nDefaultLanguage_CTL = LANGUAGE_NONE;
110cdf0e10cSrcweir 
111cdf0e10cSrcweir 	// general options
112cdf0e10cSrcweir 	bIsUseDictionaryList	=
113cdf0e10cSrcweir 	bIsIgnoreControlCharacters	= sal_True;
114cdf0e10cSrcweir 
115cdf0e10cSrcweir 	// spelling options
116cdf0e10cSrcweir 	bIsSpellCapitalization	=
117cdf0e10cSrcweir 	bIsSpellSpecial			= sal_True;
118cdf0e10cSrcweir 	bIsSpellAuto			=
119cdf0e10cSrcweir 	bIsSpellReverse			=
120cdf0e10cSrcweir 	bIsSpellWithDigits		=
121cdf0e10cSrcweir 	bIsSpellUpperCase		= sal_False;
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     // text conversion options
124cdf0e10cSrcweir     bIsIgnorePostPositionalWord     = sal_True;
125cdf0e10cSrcweir     bIsAutoCloseDialog              =
126cdf0e10cSrcweir     bIsShowEntriesRecentlyUsedFirst =
127cdf0e10cSrcweir     bIsAutoReplaceUniqueEntries     = sal_False;
128cdf0e10cSrcweir     bIsDirectionToSimplified        = sal_True;
129cdf0e10cSrcweir     bIsUseCharacterVariants         =
130cdf0e10cSrcweir     bIsTranslateCommonTerms         =
131cdf0e10cSrcweir     bIsReverseMapping               = sal_False;
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     bROIsDirectionToSimplified      =
134cdf0e10cSrcweir     bROIsUseCharacterVariants       =
135cdf0e10cSrcweir     bROIsTranslateCommonTerms       =
136cdf0e10cSrcweir     bROIsReverseMapping             = sal_False;
137cdf0e10cSrcweir 
138cdf0e10cSrcweir 	// hyphenation options
139cdf0e10cSrcweir 	bIsHyphSpecial			= sal_True;
140cdf0e10cSrcweir 	bIsHyphAuto				= sal_False;
141cdf0e10cSrcweir 	nHyphMinLeading			=
142cdf0e10cSrcweir 	nHyphMinTrailing		= 2;
143cdf0e10cSrcweir 	nHyphMinWordLength		= 0;
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     nDataFilesChangedCheckValue = 0;
146cdf0e10cSrcweir 
147cdf0e10cSrcweir     //grammar options
148cdf0e10cSrcweir     bIsGrammarAuto = sal_False,
149cdf0e10cSrcweir     bIsGrammarInteractive = sal_False;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir }
152cdf0e10cSrcweir 
153cdf0e10cSrcweir 
154cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
155cdf0e10cSrcweir 
156cdf0e10cSrcweir 
157cdf0e10cSrcweir class SvtLinguConfigItem : public utl::ConfigItem
158cdf0e10cSrcweir {
159cdf0e10cSrcweir     SvtLinguOptions     aOpt;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     // disallow copy-constructor and assignment-operator for now
162cdf0e10cSrcweir     SvtLinguConfigItem( const SvtLinguConfigItem & );
163cdf0e10cSrcweir     SvtLinguConfigItem & operator = ( const SvtLinguConfigItem & );
164cdf0e10cSrcweir 
165cdf0e10cSrcweir     static sal_Bool GetHdlByName( sal_Int32 &rnHdl, const OUString &rPropertyName, sal_Bool bFullPropName = sal_False );
166cdf0e10cSrcweir     static const uno::Sequence< OUString > & GetPropertyNames();
167cdf0e10cSrcweir     sal_Bool                LoadOptions( const uno::Sequence< OUString > &rProperyNames );
168cdf0e10cSrcweir     sal_Bool                SaveOptions( const uno::Sequence< OUString > &rProperyNames );
169cdf0e10cSrcweir 
170cdf0e10cSrcweir public:
171cdf0e10cSrcweir     SvtLinguConfigItem();
172cdf0e10cSrcweir     virtual ~SvtLinguConfigItem();
173cdf0e10cSrcweir 
174cdf0e10cSrcweir     // utl::ConfigItem
175cdf0e10cSrcweir     virtual void    Notify( const com::sun::star::uno::Sequence< rtl::OUString > &rPropertyNames );
176cdf0e10cSrcweir     virtual void    Commit();
177cdf0e10cSrcweir 
178cdf0e10cSrcweir     // make some protected functions of utl::ConfigItem public
179cdf0e10cSrcweir     using utl::ConfigItem::GetNodeNames;
180cdf0e10cSrcweir     using utl::ConfigItem::GetProperties;
181cdf0e10cSrcweir     //using utl::ConfigItem::PutProperties;
182cdf0e10cSrcweir     //using utl::ConfigItem::SetSetProperties;
183cdf0e10cSrcweir     using utl::ConfigItem::ReplaceSetProperties;
184cdf0e10cSrcweir     //using utl::ConfigItem::GetReadOnlyStates;
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 
187cdf0e10cSrcweir     com::sun::star::uno::Any
188cdf0e10cSrcweir             GetProperty( const rtl::OUString &rPropertyName ) const;
189cdf0e10cSrcweir     com::sun::star::uno::Any
190cdf0e10cSrcweir             GetProperty( sal_Int32 nPropertyHandle ) const;
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     sal_Bool    SetProperty( const rtl::OUString &rPropertyName,
193cdf0e10cSrcweir                          const com::sun::star::uno::Any &rValue );
194cdf0e10cSrcweir     sal_Bool    SetProperty( sal_Int32 nPropertyHandle,
195cdf0e10cSrcweir                          const com::sun::star::uno::Any &rValue );
196cdf0e10cSrcweir 
197cdf0e10cSrcweir     sal_Bool    GetOptions( SvtLinguOptions &rOptions ) const;
198cdf0e10cSrcweir     sal_Bool    SetOptions( const SvtLinguOptions &rOptions );
199cdf0e10cSrcweir 
200cdf0e10cSrcweir     sal_Bool    IsReadOnly( const rtl::OUString &rPropertyName ) const;
201cdf0e10cSrcweir     sal_Bool    IsReadOnly( sal_Int32 nPropertyHandle ) const;
202cdf0e10cSrcweir };
203cdf0e10cSrcweir 
204cdf0e10cSrcweir 
SvtLinguConfigItem()205cdf0e10cSrcweir SvtLinguConfigItem::SvtLinguConfigItem() :
206cdf0e10cSrcweir     utl::ConfigItem( String::CreateFromAscii( "Office.Linguistic" ) )
207cdf0e10cSrcweir {
208cdf0e10cSrcweir     LoadOptions( GetPropertyNames() );
209cdf0e10cSrcweir     ClearModified();
210cdf0e10cSrcweir 
211cdf0e10cSrcweir     // request notify events when properties change
212cdf0e10cSrcweir     EnableNotification( GetPropertyNames() );
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir 
~SvtLinguConfigItem()216cdf0e10cSrcweir SvtLinguConfigItem::~SvtLinguConfigItem()
217cdf0e10cSrcweir {
218cdf0e10cSrcweir     //! Commit (SaveOptions) will be called by the d-tor of the base called !
219cdf0e10cSrcweir }
220cdf0e10cSrcweir 
221cdf0e10cSrcweir 
Notify(const uno::Sequence<OUString> & rPropertyNames)222cdf0e10cSrcweir void SvtLinguConfigItem::Notify( const uno::Sequence< OUString > &rPropertyNames )
223cdf0e10cSrcweir {
224cdf0e10cSrcweir     LoadOptions( rPropertyNames );
225cdf0e10cSrcweir 	NotifyListeners(0);
226cdf0e10cSrcweir }
227cdf0e10cSrcweir 
228cdf0e10cSrcweir 
Commit()229cdf0e10cSrcweir void SvtLinguConfigItem::Commit()
230cdf0e10cSrcweir {
231cdf0e10cSrcweir     SaveOptions( GetPropertyNames() );
232cdf0e10cSrcweir }
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 
235cdf0e10cSrcweir static struct NamesToHdl
236cdf0e10cSrcweir {
237cdf0e10cSrcweir     const char   *pFullPropName;      // full qualified name as used in configuration
238cdf0e10cSrcweir     const char   *pPropName;          // property name only (atom) of above
239cdf0e10cSrcweir     sal_Int32   nHdl;               // numeric handle representing the property
240cdf0e10cSrcweir }aNamesToHdl[] =
241cdf0e10cSrcweir {
242cdf0e10cSrcweir {/*  0 */    "General/DefaultLocale",                         UPN_DEFAULT_LOCALE,                    UPH_DEFAULT_LOCALE},
243cdf0e10cSrcweir {/*  1 */    "General/DictionaryList/ActiveDictionaries",     UPN_ACTIVE_DICTIONARIES,               UPH_ACTIVE_DICTIONARIES},
244cdf0e10cSrcweir {/*  2 */    "General/DictionaryList/IsUseDictionaryList",    UPN_IS_USE_DICTIONARY_LIST,            UPH_IS_USE_DICTIONARY_LIST},
245cdf0e10cSrcweir {/*  3 */    "General/IsIgnoreControlCharacters",             UPN_IS_IGNORE_CONTROL_CHARACTERS,      UPH_IS_IGNORE_CONTROL_CHARACTERS},
246cdf0e10cSrcweir {/*  5 */    "General/DefaultLocale_CJK",                     UPN_DEFAULT_LOCALE_CJK,                UPH_DEFAULT_LOCALE_CJK},
247cdf0e10cSrcweir {/*  6 */    "General/DefaultLocale_CTL",                     UPN_DEFAULT_LOCALE_CTL,                UPH_DEFAULT_LOCALE_CTL},
248cdf0e10cSrcweir 
249cdf0e10cSrcweir {/*  7 */    "SpellChecking/IsSpellUpperCase",                UPN_IS_SPELL_UPPER_CASE,               UPH_IS_SPELL_UPPER_CASE},
250cdf0e10cSrcweir {/*  8 */    "SpellChecking/IsSpellWithDigits",               UPN_IS_SPELL_WITH_DIGITS,              UPH_IS_SPELL_WITH_DIGITS},
251cdf0e10cSrcweir {/*  9 */    "SpellChecking/IsSpellCapitalization",           UPN_IS_SPELL_CAPITALIZATION,           UPH_IS_SPELL_CAPITALIZATION},
252cdf0e10cSrcweir {/* 10 */    "SpellChecking/IsSpellAuto",                     UPN_IS_SPELL_AUTO,                     UPH_IS_SPELL_AUTO},
253cdf0e10cSrcweir {/* 11 */    "SpellChecking/IsSpellSpecial",                  UPN_IS_SPELL_SPECIAL,                  UPH_IS_SPELL_SPECIAL},
254cdf0e10cSrcweir {/* 14 */    "SpellChecking/IsReverseDirection",              UPN_IS_WRAP_REVERSE,                   UPH_IS_WRAP_REVERSE},
255cdf0e10cSrcweir 
256cdf0e10cSrcweir {/* 15 */    "Hyphenation/MinLeading",                        UPN_HYPH_MIN_LEADING,                  UPH_HYPH_MIN_LEADING},
257cdf0e10cSrcweir {/* 16 */    "Hyphenation/MinTrailing",                       UPN_HYPH_MIN_TRAILING,                 UPH_HYPH_MIN_TRAILING},
258cdf0e10cSrcweir {/* 17 */    "Hyphenation/MinWordLength",                     UPN_HYPH_MIN_WORD_LENGTH,              UPH_HYPH_MIN_WORD_LENGTH},
259cdf0e10cSrcweir {/* 18 */    "Hyphenation/IsHyphSpecial",                     UPN_IS_HYPH_SPECIAL,                   UPH_IS_HYPH_SPECIAL},
260cdf0e10cSrcweir {/* 19 */    "Hyphenation/IsHyphAuto",                        UPN_IS_HYPH_AUTO,                      UPH_IS_HYPH_AUTO},
261cdf0e10cSrcweir 
262cdf0e10cSrcweir {/* 20 */    "TextConversion/ActiveConversionDictionaries",   UPN_ACTIVE_CONVERSION_DICTIONARIES,        UPH_ACTIVE_CONVERSION_DICTIONARIES},
263cdf0e10cSrcweir {/* 21 */    "TextConversion/IsIgnorePostPositionalWord",     UPN_IS_IGNORE_POST_POSITIONAL_WORD,        UPH_IS_IGNORE_POST_POSITIONAL_WORD},
264cdf0e10cSrcweir {/* 22 */    "TextConversion/IsAutoCloseDialog",              UPN_IS_AUTO_CLOSE_DIALOG,                  UPH_IS_AUTO_CLOSE_DIALOG},
265cdf0e10cSrcweir {/* 23 */    "TextConversion/IsShowEntriesRecentlyUsedFirst", UPN_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST,   UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST},
266cdf0e10cSrcweir {/* 24 */    "TextConversion/IsAutoReplaceUniqueEntries",     UPN_IS_AUTO_REPLACE_UNIQUE_ENTRIES,        UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES},
267cdf0e10cSrcweir {/* 25 */    "TextConversion/IsDirectionToSimplified",        UPN_IS_DIRECTION_TO_SIMPLIFIED,            UPH_IS_DIRECTION_TO_SIMPLIFIED},
268cdf0e10cSrcweir {/* 26 */    "TextConversion/IsUseCharacterVariants",         UPN_IS_USE_CHARACTER_VARIANTS,             UPH_IS_USE_CHARACTER_VARIANTS},
269cdf0e10cSrcweir {/* 27 */    "TextConversion/IsTranslateCommonTerms",         UPN_IS_TRANSLATE_COMMON_TERMS,             UPH_IS_TRANSLATE_COMMON_TERMS},
270cdf0e10cSrcweir {/* 28 */    "TextConversion/IsReverseMapping",               UPN_IS_REVERSE_MAPPING,                    UPH_IS_REVERSE_MAPPING},
271cdf0e10cSrcweir 
272cdf0e10cSrcweir {/* 29 */    "ServiceManager/DataFilesChangedCheckValue",     UPN_DATA_FILES_CHANGED_CHECK_VALUE,        UPH_DATA_FILES_CHANGED_CHECK_VALUE},
273cdf0e10cSrcweir 
274cdf0e10cSrcweir {/* 30 */    "GrammarChecking/IsAutoCheck",                   UPN_IS_GRAMMAR_AUTO,                      UPH_IS_GRAMMAR_AUTO},
275cdf0e10cSrcweir {/* 31 */    "GrammarChecking/IsInteractiveCheck",            UPN_IS_GRAMMAR_INTERACTIVE,               UPH_IS_GRAMMAR_INTERACTIVE},
276cdf0e10cSrcweir 
277cdf0e10cSrcweir             /* similar to entry 0 (thus no own configuration entry) but with different property name and type */
278cdf0e10cSrcweir {            NULL,											 UPN_DEFAULT_LANGUAGE,                      UPH_DEFAULT_LANGUAGE},
279cdf0e10cSrcweir 
280cdf0e10cSrcweir {            NULL,                                            NULL,                                      -1}
281cdf0e10cSrcweir };
282cdf0e10cSrcweir 
283cdf0e10cSrcweir 
GetPropertyNames()284cdf0e10cSrcweir const uno::Sequence< OUString > & SvtLinguConfigItem::GetPropertyNames()
285cdf0e10cSrcweir {
286cdf0e10cSrcweir     static uno::Sequence< OUString > aNames;
287cdf0e10cSrcweir 	static sal_Bool bInitialized = sal_False;
288cdf0e10cSrcweir 
289cdf0e10cSrcweir 	if (!bInitialized)
290cdf0e10cSrcweir 	{
291cdf0e10cSrcweir 		sal_Int32 nMax = sizeof(aNamesToHdl) / sizeof(aNamesToHdl[0]);
292cdf0e10cSrcweir 
293cdf0e10cSrcweir 		aNames.realloc( nMax );
294cdf0e10cSrcweir 		OUString *pNames = aNames.getArray();
295cdf0e10cSrcweir 		sal_Int32 nIdx = 0;
296cdf0e10cSrcweir 		for (sal_Int32 i = 0; i < nMax;  ++i)
297cdf0e10cSrcweir 		{
298cdf0e10cSrcweir 			const sal_Char *pFullPropName = aNamesToHdl[i].pFullPropName;
299cdf0e10cSrcweir 			if (pFullPropName)
300cdf0e10cSrcweir 				pNames[ nIdx++ ] = A2OU( pFullPropName );
301cdf0e10cSrcweir 		}
302cdf0e10cSrcweir 		aNames.realloc( nIdx );
303cdf0e10cSrcweir 		bInitialized = sal_True;
304cdf0e10cSrcweir 	}
305cdf0e10cSrcweir 	return aNames;
306cdf0e10cSrcweir }
307cdf0e10cSrcweir 
308cdf0e10cSrcweir 
GetHdlByName(sal_Int32 & rnHdl,const OUString & rPropertyName,sal_Bool bFullPropName)309cdf0e10cSrcweir sal_Bool SvtLinguConfigItem::GetHdlByName(
310cdf0e10cSrcweir 	sal_Int32 &rnHdl,
311cdf0e10cSrcweir 	const OUString &rPropertyName,
312cdf0e10cSrcweir 	sal_Bool bFullPropName )
313cdf0e10cSrcweir {
314cdf0e10cSrcweir     NamesToHdl *pEntry = &aNamesToHdl[0];
315cdf0e10cSrcweir 
316cdf0e10cSrcweir 	if (bFullPropName)
317cdf0e10cSrcweir 	{
318cdf0e10cSrcweir 		while (pEntry && pEntry->pFullPropName != NULL)
319cdf0e10cSrcweir 		{
320cdf0e10cSrcweir 			if (0 == rPropertyName.compareToAscii( pEntry->pFullPropName ))
321cdf0e10cSrcweir 			{
322cdf0e10cSrcweir 				rnHdl = pEntry->nHdl;
323cdf0e10cSrcweir 				break;
324cdf0e10cSrcweir 			}
325cdf0e10cSrcweir 			++pEntry;
326cdf0e10cSrcweir 		}
327cdf0e10cSrcweir 		return pEntry && pEntry->pFullPropName != NULL;
328cdf0e10cSrcweir 	}
329cdf0e10cSrcweir 	else
330cdf0e10cSrcweir 	{
331cdf0e10cSrcweir 		while (pEntry && pEntry->pPropName != NULL)
332cdf0e10cSrcweir 		{
333cdf0e10cSrcweir 			if (0 == rPropertyName.compareToAscii( pEntry->pPropName ))
334cdf0e10cSrcweir 			{
335cdf0e10cSrcweir 				rnHdl = pEntry->nHdl;
336cdf0e10cSrcweir 				break;
337cdf0e10cSrcweir 			}
338cdf0e10cSrcweir 			++pEntry;
339cdf0e10cSrcweir 		}
340cdf0e10cSrcweir 		return pEntry && pEntry->pPropName != NULL;
341cdf0e10cSrcweir 	}
342cdf0e10cSrcweir }
343cdf0e10cSrcweir 
344cdf0e10cSrcweir 
GetProperty(const OUString & rPropertyName) const345cdf0e10cSrcweir uno::Any SvtLinguConfigItem::GetProperty( const OUString &rPropertyName ) const
346cdf0e10cSrcweir {
347cdf0e10cSrcweir     osl::MutexGuard aGuard( GetOwnMutex() );
348cdf0e10cSrcweir 
349cdf0e10cSrcweir     sal_Int32 nHdl;
350cdf0e10cSrcweir     return GetHdlByName( nHdl, rPropertyName ) ? GetProperty( nHdl ) : uno::Any();
351cdf0e10cSrcweir }
352cdf0e10cSrcweir 
353cdf0e10cSrcweir 
GetProperty(sal_Int32 nPropertyHandle) const354cdf0e10cSrcweir uno::Any SvtLinguConfigItem::GetProperty( sal_Int32 nPropertyHandle ) const
355cdf0e10cSrcweir {
356cdf0e10cSrcweir     osl::MutexGuard aGuard( GetOwnMutex() );
357cdf0e10cSrcweir 
358cdf0e10cSrcweir     uno::Any aRes;
359cdf0e10cSrcweir 
360cdf0e10cSrcweir     const sal_Int16 *pnVal = 0;
361cdf0e10cSrcweir     const sal_Bool  *pbVal = 0;
362cdf0e10cSrcweir     const sal_Int32 *pnInt32Val = 0;
363cdf0e10cSrcweir 
364cdf0e10cSrcweir     const SvtLinguOptions &rOpt = const_cast< SvtLinguConfigItem * >(this)->aOpt;
365cdf0e10cSrcweir     switch (nPropertyHandle)
366cdf0e10cSrcweir     {
367cdf0e10cSrcweir         case UPH_IS_USE_DICTIONARY_LIST :   pbVal = &rOpt.bIsUseDictionaryList; break;
368cdf0e10cSrcweir         case UPH_IS_IGNORE_CONTROL_CHARACTERS : pbVal = &rOpt.bIsIgnoreControlCharacters;   break;
369cdf0e10cSrcweir         case UPH_IS_HYPH_AUTO :             pbVal = &rOpt.bIsHyphAuto;  break;
370cdf0e10cSrcweir         case UPH_IS_HYPH_SPECIAL :          pbVal = &rOpt.bIsHyphSpecial;   break;
371cdf0e10cSrcweir         case UPH_IS_SPELL_AUTO :            pbVal = &rOpt.bIsSpellAuto; break;
372cdf0e10cSrcweir         case UPH_IS_SPELL_SPECIAL :         pbVal = &rOpt.bIsSpellSpecial;  break;
373cdf0e10cSrcweir         case UPH_IS_WRAP_REVERSE :          pbVal = &rOpt.bIsSpellReverse;  break;
374cdf0e10cSrcweir         case UPH_DEFAULT_LANGUAGE :         pnVal = &rOpt.nDefaultLanguage; break;
375cdf0e10cSrcweir         case UPH_IS_SPELL_CAPITALIZATION :  pbVal = &rOpt.bIsSpellCapitalization;       break;
376cdf0e10cSrcweir         case UPH_IS_SPELL_WITH_DIGITS :     pbVal = &rOpt.bIsSpellWithDigits;   break;
377cdf0e10cSrcweir         case UPH_IS_SPELL_UPPER_CASE :      pbVal = &rOpt.bIsSpellUpperCase;        break;
378cdf0e10cSrcweir         case UPH_HYPH_MIN_LEADING :         pnVal = &rOpt.nHyphMinLeading;      break;
379cdf0e10cSrcweir         case UPH_HYPH_MIN_TRAILING :        pnVal = &rOpt.nHyphMinTrailing; break;
380cdf0e10cSrcweir         case UPH_HYPH_MIN_WORD_LENGTH :     pnVal = &rOpt.nHyphMinWordLength;   break;
381cdf0e10cSrcweir         case UPH_ACTIVE_DICTIONARIES :
382cdf0e10cSrcweir         {
383cdf0e10cSrcweir             aRes <<= rOpt.aActiveDics;
384cdf0e10cSrcweir             break;
385cdf0e10cSrcweir         }
386cdf0e10cSrcweir         case UPH_ACTIVE_CONVERSION_DICTIONARIES :
387cdf0e10cSrcweir         {
388cdf0e10cSrcweir             aRes <<= rOpt.aActiveConvDics;
389cdf0e10cSrcweir             break;
390cdf0e10cSrcweir         }
391cdf0e10cSrcweir         case UPH_DEFAULT_LOCALE :
392cdf0e10cSrcweir         {
393cdf0e10cSrcweir             lang::Locale aLocale( MsLangId::convertLanguageToLocale( rOpt.nDefaultLanguage, false ) );
394cdf0e10cSrcweir             aRes.setValue( &aLocale, ::getCppuType((lang::Locale*)0 ));
395cdf0e10cSrcweir             break;
396cdf0e10cSrcweir         }
397cdf0e10cSrcweir         case UPH_DEFAULT_LOCALE_CJK :
398cdf0e10cSrcweir         {
399cdf0e10cSrcweir             lang::Locale aLocale( MsLangId::convertLanguageToLocale( rOpt.nDefaultLanguage_CJK, false ) );
400cdf0e10cSrcweir             aRes.setValue( &aLocale, ::getCppuType((lang::Locale*)0 ));
401cdf0e10cSrcweir             break;
402cdf0e10cSrcweir         }
403cdf0e10cSrcweir         case UPH_DEFAULT_LOCALE_CTL :
404cdf0e10cSrcweir         {
405cdf0e10cSrcweir             lang::Locale aLocale( MsLangId::convertLanguageToLocale( rOpt.nDefaultLanguage_CTL, false ) );
406cdf0e10cSrcweir             aRes.setValue( &aLocale, ::getCppuType((lang::Locale*)0 ));
407cdf0e10cSrcweir             break;
408cdf0e10cSrcweir         }
409cdf0e10cSrcweir         case UPH_IS_IGNORE_POST_POSITIONAL_WORD :       pbVal = &rOpt.bIsIgnorePostPositionalWord; break;
410cdf0e10cSrcweir         case UPH_IS_AUTO_CLOSE_DIALOG :                 pbVal = &rOpt.bIsAutoCloseDialog; break;
411cdf0e10cSrcweir         case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST :  pbVal = &rOpt.bIsShowEntriesRecentlyUsedFirst; break;
412cdf0e10cSrcweir         case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES :       pbVal = &rOpt.bIsAutoReplaceUniqueEntries; break;
413cdf0e10cSrcweir 
414cdf0e10cSrcweir         case UPH_IS_DIRECTION_TO_SIMPLIFIED:            pbVal = &rOpt.bIsDirectionToSimplified; break;
415cdf0e10cSrcweir         case UPH_IS_USE_CHARACTER_VARIANTS :            pbVal = &rOpt.bIsUseCharacterVariants; break;
416cdf0e10cSrcweir         case UPH_IS_TRANSLATE_COMMON_TERMS :            pbVal = &rOpt.bIsTranslateCommonTerms; break;
417cdf0e10cSrcweir         case UPH_IS_REVERSE_MAPPING :                   pbVal = &rOpt.bIsReverseMapping; break;
418cdf0e10cSrcweir 
419cdf0e10cSrcweir         case UPH_DATA_FILES_CHANGED_CHECK_VALUE :       pnInt32Val = &rOpt.nDataFilesChangedCheckValue; break;
420cdf0e10cSrcweir         case UPH_IS_GRAMMAR_AUTO:                       pbVal = &rOpt.bIsGrammarAuto; break;
421cdf0e10cSrcweir         case UPH_IS_GRAMMAR_INTERACTIVE:                pbVal = &rOpt.bIsGrammarInteractive; break;
422cdf0e10cSrcweir         default :
423cdf0e10cSrcweir             DBG_ASSERT( 0, "unexpected property handle" );
424cdf0e10cSrcweir     }
425cdf0e10cSrcweir 
426cdf0e10cSrcweir     if (pbVal)
427cdf0e10cSrcweir         aRes <<= *pbVal;
428cdf0e10cSrcweir     else if (pnVal)
429cdf0e10cSrcweir         aRes <<= *pnVal;
430cdf0e10cSrcweir     else if (pnInt32Val)
431cdf0e10cSrcweir         aRes <<= *pnInt32Val;
432cdf0e10cSrcweir 
433cdf0e10cSrcweir     return aRes;
434cdf0e10cSrcweir }
435cdf0e10cSrcweir 
436cdf0e10cSrcweir 
SetProperty(const OUString & rPropertyName,const uno::Any & rValue)437cdf0e10cSrcweir sal_Bool SvtLinguConfigItem::SetProperty( const OUString &rPropertyName, const uno::Any &rValue )
438cdf0e10cSrcweir {
439cdf0e10cSrcweir     osl::MutexGuard aGuard( GetOwnMutex() );
440cdf0e10cSrcweir 
441cdf0e10cSrcweir     sal_Bool bSucc = sal_False;
442cdf0e10cSrcweir     sal_Int32 nHdl;
443cdf0e10cSrcweir     if (GetHdlByName( nHdl, rPropertyName ))
444cdf0e10cSrcweir         bSucc = SetProperty( nHdl, rValue );
445cdf0e10cSrcweir     return bSucc;
446cdf0e10cSrcweir }
447cdf0e10cSrcweir 
448cdf0e10cSrcweir 
SetProperty(sal_Int32 nPropertyHandle,const uno::Any & rValue)449cdf0e10cSrcweir sal_Bool SvtLinguConfigItem::SetProperty( sal_Int32 nPropertyHandle, const uno::Any &rValue )
450cdf0e10cSrcweir {
451cdf0e10cSrcweir     osl::MutexGuard aGuard( GetOwnMutex() );
452cdf0e10cSrcweir 
453cdf0e10cSrcweir     sal_Bool bSucc = sal_False;
454cdf0e10cSrcweir     if (!rValue.hasValue())
455cdf0e10cSrcweir         return bSucc;
456cdf0e10cSrcweir 
457cdf0e10cSrcweir     sal_Bool bMod = sal_False;
458cdf0e10cSrcweir 
459cdf0e10cSrcweir     sal_Int16 *pnVal = 0;
460cdf0e10cSrcweir     sal_Bool  *pbVal = 0;
461cdf0e10cSrcweir     sal_Int32 *pnInt32Val = 0;
462cdf0e10cSrcweir 
463cdf0e10cSrcweir     SvtLinguOptions &rOpt = aOpt;
464cdf0e10cSrcweir     switch (nPropertyHandle)
465cdf0e10cSrcweir     {
466cdf0e10cSrcweir         case UPH_IS_USE_DICTIONARY_LIST :   pbVal = &rOpt.bIsUseDictionaryList;    break;
467cdf0e10cSrcweir         case UPH_IS_IGNORE_CONTROL_CHARACTERS : pbVal = &rOpt.bIsIgnoreControlCharacters;  break;
468cdf0e10cSrcweir         case UPH_IS_HYPH_AUTO :             pbVal = &rOpt.bIsHyphAuto; break;
469cdf0e10cSrcweir         case UPH_IS_HYPH_SPECIAL :          pbVal = &rOpt.bIsHyphSpecial;  break;
470cdf0e10cSrcweir         case UPH_IS_SPELL_AUTO :            pbVal = &rOpt.bIsSpellAuto;    break;
471cdf0e10cSrcweir         case UPH_IS_SPELL_SPECIAL :         pbVal = &rOpt.bIsSpellSpecial; break;
472cdf0e10cSrcweir         case UPH_IS_WRAP_REVERSE :          pbVal = &rOpt.bIsSpellReverse; break;
473cdf0e10cSrcweir         case UPH_DEFAULT_LANGUAGE :         pnVal = &rOpt.nDefaultLanguage;    break;
474cdf0e10cSrcweir         case UPH_IS_SPELL_CAPITALIZATION :  pbVal = &rOpt.bIsSpellCapitalization;      break;
475cdf0e10cSrcweir         case UPH_IS_SPELL_WITH_DIGITS :     pbVal = &rOpt.bIsSpellWithDigits;  break;
476cdf0e10cSrcweir         case UPH_IS_SPELL_UPPER_CASE :      pbVal = &rOpt.bIsSpellUpperCase;       break;
477cdf0e10cSrcweir         case UPH_HYPH_MIN_LEADING :         pnVal = &rOpt.nHyphMinLeading;     break;
478cdf0e10cSrcweir         case UPH_HYPH_MIN_TRAILING :        pnVal = &rOpt.nHyphMinTrailing;    break;
479cdf0e10cSrcweir         case UPH_HYPH_MIN_WORD_LENGTH :     pnVal = &rOpt.nHyphMinWordLength;  break;
480cdf0e10cSrcweir         case UPH_ACTIVE_DICTIONARIES :
481cdf0e10cSrcweir         {
482cdf0e10cSrcweir             rValue >>= rOpt.aActiveDics;
483cdf0e10cSrcweir             bMod = sal_True;
484cdf0e10cSrcweir             break;
485cdf0e10cSrcweir         }
486cdf0e10cSrcweir         case UPH_ACTIVE_CONVERSION_DICTIONARIES :
487cdf0e10cSrcweir         {
488cdf0e10cSrcweir             rValue >>= rOpt.aActiveConvDics;
489cdf0e10cSrcweir             bMod = sal_True;
490cdf0e10cSrcweir             break;
491cdf0e10cSrcweir         }
492cdf0e10cSrcweir         case UPH_DEFAULT_LOCALE :
493cdf0e10cSrcweir         {
494cdf0e10cSrcweir             bSucc = lcl_SetLocale( rOpt.nDefaultLanguage, rValue );
495cdf0e10cSrcweir             bMod = bSucc;
496cdf0e10cSrcweir             break;
497cdf0e10cSrcweir         }
498cdf0e10cSrcweir         case UPH_DEFAULT_LOCALE_CJK :
499cdf0e10cSrcweir         {
500cdf0e10cSrcweir             bSucc = lcl_SetLocale( rOpt.nDefaultLanguage_CJK, rValue );
501cdf0e10cSrcweir             bMod = bSucc;
502cdf0e10cSrcweir             break;
503cdf0e10cSrcweir         }
504cdf0e10cSrcweir         case UPH_DEFAULT_LOCALE_CTL :
505cdf0e10cSrcweir         {
506cdf0e10cSrcweir             bSucc = lcl_SetLocale( rOpt.nDefaultLanguage_CTL, rValue );
507cdf0e10cSrcweir             bMod = bSucc;
508cdf0e10cSrcweir             break;
509cdf0e10cSrcweir         }
510cdf0e10cSrcweir         case UPH_IS_IGNORE_POST_POSITIONAL_WORD :       pbVal = &rOpt.bIsIgnorePostPositionalWord; break;
511cdf0e10cSrcweir         case UPH_IS_AUTO_CLOSE_DIALOG :                 pbVal = &rOpt.bIsAutoCloseDialog; break;
512cdf0e10cSrcweir         case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST :  pbVal = &rOpt.bIsShowEntriesRecentlyUsedFirst; break;
513cdf0e10cSrcweir         case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES :       pbVal = &rOpt.bIsAutoReplaceUniqueEntries; break;
514cdf0e10cSrcweir 
515cdf0e10cSrcweir         case UPH_IS_DIRECTION_TO_SIMPLIFIED :           pbVal = &rOpt.bIsDirectionToSimplified; break;
516cdf0e10cSrcweir         case UPH_IS_USE_CHARACTER_VARIANTS :            pbVal = &rOpt.bIsUseCharacterVariants; break;
517cdf0e10cSrcweir         case UPH_IS_TRANSLATE_COMMON_TERMS :            pbVal = &rOpt.bIsTranslateCommonTerms; break;
518cdf0e10cSrcweir         case UPH_IS_REVERSE_MAPPING :                   pbVal = &rOpt.bIsReverseMapping; break;
519cdf0e10cSrcweir 
520cdf0e10cSrcweir         case UPH_DATA_FILES_CHANGED_CHECK_VALUE :       pnInt32Val = &rOpt.nDataFilesChangedCheckValue; break;
521cdf0e10cSrcweir         case UPH_IS_GRAMMAR_AUTO:                       pbVal = &rOpt.bIsGrammarAuto; break;
522cdf0e10cSrcweir         case UPH_IS_GRAMMAR_INTERACTIVE:                pbVal = &rOpt.bIsGrammarInteractive; break;
523cdf0e10cSrcweir         default :
524cdf0e10cSrcweir             DBG_ASSERT( 0, "unexpected property handle" );
525cdf0e10cSrcweir     }
526cdf0e10cSrcweir 
527cdf0e10cSrcweir     if (pbVal)
528cdf0e10cSrcweir     {
529cdf0e10cSrcweir         sal_Bool bNew = sal_Bool();
530cdf0e10cSrcweir         if (rValue >>= bNew)
531cdf0e10cSrcweir         {
532cdf0e10cSrcweir             if (bNew != *pbVal)
533cdf0e10cSrcweir             {
534cdf0e10cSrcweir                 *pbVal = bNew;
535cdf0e10cSrcweir                 bMod = sal_True;
536cdf0e10cSrcweir             }
537cdf0e10cSrcweir             bSucc = sal_True;
538cdf0e10cSrcweir         }
539cdf0e10cSrcweir     }
540cdf0e10cSrcweir     else if (pnVal)
541cdf0e10cSrcweir     {
542cdf0e10cSrcweir         sal_Int16 nNew = sal_Int16();
543cdf0e10cSrcweir         if (rValue >>= nNew)
544cdf0e10cSrcweir         {
545cdf0e10cSrcweir             if (nNew != *pnVal)
546cdf0e10cSrcweir             {
547cdf0e10cSrcweir                 *pnVal = nNew;
548cdf0e10cSrcweir                 bMod = sal_True;
549cdf0e10cSrcweir             }
550cdf0e10cSrcweir             bSucc = sal_True;
551cdf0e10cSrcweir         }
552cdf0e10cSrcweir     }
553cdf0e10cSrcweir     else if (pnInt32Val)
554cdf0e10cSrcweir     {
555cdf0e10cSrcweir         sal_Int32 nNew = sal_Int32();
556cdf0e10cSrcweir         if (rValue >>= nNew)
557cdf0e10cSrcweir         {
558cdf0e10cSrcweir             if (nNew != *pnInt32Val)
559cdf0e10cSrcweir             {
560cdf0e10cSrcweir                 *pnInt32Val = nNew;
561cdf0e10cSrcweir                 bMod = sal_True;
562cdf0e10cSrcweir             }
563cdf0e10cSrcweir             bSucc = sal_True;
564cdf0e10cSrcweir         }
565cdf0e10cSrcweir     }
566cdf0e10cSrcweir 
567cdf0e10cSrcweir     if (bMod)
568cdf0e10cSrcweir         SetModified();
569cdf0e10cSrcweir 
570cdf0e10cSrcweir 	NotifyListeners(0);
571cdf0e10cSrcweir     return bSucc;
572cdf0e10cSrcweir }
573cdf0e10cSrcweir 
574cdf0e10cSrcweir 
GetOptions(SvtLinguOptions & rOptions) const575cdf0e10cSrcweir sal_Bool SvtLinguConfigItem::GetOptions( SvtLinguOptions &rOptions ) const
576cdf0e10cSrcweir {
577cdf0e10cSrcweir     osl::MutexGuard aGuard( GetOwnMutex() );
578cdf0e10cSrcweir 
579cdf0e10cSrcweir     rOptions = aOpt;
580cdf0e10cSrcweir     return sal_True;
581cdf0e10cSrcweir }
582cdf0e10cSrcweir 
583cdf0e10cSrcweir 
SetOptions(const SvtLinguOptions & rOptions)584cdf0e10cSrcweir sal_Bool SvtLinguConfigItem::SetOptions( const SvtLinguOptions &rOptions )
585cdf0e10cSrcweir {
586cdf0e10cSrcweir     osl::MutexGuard aGuard( GetOwnMutex() );
587cdf0e10cSrcweir 
588cdf0e10cSrcweir     aOpt = rOptions;
589cdf0e10cSrcweir     SetModified();
590cdf0e10cSrcweir 	NotifyListeners(0);
591cdf0e10cSrcweir     return sal_True;
592cdf0e10cSrcweir }
593cdf0e10cSrcweir 
594cdf0e10cSrcweir 
LoadOptions(const uno::Sequence<OUString> & rProperyNames)595cdf0e10cSrcweir sal_Bool SvtLinguConfigItem::LoadOptions( const uno::Sequence< OUString > &rProperyNames )
596cdf0e10cSrcweir {
597cdf0e10cSrcweir     osl::MutexGuard aGuard( GetOwnMutex() );
598cdf0e10cSrcweir 
599cdf0e10cSrcweir     sal_Bool bRes = sal_False;
600cdf0e10cSrcweir 
601cdf0e10cSrcweir     const OUString *pProperyNames = rProperyNames.getConstArray();
602cdf0e10cSrcweir     sal_Int32 nProps = rProperyNames.getLength();
603cdf0e10cSrcweir 
604cdf0e10cSrcweir     const uno::Sequence< uno::Any > aValues = GetProperties( rProperyNames );
605cdf0e10cSrcweir     const uno::Sequence< sal_Bool > aROStates = GetReadOnlyStates( rProperyNames );
606cdf0e10cSrcweir 
607cdf0e10cSrcweir     if (nProps  &&  aValues.getLength() == nProps &&  aROStates.getLength() == nProps)
608cdf0e10cSrcweir     {
609cdf0e10cSrcweir         SvtLinguOptions &rOpt = aOpt;
610cdf0e10cSrcweir 
611cdf0e10cSrcweir         const uno::Any *pValue = aValues.getConstArray();
612cdf0e10cSrcweir         const sal_Bool *pROStates = aROStates.getConstArray();
613cdf0e10cSrcweir         for (sal_Int32 i = 0;  i < nProps;  ++i)
614cdf0e10cSrcweir         {
615cdf0e10cSrcweir             const uno::Any &rVal = pValue[i];
616cdf0e10cSrcweir             sal_Int32 nPropertyHandle;
617cdf0e10cSrcweir             GetHdlByName( nPropertyHandle, pProperyNames[i], sal_True );
618cdf0e10cSrcweir             switch ( nPropertyHandle )
619cdf0e10cSrcweir             {
620cdf0e10cSrcweir                 case UPH_DEFAULT_LOCALE :
621cdf0e10cSrcweir                     { rOpt.bRODefaultLanguage = pROStates[i]; rOpt.nDefaultLanguage = lcl_CfgAnyToLanguage( rVal ); } break;
622cdf0e10cSrcweir                 case UPH_ACTIVE_DICTIONARIES :
623cdf0e10cSrcweir                     { rOpt.bROActiveDics = pROStates[i]; rVal >>= rOpt.aActiveDics;   } break;
624cdf0e10cSrcweir                 case UPH_IS_USE_DICTIONARY_LIST :
625cdf0e10cSrcweir                     { rOpt.bROIsUseDictionaryList = pROStates[i]; rVal >>= rOpt.bIsUseDictionaryList;  } break;
626cdf0e10cSrcweir                 case UPH_IS_IGNORE_CONTROL_CHARACTERS :
627cdf0e10cSrcweir                     { rOpt.bROIsIgnoreControlCharacters = pROStates[i]; rVal >>= rOpt.bIsIgnoreControlCharacters;    } break;
628cdf0e10cSrcweir                 case UPH_DEFAULT_LOCALE_CJK :
629cdf0e10cSrcweir                     { rOpt.bRODefaultLanguage_CJK = pROStates[i]; rOpt.nDefaultLanguage_CJK = lcl_CfgAnyToLanguage( rVal );    } break;
630cdf0e10cSrcweir                 case UPH_DEFAULT_LOCALE_CTL :
631cdf0e10cSrcweir                     { rOpt.bRODefaultLanguage_CTL = pROStates[i]; rOpt.nDefaultLanguage_CTL = lcl_CfgAnyToLanguage( rVal );    } break;
632cdf0e10cSrcweir 
633cdf0e10cSrcweir                 case UPH_IS_SPELL_UPPER_CASE :
634cdf0e10cSrcweir                     { rOpt.bROIsSpellUpperCase = pROStates[i]; rVal >>= rOpt.bIsSpellUpperCase; } break;
635cdf0e10cSrcweir                 case UPH_IS_SPELL_WITH_DIGITS :
636cdf0e10cSrcweir                     { rOpt.bROIsSpellWithDigits = pROStates[i]; rVal >>= rOpt.bIsSpellWithDigits;    } break;
637cdf0e10cSrcweir                 case UPH_IS_SPELL_CAPITALIZATION :
638cdf0e10cSrcweir                     { rOpt.bROIsSpellCapitalization = pROStates[i]; rVal >>= rOpt.bIsSpellCapitalization;    } break;
639cdf0e10cSrcweir                 case UPH_IS_SPELL_AUTO :
640cdf0e10cSrcweir                     { rOpt.bROIsSpellAuto = pROStates[i]; rVal >>= rOpt.bIsSpellAuto;  } break;
641cdf0e10cSrcweir                 case UPH_IS_SPELL_SPECIAL :
642cdf0e10cSrcweir                     { rOpt.bROIsSpellSpecial = pROStates[i]; rVal >>= rOpt.bIsSpellSpecial;   } break;
643cdf0e10cSrcweir                 case UPH_IS_WRAP_REVERSE :
644cdf0e10cSrcweir                     { rOpt.bROIsSpellReverse = pROStates[i]; rVal >>= rOpt.bIsSpellReverse;   } break;
645cdf0e10cSrcweir 
646cdf0e10cSrcweir                 case UPH_HYPH_MIN_LEADING :
647cdf0e10cSrcweir                     { rOpt.bROHyphMinLeading = pROStates[i]; rVal >>= rOpt.nHyphMinLeading;   } break;
648cdf0e10cSrcweir                 case UPH_HYPH_MIN_TRAILING :
649cdf0e10cSrcweir                     { rOpt.bROHyphMinTrailing = pROStates[i]; rVal >>= rOpt.nHyphMinTrailing;  } break;
650cdf0e10cSrcweir                 case UPH_HYPH_MIN_WORD_LENGTH :
651cdf0e10cSrcweir                     { rOpt.bROHyphMinWordLength = pROStates[i]; rVal >>= rOpt.nHyphMinWordLength;    } break;
652cdf0e10cSrcweir                 case UPH_IS_HYPH_SPECIAL :
653cdf0e10cSrcweir                     { rOpt.bROIsHyphSpecial = pROStates[i]; rVal >>= rOpt.bIsHyphSpecial;    } break;
654cdf0e10cSrcweir                 case UPH_IS_HYPH_AUTO :
655cdf0e10cSrcweir                     { rOpt.bROIsHyphAuto = pROStates[i]; rVal >>= rOpt.bIsHyphAuto;   } break;
656cdf0e10cSrcweir 
657cdf0e10cSrcweir                 case UPH_ACTIVE_CONVERSION_DICTIONARIES : { rOpt.bROActiveConvDics = pROStates[i]; rVal >>= rOpt.aActiveConvDics;   } break;
658cdf0e10cSrcweir 
659cdf0e10cSrcweir                 case UPH_IS_IGNORE_POST_POSITIONAL_WORD :
660cdf0e10cSrcweir                     { rOpt.bROIsIgnorePostPositionalWord = pROStates[i]; rVal >>= rOpt.bIsIgnorePostPositionalWord;  } break;
661cdf0e10cSrcweir                 case UPH_IS_AUTO_CLOSE_DIALOG :
662cdf0e10cSrcweir                     { rOpt.bROIsAutoCloseDialog = pROStates[i]; rVal >>= rOpt.bIsAutoCloseDialog;  } break;
663cdf0e10cSrcweir                 case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST :
664cdf0e10cSrcweir                     { rOpt.bROIsShowEntriesRecentlyUsedFirst = pROStates[i]; rVal >>= rOpt.bIsShowEntriesRecentlyUsedFirst;  } break;
665cdf0e10cSrcweir                 case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES :
666cdf0e10cSrcweir                     { rOpt.bROIsAutoReplaceUniqueEntries = pROStates[i]; rVal >>= rOpt.bIsAutoReplaceUniqueEntries;  } break;
667cdf0e10cSrcweir 
668cdf0e10cSrcweir                 case UPH_IS_DIRECTION_TO_SIMPLIFIED :
669cdf0e10cSrcweir                     { rOpt.bROIsDirectionToSimplified = pROStates[i];
670cdf0e10cSrcweir                             if( ! (rVal >>= rOpt.bIsDirectionToSimplified) )
671cdf0e10cSrcweir                             {
672cdf0e10cSrcweir                                 //default is locale dependent:
673cdf0e10cSrcweir                                 if(  rOpt.nDefaultLanguage_CJK == LANGUAGE_CHINESE_HONGKONG
674cdf0e10cSrcweir                                   || rOpt.nDefaultLanguage_CJK == LANGUAGE_CHINESE_MACAU
675cdf0e10cSrcweir                                   || rOpt.nDefaultLanguage_CJK == LANGUAGE_CHINESE_TRADITIONAL )
676cdf0e10cSrcweir                                 {
677cdf0e10cSrcweir                                     rOpt.bIsDirectionToSimplified = sal_False;
678cdf0e10cSrcweir                                 }
679cdf0e10cSrcweir                                 else
680cdf0e10cSrcweir                                 {
681cdf0e10cSrcweir                                     rOpt.bIsDirectionToSimplified = sal_True;
682cdf0e10cSrcweir                                 }
683cdf0e10cSrcweir                             }
684cdf0e10cSrcweir                     } break;
685cdf0e10cSrcweir                 case UPH_IS_USE_CHARACTER_VARIANTS :
686cdf0e10cSrcweir                     { rOpt.bROIsUseCharacterVariants = pROStates[i]; rVal >>= rOpt.bIsUseCharacterVariants;  } break;
687cdf0e10cSrcweir                 case UPH_IS_TRANSLATE_COMMON_TERMS :
688cdf0e10cSrcweir                     { rOpt.bROIsTranslateCommonTerms = pROStates[i]; rVal >>= rOpt.bIsTranslateCommonTerms;  } break;
689cdf0e10cSrcweir                 case UPH_IS_REVERSE_MAPPING :
690cdf0e10cSrcweir                     { rOpt.bROIsReverseMapping = pROStates[i]; rVal >>= rOpt.bIsReverseMapping;  } break;
691cdf0e10cSrcweir 
692cdf0e10cSrcweir                 case UPH_DATA_FILES_CHANGED_CHECK_VALUE :
693cdf0e10cSrcweir                     { rOpt.bRODataFilesChangedCheckValue = pROStates[i]; rVal >>= rOpt.nDataFilesChangedCheckValue;  } break;
694cdf0e10cSrcweir 
695cdf0e10cSrcweir                 case UPH_IS_GRAMMAR_AUTO:
696cdf0e10cSrcweir                     { rOpt.bROIsGrammarAuto = pROStates[i]; rVal >>= rOpt.bIsGrammarAuto; }
697cdf0e10cSrcweir                 break;
698cdf0e10cSrcweir                 case UPH_IS_GRAMMAR_INTERACTIVE:
699cdf0e10cSrcweir                     { rOpt.bROIsGrammarInteractive = pROStates[i]; rVal >>= rOpt.bIsGrammarInteractive; }
700cdf0e10cSrcweir                 break;
701cdf0e10cSrcweir 
702cdf0e10cSrcweir                 default:
703cdf0e10cSrcweir                     DBG_ASSERT( 0, "unexpected case" );
704cdf0e10cSrcweir             }
705cdf0e10cSrcweir         }
706cdf0e10cSrcweir 
707cdf0e10cSrcweir         bRes = sal_True;
708cdf0e10cSrcweir     }
709cdf0e10cSrcweir     DBG_ASSERT( bRes, "LoadOptions failed" );
710cdf0e10cSrcweir 
711cdf0e10cSrcweir     return bRes;
712cdf0e10cSrcweir }
713cdf0e10cSrcweir 
714cdf0e10cSrcweir 
SaveOptions(const uno::Sequence<OUString> & rProperyNames)715cdf0e10cSrcweir sal_Bool SvtLinguConfigItem::SaveOptions( const uno::Sequence< OUString > &rProperyNames )
716cdf0e10cSrcweir {
717cdf0e10cSrcweir     if (!IsModified())
718cdf0e10cSrcweir         return sal_True;
719cdf0e10cSrcweir 
720cdf0e10cSrcweir     osl::MutexGuard aGuard( GetOwnMutex() );
721cdf0e10cSrcweir 
722cdf0e10cSrcweir     sal_Bool bRet = sal_False;
723cdf0e10cSrcweir     const uno::Type &rBOOL     = ::getBooleanCppuType();
724cdf0e10cSrcweir     const uno::Type &rINT16    = ::getCppuType( (sal_Int16 *) NULL );
725cdf0e10cSrcweir     const uno::Type &rINT32    = ::getCppuType( (sal_Int32 *) NULL );
726cdf0e10cSrcweir 
727cdf0e10cSrcweir     sal_Int32 nProps = rProperyNames.getLength();
728cdf0e10cSrcweir     uno::Sequence< uno::Any > aValues( nProps );
729cdf0e10cSrcweir     uno::Any *pValue = aValues.getArray();
730cdf0e10cSrcweir 
731cdf0e10cSrcweir     if (nProps  &&  aValues.getLength() == nProps)
732cdf0e10cSrcweir     {
733cdf0e10cSrcweir         const SvtLinguOptions &rOpt = aOpt;
734cdf0e10cSrcweir 
735cdf0e10cSrcweir         OUString aTmp( lcl_LanguageToCfgLocaleStr( rOpt.nDefaultLanguage ) );
736cdf0e10cSrcweir         *pValue++ = uno::makeAny( aTmp );                               //   0
737cdf0e10cSrcweir         *pValue++ = uno::makeAny( rOpt.aActiveDics );                   //   1
738cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsUseDictionaryList, rBOOL );        //   2
739cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsIgnoreControlCharacters, rBOOL );  //   3
740cdf0e10cSrcweir         aTmp = lcl_LanguageToCfgLocaleStr( rOpt.nDefaultLanguage_CJK );
741cdf0e10cSrcweir         *pValue++ = uno::makeAny( aTmp );                               //   5
742cdf0e10cSrcweir         aTmp = lcl_LanguageToCfgLocaleStr( rOpt.nDefaultLanguage_CTL );
743cdf0e10cSrcweir         *pValue++ = uno::makeAny( aTmp );                               //   6
744cdf0e10cSrcweir 
745cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsSpellUpperCase, rBOOL );          //   7
746cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsSpellWithDigits, rBOOL );         //   8
747cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsSpellCapitalization, rBOOL );     //   9
748cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsSpellAuto, rBOOL );               //  10
749cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsSpellSpecial, rBOOL );            //  11
750cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsSpellReverse, rBOOL );            //  14
751cdf0e10cSrcweir 
752cdf0e10cSrcweir         pValue++->setValue( &rOpt.nHyphMinLeading, rINT16 );           //  15
753cdf0e10cSrcweir         pValue++->setValue( &rOpt.nHyphMinTrailing, rINT16 );          //  16
754cdf0e10cSrcweir         pValue++->setValue( &rOpt.nHyphMinWordLength, rINT16 );        //  17
755cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsHyphSpecial, rBOOL );             //  18
756cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsHyphAuto, rBOOL );                //  19
757cdf0e10cSrcweir 
758cdf0e10cSrcweir         *pValue++ = uno::makeAny( rOpt.aActiveConvDics );               //   20
759cdf0e10cSrcweir 
760cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsIgnorePostPositionalWord, rBOOL ); //  21
761cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsAutoCloseDialog, rBOOL );          //  22
762cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsShowEntriesRecentlyUsedFirst, rBOOL ); //  23
763cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsAutoReplaceUniqueEntries, rBOOL ); //  24
764cdf0e10cSrcweir 
765cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsDirectionToSimplified, rBOOL ); //  25
766cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsUseCharacterVariants, rBOOL ); //  26
767cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsTranslateCommonTerms, rBOOL ); //  27
768cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsReverseMapping, rBOOL ); //  28
769cdf0e10cSrcweir 
770cdf0e10cSrcweir         pValue++->setValue( &rOpt.nDataFilesChangedCheckValue, rINT32 ); //  29
771cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsGrammarAuto, rBOOL ); //  30
772cdf0e10cSrcweir         pValue++->setValue( &rOpt.bIsGrammarInteractive, rBOOL ); // 31
773cdf0e10cSrcweir 
774cdf0e10cSrcweir         bRet |= PutProperties( rProperyNames, aValues );
775cdf0e10cSrcweir     }
776cdf0e10cSrcweir 
777cdf0e10cSrcweir     if (bRet)
778cdf0e10cSrcweir         ClearModified();
779cdf0e10cSrcweir 
780cdf0e10cSrcweir     return bRet;
781cdf0e10cSrcweir }
782cdf0e10cSrcweir 
IsReadOnly(const rtl::OUString & rPropertyName) const783cdf0e10cSrcweir sal_Bool SvtLinguConfigItem::IsReadOnly( const rtl::OUString &rPropertyName ) const
784cdf0e10cSrcweir {
785cdf0e10cSrcweir     osl::MutexGuard aGuard( GetOwnMutex() );
786cdf0e10cSrcweir 
787cdf0e10cSrcweir     sal_Bool bReadOnly = sal_False;
788cdf0e10cSrcweir     sal_Int32 nHdl;
789cdf0e10cSrcweir     if (GetHdlByName( nHdl, rPropertyName ))
790cdf0e10cSrcweir         bReadOnly = IsReadOnly( nHdl );
791cdf0e10cSrcweir     return bReadOnly;
792cdf0e10cSrcweir }
793cdf0e10cSrcweir 
IsReadOnly(sal_Int32 nPropertyHandle) const794cdf0e10cSrcweir sal_Bool SvtLinguConfigItem::IsReadOnly( sal_Int32 nPropertyHandle ) const
795cdf0e10cSrcweir {
796cdf0e10cSrcweir     osl::MutexGuard aGuard( GetOwnMutex() );
797cdf0e10cSrcweir 
798cdf0e10cSrcweir     sal_Bool bReadOnly = sal_False;
799cdf0e10cSrcweir 
800cdf0e10cSrcweir     const SvtLinguOptions &rOpt = const_cast< SvtLinguConfigItem * >(this)->aOpt;
801cdf0e10cSrcweir     switch(nPropertyHandle)
802cdf0e10cSrcweir     {
803cdf0e10cSrcweir         case UPH_IS_USE_DICTIONARY_LIST         : bReadOnly = rOpt.bROIsUseDictionaryList      ; break;
804cdf0e10cSrcweir         case UPH_IS_IGNORE_CONTROL_CHARACTERS   : bReadOnly = rOpt.bROIsIgnoreControlCharacters; break;
805cdf0e10cSrcweir         case UPH_IS_HYPH_AUTO                   : bReadOnly = rOpt.bROIsHyphAuto               ; break;
806cdf0e10cSrcweir         case UPH_IS_HYPH_SPECIAL                : bReadOnly = rOpt.bROIsHyphSpecial            ; break;
807cdf0e10cSrcweir         case UPH_IS_SPELL_AUTO                  : bReadOnly = rOpt.bROIsSpellAuto              ; break;
808cdf0e10cSrcweir         case UPH_IS_SPELL_SPECIAL               : bReadOnly = rOpt.bROIsSpellSpecial           ; break;
809cdf0e10cSrcweir         case UPH_IS_WRAP_REVERSE                : bReadOnly = rOpt.bROIsSpellReverse           ; break;
810cdf0e10cSrcweir         case UPH_DEFAULT_LANGUAGE               : bReadOnly = rOpt.bRODefaultLanguage          ; break;
811cdf0e10cSrcweir         case UPH_IS_SPELL_CAPITALIZATION        : bReadOnly = rOpt.bROIsSpellCapitalization    ; break;
812cdf0e10cSrcweir         case UPH_IS_SPELL_WITH_DIGITS           : bReadOnly = rOpt.bROIsSpellWithDigits        ; break;
813cdf0e10cSrcweir         case UPH_IS_SPELL_UPPER_CASE            : bReadOnly = rOpt.bROIsSpellUpperCase         ; break;
814cdf0e10cSrcweir         case UPH_HYPH_MIN_LEADING               : bReadOnly = rOpt.bROHyphMinLeading           ; break;
815cdf0e10cSrcweir         case UPH_HYPH_MIN_TRAILING              : bReadOnly = rOpt.bROHyphMinTrailing          ; break;
816cdf0e10cSrcweir         case UPH_HYPH_MIN_WORD_LENGTH           : bReadOnly = rOpt.bROHyphMinWordLength        ; break;
817cdf0e10cSrcweir         case UPH_ACTIVE_DICTIONARIES            : bReadOnly = rOpt.bROActiveDics               ; break;
818cdf0e10cSrcweir         case UPH_ACTIVE_CONVERSION_DICTIONARIES : bReadOnly = rOpt.bROActiveConvDics           ; break;
819cdf0e10cSrcweir         case UPH_DEFAULT_LOCALE                 : bReadOnly = rOpt.bRODefaultLanguage          ; break;
820cdf0e10cSrcweir         case UPH_DEFAULT_LOCALE_CJK             : bReadOnly = rOpt.bRODefaultLanguage_CJK      ; break;
821cdf0e10cSrcweir         case UPH_DEFAULT_LOCALE_CTL             : bReadOnly = rOpt.bRODefaultLanguage_CTL      ; break;
822cdf0e10cSrcweir         case UPH_IS_IGNORE_POST_POSITIONAL_WORD :       bReadOnly = rOpt.bROIsIgnorePostPositionalWord; break;
823cdf0e10cSrcweir         case UPH_IS_AUTO_CLOSE_DIALOG :                 bReadOnly = rOpt.bROIsAutoCloseDialog; break;
824cdf0e10cSrcweir         case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST :  bReadOnly = rOpt.bROIsShowEntriesRecentlyUsedFirst; break;
825cdf0e10cSrcweir         case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES :       bReadOnly = rOpt.bROIsAutoReplaceUniqueEntries; break;
826cdf0e10cSrcweir         case UPH_IS_DIRECTION_TO_SIMPLIFIED : bReadOnly = rOpt.bROIsDirectionToSimplified; break;
827cdf0e10cSrcweir         case UPH_IS_USE_CHARACTER_VARIANTS : bReadOnly = rOpt.bROIsUseCharacterVariants; break;
828cdf0e10cSrcweir         case UPH_IS_TRANSLATE_COMMON_TERMS : bReadOnly = rOpt.bROIsTranslateCommonTerms; break;
829cdf0e10cSrcweir         case UPH_IS_REVERSE_MAPPING :        bReadOnly = rOpt.bROIsReverseMapping; break;
830cdf0e10cSrcweir         case UPH_DATA_FILES_CHANGED_CHECK_VALUE :       bReadOnly = rOpt.bRODataFilesChangedCheckValue; break;
831cdf0e10cSrcweir         case UPH_IS_GRAMMAR_AUTO:                       bReadOnly = rOpt.bROIsGrammarAuto; break;
832cdf0e10cSrcweir         case UPH_IS_GRAMMAR_INTERACTIVE:                bReadOnly = rOpt.bROIsGrammarInteractive; break;
833cdf0e10cSrcweir         default :
834cdf0e10cSrcweir             DBG_ASSERT( 0, "unexpected property handle" );
835cdf0e10cSrcweir     }
836cdf0e10cSrcweir     return bReadOnly;
837cdf0e10cSrcweir }
838cdf0e10cSrcweir 
839cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
840cdf0e10cSrcweir 
841cdf0e10cSrcweir static SvtLinguConfigItem *pCfgItem = 0;
842cdf0e10cSrcweir static sal_Int32           nCfgItemRefCount = 0;
843cdf0e10cSrcweir 
844cdf0e10cSrcweir static const rtl::OUString aG_SupportedDictionaryFormats( A2OU("SupportedDictionaryFormats") );
845cdf0e10cSrcweir static const rtl::OUString aG_Dictionaries( A2OU("Dictionaries") );
846cdf0e10cSrcweir static const rtl::OUString aG_Locations( A2OU("Locations") );
847cdf0e10cSrcweir static const rtl::OUString aG_Format( A2OU("Format") );
848cdf0e10cSrcweir static const rtl::OUString aG_Locales( A2OU("Locales") );
849cdf0e10cSrcweir static const rtl::OUString aG_DisabledDictionaries( A2OU("DisabledDictionaries") );
850cdf0e10cSrcweir static const rtl::OUString aG_LastActiveDictionaries( A2OU("LastActiveDictionaries") );
851cdf0e10cSrcweir 
SvtLinguConfig()852cdf0e10cSrcweir SvtLinguConfig::SvtLinguConfig()
853cdf0e10cSrcweir {
854cdf0e10cSrcweir     // Global access, must be guarded (multithreading)
855cdf0e10cSrcweir     osl::MutexGuard aGuard( GetOwnMutex() );
856cdf0e10cSrcweir     ++nCfgItemRefCount;
857cdf0e10cSrcweir }
858cdf0e10cSrcweir 
859cdf0e10cSrcweir 
~SvtLinguConfig()860cdf0e10cSrcweir SvtLinguConfig::~SvtLinguConfig()
861cdf0e10cSrcweir {
862cdf0e10cSrcweir     osl::MutexGuard aGuard( GetOwnMutex() );
863cdf0e10cSrcweir 
864cdf0e10cSrcweir     if (pCfgItem && pCfgItem->IsModified())
865cdf0e10cSrcweir         pCfgItem->Commit();
866cdf0e10cSrcweir 
867cdf0e10cSrcweir     if (--nCfgItemRefCount <= 0)
868cdf0e10cSrcweir     {
869cdf0e10cSrcweir         if (pCfgItem)
870cdf0e10cSrcweir             delete pCfgItem;
871cdf0e10cSrcweir         pCfgItem = 0;
872cdf0e10cSrcweir     }
873cdf0e10cSrcweir }
874cdf0e10cSrcweir 
875cdf0e10cSrcweir 
GetConfigItem()876cdf0e10cSrcweir SvtLinguConfigItem & SvtLinguConfig::GetConfigItem()
877cdf0e10cSrcweir {
878cdf0e10cSrcweir     // Global access, must be guarded (multithreading)
879cdf0e10cSrcweir     osl::MutexGuard aGuard( GetOwnMutex() );
880cdf0e10cSrcweir     if (!pCfgItem)
881cdf0e10cSrcweir     {
882cdf0e10cSrcweir         pCfgItem = new SvtLinguConfigItem;
883cdf0e10cSrcweir         ItemHolder1::holdConfigItem(E_LINGUCFG);
884cdf0e10cSrcweir     }
885cdf0e10cSrcweir     return *pCfgItem;
886cdf0e10cSrcweir }
887cdf0e10cSrcweir 
888cdf0e10cSrcweir 
GetNodeNames(const OUString & rNode)889cdf0e10cSrcweir uno::Sequence< OUString > SvtLinguConfig::GetNodeNames( const OUString &rNode )
890cdf0e10cSrcweir {
891cdf0e10cSrcweir     return GetConfigItem().GetNodeNames( rNode );
892cdf0e10cSrcweir }
893cdf0e10cSrcweir 
894cdf0e10cSrcweir 
GetProperties(const uno::Sequence<OUString> & rNames)895cdf0e10cSrcweir uno::Sequence< uno::Any > SvtLinguConfig::GetProperties( const uno::Sequence< OUString > &rNames )
896cdf0e10cSrcweir {
897cdf0e10cSrcweir     return GetConfigItem().GetProperties(rNames);
898cdf0e10cSrcweir }
899cdf0e10cSrcweir 
900cdf0e10cSrcweir 
ReplaceSetProperties(const OUString & rNode,uno::Sequence<beans::PropertyValue> rValues)901cdf0e10cSrcweir sal_Bool SvtLinguConfig::ReplaceSetProperties(
902cdf0e10cSrcweir         const OUString &rNode, uno::Sequence< beans::PropertyValue > rValues )
903cdf0e10cSrcweir {
904cdf0e10cSrcweir     return GetConfigItem().ReplaceSetProperties( rNode, rValues );
905cdf0e10cSrcweir }
906cdf0e10cSrcweir 
907cdf0e10cSrcweir 
GetProperty(const OUString & rPropertyName) const908cdf0e10cSrcweir uno::Any SvtLinguConfig::GetProperty( const OUString &rPropertyName ) const
909cdf0e10cSrcweir {
910cdf0e10cSrcweir     return GetConfigItem().GetProperty( rPropertyName );
911cdf0e10cSrcweir }
912cdf0e10cSrcweir 
913cdf0e10cSrcweir 
GetProperty(sal_Int32 nPropertyHandle) const914cdf0e10cSrcweir uno::Any SvtLinguConfig::GetProperty( sal_Int32 nPropertyHandle ) const
915cdf0e10cSrcweir {
916cdf0e10cSrcweir     return GetConfigItem().GetProperty( nPropertyHandle );
917cdf0e10cSrcweir }
918cdf0e10cSrcweir 
919cdf0e10cSrcweir 
SetProperty(const OUString & rPropertyName,const uno::Any & rValue)920cdf0e10cSrcweir sal_Bool SvtLinguConfig::SetProperty( const OUString &rPropertyName, const uno::Any &rValue )
921cdf0e10cSrcweir {
922cdf0e10cSrcweir     return GetConfigItem().SetProperty( rPropertyName, rValue );
923cdf0e10cSrcweir }
924cdf0e10cSrcweir 
925cdf0e10cSrcweir 
SetProperty(sal_Int32 nPropertyHandle,const uno::Any & rValue)926cdf0e10cSrcweir sal_Bool SvtLinguConfig::SetProperty( sal_Int32 nPropertyHandle, const uno::Any &rValue )
927cdf0e10cSrcweir {
928cdf0e10cSrcweir     return GetConfigItem().SetProperty( nPropertyHandle, rValue );
929cdf0e10cSrcweir }
930cdf0e10cSrcweir 
931cdf0e10cSrcweir 
GetOptions(SvtLinguOptions & rOptions) const932cdf0e10cSrcweir sal_Bool SvtLinguConfig::GetOptions( SvtLinguOptions &rOptions ) const
933cdf0e10cSrcweir {
934cdf0e10cSrcweir     return GetConfigItem().GetOptions( rOptions );
935cdf0e10cSrcweir }
936cdf0e10cSrcweir 
937cdf0e10cSrcweir 
SetOptions(const SvtLinguOptions & rOptions)938cdf0e10cSrcweir sal_Bool SvtLinguConfig::SetOptions( const SvtLinguOptions &rOptions )
939cdf0e10cSrcweir {
940cdf0e10cSrcweir     return GetConfigItem().SetOptions( rOptions );
941cdf0e10cSrcweir }
942cdf0e10cSrcweir 
943cdf0e10cSrcweir 
IsReadOnly(const rtl::OUString & rPropertyName) const944cdf0e10cSrcweir sal_Bool SvtLinguConfig::IsReadOnly( const rtl::OUString &rPropertyName ) const
945cdf0e10cSrcweir {
946cdf0e10cSrcweir     return GetConfigItem().IsReadOnly( rPropertyName );
947cdf0e10cSrcweir }
948cdf0e10cSrcweir 
IsReadOnly(sal_Int32 nPropertyHandle) const949cdf0e10cSrcweir sal_Bool SvtLinguConfig::IsReadOnly( sal_Int32 nPropertyHandle ) const
950cdf0e10cSrcweir {
951cdf0e10cSrcweir     return GetConfigItem().IsReadOnly( nPropertyHandle );
952cdf0e10cSrcweir }
953cdf0e10cSrcweir 
GetElementNamesFor(const rtl::OUString & rNodeName,uno::Sequence<rtl::OUString> & rElementNames) const954cdf0e10cSrcweir sal_Bool SvtLinguConfig::GetElementNamesFor(
955cdf0e10cSrcweir      const rtl::OUString &rNodeName,
956cdf0e10cSrcweir      uno::Sequence< rtl::OUString > &rElementNames ) const
957cdf0e10cSrcweir {
958cdf0e10cSrcweir     bool bSuccess = false;
959cdf0e10cSrcweir     try
960cdf0e10cSrcweir     {
961cdf0e10cSrcweir         uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW );
962cdf0e10cSrcweir         xNA.set( xNA->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW );
963cdf0e10cSrcweir         xNA.set( xNA->getByName( rNodeName ), uno::UNO_QUERY_THROW );
964cdf0e10cSrcweir         rElementNames = xNA->getElementNames();
965cdf0e10cSrcweir         bSuccess = true;
966cdf0e10cSrcweir     }
967cdf0e10cSrcweir     catch (uno::Exception &)
968cdf0e10cSrcweir     {
969cdf0e10cSrcweir     }
970cdf0e10cSrcweir     return bSuccess;
971cdf0e10cSrcweir }
972cdf0e10cSrcweir 
GetOrCreateSetEntry_Impl(const uno::Reference<container::XNameAccess> & rxSetNameAccess,const rtl::OUString & rEntryName)973cdf0e10cSrcweir static uno::Reference< container::XNameAccess > GetOrCreateSetEntry_Impl(
974cdf0e10cSrcweir     const uno::Reference< container::XNameAccess > &rxSetNameAccess,
975cdf0e10cSrcweir     const rtl::OUString &rEntryName )
976cdf0e10cSrcweir {
977cdf0e10cSrcweir     uno::Reference< container::XNameAccess > xResult;
978cdf0e10cSrcweir     try
979cdf0e10cSrcweir     {
980cdf0e10cSrcweir         if (!rxSetNameAccess->hasByName( rEntryName ))
981cdf0e10cSrcweir         {
982cdf0e10cSrcweir             uno::Reference< lang::XSingleServiceFactory > xFactory( rxSetNameAccess, uno::UNO_QUERY_THROW);
983cdf0e10cSrcweir             uno::Reference< uno::XInterface > xNewEntry( xFactory->createInstance() );
984cdf0e10cSrcweir             uno::Reference< container::XNameContainer > xNC( rxSetNameAccess, uno::UNO_QUERY_THROW );
985cdf0e10cSrcweir             xNC->insertByName( rEntryName, makeAny( xNewEntry ) );
986cdf0e10cSrcweir         }
987cdf0e10cSrcweir         xResult.set( rxSetNameAccess->getByName( rEntryName ), uno::UNO_QUERY_THROW );
988cdf0e10cSrcweir     }
989cdf0e10cSrcweir     catch (uno::Exception &)
990cdf0e10cSrcweir     {
991cdf0e10cSrcweir     }
992cdf0e10cSrcweir     return xResult;
993cdf0e10cSrcweir }
994cdf0e10cSrcweir 
GetSupportedDictionaryFormatsFor(const rtl::OUString & rSetName,const rtl::OUString & rSetEntry,uno::Sequence<rtl::OUString> & rFormatList) const995cdf0e10cSrcweir sal_Bool SvtLinguConfig::GetSupportedDictionaryFormatsFor(
996cdf0e10cSrcweir     const rtl::OUString &rSetName,
997cdf0e10cSrcweir     const rtl::OUString &rSetEntry,
998cdf0e10cSrcweir     uno::Sequence< rtl::OUString > &rFormatList ) const
999cdf0e10cSrcweir {
1000cdf0e10cSrcweir     if (rSetName.getLength() == 0 || rSetEntry.getLength() == 0)
1001cdf0e10cSrcweir         return sal_False;
1002cdf0e10cSrcweir     bool bSuccess = false;
1003cdf0e10cSrcweir     try
1004cdf0e10cSrcweir     {
1005cdf0e10cSrcweir         uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW );
1006cdf0e10cSrcweir         xNA.set( xNA->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW );
1007cdf0e10cSrcweir         xNA.set( xNA->getByName( rSetName ), uno::UNO_QUERY_THROW );
1008cdf0e10cSrcweir         xNA.set( xNA->getByName( rSetEntry ), uno::UNO_QUERY_THROW );
1009cdf0e10cSrcweir         if (xNA->getByName( aG_SupportedDictionaryFormats ) >>= rFormatList)
1010cdf0e10cSrcweir             bSuccess = true;
1011cdf0e10cSrcweir         DBG_ASSERT( rFormatList.getLength(), "supported dictionary format list is empty" );
1012cdf0e10cSrcweir     }
1013cdf0e10cSrcweir     catch (uno::Exception &)
1014cdf0e10cSrcweir     {
1015cdf0e10cSrcweir     }
1016cdf0e10cSrcweir     return bSuccess;
1017cdf0e10cSrcweir }
1018cdf0e10cSrcweir 
SetOrCreateSupportedDictionaryFormatsFor(const rtl::OUString & rSetName,const rtl::OUString & rSetEntry,const uno::Sequence<rtl::OUString> & rFormatList) const1019cdf0e10cSrcweir void SvtLinguConfig::SetOrCreateSupportedDictionaryFormatsFor(
1020cdf0e10cSrcweir     const rtl::OUString &rSetName,
1021cdf0e10cSrcweir     const rtl::OUString &rSetEntry,
1022cdf0e10cSrcweir     const uno::Sequence< rtl::OUString > &rFormatList  ) const
1023cdf0e10cSrcweir {
1024cdf0e10cSrcweir     if (rSetName.getLength() == 0 || rSetEntry.getLength() == 0)
1025cdf0e10cSrcweir         return;
1026cdf0e10cSrcweir     try
1027cdf0e10cSrcweir     {
1028cdf0e10cSrcweir         DBG_ASSERT( rFormatList.getLength(), "applying empty format list. Really??" );
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir         uno::Reference< util::XChangesBatch > xUpdateAccess( GetMainUpdateAccess() );
1031cdf0e10cSrcweir         uno::Reference< container::XNameAccess > xNA( xUpdateAccess, uno::UNO_QUERY_THROW );
1032cdf0e10cSrcweir         xNA.set( xNA->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW );
1033cdf0e10cSrcweir         xNA.set( xNA->getByName( rSetName ), uno::UNO_QUERY_THROW );
1034cdf0e10cSrcweir         xNA = GetOrCreateSetEntry_Impl( xNA, rSetEntry );
1035cdf0e10cSrcweir 
1036cdf0e10cSrcweir         uno::Reference< container::XNameReplace > xNR( xNA, uno::UNO_QUERY_THROW );
1037cdf0e10cSrcweir         xNR->replaceByName( aG_SupportedDictionaryFormats, uno::makeAny( rFormatList ) );
1038cdf0e10cSrcweir 
1039cdf0e10cSrcweir         xUpdateAccess->commitChanges();
1040cdf0e10cSrcweir     }
1041cdf0e10cSrcweir     catch (uno::Exception &)
1042cdf0e10cSrcweir     {
1043cdf0e10cSrcweir     }
1044cdf0e10cSrcweir }
1045cdf0e10cSrcweir 
1046cdf0e10cSrcweir 
1047cdf0e10cSrcweir static uno::WeakReference< util::XMacroExpander > aG_xMacroExpander;
1048cdf0e10cSrcweir 
lcl_GetMacroExpander()1049cdf0e10cSrcweir static uno::Reference< util::XMacroExpander > lcl_GetMacroExpander()
1050cdf0e10cSrcweir {
1051cdf0e10cSrcweir     uno::Reference< util::XMacroExpander > xMacroExpander( aG_xMacroExpander );
1052cdf0e10cSrcweir     if ( !xMacroExpander.is() )
1053cdf0e10cSrcweir     {
1054cdf0e10cSrcweir         if ( !xMacroExpander.is() )
1055cdf0e10cSrcweir         {
1056cdf0e10cSrcweir             uno::Reference< uno::XComponentContext > xContext;
1057cdf0e10cSrcweir             uno::Reference< beans::XPropertySet > xProps( ::comphelper::getProcessServiceFactory(), uno::UNO_QUERY );
1058cdf0e10cSrcweir             xProps->getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "DefaultContext" ))) >>= xContext;
1059cdf0e10cSrcweir             if ( xContext.is() )
1060cdf0e10cSrcweir             {
1061cdf0e10cSrcweir                 aG_xMacroExpander =  uno::Reference< com::sun::star::util::XMacroExpander >( xContext->getValueByName(
1062cdf0e10cSrcweir                                         OUString( RTL_CONSTASCII_USTRINGPARAM( "/singletons/com.sun.star.util.theMacroExpander"))),
1063cdf0e10cSrcweir                                         uno::UNO_QUERY );
1064cdf0e10cSrcweir                 xMacroExpander = aG_xMacroExpander;
1065cdf0e10cSrcweir             }
1066cdf0e10cSrcweir         }
1067cdf0e10cSrcweir     }
1068cdf0e10cSrcweir 
1069cdf0e10cSrcweir     return xMacroExpander;
1070cdf0e10cSrcweir }
1071cdf0e10cSrcweir 
1072cdf0e10cSrcweir 
lcl_GetFileUrlFromOrigin(OUString & rFileUrl,const OUString & rOrigin,uno::Reference<util::XMacroExpander> & rxMacroExpander)1073cdf0e10cSrcweir static bool lcl_GetFileUrlFromOrigin(
1074cdf0e10cSrcweir     OUString /*out*/ &rFileUrl,
1075cdf0e10cSrcweir     const OUString &rOrigin,
1076cdf0e10cSrcweir     uno::Reference< util::XMacroExpander > &rxMacroExpander )
1077cdf0e10cSrcweir {
1078cdf0e10cSrcweir     bool bSuccess = false;
1079cdf0e10cSrcweir     if (rOrigin.getLength() > 0 && rxMacroExpander.is())
1080cdf0e10cSrcweir     {
1081cdf0e10cSrcweir         rtl::OUString aURL( rOrigin );
1082cdf0e10cSrcweir         if (( aURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM( EXPAND_PROTOCOL )) == 0 ) &&
1083cdf0e10cSrcweir             rxMacroExpander.is() )
1084cdf0e10cSrcweir         {
1085cdf0e10cSrcweir             // cut protocol
1086cdf0e10cSrcweir             OUString aMacro( aURL.copy( sizeof ( EXPAND_PROTOCOL ) -1 ) );
1087cdf0e10cSrcweir             // decode uric class chars
1088cdf0e10cSrcweir             aMacro = Uri::decode( aMacro, rtl_UriDecodeWithCharset, RTL_TEXTENCODING_UTF8 );
1089cdf0e10cSrcweir             // expand macro string
1090cdf0e10cSrcweir             aURL = rxMacroExpander->expandMacros( aMacro );
1091cdf0e10cSrcweir 
1092cdf0e10cSrcweir             bool bIsFileUrl = aURL.compareToAscii( RTL_CONSTASCII_STRINGPARAM( FILE_PROTOCOL )) == 0;
1093cdf0e10cSrcweir             if (bIsFileUrl)
1094cdf0e10cSrcweir             {
1095cdf0e10cSrcweir                 rFileUrl = aURL;
1096cdf0e10cSrcweir                 bSuccess = true;
1097cdf0e10cSrcweir             }
1098cdf0e10cSrcweir             else
1099cdf0e10cSrcweir             {
1100cdf0e10cSrcweir                 DBG_ASSERT( bIsFileUrl, "not a file URL");
1101cdf0e10cSrcweir             }
1102cdf0e10cSrcweir         }
1103cdf0e10cSrcweir         else
1104cdf0e10cSrcweir         {
1105cdf0e10cSrcweir             DBG_ASSERT( 0, "failed to get file URL" );
1106cdf0e10cSrcweir         }
1107cdf0e10cSrcweir     }
1108cdf0e10cSrcweir     return bSuccess;
1109cdf0e10cSrcweir }
1110cdf0e10cSrcweir 
1111cdf0e10cSrcweir 
GetDictionaryEntry(const rtl::OUString & rNodeName,SvtLinguConfigDictionaryEntry & rDicEntry) const1112cdf0e10cSrcweir sal_Bool SvtLinguConfig::GetDictionaryEntry(
1113cdf0e10cSrcweir     const rtl::OUString &rNodeName,
1114cdf0e10cSrcweir     SvtLinguConfigDictionaryEntry &rDicEntry ) const
1115cdf0e10cSrcweir {
1116cdf0e10cSrcweir     if (rNodeName.getLength() == 0)
1117cdf0e10cSrcweir         return sal_False;
1118cdf0e10cSrcweir     bool bSuccess = false;
1119cdf0e10cSrcweir     try
1120cdf0e10cSrcweir     {
1121cdf0e10cSrcweir         uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW );
1122cdf0e10cSrcweir         xNA.set( xNA->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW );
1123cdf0e10cSrcweir         xNA.set( xNA->getByName( aG_Dictionaries ), uno::UNO_QUERY_THROW );
1124cdf0e10cSrcweir         xNA.set( xNA->getByName( rNodeName ), uno::UNO_QUERY_THROW );
1125cdf0e10cSrcweir 
1126cdf0e10cSrcweir         // read group data...
1127cdf0e10cSrcweir         uno::Sequence< rtl::OUString >	aLocations;
1128cdf0e10cSrcweir         rtl::OUString					aFormatName;
1129cdf0e10cSrcweir 		uno::Sequence< rtl::OUString >  aLocaleNames;
1130cdf0e10cSrcweir         bSuccess =  (xNA->getByName( aG_Locations ) >>= aLocations)  &&
1131cdf0e10cSrcweir                     (xNA->getByName( aG_Format )    >>= aFormatName) &&
1132cdf0e10cSrcweir                     (xNA->getByName( aG_Locales )   >>= aLocaleNames);
1133cdf0e10cSrcweir         DBG_ASSERT( aLocations.getLength(), "Dictionary locations not set" );
1134cdf0e10cSrcweir         DBG_ASSERT( aFormatName.getLength(), "Dictionary format name not set" );
1135cdf0e10cSrcweir         DBG_ASSERT( aLocaleNames.getLength(), "No locales set for the dictionary" );
1136cdf0e10cSrcweir 
1137cdf0e10cSrcweir         // if sucessful continue
1138cdf0e10cSrcweir         if (bSuccess)
1139cdf0e10cSrcweir         {
1140cdf0e10cSrcweir             // get file URL's for the locations
1141cdf0e10cSrcweir             uno::Reference< util::XMacroExpander > xMacroExpander( lcl_GetMacroExpander() );
1142cdf0e10cSrcweir             for (sal_Int32 i = 0;  i < aLocations.getLength();  ++i)
1143cdf0e10cSrcweir             {
1144cdf0e10cSrcweir                 rtl::OUString &rLocation = aLocations[i];
1145cdf0e10cSrcweir                 if (!lcl_GetFileUrlFromOrigin( rLocation, rLocation, xMacroExpander ))
1146cdf0e10cSrcweir                     bSuccess = false;
1147cdf0e10cSrcweir             }
1148cdf0e10cSrcweir 
1149cdf0e10cSrcweir             // if everything was fine return the result
1150cdf0e10cSrcweir             if (bSuccess)
1151cdf0e10cSrcweir             {
1152cdf0e10cSrcweir                 rDicEntry.aLocations    = aLocations;
1153cdf0e10cSrcweir                 rDicEntry.aFormatName   = aFormatName;
1154cdf0e10cSrcweir                 rDicEntry.aLocaleNames  = aLocaleNames;
1155cdf0e10cSrcweir             }
1156cdf0e10cSrcweir         }
1157cdf0e10cSrcweir     }
1158cdf0e10cSrcweir     catch (uno::Exception &)
1159cdf0e10cSrcweir     {
1160cdf0e10cSrcweir     }
1161cdf0e10cSrcweir     return bSuccess;
1162cdf0e10cSrcweir }
1163cdf0e10cSrcweir 
SetOrCreateDictionaryEntry(const rtl::OUString & rNodeName,const SvtLinguConfigDictionaryEntry & rDicEntry) const1164cdf0e10cSrcweir void SvtLinguConfig::SetOrCreateDictionaryEntry(
1165cdf0e10cSrcweir     const rtl::OUString &rNodeName,
1166cdf0e10cSrcweir     const SvtLinguConfigDictionaryEntry &rDicEntry ) const
1167cdf0e10cSrcweir {
1168cdf0e10cSrcweir     if (rNodeName.getLength() == 0)
1169cdf0e10cSrcweir         return;
1170cdf0e10cSrcweir     try
1171cdf0e10cSrcweir     {
1172cdf0e10cSrcweir         uno::Reference< util::XChangesBatch > xUpdateAccess( GetMainUpdateAccess() );
1173cdf0e10cSrcweir         uno::Reference< container::XNameAccess > xNA( xUpdateAccess, uno::UNO_QUERY_THROW );
1174cdf0e10cSrcweir         xNA.set( xNA->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW );
1175cdf0e10cSrcweir         xNA.set( xNA->getByName( aG_Dictionaries ), uno::UNO_QUERY_THROW );
1176cdf0e10cSrcweir         xNA = GetOrCreateSetEntry_Impl( xNA, rNodeName );
1177cdf0e10cSrcweir 
1178cdf0e10cSrcweir         DBG_ASSERT( rDicEntry.aLocations.getLength(), "Applying empty dictionary locations. Really correct??" );
1179cdf0e10cSrcweir         DBG_ASSERT( rDicEntry.aFormatName.getLength(), "Applying empty dictionary format name. Really correct??" );
1180cdf0e10cSrcweir         DBG_ASSERT( rDicEntry.aLocaleNames.getLength(), "Applying empty list of locales for the dictionary. Really correct??" );
1181cdf0e10cSrcweir 
1182cdf0e10cSrcweir         uno::Reference< container::XNameReplace > xNR( xNA, uno::UNO_QUERY_THROW );
1183cdf0e10cSrcweir         xNR->replaceByName( aG_Locations, uno::makeAny( rDicEntry.aLocations ) );
1184cdf0e10cSrcweir         xNR->replaceByName( aG_Format,    uno::makeAny( rDicEntry.aFormatName ) );
1185cdf0e10cSrcweir         xNR->replaceByName( aG_Locales,   uno::makeAny( rDicEntry.aLocaleNames ) );
1186cdf0e10cSrcweir 
1187cdf0e10cSrcweir         xUpdateAccess->commitChanges();
1188cdf0e10cSrcweir     }
1189cdf0e10cSrcweir     catch (uno::Exception &)
1190cdf0e10cSrcweir     {
1191cdf0e10cSrcweir     }
1192cdf0e10cSrcweir }
1193cdf0e10cSrcweir 
GetDisabledDictionaries() const1194cdf0e10cSrcweir uno::Sequence< rtl::OUString > SvtLinguConfig::GetDisabledDictionaries() const
1195cdf0e10cSrcweir {
1196cdf0e10cSrcweir     uno::Sequence< rtl::OUString > aResult;
1197cdf0e10cSrcweir     try
1198cdf0e10cSrcweir     {
1199cdf0e10cSrcweir         uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW );
1200cdf0e10cSrcweir         xNA.set( xNA->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW );
1201cdf0e10cSrcweir         xNA->getByName( aG_DisabledDictionaries ) >>= aResult;
1202cdf0e10cSrcweir     }
1203cdf0e10cSrcweir     catch (uno::Exception &)
1204cdf0e10cSrcweir     {
1205cdf0e10cSrcweir     }
1206cdf0e10cSrcweir     return aResult;
1207cdf0e10cSrcweir }
1208cdf0e10cSrcweir 
SetDisabledDictionaries(const uno::Sequence<rtl::OUString> & rDictionaries) const1209cdf0e10cSrcweir void SvtLinguConfig::SetDisabledDictionaries(
1210cdf0e10cSrcweir     const uno::Sequence< rtl::OUString > &rDictionaries ) const
1211cdf0e10cSrcweir {
1212cdf0e10cSrcweir     try
1213cdf0e10cSrcweir     {
1214cdf0e10cSrcweir         uno::Reference< util::XChangesBatch > xUpdateAccess( GetMainUpdateAccess() );
1215cdf0e10cSrcweir         uno::Reference< container::XNameAccess > xNA( xUpdateAccess, uno::UNO_QUERY_THROW );
1216cdf0e10cSrcweir         xNA.set( xNA->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW );
1217cdf0e10cSrcweir         if (xNA->hasByName( aG_DisabledDictionaries ))
1218cdf0e10cSrcweir         {
1219cdf0e10cSrcweir             uno::Reference< container::XNameReplace > xNR( xNA, uno::UNO_QUERY_THROW );
1220cdf0e10cSrcweir             xNR->replaceByName( aG_DisabledDictionaries, makeAny( rDictionaries ) );
1221cdf0e10cSrcweir         }
1222cdf0e10cSrcweir         else
1223cdf0e10cSrcweir         {
1224cdf0e10cSrcweir             uno::Reference< container::XNameContainer > xNC( xNA, uno::UNO_QUERY_THROW );
1225cdf0e10cSrcweir             xNC->insertByName( aG_DisabledDictionaries, makeAny( rDictionaries ) );
1226cdf0e10cSrcweir         }
1227cdf0e10cSrcweir 
1228cdf0e10cSrcweir         xUpdateAccess->commitChanges();
1229cdf0e10cSrcweir     }
1230cdf0e10cSrcweir     catch (uno::Exception &)
1231cdf0e10cSrcweir     {
1232cdf0e10cSrcweir     }
1233cdf0e10cSrcweir }
1234cdf0e10cSrcweir 
GetActiveDictionariesByFormat(const rtl::OUString & rFormatName)1235cdf0e10cSrcweir std::vector< SvtLinguConfigDictionaryEntry > SvtLinguConfig::GetActiveDictionariesByFormat(
1236cdf0e10cSrcweir     const rtl::OUString &rFormatName )
1237cdf0e10cSrcweir {
1238cdf0e10cSrcweir     std::vector< SvtLinguConfigDictionaryEntry > aRes;
1239cdf0e10cSrcweir     if (rFormatName.getLength() == 0)
1240cdf0e10cSrcweir         return aRes;
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir     try
1243cdf0e10cSrcweir     {
1244cdf0e10cSrcweir         uno::Sequence< rtl::OUString > aElementNames;
1245cdf0e10cSrcweir         GetElementNamesFor( aG_Dictionaries, aElementNames );
1246cdf0e10cSrcweir         sal_Int32 nLen = aElementNames.getLength();
1247cdf0e10cSrcweir         const rtl::OUString *pElementNames = aElementNames.getConstArray();
1248cdf0e10cSrcweir 
1249cdf0e10cSrcweir         SvtLinguConfigDictionaryEntry aDicEntry;
1250cdf0e10cSrcweir         for (sal_Int32 i = 0;  i < nLen;  ++i)
1251cdf0e10cSrcweir         {
1252cdf0e10cSrcweir             // does dictionary match the format we are looking for?
1253cdf0e10cSrcweir             if (GetDictionaryEntry( pElementNames[i], aDicEntry ) &&
1254cdf0e10cSrcweir                 aDicEntry.aFormatName == rFormatName)
1255cdf0e10cSrcweir             {
1256cdf0e10cSrcweir                 // check if it is active or not
1257cdf0e10cSrcweir                 bool bDicIsActive = true;
1258cdf0e10cSrcweir                 const uno::Sequence< rtl::OUString > aDisabledDics( GetDisabledDictionaries() );
1259cdf0e10cSrcweir                 for (sal_Int32 k = 0;  bDicIsActive && k < aDisabledDics.getLength();  ++k)
1260cdf0e10cSrcweir                 {
1261cdf0e10cSrcweir                     if (aDisabledDics[k] == pElementNames[i])
1262cdf0e10cSrcweir                         bDicIsActive = false;
1263cdf0e10cSrcweir                 }
1264cdf0e10cSrcweir 
1265cdf0e10cSrcweir                 if (bDicIsActive)
1266cdf0e10cSrcweir                 {
1267cdf0e10cSrcweir                     DBG_ASSERT( aDicEntry.aFormatName.getLength(),
1268cdf0e10cSrcweir                             "FormatName not set" );
1269cdf0e10cSrcweir                     DBG_ASSERT( aDicEntry.aLocations.getLength(),
1270cdf0e10cSrcweir                             "Locations not set" );
1271cdf0e10cSrcweir                     DBG_ASSERT( aDicEntry.aLocaleNames.getLength(),
1272cdf0e10cSrcweir                             "Locales not set" );
1273cdf0e10cSrcweir                     aRes.push_back( aDicEntry );
1274cdf0e10cSrcweir                 }
1275cdf0e10cSrcweir             }
1276cdf0e10cSrcweir         }
1277cdf0e10cSrcweir     }
1278cdf0e10cSrcweir     catch (uno::Exception &)
1279cdf0e10cSrcweir     {
1280cdf0e10cSrcweir     }
1281cdf0e10cSrcweir 
1282cdf0e10cSrcweir     return aRes;
1283cdf0e10cSrcweir }
1284cdf0e10cSrcweir 
1285cdf0e10cSrcweir 
GetMainUpdateAccess() const1286cdf0e10cSrcweir uno::Reference< util::XChangesBatch > SvtLinguConfig::GetMainUpdateAccess() const
1287cdf0e10cSrcweir {
1288cdf0e10cSrcweir     if (!m_xMainUpdateAccess.is())
1289cdf0e10cSrcweir     {
1290cdf0e10cSrcweir         try
1291cdf0e10cSrcweir         {
1292cdf0e10cSrcweir             // get configuration provider
1293cdf0e10cSrcweir             uno::Reference< lang::XMultiServiceFactory > xConfigurationProvider;
1294cdf0e10cSrcweir             uno::Reference< lang::XMultiServiceFactory > xMgr = comphelper::getProcessServiceFactory();
1295cdf0e10cSrcweir             if (xMgr.is())
1296cdf0e10cSrcweir             {
1297cdf0e10cSrcweir                 xConfigurationProvider = uno::Reference< lang::XMultiServiceFactory > (
1298cdf0e10cSrcweir                         xMgr->createInstance( OUString( RTL_CONSTASCII_USTRINGPARAM(
1299cdf0e10cSrcweir                             "com.sun.star.configuration.ConfigurationProvider" ) ) ),
1300cdf0e10cSrcweir                         uno::UNO_QUERY_THROW ) ;
1301cdf0e10cSrcweir             }
1302cdf0e10cSrcweir 
1303cdf0e10cSrcweir             // get configuration update access
1304cdf0e10cSrcweir             beans::PropertyValue aValue;
1305cdf0e10cSrcweir             aValue.Name  = A2OU( "nodepath" );
1306cdf0e10cSrcweir             aValue.Value = uno::makeAny( A2OU("org.openoffice.Office.Linguistic") );
1307cdf0e10cSrcweir             uno::Sequence< uno::Any > aProps(1);
1308cdf0e10cSrcweir             aProps[0] <<= aValue;
1309cdf0e10cSrcweir             m_xMainUpdateAccess = uno::Reference< util::XChangesBatch >(
1310cdf0e10cSrcweir                     xConfigurationProvider->createInstanceWithArguments(
1311cdf0e10cSrcweir                         A2OU( "com.sun.star.configuration.ConfigurationUpdateAccess" ), aProps ),
1312cdf0e10cSrcweir                         uno::UNO_QUERY_THROW );
1313cdf0e10cSrcweir         }
1314cdf0e10cSrcweir         catch (uno::Exception &)
1315cdf0e10cSrcweir         {
1316cdf0e10cSrcweir         }
1317cdf0e10cSrcweir     }
1318cdf0e10cSrcweir 
1319cdf0e10cSrcweir     return m_xMainUpdateAccess;
1320cdf0e10cSrcweir }
1321cdf0e10cSrcweir 
1322cdf0e10cSrcweir 
GetVendorImageUrl_Impl(const rtl::OUString & rServiceImplName,const rtl::OUString & rImageName) const1323cdf0e10cSrcweir rtl::OUString SvtLinguConfig::GetVendorImageUrl_Impl(
1324cdf0e10cSrcweir     const rtl::OUString &rServiceImplName,
1325cdf0e10cSrcweir     const rtl::OUString &rImageName ) const
1326cdf0e10cSrcweir {
1327cdf0e10cSrcweir     rtl::OUString aRes;
1328cdf0e10cSrcweir     try
1329cdf0e10cSrcweir     {
1330cdf0e10cSrcweir         uno::Reference< container::XNameAccess > xImagesNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW );
1331cdf0e10cSrcweir         xImagesNA.set( xImagesNA->getByName( A2OU("Images") ), uno::UNO_QUERY_THROW );
1332cdf0e10cSrcweir 
1333cdf0e10cSrcweir         uno::Reference< container::XNameAccess > xNA( xImagesNA->getByName( A2OU("ServiceNameEntries") ), uno::UNO_QUERY_THROW );
1334cdf0e10cSrcweir         xNA.set( xNA->getByName( rServiceImplName ), uno::UNO_QUERY_THROW );
1335cdf0e10cSrcweir         uno::Any aAny( xNA->getByName( A2OU("VendorImagesNode") ) );
1336cdf0e10cSrcweir         rtl::OUString aVendorImagesNode;
1337cdf0e10cSrcweir         if (aAny >>= aVendorImagesNode)
1338cdf0e10cSrcweir         {
1339cdf0e10cSrcweir             xNA = xImagesNA;
1340cdf0e10cSrcweir             xNA.set( xNA->getByName( A2OU("VendorImages") ), uno::UNO_QUERY_THROW );
1341cdf0e10cSrcweir             xNA.set( xNA->getByName( aVendorImagesNode ), uno::UNO_QUERY_THROW );
1342cdf0e10cSrcweir             aAny = xNA->getByName( rImageName );
1343cdf0e10cSrcweir             rtl::OUString aTmp;
1344cdf0e10cSrcweir             if (aAny >>= aTmp)
1345cdf0e10cSrcweir             {
1346cdf0e10cSrcweir                 uno::Reference< util::XMacroExpander > xMacroExpander( lcl_GetMacroExpander() );
1347cdf0e10cSrcweir                 if (lcl_GetFileUrlFromOrigin( aTmp, aTmp, xMacroExpander ))
1348cdf0e10cSrcweir                     aRes = aTmp;
1349cdf0e10cSrcweir             }
1350cdf0e10cSrcweir         }
1351cdf0e10cSrcweir     }
1352cdf0e10cSrcweir     catch (uno::Exception &)
1353cdf0e10cSrcweir     {
1354cdf0e10cSrcweir         DBG_ASSERT( 0, "exception caught. GetVendorImageUrl_Impl failed" );
1355cdf0e10cSrcweir     }
1356cdf0e10cSrcweir     return aRes;
1357cdf0e10cSrcweir }
1358cdf0e10cSrcweir 
1359cdf0e10cSrcweir 
GetSpellAndGrammarDialogImage(const rtl::OUString & rServiceImplName,bool bHighContrast) const1360cdf0e10cSrcweir rtl::OUString SvtLinguConfig::GetSpellAndGrammarDialogImage(
1361cdf0e10cSrcweir     const rtl::OUString &rServiceImplName,
1362cdf0e10cSrcweir     bool bHighContrast ) const
1363cdf0e10cSrcweir {
1364cdf0e10cSrcweir     rtl::OUString   aRes;
1365cdf0e10cSrcweir     if (rServiceImplName.getLength() > 0)
1366cdf0e10cSrcweir     {
1367cdf0e10cSrcweir         rtl::OUString aImageName( A2OU( bHighContrast ? "SpellAndGrammarDialogImage_HC" : "SpellAndGrammarDialogImage" ));
1368cdf0e10cSrcweir         rtl::OUString aPath( GetVendorImageUrl_Impl( rServiceImplName, aImageName ) );
1369cdf0e10cSrcweir         aRes = aPath;
1370cdf0e10cSrcweir     }
1371cdf0e10cSrcweir     return aRes;
1372cdf0e10cSrcweir }
1373cdf0e10cSrcweir 
1374cdf0e10cSrcweir 
GetSpellAndGrammarContextSuggestionImage(const rtl::OUString & rServiceImplName,bool bHighContrast) const1375cdf0e10cSrcweir rtl::OUString SvtLinguConfig::GetSpellAndGrammarContextSuggestionImage(
1376cdf0e10cSrcweir     const rtl::OUString &rServiceImplName,
1377cdf0e10cSrcweir     bool bHighContrast ) const
1378cdf0e10cSrcweir {
1379cdf0e10cSrcweir     rtl::OUString   aRes;
1380cdf0e10cSrcweir     if (rServiceImplName.getLength() > 0)
1381cdf0e10cSrcweir     {
1382cdf0e10cSrcweir         rtl::OUString aImageName( A2OU( bHighContrast ? "SpellAndGrammarContextMenuSuggestionImage_HC" : "SpellAndGrammarContextMenuSuggestionImage" ));
1383cdf0e10cSrcweir         rtl::OUString aPath( GetVendorImageUrl_Impl( rServiceImplName, aImageName ) );
1384cdf0e10cSrcweir         aRes = aPath;
1385cdf0e10cSrcweir     }
1386cdf0e10cSrcweir     return aRes;
1387cdf0e10cSrcweir }
1388cdf0e10cSrcweir 
1389cdf0e10cSrcweir 
GetSpellAndGrammarContextDictionaryImage(const rtl::OUString & rServiceImplName,bool bHighContrast) const1390cdf0e10cSrcweir rtl::OUString SvtLinguConfig::GetSpellAndGrammarContextDictionaryImage(
1391cdf0e10cSrcweir     const rtl::OUString &rServiceImplName,
1392cdf0e10cSrcweir     bool bHighContrast ) const
1393cdf0e10cSrcweir {
1394cdf0e10cSrcweir     rtl::OUString   aRes;
1395cdf0e10cSrcweir     if (rServiceImplName.getLength() > 0)
1396cdf0e10cSrcweir     {
1397cdf0e10cSrcweir         rtl::OUString aImageName( A2OU( bHighContrast ? "SpellAndGrammarContextMenuDictionaryImage_HC" : "SpellAndGrammarContextMenuDictionaryImage" ));
1398cdf0e10cSrcweir         rtl::OUString aPath( GetVendorImageUrl_Impl( rServiceImplName, aImageName ) );
1399cdf0e10cSrcweir         aRes = aPath;
1400cdf0e10cSrcweir     }
1401cdf0e10cSrcweir     return aRes;
1402cdf0e10cSrcweir }
1403cdf0e10cSrcweir 
1404cdf0e10cSrcweir 
GetThesaurusDialogImage(const::rtl::OUString & rServiceImplName,bool bHighContrast) const1405cdf0e10cSrcweir ::rtl::OUString SvtLinguConfig::GetThesaurusDialogImage(
1406cdf0e10cSrcweir     const ::rtl::OUString &rServiceImplName,
1407cdf0e10cSrcweir     bool bHighContrast ) const
1408cdf0e10cSrcweir {
1409cdf0e10cSrcweir     rtl::OUString   aRes;
1410cdf0e10cSrcweir     if (rServiceImplName.getLength() > 0)
1411cdf0e10cSrcweir     {
1412cdf0e10cSrcweir         rtl::OUString aImageName( A2OU( bHighContrast ? "ThesaurusDialogImage_HC" : "ThesaurusDialogImage" ));
1413cdf0e10cSrcweir         rtl::OUString aPath( GetVendorImageUrl_Impl( rServiceImplName, aImageName ) );
1414cdf0e10cSrcweir         aRes = aPath;
1415cdf0e10cSrcweir     }
1416cdf0e10cSrcweir     return aRes;
1417cdf0e10cSrcweir }
1418cdf0e10cSrcweir 
1419cdf0e10cSrcweir 
GetSynonymsContextImage(const::rtl::OUString & rServiceImplName,bool bHighContrast) const1420cdf0e10cSrcweir ::rtl::OUString SvtLinguConfig::GetSynonymsContextImage(
1421cdf0e10cSrcweir     const ::rtl::OUString &rServiceImplName,
1422cdf0e10cSrcweir     bool bHighContrast ) const
1423cdf0e10cSrcweir {
1424cdf0e10cSrcweir     rtl::OUString   aRes;
1425cdf0e10cSrcweir     if (rServiceImplName.getLength() > 0)
1426cdf0e10cSrcweir     {
1427cdf0e10cSrcweir         rtl::OUString aImageName( A2OU( bHighContrast ? "SynonymsContextMenuImage_HC" : "SynonymsContextMenuImage" ));
1428cdf0e10cSrcweir         rtl::OUString aPath( GetVendorImageUrl_Impl( rServiceImplName, aImageName ) );
1429cdf0e10cSrcweir         aRes = aPath;
1430cdf0e10cSrcweir     }
1431cdf0e10cSrcweir     return aRes;
1432cdf0e10cSrcweir }
1433cdf0e10cSrcweir 
1434cdf0e10cSrcweir 
HasVendorImages(const char * pImageName) const1435cdf0e10cSrcweir bool SvtLinguConfig::HasVendorImages( const char *pImageName ) const
1436cdf0e10cSrcweir {
1437cdf0e10cSrcweir     bool bRes = false;
1438cdf0e10cSrcweir     if (pImageName)
1439cdf0e10cSrcweir     {
1440cdf0e10cSrcweir         try
1441cdf0e10cSrcweir         {
1442cdf0e10cSrcweir             uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW );
1443cdf0e10cSrcweir             xNA.set( xNA->getByName( A2OU("Images") ), uno::UNO_QUERY_THROW );
1444cdf0e10cSrcweir             xNA.set( xNA->getByName( A2OU("VendorImages") ), uno::UNO_QUERY_THROW );
1445cdf0e10cSrcweir 
1446cdf0e10cSrcweir             uno::Sequence< rtl::OUString > aElementNames( xNA->getElementNames() );
1447cdf0e10cSrcweir             sal_Int32 nVendors = aElementNames.getLength();
1448cdf0e10cSrcweir             const rtl::OUString *pVendor = aElementNames.getConstArray();
1449cdf0e10cSrcweir             for (sal_Int32 i = 0;  i < nVendors;  ++i)
1450cdf0e10cSrcweir             {
1451cdf0e10cSrcweir                 uno::Reference< container::XNameAccess > xNA2( xNA->getByName( pVendor[i] ), uno::UNO_QUERY_THROW  );
1452cdf0e10cSrcweir                 uno::Sequence< rtl::OUString > aPropNames( xNA2->getElementNames() );
1453cdf0e10cSrcweir                 sal_Int32 nProps = aPropNames.getLength();
1454cdf0e10cSrcweir                 const rtl::OUString *pPropNames = aPropNames.getConstArray();
1455cdf0e10cSrcweir                 for (sal_Int32 k = 0;  k < nProps;  ++k)
1456cdf0e10cSrcweir                 {
1457cdf0e10cSrcweir                     // for a quicker check we ignore the HC image names here
1458cdf0e10cSrcweir                     const OUString &rName = pPropNames[k];
1459cdf0e10cSrcweir                     if (rName.equalsAscii( pImageName ))
1460cdf0e10cSrcweir                     {
1461cdf0e10cSrcweir                         bRes = true;
1462cdf0e10cSrcweir                         break;
1463cdf0e10cSrcweir                     }
1464cdf0e10cSrcweir                 }
1465cdf0e10cSrcweir             }
1466cdf0e10cSrcweir         }
1467cdf0e10cSrcweir         catch (uno::Exception &)
1468cdf0e10cSrcweir         {
1469cdf0e10cSrcweir             DBG_ASSERT( 0, "exception caught. HasVendorImages failed" );
1470cdf0e10cSrcweir         }
1471cdf0e10cSrcweir     }
1472cdf0e10cSrcweir     return bRes;
1473cdf0e10cSrcweir }
1474cdf0e10cSrcweir 
1475cdf0e10cSrcweir 
HasGrammarChecker() const1476cdf0e10cSrcweir bool SvtLinguConfig::HasGrammarChecker() const
1477cdf0e10cSrcweir {
1478cdf0e10cSrcweir 	bool bRes = false;
1479cdf0e10cSrcweir 
1480cdf0e10cSrcweir 	try
1481cdf0e10cSrcweir 	{
1482cdf0e10cSrcweir         uno::Reference< container::XNameAccess > xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW );
1483cdf0e10cSrcweir         xNA.set( xNA->getByName( A2OU("ServiceManager") ), uno::UNO_QUERY_THROW );
1484cdf0e10cSrcweir 		xNA.set( xNA->getByName( A2OU("GrammarCheckerList") ), uno::UNO_QUERY_THROW );
1485cdf0e10cSrcweir 
1486cdf0e10cSrcweir 		uno::Sequence< rtl::OUString > aElementNames( xNA->getElementNames() );
1487cdf0e10cSrcweir 		bRes = aElementNames.getLength() > 0;
1488cdf0e10cSrcweir 	}
1489cdf0e10cSrcweir 	catch (uno::Exception &)
1490cdf0e10cSrcweir 	{
1491cdf0e10cSrcweir 	}
1492cdf0e10cSrcweir 
1493cdf0e10cSrcweir     return bRes;
1494cdf0e10cSrcweir }
1495cdf0e10cSrcweir 
1496cdf0e10cSrcweir //////////////////////////////////////////////////////////////////////
1497cdf0e10cSrcweir 
1498