LibreOffice Module sd (master) 1
CenterViewFocusModule.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
21
24
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>
31
32using namespace ::com::sun::star;
33using namespace ::com::sun::star::uno;
35
36using ::sd::framework::FrameworkHelper;
37
38namespace sd::framework {
39
40//===== CenterViewFocusModule ====================================================
41
43 : mbValid(false),
44 mpBase(nullptr),
45 mbNewViewCreated(false)
46{
47 if (rxController.is())
48 {
49 mxConfigurationController = rxController->getConfigurationController();
50
51 // Tunnel through the controller to obtain a ViewShellBase.
52 if (rxController != nullptr)
53 mpBase = rxController->GetViewShellBase();
54
55 // Check, if all required objects do exist.
56 if (mxConfigurationController.is() && mpBase!=nullptr)
57 {
58 mbValid = true;
59 }
60 }
61
62 if (mbValid)
63 {
64 mxConfigurationController->addConfigurationChangeListener(
65 this,
67 Any());
68 mxConfigurationController->addConfigurationChangeListener(
69 this,
71 Any());
72 }
73}
74
76{
77}
78
79void CenterViewFocusModule::disposing(std::unique_lock<std::mutex>&)
80{
82 mxConfigurationController->removeConfigurationChangeListener(this);
83
84 mbValid = false;
86 mpBase = nullptr;
87}
88
90 const ConfigurationChangeEvent& rEvent)
91{
92 if (mbValid)
93 {
95 {
96 HandleNewView(rEvent.Configuration);
97 }
98 else if (rEvent.Type == FrameworkHelper::msResourceActivationEvent)
99 {
100 if (rEvent.ResourceId->getResourceURL().match(FrameworkHelper::msViewURLPrefix))
101 mbNewViewCreated = true;
102 }
103 }
104}
105
107 const Reference<XConfiguration>& rxConfiguration)
108{
109 if (!mbNewViewCreated)
110 return;
111
112 mbNewViewCreated = false;
113 // Make the center pane the active one. Tunnel through the
114 // controller to obtain a ViewShell pointer.
115
116 Sequence<Reference<XResourceId> > xViewIds (rxConfiguration->getResources(
119 AnchorBindingMode_DIRECT));
120 Reference<XView> xView;
121 if (xViewIds.hasElements())
122 xView.set( mxConfigurationController->getResource(xViewIds[0]),UNO_QUERY);
123 if (mpBase!=nullptr)
124 {
125 auto pViewShellWrapper = dynamic_cast<ViewShellWrapper*>(xView.get());
126 if (pViewShellWrapper != nullptr)
127 {
128 std::shared_ptr<ViewShell> pViewShell = pViewShellWrapper->GetViewShell();
129 if (pViewShell != nullptr)
130 mpBase->GetViewShellManager()->MoveToTop(*pViewShell);
131 }
132 }
133}
134
136 const lang::EventObject& rEvent)
137{
139 if (rEvent.Source == mxConfigurationController)
140 {
141 mbValid = false;
143 mpBase = nullptr;
144 }
145}
146
147} // end of namespace sd::framework
148
149/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
std::shared_ptr< ViewShellManager > const & GetViewShellManager() const
CenterViewFocusModule(rtl::Reference< sd::DrawController > const &rxController)
void HandleNewView(const css::uno::Reference< css::drawing::framework::XConfiguration > &rxConfiguration)
At the end of an update of the current configuration this method handles a new view in the center pan...
css::uno::Reference< css::drawing::framework::XConfigurationController > mxConfigurationController
bool mbNewViewCreated
This flag indicates whether in the last configuration change cycle a new view has been created and th...
virtual void SAL_CALL notifyConfigurationChange(const css::drawing::framework::ConfigurationChangeEvent &rEvent) override
virtual void disposing(std::unique_lock< std::mutex > &) override
static css::uno::Reference< css::drawing::framework::XResourceId > CreateResourceId(const OUString &rsResourceURL)
Create a new XResourceId object for the given resource URL.
static const OUString msCenterPaneURL
static constexpr OUStringLiteral msConfigurationUpdateEndEvent
static constexpr OUStringLiteral msResourceActivationEvent
static constexpr OUStringLiteral msViewURLPrefix
This class wraps ViewShell objects and makes them look like an XView.
const ::std::shared_ptr< ViewShell > & GetViewShell() const
This method is typically used to obtain a pointer to the wrapped ViewShell object for a given XView o...
bool mbValid