1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ToolBarModule.cxx,v $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 #include "precompiled_sd.hxx"
34 #include "ToolBarModule.hxx"
35 #include "ViewShellBase.hxx"
36 #include "DrawController.hxx"
37 #include "framework/FrameworkHelper.hxx"
38 #include "framework/ConfigurationController.hxx"
41 using namespace ::com::sun::star
;
42 using namespace ::com::sun::star::uno
;
43 using namespace ::com::sun::star::drawing::framework
;
45 using ::rtl::OUString
;
46 using ::sd::framework::FrameworkHelper
;
49 static const sal_Int32
gnConfigurationUpdateStartEvent(0);
50 static const sal_Int32
gnConfigurationUpdateEndEvent(1);
51 static const sal_Int32
gnResourceActivationRequestEvent(2);
52 static const sal_Int32
gnResourceDeactivationRequestEvent(3);
55 namespace sd
{ namespace framework
{
57 //===== ToolBarModule =========================================================
59 ToolBarModule::ToolBarModule (
60 const Reference
<frame::XController
>& rxController
)
61 : ToolBarModuleInterfaceBase(m_aMutex
),
62 mxConfigurationController(),
64 mpToolBarManagerLock(),
65 mbMainViewSwitchUpdatePending(false)
67 // Tunnel through the controller to obtain a ViewShellBase.
68 Reference
<lang::XUnoTunnel
> xTunnel (rxController
, UNO_QUERY
);
71 ::sd::DrawController
* pController
= reinterpret_cast<sd::DrawController
*>(
72 xTunnel
->getSomething(sd::DrawController::getUnoTunnelId()));
73 if (pController
!= NULL
)
74 mpBase
= pController
->GetViewShellBase();
77 Reference
<XControllerManager
> xControllerManager (rxController
, UNO_QUERY
);
78 if (xControllerManager
.is())
80 mxConfigurationController
= xControllerManager
->getConfigurationController();
81 if (mxConfigurationController
.is())
83 mxConfigurationController
->addConfigurationChangeListener(
85 FrameworkHelper::msConfigurationUpdateStartEvent
,
86 makeAny(gnConfigurationUpdateStartEvent
));
87 mxConfigurationController
->addConfigurationChangeListener(
89 FrameworkHelper::msConfigurationUpdateEndEvent
,
90 makeAny(gnConfigurationUpdateEndEvent
));
91 mxConfigurationController
->addConfigurationChangeListener(
93 FrameworkHelper::msResourceActivationRequestEvent
,
94 makeAny(gnResourceActivationRequestEvent
));
95 mxConfigurationController
->addConfigurationChangeListener(
97 FrameworkHelper::msResourceDeactivationRequestEvent
,
98 makeAny(gnResourceDeactivationRequestEvent
));
106 ToolBarModule::~ToolBarModule (void)
113 void SAL_CALL
ToolBarModule::disposing (void)
115 if (mxConfigurationController
.is())
116 mxConfigurationController
->removeConfigurationChangeListener(this);
118 mxConfigurationController
= NULL
;
124 void SAL_CALL
ToolBarModule::notifyConfigurationChange (
125 const ConfigurationChangeEvent
& rEvent
)
126 throw (RuntimeException
)
128 if (mxConfigurationController
.is())
130 sal_Int32 nEventType
= 0;
131 rEvent
.UserData
>>= nEventType
;
134 case gnConfigurationUpdateStartEvent
:
138 case gnConfigurationUpdateEndEvent
:
142 case gnResourceActivationRequestEvent
:
143 case gnResourceDeactivationRequestEvent
:
144 // Remember the request for the activation or deactivation
145 // of the center pane view. When that happens then on end
146 // of the next configuration update the set of visible tool
147 // bars will be updated.
148 if ( ! mbMainViewSwitchUpdatePending
)
149 if (rEvent
.ResourceId
->getResourceURL().match(
150 FrameworkHelper::msViewURLPrefix
)
151 && rEvent
.ResourceId
->isBoundToURL(
152 FrameworkHelper::msCenterPaneURL
, AnchorBindingMode_DIRECT
))
154 mbMainViewSwitchUpdatePending
= true;
164 //-----------------------------------------------------------------------------
167 void ToolBarModule::HandleUpdateStart (void)
169 // Lock the ToolBarManager and tell it to lock the ViewShellManager as
170 // well. This way the ToolBarManager can optimize the releasing of
171 // locks and arranging of updates of both tool bars and the view shell
175 ::boost::shared_ptr
<ToolBarManager
> pToolBarManager (mpBase
->GetToolBarManager());
176 mpToolBarManagerLock
.reset(new ToolBarManager::UpdateLock(pToolBarManager
));
177 pToolBarManager
->LockViewShellManager();
184 void ToolBarModule::HandleUpdateEnd (void)
186 if (mbMainViewSwitchUpdatePending
)
188 mbMainViewSwitchUpdatePending
= false;
189 // Update the set of visible tool bars and deactivate those that are
190 // no longer visible. This is done before the old view shell is
191 // destroyed in order to avoid unnecessary updates of those tool
193 ::boost::shared_ptr
<ToolBarManager
> pToolBarManager (mpBase
->GetToolBarManager());
194 ::boost::shared_ptr
<FrameworkHelper
> pFrameworkHelper (
195 FrameworkHelper::Instance(*mpBase
));
196 ViewShell
* pViewShell
197 = pFrameworkHelper
->GetViewShell(FrameworkHelper::msCenterPaneURL
).get();
198 if (pViewShell
!= NULL
)
200 pToolBarManager
->MainViewShellChanged(*pViewShell
);
201 pToolBarManager
->SelectionHasChanged(
203 *pViewShell
->GetView());
204 pToolBarManager
->PreUpdate();
208 pToolBarManager
->MainViewShellChanged(ViewShell::ST_NONE
);
209 pToolBarManager
->PreUpdate();
213 // Releasing the update lock of the ToolBarManager will let the
214 // ToolBarManager with the help of the ViewShellManager take care of
215 // updating tool bars and view shell with the minimal amount of
216 // shell stack modifications and tool bar updates.
217 mpToolBarManagerLock
.reset();
223 void SAL_CALL
ToolBarModule::disposing (const lang::EventObject
& rEvent
)
224 throw (RuntimeException
)
226 if (mxConfigurationController
.is()
227 && rEvent
.Source
== mxConfigurationController
)
229 // Without the configuration controller this class can do nothing.
230 mxConfigurationController
= NULL
;
238 } } // end of namespace sd::framework