update dev300-m58
[ooovba.git] / formula / source / ui / resource / ModuleHelper.cxx
blobe6ea0353ce9bbaecdcdebdc42c87dac35d5bf306
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ModuleHelper.cxx,v $
10 * $Revision: 1.4 $
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 ************************************************************************/
30 #include "ModuleHelper.hxx"
31 #include <comphelper/configurationhelper.hxx>
32 #include <comphelper/processfactory.hxx>
33 #include <osl/thread.h>
34 #include <com/sun/star/util/XMacroExpander.hpp>
35 #include <com/sun/star/beans/XPropertySet.hpp>
36 #include <com/sun/star/uno/XComponentContext.hpp>
37 #include <rtl/uri.hxx>
38 #include <tools/debug.hxx>
39 #ifndef _SOLAR_HRC
40 #include <svtools/solar.hrc>
41 #endif
43 #define EXPAND_PROTOCOL "vnd.sun.star.expand:"
44 #define ENTER_MOD_METHOD() \
45 ::osl::MutexGuard aGuard(s_aMutex); \
46 ensureImpl()
48 //.........................................................................
49 namespace formula
51 //.........................................................................
52 using namespace ::com::sun::star;
53 //=========================================================================
54 //= OModuleImpl
55 //=========================================================================
56 /** implementation for <type>OModule</type>. not threadsafe, has to be guarded by it's owner
58 class OModuleImpl
60 ResMgr* m_pRessources;
62 public:
63 /// ctor
64 OModuleImpl();
65 ~OModuleImpl();
67 /// get the manager for the ressources of the module
68 ResMgr* getResManager();
71 DBG_NAME( rpt_OModuleImpl )
72 //-------------------------------------------------------------------------
73 OModuleImpl::OModuleImpl()
74 :m_pRessources(NULL)
76 DBG_CTOR( rpt_OModuleImpl,NULL);
80 //-------------------------------------------------------------------------
81 OModuleImpl::~OModuleImpl()
83 if (m_pRessources)
84 delete m_pRessources;
86 DBG_DTOR( rpt_OModuleImpl,NULL);
89 //-------------------------------------------------------------------------
90 ResMgr* OModuleImpl::getResManager()
92 // note that this method is not threadsafe, which counts for the whole class !
94 if (!m_pRessources)
96 // create a manager with a fixed prefix
97 rtl::OString sName = rtl::OString( "forui" );
98 m_pRessources = ResMgr::CreateResMgr(sName);
100 return m_pRessources;
103 //=========================================================================
104 //= OModule
105 //=========================================================================
106 ::osl::Mutex OModule::s_aMutex;
107 sal_Int32 OModule::s_nClients = 0;
108 OModuleImpl* OModule::s_pImpl = NULL;
109 //-------------------------------------------------------------------------
110 ResMgr* OModule::getResManager()
112 ENTER_MOD_METHOD();
113 return s_pImpl->getResManager();
116 //-------------------------------------------------------------------------
117 void OModule::registerClient()
119 ::osl::MutexGuard aGuard(s_aMutex);
120 ++s_nClients;
123 //-------------------------------------------------------------------------
124 void OModule::revokeClient()
126 ::osl::MutexGuard aGuard(s_aMutex);
127 if (!--s_nClients && s_pImpl)
129 delete s_pImpl;
130 s_pImpl = NULL;
134 //-------------------------------------------------------------------------
135 void OModule::ensureImpl()
137 if (s_pImpl)
138 return;
139 s_pImpl = new OModuleImpl();
142 //.........................................................................
143 } // namespace formula
144 //.........................................................................