Line data Source code
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 :
21 : #include "ToolBarModule.hxx"
22 : #include "ViewShellBase.hxx"
23 : #include "DrawController.hxx"
24 : #include "framework/FrameworkHelper.hxx"
25 : #include "framework/ConfigurationController.hxx"
26 :
27 :
28 : using namespace ::com::sun::star;
29 : using namespace ::com::sun::star::uno;
30 : using namespace ::com::sun::star::drawing::framework;
31 :
32 : using ::sd::framework::FrameworkHelper;
33 :
34 : namespace {
35 : static const sal_Int32 gnConfigurationUpdateStartEvent(0);
36 : static const sal_Int32 gnConfigurationUpdateEndEvent(1);
37 : static const sal_Int32 gnResourceActivationRequestEvent(2);
38 : static const sal_Int32 gnResourceDeactivationRequestEvent(3);
39 : }
40 :
41 : namespace sd { namespace framework {
42 :
43 : //===== ToolBarModule =========================================================
44 :
45 73 : ToolBarModule::ToolBarModule (
46 : const Reference<frame::XController>& rxController)
47 : : ToolBarModuleInterfaceBase(m_aMutex),
48 : mxConfigurationController(),
49 : mpBase(NULL),
50 : mpToolBarManagerLock(),
51 73 : mbMainViewSwitchUpdatePending(false)
52 : {
53 : // Tunnel through the controller to obtain a ViewShellBase.
54 73 : Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY);
55 73 : if (xTunnel.is())
56 : {
57 : ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
58 73 : xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
59 73 : if (pController != NULL)
60 73 : mpBase = pController->GetViewShellBase();
61 : }
62 :
63 146 : Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
64 73 : if (xControllerManager.is())
65 : {
66 73 : mxConfigurationController = xControllerManager->getConfigurationController();
67 73 : if (mxConfigurationController.is())
68 : {
69 73 : mxConfigurationController->addConfigurationChangeListener(
70 : this,
71 : FrameworkHelper::msConfigurationUpdateStartEvent,
72 73 : makeAny(gnConfigurationUpdateStartEvent));
73 73 : mxConfigurationController->addConfigurationChangeListener(
74 : this,
75 : FrameworkHelper::msConfigurationUpdateEndEvent,
76 73 : makeAny(gnConfigurationUpdateEndEvent));
77 73 : mxConfigurationController->addConfigurationChangeListener(
78 : this,
79 : FrameworkHelper::msResourceActivationRequestEvent,
80 73 : makeAny(gnResourceActivationRequestEvent));
81 73 : mxConfigurationController->addConfigurationChangeListener(
82 : this,
83 : FrameworkHelper::msResourceDeactivationRequestEvent,
84 73 : makeAny(gnResourceDeactivationRequestEvent));
85 : }
86 73 : }
87 73 : }
88 :
89 :
90 :
91 :
92 146 : ToolBarModule::~ToolBarModule (void)
93 : {
94 146 : }
95 :
96 :
97 :
98 :
99 73 : void SAL_CALL ToolBarModule::disposing (void)
100 : {
101 73 : if (mxConfigurationController.is())
102 0 : mxConfigurationController->removeConfigurationChangeListener(this);
103 :
104 73 : mxConfigurationController = NULL;
105 73 : }
106 :
107 :
108 :
109 :
110 1214 : void SAL_CALL ToolBarModule::notifyConfigurationChange (
111 : const ConfigurationChangeEvent& rEvent)
112 : throw (RuntimeException, std::exception)
113 : {
114 1214 : if (mxConfigurationController.is())
115 : {
116 1214 : sal_Int32 nEventType = 0;
117 1214 : rEvent.UserData >>= nEventType;
118 1214 : switch (nEventType)
119 : {
120 : case gnConfigurationUpdateStartEvent:
121 252 : HandleUpdateStart();
122 252 : break;
123 :
124 : case gnConfigurationUpdateEndEvent:
125 252 : HandleUpdateEnd();
126 252 : break;
127 :
128 : case gnResourceActivationRequestEvent:
129 : case gnResourceDeactivationRequestEvent:
130 : // Remember the request for the activation or deactivation
131 : // of the center pane view. When that happens then on end
132 : // of the next configuration update the set of visible tool
133 : // bars will be updated.
134 710 : if ( ! mbMainViewSwitchUpdatePending)
135 1221 : if (rEvent.ResourceId->getResourceURL().match(
136 1628 : FrameworkHelper::msViewURLPrefix)
137 1482 : && rEvent.ResourceId->isBoundToURL(
138 261 : FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
139 : {
140 146 : mbMainViewSwitchUpdatePending = true;
141 : }
142 710 : break;
143 : }
144 : }
145 1214 : }
146 :
147 :
148 :
149 :
150 :
151 :
152 :
153 252 : void ToolBarModule::HandleUpdateStart (void)
154 : {
155 : // Lock the ToolBarManager and tell it to lock the ViewShellManager as
156 : // well. This way the ToolBarManager can optimize the releasing of
157 : // locks and arranging of updates of both tool bars and the view shell
158 : // stack.
159 252 : if (mpBase != NULL)
160 : {
161 252 : ::boost::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager());
162 252 : mpToolBarManagerLock.reset(new ToolBarManager::UpdateLock(pToolBarManager));
163 252 : pToolBarManager->LockViewShellManager();
164 : }
165 252 : }
166 :
167 :
168 :
169 :
170 252 : void ToolBarModule::HandleUpdateEnd (void)
171 : {
172 252 : if (mbMainViewSwitchUpdatePending)
173 : {
174 146 : mbMainViewSwitchUpdatePending = false;
175 : // Update the set of visible tool bars and deactivate those that are
176 : // no longer visible. This is done before the old view shell is
177 : // destroyed in order to avoid unnecessary updates of those tool
178 : // bars.
179 146 : ::boost::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager());
180 : ::boost::shared_ptr<FrameworkHelper> pFrameworkHelper (
181 292 : FrameworkHelper::Instance(*mpBase));
182 : ViewShell* pViewShell
183 146 : = pFrameworkHelper->GetViewShell(FrameworkHelper::msCenterPaneURL).get();
184 146 : if (pViewShell != NULL)
185 : {
186 69 : pToolBarManager->MainViewShellChanged(*pViewShell);
187 : pToolBarManager->SelectionHasChanged(
188 : *pViewShell,
189 69 : *pViewShell->GetView());
190 69 : pToolBarManager->PreUpdate();
191 : }
192 : else
193 : {
194 77 : pToolBarManager->MainViewShellChanged(ViewShell::ST_NONE);
195 77 : pToolBarManager->PreUpdate();
196 146 : }
197 : }
198 :
199 : // Releasing the update lock of the ToolBarManager will let the
200 : // ToolBarManager with the help of the ViewShellManager take care of
201 : // updating tool bars and view shell with the minimal amount of
202 : // shell stack modifications and tool bar updates.
203 252 : mpToolBarManagerLock.reset();
204 252 : }
205 :
206 :
207 :
208 :
209 73 : void SAL_CALL ToolBarModule::disposing (const lang::EventObject& rEvent)
210 : throw (RuntimeException, std::exception)
211 : {
212 146 : if (mxConfigurationController.is()
213 73 : && rEvent.Source == mxConfigurationController)
214 : {
215 : // Without the configuration controller this class can do nothing.
216 73 : mxConfigurationController = NULL;
217 73 : dispose();
218 : }
219 73 : }
220 :
221 :
222 :
223 :
224 : } } // end of namespace sd::framework
225 :
226 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|