bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / framework / module / ToolBarModule.cxx
blob51e4b6ba62549f56c08eb73734e057937c9ae762
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 "ToolBarModule.hxx"
21 #include "ViewShellBase.hxx"
22 #include "DrawController.hxx"
23 #include "framework/FrameworkHelper.hxx"
24 #include "framework/ConfigurationController.hxx"
26 using namespace ::com::sun::star;
27 using namespace ::com::sun::star::uno;
28 using namespace ::com::sun::star::drawing::framework;
30 using ::sd::framework::FrameworkHelper;
32 namespace {
33 static const sal_Int32 gnConfigurationUpdateStartEvent(0);
34 static const sal_Int32 gnConfigurationUpdateEndEvent(1);
35 static const sal_Int32 gnResourceActivationRequestEvent(2);
36 static const sal_Int32 gnResourceDeactivationRequestEvent(3);
39 namespace sd { namespace framework {
41 //===== ToolBarModule =========================================================
43 ToolBarModule::ToolBarModule (
44 const Reference<frame::XController>& rxController)
45 : ToolBarModuleInterfaceBase(m_aMutex),
46 mxConfigurationController(),
47 mpBase(NULL),
48 mpToolBarManagerLock(),
49 mbMainViewSwitchUpdatePending(false)
51 // Tunnel through the controller to obtain a ViewShellBase.
52 Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
53 if (xTunnel.is())
55 ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
56 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
57 if (pController != NULL)
58 mpBase = pController->GetViewShellBase();
61 Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
62 if (xControllerManager.is())
64 mxConfigurationController = xControllerManager->getConfigurationController();
65 if (mxConfigurationController.is())
67 mxConfigurationController->addConfigurationChangeListener(
68 this,
69 FrameworkHelper::msConfigurationUpdateStartEvent,
70 makeAny(gnConfigurationUpdateStartEvent));
71 mxConfigurationController->addConfigurationChangeListener(
72 this,
73 FrameworkHelper::msConfigurationUpdateEndEvent,
74 makeAny(gnConfigurationUpdateEndEvent));
75 mxConfigurationController->addConfigurationChangeListener(
76 this,
77 FrameworkHelper::msResourceActivationRequestEvent,
78 makeAny(gnResourceActivationRequestEvent));
79 mxConfigurationController->addConfigurationChangeListener(
80 this,
81 FrameworkHelper::msResourceDeactivationRequestEvent,
82 makeAny(gnResourceDeactivationRequestEvent));
87 ToolBarModule::~ToolBarModule()
91 void SAL_CALL ToolBarModule::disposing()
93 if (mxConfigurationController.is())
94 mxConfigurationController->removeConfigurationChangeListener(this);
96 mxConfigurationController = NULL;
99 void SAL_CALL ToolBarModule::notifyConfigurationChange (
100 const ConfigurationChangeEvent& rEvent)
101 throw (RuntimeException, std::exception)
103 if (mxConfigurationController.is())
105 sal_Int32 nEventType = 0;
106 rEvent.UserData >>= nEventType;
107 switch (nEventType)
109 case gnConfigurationUpdateStartEvent:
110 HandleUpdateStart();
111 break;
113 case gnConfigurationUpdateEndEvent:
114 HandleUpdateEnd();
115 break;
117 case gnResourceActivationRequestEvent:
118 case gnResourceDeactivationRequestEvent:
119 // Remember the request for the activation or deactivation
120 // of the center pane view. When that happens then on end
121 // of the next configuration update the set of visible tool
122 // bars will be updated.
123 if ( ! mbMainViewSwitchUpdatePending)
124 if (rEvent.ResourceId->getResourceURL().match(
125 FrameworkHelper::msViewURLPrefix)
126 && rEvent.ResourceId->isBoundToURL(
127 FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
129 mbMainViewSwitchUpdatePending = true;
131 break;
136 void ToolBarModule::HandleUpdateStart()
138 // Lock the ToolBarManager and tell it to lock the ViewShellManager as
139 // well. This way the ToolBarManager can optimize the releasing of
140 // locks and arranging of updates of both tool bars and the view shell
141 // stack.
142 if (mpBase != NULL)
144 ::boost::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager());
145 mpToolBarManagerLock.reset(new ToolBarManager::UpdateLock(pToolBarManager));
146 pToolBarManager->LockViewShellManager();
150 void ToolBarModule::HandleUpdateEnd()
152 if (mbMainViewSwitchUpdatePending)
154 mbMainViewSwitchUpdatePending = false;
155 // Update the set of visible tool bars and deactivate those that are
156 // no longer visible. This is done before the old view shell is
157 // destroyed in order to avoid unnecessary updates of those tool
158 // bars.
159 ::boost::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager());
160 ::boost::shared_ptr<FrameworkHelper> pFrameworkHelper (
161 FrameworkHelper::Instance(*mpBase));
162 ViewShell* pViewShell
163 = pFrameworkHelper->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
164 if (pViewShell != NULL)
166 pToolBarManager->MainViewShellChanged(*pViewShell);
167 pToolBarManager->SelectionHasChanged(
168 *pViewShell,
169 *pViewShell->GetView());
170 pToolBarManager->PreUpdate();
172 else
174 pToolBarManager->MainViewShellChanged(ViewShell::ST_NONE);
175 pToolBarManager->PreUpdate();
179 // Releasing the update lock of the ToolBarManager will let the
180 // ToolBarManager with the help of the ViewShellManager take care of
181 // updating tool bars and view shell with the minimal amount of
182 // shell stack modifications and tool bar updates.
183 mpToolBarManagerLock.reset();
186 void SAL_CALL ToolBarModule::disposing (const lang::EventObject& rEvent)
187 throw (RuntimeException, std::exception)
189 if (mxConfigurationController.is()
190 && rEvent.Source == mxConfigurationController)
192 // Without the configuration controller this class can do nothing.
193 mxConfigurationController = NULL;
194 dispose();
198 } } // end of namespace sd::framework
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */