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