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