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