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_CONTROLLER_HXX
25 #define SD_FRAMEWORK_CONFIGURATION_CONTROLLER_HXX
26 
27 #include "MutexOwner.hxx"
28 
29 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
30 #include <com/sun/star/drawing/framework/XConfigurationChangeRequest.hpp>
31 #include <com/sun/star/drawing/framework/XConfiguration.hpp>
32 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
33 #include <com/sun/star/drawing/framework/XResourceFactoryManager.hpp>
34 #include <com/sun/star/drawing/framework/XResourceId.hpp>
35 #include <com/sun/star/drawing/framework/ConfigurationChangeEvent.hpp>
36 #include <com/sun/star/lang/XInitialization.hpp>
37 #include <com/sun/star/uno/XComponentContext.hpp>
38 
39 #include <cppuhelper/compbase2.hxx>
40 #include <tools/link.hxx>
41 #include <rtl/ref.hxx>
42 
43 #include <boost/scoped_ptr.hpp>
44 #include <boost/shared_ptr.hpp>
45 #include <boost/noncopyable.hpp>
46 
47 namespace css = ::com::sun::star;
48 
49 namespace {
50 
51 typedef ::cppu::WeakComponentImplHelper2 <
52     ::css::drawing::framework::XConfigurationController,
53     ::css::lang::XInitialization
54     > ConfigurationControllerInterfaceBase;
55 
56 } // end of anonymous namespace.
57 
58 
59 namespace sd { class ViewShellBase; }
60 
61 
62 namespace sd { namespace framework {
63 
64 class ChangeRequestQueueProcessor;
65 class ConfigurationControllerBroadcaster;
66 class ConfigurationUpdater;
67 class ConfigurationUpdaterLock;
68 
69 /** The configuration controller is responsible for maintaining the current
70     configuration.
71 
72     @see css::drawing::framework::XConfigurationController
73         for an extended documentation.
74 */
75 class ConfigurationController
76     : private sd::MutexOwner,
77       private boost::noncopyable,
78       public ConfigurationControllerInterfaceBase
79 {
80 public:
81     ConfigurationController (void) throw();
82     virtual ~ConfigurationController (void) throw();
83 
84     virtual void SAL_CALL disposing (void);
85 
86     void ProcessEvent (void);
87 
88     /** Normally the requested changes of the configuration are executed
89         asynchronously.  However, there is at least one situation (searching
90         with the Outliner) where the surrounding code does not cope with
91         this.  So, instead of calling Reschedule until the global event loop
92         executes the configuration update, this method does (almost) the
93         same without the reschedules.
94 
95         Do not use this method until there is absolutely no other way.
96     */
97     void RequestSynchronousUpdate (void);
98 
99     // XConfigurationController
100 
101     virtual void SAL_CALL lock (void)
102         throw (css::uno::RuntimeException);
103 
104     virtual void SAL_CALL unlock (void)
105         throw (css::uno::RuntimeException);
106 
107     virtual void SAL_CALL requestResourceActivation (
108         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
109         css::drawing::framework::ResourceActivationMode eMode)
110         throw (css::uno::RuntimeException);
111 
112     virtual void SAL_CALL requestResourceDeactivation (
113         const css::uno::Reference<css::drawing::framework::XResourceId>&
114             rxResourceId)
115         throw (css::uno::RuntimeException);
116 
117     virtual css::uno::Reference<css::drawing::framework::XResource>
118         SAL_CALL getResource (
119             const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId)
120         throw (css::uno::RuntimeException);
121 
122     virtual void SAL_CALL update (void)
123         throw (css::uno::RuntimeException);
124 
125     virtual  css::uno::Reference<
126         css::drawing::framework::XConfiguration>
127         SAL_CALL getRequestedConfiguration (void)
128         throw (css::uno::RuntimeException);
129 
130     virtual  css::uno::Reference<
131         css::drawing::framework::XConfiguration>
132         SAL_CALL getCurrentConfiguration (void)
133         throw (css::uno::RuntimeException);
134 
135     virtual void SAL_CALL restoreConfiguration (
136         const css::uno::Reference<css::drawing::framework::XConfiguration>&
137         rxConfiguration)
138         throw (css::uno::RuntimeException);
139 
140 
141     // XConfigurationControllerBroadcaster
142 
143     virtual void SAL_CALL addConfigurationChangeListener (
144         const css::uno::Reference<
145             css::drawing::framework::XConfigurationChangeListener>& rxListener,
146         const ::rtl::OUString& rsEventType,
147         const css::uno::Any& rUserData)
148         throw (css::uno::RuntimeException);
149 
150     virtual void SAL_CALL removeConfigurationChangeListener (
151         const css::uno::Reference<
152             css::drawing::framework::XConfigurationChangeListener>& rxListener)
153         throw (css::uno::RuntimeException);
154 
155     virtual void SAL_CALL notifyEvent (
156         const css::drawing::framework::ConfigurationChangeEvent& rEvent)
157         throw (css::uno::RuntimeException);
158 
159 
160     // XConfigurationRequestQueue
161 
162     virtual sal_Bool SAL_CALL hasPendingRequests (void)
163         throw (css::uno::RuntimeException);
164 
165     virtual void SAL_CALL postChangeRequest (
166         const css::uno::Reference<
167             css::drawing::framework::XConfigurationChangeRequest>& rxRequest)
168         throw (css::uno::RuntimeException);
169 
170 
171     // XResourceFactoryManager
172 
173     virtual void SAL_CALL addResourceFactory(
174         const ::rtl::OUString& sResourceURL,
175         const css::uno::Reference<css::drawing::framework::XResourceFactory>& rxResourceFactory)
176         throw (css::uno::RuntimeException);
177 
178     virtual void SAL_CALL removeResourceFactoryForURL(
179         const ::rtl::OUString& sResourceURL)
180         throw (css::uno::RuntimeException);
181 
182     virtual void SAL_CALL removeResourceFactoryForReference(
183         const css::uno::Reference<css::drawing::framework::XResourceFactory>& rxResourceFactory)
184         throw (css::uno::RuntimeException);
185 
186     virtual css::uno::Reference<css::drawing::framework::XResourceFactory>
187         SAL_CALL getResourceFactory (
188         const ::rtl::OUString& sResourceURL)
189         throw (css::uno::RuntimeException);
190 
191 
192     // XInitialization
193 
194     virtual void SAL_CALL initialize(
195         const css::uno::Sequence<css::uno::Any>& rArguments)
196         throw (css::uno::Exception, css::uno::RuntimeException);
197 
198 
199     /** Use this class instead of calling lock() and unlock() directly in
200         order to be exception safe.
201     */
202     class Lock
203     {
204     public:
205         Lock (const css::uno::Reference<
206             css::drawing::framework::XConfigurationController>& rxController);
207         ~Lock (void);
208     private:
209         css::uno::Reference<
210             css::drawing::framework::XConfigurationController> mxController;
211     };
212 
213 private:
214     class Implementation;
215     ::boost::scoped_ptr<Implementation> mpImplementation;
216     bool mbIsDisposed;
217 
218     /** When the called object has already been disposed this method throws
219         an exception and does not return.
220     */
221     void ThrowIfDisposed (void) const
222         throw (css::lang::DisposedException);
223 };
224 
225 } } // end of namespace sd::framework
226 
227 #endif
228