Update ooo320-m1
[ooovba.git] / sd / source / ui / framework / module / ResourceManager.cxx
blob21bf933d95c3fc8c95bf51e204d12971af887b52
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ResourceManager.cxx,v $
10 * $Revision: 1.5 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 #include "precompiled_sd.hxx"
33 #include "ResourceManager.hxx"
35 #include "framework/FrameworkHelper.hxx"
36 #include "framework/ConfigurationController.hxx"
37 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
39 #include <comphelper/stl_types.hxx>
40 #include <set>
42 using namespace ::com::sun::star;
43 using namespace ::com::sun::star::uno;
44 using namespace ::com::sun::star::drawing::framework;
46 using ::rtl::OUString;
47 using ::sd::framework::FrameworkHelper;
49 namespace {
50 static const sal_Int32 ResourceActivationRequestEvent = 0;
51 static const sal_Int32 ResourceDeactivationRequestEvent = 1;
57 namespace sd { namespace framework {
59 class ResourceManager::MainViewContainer
60 : public ::std::set<OUString, ::comphelper::UStringLess>
62 public:
63 MainViewContainer (void) {}
69 //===== ResourceManager =======================================================
71 ResourceManager::ResourceManager (
72 const Reference<frame::XController>& rxController,
73 const Reference<XResourceId>& rxResourceId)
74 : ResourceManagerInterfaceBase(MutexOwner::maMutex),
75 mxConfigurationController(),
76 mpActiveMainViewContainer(new MainViewContainer()),
77 mxResourceId(rxResourceId),
78 mxMainViewAnchorId(FrameworkHelper::Instance(rxController)->CreateResourceId(
79 FrameworkHelper::msCenterPaneURL)),
80 msCurrentMainViewURL(),
81 mbIsEnabled(true)
83 Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
84 if (xControllerManager.is())
86 mxConfigurationController = xControllerManager->getConfigurationController();
88 if (mxConfigurationController.is())
90 mxConfigurationController->addConfigurationChangeListener(
91 this,
92 FrameworkHelper::msResourceActivationRequestEvent,
93 makeAny(ResourceActivationRequestEvent));
94 mxConfigurationController->addConfigurationChangeListener(
95 this,
96 FrameworkHelper::msResourceDeactivationRequestEvent,
97 makeAny(ResourceDeactivationRequestEvent));
105 ResourceManager::~ResourceManager (void)
112 void ResourceManager::AddActiveMainView (
113 const OUString& rsMainViewURL)
115 mpActiveMainViewContainer->insert(rsMainViewURL);
121 void SAL_CALL ResourceManager::disposing (void)
123 if (mxConfigurationController.is())
125 mxConfigurationController->removeConfigurationChangeListener(this);
126 mxConfigurationController = NULL;
133 void ResourceManager::Enable (void)
135 mbIsEnabled = true;
136 UpdateForMainViewShell();
142 void ResourceManager::Disable (void)
144 mbIsEnabled = false;
145 UpdateForMainViewShell();
151 void SAL_CALL ResourceManager::notifyConfigurationChange (
152 const ConfigurationChangeEvent& rEvent)
153 throw (RuntimeException)
155 OSL_ASSERT(rEvent.ResourceId.is());
157 sal_Int32 nEventType = 0;
158 rEvent.UserData >>= nEventType;
159 switch (nEventType)
161 case ResourceActivationRequestEvent:
162 if (rEvent.ResourceId->isBoundToURL(
163 FrameworkHelper::msCenterPaneURL,
164 AnchorBindingMode_DIRECT))
166 // A resource directly bound to the center pane has been
167 // requested.
168 if (rEvent.ResourceId->getResourceTypePrefix().equals(
169 FrameworkHelper::msViewURLPrefix))
171 // The requested resource is a view. Show or hide the
172 // resource managed by this ResourceManager accordingly.
173 HandleMainViewSwitch(
174 rEvent.ResourceId->getResourceURL(),
175 rEvent.Configuration,
176 true);
179 else if (rEvent.ResourceId->compareTo(mxResourceId) == 0)
181 // The resource managed by this ResourceManager has been
182 // explicitly been requested (maybe by us). Remember this
183 // setting.
184 HandleResourceRequest(true, rEvent.Configuration);
186 break;
188 case ResourceDeactivationRequestEvent:
189 if (rEvent.ResourceId->compareTo(mxMainViewAnchorId) == 0)
191 HandleMainViewSwitch(
192 OUString(),
193 rEvent.Configuration,
194 false);
196 else if (rEvent.ResourceId->compareTo(mxResourceId) == 0)
198 // The resource managed by this ResourceManager has been
199 // explicitly been requested to be hidden (maybe by us).
200 // Remember this setting.
201 HandleResourceRequest(false, rEvent.Configuration);
203 break;
210 void ResourceManager::UpdateForMainViewShell (void)
212 if (mxConfigurationController.is())
214 ConfigurationController::Lock aLock (mxConfigurationController);
216 if (mbIsEnabled
217 && mpActiveMainViewContainer->find(msCurrentMainViewURL)
218 != mpActiveMainViewContainer->end())
220 // Activate resource.
221 mxConfigurationController->requestResourceActivation(
222 mxResourceId->getAnchor(),
223 ResourceActivationMode_ADD);
224 mxConfigurationController->requestResourceActivation(
225 mxResourceId,
226 ResourceActivationMode_REPLACE);
228 else
230 mxConfigurationController->requestResourceDeactivation(mxResourceId);
238 void ResourceManager::HandleMainViewSwitch (
239 const OUString& rsViewURL,
240 const Reference<XConfiguration>& rxConfiguration,
241 const bool bIsActivated)
243 (void)rxConfiguration;
244 if (bIsActivated)
245 msCurrentMainViewURL = rsViewURL;
246 else
247 msCurrentMainViewURL = OUString();
248 UpdateForMainViewShell();
254 void ResourceManager::HandleResourceRequest(
255 bool bActivation,
256 const Reference<XConfiguration>& rxConfiguration)
258 if (mbIsEnabled)
260 Sequence<Reference<XResourceId> > aCenterViews = rxConfiguration->getResources(
261 FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
262 FrameworkHelper::msViewURLPrefix,
263 AnchorBindingMode_DIRECT);
264 if (aCenterViews.getLength() == 1)
266 if (bActivation)
268 mpActiveMainViewContainer->insert(aCenterViews[0]->getResourceURL());
270 else
272 MainViewContainer::iterator iElement (
273 mpActiveMainViewContainer->find(aCenterViews[0]->getResourceURL()));
274 if (iElement != mpActiveMainViewContainer->end())
275 mpActiveMainViewContainer->erase(iElement);
284 void SAL_CALL ResourceManager::disposing (
285 const lang::EventObject& rEvent)
286 throw (RuntimeException)
288 if (mxConfigurationController.is()
289 && rEvent.Source == mxConfigurationController)
291 // Without the configuration controller this class can do nothing.
292 mxConfigurationController = NULL;
293 dispose();
300 void ResourceManager::Trace (void) const
302 OSL_TRACE("main views with resource %s:",
303 ::rtl::OUStringToOString(
304 FrameworkHelper::ResourceIdToString(mxResourceId), RTL_TEXTENCODING_UTF8).getStr());
306 MainViewContainer::const_iterator iDescriptor;
307 for (iDescriptor=mpActiveMainViewContainer->begin();
308 iDescriptor!=mpActiveMainViewContainer->end();
309 ++iDescriptor)
311 OSL_TRACE(" %s",
312 ::rtl::OUStringToOString(*iDescriptor, RTL_TEXTENCODING_UTF8).getStr());
318 } } // end of namespace sd::framework