1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #ifndef _RPTUI_MODULE_HELPER_RPT_HXX_
29 #define _RPTUI_MODULE_HELPER_RPT_HXX_
30 
31 #include "dllapi.h"
32 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
33 #include <tools/resmgr.hxx>
34 
35 //.........................................................................
36 namespace rptui
37 {
38 //.........................................................................
39     //=========================================================================
40     //= OModule
41     //=========================================================================
42     class OModuleImpl;
43     class REPORTDESIGN_DLLPUBLIC OModule
44     {
45 	    friend class OModuleClient;
46 
47     private:
48 	    OModule();
49 		    // not implemented. OModule is a static class
50 
51     protected:
52 	    static ::osl::Mutex	s_aMutex;		/// access safety
53 	    static sal_Int32	s_nClients;		/// number of registered clients
54 	    static OModuleImpl*	s_pImpl;		/// impl class. lives as long as at least one client for the module is registered
55 
56     public:
57 	    /// get the vcl res manager of the module
58 	    static ResMgr*	getResManager();
59     protected:
60 	    /// register a client for the module
61 	    static void	registerClient();
62 	    /// revoke a client for the module
63 	    static void	revokeClient();
64 
65     private:
66 	    /** ensure that the impl class exists
67 		    @precond m_aMutex is guarded when this method gets called
68 	    */
69 	    static void ensureImpl();
70     };
71 
72     //=========================================================================
73     //= OModuleClient
74     //=========================================================================
75     /** base class for objects which uses any global module-specific ressources
76     */
77     class REPORTDESIGN_DLLPUBLIC OModuleClient
78     {
79     public:
80 	    inline OModuleClient()		{ OModule::registerClient(); }
81 	    inline ~OModuleClient()	{ OModule::revokeClient(); }
82     };
83 
84     //=========================================================================
85     //= ModuleRes
86     //=========================================================================
87     /** specialized ResId, using the ressource manager provided by the global module
88     */
89     class REPORTDESIGN_DLLPUBLIC ModuleRes : public ::ResId
90     {
91     public:
92 	    inline ModuleRes(sal_uInt16 _nId) : ResId(_nId, *OModule::getResManager()) { }
93     };
94 //.........................................................................
95 }	// namespace rptui
96 //.........................................................................
97 
98 #endif // _RPTUI_MODULE_HELPER_RPT_HXX_
99 
100 
101