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 .
20 #include "ResourceManager.hxx"
22 #include "framework/FrameworkHelper.hxx"
23 #include "framework/ConfigurationController.hxx"
24 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
29 using namespace css::uno
;
30 using namespace css::drawing::framework
;
32 using ::sd::framework::FrameworkHelper
;
35 static const sal_Int32 ResourceActivationRequestEvent
= 0;
36 static const sal_Int32 ResourceDeactivationRequestEvent
= 1;
39 namespace sd
{ namespace framework
{
41 class ResourceManager::MainViewContainer
42 : public ::std::set
<OUString
>
45 MainViewContainer() {}
48 //===== ResourceManager =======================================================
50 ResourceManager::ResourceManager (
51 const Reference
<frame::XController
>& rxController
,
52 const Reference
<XResourceId
>& rxResourceId
)
53 : ResourceManagerInterfaceBase(MutexOwner::maMutex
),
54 mxConfigurationController(),
55 mpActiveMainViewContainer(new MainViewContainer()),
56 mxResourceId(rxResourceId
),
57 mxMainViewAnchorId(FrameworkHelper::CreateResourceId(
58 FrameworkHelper::msCenterPaneURL
)),
59 msCurrentMainViewURL()
61 Reference
<XControllerManager
> xControllerManager (rxController
, UNO_QUERY
);
62 if (xControllerManager
.is())
64 mxConfigurationController
= xControllerManager
->getConfigurationController();
66 if (mxConfigurationController
.is())
68 uno::Reference
<lang::XComponent
> const xComppnent(
69 mxConfigurationController
, UNO_QUERY_THROW
);
70 xComppnent
->addEventListener(this);
71 mxConfigurationController
->addConfigurationChangeListener(
73 FrameworkHelper::msResourceActivationRequestEvent
,
74 makeAny(ResourceActivationRequestEvent
));
75 mxConfigurationController
->addConfigurationChangeListener(
77 FrameworkHelper::msResourceDeactivationRequestEvent
,
78 makeAny(ResourceDeactivationRequestEvent
));
83 ResourceManager::~ResourceManager()
87 void ResourceManager::AddActiveMainView (
88 const OUString
& rsMainViewURL
)
90 mpActiveMainViewContainer
->insert(rsMainViewURL
);
93 bool ResourceManager::IsResourceActive (
94 const OUString
& rsMainViewURL
)
96 return (mpActiveMainViewContainer
->find(rsMainViewURL
) != mpActiveMainViewContainer
->end());
99 void ResourceManager::SaveResourceState()
103 void SAL_CALL
ResourceManager::disposing()
105 if (mxConfigurationController
.is())
107 mxConfigurationController
->removeConfigurationChangeListener(this);
108 mxConfigurationController
= NULL
;
112 void SAL_CALL
ResourceManager::notifyConfigurationChange (
113 const ConfigurationChangeEvent
& rEvent
)
114 throw (RuntimeException
, std::exception
)
116 OSL_ASSERT(rEvent
.ResourceId
.is());
118 sal_Int32 nEventType
= 0;
119 rEvent
.UserData
>>= nEventType
;
122 case ResourceActivationRequestEvent
:
123 if (rEvent
.ResourceId
->isBoundToURL(
124 FrameworkHelper::msCenterPaneURL
,
125 AnchorBindingMode_DIRECT
))
127 // A resource directly bound to the center pane has been
129 if (rEvent
.ResourceId
->getResourceTypePrefix().equals(
130 FrameworkHelper::msViewURLPrefix
))
132 // The requested resource is a view. Show or hide the
133 // resource managed by this ResourceManager accordingly.
134 HandleMainViewSwitch(
135 rEvent
.ResourceId
->getResourceURL(),
136 rEvent
.Configuration
,
140 else if (rEvent
.ResourceId
->compareTo(mxResourceId
) == 0)
142 // The resource managed by this ResourceManager has been
143 // explicitly been requested (maybe by us). Remember this
145 HandleResourceRequest(true, rEvent
.Configuration
);
149 case ResourceDeactivationRequestEvent
:
150 if (rEvent
.ResourceId
->compareTo(mxMainViewAnchorId
) == 0)
152 HandleMainViewSwitch(
154 rEvent
.Configuration
,
157 else if (rEvent
.ResourceId
->compareTo(mxResourceId
) == 0)
159 // The resource managed by this ResourceManager has been
160 // explicitly been requested to be hidden (maybe by us).
161 // Remember this setting.
162 HandleResourceRequest(false, rEvent
.Configuration
);
168 void ResourceManager::UpdateForMainViewShell()
170 if (mxConfigurationController
.is())
172 ConfigurationController::Lock
aLock (mxConfigurationController
);
174 if (mpActiveMainViewContainer
->find(msCurrentMainViewURL
)
175 != mpActiveMainViewContainer
->end())
177 // Activate resource.
178 mxConfigurationController
->requestResourceActivation(
179 mxResourceId
->getAnchor(),
180 ResourceActivationMode_ADD
);
181 mxConfigurationController
->requestResourceActivation(
183 ResourceActivationMode_REPLACE
);
187 mxConfigurationController
->requestResourceDeactivation(mxResourceId
);
192 void ResourceManager::HandleMainViewSwitch (
193 const OUString
& rsViewURL
,
194 const Reference
<XConfiguration
>& rxConfiguration
,
195 const bool bIsActivated
)
197 (void)rxConfiguration
;
199 msCurrentMainViewURL
= rsViewURL
;
201 msCurrentMainViewURL
.clear();
202 UpdateForMainViewShell();
205 void ResourceManager::HandleResourceRequest(
207 const Reference
<XConfiguration
>& rxConfiguration
)
209 Sequence
<Reference
<XResourceId
> > aCenterViews
= rxConfiguration
->getResources(
210 FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL
),
211 FrameworkHelper::msViewURLPrefix
,
212 AnchorBindingMode_DIRECT
);
213 if (aCenterViews
.getLength() == 1)
217 mpActiveMainViewContainer
->insert(aCenterViews
[0]->getResourceURL());
221 MainViewContainer::iterator
iElement (
222 mpActiveMainViewContainer
->find(aCenterViews
[0]->getResourceURL()));
223 if (iElement
!= mpActiveMainViewContainer
->end())
224 mpActiveMainViewContainer
->erase(iElement
);
229 void SAL_CALL
ResourceManager::disposing (
230 const lang::EventObject
& rEvent
)
231 throw (RuntimeException
, std::exception
)
233 if (mxConfigurationController
.is()
234 && rEvent
.Source
== mxConfigurationController
)
237 // Without the configuration controller this class can do nothing.
238 mxConfigurationController
= NULL
;
243 } } // end of namespace sd::framework
245 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */