Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
5 : : * This Source Code Form is subject to the terms of the Mozilla Public
6 : : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
11 : : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : : * contributor license agreements. See the NOTICE file distributed
13 : : * with this work for additional information regarding copyright
14 : : * ownership. The ASF licenses this file to you under the Apache
15 : : * License, Version 2.0 (the "License"); you may not use this file
16 : : * except in compliance with the License. You may obtain a copy of
17 : : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : : */
19 : :
20 : :
21 : : #include "ResourceManager.hxx"
22 : :
23 : : #include "framework/FrameworkHelper.hxx"
24 : : #include "framework/ConfigurationController.hxx"
25 : : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
26 : :
27 : : #include <comphelper/stl_types.hxx>
28 : : #include <set>
29 : :
30 : : using namespace ::com::sun::star;
31 : : using namespace ::com::sun::star::uno;
32 : : using namespace ::com::sun::star::drawing::framework;
33 : :
34 : : using ::rtl::OUString;
35 : : using ::sd::framework::FrameworkHelper;
36 : :
37 : : namespace {
38 : : static const sal_Int32 ResourceActivationRequestEvent = 0;
39 : : static const sal_Int32 ResourceDeactivationRequestEvent = 1;
40 : : }
41 : :
42 : :
43 : :
44 : :
45 : : namespace sd { namespace framework {
46 : :
47 : 156 : class ResourceManager::MainViewContainer
48 : : : public ::std::set<OUString, ::comphelper::UStringLess>
49 : : {
50 : : public:
51 : 156 : MainViewContainer (void) {}
52 : : };
53 : :
54 : :
55 : :
56 : :
57 : : //===== ResourceManager =======================================================
58 : :
59 : 156 : ResourceManager::ResourceManager (
60 : : const Reference<frame::XController>& rxController,
61 : : const Reference<XResourceId>& rxResourceId)
62 : : : ResourceManagerInterfaceBase(MutexOwner::maMutex),
63 : : mxConfigurationController(),
64 : 0 : mpActiveMainViewContainer(new MainViewContainer()),
65 : : mxResourceId(rxResourceId),
66 [ + - ][ + - ]: 312 : mxMainViewAnchorId(FrameworkHelper::Instance(rxController)->CreateResourceId(
67 : : FrameworkHelper::msCenterPaneURL)),
68 : : msCurrentMainViewURL(),
69 [ + - ][ + - ]: 468 : mbIsEnabled(true)
[ + - ]
70 : : {
71 [ + - ]: 156 : Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
72 [ + - ]: 156 : if (xControllerManager.is())
73 : : {
74 [ + - ][ + - ]: 156 : mxConfigurationController = xControllerManager->getConfigurationController();
[ + - ]
75 : :
76 [ + - ]: 156 : if (mxConfigurationController.is())
77 : : {
78 : : uno::Reference<lang::XComponent> const xComppnent(
79 [ + - ]: 156 : mxConfigurationController, UNO_QUERY_THROW);
80 [ + - ][ + - ]: 156 : xComppnent->addEventListener(this);
[ + - ]
81 [ + - ]: 156 : mxConfigurationController->addConfigurationChangeListener(
82 : : this,
83 : : FrameworkHelper::msResourceActivationRequestEvent,
84 [ + - ][ + - ]: 156 : makeAny(ResourceActivationRequestEvent));
[ + - ]
85 [ + - ]: 156 : mxConfigurationController->addConfigurationChangeListener(
86 : : this,
87 : : FrameworkHelper::msResourceDeactivationRequestEvent,
88 [ + - ][ + - ]: 156 : makeAny(ResourceDeactivationRequestEvent));
[ + - ]
89 : : }
90 : 156 : }
91 : 156 : }
92 : :
93 : :
94 : :
95 : :
96 [ + - ][ + - ]: 156 : ResourceManager::~ResourceManager (void)
97 : : {
98 [ - + ]: 182 : }
99 : :
100 : :
101 : :
102 : :
103 : 624 : void ResourceManager::AddActiveMainView (
104 : : const OUString& rsMainViewURL)
105 : : {
106 : 624 : mpActiveMainViewContainer->insert(rsMainViewURL);
107 : 624 : }
108 : :
109 : 780 : sal_Bool ResourceManager::IsResourceActive (
110 : : const OUString& rsMainViewURL)
111 : : {
112 [ + - ]: 780 : return (mpActiveMainViewContainer->find(rsMainViewURL) != mpActiveMainViewContainer->end());
113 : : }
114 : :
115 : 26 : void ResourceManager::SaveResourceState (void)
116 : : {
117 : 26 : }
118 : :
119 : 156 : void SAL_CALL ResourceManager::disposing (void)
120 : : {
121 [ - + ]: 156 : if (mxConfigurationController.is())
122 : : {
123 [ # # ]: 0 : mxConfigurationController->removeConfigurationChangeListener(this);
124 : 0 : mxConfigurationController = NULL;
125 : : }
126 : 156 : }
127 : :
128 : :
129 : :
130 : :
131 : 39 : void ResourceManager::Enable (void)
132 : : {
133 : 39 : mbIsEnabled = true;
134 : 39 : UpdateForMainViewShell();
135 : 39 : }
136 : :
137 : :
138 : :
139 : :
140 : 0 : void ResourceManager::Disable (void)
141 : : {
142 : 0 : mbIsEnabled = false;
143 : 0 : UpdateForMainViewShell();
144 : 0 : }
145 : :
146 : :
147 : :
148 : :
149 : 1648 : void SAL_CALL ResourceManager::notifyConfigurationChange (
150 : : const ConfigurationChangeEvent& rEvent)
151 : : throw (RuntimeException)
152 : : {
153 : : OSL_ASSERT(rEvent.ResourceId.is());
154 : :
155 : 1648 : sal_Int32 nEventType = 0;
156 : 1648 : rEvent.UserData >>= nEventType;
157 [ + + - ]: 1648 : switch (nEventType)
158 : : {
159 : : case ResourceActivationRequestEvent:
160 [ + - ][ + + ]: 1648 : if (rEvent.ResourceId->isBoundToURL(
161 : : FrameworkHelper::msCenterPaneURL,
162 [ + - ]: 824 : AnchorBindingMode_DIRECT))
163 : : {
164 : : // A resource directly bound to the center pane has been
165 : : // requested.
166 [ + - + + ]: 416 : if (rEvent.ResourceId->getResourceTypePrefix().equals(
167 [ + - ]: 208 : FrameworkHelper::msViewURLPrefix))
168 : : {
169 : : // The requested resource is a view. Show or hide the
170 : : // resource managed by this ResourceManager accordingly.
171 : : HandleMainViewSwitch(
172 [ + - ]: 156 : rEvent.ResourceId->getResourceURL(),
173 : : rEvent.Configuration,
174 [ + - ][ + - ]: 156 : true);
175 : : }
176 : : }
177 [ + - ][ + - ]: 616 : else if (rEvent.ResourceId->compareTo(mxResourceId) == 0)
[ + + ]
178 : : {
179 : : // The resource managed by this ResourceManager has been
180 : : // explicitly been requested (maybe by us). Remember this
181 : : // setting.
182 [ + - ]: 156 : HandleResourceRequest(true, rEvent.Configuration);
183 : : }
184 : 824 : break;
185 : :
186 : : case ResourceDeactivationRequestEvent:
187 [ + - ][ + - ]: 824 : if (rEvent.ResourceId->compareTo(mxMainViewAnchorId) == 0)
[ + + ]
188 : : {
189 : : HandleMainViewSwitch(
190 : : OUString(),
191 : : rEvent.Configuration,
192 [ + - ]: 156 : false);
193 : : }
194 [ + - ][ + - ]: 668 : else if (rEvent.ResourceId->compareTo(mxResourceId) == 0)
[ + + ]
195 : : {
196 : : // The resource managed by this ResourceManager has been
197 : : // explicitly been requested to be hidden (maybe by us).
198 : : // Remember this setting.
199 [ + - ]: 156 : HandleResourceRequest(false, rEvent.Configuration);
200 : : }
201 : 824 : break;
202 : : }
203 : 1648 : }
204 : :
205 : :
206 : :
207 : :
208 : 351 : void ResourceManager::UpdateForMainViewShell (void)
209 : : {
210 [ + + ]: 351 : if (mxConfigurationController.is())
211 : : {
212 [ + - ]: 195 : ConfigurationController::Lock aLock (mxConfigurationController);
213 : :
214 [ + - + - ]: 585 : if (mbIsEnabled
[ + - ]
215 : 195 : && mpActiveMainViewContainer->find(msCurrentMainViewURL)
216 [ + - ][ + - ]: 585 : != mpActiveMainViewContainer->end())
[ + - ]
[ # # # # ]
217 : : {
218 : : // Activate resource.
219 [ + - ]: 195 : mxConfigurationController->requestResourceActivation(
220 [ + - ]: 195 : mxResourceId->getAnchor(),
221 [ + - ][ + - ]: 195 : ResourceActivationMode_ADD);
222 [ + - ]: 195 : mxConfigurationController->requestResourceActivation(
223 : : mxResourceId,
224 [ + - ]: 195 : ResourceActivationMode_REPLACE);
225 : : }
226 : : else
227 : : {
228 [ # # ][ # # ]: 0 : mxConfigurationController->requestResourceDeactivation(mxResourceId);
229 [ + - ]: 195 : }
230 : : }
231 : 351 : }
232 : :
233 : :
234 : :
235 : :
236 : 312 : void ResourceManager::HandleMainViewSwitch (
237 : : const OUString& rsViewURL,
238 : : const Reference<XConfiguration>& rxConfiguration,
239 : : const bool bIsActivated)
240 : : {
241 : : (void)rxConfiguration;
242 [ + + ]: 312 : if (bIsActivated)
243 : 156 : msCurrentMainViewURL = rsViewURL;
244 : : else
245 : 156 : msCurrentMainViewURL = OUString();
246 : 312 : UpdateForMainViewShell();
247 : 312 : }
248 : :
249 : :
250 : :
251 : :
252 : 312 : void ResourceManager::HandleResourceRequest(
253 : : bool bActivation,
254 : : const Reference<XConfiguration>& rxConfiguration)
255 : : {
256 [ + - ]: 312 : if (mbIsEnabled)
257 : : {
258 [ + - ]: 312 : Sequence<Reference<XResourceId> > aCenterViews = rxConfiguration->getResources(
259 : : FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
260 : : FrameworkHelper::msViewURLPrefix,
261 [ + - ][ + - ]: 312 : AnchorBindingMode_DIRECT);
262 [ + - ]: 312 : if (aCenterViews.getLength() == 1)
263 : : {
264 [ + + ]: 312 : if (bActivation)
265 : : {
266 [ + - ][ + - ]: 156 : mpActiveMainViewContainer->insert(aCenterViews[0]->getResourceURL());
[ + - ][ + - ]
267 : : }
268 : : else
269 : : {
270 : : MainViewContainer::iterator iElement (
271 [ + - ][ + - ]: 156 : mpActiveMainViewContainer->find(aCenterViews[0]->getResourceURL()));
[ + - ][ + - ]
272 [ + - ]: 156 : if (iElement != mpActiveMainViewContainer->end())
273 [ + - ]: 156 : mpActiveMainViewContainer->erase(iElement);
274 : : }
275 [ + - ]: 312 : }
276 : : }
277 : 312 : }
278 : :
279 : :
280 : :
281 : :
282 : 416 : void SAL_CALL ResourceManager::disposing (
283 : : const lang::EventObject& rEvent)
284 : : throw (RuntimeException)
285 : : {
286 [ + + + - ]: 572 : if (mxConfigurationController.is()
[ + + ]
287 : 156 : && rEvent.Source == mxConfigurationController)
288 : : {
289 : 156 : SaveResourceState();
290 : : // Without the configuration controller this class can do nothing.
291 : 156 : mxConfigurationController = NULL;
292 : 156 : dispose();
293 : : }
294 : 416 : }
295 : :
296 : : } } // end of namespace sd::framework
297 : :
298 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|