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 SD_FRAMEWORK_RESOURCE_MANAGER_HXX
29 #define SD_FRAMEWORK_RESOURCE_MANAGER_HXX
30 
31 #include <com/sun/star/drawing/framework/XConfiguration.hpp>
32 #include <com/sun/star/drawing/framework/XResource.hpp>
33 #include <com/sun/star/drawing/framework/XResourceFactory.hpp>
34 #include <boost/noncopyable.hpp>
35 #include <boost/shared_ptr.hpp>
36 #include <map>
37 #include <vector>
38 
39 namespace css = ::com::sun::star;
40 
41 namespace sd { namespace framework {
42 
43 class ConfigurationControllerBroadcaster;
44 class ResourceFactoryManager;
45 
46 /** Manage the set of active resources.  Activate and deactivate resources.
47 */
48 class ConfigurationControllerResourceManager
49     : ::boost::noncopyable
50 {
51 public:
52     /** For every active resource both the resource itself as well as its
53         creating factory are remembered, so that on deactivation, the
54         resource can be deactivated by this factory.
55     */
56     class ResourceDescriptor
57     {
58     public:
59         css::uno::Reference<css::drawing::framework::XResource> mxResource;
60         css::uno::Reference<css::drawing::framework::XResourceFactory> mxResourceFactory;
61     };
62 
63     /** A new ResourceManager object is created with the resource factory
64         container for creating resources and the event broadcaster for
65         notifying ConfigurationChangeListeners of activated or deactivated
66         resources.
67     */
68     ConfigurationControllerResourceManager (
69         const ::boost::shared_ptr<ResourceFactoryManager>& rpResourceFactoryContainer,
70         const ::boost::shared_ptr<ConfigurationControllerBroadcaster>& rpBroadcaster);
71 
72     ~ConfigurationControllerResourceManager (void);
73 
74     /** Activate all the resources that are specified by resource ids in
75         rResources.  The resource ids of activated resources are added to
76         the given configuration.  Activated resources are notified to all
77         interested ConfigurationChangeListeners.
78     */
79     void ActivateResources (
80         const ::std::vector<
81             css::uno::Reference<css::drawing::framework::XResourceId> >& rResources,
82         const css::uno::Reference<css::drawing::framework::XConfiguration>& rxConfiguration);
83 
84     /** Deactivate all the resources that are specified by resource ids in
85         rResources.  The resource ids of deactivated resources are removed
86         from the given configuration.  Activated resources are notified to all
87         interested ConfigurationChangeListeners.
88     */
89     void DeactivateResources (
90         const ::std::vector<
91             css::uno::Reference<css::drawing::framework::XResourceId> >& rResources,
92         const css::uno::Reference<css::drawing::framework::XConfiguration>& rxConfiguration);
93 
94     /** Return the descriptor for the specified resource.
95         @return
96             When there is no active resource for the given resource id then
97             an empty descriptor is returned.
98     */
99     ResourceDescriptor GetResource (
100         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId);
101 
102 private:
103     osl::Mutex maMutex;
104 
105     class ResourceComparator
106     {
107     public:
108         bool operator() (
109             const css::uno::Reference<css::drawing::framework::XResourceId>& rxId1,
110             const css::uno::Reference<css::drawing::framework::XResourceId>& rxId2) const;
111     };
112 
113     typedef ::std::map<
114         css::uno::Reference<css::drawing::framework::XResourceId>,
115         ResourceDescriptor,
116         ResourceComparator> ResourceMap;
117     ResourceMap maResourceMap;
118 
119     ::boost::shared_ptr<ResourceFactoryManager> mpResourceFactoryContainer;
120 
121     /** This broadcaster is used to notify the activation and deactivation
122         of resources.
123     */
124     ::boost::shared_ptr<ConfigurationControllerBroadcaster> mpBroadcaster;
125 
126     void ActivateResource (
127         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
128         const css::uno::Reference<css::drawing::framework::XConfiguration>& rxConfiguration);
129 
130     void DeactivateResource (
131         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
132         const css::uno::Reference<css::drawing::framework::XConfiguration>& rxConfiguration);
133 
134     void AddResource (
135         const css::uno::Reference<css::drawing::framework::XResource>& rxResource,
136         const css::uno::Reference<css::drawing::framework::XResourceFactory>& rxFactory);
137 
138     ResourceDescriptor RemoveResource (
139         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId);
140 };
141 
142 
143 } } // end of namespace sd::framework
144 
145 #endif
146