Move setting of LD_LIBRARY_PATH closer to invocation of cppunittester
[LibreOffice.git] / sd / source / ui / framework / module / CenterViewFocusModule.cxx
blob2c799e04bbb19ecfaa0b11dcf6969d4cb0f2cec0
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 "CenterViewFocusModule.hxx"
22 #include <framework/FrameworkHelper.hxx>
23 #include <framework/ViewShellWrapper.hxx>
25 #include <DrawController.hxx>
26 #include <ViewShellBase.hxx>
27 #include <ViewShellManager.hxx>
28 #include <com/sun/star/drawing/framework/XControllerManager.hpp>
29 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
30 #include <comphelper/servicehelper.hxx>
32 using namespace ::com::sun::star;
33 using namespace ::com::sun::star::uno;
34 using namespace ::com::sun::star::drawing::framework;
36 using ::sd::framework::FrameworkHelper;
38 namespace sd::framework {
40 //===== CenterViewFocusModule ====================================================
42 CenterViewFocusModule::CenterViewFocusModule (rtl::Reference<sd::DrawController> const & rxController)
43 : mbValid(false),
44 mpBase(nullptr),
45 mbNewViewCreated(false)
47 if (rxController.is())
49 mxConfigurationController = rxController->getConfigurationController();
51 // Tunnel through the controller to obtain a ViewShellBase.
52 if (rxController != nullptr)
53 mpBase = rxController->GetViewShellBase();
55 // Check, if all required objects do exist.
56 if (mxConfigurationController.is() && mpBase!=nullptr)
58 mbValid = true;
62 if (mbValid)
64 mxConfigurationController->addConfigurationChangeListener(
65 this,
66 FrameworkHelper::msConfigurationUpdateEndEvent,
67 Any());
68 mxConfigurationController->addConfigurationChangeListener(
69 this,
70 FrameworkHelper::msResourceActivationEvent,
71 Any());
75 CenterViewFocusModule::~CenterViewFocusModule()
79 void CenterViewFocusModule::disposing(std::unique_lock<std::mutex>&)
81 if (mxConfigurationController.is())
82 mxConfigurationController->removeConfigurationChangeListener(this);
84 mbValid = false;
85 mxConfigurationController = nullptr;
86 mpBase = nullptr;
89 void SAL_CALL CenterViewFocusModule::notifyConfigurationChange (
90 const ConfigurationChangeEvent& rEvent)
92 if (mbValid)
94 if (rEvent.Type == FrameworkHelper::msConfigurationUpdateEndEvent)
96 HandleNewView(rEvent.Configuration);
98 else if (rEvent.Type == FrameworkHelper::msResourceActivationEvent)
100 if (rEvent.ResourceId->getResourceURL().match(FrameworkHelper::msViewURLPrefix))
101 mbNewViewCreated = true;
106 void CenterViewFocusModule::HandleNewView (
107 const Reference<XConfiguration>& rxConfiguration)
109 if (!mbNewViewCreated)
110 return;
112 mbNewViewCreated = false;
113 // Make the center pane the active one. Tunnel through the
114 // controller to obtain a ViewShell pointer.
116 Sequence<Reference<XResourceId> > xViewIds (rxConfiguration->getResources(
117 FrameworkHelper::CreateResourceId(FrameworkHelper::msCenterPaneURL),
118 FrameworkHelper::msViewURLPrefix,
119 AnchorBindingMode_DIRECT));
120 Reference<XView> xView;
121 if (xViewIds.hasElements())
122 xView.set( mxConfigurationController->getResource(xViewIds[0]),UNO_QUERY);
123 if (mpBase!=nullptr)
125 auto pViewShellWrapper = dynamic_cast<ViewShellWrapper*>(xView.get());
126 if (pViewShellWrapper != nullptr)
128 std::shared_ptr<ViewShell> pViewShell = pViewShellWrapper->GetViewShell();
129 if (pViewShell != nullptr)
130 mpBase->GetViewShellManager()->MoveToTop(*pViewShell);
135 void SAL_CALL CenterViewFocusModule::disposing (
136 const lang::EventObject& rEvent)
138 if (mxConfigurationController.is())
139 if (rEvent.Source == mxConfigurationController)
141 mbValid = false;
142 mxConfigurationController = nullptr;
143 mpBase = nullptr;
147 } // end of namespace sd::framework
149 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */