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_formula.hxx"
26 
27 #include "core_resource.hxx"
28 
29 #include <tools/resmgr.hxx>
30 
31 // ---- needed as long as we have no contexts for components ---
32 #include <vcl/svapp.hxx>
33 #include <svl/solar.hrc>
34 
35 //.........................................................................
36 namespace formula
37 {
38 
39 	//==================================================================
40 	//= ResourceManager
41 	//==================================================================
42     ::osl::Mutex	ResourceManager::s_aMutex;
43     sal_Int32		ResourceManager::s_nClients = 0;
44 	ResMgr*         ResourceManager::m_pImpl = NULL;
45 
46 	//------------------------------------------------------------------
ensureImplExists()47 	void ResourceManager::ensureImplExists()
48 	{
49 		if (m_pImpl)
50 			return;
51 
52 		::com::sun::star::lang::Locale aLocale = Application::GetSettings().GetUILocale();
53 
54 		ByteString sFileName("for");
55 
56 		m_pImpl = ResMgr::CreateResMgr(sFileName.GetBuffer(), aLocale);
57 	}
58 
59 	//------------------------------------------------------------------
loadString(sal_uInt16 _nResId)60 	::rtl::OUString ResourceManager::loadString(sal_uInt16 _nResId)
61 	{
62 		::rtl::OUString sReturn;
63 
64 		ensureImplExists();
65 		if (m_pImpl)
66 			sReturn = String(ResId(_nResId,*m_pImpl));
67 
68 		return sReturn;
69 	}
70 
71 	//------------------------------------------------------------------
loadString(sal_uInt16 _nResId,const sal_Char * _pPlaceholderAscii,const::rtl::OUString & _rReplace)72     ::rtl::OUString ResourceManager::loadString( sal_uInt16 _nResId, const sal_Char* _pPlaceholderAscii, const ::rtl::OUString& _rReplace )
73     {
74         String sString( loadString( _nResId ) );
75         sString.SearchAndReplaceAscii( _pPlaceholderAscii, _rReplace );
76         return sString;
77     }
78     //-------------------------------------------------------------------------
registerClient()79     void ResourceManager::registerClient()
80     {
81 	    ::osl::MutexGuard aGuard(s_aMutex);
82 	    ++s_nClients;
83     }
84 
85     //-------------------------------------------------------------------------
revokeClient()86     void ResourceManager::revokeClient()
87     {
88 	    ::osl::MutexGuard aGuard(s_aMutex);
89 	    if (!--s_nClients && m_pImpl)
90 	    {
91 		    delete m_pImpl;
92 		    m_pImpl = NULL;
93 	    }
94     }
getResManager()95     ResMgr*	ResourceManager::getResManager()
96     {
97         ensureImplExists();
98 		return m_pImpl;
99     }
100 
101 //.........................................................................
102 } // formula
103 //.........................................................................
104 
105