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 ::sd::framework::FrameworkHelper;
35 :
36 : namespace {
37 : static const sal_Int32 ResourceActivationRequestEvent = 0;
38 : static const sal_Int32 ResourceDeactivationRequestEvent = 1;
39 : }
40 :
41 :
42 :
43 :
44 : namespace sd { namespace framework {
45 :
46 78 : class ResourceManager::MainViewContainer
47 : : public ::std::set<OUString, ::comphelper::UStringLess>
48 : {
49 : public:
50 78 : MainViewContainer (void) {}
51 : };
52 :
53 :
54 :
55 :
56 : //===== ResourceManager =======================================================
57 :
58 78 : ResourceManager::ResourceManager (
59 : const Reference<frame::XController>& rxController,
60 : const Reference<XResourceId>& rxResourceId)
61 : : ResourceManagerInterfaceBase(MutexOwner::maMutex),
62 : mxConfigurationController(),
63 0 : mpActiveMainViewContainer(new MainViewContainer()),
64 : mxResourceId(rxResourceId),
65 156 : mxMainViewAnchorId(FrameworkHelper::Instance(rxController)->CreateResourceId(
66 : FrameworkHelper::msCenterPaneURL)),
67 234 : msCurrentMainViewURL()
68 : {
69 78 : Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
70 78 : if (xControllerManager.is())
71 : {
72 78 : mxConfigurationController = xControllerManager->getConfigurationController();
73 :
74 78 : if (mxConfigurationController.is())
75 : {
76 : uno::Reference<lang::XComponent> const xComppnent(
77 78 : mxConfigurationController, UNO_QUERY_THROW);
78 78 : xComppnent->addEventListener(this);
79 78 : mxConfigurationController->addConfigurationChangeListener(
80 : this,
81 : FrameworkHelper::msResourceActivationRequestEvent,
82 78 : makeAny(ResourceActivationRequestEvent));
83 78 : mxConfigurationController->addConfigurationChangeListener(
84 : this,
85 : FrameworkHelper::msResourceDeactivationRequestEvent,
86 78 : makeAny(ResourceDeactivationRequestEvent));
87 : }
88 78 : }
89 78 : }
90 :
91 :
92 :
93 :
94 78 : ResourceManager::~ResourceManager (void)
95 : {
96 78 : }
97 :
98 :
99 :
100 :
101 312 : void ResourceManager::AddActiveMainView (
102 : const OUString& rsMainViewURL)
103 : {
104 312 : mpActiveMainViewContainer->insert(rsMainViewURL);
105 312 : }
106 :
107 455 : sal_Bool ResourceManager::IsResourceActive (
108 : const OUString& rsMainViewURL)
109 : {
110 455 : return (mpActiveMainViewContainer->find(rsMainViewURL) != mpActiveMainViewContainer->end());
111 : }
112 :
113 0 : void ResourceManager::SaveResourceState (void)
114 : {
115 0 : }
116 :
117 78 : void SAL_CALL ResourceManager::disposing (void)
118 : {
119 78 : if (mxConfigurationController.is())
120 : {
121 0 : mxConfigurationController->removeConfigurationChangeListener(this);
122 0 : mxConfigurationController = NULL;
123 : }
124 78 : }
125 :
126 828 : void SAL_CALL ResourceManager::notifyConfigurationChange (
127 : const ConfigurationChangeEvent& rEvent)
128 : throw (RuntimeException)
129 : {
130 : OSL_ASSERT(rEvent.ResourceId.is());
131 :
132 828 : sal_Int32 nEventType = 0;
133 828 : rEvent.UserData >>= nEventType;
134 828 : switch (nEventType)
135 : {
136 : case ResourceActivationRequestEvent:
137 828 : if (rEvent.ResourceId->isBoundToURL(
138 : FrameworkHelper::msCenterPaneURL,
139 414 : AnchorBindingMode_DIRECT))
140 : {
141 : // A resource directly bound to the center pane has been
142 : // requested.
143 312 : if (rEvent.ResourceId->getResourceTypePrefix().equals(
144 208 : FrameworkHelper::msViewURLPrefix))
145 : {
146 : // The requested resource is a view. Show or hide the
147 : // resource managed by this ResourceManager accordingly.
148 : HandleMainViewSwitch(
149 78 : rEvent.ResourceId->getResourceURL(),
150 : rEvent.Configuration,
151 156 : true);
152 : }
153 : }
154 310 : else if (rEvent.ResourceId->compareTo(mxResourceId) == 0)
155 : {
156 : // The resource managed by this ResourceManager has been
157 : // explicitly been requested (maybe by us). Remember this
158 : // setting.
159 78 : HandleResourceRequest(true, rEvent.Configuration);
160 : }
161 414 : break;
162 :
163 : case ResourceDeactivationRequestEvent:
164 414 : if (rEvent.ResourceId->compareTo(mxMainViewAnchorId) == 0)
165 : {
166 : HandleMainViewSwitch(
167 : OUString(),
168 : rEvent.Configuration,
169 78 : false);
170 : }
171 336 : else if (rEvent.ResourceId->compareTo(mxResourceId) == 0)
172 : {
173 : // The resource managed by this ResourceManager has been
174 : // explicitly been requested to be hidden (maybe by us).
175 : // Remember this setting.
176 78 : HandleResourceRequest(false, rEvent.Configuration);
177 : }
178 414 : break;
179 : }
180 828 : }
181 :
182 :
183 :
184 :
185 156 : void ResourceManager::UpdateForMainViewShell (void)
186 : {
187 156 : if (mxConfigurationController.is())
188 : {
189 78 : ConfigurationController::Lock aLock (mxConfigurationController);
190 :
191 234 : if (mpActiveMainViewContainer->find(msCurrentMainViewURL)
192 234 : != mpActiveMainViewContainer->end())
193 : {
194 : // Activate resource.
195 78 : mxConfigurationController->requestResourceActivation(
196 78 : mxResourceId->getAnchor(),
197 156 : ResourceActivationMode_ADD);
198 78 : mxConfigurationController->requestResourceActivation(
199 : mxResourceId,
200 78 : ResourceActivationMode_REPLACE);
201 : }
202 : else
203 : {
204 0 : mxConfigurationController->requestResourceDeactivation(mxResourceId);
205 78 : }
206 : }
207 156 : }
208 :
209 :
210 :
211 :
212 156 : void ResourceManager::HandleMainViewSwitch (
213 : const OUString& rsViewURL,
214 : const Reference<XConfiguration>& rxConfiguration,
215 : const bool bIsActivated)
216 : {
217 : (void)rxConfiguration;
218 156 : if (bIsActivated)
219 78 : msCurrentMainViewURL = rsViewURL;
220 : else
221 78 : msCurrentMainViewURL = OUString();
222 156 : UpdateForMainViewShell();
223 156 : }
224 :
225 :
226 :
227 :
228 156 : void ResourceManager::HandleResourceRequest(
229 : bool bActivation,
230 : const Reference<XConfiguration>& rxConfiguration)
231 : {
232 156 : Sequence<Reference<XResourceId> > aCenterViews = rxConfiguration->getResources(
233 : FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
234 : FrameworkHelper::msViewURLPrefix,
235 156 : AnchorBindingMode_DIRECT);
236 156 : if (aCenterViews.getLength() == 1)
237 : {
238 156 : if (bActivation)
239 : {
240 78 : mpActiveMainViewContainer->insert(aCenterViews[0]->getResourceURL());
241 : }
242 : else
243 : {
244 : MainViewContainer::iterator iElement (
245 78 : mpActiveMainViewContainer->find(aCenterViews[0]->getResourceURL()));
246 78 : if (iElement != mpActiveMainViewContainer->end())
247 78 : mpActiveMainViewContainer->erase(iElement);
248 : }
249 156 : }
250 156 : }
251 :
252 :
253 :
254 :
255 208 : void SAL_CALL ResourceManager::disposing (
256 : const lang::EventObject& rEvent)
257 : throw (RuntimeException)
258 : {
259 416 : if (mxConfigurationController.is()
260 208 : && rEvent.Source == mxConfigurationController)
261 : {
262 78 : SaveResourceState();
263 : // Without the configuration controller this class can do nothing.
264 78 : mxConfigurationController = NULL;
265 78 : dispose();
266 : }
267 208 : }
268 :
269 33 : } } // end of namespace sd::framework
270 :
271 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|