1*b1cdbd2cSJim Jagielski /**************************************************************
2*b1cdbd2cSJim Jagielski *
3*b1cdbd2cSJim Jagielski * Licensed to the Apache Software Foundation (ASF) under one
4*b1cdbd2cSJim Jagielski * or more contributor license agreements. See the NOTICE file
5*b1cdbd2cSJim Jagielski * distributed with this work for additional information
6*b1cdbd2cSJim Jagielski * regarding copyright ownership. The ASF licenses this file
7*b1cdbd2cSJim Jagielski * to you under the Apache License, Version 2.0 (the
8*b1cdbd2cSJim Jagielski * "License"); you may not use this file except in compliance
9*b1cdbd2cSJim Jagielski * with the License. You may obtain a copy of the License at
10*b1cdbd2cSJim Jagielski *
11*b1cdbd2cSJim Jagielski * http://www.apache.org/licenses/LICENSE-2.0
12*b1cdbd2cSJim Jagielski *
13*b1cdbd2cSJim Jagielski * Unless required by applicable law or agreed to in writing,
14*b1cdbd2cSJim Jagielski * software distributed under the License is distributed on an
15*b1cdbd2cSJim Jagielski * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*b1cdbd2cSJim Jagielski * KIND, either express or implied. See the License for the
17*b1cdbd2cSJim Jagielski * specific language governing permissions and limitations
18*b1cdbd2cSJim Jagielski * under the License.
19*b1cdbd2cSJim Jagielski *
20*b1cdbd2cSJim Jagielski *************************************************************/
21*b1cdbd2cSJim Jagielski
22*b1cdbd2cSJim Jagielski
23*b1cdbd2cSJim Jagielski
24*b1cdbd2cSJim Jagielski #include "precompiled_sd.hxx"
25*b1cdbd2cSJim Jagielski
26*b1cdbd2cSJim Jagielski #include "ResourceManager.hxx"
27*b1cdbd2cSJim Jagielski
28*b1cdbd2cSJim Jagielski #include "framework/FrameworkHelper.hxx"
29*b1cdbd2cSJim Jagielski #include "framework/ConfigurationController.hxx"
30*b1cdbd2cSJim Jagielski #include <com/sun/star/drawing/framework/XControllerManager.hpp>
31*b1cdbd2cSJim Jagielski
32*b1cdbd2cSJim Jagielski #include <comphelper/stl_types.hxx>
33*b1cdbd2cSJim Jagielski #include <set>
34*b1cdbd2cSJim Jagielski
35*b1cdbd2cSJim Jagielski using namespace ::com::sun::star;
36*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::uno;
37*b1cdbd2cSJim Jagielski using namespace ::com::sun::star::drawing::framework;
38*b1cdbd2cSJim Jagielski
39*b1cdbd2cSJim Jagielski using ::rtl::OUString;
40*b1cdbd2cSJim Jagielski using ::sd::framework::FrameworkHelper;
41*b1cdbd2cSJim Jagielski
42*b1cdbd2cSJim Jagielski namespace {
43*b1cdbd2cSJim Jagielski static const sal_Int32 ResourceActivationRequestEvent = 0;
44*b1cdbd2cSJim Jagielski static const sal_Int32 ResourceDeactivationRequestEvent = 1;
45*b1cdbd2cSJim Jagielski }
46*b1cdbd2cSJim Jagielski
47*b1cdbd2cSJim Jagielski
48*b1cdbd2cSJim Jagielski
49*b1cdbd2cSJim Jagielski
50*b1cdbd2cSJim Jagielski namespace sd { namespace framework {
51*b1cdbd2cSJim Jagielski
52*b1cdbd2cSJim Jagielski class ResourceManager::MainViewContainer
53*b1cdbd2cSJim Jagielski : public ::std::set<OUString, ::comphelper::UStringLess>
54*b1cdbd2cSJim Jagielski {
55*b1cdbd2cSJim Jagielski public:
MainViewContainer(void)56*b1cdbd2cSJim Jagielski MainViewContainer (void) {}
57*b1cdbd2cSJim Jagielski };
58*b1cdbd2cSJim Jagielski
59*b1cdbd2cSJim Jagielski
60*b1cdbd2cSJim Jagielski
61*b1cdbd2cSJim Jagielski
62*b1cdbd2cSJim Jagielski //===== ResourceManager =======================================================
63*b1cdbd2cSJim Jagielski
ResourceManager(const Reference<frame::XController> & rxController,const Reference<XResourceId> & rxResourceId)64*b1cdbd2cSJim Jagielski ResourceManager::ResourceManager (
65*b1cdbd2cSJim Jagielski const Reference<frame::XController>& rxController,
66*b1cdbd2cSJim Jagielski const Reference<XResourceId>& rxResourceId)
67*b1cdbd2cSJim Jagielski : ResourceManagerInterfaceBase(MutexOwner::maMutex),
68*b1cdbd2cSJim Jagielski mxConfigurationController(),
69*b1cdbd2cSJim Jagielski mpActiveMainViewContainer(new MainViewContainer()),
70*b1cdbd2cSJim Jagielski mxResourceId(rxResourceId),
71*b1cdbd2cSJim Jagielski mxMainViewAnchorId(FrameworkHelper::Instance(rxController)->CreateResourceId(
72*b1cdbd2cSJim Jagielski FrameworkHelper::msCenterPaneURL)),
73*b1cdbd2cSJim Jagielski msCurrentMainViewURL(),
74*b1cdbd2cSJim Jagielski mbIsEnabled(true)
75*b1cdbd2cSJim Jagielski {
76*b1cdbd2cSJim Jagielski Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
77*b1cdbd2cSJim Jagielski if (xControllerManager.is())
78*b1cdbd2cSJim Jagielski {
79*b1cdbd2cSJim Jagielski mxConfigurationController = xControllerManager->getConfigurationController();
80*b1cdbd2cSJim Jagielski
81*b1cdbd2cSJim Jagielski if (mxConfigurationController.is())
82*b1cdbd2cSJim Jagielski {
83*b1cdbd2cSJim Jagielski mxConfigurationController->addConfigurationChangeListener(
84*b1cdbd2cSJim Jagielski this,
85*b1cdbd2cSJim Jagielski FrameworkHelper::msResourceActivationRequestEvent,
86*b1cdbd2cSJim Jagielski makeAny(ResourceActivationRequestEvent));
87*b1cdbd2cSJim Jagielski mxConfigurationController->addConfigurationChangeListener(
88*b1cdbd2cSJim Jagielski this,
89*b1cdbd2cSJim Jagielski FrameworkHelper::msResourceDeactivationRequestEvent,
90*b1cdbd2cSJim Jagielski makeAny(ResourceDeactivationRequestEvent));
91*b1cdbd2cSJim Jagielski }
92*b1cdbd2cSJim Jagielski }
93*b1cdbd2cSJim Jagielski }
94*b1cdbd2cSJim Jagielski
95*b1cdbd2cSJim Jagielski
96*b1cdbd2cSJim Jagielski
97*b1cdbd2cSJim Jagielski
~ResourceManager(void)98*b1cdbd2cSJim Jagielski ResourceManager::~ResourceManager (void)
99*b1cdbd2cSJim Jagielski {
100*b1cdbd2cSJim Jagielski }
101*b1cdbd2cSJim Jagielski
102*b1cdbd2cSJim Jagielski
103*b1cdbd2cSJim Jagielski
104*b1cdbd2cSJim Jagielski
AddActiveMainView(const OUString & rsMainViewURL)105*b1cdbd2cSJim Jagielski void ResourceManager::AddActiveMainView (
106*b1cdbd2cSJim Jagielski const OUString& rsMainViewURL)
107*b1cdbd2cSJim Jagielski {
108*b1cdbd2cSJim Jagielski mpActiveMainViewContainer->insert(rsMainViewURL);
109*b1cdbd2cSJim Jagielski }
110*b1cdbd2cSJim Jagielski
111*b1cdbd2cSJim Jagielski
112*b1cdbd2cSJim Jagielski
113*b1cdbd2cSJim Jagielski
disposing(void)114*b1cdbd2cSJim Jagielski void SAL_CALL ResourceManager::disposing (void)
115*b1cdbd2cSJim Jagielski {
116*b1cdbd2cSJim Jagielski if (mxConfigurationController.is())
117*b1cdbd2cSJim Jagielski {
118*b1cdbd2cSJim Jagielski mxConfigurationController->removeConfigurationChangeListener(this);
119*b1cdbd2cSJim Jagielski mxConfigurationController = NULL;
120*b1cdbd2cSJim Jagielski }
121*b1cdbd2cSJim Jagielski }
122*b1cdbd2cSJim Jagielski
123*b1cdbd2cSJim Jagielski
124*b1cdbd2cSJim Jagielski
125*b1cdbd2cSJim Jagielski
Enable(void)126*b1cdbd2cSJim Jagielski void ResourceManager::Enable (void)
127*b1cdbd2cSJim Jagielski {
128*b1cdbd2cSJim Jagielski mbIsEnabled = true;
129*b1cdbd2cSJim Jagielski UpdateForMainViewShell();
130*b1cdbd2cSJim Jagielski }
131*b1cdbd2cSJim Jagielski
132*b1cdbd2cSJim Jagielski
133*b1cdbd2cSJim Jagielski
134*b1cdbd2cSJim Jagielski
Disable(void)135*b1cdbd2cSJim Jagielski void ResourceManager::Disable (void)
136*b1cdbd2cSJim Jagielski {
137*b1cdbd2cSJim Jagielski mbIsEnabled = false;
138*b1cdbd2cSJim Jagielski UpdateForMainViewShell();
139*b1cdbd2cSJim Jagielski }
140*b1cdbd2cSJim Jagielski
141*b1cdbd2cSJim Jagielski
142*b1cdbd2cSJim Jagielski
143*b1cdbd2cSJim Jagielski
notifyConfigurationChange(const ConfigurationChangeEvent & rEvent)144*b1cdbd2cSJim Jagielski void SAL_CALL ResourceManager::notifyConfigurationChange (
145*b1cdbd2cSJim Jagielski const ConfigurationChangeEvent& rEvent)
146*b1cdbd2cSJim Jagielski throw (RuntimeException)
147*b1cdbd2cSJim Jagielski {
148*b1cdbd2cSJim Jagielski OSL_ASSERT(rEvent.ResourceId.is());
149*b1cdbd2cSJim Jagielski
150*b1cdbd2cSJim Jagielski sal_Int32 nEventType = 0;
151*b1cdbd2cSJim Jagielski rEvent.UserData >>= nEventType;
152*b1cdbd2cSJim Jagielski switch (nEventType)
153*b1cdbd2cSJim Jagielski {
154*b1cdbd2cSJim Jagielski case ResourceActivationRequestEvent:
155*b1cdbd2cSJim Jagielski if (rEvent.ResourceId->isBoundToURL(
156*b1cdbd2cSJim Jagielski FrameworkHelper::msCenterPaneURL,
157*b1cdbd2cSJim Jagielski AnchorBindingMode_DIRECT))
158*b1cdbd2cSJim Jagielski {
159*b1cdbd2cSJim Jagielski // A resource directly bound to the center pane has been
160*b1cdbd2cSJim Jagielski // requested.
161*b1cdbd2cSJim Jagielski if (rEvent.ResourceId->getResourceTypePrefix().equals(
162*b1cdbd2cSJim Jagielski FrameworkHelper::msViewURLPrefix))
163*b1cdbd2cSJim Jagielski {
164*b1cdbd2cSJim Jagielski // The requested resource is a view. Show or hide the
165*b1cdbd2cSJim Jagielski // resource managed by this ResourceManager accordingly.
166*b1cdbd2cSJim Jagielski HandleMainViewSwitch(
167*b1cdbd2cSJim Jagielski rEvent.ResourceId->getResourceURL(),
168*b1cdbd2cSJim Jagielski rEvent.Configuration,
169*b1cdbd2cSJim Jagielski true);
170*b1cdbd2cSJim Jagielski }
171*b1cdbd2cSJim Jagielski }
172*b1cdbd2cSJim Jagielski else if (rEvent.ResourceId->compareTo(mxResourceId) == 0)
173*b1cdbd2cSJim Jagielski {
174*b1cdbd2cSJim Jagielski // The resource managed by this ResourceManager has been
175*b1cdbd2cSJim Jagielski // explicitly been requested (maybe by us). Remember this
176*b1cdbd2cSJim Jagielski // setting.
177*b1cdbd2cSJim Jagielski HandleResourceRequest(true, rEvent.Configuration);
178*b1cdbd2cSJim Jagielski }
179*b1cdbd2cSJim Jagielski break;
180*b1cdbd2cSJim Jagielski
181*b1cdbd2cSJim Jagielski case ResourceDeactivationRequestEvent:
182*b1cdbd2cSJim Jagielski if (rEvent.ResourceId->compareTo(mxMainViewAnchorId) == 0)
183*b1cdbd2cSJim Jagielski {
184*b1cdbd2cSJim Jagielski HandleMainViewSwitch(
185*b1cdbd2cSJim Jagielski OUString(),
186*b1cdbd2cSJim Jagielski rEvent.Configuration,
187*b1cdbd2cSJim Jagielski false);
188*b1cdbd2cSJim Jagielski }
189*b1cdbd2cSJim Jagielski else if (rEvent.ResourceId->compareTo(mxResourceId) == 0)
190*b1cdbd2cSJim Jagielski {
191*b1cdbd2cSJim Jagielski // The resource managed by this ResourceManager has been
192*b1cdbd2cSJim Jagielski // explicitly been requested to be hidden (maybe by us).
193*b1cdbd2cSJim Jagielski // Remember this setting.
194*b1cdbd2cSJim Jagielski HandleResourceRequest(false, rEvent.Configuration);
195*b1cdbd2cSJim Jagielski }
196*b1cdbd2cSJim Jagielski break;
197*b1cdbd2cSJim Jagielski }
198*b1cdbd2cSJim Jagielski }
199*b1cdbd2cSJim Jagielski
200*b1cdbd2cSJim Jagielski
201*b1cdbd2cSJim Jagielski
202*b1cdbd2cSJim Jagielski
UpdateForMainViewShell(void)203*b1cdbd2cSJim Jagielski void ResourceManager::UpdateForMainViewShell (void)
204*b1cdbd2cSJim Jagielski {
205*b1cdbd2cSJim Jagielski if (mxConfigurationController.is())
206*b1cdbd2cSJim Jagielski {
207*b1cdbd2cSJim Jagielski ConfigurationController::Lock aLock (mxConfigurationController);
208*b1cdbd2cSJim Jagielski
209*b1cdbd2cSJim Jagielski if (mbIsEnabled
210*b1cdbd2cSJim Jagielski && mpActiveMainViewContainer->find(msCurrentMainViewURL)
211*b1cdbd2cSJim Jagielski != mpActiveMainViewContainer->end())
212*b1cdbd2cSJim Jagielski {
213*b1cdbd2cSJim Jagielski // Activate resource.
214*b1cdbd2cSJim Jagielski mxConfigurationController->requestResourceActivation(
215*b1cdbd2cSJim Jagielski mxResourceId->getAnchor(),
216*b1cdbd2cSJim Jagielski ResourceActivationMode_ADD);
217*b1cdbd2cSJim Jagielski mxConfigurationController->requestResourceActivation(
218*b1cdbd2cSJim Jagielski mxResourceId,
219*b1cdbd2cSJim Jagielski ResourceActivationMode_REPLACE);
220*b1cdbd2cSJim Jagielski }
221*b1cdbd2cSJim Jagielski else
222*b1cdbd2cSJim Jagielski {
223*b1cdbd2cSJim Jagielski mxConfigurationController->requestResourceDeactivation(mxResourceId);
224*b1cdbd2cSJim Jagielski }
225*b1cdbd2cSJim Jagielski }
226*b1cdbd2cSJim Jagielski }
227*b1cdbd2cSJim Jagielski
228*b1cdbd2cSJim Jagielski
229*b1cdbd2cSJim Jagielski
230*b1cdbd2cSJim Jagielski
HandleMainViewSwitch(const OUString & rsViewURL,const Reference<XConfiguration> & rxConfiguration,const bool bIsActivated)231*b1cdbd2cSJim Jagielski void ResourceManager::HandleMainViewSwitch (
232*b1cdbd2cSJim Jagielski const OUString& rsViewURL,
233*b1cdbd2cSJim Jagielski const Reference<XConfiguration>& rxConfiguration,
234*b1cdbd2cSJim Jagielski const bool bIsActivated)
235*b1cdbd2cSJim Jagielski {
236*b1cdbd2cSJim Jagielski (void)rxConfiguration;
237*b1cdbd2cSJim Jagielski if (bIsActivated)
238*b1cdbd2cSJim Jagielski msCurrentMainViewURL = rsViewURL;
239*b1cdbd2cSJim Jagielski else
240*b1cdbd2cSJim Jagielski msCurrentMainViewURL = OUString();
241*b1cdbd2cSJim Jagielski UpdateForMainViewShell();
242*b1cdbd2cSJim Jagielski }
243*b1cdbd2cSJim Jagielski
244*b1cdbd2cSJim Jagielski
245*b1cdbd2cSJim Jagielski
246*b1cdbd2cSJim Jagielski
HandleResourceRequest(bool bActivation,const Reference<XConfiguration> & rxConfiguration)247*b1cdbd2cSJim Jagielski void ResourceManager::HandleResourceRequest(
248*b1cdbd2cSJim Jagielski bool bActivation,
249*b1cdbd2cSJim Jagielski const Reference<XConfiguration>& rxConfiguration)
250*b1cdbd2cSJim Jagielski {
251*b1cdbd2cSJim Jagielski if (mbIsEnabled)
252*b1cdbd2cSJim Jagielski {
253*b1cdbd2cSJim Jagielski Sequence<Reference<XResourceId> > aCenterViews = rxConfiguration->getResources(
254*b1cdbd2cSJim Jagielski FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
255*b1cdbd2cSJim Jagielski FrameworkHelper::msViewURLPrefix,
256*b1cdbd2cSJim Jagielski AnchorBindingMode_DIRECT);
257*b1cdbd2cSJim Jagielski if (aCenterViews.getLength() == 1)
258*b1cdbd2cSJim Jagielski {
259*b1cdbd2cSJim Jagielski if (bActivation)
260*b1cdbd2cSJim Jagielski {
261*b1cdbd2cSJim Jagielski mpActiveMainViewContainer->insert(aCenterViews[0]->getResourceURL());
262*b1cdbd2cSJim Jagielski }
263*b1cdbd2cSJim Jagielski else
264*b1cdbd2cSJim Jagielski {
265*b1cdbd2cSJim Jagielski MainViewContainer::iterator iElement (
266*b1cdbd2cSJim Jagielski mpActiveMainViewContainer->find(aCenterViews[0]->getResourceURL()));
267*b1cdbd2cSJim Jagielski if (iElement != mpActiveMainViewContainer->end())
268*b1cdbd2cSJim Jagielski mpActiveMainViewContainer->erase(iElement);
269*b1cdbd2cSJim Jagielski }
270*b1cdbd2cSJim Jagielski }
271*b1cdbd2cSJim Jagielski }
272*b1cdbd2cSJim Jagielski }
273*b1cdbd2cSJim Jagielski
274*b1cdbd2cSJim Jagielski
275*b1cdbd2cSJim Jagielski
276*b1cdbd2cSJim Jagielski
disposing(const lang::EventObject & rEvent)277*b1cdbd2cSJim Jagielski void SAL_CALL ResourceManager::disposing (
278*b1cdbd2cSJim Jagielski const lang::EventObject& rEvent)
279*b1cdbd2cSJim Jagielski throw (RuntimeException)
280*b1cdbd2cSJim Jagielski {
281*b1cdbd2cSJim Jagielski if (mxConfigurationController.is()
282*b1cdbd2cSJim Jagielski && rEvent.Source == mxConfigurationController)
283*b1cdbd2cSJim Jagielski {
284*b1cdbd2cSJim Jagielski // Without the configuration controller this class can do nothing.
285*b1cdbd2cSJim Jagielski mxConfigurationController = NULL;
286*b1cdbd2cSJim Jagielski dispose();
287*b1cdbd2cSJim Jagielski }
288*b1cdbd2cSJim Jagielski }
289*b1cdbd2cSJim Jagielski
290*b1cdbd2cSJim Jagielski } } // end of namespace sd::framework
291