1*c45d927aSAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*c45d927aSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*c45d927aSAndrew Rist * or more contributor license agreements. See the NOTICE file 5*c45d927aSAndrew Rist * distributed with this work for additional information 6*c45d927aSAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*c45d927aSAndrew Rist * to you under the Apache License, Version 2.0 (the 8*c45d927aSAndrew Rist * "License"); you may not use this file except in compliance 9*c45d927aSAndrew Rist * with the License. You may obtain a copy of the License at 10*c45d927aSAndrew Rist * 11*c45d927aSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*c45d927aSAndrew Rist * 13*c45d927aSAndrew Rist * Unless required by applicable law or agreed to in writing, 14*c45d927aSAndrew Rist * software distributed under the License is distributed on an 15*c45d927aSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*c45d927aSAndrew Rist * KIND, either express or implied. See the License for the 17*c45d927aSAndrew Rist * specific language governing permissions and limitations 18*c45d927aSAndrew Rist * under the License. 19*c45d927aSAndrew Rist * 20*c45d927aSAndrew Rist *************************************************************/ 21*c45d927aSAndrew Rist 22*c45d927aSAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir #ifndef SD_FRAMEWORK_READ_ONLY_MODE_OBSERVER_HXX 25cdf0e10cSrcweir #define SD_FRAMEWORK_READ_ONLY_MODE_OBSERVER_HXX 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include "MutexOwner.hxx" 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 30cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp> 31cdf0e10cSrcweir #include <com/sun/star/frame/XStatusListener.hpp> 32cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp> 33cdf0e10cSrcweir #include <com/sun/star/lang/XEventListener.hpp> 34cdf0e10cSrcweir #include <com/sun/star/util/XModifyListener.hpp> 35cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XConfigurationController.hpp> 36cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp> 37cdf0e10cSrcweir #include <osl/mutex.hxx> 38cdf0e10cSrcweir #include <cppuhelper/compbase2.hxx> 39cdf0e10cSrcweir #include <tools/link.hxx> 40cdf0e10cSrcweir #include <boost/function.hpp> 41cdf0e10cSrcweir #include <boost/scoped_ptr.hpp> 42cdf0e10cSrcweir #include <boost/shared_ptr.hpp> 43cdf0e10cSrcweir 44cdf0e10cSrcweir namespace { 45cdf0e10cSrcweir 46cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper2 < 47cdf0e10cSrcweir ::com::sun::star::drawing::framework::XConfigurationChangeListener, 48cdf0e10cSrcweir ::com::sun::star::frame::XStatusListener 49cdf0e10cSrcweir > ReadOnlyModeObserverInterfaceBase; 50cdf0e10cSrcweir 51cdf0e10cSrcweir } // end of anonymous namespace. 52cdf0e10cSrcweir 53cdf0e10cSrcweir 54cdf0e10cSrcweir 55cdf0e10cSrcweir 56cdf0e10cSrcweir namespace sd { namespace framework { 57cdf0e10cSrcweir 58cdf0e10cSrcweir /** Wait for changes of the read-only mode. On switching between read-only 59cdf0e10cSrcweir mode and read-write the registered listeners are called. 60cdf0e10cSrcweir 61cdf0e10cSrcweir This class handles the case that the given controller is not yet 62cdf0e10cSrcweir connected to a frame and that the dispatcher is not yet set up. It 63cdf0e10cSrcweir waits for this to happen and then registers at the .uno:EditDoc command 64cdf0e10cSrcweir and waits for state changes. 65cdf0e10cSrcweir */ 66cdf0e10cSrcweir class ReadOnlyModeObserver 67cdf0e10cSrcweir : private sd::MutexOwner, 68cdf0e10cSrcweir public ReadOnlyModeObserverInterfaceBase 69cdf0e10cSrcweir { 70cdf0e10cSrcweir public: 71cdf0e10cSrcweir /** Create a new read-only mode observer for the given controller. 72cdf0e10cSrcweir */ 73cdf0e10cSrcweir ReadOnlyModeObserver ( 74cdf0e10cSrcweir const ::com::sun::star::uno::Reference<com::sun::star::frame::XController>& rxController); 75cdf0e10cSrcweir virtual ~ReadOnlyModeObserver (void); 76cdf0e10cSrcweir 77cdf0e10cSrcweir virtual void SAL_CALL disposing (void); 78cdf0e10cSrcweir 79cdf0e10cSrcweir 80cdf0e10cSrcweir /** Add a status listener that is called when the state of the 81cdf0e10cSrcweir .uno:EditDoc command changes. Note that the listener has to take 82cdf0e10cSrcweir into account both the IsEnabled and the State fields of the 83cdf0e10cSrcweir FeatureStateEvent. Only when IsEnabled is true then the State field 84cdf0e10cSrcweir is valid. 85cdf0e10cSrcweir */ 86cdf0e10cSrcweir void AddStatusListener ( 87cdf0e10cSrcweir const ::com::sun::star::uno::Reference< 88cdf0e10cSrcweir com::sun::star::frame::XStatusListener>& rxListener); 89cdf0e10cSrcweir 90cdf0e10cSrcweir // XEventListener 91cdf0e10cSrcweir 92cdf0e10cSrcweir virtual void SAL_CALL disposing ( 93cdf0e10cSrcweir const com::sun::star::lang::EventObject& rEvent) 94cdf0e10cSrcweir throw (com::sun::star::uno::RuntimeException); 95cdf0e10cSrcweir 96cdf0e10cSrcweir 97cdf0e10cSrcweir // frame::XStatusListener 98cdf0e10cSrcweir 99cdf0e10cSrcweir /** Called by slot state change broadcasters. 100cdf0e10cSrcweir @throws DisposedException 101cdf0e10cSrcweir */ 102cdf0e10cSrcweir virtual void SAL_CALL 103cdf0e10cSrcweir statusChanged ( 104cdf0e10cSrcweir const ::com::sun::star::frame::FeatureStateEvent& rState) 105cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 106cdf0e10cSrcweir 107cdf0e10cSrcweir // XConfigurationChangeListener 108cdf0e10cSrcweir 109cdf0e10cSrcweir virtual void SAL_CALL notifyConfigurationChange ( 110cdf0e10cSrcweir const ::com::sun::star::drawing::framework::ConfigurationChangeEvent& rEvent) 111cdf0e10cSrcweir throw (::com::sun::star::uno::RuntimeException); 112cdf0e10cSrcweir 113cdf0e10cSrcweir private: 114cdf0e10cSrcweir ::com::sun::star::util::URL maSlotNameURL; 115cdf0e10cSrcweir /** The XController is stored to enable repeated calls to 116cdf0e10cSrcweir ConnectToDispatch() (get access to the XDispatchProvider. 117cdf0e10cSrcweir */ 118cdf0e10cSrcweir ::com::sun::star::uno::Reference<com::sun::star::frame::XController> 119cdf0e10cSrcweir mxController; 120cdf0e10cSrcweir ::com::sun::star::uno::Reference<com::sun::star::drawing::framework::XConfigurationController> 121cdf0e10cSrcweir mxConfigurationController; 122cdf0e10cSrcweir ::com::sun::star::uno::Reference<com::sun::star::frame::XDispatch> 123cdf0e10cSrcweir mxDispatch; 124cdf0e10cSrcweir class ModifyBroadcaster; 125cdf0e10cSrcweir ::boost::scoped_ptr<ModifyBroadcaster> mpBroadcaster; 126cdf0e10cSrcweir 127cdf0e10cSrcweir /** Listen for the .uno:EditMode command. Returns <TRUE/> when the connection 128cdf0e10cSrcweir has been established. 129cdf0e10cSrcweir */ 130cdf0e10cSrcweir bool ConnectToDispatch (void); 131cdf0e10cSrcweir }; 132cdf0e10cSrcweir 133cdf0e10cSrcweir } } // end of namespace sd::framework 134cdf0e10cSrcweir 135cdf0e10cSrcweir #endif 136