1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: syslocale.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
36 #include <svtools/syslocale.hxx>
37 #include <broadcast.hxx>
38 #include <listener.hxx>
39 #include <svtools/smplhint.hxx>
40 #include <vcl/svapp.hxx>
41 #include <tools/string.hxx>
42 #include <svtools/syslocaleoptions.hxx>
43 #include <unotools/localedatawrapper.hxx>
44 #include <comphelper/processfactory.hxx>
48 using namespace com::sun::star
;
51 SvtSysLocale_Impl
* SvtSysLocale::pImpl
= NULL
;
52 sal_Int32
SvtSysLocale::nRefCount
= 0;
55 class SvtSysLocale_Impl
: public SvtListener
57 friend class SvtSysLocale
;
59 SvtSysLocaleOptions aSysLocaleOptions
;
60 LocaleDataWrapper
* pLocaleData
;
61 CharClass
* pCharClass
;
65 virtual ~SvtSysLocale_Impl();
67 virtual void Notify( SvtBroadcaster
& rBC
, const SfxHint
& rHint
);
69 CharClass
* GetCharClass();
74 // -----------------------------------------------------------------------
76 SvtSysLocale_Impl::SvtSysLocale_Impl() : pCharClass(NULL
)
78 const lang::Locale
& rLocale
= Application::GetSettings().GetLocale();
79 pLocaleData
= new LocaleDataWrapper(
80 ::comphelper::getProcessServiceFactory(), rLocale
);
81 aSysLocaleOptions
.AddListener( *this );
85 SvtSysLocale_Impl::~SvtSysLocale_Impl()
87 aSysLocaleOptions
.RemoveListener( *this );
92 CharClass
* SvtSysLocale_Impl::GetCharClass()
96 const lang::Locale
& rLocale
= Application::GetSettings().GetLocale();
97 pCharClass
= new CharClass(::comphelper::getProcessServiceFactory(), rLocale
);
101 void SvtSysLocale_Impl::Notify( SvtBroadcaster
&, const SfxHint
& rHint
)
103 const SfxSimpleHint
* p
= PTR_CAST( SfxSimpleHint
, &rHint
);
104 if( p
&& (p
->GetId() & SYSLOCALEOPTIONS_HINT_LOCALE
) )
106 MutexGuard
aGuard( SvtSysLocale::GetMutex() );
107 const lang::Locale
& rLocale
= Application::GetSettings().GetLocale();
108 pLocaleData
->setLocale( rLocale
);
109 GetCharClass()->setLocale( rLocale
);
114 // ====================================================================
116 SvtSysLocale::SvtSysLocale()
118 MutexGuard
aGuard( GetMutex() );
120 pImpl
= new SvtSysLocale_Impl
;
125 SvtSysLocale::~SvtSysLocale()
127 MutexGuard
aGuard( GetMutex() );
137 Mutex
& SvtSysLocale::GetMutex()
139 static Mutex
* pMutex
= NULL
;
142 MutexGuard
aGuard( Mutex::getGlobalMutex() );
145 // #i77768# Due to a static reference in the toolkit lib
146 // we need a mutex that lives longer than the svtools library.
147 // Otherwise the dtor would use a destructed mutex!!
155 const LocaleDataWrapper
& SvtSysLocale::GetLocaleData() const
157 return *(pImpl
->pLocaleData
);
161 const LocaleDataWrapper
* SvtSysLocale::GetLocaleDataPtr() const
163 return pImpl
->pLocaleData
;
167 const CharClass
& SvtSysLocale::GetCharClass() const
169 return *(pImpl
->GetCharClass());
173 const CharClass
* SvtSysLocale::GetCharClassPtr() const
175 return pImpl
->GetCharClass();