LibreOffice Module sd (master) 1
ToolBarModule.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
20#include "ToolBarModule.hxx"
21#include <ViewShellBase.hxx>
22#include <DrawController.hxx>
25
26using namespace ::com::sun::star;
27using namespace ::com::sun::star::uno;
29
30using ::sd::framework::FrameworkHelper;
31
32namespace {
33 const sal_Int32 gnConfigurationUpdateStartEvent(0);
34 const sal_Int32 gnConfigurationUpdateEndEvent(1);
35 const sal_Int32 gnResourceActivationRequestEvent(2);
36 const sal_Int32 gnResourceDeactivationRequestEvent(3);
37}
38
39namespace sd::framework {
40
41//===== ToolBarModule =========================================================
42
44 const rtl::Reference<sd::DrawController>& rxController)
45 : mpBase(nullptr),
46 mbMainViewSwitchUpdatePending(false)
47{
48 // Tunnel through the controller to obtain a ViewShellBase.
49 if (rxController != nullptr)
50 mpBase = rxController->GetViewShellBase();
51
52 if (!rxController.is())
53 return;
54
55 mxConfigurationController = rxController->getConfigurationController();
57 return;
58
59 mxConfigurationController->addConfigurationChangeListener(
60 this,
62 Any(gnConfigurationUpdateStartEvent));
63 mxConfigurationController->addConfigurationChangeListener(
64 this,
66 Any(gnConfigurationUpdateEndEvent));
67 mxConfigurationController->addConfigurationChangeListener(
68 this,
70 Any(gnResourceActivationRequestEvent));
71 mxConfigurationController->addConfigurationChangeListener(
72 this,
74 Any(gnResourceDeactivationRequestEvent));
75}
76
78{
79}
80
81void ToolBarModule::disposing(std::unique_lock<std::mutex>&)
82{
84 {
85 mxConfigurationController->removeConfigurationChangeListener(this);
87 }
88}
89
91 const ConfigurationChangeEvent& rEvent)
92{
94 return;
95
96 sal_Int32 nEventType = 0;
97 rEvent.UserData >>= nEventType;
98 switch (nEventType)
99 {
100 case gnConfigurationUpdateStartEvent:
102 break;
103
104 case gnConfigurationUpdateEndEvent:
106 break;
107
108 case gnResourceActivationRequestEvent:
109 case gnResourceDeactivationRequestEvent:
110 // Remember the request for the activation or deactivation
111 // of the center pane view. When that happens then on end
112 // of the next configuration update the set of visible tool
113 // bars will be updated.
115 if (rEvent.ResourceId->getResourceURL().match(
117 && rEvent.ResourceId->isBoundToURL(
118 FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
119 {
121 }
122 break;
123 }
124}
125
127{
128 // Lock the ToolBarManager and tell it to lock the ViewShellManager as
129 // well. This way the ToolBarManager can optimize the releasing of
130 // locks and arranging of updates of both tool bars and the view shell
131 // stack.
132 if (mpBase != nullptr)
133 {
134 std::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager());
135 mpToolBarManagerLock.reset(new ToolBarManager::UpdateLock(pToolBarManager));
136 pToolBarManager->LockViewShellManager();
137 }
138}
139
141{
143 {
145 // Update the set of visible tool bars and deactivate those that are
146 // no longer visible. This is done before the old view shell is
147 // destroyed in order to avoid unnecessary updates of those tool
148 // bars.
149 std::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager());
150 std::shared_ptr<FrameworkHelper> pFrameworkHelper (
152 ViewShell* pViewShell
153 = pFrameworkHelper->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
154 if (pViewShell != nullptr)
155 {
156 pToolBarManager->MainViewShellChanged(*pViewShell);
157 pToolBarManager->SelectionHasChanged(
158 *pViewShell,
159 *pViewShell->GetView());
160 pToolBarManager->PreUpdate();
161 }
162 else
163 {
164 pToolBarManager->MainViewShellChanged();
165 pToolBarManager->PreUpdate();
166 }
167 }
168
169 // Releasing the update lock of the ToolBarManager will let the
170 // ToolBarManager with the help of the ViewShellManager take care of
171 // updating tool bars and view shell with the minimal amount of
172 // shell stack modifications and tool bar updates.
173 mpToolBarManagerLock.reset();
174}
175
176void SAL_CALL ToolBarModule::disposing (const lang::EventObject& rEvent)
177{
179 && rEvent.Source == mxConfigurationController)
180 {
181 // Without the configuration controller this class can do nothing.
183 dispose();
184 }
185}
186
187} // end of namespace sd::framework
188
189/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxViewShell * GetViewShell() const
virtual void SAL_CALL dispose() noexcept final override
Use this class to prevent the visible tool bars from being updated (and thus causing repaints and GUI...
std::shared_ptr< ToolBarManager > const & GetToolBarManager() const
Base class of the stacked shell hierarchy.
Definition: ViewShell.hxx:92
::sd::View * GetView() const
Definition: ViewShell.hxx:144
static const OUString msCenterPaneURL
static constexpr OUStringLiteral msConfigurationUpdateStartEvent
static constexpr OUStringLiteral msResourceActivationRequestEvent
static constexpr OUStringLiteral msConfigurationUpdateEndEvent
static constexpr OUStringLiteral msResourceDeactivationRequestEvent
static ::std::shared_ptr< FrameworkHelper > Instance(ViewShellBase &rBase)
Return the FrameworkHelper object that is associated with the given ViewShellBase.
static constexpr OUStringLiteral msViewURLPrefix
virtual void disposing(std::unique_lock< std::mutex > &) override
virtual ~ToolBarModule() override
std::unique_ptr< ToolBarManager::UpdateLock, o3tl::default_delete< ToolBarManager::UpdateLock > > mpToolBarManagerLock
ToolBarModule(const rtl::Reference< sd::DrawController > &rxController)
Create a new module.
virtual void SAL_CALL notifyConfigurationChange(const css::drawing::framework::ConfigurationChangeEvent &rEvent) override
css::uno::Reference< css::drawing::framework::XConfigurationController > mxConfigurationController