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 "ReadOnlyModeObserver.hxx" 31*cdf0e10cSrcweir 32*cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XControllerManager.hpp> 33*cdf0e10cSrcweir #include <com/sun/star/lang/DisposedException.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/util/XURLTransformer.hpp> 35*cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 36*cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx> 37*cdf0e10cSrcweir 38*cdf0e10cSrcweir #include "tools/SlotStateListener.hxx" 39*cdf0e10cSrcweir #include "framework/FrameworkHelper.hxx" 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 42*cdf0e10cSrcweir using namespace ::com::sun::star; 43*cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework; 44*cdf0e10cSrcweir using ::rtl::OUString; 45*cdf0e10cSrcweir 46*cdf0e10cSrcweir namespace sd { namespace framework { 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir class ReadOnlyModeObserver::ModifyBroadcaster 49*cdf0e10cSrcweir : public ::cppu::OBroadcastHelper 50*cdf0e10cSrcweir { 51*cdf0e10cSrcweir public: 52*cdf0e10cSrcweir explicit ModifyBroadcaster (::osl::Mutex& rOslMutex) : ::cppu::OBroadcastHelper(rOslMutex) {} 53*cdf0e10cSrcweir }; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir ReadOnlyModeObserver::ReadOnlyModeObserver ( 59*cdf0e10cSrcweir const Reference<frame::XController>& rxController) 60*cdf0e10cSrcweir : ReadOnlyModeObserverInterfaceBase(maMutex), 61*cdf0e10cSrcweir maSlotNameURL(), 62*cdf0e10cSrcweir mxController(rxController), 63*cdf0e10cSrcweir mxConfigurationController(NULL), 64*cdf0e10cSrcweir mxDispatch(NULL), 65*cdf0e10cSrcweir mpBroadcaster(new ModifyBroadcaster(maMutex)) 66*cdf0e10cSrcweir { 67*cdf0e10cSrcweir // Create a URL object for the slot name. 68*cdf0e10cSrcweir maSlotNameURL.Complete = OUString::createFromAscii(".uno:EditDoc"); 69*cdf0e10cSrcweir uno::Reference<lang::XMultiServiceFactory> xServiceManager ( 70*cdf0e10cSrcweir ::comphelper::getProcessServiceFactory()); 71*cdf0e10cSrcweir if (xServiceManager.is()) 72*cdf0e10cSrcweir { 73*cdf0e10cSrcweir Reference<util::XURLTransformer> xTransformer(xServiceManager->createInstance( 74*cdf0e10cSrcweir OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.util.URLTransformer"))), 75*cdf0e10cSrcweir UNO_QUERY); 76*cdf0e10cSrcweir if (xTransformer.is()) 77*cdf0e10cSrcweir xTransformer->parseStrict(maSlotNameURL); 78*cdf0e10cSrcweir } 79*cdf0e10cSrcweir 80*cdf0e10cSrcweir if ( ! ConnectToDispatch()) 81*cdf0e10cSrcweir { 82*cdf0e10cSrcweir // The controller is not yet connected to a frame. This means that 83*cdf0e10cSrcweir // the dispatcher is not yet set up. We wait for this to happen by 84*cdf0e10cSrcweir // waiting for configuration updates and try again. 85*cdf0e10cSrcweir Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY); 86*cdf0e10cSrcweir if (xControllerManager.is()) 87*cdf0e10cSrcweir { 88*cdf0e10cSrcweir mxConfigurationController = xControllerManager->getConfigurationController(); 89*cdf0e10cSrcweir if (mxConfigurationController.is()) 90*cdf0e10cSrcweir { 91*cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener( 92*cdf0e10cSrcweir this, 93*cdf0e10cSrcweir FrameworkHelper::msConfigurationUpdateStartEvent, 94*cdf0e10cSrcweir Any()); 95*cdf0e10cSrcweir } 96*cdf0e10cSrcweir } 97*cdf0e10cSrcweir } 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir ReadOnlyModeObserver::~ReadOnlyModeObserver (void) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir } 106*cdf0e10cSrcweir 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir void SAL_CALL ReadOnlyModeObserver::disposing (void) 111*cdf0e10cSrcweir { 112*cdf0e10cSrcweir if (mxController.is()) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir mxController = NULL; 115*cdf0e10cSrcweir } 116*cdf0e10cSrcweir if (mxConfigurationController.is()) 117*cdf0e10cSrcweir { 118*cdf0e10cSrcweir mxConfigurationController->removeConfigurationChangeListener(this); 119*cdf0e10cSrcweir mxConfigurationController = NULL; 120*cdf0e10cSrcweir } 121*cdf0e10cSrcweir if (mxDispatch.is()) 122*cdf0e10cSrcweir { 123*cdf0e10cSrcweir mxDispatch->removeStatusListener(this, maSlotNameURL); 124*cdf0e10cSrcweir mxDispatch = NULL; 125*cdf0e10cSrcweir } 126*cdf0e10cSrcweir 127*cdf0e10cSrcweir lang::EventObject aEvent; 128*cdf0e10cSrcweir aEvent.Source = static_cast<XWeak*>(this); 129*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* pIterator 130*cdf0e10cSrcweir = mpBroadcaster->getContainer(getCppuType((Reference<frame::XStatusListener>*)NULL)); 131*cdf0e10cSrcweir pIterator->disposeAndClear(aEvent); 132*cdf0e10cSrcweir } 133*cdf0e10cSrcweir 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir void ReadOnlyModeObserver::AddStatusListener ( 138*cdf0e10cSrcweir const Reference<frame::XStatusListener>& rxListener) 139*cdf0e10cSrcweir { 140*cdf0e10cSrcweir mpBroadcaster->addListener( 141*cdf0e10cSrcweir getCppuType((Reference<frame::XStatusListener>*)NULL), 142*cdf0e10cSrcweir rxListener); 143*cdf0e10cSrcweir } 144*cdf0e10cSrcweir 145*cdf0e10cSrcweir 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir 148*cdf0e10cSrcweir bool ReadOnlyModeObserver::ConnectToDispatch (void) 149*cdf0e10cSrcweir { 150*cdf0e10cSrcweir if ( ! mxDispatch.is()) 151*cdf0e10cSrcweir { 152*cdf0e10cSrcweir // Get the dispatch object. 153*cdf0e10cSrcweir Reference<frame::XDispatchProvider> xProvider (mxController->getFrame(), UNO_QUERY); 154*cdf0e10cSrcweir if (xProvider.is()) 155*cdf0e10cSrcweir { 156*cdf0e10cSrcweir mxDispatch = xProvider->queryDispatch(maSlotNameURL, OUString(), 0); 157*cdf0e10cSrcweir if (mxDispatch.is()) 158*cdf0e10cSrcweir { 159*cdf0e10cSrcweir mxDispatch->addStatusListener(this, maSlotNameURL); 160*cdf0e10cSrcweir } 161*cdf0e10cSrcweir } 162*cdf0e10cSrcweir } 163*cdf0e10cSrcweir 164*cdf0e10cSrcweir return mxDispatch.is(); 165*cdf0e10cSrcweir } 166*cdf0e10cSrcweir 167*cdf0e10cSrcweir 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir 170*cdf0e10cSrcweir void ReadOnlyModeObserver::statusChanged (const frame::FeatureStateEvent& rEvent) 171*cdf0e10cSrcweir throw (RuntimeException) 172*cdf0e10cSrcweir { 173*cdf0e10cSrcweir ::cppu::OInterfaceContainerHelper* pIterator 174*cdf0e10cSrcweir = mpBroadcaster->getContainer(getCppuType((Reference<frame::XStatusListener>*)NULL)); 175*cdf0e10cSrcweir if (pIterator != NULL) 176*cdf0e10cSrcweir { 177*cdf0e10cSrcweir pIterator->notifyEach(&frame::XStatusListener::statusChanged, rEvent); 178*cdf0e10cSrcweir } 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir 182*cdf0e10cSrcweir 183*cdf0e10cSrcweir 184*cdf0e10cSrcweir //----- XEventListener -------------------------------------------------------- 185*cdf0e10cSrcweir 186*cdf0e10cSrcweir void SAL_CALL ReadOnlyModeObserver::disposing ( 187*cdf0e10cSrcweir const lang::EventObject& rEvent) 188*cdf0e10cSrcweir throw (RuntimeException) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir if (rEvent.Source == mxConfigurationController) 191*cdf0e10cSrcweir mxConfigurationController = NULL; 192*cdf0e10cSrcweir else if (rEvent.Source == mxDispatch) 193*cdf0e10cSrcweir mxDispatch = NULL; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir dispose(); 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir 199*cdf0e10cSrcweir 200*cdf0e10cSrcweir 201*cdf0e10cSrcweir void SAL_CALL ReadOnlyModeObserver::notifyConfigurationChange ( 202*cdf0e10cSrcweir const ConfigurationChangeEvent& rEvent) 203*cdf0e10cSrcweir throw (RuntimeException) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir if (rEvent.Type.equals(FrameworkHelper::msConfigurationUpdateStartEvent)) 206*cdf0e10cSrcweir { 207*cdf0e10cSrcweir if (mxController.is() && mxController->getFrame().is()) 208*cdf0e10cSrcweir { 209*cdf0e10cSrcweir if (ConnectToDispatch()) 210*cdf0e10cSrcweir { 211*cdf0e10cSrcweir // We have connected successfully to the dispatcher and 212*cdf0e10cSrcweir // therefore can disconnect from the configuration controller. 213*cdf0e10cSrcweir mxConfigurationController->removeConfigurationChangeListener(this); 214*cdf0e10cSrcweir mxConfigurationController = NULL; 215*cdf0e10cSrcweir } 216*cdf0e10cSrcweir } 217*cdf0e10cSrcweir } 218*cdf0e10cSrcweir } 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir } } // end of namespace sd::framework 221