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 #ifndef SD_FRAMEWORK_READ_ONLY_MODE_OBSERVER_HXX 29*cdf0e10cSrcweir #define SD_FRAMEWORK_READ_ONLY_MODE_OBSERVER_HXX 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "MutexOwner.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 34*cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/frame/XStatusListener.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/util/XModifyListener.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XConfigurationController.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp> 41*cdf0e10cSrcweir #include <osl/mutex.hxx> 42*cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx> 43*cdf0e10cSrcweir #include <tools/link.hxx> 44*cdf0e10cSrcweir #include <boost/function.hpp> 45*cdf0e10cSrcweir #include <boost/scoped_ptr.hpp> 46*cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 47*cdf0e10cSrcweir 48*cdf0e10cSrcweir namespace { 49*cdf0e10cSrcweir 50*cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper2 < 51*cdf0e10cSrcweir ::com::sun::star::drawing::framework::XConfigurationChangeListener, 52*cdf0e10cSrcweir ::com::sun::star::frame::XStatusListener 53*cdf0e10cSrcweir > ReadOnlyModeObserverInterfaceBase; 54*cdf0e10cSrcweir 55*cdf0e10cSrcweir } // end of anonymous namespace. 56*cdf0e10cSrcweir 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir 59*cdf0e10cSrcweir 60*cdf0e10cSrcweir namespace sd { namespace framework { 61*cdf0e10cSrcweir 62*cdf0e10cSrcweir /** Wait for changes of the read-only mode. On switching between read-only 63*cdf0e10cSrcweir mode and read-write the registered listeners are called. 64*cdf0e10cSrcweir 65*cdf0e10cSrcweir This class handles the case that the given controller is not yet 66*cdf0e10cSrcweir connected to a frame and that the dispatcher is not yet set up. It 67*cdf0e10cSrcweir waits for this to happen and then registers at the .uno:EditDoc command 68*cdf0e10cSrcweir and waits for state changes. 69*cdf0e10cSrcweir */ 70*cdf0e10cSrcweir class ReadOnlyModeObserver 71*cdf0e10cSrcweir : private sd::MutexOwner, 72*cdf0e10cSrcweir public ReadOnlyModeObserverInterfaceBase 73*cdf0e10cSrcweir { 74*cdf0e10cSrcweir public: 75*cdf0e10cSrcweir /** Create a new read-only mode observer for the given controller. 76*cdf0e10cSrcweir */ 77*cdf0e10cSrcweir ReadOnlyModeObserver ( 78*cdf0e10cSrcweir const ::com::sun::star::uno::Reference<com::sun::star::frame::XController>& rxController); 79*cdf0e10cSrcweir virtual ~ReadOnlyModeObserver (void); 80*cdf0e10cSrcweir 81*cdf0e10cSrcweir virtual void SAL_CALL disposing (void); 82*cdf0e10cSrcweir 83*cdf0e10cSrcweir 84*cdf0e10cSrcweir /** Add a status listener that is called when the state of the 85*cdf0e10cSrcweir .uno:EditDoc command changes. Note that the listener has to take 86*cdf0e10cSrcweir into account both the IsEnabled and the State fields of the 87*cdf0e10cSrcweir FeatureStateEvent. Only when IsEnabled is true then the State field 88*cdf0e10cSrcweir is valid. 89*cdf0e10cSrcweir */ 90*cdf0e10cSrcweir void AddStatusListener ( 91*cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 92*cdf0e10cSrcweir com::sun::star::frame::XStatusListener>& rxListener); 93*cdf0e10cSrcweir 94*cdf0e10cSrcweir // XEventListener 95*cdf0e10cSrcweir 96*cdf0e10cSrcweir virtual void SAL_CALL disposing ( 97*cdf0e10cSrcweir const com::sun::star::lang::EventObject& rEvent) 98*cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir // frame::XStatusListener 102*cdf0e10cSrcweir 103*cdf0e10cSrcweir /** Called by slot state change broadcasters. 104*cdf0e10cSrcweir @throws DisposedException 105*cdf0e10cSrcweir */ 106*cdf0e10cSrcweir virtual void SAL_CALL 107*cdf0e10cSrcweir statusChanged ( 108*cdf0e10cSrcweir const ::com::sun::star::frame::FeatureStateEvent& rState) 109*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 110*cdf0e10cSrcweir 111*cdf0e10cSrcweir // XConfigurationChangeListener 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir virtual void SAL_CALL notifyConfigurationChange ( 114*cdf0e10cSrcweir const ::com::sun::star::drawing::framework::ConfigurationChangeEvent& rEvent) 115*cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir private: 118*cdf0e10cSrcweir ::com::sun::star::util::URL maSlotNameURL; 119*cdf0e10cSrcweir /** The XController is stored to enable repeated calls to 120*cdf0e10cSrcweir ConnectToDispatch() (get access to the XDispatchProvider. 121*cdf0e10cSrcweir */ 122*cdf0e10cSrcweir ::com::sun::star::uno::Reference<com::sun::star::frame::XController> 123*cdf0e10cSrcweir mxController; 124*cdf0e10cSrcweir ::com::sun::star::uno::Reference<com::sun::star::drawing::framework::XConfigurationController> 125*cdf0e10cSrcweir mxConfigurationController; 126*cdf0e10cSrcweir ::com::sun::star::uno::Reference<com::sun::star::frame::XDispatch> 127*cdf0e10cSrcweir mxDispatch; 128*cdf0e10cSrcweir class ModifyBroadcaster; 129*cdf0e10cSrcweir ::boost::scoped_ptr<ModifyBroadcaster> mpBroadcaster; 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir /** Listen for the .uno:EditMode command. Returns <TRUE/> when the connection 132*cdf0e10cSrcweir has been established. 133*cdf0e10cSrcweir */ 134*cdf0e10cSrcweir bool ConnectToDispatch (void); 135*cdf0e10cSrcweir }; 136*cdf0e10cSrcweir 137*cdf0e10cSrcweir } } // end of namespace sd::framework 138*cdf0e10cSrcweir 139*cdf0e10cSrcweir #endif 140