1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir #include "precompiled_sd.hxx" 29*cdf0e10cSrcweir 30*cdf0e10cSrcweir #include "ToolBarModule.hxx" 31*cdf0e10cSrcweir #include "ViewShellBase.hxx" 32*cdf0e10cSrcweir #include "DrawController.hxx" 33*cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx" 34*cdf0e10cSrcweir #include "framework/ConfigurationController.hxx" 35*cdf0e10cSrcweir 36*cdf0e10cSrcweir 37*cdf0e10cSrcweir using namespace ::com::sun::star; 38*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 39*cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework; 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir using ::rtl::OUString; 42*cdf0e10cSrcweir using ::sd::framework::FrameworkHelper; 43*cdf0e10cSrcweir 44*cdf0e10cSrcweir namespace { 45*cdf0e10cSrcweir static const sal_Int32 gnConfigurationUpdateStartEvent(0); 46*cdf0e10cSrcweir static const sal_Int32 gnConfigurationUpdateEndEvent(1); 47*cdf0e10cSrcweir static const sal_Int32 gnResourceActivationRequestEvent(2); 48*cdf0e10cSrcweir static const sal_Int32 gnResourceDeactivationRequestEvent(3); 49*cdf0e10cSrcweir } 50*cdf0e10cSrcweir 51*cdf0e10cSrcweir namespace sd { namespace framework { 52*cdf0e10cSrcweir 53*cdf0e10cSrcweir //===== ToolBarModule ========================================================= 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir ToolBarModule::ToolBarModule ( 56*cdf0e10cSrcweir const Reference<frame::XController>& rxController) 57*cdf0e10cSrcweir : ToolBarModuleInterfaceBase(m_aMutex), 58*cdf0e10cSrcweir mxConfigurationController(), 59*cdf0e10cSrcweir mpBase(NULL), 60*cdf0e10cSrcweir mpToolBarManagerLock(), 61*cdf0e10cSrcweir mbMainViewSwitchUpdatePending(false) 62*cdf0e10cSrcweir { 63*cdf0e10cSrcweir // Tunnel through the controller to obtain a ViewShellBase. 64*cdf0e10cSrcweir Reference<lang::XUnoTunnel> xTunnel (rxController, UNO_QUERY); 65*cdf0e10cSrcweir if (xTunnel.is()) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>( 68*cdf0e10cSrcweir xTunnel->getSomething(sd::DrawController::getUnoTunnelId())); 69*cdf0e10cSrcweir if (pController != NULL) 70*cdf0e10cSrcweir mpBase = pController->GetViewShellBase(); 71*cdf0e10cSrcweir } 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY); 74*cdf0e10cSrcweir if (xControllerManager.is()) 75*cdf0e10cSrcweir { 76*cdf0e10cSrcweir mxConfigurationController = xControllerManager->getConfigurationController(); 77*cdf0e10cSrcweir if (mxConfigurationController.is()) 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener( 80*cdf0e10cSrcweir this, 81*cdf0e10cSrcweir FrameworkHelper::msConfigurationUpdateStartEvent, 82*cdf0e10cSrcweir makeAny(gnConfigurationUpdateStartEvent)); 83*cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener( 84*cdf0e10cSrcweir this, 85*cdf0e10cSrcweir FrameworkHelper::msConfigurationUpdateEndEvent, 86*cdf0e10cSrcweir makeAny(gnConfigurationUpdateEndEvent)); 87*cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener( 88*cdf0e10cSrcweir this, 89*cdf0e10cSrcweir FrameworkHelper::msResourceActivationRequestEvent, 90*cdf0e10cSrcweir makeAny(gnResourceActivationRequestEvent)); 91*cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener( 92*cdf0e10cSrcweir this, 93*cdf0e10cSrcweir FrameworkHelper::msResourceDeactivationRequestEvent, 94*cdf0e10cSrcweir makeAny(gnResourceDeactivationRequestEvent)); 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir ToolBarModule::~ToolBarModule (void) 103*cdf0e10cSrcweir { 104*cdf0e10cSrcweir } 105*cdf0e10cSrcweir 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir void SAL_CALL ToolBarModule::disposing (void) 110*cdf0e10cSrcweir { 111*cdf0e10cSrcweir if (mxConfigurationController.is()) 112*cdf0e10cSrcweir mxConfigurationController->removeConfigurationChangeListener(this); 113*cdf0e10cSrcweir 114*cdf0e10cSrcweir mxConfigurationController = NULL; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir void SAL_CALL ToolBarModule::notifyConfigurationChange ( 121*cdf0e10cSrcweir const ConfigurationChangeEvent& rEvent) 122*cdf0e10cSrcweir throw (RuntimeException) 123*cdf0e10cSrcweir { 124*cdf0e10cSrcweir if (mxConfigurationController.is()) 125*cdf0e10cSrcweir { 126*cdf0e10cSrcweir sal_Int32 nEventType = 0; 127*cdf0e10cSrcweir rEvent.UserData >>= nEventType; 128*cdf0e10cSrcweir switch (nEventType) 129*cdf0e10cSrcweir { 130*cdf0e10cSrcweir case gnConfigurationUpdateStartEvent: 131*cdf0e10cSrcweir HandleUpdateStart(); 132*cdf0e10cSrcweir break; 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir case gnConfigurationUpdateEndEvent: 135*cdf0e10cSrcweir HandleUpdateEnd(); 136*cdf0e10cSrcweir break; 137*cdf0e10cSrcweir 138*cdf0e10cSrcweir case gnResourceActivationRequestEvent: 139*cdf0e10cSrcweir case gnResourceDeactivationRequestEvent: 140*cdf0e10cSrcweir // Remember the request for the activation or deactivation 141*cdf0e10cSrcweir // of the center pane view. When that happens then on end 142*cdf0e10cSrcweir // of the next configuration update the set of visible tool 143*cdf0e10cSrcweir // bars will be updated. 144*cdf0e10cSrcweir if ( ! mbMainViewSwitchUpdatePending) 145*cdf0e10cSrcweir if (rEvent.ResourceId->getResourceURL().match( 146*cdf0e10cSrcweir FrameworkHelper::msViewURLPrefix) 147*cdf0e10cSrcweir && rEvent.ResourceId->isBoundToURL( 148*cdf0e10cSrcweir FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT)) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir mbMainViewSwitchUpdatePending = true; 151*cdf0e10cSrcweir } 152*cdf0e10cSrcweir break; 153*cdf0e10cSrcweir } 154*cdf0e10cSrcweir } 155*cdf0e10cSrcweir } 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir 160*cdf0e10cSrcweir //----------------------------------------------------------------------------- 161*cdf0e10cSrcweir 162*cdf0e10cSrcweir 163*cdf0e10cSrcweir void ToolBarModule::HandleUpdateStart (void) 164*cdf0e10cSrcweir { 165*cdf0e10cSrcweir // Lock the ToolBarManager and tell it to lock the ViewShellManager as 166*cdf0e10cSrcweir // well. This way the ToolBarManager can optimize the releasing of 167*cdf0e10cSrcweir // locks and arranging of updates of both tool bars and the view shell 168*cdf0e10cSrcweir // stack. 169*cdf0e10cSrcweir if (mpBase != NULL) 170*cdf0e10cSrcweir { 171*cdf0e10cSrcweir ::boost::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager()); 172*cdf0e10cSrcweir mpToolBarManagerLock.reset(new ToolBarManager::UpdateLock(pToolBarManager)); 173*cdf0e10cSrcweir pToolBarManager->LockViewShellManager(); 174*cdf0e10cSrcweir } 175*cdf0e10cSrcweir } 176*cdf0e10cSrcweir 177*cdf0e10cSrcweir 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir 180*cdf0e10cSrcweir void ToolBarModule::HandleUpdateEnd (void) 181*cdf0e10cSrcweir { 182*cdf0e10cSrcweir if (mbMainViewSwitchUpdatePending) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir mbMainViewSwitchUpdatePending = false; 185*cdf0e10cSrcweir // Update the set of visible tool bars and deactivate those that are 186*cdf0e10cSrcweir // no longer visible. This is done before the old view shell is 187*cdf0e10cSrcweir // destroyed in order to avoid unnecessary updates of those tool 188*cdf0e10cSrcweir // bars. 189*cdf0e10cSrcweir ::boost::shared_ptr<ToolBarManager> pToolBarManager (mpBase->GetToolBarManager()); 190*cdf0e10cSrcweir ::boost::shared_ptr<FrameworkHelper> pFrameworkHelper ( 191*cdf0e10cSrcweir FrameworkHelper::Instance(*mpBase)); 192*cdf0e10cSrcweir ViewShell* pViewShell 193*cdf0e10cSrcweir = pFrameworkHelper->GetViewShell(FrameworkHelper::msCenterPaneURL).get(); 194*cdf0e10cSrcweir if (pViewShell != NULL) 195*cdf0e10cSrcweir { 196*cdf0e10cSrcweir pToolBarManager->MainViewShellChanged(*pViewShell); 197*cdf0e10cSrcweir pToolBarManager->SelectionHasChanged( 198*cdf0e10cSrcweir *pViewShell, 199*cdf0e10cSrcweir *pViewShell->GetView()); 200*cdf0e10cSrcweir pToolBarManager->PreUpdate(); 201*cdf0e10cSrcweir } 202*cdf0e10cSrcweir else 203*cdf0e10cSrcweir { 204*cdf0e10cSrcweir pToolBarManager->MainViewShellChanged(ViewShell::ST_NONE); 205*cdf0e10cSrcweir pToolBarManager->PreUpdate(); 206*cdf0e10cSrcweir } 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir // Releasing the update lock of the ToolBarManager will let the 210*cdf0e10cSrcweir // ToolBarManager with the help of the ViewShellManager take care of 211*cdf0e10cSrcweir // updating tool bars and view shell with the minimal amount of 212*cdf0e10cSrcweir // shell stack modifications and tool bar updates. 213*cdf0e10cSrcweir mpToolBarManagerLock.reset(); 214*cdf0e10cSrcweir } 215*cdf0e10cSrcweir 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir 218*cdf0e10cSrcweir 219*cdf0e10cSrcweir void SAL_CALL ToolBarModule::disposing (const lang::EventObject& rEvent) 220*cdf0e10cSrcweir throw (RuntimeException) 221*cdf0e10cSrcweir { 222*cdf0e10cSrcweir if (mxConfigurationController.is() 223*cdf0e10cSrcweir && rEvent.Source == mxConfigurationController) 224*cdf0e10cSrcweir { 225*cdf0e10cSrcweir // Without the configuration controller this class can do nothing. 226*cdf0e10cSrcweir mxConfigurationController = NULL; 227*cdf0e10cSrcweir dispose(); 228*cdf0e10cSrcweir } 229*cdf0e10cSrcweir } 230*cdf0e10cSrcweir 231*cdf0e10cSrcweir 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir 234*cdf0e10cSrcweir } } // end of namespace sd::framework 235