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 : #include "core_resource.hxx"
21 :
22 : #include <tools/resmgr.hxx>
23 :
24 : // ---- needed as long as we have no contexts for components ---
25 : #include <vcl/svapp.hxx>
26 : #include <vcl/settings.hxx>
27 : #include <rtl/instance.hxx>
28 : #include <svl/solar.hrc>
29 :
30 : namespace dbaccess
31 : {
32 :
33 : // ResourceManager
34 : namespace
35 : {
36 : // access safety
37 : struct theResourceManagerMutex : public rtl::Static< osl::Mutex, theResourceManagerMutex > {};
38 : }
39 :
40 : sal_Int32 ResourceManager::s_nClients = 0;
41 : ResMgr* ResourceManager::m_pImpl = NULL;
42 :
43 464 : void ResourceManager::ensureImplExists()
44 : {
45 464 : if (m_pImpl)
46 911 : return;
47 :
48 17 : m_pImpl = ResMgr::CreateResMgr("dba", Application::GetSettings().GetUILanguageTag());
49 : }
50 :
51 464 : OUString ResourceManager::loadString(sal_uInt16 _nResId)
52 : {
53 464 : OUString sReturn;
54 :
55 464 : ensureImplExists();
56 464 : if (m_pImpl)
57 464 : sReturn = OUString(ResId(_nResId,*m_pImpl));
58 :
59 464 : return sReturn;
60 : }
61 :
62 0 : OUString ResourceManager::loadString( sal_uInt16 _nResId, const sal_Char* _pPlaceholderAscii, const OUString& _rReplace )
63 : {
64 0 : OUString sString( loadString( _nResId ) );
65 0 : return sString.replaceFirst( OUString::createFromAscii(_pPlaceholderAscii), _rReplace );
66 : }
67 :
68 0 : OUString ResourceManager::loadString( sal_uInt16 _nResId, const sal_Char* _pPlaceholderAscii1, const OUString& _rReplace1,
69 : const sal_Char* _pPlaceholderAscii2, const OUString& _rReplace2 )
70 : {
71 0 : OUString sString( loadString( _nResId ) );
72 0 : sString = sString.replaceFirst( OUString::createFromAscii(_pPlaceholderAscii1), _rReplace1 );
73 0 : sString = sString.replaceFirst( OUString::createFromAscii(_pPlaceholderAscii2), _rReplace2 );
74 0 : return sString;
75 : }
76 :
77 576 : void ResourceManager::registerClient()
78 : {
79 576 : ::osl::MutexGuard aGuard(theResourceManagerMutex::get());
80 576 : ++s_nClients;
81 576 : }
82 :
83 570 : void ResourceManager::revokeClient()
84 : {
85 570 : ::osl::MutexGuard aGuard(theResourceManagerMutex::get());
86 570 : if (!--s_nClients && m_pImpl)
87 : {
88 17 : delete m_pImpl;
89 17 : m_pImpl = NULL;
90 570 : }
91 570 : }
92 168 : }
93 :
94 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|