xref: /AOO41X/main/unotools/source/config/syslocaleoptions.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_unotools.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
32*cdf0e10cSrcweir #include <rtl/ustrbuf.hxx>
33*cdf0e10cSrcweir #include <rtl/instance.hxx>
34*cdf0e10cSrcweir #include <rtl/logfile.hxx>
35*cdf0e10cSrcweir #include <i18npool/mslangid.hxx>
36*cdf0e10cSrcweir #include <tools/string.hxx>
37*cdf0e10cSrcweir #include <tools/debug.hxx>
38*cdf0e10cSrcweir #include <unotools/syslocaleoptions.hxx>
39*cdf0e10cSrcweir #include <unotools/configmgr.hxx>
40*cdf0e10cSrcweir #include <unotools/configitem.hxx>
41*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir #include "itemholder1.hxx"
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #define CFG_READONLY_DEFAULT    sal_False
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir using namespace osl;
48*cdf0e10cSrcweir using namespace utl;
49*cdf0e10cSrcweir using namespace rtl;
50*cdf0e10cSrcweir using namespace com::sun::star::uno;
51*cdf0e10cSrcweir using namespace com::sun::star::lang;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir 
54*cdf0e10cSrcweir SvtSysLocaleOptions_Impl*   SvtSysLocaleOptions::pOptions = NULL;
55*cdf0e10cSrcweir sal_Int32                   SvtSysLocaleOptions::nRefCount = 0;
56*cdf0e10cSrcweir namespace
57*cdf0e10cSrcweir {
58*cdf0e10cSrcweir     struct CurrencyChangeLink
59*cdf0e10cSrcweir         : public rtl::Static<Link, CurrencyChangeLink> {};
60*cdf0e10cSrcweir }
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir com::sun::star::lang::Locale lcl_str_to_locale( const ::rtl::OUString rStr )
63*cdf0e10cSrcweir {
64*cdf0e10cSrcweir 	com::sun::star::lang::Locale aRet;
65*cdf0e10cSrcweir 	if ( rStr.getLength() )
66*cdf0e10cSrcweir 	{
67*cdf0e10cSrcweir 		aRet = com::sun::star::lang::Locale();
68*cdf0e10cSrcweir 		sal_Int32 nSep = rStr.indexOf('-');
69*cdf0e10cSrcweir 		if (nSep < 0)
70*cdf0e10cSrcweir 			aRet.Language = rStr;
71*cdf0e10cSrcweir 		else
72*cdf0e10cSrcweir 		{
73*cdf0e10cSrcweir 			aRet.Language = rStr.copy(0, nSep);
74*cdf0e10cSrcweir 			if (nSep < rStr.getLength())
75*cdf0e10cSrcweir 				aRet.Country = rStr.copy(nSep+1, rStr.getLength() - (nSep+1));
76*cdf0e10cSrcweir 		}
77*cdf0e10cSrcweir 	}
78*cdf0e10cSrcweir 
79*cdf0e10cSrcweir 	return aRet;
80*cdf0e10cSrcweir }
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir class SvtSysLocaleOptions_Impl : public utl::ConfigItem
83*cdf0e10cSrcweir {
84*cdf0e10cSrcweir 		Locale					m_aRealLocale;
85*cdf0e10cSrcweir 		Locale					m_aRealUILocale;
86*cdf0e10cSrcweir 		LanguageType			m_eRealLanguage;
87*cdf0e10cSrcweir 		LanguageType			m_eRealUILanguage;
88*cdf0e10cSrcweir 		OUString                m_aLocaleString;    // en-US or de-DE or empty for SYSTEM
89*cdf0e10cSrcweir         OUString                m_aUILocaleString;    // en-US or de-DE or empty for SYSTEM
90*cdf0e10cSrcweir         OUString                m_aCurrencyString;  // USD-en-US or EUR-de-DE
91*cdf0e10cSrcweir         sal_uLong                   m_nBlockedHint;     // pending hints
92*cdf0e10cSrcweir         sal_Bool                m_bDecimalSeparator; //use decimal separator same as locale
93*cdf0e10cSrcweir 
94*cdf0e10cSrcweir         sal_Bool                m_bROLocale;
95*cdf0e10cSrcweir         sal_Bool                m_bROUILocale;
96*cdf0e10cSrcweir         sal_Bool                m_bROCurrency;
97*cdf0e10cSrcweir         sal_Bool                m_bRODecimalSeparator;
98*cdf0e10cSrcweir 
99*cdf0e10cSrcweir 		static  const Sequence< /* const */ OUString >  GetPropertyNames();
100*cdf0e10cSrcweir 		void					MakeRealLocale();
101*cdf0e10cSrcweir 		void					MakeRealUILocale();
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir public:
104*cdf0e10cSrcweir                                 SvtSysLocaleOptions_Impl();
105*cdf0e10cSrcweir     virtual                     ~SvtSysLocaleOptions_Impl();
106*cdf0e10cSrcweir 
107*cdf0e10cSrcweir     virtual void                Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
108*cdf0e10cSrcweir     virtual void                Commit();
109*cdf0e10cSrcweir 
110*cdf0e10cSrcweir             const OUString&     GetLocaleString() const
111*cdf0e10cSrcweir                                     { return m_aLocaleString; }
112*cdf0e10cSrcweir             void                SetLocaleString( const OUString& rStr );
113*cdf0e10cSrcweir 
114*cdf0e10cSrcweir             const OUString&     GetUILocaleString() const
115*cdf0e10cSrcweir                                     { return m_aUILocaleString; }
116*cdf0e10cSrcweir             void                SetUILocaleString( const OUString& rStr );
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir             const OUString&     GetCurrencyString() const
119*cdf0e10cSrcweir                                     { return m_aCurrencyString; }
120*cdf0e10cSrcweir             void                SetCurrencyString( const OUString& rStr );
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir             sal_Bool            IsDecimalSeparatorAsLocale() const { return m_bDecimalSeparator;}
123*cdf0e10cSrcweir             void                SetDecimalSeparatorAsLocale( sal_Bool bSet);
124*cdf0e10cSrcweir 
125*cdf0e10cSrcweir             sal_Bool            IsReadOnly( SvtSysLocaleOptions::EOption eOption ) const;
126*cdf0e10cSrcweir 			const Locale&		GetRealLocale() { return m_aRealLocale; }
127*cdf0e10cSrcweir 			const Locale&		GetRealUILocale() { return m_aRealUILocale; }
128*cdf0e10cSrcweir 			LanguageType		GetRealLanguage() { return m_eRealLanguage; }
129*cdf0e10cSrcweir 			LanguageType		GetRealUILanguage() { return m_eRealUILanguage; }
130*cdf0e10cSrcweir };
131*cdf0e10cSrcweir 
132*cdf0e10cSrcweir 
133*cdf0e10cSrcweir #define ROOTNODE_SYSLOCALE  			OUString(RTL_CONSTASCII_USTRINGPARAM("Setup/L10N"))
134*cdf0e10cSrcweir 
135*cdf0e10cSrcweir #define PROPERTYNAME_LOCALE         	OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupSystemLocale"))
136*cdf0e10cSrcweir #define PROPERTYNAME_UILOCALE       	OUString(RTL_CONSTASCII_USTRINGPARAM("ooLocale"))
137*cdf0e10cSrcweir #define PROPERTYNAME_CURRENCY       	OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupCurrency"))
138*cdf0e10cSrcweir #define PROPERTYNAME_DECIMALSEPARATOR 	OUString(RTL_CONSTASCII_USTRINGPARAM("DecimalSeparatorAsLocale"))
139*cdf0e10cSrcweir 
140*cdf0e10cSrcweir #define PROPERTYHANDLE_LOCALE       	0
141*cdf0e10cSrcweir #define PROPERTYHANDLE_UILOCALE       	1
142*cdf0e10cSrcweir #define PROPERTYHANDLE_CURRENCY     	2
143*cdf0e10cSrcweir #define PROPERTYHANDLE_DECIMALSEPARATOR 3
144*cdf0e10cSrcweir 
145*cdf0e10cSrcweir #define PROPERTYCOUNT               	4
146*cdf0e10cSrcweir 
147*cdf0e10cSrcweir const Sequence< OUString > SvtSysLocaleOptions_Impl::GetPropertyNames()
148*cdf0e10cSrcweir {
149*cdf0e10cSrcweir 	static const OUString pProperties[] =
150*cdf0e10cSrcweir 	{
151*cdf0e10cSrcweir         PROPERTYNAME_LOCALE,
152*cdf0e10cSrcweir         PROPERTYNAME_UILOCALE,
153*cdf0e10cSrcweir         PROPERTYNAME_CURRENCY,
154*cdf0e10cSrcweir         PROPERTYNAME_DECIMALSEPARATOR
155*cdf0e10cSrcweir 	};
156*cdf0e10cSrcweir     static const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
157*cdf0e10cSrcweir 	return seqPropertyNames;
158*cdf0e10cSrcweir }
159*cdf0e10cSrcweir 
160*cdf0e10cSrcweir // -----------------------------------------------------------------------
161*cdf0e10cSrcweir 
162*cdf0e10cSrcweir SvtSysLocaleOptions_Impl::SvtSysLocaleOptions_Impl()
163*cdf0e10cSrcweir     : ConfigItem( ROOTNODE_SYSLOCALE )
164*cdf0e10cSrcweir     , m_nBlockedHint( 0 )
165*cdf0e10cSrcweir     , m_bDecimalSeparator( sal_True )
166*cdf0e10cSrcweir     , m_bROLocale(CFG_READONLY_DEFAULT)
167*cdf0e10cSrcweir     , m_bROUILocale(CFG_READONLY_DEFAULT)
168*cdf0e10cSrcweir     , m_bROCurrency(CFG_READONLY_DEFAULT)
169*cdf0e10cSrcweir     , m_bRODecimalSeparator(sal_False)
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir {
172*cdf0e10cSrcweir     if ( IsValidConfigMgr() )
173*cdf0e10cSrcweir     {
174*cdf0e10cSrcweir         const Sequence< OUString > aNames = GetPropertyNames();
175*cdf0e10cSrcweir         Sequence< Any > aValues = GetProperties( aNames );
176*cdf0e10cSrcweir         Sequence< sal_Bool > aROStates = GetReadOnlyStates( aNames );
177*cdf0e10cSrcweir         const Any* pValues = aValues.getConstArray();
178*cdf0e10cSrcweir         const sal_Bool* pROStates = aROStates.getConstArray();
179*cdf0e10cSrcweir         DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
180*cdf0e10cSrcweir         DBG_ASSERT( aROStates.getLength() == aNames.getLength(), "GetReadOnlyStates failed" );
181*cdf0e10cSrcweir         if ( aValues.getLength() == aNames.getLength() && aROStates.getLength() == aNames.getLength() )
182*cdf0e10cSrcweir         {
183*cdf0e10cSrcweir             for ( sal_Int32 nProp = 0; nProp < aNames.getLength(); nProp++ )
184*cdf0e10cSrcweir             {
185*cdf0e10cSrcweir                 DBG_ASSERT( pValues[nProp].hasValue(), "property value missing" );
186*cdf0e10cSrcweir                 if ( pValues[nProp].hasValue() )
187*cdf0e10cSrcweir                 {
188*cdf0e10cSrcweir                     switch ( nProp )
189*cdf0e10cSrcweir                     {
190*cdf0e10cSrcweir                         case PROPERTYHANDLE_LOCALE :
191*cdf0e10cSrcweir                             {
192*cdf0e10cSrcweir                                 OUString aStr;
193*cdf0e10cSrcweir                                 if ( pValues[nProp] >>= aStr )
194*cdf0e10cSrcweir                                     m_aLocaleString = aStr;
195*cdf0e10cSrcweir                                 else
196*cdf0e10cSrcweir                                 {
197*cdf0e10cSrcweir                                     DBG_ERRORFILE( "Wrong property type!" );
198*cdf0e10cSrcweir                                 }
199*cdf0e10cSrcweir                                 m_bROLocale = pROStates[nProp];
200*cdf0e10cSrcweir                             }
201*cdf0e10cSrcweir                             break;
202*cdf0e10cSrcweir                         case PROPERTYHANDLE_UILOCALE :
203*cdf0e10cSrcweir                             {
204*cdf0e10cSrcweir                                 OUString aStr;
205*cdf0e10cSrcweir                                 if ( pValues[nProp] >>= aStr )
206*cdf0e10cSrcweir                                     m_aUILocaleString = aStr;
207*cdf0e10cSrcweir                                 else
208*cdf0e10cSrcweir                                 {
209*cdf0e10cSrcweir                                     DBG_ERRORFILE( "Wrong property type!" );
210*cdf0e10cSrcweir                                 }
211*cdf0e10cSrcweir                                 m_bROUILocale = pROStates[nProp];
212*cdf0e10cSrcweir                             }
213*cdf0e10cSrcweir                             break;
214*cdf0e10cSrcweir                         case PROPERTYHANDLE_CURRENCY :
215*cdf0e10cSrcweir                             {
216*cdf0e10cSrcweir                                 OUString aStr;
217*cdf0e10cSrcweir                                 if ( pValues[nProp] >>= aStr )
218*cdf0e10cSrcweir                                     m_aCurrencyString = aStr;
219*cdf0e10cSrcweir                                 else
220*cdf0e10cSrcweir                                 {
221*cdf0e10cSrcweir                                     DBG_ERRORFILE( "Wrong property type!" );
222*cdf0e10cSrcweir                                 }
223*cdf0e10cSrcweir                                 m_bROCurrency = pROStates[nProp];
224*cdf0e10cSrcweir                             }
225*cdf0e10cSrcweir                         break;
226*cdf0e10cSrcweir                         case  PROPERTYHANDLE_DECIMALSEPARATOR:
227*cdf0e10cSrcweir                         {
228*cdf0e10cSrcweir                                     sal_Bool bValue = sal_Bool();
229*cdf0e10cSrcweir                             if ( pValues[nProp] >>= bValue )
230*cdf0e10cSrcweir                                 m_bDecimalSeparator = bValue;
231*cdf0e10cSrcweir                             else
232*cdf0e10cSrcweir                             {
233*cdf0e10cSrcweir                                 DBG_ERRORFILE( "Wrong property type!" );
234*cdf0e10cSrcweir                             }
235*cdf0e10cSrcweir                             m_bRODecimalSeparator = pROStates[nProp];
236*cdf0e10cSrcweir                         }
237*cdf0e10cSrcweir                         break;
238*cdf0e10cSrcweir                         default:
239*cdf0e10cSrcweir                             DBG_ERRORFILE( "Wrong property type!" );
240*cdf0e10cSrcweir                     }
241*cdf0e10cSrcweir                 }
242*cdf0e10cSrcweir             }
243*cdf0e10cSrcweir         }
244*cdf0e10cSrcweir //        UpdateMiscSettings_Impl();
245*cdf0e10cSrcweir         EnableNotification( aNames );
246*cdf0e10cSrcweir     }
247*cdf0e10cSrcweir 
248*cdf0e10cSrcweir 	MakeRealLocale();
249*cdf0e10cSrcweir 	MakeRealUILocale();
250*cdf0e10cSrcweir }
251*cdf0e10cSrcweir 
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir SvtSysLocaleOptions_Impl::~SvtSysLocaleOptions_Impl()
254*cdf0e10cSrcweir {
255*cdf0e10cSrcweir     if ( IsModified() )
256*cdf0e10cSrcweir         Commit();
257*cdf0e10cSrcweir }
258*cdf0e10cSrcweir 
259*cdf0e10cSrcweir void SvtSysLocaleOptions_Impl::MakeRealLocale()
260*cdf0e10cSrcweir {
261*cdf0e10cSrcweir 	m_aRealLocale = lcl_str_to_locale( m_aLocaleString );
262*cdf0e10cSrcweir 	if ( m_aRealLocale.Language.getLength() )
263*cdf0e10cSrcweir 	{
264*cdf0e10cSrcweir 	    m_eRealLanguage = MsLangId::convertLocaleToLanguage( m_aRealLocale );
265*cdf0e10cSrcweir 	}
266*cdf0e10cSrcweir 	else
267*cdf0e10cSrcweir 	{
268*cdf0e10cSrcweir 		m_eRealLanguage = MsLangId::getSystemLanguage();
269*cdf0e10cSrcweir 	    MsLangId::convertLanguageToLocale( m_eRealLanguage, m_aRealLocale );
270*cdf0e10cSrcweir 	}
271*cdf0e10cSrcweir }
272*cdf0e10cSrcweir 
273*cdf0e10cSrcweir void SvtSysLocaleOptions_Impl::MakeRealUILocale()
274*cdf0e10cSrcweir {
275*cdf0e10cSrcweir 	if ( !m_aRealUILocale.Language.getLength() )
276*cdf0e10cSrcweir 	{
277*cdf0e10cSrcweir 		// as we can't switch UILocale at runtime, we only store changes in the configuration
278*cdf0e10cSrcweir 		m_aRealUILocale = lcl_str_to_locale( m_aUILocaleString );
279*cdf0e10cSrcweir 		if ( m_aRealUILocale.Language.getLength() )
280*cdf0e10cSrcweir 		{
281*cdf0e10cSrcweir 			m_eRealUILanguage = MsLangId::convertLocaleToLanguage( m_aRealUILocale );
282*cdf0e10cSrcweir 		}
283*cdf0e10cSrcweir 		else
284*cdf0e10cSrcweir 		{
285*cdf0e10cSrcweir 			m_eRealUILanguage = MsLangId::getSystemUILanguage();
286*cdf0e10cSrcweir 			MsLangId::convertLanguageToLocale( m_eRealUILanguage, m_aRealUILocale );
287*cdf0e10cSrcweir 		}
288*cdf0e10cSrcweir 	}
289*cdf0e10cSrcweir }
290*cdf0e10cSrcweir 
291*cdf0e10cSrcweir sal_Bool SvtSysLocaleOptions_Impl::IsReadOnly( SvtSysLocaleOptions::EOption eOption ) const
292*cdf0e10cSrcweir {
293*cdf0e10cSrcweir     sal_Bool bReadOnly = CFG_READONLY_DEFAULT;
294*cdf0e10cSrcweir     switch(eOption)
295*cdf0e10cSrcweir     {
296*cdf0e10cSrcweir         case SvtSysLocaleOptions::E_LOCALE :
297*cdf0e10cSrcweir             {
298*cdf0e10cSrcweir                 bReadOnly = m_bROLocale;
299*cdf0e10cSrcweir                 break;
300*cdf0e10cSrcweir             }
301*cdf0e10cSrcweir         case SvtSysLocaleOptions::E_UILOCALE :
302*cdf0e10cSrcweir             {
303*cdf0e10cSrcweir                 bReadOnly = m_bROUILocale;
304*cdf0e10cSrcweir                 break;
305*cdf0e10cSrcweir             }
306*cdf0e10cSrcweir         case SvtSysLocaleOptions::E_CURRENCY :
307*cdf0e10cSrcweir             {
308*cdf0e10cSrcweir                 bReadOnly = m_bROCurrency;
309*cdf0e10cSrcweir                 break;
310*cdf0e10cSrcweir             }
311*cdf0e10cSrcweir     }
312*cdf0e10cSrcweir     return bReadOnly;
313*cdf0e10cSrcweir }
314*cdf0e10cSrcweir 
315*cdf0e10cSrcweir 
316*cdf0e10cSrcweir void SvtSysLocaleOptions_Impl::Commit()
317*cdf0e10cSrcweir {
318*cdf0e10cSrcweir     const Sequence< OUString > aOrgNames = GetPropertyNames();
319*cdf0e10cSrcweir     sal_Int32 nOrgCount = aOrgNames.getLength();
320*cdf0e10cSrcweir 
321*cdf0e10cSrcweir     Sequence< OUString > aNames( nOrgCount );
322*cdf0e10cSrcweir     Sequence< Any > aValues( nOrgCount );
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir     OUString* pNames = aNames.getArray();
325*cdf0e10cSrcweir 	Any* pValues = aValues.getArray();
326*cdf0e10cSrcweir     sal_Int32 nRealCount = 0;
327*cdf0e10cSrcweir 
328*cdf0e10cSrcweir     for ( sal_Int32 nProp = 0; nProp < nOrgCount; nProp++ )
329*cdf0e10cSrcweir 	{
330*cdf0e10cSrcweir         switch ( nProp )
331*cdf0e10cSrcweir         {
332*cdf0e10cSrcweir             case PROPERTYHANDLE_LOCALE :
333*cdf0e10cSrcweir                 {
334*cdf0e10cSrcweir                     if (!m_bROLocale)
335*cdf0e10cSrcweir                     {
336*cdf0e10cSrcweir                         pNames[nRealCount] = aOrgNames[nProp];
337*cdf0e10cSrcweir                         pValues[nRealCount] <<= m_aLocaleString;
338*cdf0e10cSrcweir                         ++nRealCount;
339*cdf0e10cSrcweir                     }
340*cdf0e10cSrcweir                 }
341*cdf0e10cSrcweir                 break;
342*cdf0e10cSrcweir             case PROPERTYHANDLE_UILOCALE :
343*cdf0e10cSrcweir                 {
344*cdf0e10cSrcweir                     if (!m_bROUILocale)
345*cdf0e10cSrcweir                     {
346*cdf0e10cSrcweir                         pNames[nRealCount] = aOrgNames[nProp];
347*cdf0e10cSrcweir                         pValues[nRealCount] <<= m_aUILocaleString;
348*cdf0e10cSrcweir                         ++nRealCount;
349*cdf0e10cSrcweir                     }
350*cdf0e10cSrcweir                 }
351*cdf0e10cSrcweir                 break;
352*cdf0e10cSrcweir             case PROPERTYHANDLE_CURRENCY :
353*cdf0e10cSrcweir                 {
354*cdf0e10cSrcweir                     if (!m_bROCurrency)
355*cdf0e10cSrcweir                     {
356*cdf0e10cSrcweir                         pNames[nRealCount] = aOrgNames[nProp];
357*cdf0e10cSrcweir                         pValues[nRealCount] <<= m_aCurrencyString;
358*cdf0e10cSrcweir                         ++nRealCount;
359*cdf0e10cSrcweir                     }
360*cdf0e10cSrcweir                 }
361*cdf0e10cSrcweir                 break;
362*cdf0e10cSrcweir             case  PROPERTYHANDLE_DECIMALSEPARATOR:
363*cdf0e10cSrcweir                 if( !m_bRODecimalSeparator )
364*cdf0e10cSrcweir                 {
365*cdf0e10cSrcweir                     pNames[nRealCount] = aOrgNames[nProp];
366*cdf0e10cSrcweir                     pValues[nRealCount] <<= m_bDecimalSeparator;
367*cdf0e10cSrcweir                     ++nRealCount;
368*cdf0e10cSrcweir                 }
369*cdf0e10cSrcweir             break;
370*cdf0e10cSrcweir             default:
371*cdf0e10cSrcweir                 DBG_ERRORFILE( "invalid index to save a path" );
372*cdf0e10cSrcweir         }
373*cdf0e10cSrcweir 	}
374*cdf0e10cSrcweir     aNames.realloc(nRealCount);
375*cdf0e10cSrcweir     aValues.realloc(nRealCount);
376*cdf0e10cSrcweir 	PutProperties( aNames, aValues );
377*cdf0e10cSrcweir     ClearModified();
378*cdf0e10cSrcweir }
379*cdf0e10cSrcweir 
380*cdf0e10cSrcweir 
381*cdf0e10cSrcweir void SvtSysLocaleOptions_Impl::SetLocaleString( const OUString& rStr )
382*cdf0e10cSrcweir {
383*cdf0e10cSrcweir     if (!m_bROLocale && rStr != m_aLocaleString )
384*cdf0e10cSrcweir     {
385*cdf0e10cSrcweir         m_aLocaleString = rStr;
386*cdf0e10cSrcweir 		MakeRealLocale();
387*cdf0e10cSrcweir 	    MsLangId::setConfiguredSystemLanguage( m_eRealLanguage );
388*cdf0e10cSrcweir         SetModified();
389*cdf0e10cSrcweir         sal_uLong nHint = SYSLOCALEOPTIONS_HINT_LOCALE;
390*cdf0e10cSrcweir 		if ( !m_aCurrencyString.getLength() )
391*cdf0e10cSrcweir 		    nHint |= SYSLOCALEOPTIONS_HINT_CURRENCY;
392*cdf0e10cSrcweir 		NotifyListeners( nHint );
393*cdf0e10cSrcweir     }
394*cdf0e10cSrcweir }
395*cdf0e10cSrcweir 
396*cdf0e10cSrcweir void SvtSysLocaleOptions_Impl::SetUILocaleString( const OUString& rStr )
397*cdf0e10cSrcweir {
398*cdf0e10cSrcweir     if (!m_bROUILocale && rStr != m_aUILocaleString )
399*cdf0e10cSrcweir     {
400*cdf0e10cSrcweir         m_aUILocaleString = rStr;
401*cdf0e10cSrcweir /*
402*cdf0e10cSrcweir 		// as we can't switch UILocale at runtime, we only store changes in the configuration
403*cdf0e10cSrcweir 		MakeRealUILocale();
404*cdf0e10cSrcweir 	    MsLangId::setConfiguredSystemLanguage( m_eRealUILanguage );
405*cdf0e10cSrcweir         SetModified();
406*cdf0e10cSrcweir 		NotifyListeners( SYSLOCALEOPTIONS_HINT_UILOCALE );
407*cdf0e10cSrcweir */
408*cdf0e10cSrcweir     }
409*cdf0e10cSrcweir }
410*cdf0e10cSrcweir 
411*cdf0e10cSrcweir void SvtSysLocaleOptions_Impl::SetCurrencyString( const OUString& rStr )
412*cdf0e10cSrcweir {
413*cdf0e10cSrcweir     if (!m_bROCurrency && rStr != m_aCurrencyString )
414*cdf0e10cSrcweir     {
415*cdf0e10cSrcweir         m_aCurrencyString = rStr;
416*cdf0e10cSrcweir         SetModified();
417*cdf0e10cSrcweir 		NotifyListeners( SYSLOCALEOPTIONS_HINT_CURRENCY );
418*cdf0e10cSrcweir     }
419*cdf0e10cSrcweir }
420*cdf0e10cSrcweir 
421*cdf0e10cSrcweir void SvtSysLocaleOptions_Impl::SetDecimalSeparatorAsLocale( sal_Bool bSet)
422*cdf0e10cSrcweir {
423*cdf0e10cSrcweir     if(bSet != m_bDecimalSeparator)
424*cdf0e10cSrcweir     {
425*cdf0e10cSrcweir         m_bDecimalSeparator = bSet;
426*cdf0e10cSrcweir         SetModified();
427*cdf0e10cSrcweir 		NotifyListeners( SYSLOCALEOPTIONS_HINT_DECSEP );
428*cdf0e10cSrcweir     }
429*cdf0e10cSrcweir }
430*cdf0e10cSrcweir 
431*cdf0e10cSrcweir void SvtSysLocaleOptions_Impl::Notify( const Sequence< rtl::OUString >& seqPropertyNames )
432*cdf0e10cSrcweir {
433*cdf0e10cSrcweir     sal_uLong nHint = 0;
434*cdf0e10cSrcweir 	Sequence< Any > seqValues = GetProperties( seqPropertyNames );
435*cdf0e10cSrcweir     Sequence< sal_Bool > seqROStates = GetReadOnlyStates( seqPropertyNames );
436*cdf0e10cSrcweir 	sal_Int32 nCount = seqPropertyNames.getLength();
437*cdf0e10cSrcweir     for( sal_Int32 nProp = 0; nProp < nCount; ++nProp )
438*cdf0e10cSrcweir 	{
439*cdf0e10cSrcweir         if( seqPropertyNames[nProp] == PROPERTYNAME_LOCALE )
440*cdf0e10cSrcweir 		{
441*cdf0e10cSrcweir             DBG_ASSERT( seqValues[nProp].getValueTypeClass() == TypeClass_STRING, "Locale property type" );
442*cdf0e10cSrcweir             seqValues[nProp] >>= m_aLocaleString;
443*cdf0e10cSrcweir             m_bROLocale = seqROStates[nProp];
444*cdf0e10cSrcweir             nHint |= SYSLOCALEOPTIONS_HINT_LOCALE;
445*cdf0e10cSrcweir 			if ( !m_aCurrencyString.getLength() )
446*cdf0e10cSrcweir 				nHint |= SYSLOCALEOPTIONS_HINT_CURRENCY;
447*cdf0e10cSrcweir 			MakeRealLocale();
448*cdf0e10cSrcweir 		}
449*cdf0e10cSrcweir         if( seqPropertyNames[nProp] == PROPERTYNAME_UILOCALE )
450*cdf0e10cSrcweir 		{
451*cdf0e10cSrcweir             DBG_ASSERT( seqValues[nProp].getValueTypeClass() == TypeClass_STRING, "Locale property type" );
452*cdf0e10cSrcweir             seqValues[nProp] >>= m_aUILocaleString;
453*cdf0e10cSrcweir             m_bROUILocale = seqROStates[nProp];
454*cdf0e10cSrcweir             nHint |= SYSLOCALEOPTIONS_HINT_UILOCALE;
455*cdf0e10cSrcweir 			MakeRealUILocale();
456*cdf0e10cSrcweir 		}
457*cdf0e10cSrcweir         else if( seqPropertyNames[nProp] == PROPERTYNAME_CURRENCY )
458*cdf0e10cSrcweir 		{
459*cdf0e10cSrcweir             DBG_ASSERT( seqValues[nProp].getValueTypeClass() == TypeClass_STRING, "Currency property type" );
460*cdf0e10cSrcweir             seqValues[nProp] >>= m_aCurrencyString;
461*cdf0e10cSrcweir             m_bROCurrency = seqROStates[nProp];
462*cdf0e10cSrcweir             nHint |= SYSLOCALEOPTIONS_HINT_CURRENCY;
463*cdf0e10cSrcweir 		}
464*cdf0e10cSrcweir         else if( seqPropertyNames[nProp] == PROPERTYNAME_DECIMALSEPARATOR )
465*cdf0e10cSrcweir         {
466*cdf0e10cSrcweir             seqValues[nProp] >>= m_bDecimalSeparator;
467*cdf0e10cSrcweir             m_bRODecimalSeparator = seqROStates[nProp];
468*cdf0e10cSrcweir         }
469*cdf0e10cSrcweir 	}
470*cdf0e10cSrcweir     if ( nHint )
471*cdf0e10cSrcweir 		NotifyListeners( nHint );
472*cdf0e10cSrcweir }
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir // ====================================================================
475*cdf0e10cSrcweir 
476*cdf0e10cSrcweir SvtSysLocaleOptions::SvtSysLocaleOptions()
477*cdf0e10cSrcweir {
478*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
479*cdf0e10cSrcweir     if ( !pOptions )
480*cdf0e10cSrcweir     {
481*cdf0e10cSrcweir         RTL_LOGFILE_CONTEXT(aLog, "svl ( ??? ) ::SvtSysLocaleOptions_Impl::ctor()");
482*cdf0e10cSrcweir         pOptions = new SvtSysLocaleOptions_Impl;
483*cdf0e10cSrcweir 
484*cdf0e10cSrcweir         ItemHolder1::holdConfigItem(E_SYSLOCALEOPTIONS);
485*cdf0e10cSrcweir     }
486*cdf0e10cSrcweir     ++nRefCount;
487*cdf0e10cSrcweir 	pOptions->AddListener(this);
488*cdf0e10cSrcweir }
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir 
491*cdf0e10cSrcweir SvtSysLocaleOptions::~SvtSysLocaleOptions()
492*cdf0e10cSrcweir {
493*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
494*cdf0e10cSrcweir 	pOptions->RemoveListener(this);
495*cdf0e10cSrcweir     if ( !--nRefCount )
496*cdf0e10cSrcweir 	{
497*cdf0e10cSrcweir         delete pOptions;
498*cdf0e10cSrcweir         pOptions = NULL;
499*cdf0e10cSrcweir 	}
500*cdf0e10cSrcweir }
501*cdf0e10cSrcweir 
502*cdf0e10cSrcweir 
503*cdf0e10cSrcweir // static
504*cdf0e10cSrcweir Mutex& SvtSysLocaleOptions::GetMutex()
505*cdf0e10cSrcweir {
506*cdf0e10cSrcweir     static Mutex* pMutex = NULL;
507*cdf0e10cSrcweir     if( !pMutex )
508*cdf0e10cSrcweir     {
509*cdf0e10cSrcweir         MutexGuard aGuard( Mutex::getGlobalMutex() );
510*cdf0e10cSrcweir         if( !pMutex )
511*cdf0e10cSrcweir         {
512*cdf0e10cSrcweir             // #i77768# Due to a static reference in the toolkit lib
513*cdf0e10cSrcweir             // we need a mutex that lives longer than the svl library.
514*cdf0e10cSrcweir             // Otherwise the dtor would use a destructed mutex!!
515*cdf0e10cSrcweir             pMutex = new Mutex;
516*cdf0e10cSrcweir         }
517*cdf0e10cSrcweir     }
518*cdf0e10cSrcweir     return *pMutex;
519*cdf0e10cSrcweir }
520*cdf0e10cSrcweir 
521*cdf0e10cSrcweir 
522*cdf0e10cSrcweir sal_Bool SvtSysLocaleOptions::IsModified()
523*cdf0e10cSrcweir {
524*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
525*cdf0e10cSrcweir     return pOptions->IsModified();
526*cdf0e10cSrcweir }
527*cdf0e10cSrcweir 
528*cdf0e10cSrcweir 
529*cdf0e10cSrcweir void SvtSysLocaleOptions::Commit()
530*cdf0e10cSrcweir {
531*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
532*cdf0e10cSrcweir     pOptions->Commit();
533*cdf0e10cSrcweir }
534*cdf0e10cSrcweir 
535*cdf0e10cSrcweir 
536*cdf0e10cSrcweir void SvtSysLocaleOptions::BlockBroadcasts( bool bBlock )
537*cdf0e10cSrcweir {
538*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
539*cdf0e10cSrcweir     pOptions->BlockBroadcasts( bBlock );
540*cdf0e10cSrcweir }
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir 
543*cdf0e10cSrcweir const OUString& SvtSysLocaleOptions::GetLocaleConfigString() const
544*cdf0e10cSrcweir {
545*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
546*cdf0e10cSrcweir     return pOptions->GetLocaleString();
547*cdf0e10cSrcweir }
548*cdf0e10cSrcweir 
549*cdf0e10cSrcweir void SvtSysLocaleOptions::SetLocaleConfigString( const OUString& rStr )
550*cdf0e10cSrcweir {
551*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
552*cdf0e10cSrcweir     pOptions->SetLocaleString( rStr );
553*cdf0e10cSrcweir }
554*cdf0e10cSrcweir 
555*cdf0e10cSrcweir const OUString& SvtSysLocaleOptions::GetUILocaleConfigString() const
556*cdf0e10cSrcweir {
557*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
558*cdf0e10cSrcweir     return pOptions->GetUILocaleString();
559*cdf0e10cSrcweir }
560*cdf0e10cSrcweir 
561*cdf0e10cSrcweir void SvtSysLocaleOptions::SetUILocaleConfigString( const OUString& rStr )
562*cdf0e10cSrcweir {
563*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
564*cdf0e10cSrcweir     pOptions->SetUILocaleString( rStr );
565*cdf0e10cSrcweir }
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir const OUString& SvtSysLocaleOptions::GetCurrencyConfigString() const
568*cdf0e10cSrcweir {
569*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
570*cdf0e10cSrcweir     return pOptions->GetCurrencyString();
571*cdf0e10cSrcweir }
572*cdf0e10cSrcweir 
573*cdf0e10cSrcweir 
574*cdf0e10cSrcweir void SvtSysLocaleOptions::SetCurrencyConfigString( const OUString& rStr )
575*cdf0e10cSrcweir {
576*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
577*cdf0e10cSrcweir     pOptions->SetCurrencyString( rStr );
578*cdf0e10cSrcweir }
579*cdf0e10cSrcweir 
580*cdf0e10cSrcweir 
581*cdf0e10cSrcweir 
582*cdf0e10cSrcweir /*-- 11.02.2004 13:31:41---------------------------------------------------
583*cdf0e10cSrcweir 
584*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
585*cdf0e10cSrcweir sal_Bool SvtSysLocaleOptions::IsDecimalSeparatorAsLocale() const
586*cdf0e10cSrcweir {
587*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
588*cdf0e10cSrcweir     return pOptions->IsDecimalSeparatorAsLocale();
589*cdf0e10cSrcweir }
590*cdf0e10cSrcweir /*-- 11.02.2004 13:31:41---------------------------------------------------
591*cdf0e10cSrcweir 
592*cdf0e10cSrcweir   -----------------------------------------------------------------------*/
593*cdf0e10cSrcweir void SvtSysLocaleOptions::SetDecimalSeparatorAsLocale( sal_Bool bSet)
594*cdf0e10cSrcweir {
595*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
596*cdf0e10cSrcweir     pOptions->SetDecimalSeparatorAsLocale(bSet);
597*cdf0e10cSrcweir }
598*cdf0e10cSrcweir 
599*cdf0e10cSrcweir 
600*cdf0e10cSrcweir sal_Bool SvtSysLocaleOptions::IsReadOnly( EOption eOption ) const
601*cdf0e10cSrcweir {
602*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
603*cdf0e10cSrcweir     return pOptions->IsReadOnly( eOption );
604*cdf0e10cSrcweir }
605*cdf0e10cSrcweir 
606*cdf0e10cSrcweir // static
607*cdf0e10cSrcweir void SvtSysLocaleOptions::GetCurrencyAbbrevAndLanguage( String& rAbbrev,
608*cdf0e10cSrcweir         LanguageType& eLang, const ::rtl::OUString& rConfigString )
609*cdf0e10cSrcweir {
610*cdf0e10cSrcweir     sal_Int32 nDelim = rConfigString.indexOf( '-' );
611*cdf0e10cSrcweir     if ( nDelim >= 0 )
612*cdf0e10cSrcweir     {
613*cdf0e10cSrcweir         rAbbrev = rConfigString.copy( 0, nDelim );
614*cdf0e10cSrcweir         String aIsoStr( rConfigString.copy( nDelim+1 ) );
615*cdf0e10cSrcweir         eLang = MsLangId::convertIsoStringToLanguage( aIsoStr );
616*cdf0e10cSrcweir     }
617*cdf0e10cSrcweir     else
618*cdf0e10cSrcweir     {
619*cdf0e10cSrcweir         rAbbrev = rConfigString;
620*cdf0e10cSrcweir         eLang = (rAbbrev.Len() ? LANGUAGE_NONE : LANGUAGE_SYSTEM);
621*cdf0e10cSrcweir     }
622*cdf0e10cSrcweir }
623*cdf0e10cSrcweir 
624*cdf0e10cSrcweir 
625*cdf0e10cSrcweir // static
626*cdf0e10cSrcweir ::rtl::OUString SvtSysLocaleOptions::CreateCurrencyConfigString(
627*cdf0e10cSrcweir         const String& rAbbrev, LanguageType eLang )
628*cdf0e10cSrcweir {
629*cdf0e10cSrcweir     String aIsoStr( MsLangId::convertLanguageToIsoString( eLang ) );
630*cdf0e10cSrcweir     if ( aIsoStr.Len() )
631*cdf0e10cSrcweir     {
632*cdf0e10cSrcweir         ::rtl::OUStringBuffer aStr( rAbbrev.Len() + 1 + aIsoStr.Len() );
633*cdf0e10cSrcweir         aStr.append( rAbbrev.GetBuffer(), rAbbrev.Len() );
634*cdf0e10cSrcweir         aStr.append( sal_Unicode('-') );
635*cdf0e10cSrcweir         aStr.append( aIsoStr.GetBuffer(), aIsoStr.Len() );
636*cdf0e10cSrcweir         return aStr.makeStringAndClear();
637*cdf0e10cSrcweir     }
638*cdf0e10cSrcweir     else
639*cdf0e10cSrcweir         return rAbbrev;
640*cdf0e10cSrcweir }
641*cdf0e10cSrcweir 
642*cdf0e10cSrcweir 
643*cdf0e10cSrcweir // static
644*cdf0e10cSrcweir void SvtSysLocaleOptions::SetCurrencyChangeLink( const Link& rLink )
645*cdf0e10cSrcweir {
646*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
647*cdf0e10cSrcweir     DBG_ASSERT( !CurrencyChangeLink::get().IsSet(), "SvtSysLocaleOptions::SetCurrencyChangeLink: already set" );
648*cdf0e10cSrcweir     CurrencyChangeLink::get() = rLink;
649*cdf0e10cSrcweir }
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir 
652*cdf0e10cSrcweir // static
653*cdf0e10cSrcweir const Link& SvtSysLocaleOptions::GetCurrencyChangeLink()
654*cdf0e10cSrcweir {
655*cdf0e10cSrcweir     MutexGuard aGuard( GetMutex() );
656*cdf0e10cSrcweir     return CurrencyChangeLink::get();
657*cdf0e10cSrcweir }
658*cdf0e10cSrcweir 
659*cdf0e10cSrcweir 
660*cdf0e10cSrcweir void SvtSysLocaleOptions::ConfigurationChanged( utl::ConfigurationBroadcaster* p, sal_uInt32 nHint  )
661*cdf0e10cSrcweir {
662*cdf0e10cSrcweir     if ( nHint & SYSLOCALEOPTIONS_HINT_CURRENCY )
663*cdf0e10cSrcweir 	{
664*cdf0e10cSrcweir 		const Link& rLink = GetCurrencyChangeLink();
665*cdf0e10cSrcweir 		if ( rLink.IsSet() )
666*cdf0e10cSrcweir 		    rLink.Call( NULL );
667*cdf0e10cSrcweir 	}
668*cdf0e10cSrcweir 
669*cdf0e10cSrcweir 	::utl::detail::Options::ConfigurationChanged( p, nHint );
670*cdf0e10cSrcweir }
671*cdf0e10cSrcweir 
672*cdf0e10cSrcweir com::sun::star::lang::Locale SvtSysLocaleOptions::GetLocale() const
673*cdf0e10cSrcweir {
674*cdf0e10cSrcweir 	return lcl_str_to_locale( GetLocaleConfigString() );
675*cdf0e10cSrcweir }
676*cdf0e10cSrcweir 
677*cdf0e10cSrcweir com::sun::star::lang::Locale SvtSysLocaleOptions::GetUILocale() const
678*cdf0e10cSrcweir {
679*cdf0e10cSrcweir 	return lcl_str_to_locale( GetUILocaleConfigString() );
680*cdf0e10cSrcweir }
681*cdf0e10cSrcweir 
682*cdf0e10cSrcweir com::sun::star::lang::Locale SvtSysLocaleOptions::GetRealLocale() const
683*cdf0e10cSrcweir {
684*cdf0e10cSrcweir 	return pOptions->GetRealLocale();
685*cdf0e10cSrcweir }
686*cdf0e10cSrcweir 
687*cdf0e10cSrcweir com::sun::star::lang::Locale SvtSysLocaleOptions::GetRealUILocale() const
688*cdf0e10cSrcweir {
689*cdf0e10cSrcweir 	return pOptions->GetRealUILocale();
690*cdf0e10cSrcweir }
691*cdf0e10cSrcweir 
692*cdf0e10cSrcweir LanguageType SvtSysLocaleOptions::GetRealLanguage() const
693*cdf0e10cSrcweir {
694*cdf0e10cSrcweir 	return pOptions->GetRealLanguage();
695*cdf0e10cSrcweir }
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir LanguageType SvtSysLocaleOptions::GetRealUILanguage() const
698*cdf0e10cSrcweir {
699*cdf0e10cSrcweir 	return pOptions->GetRealUILanguage();
700*cdf0e10cSrcweir }
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir 
703