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 SD_FRAMEWORK_CONFIGURATION_CONFIGURATION_HXX
25 #define SD_FRAMEWORK_CONFIGURATION_CONFIGURATION_HXX
26 
27 #include "MutexOwner.hxx"
28 #include <com/sun/star/drawing/framework/XConfiguration.hpp>
29 #include <com/sun/star/drawing/framework/XConfigurationControllerBroadcaster.hpp>
30 #include <com/sun/star/util/XCloneable.hpp>
31 #include <com/sun/star/container/XNamed.hpp>
32 #include <cppuhelper/compbase2.hxx>
33 
34 #include <boost/scoped_ptr.hpp>
35 
36 namespace {
37 
38 typedef ::cppu::WeakComponentImplHelper2 <
39     ::com::sun::star::drawing::framework::XConfiguration,
40     ::com::sun::star::container::XNamed
41     > ConfigurationInterfaceBase;
42 
43 } // end of anonymous namespace.
44 
45 
46 
47 
48 namespace sd { namespace framework {
49 
50 /** A configuration describes the resources of an application like panes,
51     views, and tool bars and their relationships that are currently active
52     or are requested to be activated. Resources are specified by URLs rather
53     than references so that not only the current configuration but also a
54     requested configuration can be represented.
55 
56     A resource URL describes the type of a resource, not its actual
57     instance. For resources, like panes, that are unique with respect to an
58     application frame, that does not mean much of a difference. For other
59     resources like views, that may have more than one instance per
60     application frame, this is different. To identify them unambigously a
61     second URL, one of a unique resource, is necessary. This second URL is
62     called the anchor of the first. The two types of resources are called
63     unique and linked respectively.
64 
65     Direct manipulation of a configuration object is not advised with the
66     exception of the configuration controller and objects that implement the
67     XConfigurationChangeOperation interface.
68 */
69 class Configuration
70     : private sd::MutexOwner,
71       public ConfigurationInterfaceBase
72 {
73 public:
74     /** Create a new configuration with a broadcaster that is used to send
75         events about requested configuration changes.
76         @param rxBroadcaster
77             This broadcaster is typically the same as the one used by the
78             ConfigurationController.
79         @param bBroadcastRequestEvents
80             When this is <TRUE/> then modifications to the configuration
81             trigger the broadcasting of "ResourceActivationRequestEvent" and
82             "ResourceDeactivationRequestEvent".  When this flag is <FALSE/>
83             then events with type "ResourceActivationEvent" and
84             "ResourceDeactivationEvent" are broadcasted.
85     */
86     Configuration (const ::com::sun::star::uno::Reference<
87         ::com::sun::star::drawing::framework::XConfigurationControllerBroadcaster>& rxBroadcaster,
88         bool bBroadcastRequestEvents);
89     virtual ~Configuration (void);
90 
91     virtual void SAL_CALL disposing (void);
92 
93 
94     // XConfiguration
95 
96     virtual void SAL_CALL addResource (
97         const ::com::sun::star::uno::Reference<com::sun::star::drawing::framework::XResourceId>&
98             rxResourceId)
99         throw (::com::sun::star::uno::RuntimeException);
100 
101     virtual void SAL_CALL removeResource(
102         const ::com::sun::star::uno::Reference<com::sun::star::drawing::framework::XResourceId>&
103             rxResourceId)
104         throw (::com::sun::star::uno::RuntimeException);
105 
106     virtual ::com::sun::star::uno::Sequence< com::sun::star::uno::Reference<
107         com::sun::star::drawing::framework::XResourceId> > SAL_CALL getResources (
108         const ::com::sun::star::uno::Reference<
109             ::com::sun::star::drawing::framework::XResourceId>& rxAnchorId,
110         const ::rtl::OUString& rsResourceURLPrefix,
111         ::com::sun::star::drawing::framework::AnchorBindingMode eMode)
112         throw (::com::sun::star::uno::RuntimeException);
113 
114     virtual sal_Bool SAL_CALL hasResource (
115         const ::com::sun::star::uno::Reference<com::sun::star::drawing::framework::XResourceId>&
116             rxResourceId)
117         throw (::com::sun::star::uno::RuntimeException);
118 
119 
120     // XCloneable
121 
122     virtual ::com::sun::star::uno::Reference<com::sun::star::util::XCloneable>
123         SAL_CALL createClone (void)
124         throw (::com::sun::star::uno::RuntimeException);
125 
126 
127     // XNamed
128 
129     /** Return a human readable string representation.  This is used for
130         debugging purposes.
131     */
132     virtual ::rtl::OUString SAL_CALL getName (void)
133         throw (::com::sun::star::uno::RuntimeException);
134 
135     /** This call is ignored because the XNamed interface is (mis)used to
136         give access to a human readable name for debugging purposes.
137     */
138     virtual void SAL_CALL setName (const ::rtl::OUString& rName)
139         throw (::com::sun::star::uno::RuntimeException);
140 
141 private:
142     class ResourceContainer;
143     /** The resource container holds the URLs of unique resource and of
144         resource linked to unique resources.
145     */
146     ::boost::scoped_ptr<ResourceContainer> mpResourceContainer;
147 
148     /** The broadcaster used for notifying listeners of requests for
149         configuration changes.
150     */
151     ::com::sun::star::uno::Reference<
152         ::com::sun::star::drawing::framework::XConfigurationControllerBroadcaster>
153         mxBroadcaster;
154 
155     bool mbBroadcastRequestEvents;
156 
157     /** This private variant of the constructor is used for cloning a
158         Configuration object.
159         @param rResourceContainer
160             The new Configuration is created with a copy of the elements in
161             this container.
162     */
163     Configuration (const ::com::sun::star::uno::Reference<
164         ::com::sun::star::drawing::framework::XConfigurationControllerBroadcaster>& rxBroadcaster,
165         bool bBroadcastRequestEvents,
166         const ResourceContainer& rResourceContainer);
167 
168     /** Send an event to all interested listeners that a resource has been
169         added or removed.  The event is sent to the listeners via the
170         ConfigurationController.
171         @param rxResourceId
172             The resource that is added to or removed from the configuration.
173         @param bActivation
174             This specifies whether an activation or deactivation is
175             broadcasted.  The mbBroadcastRequestEvents member is also taken
176             into account when the actual event type field is determined.
177     */
178     void PostEvent (
179         const ::com::sun::star::uno::Reference<com::sun::star::drawing::framework::XResourceId>&
180             rxResourceId,
181         const bool bActivation);
182 
183     /** When the called object has already been disposed this method throws
184         an exception and does not return.
185     */
186     void ThrowIfDisposed (void) const
187         throw (::com::sun::star::lang::DisposedException);
188 };
189 
190 
191 /** Return whether the two given configurations contain the same resource
192     ids.  The order of resource ids is ignored.  Empty references are
193     treated like empty configurations.
194 */
195 bool AreConfigurationsEquivalent (
196         const ::com::sun::star::uno::Reference<
197             ::com::sun::star::drawing::framework::XConfiguration>& rxConfiguration1,
198         const ::com::sun::star::uno::Reference<
199             ::com::sun::star::drawing::framework::XConfiguration>& rxConfiguration2);
200 
201 } } // end of namespace sd::framework
202 
203 #endif
204