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