Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / sd / source / ui / framework / module / SlideSorterModule.cxx
blobb572f59ec9e935afd7d3e19e49ba42fbddc06ffb
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 "SlideSorterModule.hxx"
22 #include <comphelper/lok.hxx>
23 #include <framework/FrameworkHelper.hxx>
24 #include <framework/ConfigurationController.hxx>
25 #include <o3tl/test_info.hxx>
26 #include <officecfg/Office/Impress.hxx>
27 #include <DrawController.hxx>
28 #include <com/sun/star/drawing/framework/XTabBar.hpp>
29 #include <com/sun/star/drawing/framework/TabBarButton.hpp>
30 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
31 #include <com/sun/star/frame/XController.hpp>
33 #include <strings.hrc>
34 #include <sdresid.hxx>
36 using namespace ::com::sun::star;
37 using namespace ::com::sun::star::uno;
38 using namespace ::com::sun::star::drawing::framework;
40 using ::sd::framework::FrameworkHelper;
42 namespace {
43 const sal_Int32 ResourceActivationRequestEvent = 0;
44 const sal_Int32 ResourceDeactivationRequestEvent = 1;
47 namespace sd::framework {
49 //===== SlideSorterModule ==================================================
51 SlideSorterModule::SlideSorterModule (
52 const rtl::Reference<::sd::DrawController>& rxController,
53 const OUString& rsLeftPaneURL)
54 : mxResourceId(FrameworkHelper::CreateResourceId(FrameworkHelper::msSlideSorterURL, rsLeftPaneURL)),
55 mxMainViewAnchorId(FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL)),
56 mxViewTabBarId(FrameworkHelper::CreateResourceId(
57 FrameworkHelper::msViewTabBarURL,
58 FrameworkHelper::msCenterPaneURL)),
59 mxControllerManager(rxController)
61 if (mxControllerManager.is())
63 mxConfigurationController = mxControllerManager->getConfigurationController();
65 if (mxConfigurationController.is())
67 uno::Reference<lang::XComponent> const xComppnent(
68 mxConfigurationController, UNO_QUERY_THROW);
69 xComppnent->addEventListener(this);
70 mxConfigurationController->addConfigurationChangeListener(
71 this,
72 FrameworkHelper::msResourceActivationRequestEvent,
73 Any(ResourceActivationRequestEvent));
74 mxConfigurationController->addConfigurationChangeListener(
75 this,
76 FrameworkHelper::msResourceDeactivationRequestEvent,
77 Any(ResourceDeactivationRequestEvent));
80 if (!mxConfigurationController.is())
81 return;
83 UpdateViewTabBar(nullptr);
85 if (officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::ImpressView::get().value_or(true)
86 && (!o3tl::IsRunningUnitTest() || !comphelper::LibreOfficeKit::isActive()))
87 AddActiveMainView(FrameworkHelper::msImpressViewURL);
88 if (officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::OutlineView::get().value_or(true))
89 AddActiveMainView(FrameworkHelper::msOutlineViewURL);
90 if (officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::NotesView::get().value_or(true))
91 AddActiveMainView(FrameworkHelper::msNotesViewURL);
92 if (officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::HandoutView::get().value_or(false))
93 AddActiveMainView(FrameworkHelper::msHandoutViewURL);
94 if (officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::SlideSorterView::get().value_or(false)
95 && !comphelper::LibreOfficeKit::isActive())
96 AddActiveMainView(FrameworkHelper::msSlideSorterURL);
97 if (officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::DrawView::get().value_or(true))
98 AddActiveMainView(FrameworkHelper::msDrawViewURL);
100 mxConfigurationController->addConfigurationChangeListener(
101 this,
102 FrameworkHelper::msResourceActivationEvent,
103 Any());
106 SlideSorterModule::~SlideSorterModule()
110 void SlideSorterModule::SaveResourceState()
112 auto xChanges = comphelper::ConfigurationChanges::create();
113 officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::ImpressView::set(IsResourceActive(FrameworkHelper::msImpressViewURL),xChanges);
114 officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::OutlineView::set(IsResourceActive(FrameworkHelper::msOutlineViewURL),xChanges);
115 officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::NotesView::set(IsResourceActive(FrameworkHelper::msNotesViewURL),xChanges);
116 officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::HandoutView::set(IsResourceActive(FrameworkHelper::msHandoutViewURL),xChanges);
117 officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::SlideSorterView::set(IsResourceActive(FrameworkHelper::msSlideSorterURL),xChanges);
118 officecfg::Office::Impress::MultiPaneGUI::SlideSorterBar::Visible::DrawView::set(IsResourceActive(FrameworkHelper::msDrawViewURL),xChanges);
119 xChanges->commit();
122 void SAL_CALL SlideSorterModule::notifyConfigurationChange (
123 const ConfigurationChangeEvent& rEvent)
125 if (rEvent.Type == FrameworkHelper::msResourceActivationEvent)
127 if (rEvent.ResourceId->compareTo(mxViewTabBarId) == 0)
129 // Update the view tab bar because the view tab bar has just
130 // become active.
131 UpdateViewTabBar(Reference<XTabBar>(rEvent.ResourceObject,UNO_QUERY));
133 else if (rEvent.ResourceId->getResourceTypePrefix() ==
134 FrameworkHelper::msViewURLPrefix
135 && rEvent.ResourceId->isBoundTo(
136 FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
137 AnchorBindingMode_DIRECT))
139 // Update the view tab bar because the view in the center pane
140 // has changed.
141 UpdateViewTabBar(nullptr);
143 return;
146 OSL_ASSERT(rEvent.ResourceId.is());
147 sal_Int32 nEventType = 0;
148 rEvent.UserData >>= nEventType;
149 switch (nEventType)
151 case ResourceActivationRequestEvent:
152 if (rEvent.ResourceId->isBoundToURL(
153 FrameworkHelper::msCenterPaneURL,
154 AnchorBindingMode_DIRECT))
156 // A resource directly bound to the center pane has been
157 // requested.
158 if (rEvent.ResourceId->getResourceTypePrefix() ==
159 FrameworkHelper::msViewURLPrefix)
161 // The requested resource is a view. Show or hide the
162 // resource managed by this ResourceManager accordingly.
163 HandleMainViewSwitch(
164 rEvent.ResourceId->getResourceURL(),
165 true);
168 else if (rEvent.ResourceId->compareTo(mxResourceId) == 0)
170 // The resource managed by this ResourceManager has been
171 // explicitly been requested (maybe by us). Remember this
172 // setting.
173 HandleResourceRequest(true, rEvent.Configuration);
175 break;
177 case ResourceDeactivationRequestEvent:
178 if (rEvent.ResourceId->compareTo(mxMainViewAnchorId) == 0)
180 HandleMainViewSwitch(
181 OUString(),
182 false);
184 else if (rEvent.ResourceId->compareTo(mxResourceId) == 0)
186 // The resource managed by this ResourceManager has been
187 // explicitly been requested to be hidden (maybe by us).
188 // Remember this setting.
189 HandleResourceRequest(false, rEvent.Configuration);
191 break;
195 void SlideSorterModule::UpdateViewTabBar (const Reference<XTabBar>& rxTabBar)
197 if ( ! mxControllerManager.is())
198 return;
200 Reference<XTabBar> xBar (rxTabBar);
201 if ( ! xBar.is())
203 Reference<XConfigurationController> xCC (
204 mxControllerManager->getConfigurationController());
205 if (xCC.is())
206 xBar.set(xCC->getResource(mxViewTabBarId), UNO_QUERY);
209 if (!xBar.is())
210 return;
212 TabBarButton aButtonA;
213 aButtonA.ResourceId = FrameworkHelper::CreateResourceId(
214 FrameworkHelper::msSlideSorterURL,
215 FrameworkHelper::msCenterPaneURL);
216 aButtonA.ButtonLabel = SdResId(STR_SLIDE_SORTER_MODE);
218 TabBarButton aButtonB;
219 aButtonB.ResourceId = FrameworkHelper::CreateResourceId(
220 FrameworkHelper::msHandoutViewURL,
221 FrameworkHelper::msCenterPaneURL);
223 if ( ! xBar->hasTabBarButton(aButtonA))
224 xBar->addTabBarButtonAfter(aButtonA, aButtonB);
227 void SlideSorterModule::AddActiveMainView (
228 const OUString& rsMainViewURL)
230 maActiveMainViewContainer.insert(rsMainViewURL);
233 bool SlideSorterModule::IsResourceActive (
234 const OUString& rsMainViewURL)
236 return (maActiveMainViewContainer.find(rsMainViewURL) != maActiveMainViewContainer.end());
239 void SlideSorterModule::disposing(std::unique_lock<std::mutex>&)
241 if (mxConfigurationController.is())
243 uno::Reference<lang::XComponent> const xComponent(mxConfigurationController, UNO_QUERY);
244 if (xComponent.is())
245 xComponent->removeEventListener(this);
247 mxConfigurationController->removeConfigurationChangeListener(this);
248 mxConfigurationController = nullptr;
252 void SlideSorterModule::HandleMainViewSwitch (
253 const OUString& rsViewURL,
254 const bool bIsActivated)
256 if (bIsActivated)
257 msCurrentMainViewURL = rsViewURL;
258 else
259 msCurrentMainViewURL.clear();
261 if (!mxConfigurationController.is())
262 return;
264 ConfigurationController::Lock aLock (mxConfigurationController);
266 if (maActiveMainViewContainer.find(msCurrentMainViewURL)
267 != maActiveMainViewContainer.end())
269 // Activate resource.
270 mxConfigurationController->requestResourceActivation(
271 mxResourceId->getAnchor(),
272 ResourceActivationMode_ADD);
273 mxConfigurationController->requestResourceActivation(
274 mxResourceId,
275 ResourceActivationMode_REPLACE);
277 else
279 mxConfigurationController->requestResourceDeactivation(mxResourceId);
283 void SlideSorterModule::HandleResourceRequest(
284 bool bActivation,
285 const Reference<XConfiguration>& rxConfiguration)
287 Sequence<Reference<XResourceId> > aCenterViews = rxConfiguration->getResources(
288 FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
289 FrameworkHelper::msViewURLPrefix,
290 AnchorBindingMode_DIRECT);
291 if (aCenterViews.getLength() == 1)
293 if (bActivation)
295 maActiveMainViewContainer.insert(aCenterViews[0]->getResourceURL());
297 else
299 maActiveMainViewContainer.erase(aCenterViews[0]->getResourceURL());
304 void SAL_CALL SlideSorterModule::disposing (
305 const lang::EventObject& rEvent)
307 if (mxConfigurationController.is()
308 && rEvent.Source == mxConfigurationController)
310 SaveResourceState();
311 // Without the configuration controller this class can do nothing.
312 mxConfigurationController = nullptr;
313 dispose();
317 } // end of namespace sd::framework
319 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */