1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
21 #include "ResourceManager.hxx"
23 #include "framework/FrameworkHelper.hxx"
24 #include "framework/ConfigurationController.hxx"
25 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
27 #include <comphelper/stl_types.hxx>
30 using namespace ::com::sun::star
;
31 using namespace ::com::sun::star::uno
;
32 using namespace ::com::sun::star::drawing::framework
;
34 using ::sd::framework::FrameworkHelper
;
37 static const sal_Int32 ResourceActivationRequestEvent
= 0;
38 static const sal_Int32 ResourceDeactivationRequestEvent
= 1;
44 namespace sd
{ namespace framework
{
46 class ResourceManager::MainViewContainer
47 : public ::std::set
<OUString
, ::comphelper::UStringLess
>
50 MainViewContainer (void) {}
56 //===== ResourceManager =======================================================
58 ResourceManager::ResourceManager (
59 const Reference
<frame::XController
>& rxController
,
60 const Reference
<XResourceId
>& rxResourceId
)
61 : ResourceManagerInterfaceBase(MutexOwner::maMutex
),
62 mxConfigurationController(),
63 mpActiveMainViewContainer(new MainViewContainer()),
64 mxResourceId(rxResourceId
),
65 mxMainViewAnchorId(FrameworkHelper::Instance(rxController
)->CreateResourceId(
66 FrameworkHelper::msCenterPaneURL
)),
67 msCurrentMainViewURL()
69 Reference
<XControllerManager
> xControllerManager (rxController
, UNO_QUERY
);
70 if (xControllerManager
.is())
72 mxConfigurationController
= xControllerManager
->getConfigurationController();
74 if (mxConfigurationController
.is())
76 uno::Reference
<lang::XComponent
> const xComppnent(
77 mxConfigurationController
, UNO_QUERY_THROW
);
78 xComppnent
->addEventListener(this);
79 mxConfigurationController
->addConfigurationChangeListener(
81 FrameworkHelper::msResourceActivationRequestEvent
,
82 makeAny(ResourceActivationRequestEvent
));
83 mxConfigurationController
->addConfigurationChangeListener(
85 FrameworkHelper::msResourceDeactivationRequestEvent
,
86 makeAny(ResourceDeactivationRequestEvent
));
94 ResourceManager::~ResourceManager (void)
101 void ResourceManager::AddActiveMainView (
102 const OUString
& rsMainViewURL
)
104 mpActiveMainViewContainer
->insert(rsMainViewURL
);
107 sal_Bool
ResourceManager::IsResourceActive (
108 const OUString
& rsMainViewURL
)
110 return (mpActiveMainViewContainer
->find(rsMainViewURL
) != mpActiveMainViewContainer
->end());
113 void ResourceManager::SaveResourceState (void)
117 void SAL_CALL
ResourceManager::disposing (void)
119 if (mxConfigurationController
.is())
121 mxConfigurationController
->removeConfigurationChangeListener(this);
122 mxConfigurationController
= NULL
;
126 void SAL_CALL
ResourceManager::notifyConfigurationChange (
127 const ConfigurationChangeEvent
& rEvent
)
128 throw (RuntimeException
)
130 OSL_ASSERT(rEvent
.ResourceId
.is());
132 sal_Int32 nEventType
= 0;
133 rEvent
.UserData
>>= nEventType
;
136 case ResourceActivationRequestEvent
:
137 if (rEvent
.ResourceId
->isBoundToURL(
138 FrameworkHelper::msCenterPaneURL
,
139 AnchorBindingMode_DIRECT
))
141 // A resource directly bound to the center pane has been
143 if (rEvent
.ResourceId
->getResourceTypePrefix().equals(
144 FrameworkHelper::msViewURLPrefix
))
146 // The requested resource is a view. Show or hide the
147 // resource managed by this ResourceManager accordingly.
148 HandleMainViewSwitch(
149 rEvent
.ResourceId
->getResourceURL(),
150 rEvent
.Configuration
,
154 else if (rEvent
.ResourceId
->compareTo(mxResourceId
) == 0)
156 // The resource managed by this ResourceManager has been
157 // explicitly been requested (maybe by us). Remember this
159 HandleResourceRequest(true, rEvent
.Configuration
);
163 case ResourceDeactivationRequestEvent
:
164 if (rEvent
.ResourceId
->compareTo(mxMainViewAnchorId
) == 0)
166 HandleMainViewSwitch(
168 rEvent
.Configuration
,
171 else if (rEvent
.ResourceId
->compareTo(mxResourceId
) == 0)
173 // The resource managed by this ResourceManager has been
174 // explicitly been requested to be hidden (maybe by us).
175 // Remember this setting.
176 HandleResourceRequest(false, rEvent
.Configuration
);
185 void ResourceManager::UpdateForMainViewShell (void)
187 if (mxConfigurationController
.is())
189 ConfigurationController::Lock
aLock (mxConfigurationController
);
191 if (mpActiveMainViewContainer
->find(msCurrentMainViewURL
)
192 != mpActiveMainViewContainer
->end())
194 // Activate resource.
195 mxConfigurationController
->requestResourceActivation(
196 mxResourceId
->getAnchor(),
197 ResourceActivationMode_ADD
);
198 mxConfigurationController
->requestResourceActivation(
200 ResourceActivationMode_REPLACE
);
204 mxConfigurationController
->requestResourceDeactivation(mxResourceId
);
212 void ResourceManager::HandleMainViewSwitch (
213 const OUString
& rsViewURL
,
214 const Reference
<XConfiguration
>& rxConfiguration
,
215 const bool bIsActivated
)
217 (void)rxConfiguration
;
219 msCurrentMainViewURL
= rsViewURL
;
221 msCurrentMainViewURL
= OUString();
222 UpdateForMainViewShell();
228 void ResourceManager::HandleResourceRequest(
230 const Reference
<XConfiguration
>& rxConfiguration
)
232 Sequence
<Reference
<XResourceId
> > aCenterViews
= rxConfiguration
->getResources(
233 FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL
),
234 FrameworkHelper::msViewURLPrefix
,
235 AnchorBindingMode_DIRECT
);
236 if (aCenterViews
.getLength() == 1)
240 mpActiveMainViewContainer
->insert(aCenterViews
[0]->getResourceURL());
244 MainViewContainer::iterator
iElement (
245 mpActiveMainViewContainer
->find(aCenterViews
[0]->getResourceURL()));
246 if (iElement
!= mpActiveMainViewContainer
->end())
247 mpActiveMainViewContainer
->erase(iElement
);
255 void SAL_CALL
ResourceManager::disposing (
256 const lang::EventObject
& rEvent
)
257 throw (RuntimeException
)
259 if (mxConfigurationController
.is()
260 && rEvent
.Source
== mxConfigurationController
)
263 // Without the configuration controller this class can do nothing.
264 mxConfigurationController
= NULL
;
269 } } // end of namespace sd::framework
271 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */