1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ResourceManager.cxx,v $
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>
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
;
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
>
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(),
83 Reference
<XControllerManager
> xControllerManager (rxController
, UNO_QUERY
);
84 if (xControllerManager
.is())
86 mxConfigurationController
= xControllerManager
->getConfigurationController();
88 if (mxConfigurationController
.is())
90 mxConfigurationController
->addConfigurationChangeListener(
92 FrameworkHelper::msResourceActivationRequestEvent
,
93 makeAny(ResourceActivationRequestEvent
));
94 mxConfigurationController
->addConfigurationChangeListener(
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)
136 UpdateForMainViewShell();
142 void ResourceManager::Disable (void)
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
;
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
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
,
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
184 HandleResourceRequest(true, rEvent
.Configuration
);
188 case ResourceDeactivationRequestEvent
:
189 if (rEvent
.ResourceId
->compareTo(mxMainViewAnchorId
) == 0)
191 HandleMainViewSwitch(
193 rEvent
.Configuration
,
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
);
210 void ResourceManager::UpdateForMainViewShell (void)
212 if (mxConfigurationController
.is())
214 ConfigurationController::Lock
aLock (mxConfigurationController
);
217 && mpActiveMainViewContainer
->find(msCurrentMainViewURL
)
218 != mpActiveMainViewContainer
->end())
220 // Activate resource.
221 mxConfigurationController
->requestResourceActivation(
222 mxResourceId
->getAnchor(),
223 ResourceActivationMode_ADD
);
224 mxConfigurationController
->requestResourceActivation(
226 ResourceActivationMode_REPLACE
);
230 mxConfigurationController
->requestResourceDeactivation(mxResourceId
);
238 void ResourceManager::HandleMainViewSwitch (
239 const OUString
& rsViewURL
,
240 const Reference
<XConfiguration
>& rxConfiguration
,
241 const bool bIsActivated
)
243 (void)rxConfiguration
;
245 msCurrentMainViewURL
= rsViewURL
;
247 msCurrentMainViewURL
= OUString();
248 UpdateForMainViewShell();
254 void ResourceManager::HandleResourceRequest(
256 const Reference
<XConfiguration
>& rxConfiguration
)
260 Sequence
<Reference
<XResourceId
> > aCenterViews
= rxConfiguration
->getResources(
261 FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL
),
262 FrameworkHelper::msViewURLPrefix
,
263 AnchorBindingMode_DIRECT
);
264 if (aCenterViews
.getLength() == 1)
268 mpActiveMainViewContainer
->insert(aCenterViews
[0]->getResourceURL());
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
;
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();
312 ::rtl::OUStringToOString(*iDescriptor
, RTL_TEXTENCODING_UTF8
).getStr());
318 } } // end of namespace sd::framework