1*c25918c1SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*c25918c1SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*c25918c1SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*c25918c1SAndrew Rist  * distributed with this work for additional information
6*c25918c1SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*c25918c1SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*c25918c1SAndrew Rist  * "License"); you may not use this file except in compliance
9*c25918c1SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*c25918c1SAndrew Rist  *
11*c25918c1SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*c25918c1SAndrew Rist  *
13*c25918c1SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*c25918c1SAndrew Rist  * software distributed under the License is distributed on an
15*c25918c1SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c25918c1SAndrew Rist  * KIND, either express or implied.  See the License for the
17*c25918c1SAndrew Rist  * specific language governing permissions and limitations
18*c25918c1SAndrew Rist  * under the License.
19*c25918c1SAndrew Rist  *
20*c25918c1SAndrew Rist  *************************************************************/
21*c25918c1SAndrew Rist 
22*c25918c1SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_formula.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "core_resource.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include <tools/resmgr.hxx>
30cdf0e10cSrcweir 
31cdf0e10cSrcweir // ---- needed as long as we have no contexts for components ---
32cdf0e10cSrcweir #include <vcl/svapp.hxx>
33cdf0e10cSrcweir #include <svl/solar.hrc>
34cdf0e10cSrcweir 
35cdf0e10cSrcweir //.........................................................................
36cdf0e10cSrcweir namespace formula
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 	//==================================================================
40cdf0e10cSrcweir 	//= ResourceManager
41cdf0e10cSrcweir 	//==================================================================
42cdf0e10cSrcweir     ::osl::Mutex	ResourceManager::s_aMutex;
43cdf0e10cSrcweir     sal_Int32		ResourceManager::s_nClients = 0;
44cdf0e10cSrcweir 	ResMgr*         ResourceManager::m_pImpl = NULL;
45cdf0e10cSrcweir 
46cdf0e10cSrcweir 	//------------------------------------------------------------------
ensureImplExists()47cdf0e10cSrcweir 	void ResourceManager::ensureImplExists()
48cdf0e10cSrcweir 	{
49cdf0e10cSrcweir 		if (m_pImpl)
50cdf0e10cSrcweir 			return;
51cdf0e10cSrcweir 
52cdf0e10cSrcweir 		::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();
53cdf0e10cSrcweir 
54cdf0e10cSrcweir 		ByteString sFileName("for");
55cdf0e10cSrcweir 
56cdf0e10cSrcweir 		m_pImpl = ResMgr::CreateResMgr(sFileName.GetBuffer(), aLocale);
57cdf0e10cSrcweir 	}
58cdf0e10cSrcweir 
59cdf0e10cSrcweir 	//------------------------------------------------------------------
loadString(sal_uInt16 _nResId)60cdf0e10cSrcweir 	::rtl::OUString ResourceManager::loadString(sal_uInt16 _nResId)
61cdf0e10cSrcweir 	{
62cdf0e10cSrcweir 		::rtl::OUString sReturn;
63cdf0e10cSrcweir 
64cdf0e10cSrcweir 		ensureImplExists();
65cdf0e10cSrcweir 		if (m_pImpl)
66cdf0e10cSrcweir 			sReturn = String(ResId(_nResId,*m_pImpl));
67cdf0e10cSrcweir 
68cdf0e10cSrcweir 		return sReturn;
69cdf0e10cSrcweir 	}
70cdf0e10cSrcweir 
71cdf0e10cSrcweir 	//------------------------------------------------------------------
loadString(sal_uInt16 _nResId,const sal_Char * _pPlaceholderAscii,const::rtl::OUString & _rReplace)72cdf0e10cSrcweir     ::rtl::OUString ResourceManager::loadString( sal_uInt16 _nResId, const sal_Char* _pPlaceholderAscii, const ::rtl::OUString& _rReplace )
73cdf0e10cSrcweir     {
74cdf0e10cSrcweir         String sString( loadString( _nResId ) );
75cdf0e10cSrcweir         sString.SearchAndReplaceAscii( _pPlaceholderAscii, _rReplace );
76cdf0e10cSrcweir         return sString;
77cdf0e10cSrcweir     }
78cdf0e10cSrcweir     //-------------------------------------------------------------------------
registerClient()79cdf0e10cSrcweir     void ResourceManager::registerClient()
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir 	    ::osl::MutexGuard aGuard(s_aMutex);
82cdf0e10cSrcweir 	    ++s_nClients;
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir 
85cdf0e10cSrcweir     //-------------------------------------------------------------------------
revokeClient()86cdf0e10cSrcweir     void ResourceManager::revokeClient()
87cdf0e10cSrcweir     {
88cdf0e10cSrcweir 	    ::osl::MutexGuard aGuard(s_aMutex);
89cdf0e10cSrcweir 	    if (!--s_nClients && m_pImpl)
90cdf0e10cSrcweir 	    {
91cdf0e10cSrcweir 		    delete m_pImpl;
92cdf0e10cSrcweir 		    m_pImpl = NULL;
93cdf0e10cSrcweir 	    }
94cdf0e10cSrcweir     }
getResManager()95cdf0e10cSrcweir     ResMgr*	ResourceManager::getResManager()
96cdf0e10cSrcweir     {
97cdf0e10cSrcweir         ensureImplExists();
98cdf0e10cSrcweir 		return m_pImpl;
99cdf0e10cSrcweir     }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir //.........................................................................
102cdf0e10cSrcweir } // formula
103cdf0e10cSrcweir //.........................................................................
104cdf0e10cSrcweir 
105