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 #ifndef FORMULA_MODULE_HELPER_RPT_HXX_
25 #define FORMULA_MODULE_HELPER_RPT_HXX_
26 
27 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
28 #include <tools/resmgr.hxx>
29 #include "formula/formuladllapi.h"
30 //.........................................................................
31 namespace formula
32 {
33 //.........................................................................
34     //=========================================================================
35     //= OModule
36     //=========================================================================
37     class OModuleImpl;
38     class FORMULA_DLLPUBLIC OModule
39     {
40 	    friend class OModuleClient;
41 
42     private:
43 	    OModule();
44 		    // not implemented. OModule is a static class
45 
46     protected:
47 	    static ::osl::Mutex	s_aMutex;		/// access safety
48 	    static sal_Int32	s_nClients;		/// number of registered clients
49 	    static OModuleImpl*	s_pImpl;		/// impl class. lives as long as at least one client for the module is registered
50 
51     public:
52 	    /// get the vcl res manager of the module
53 	    static ResMgr*	getResManager();
54     protected:
55 	    /// register a client for the module
56 	    static void	registerClient();
57 	    /// revoke a client for the module
58 	    static void	revokeClient();
59 
60     private:
61 	    /** ensure that the impl class exists
62 		    @precond m_aMutex is guarded when this method gets called
63 	    */
64 	    static void ensureImpl();
65     };
66 
67     //=========================================================================
68     //= OModuleClient
69     //=========================================================================
70     /** base class for objects which uses any global module-specific ressources
71     */
72     class FORMULA_DLLPUBLIC OModuleClient
73     {
74     public:
OModuleClient()75 	    OModuleClient()		{ OModule::registerClient(); }
~OModuleClient()76 	    ~OModuleClient()	{ OModule::revokeClient(); }
77     };
78 
79     //=========================================================================
80     //= ModuleRes
81     //=========================================================================
82     /** specialized ResId, using the ressource manager provided by the global module
83     */
84     class FORMULA_DLLPUBLIC ModuleRes : public ::ResId
85     {
86     public:
ModuleRes(sal_uInt16 _nId)87 	    ModuleRes(sal_uInt16 _nId) : ResId(_nId, *OModule::getResManager()) { }
88     };
89 //.........................................................................
90 }	// namespace formula
91 //.........................................................................
92 
93 #endif // FORMULA_MODULE_HELPER_RPT_HXX_
94 
95 
96