Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 :
21 : #include "core_resource.hxx"
22 :
23 : #include <tools/resmgr.hxx>
24 :
25 : // ---- needed as long as we have no contexts for components ---
26 : #include <vcl/svapp.hxx>
27 : //---------------------------------------------------
28 : #include <rtl/instance.hxx>
29 : #include <svl/solar.hrc>
30 :
31 : //.........................................................................
32 : namespace dbaccess
33 : {
34 :
35 : //==================================================================
36 : //= ResourceManager
37 : //==================================================================
38 : namespace
39 : {
40 : // access safety
41 : struct theResourceManagerMutex : public rtl::Static< osl::Mutex, theResourceManagerMutex > {};
42 : }
43 :
44 : sal_Int32 ResourceManager::s_nClients = 0;
45 : ResMgr* ResourceManager::m_pImpl = NULL;
46 :
47 : //------------------------------------------------------------------
48 17 : void ResourceManager::ensureImplExists()
49 : {
50 17 : if (m_pImpl)
51 32 : return;
52 :
53 2 : m_pImpl = ResMgr::CreateResMgr("dba", Application::GetSettings().GetUILanguageTag());
54 : }
55 :
56 : //------------------------------------------------------------------
57 17 : OUString ResourceManager::loadString(sal_uInt16 _nResId)
58 : {
59 17 : OUString sReturn;
60 :
61 17 : ensureImplExists();
62 17 : if (m_pImpl)
63 17 : sReturn = OUString(ResId(_nResId,*m_pImpl));
64 :
65 17 : return sReturn;
66 : }
67 :
68 : //------------------------------------------------------------------
69 0 : OUString ResourceManager::loadString( sal_uInt16 _nResId, const sal_Char* _pPlaceholderAscii, const OUString& _rReplace )
70 : {
71 0 : OUString sString( loadString( _nResId ) );
72 0 : return sString.replaceFirst( OUString::createFromAscii(_pPlaceholderAscii), _rReplace );
73 : }
74 :
75 : //------------------------------------------------------------------
76 0 : OUString ResourceManager::loadString( sal_uInt16 _nResId, const sal_Char* _pPlaceholderAscii1, const OUString& _rReplace1,
77 : const sal_Char* _pPlaceholderAscii2, const OUString& _rReplace2 )
78 : {
79 0 : OUString sString( loadString( _nResId ) );
80 0 : sString = sString.replaceFirst( OUString::createFromAscii(_pPlaceholderAscii1), _rReplace1 );
81 0 : sString = sString.replaceFirst( OUString::createFromAscii(_pPlaceholderAscii2), _rReplace2 );
82 0 : return sString;
83 : }
84 :
85 : //-------------------------------------------------------------------------
86 272 : void ResourceManager::registerClient()
87 : {
88 272 : ::osl::MutexGuard aGuard(theResourceManagerMutex::get());
89 272 : ++s_nClients;
90 272 : }
91 :
92 : //-------------------------------------------------------------------------
93 269 : void ResourceManager::revokeClient()
94 : {
95 269 : ::osl::MutexGuard aGuard(theResourceManagerMutex::get());
96 269 : if (!--s_nClients && m_pImpl)
97 : {
98 2 : delete m_pImpl;
99 2 : m_pImpl = NULL;
100 269 : }
101 269 : }
102 : //.........................................................................
103 48 : }
104 : //.........................................................................
105 :
106 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|