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